Skip to content

Instantly share code, notes, and snippets.

@leonheldattoradex
Last active October 16, 2024 11:58
Show Gist options
  • Save leonheldattoradex/b3c3053dd30eb3074746a3204ecd20e8 to your computer and use it in GitHub Desktop.
Save leonheldattoradex/b3c3053dd30eb3074746a3204ecd20e8 to your computer and use it in GitHub Desktop.
Recovery script to load Toradex Easy Installer (Tezi) images from Mac OS
#!/bin/bash
# Download Tezi from https://developer.toradex.com/easy-installer/toradex-easy-installer/download-tezi#latest-release
# Unzip it, copy this script to the unzipped directory and run as `bash recovery-mac.sh`, following the usual way to
# put your board in recovery mode
# ask for the password early
sudo true
DFU_UTIL=$(which dfu-util 2>/dev/null)
UUU_UTIL=$(which uuu 2>/dev/null)
if ! command -v dfu-util > /dev/null; then
echo "Error: uuu is not installed. Please install `uuu` using brew (https://brew.sh/) before running this script."
exit 1
fi
if ! command -v uuu > /dev/null; then
echo "Error: dfu-util is not installed. Please install `uuu` using brew (https://brew.sh/) before running this script."
exit 1
fi
if ! brew ls --versions libusb > /dev/null; then
echo "Error: libusb is not installed. Please install 'libusb' using brew (https://brew.sh/) before running this script."
exit 1
fi
# USB DFU device vendor and product ID used in the boot ROM, the R5 SPL and the A53 SPL
VID_PID_ROM="0451:6165"
VID_PID_R5="1b67:4000"
VID_PID_A53="1b67:4000"
# tiboot3.bin depends on the SoC type, GP or HS-FS
TIBOOT3_GP_BIN=tiboot3-am62x-gp-verdin.bin
TIBOOT3_HSFS_BIN=tiboot3-am62x-hs-fs-verdin.bin
wait_usb_device()
{
VID_PID=$1
while ! lsusb -d $VID_PID
do
sleep 1
done
}
# set TIBOOT3_BIN variable according to the SoC type (GP or HF-FS)
select_tiboot3_bin()
{
local soc_type
local tmp_dir
local soc_id_bin
wait_usb_device $VID_PID_ROM
tmp_dir=$(mktemp -d) || exit 1
soc_id_bin=$tmp_dir/SocId.bin
sudo $DFU_UTIL -R -a SocId --device $VID_PID_ROM -U $soc_id_bin
soc_type=$(dd if=$soc_id_bin bs=1 count=4 skip=20 2>/dev/null)
if [[ "$soc_type" == *"GP"* ]]
then
TIBOOT3_BIN=$TIBOOT3_GP_BIN
else
TIBOOT3_BIN=$TIBOOT3_HSFS_BIN
fi
rm -rf $tmp_dir
}
# select correct tiboot3.bin depending on SoC type
select_tiboot3_bin
# load boot binaries, boot script and tezi fitimage to RAM and boot U-Boot
wait_usb_device $VID_PID_ROM
sudo $DFU_UTIL -w -R -a bootloader --device $VID_PID_ROM -D $TIBOOT3_BIN
wait_usb_device $VID_PID_R5
sudo $DFU_UTIL -w -R -a tispl.bin --device $VID_PID_R5 -D tispl.bin
wait_usb_device $VID_PID_A53
sudo $DFU_UTIL -w -R -a u-boot.img --device $VID_PID_A53 -D u-boot.img-recoverytezi
# call uuu to download FIT
echo "Downloading Toradex Easy Installer..."
if [ "$1" = "-q" ]; then
sudo $UUU_UTIL recovery > /dev/null
else
sudo $UUU_UTIL recovery
fi
if [ $? != 0 ]; then
echo ""
printf "\033[31mDownloading Toradex Easy Installer failed...\033[0m\n";
exit 1
fi
printf "\033[32mSuccessfully downloaded Toradex Easy Installer.\033[0m\n\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment