upgrade.cmd 5.4 KB

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