2
1

upgrade.cmd 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. if itest.s a$uboot_defconfig == a; then
  2. echo "Please set uboot_defconfig to the appropriate value"
  3. exit
  4. fi
  5. offset=0x400
  6. erase_size=0xC0000
  7. qspi_offset=0x0
  8. a_base=0x12000000
  9. block_size=0x200
  10. if itest.s x51 == "x${imx_cpu}"; then
  11. a_base=0x92000000
  12. elif itest.s x53 == "x${imx_cpu}"; then
  13. a_base=0x72000000
  14. elif itest.s x6SX == "x${imx_cpu}" || itest.s x7D == "x${imx_cpu}"; then
  15. a_base=0x82000000
  16. elif itest.s x8MQ == "x${imx_cpu}"; then
  17. a_base=0x42000000
  18. offset=0x8400
  19. fi
  20. qspi_match=1
  21. setexpr a_qspi1 ${a_base}
  22. setexpr a_qspi2 ${a_qspi1} + 0x400000
  23. setexpr a_uImage1 ${a_qspi1} + 0x400
  24. setexpr a_uImage2 ${a_qspi2} + 0x400
  25. setexpr a_script ${a_base}
  26. setenv stdout serial,vga
  27. if itest.s "x${sfname}" == "x" ; then
  28. # U-Boot resides in (e)MMC
  29. if itest.s "x${env_dev}" == "x" || itest.s "x${env_part}" == "x"; then
  30. echo "Please set env_dev/part to the appropriate values"
  31. exit
  32. fi
  33. # Load bootloader binary for this board
  34. if ${fs}load ${devtype} ${devnum}:${distro_bootpart} ${a_uImage1} u-boot.$uboot_defconfig ; then
  35. else
  36. echo "File u-boot.$uboot_defconfig not found on SD card" ;
  37. exit
  38. fi
  39. # Compute block count for filesize and offset
  40. setexpr cntoffset ${offset} / ${block_size}
  41. setexpr cntfile ${filesize} / ${block_size}
  42. # Add 1 in case the $filesize is not a multiple of $block_size
  43. setexpr cntfile ${cntfile} + 1
  44. # Select media partition (if different from main partition)
  45. mmc dev ${env_dev} ${env_part}
  46. # Read and compare current U-Boot
  47. mmc read ${a_uImage2} ${cntoffset} ${cntfile}
  48. if cmp.b ${a_uImage1} ${a_uImage2} ${filesize} ; then
  49. echo "------- U-Boot versions match" ;
  50. exit ;
  51. fi
  52. echo "Need U-Boot upgrade" ;
  53. echo "Program in 5 seconds" ;
  54. for n in 5 4 3 2 1 ; do
  55. echo $n ;
  56. sleep 1 ;
  57. done
  58. mmc write ${a_uImage1} ${cntoffset} ${cntfile}
  59. # Make sure to boot from the proper partition
  60. if itest ${env_part} != 0 ; then
  61. mmc partconf ${env_dev} 1 ${env_part} 0
  62. fi
  63. # Switch back to main eMMC partition (to avoid confusion)
  64. mmc dev ${env_dev}
  65. else
  66. # U-Boot resides in NOR flash
  67. if sf probe || sf probe || sf probe 1 27000000 || sf probe 1 27000000 ; then
  68. echo "probed SPI ROM" ;
  69. else
  70. echo "Error initializing EEPROM"
  71. exit
  72. fi
  73. if itest.s "x${sfname}" == "xat45db041d" ; then
  74. erase_size=0x7e000
  75. fi
  76. if itest.s x7D == "x${imx_cpu}"; then
  77. echo "check qspi parameter block" ;
  78. if ${fs}load ${devtype} ${devnum}:${distro_bootpart} ${a_qspi1} qspi-${sfname}.${uboot_defconfig} ; then
  79. else
  80. echo "parameter file qspi-${sfname}.${uboot_defconfig} not found on SD card"
  81. exit
  82. fi
  83. if itest ${filesize} != 0x200 ; then
  84. echo "------- qspi-${sfname}.${uboot_defconfig} 0x${filesize} != 0x200 bytes" ;
  85. exit
  86. fi
  87. setexpr a_marker ${a_qspi1} + 0x1fc
  88. if itest *${a_marker} != c0ffee01 ; then
  89. echo "------- qspi-${sfname}.${uboot_defconfig} c0ffee01 marker missing" ;
  90. exit
  91. fi
  92. if sf read ${a_qspi2} ${qspi_offset} 0x200 ; then
  93. else
  94. echo "Error reading qspi parameter from EEPROM"
  95. exit
  96. fi
  97. if cmp.b ${a_qspi1} ${a_qspi2} 0x200 ; then
  98. echo "------- qspi parameters match"
  99. else
  100. echo "------- qspi parameters mismatch"
  101. qspi_match=0
  102. fi
  103. fi
  104. echo "check U-Boot" ;
  105. if ${fs}load ${devtype} ${devnum}:${distro_bootpart} ${a_uImage1} u-boot.$uboot_defconfig ; then
  106. else
  107. echo "File u-boot.$uboot_defconfig not found on SD card" ;
  108. exit
  109. fi
  110. echo "read $filesize bytes from SD card" ;
  111. if sf read ${a_uImage2} $offset $filesize ; then
  112. else
  113. echo "Error reading boot loader from EEPROM" ;
  114. exit
  115. fi
  116. if cmp.b ${a_uImage1} ${a_uImage2} $filesize ; then
  117. echo "------- U-Boot versions match" ;
  118. if itest.s "${qspi_match}" == "1" ; then
  119. echo "------- upgrade not needed" ;
  120. if itest.s "x" != "x${next}" ; then
  121. if ${fs}load ${devtype} ${devnum}:${distro_bootpart} ${a_script} ${next} ; then
  122. source ${a_script}
  123. else
  124. echo "${next} not found on SD card"
  125. fi
  126. fi
  127. exit
  128. fi
  129. erase_size=0x1000
  130. if itest.s xMX25L6405D == "x${sfname}"; then
  131. erase_size=0x10000
  132. fi
  133. setexpr filesize ${erase_size} - ${offset}
  134. fi
  135. echo "Need U-Boot upgrade" ;
  136. echo "Program in 5 seconds" ;
  137. for n in 5 4 3 2 1 ; do
  138. echo $n ;
  139. sleep 1 ;
  140. done
  141. echo "erasing" ;
  142. sf erase 0 ${erase_size} ;
  143. # two steps to prevent bricking
  144. echo "programming" ;
  145. setexpr a1 ${a_uImage1} + 0x400
  146. setexpr o1 ${offset} + 0x400
  147. setexpr s1 ${filesize} - 0x400
  148. sf write ${a1} ${o1} ${s1} ;
  149. sf write ${a_uImage1} $offset 0x400 ;
  150. if itest.s x7D == "x${imx_cpu}"; then
  151. sf write ${a_qspi1} ${qspi_offset} 0x200
  152. fi
  153. echo "verifying" ;
  154. if sf read ${a_uImage2} $offset $filesize ; then
  155. else
  156. echo "Error re-reading EEPROM" ;
  157. exit
  158. fi
  159. if cmp.b ${a_uImage1} ${a_uImage2} $filesize ; then
  160. else
  161. echo "Read verification error" ;
  162. exit
  163. fi
  164. if itest.s x7D == "x${imx_cpu}"; then
  165. if sf read ${a_qspi2} ${qspi_offset} 0x200 ; then
  166. else
  167. echo "Error re-reading qspi" ;
  168. exit
  169. fi
  170. if cmp.b ${a_qspi1} ${a_qspi2} 0x200 ; then
  171. else
  172. echo "qspi parameter block verification error" ;
  173. exit
  174. fi
  175. fi
  176. if itest.s "x" != "x${next}" ; then
  177. if ${fs}load ${devtype} ${devnum}:${distro_bootpart} ${a_script} ${next} ; then
  178. source ${a_script}
  179. else
  180. echo "${next} not found on ${devtype} ${devnum}:${distro_bootpart}"
  181. fi
  182. fi
  183. fi
  184. while echo "---- U-Boot upgraded. Please reset the board" ; do
  185. sleep 120
  186. done