1d67b0d97SEric Nelsonsetenv stdout serial,vga
2d67b0d97SEric Nelsonecho "check U-Boot" ;
3d67b0d97SEric Nelsonsetenv offset 0x400
4d67b0d97SEric Nelsonif ${fs}load ${dtype} ${disk}:1 12000000 u-boot.imx || ${fs}load ${dtype} ${disk}:1 12000000 u-boot.nopadding ; then
5d67b0d97SEric Nelson      echo "read $filesize bytes from SD card" ;
6d67b0d97SEric Nelson      if sf probe || sf probe || \
7d67b0d97SEric Nelson	 sf probe 1 27000000 || sf probe 1 27000000 ; then
8d67b0d97SEric Nelson	   echo "probed SPI ROM" ;
9d67b0d97SEric Nelson	   if sf read 0x12400000 $offset $filesize ; then
10d67b0d97SEric Nelson	       if cmp.b 0x12000000 0x12400000 $filesize ; then
11d67b0d97SEric Nelson		   echo "------- U-Boot versions match" ;
12d67b0d97SEric Nelson	       else
13d67b0d97SEric Nelson		   echo "Need U-Boot upgrade" ;
14d67b0d97SEric Nelson		   echo "Program in 5 seconds" ;
15d67b0d97SEric Nelson		   for n in 5 4 3 2 1 ; do
16d67b0d97SEric Nelson			echo $n ;
17d67b0d97SEric Nelson			sleep 1 ;
18d67b0d97SEric Nelson		   done
19d67b0d97SEric Nelson		   echo "erasing" ;
20*8f8b8949SEric Nelson		   sf erase 0 0xC0000 ;
21d67b0d97SEric Nelson		   # two steps to prevent bricking
22d67b0d97SEric Nelson		   echo "programming" ;
23d67b0d97SEric Nelson		   sf write 0x12000000 $offset $filesize ;
24d67b0d97SEric Nelson		   echo "verifying" ;
25d67b0d97SEric Nelson		   if sf read 0x12400000 $offset $filesize ; then
26d67b0d97SEric Nelson		       if cmp.b 0x12000000 0x12400000 $filesize ; then
27d67b0d97SEric Nelson			   while echo "---- U-Boot upgraded. reset" ; do
28d67b0d97SEric Nelson				sleep 120
29d67b0d97SEric Nelson			   done
30d67b0d97SEric Nelson		       else
31d67b0d97SEric Nelson			   echo "Read verification error" ;
32d67b0d97SEric Nelson		       fi
33d67b0d97SEric Nelson		   else
34d67b0d97SEric Nelson			echo "Error re-reading EEPROM" ;
35d67b0d97SEric Nelson		   fi
36d67b0d97SEric Nelson	       fi
37d67b0d97SEric Nelson	   else
38d67b0d97SEric Nelson	       echo "Error reading boot loader from EEPROM" ;
39d67b0d97SEric Nelson	   fi
40d67b0d97SEric Nelson      else
41d67b0d97SEric Nelson	   echo "Error initializing EEPROM" ;
42d67b0d97SEric Nelson      fi ;
43d67b0d97SEric Nelsonelse
44d67b0d97SEric Nelson     echo "No U-Boot image found on SD card" ;
45d67b0d97SEric Nelsonfi
46