upgrade.cmd 5.6 KB

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