]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/host-tools.git/blob - k3-bootswitch/dfu-boot.sh
am65xx-evm: Add prebuilt binaries
[glsdk/host-tools.git] / k3-bootswitch / dfu-boot.sh
1 #!/bin/bash
2 # Utility script to select the bootmode from command line
3 # Author: Nikhil Devshatwar
5 # No need to change anything below this line
6 UMS_part1=/dev/disk/by-id/usb-Linux_UMS_disk*part1
7 UMS_part2=/dev/disk/by-id/usb-Linux_UMS_disk*part2
8 SCRIPT=$(readlink -f $0)
9 SCRIPTPATH=`dirname $SCRIPT`
10 user=`logname`
12 usage()
13 {
14         echo
15         echo "dfu-boot.sh => Utility script to select bootmode and mount MMC to PC"
16         echo "Usage:"
17         echo "  sudo ./dfu-boot.sh PLATFORM --mount DEV | --bootmode MODE"
18         echo "    PLATFORM: Either of --j721e-evm or --am65xx-evm"
19         echo "    DEV: specify the device to mount => 1 for MMC, 0 for eMMC"
20         echo "    MODE: specify the bootmode to use"
21 }
23 init() {
24 board=$1
25         # Customize this as required
26         if [ "$board" = "j721e-evm" ]; then
27                 uart_dev=/dev/ttyUSB0
28                 switch=0
29         elif [ "$board" = "am65xx-evm" ]; then
30                 uart_dev=/dev/ttyUSB4
31                 switch=3
32         else
33                 echo "Invalid board"
34                 usage
35                 exit 1
36         fi
38         prebuilt=$SCRIPTPATH/bin/$board
39         boot_select=$SCRIPTPATH/boot_select/$board
40 }
42 toggle_power()
43 {
44 switch=$1
45         echo "    >>>> Toggling phidget..."
46         (phidget-switch $switch 0 && sleep 0.5 && phidget-switch $switch 1 && sleep 0.1) >/dev/null 2>&1
47         if [ $? -ne 0 ]; then
48                 echo -n "ERROR: phidget not found, Reboot manually and press enter.. "
49                 read DUMMY
50         fi
51 }
53 # Bootloader takes time to initialize
54 # wait till PC detects a dfu device
55 wait_till_ready() {
56 msg=$1
57         for i in `seq 30`; do
58                 dfu-util -l | grep "Found DFU" >/dev/null 2>&1
59                 if [ $? -eq "0" ]; then
60                         >&2 echo "    >>>> dfu ready $msg after $i tries"
61                         return
62                 fi
63                 sleep 0.2
64         done
65         >&2 echo "    >>>> ERROR: Timeout waiting for dfu"
66         >&2 echo "    >>>>        Make sure to connect Type-C cable to EVM and host machine"
67         >&2 echo "    >>>>        Bootswitch settings fot DFU boot:"
68         >&2 echo "    SW8 = 1000 0000    SW9 = 0010 0000    SW3 = 0101 00 1010"
69         exit 1
70 }
72 # Use dfu to send prebuilt binaries till you get to the
73 # Cortex-A u-boot prompt
74 boot_till_uboot() {
75         wait_till_ready "for tiboot3.bin"
76         2>&1 dfu-util -R -a bootloader -D $prebuilt/tiboot3.bin
77         wait_till_ready "for sysfw.itb"
78         2>&1 dfu-util -R -a sysfw.itb -D $prebuilt/sysfw.itb
79         wait_till_ready "for tispl.bin"
80         2>&1 dfu-util -R -a tispl.bin -D $prebuilt/tispl.bin
81         wait_till_ready "for u-boot.img"
82         2>&1 dfu-util -R -a u-boot.img -D $prebuilt/u-boot.img
83 }
85 # Detect and mount the partitions
86 try_mount() {
87 uart_dev=$1
88 mdev=$2
89         for i in `seq 1 100`; do
90                 echo "ums 0 mmc $mdev" > $uart_dev
91                 sleep 0.1
92                 if [ -b $UMS_part1 ] && [ -b $UMS_part2 ]; then
93                         mkdir -p /media/$user/UMS-boot
94                         mkdir -p /media/$user/UMS-rootfs
95                         mount $UMS_part1 /media/$user/UMS-boot
96                         mount $UMS_part2 /media/$user/UMS-rootfs
97                         echo "    >>>> Mounted partions at /media/$user/UMS-boot and /media/$user/UMS-rootfs"
98                         return
99                 fi
100         done
101         >&2 echo "    >>>> ERROR: Could not find partitions $UMS_part1"
102         exit 1
105 # Send a boot_select binary
106 change_bootmode() {
107 bootmode=$1
108         if [ ! -f $boot_select/spl.$bootmode ]; then
109                 echo "Invalid bootmode $bootmode"
110                 options=`ls $boot_select/spl* | awk -F"." 'BEGIN{ORS=" "} { print $2 }'`
111                 echo "Supported bootmodes for $board are: $options"
112                 exit 1
113         fi
115         wait_till_ready
116         echo "    >>>> Selecting bootmode: $bootmode"
117         dfu-util -R -a bootloader -D $boot_select/spl.$bootmode >/dev/null 2>&1
118         if [ $? -eq 0 ]; then
119                 echo "    >>>> SUCCESS"
120         else
121                 echo "    >>>> FAILED"
122         fi
125 # Main script starts from here
126 if [ `whoami` != "root" ]; then
127         echo "This script should be called with sudo!!"
128         usage
129         exit 1
130 fi
132 while [[ $# -gt 0 ]]
133 do
134 case $1 in
135         --j7|--j721e|--j721e-evm)
136                 init "j721e-evm"
137                 shift
138                 ;;
139         --am6|--am654|--am65x-evm|--am654-idk|--am65xx-evm)
140                 init "am65xx-evm"
141                 shift
142                 ;;
143         -m|--mount)
144                 mdev=$2
145                 shift
146                 shift
147                 ;;
148         -b|--bootmode)
149                 bootmode=$2
150                 shift
151                 shift
152                 ;;
153         -h|--help)
154                 usage
155                 exit 0
156                 ;;
157         *)
158                 echo "Invalid argument $1"
159                 usage
160                 exit 1
161                 ;;
162 esac
163 done
165 init $board
166 if [ ! -z $bootmode ]; then
167         # Reboot the board in specified bootmode
168         toggle_power $switch
169         change_bootmode $bootmode
171 elif [ ! -z $mdev ]; then
172         # Reboot the board and mount the specified device
173         toggle_power $switch
174         boot_till_uboot >/dev/null
175         try_mount $uart_dev $mdev
176 else
177         echo "Invalid usage!!"
178         usage
179 fi