psb.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. i.MX7D/i.MX8MM SRC_GPR10 PERSIST_SECONDARY_BOOT for bootloader A/B switching
  2. ============================================================================
  3. Introduction
  4. ------------
  5. Since at least iMX53 until iMX8MM, it is possible to have two copies of
  6. bootloader in SD/eMMC and switch between them. The switch is triggered
  7. either by the BootROM in case the bootloader image is faulty OR can be
  8. enforced by the user.
  9. Operation
  10. ---------
  11. #. Upon Power-On Reset (POR)
  12. - SRC_GPR10 bit PERSIST_SECONDARY_BOOT is set to 0
  13. - BootROM attempts to start bootloader A-copy
  14. - if A-copy valid
  15. - BootROM starts A-copy
  16. - END
  17. - if A-copy NOT valid
  18. - BootROM sets SRC_GPR10 bit PERSIST_SECONDARY_BOOT to 1
  19. - BootROM triggers WARM reset, GOTO 1)
  20. - END
  21. #. Upon COLD Reset
  22. - GOTO 1)
  23. - END
  24. #. Upon WARM Reset
  25. - SRC_GPR10 bit PERSIST_SECONDARY_BOOT is retained
  26. - if SRC_GPR10 bit PERSIST_SECONDARY_BOOT is 0
  27. - BootROM attempts to start bootloader A-copy
  28. - if A-copy valid
  29. - BootROM starts A-copy
  30. - END
  31. - if A-copy NOT valid
  32. - BootROM sets SRC_GPR10 bit PERSIST_SECONDARY_BOOT to 1
  33. - BootROM triggers WARM reset. GOTO 1.3)
  34. - END
  35. - if SRC_GPR10 bit PERSIST_SECONDARY_BOOT is 1
  36. - BootROM attempts to start bootloader B-copy
  37. - if B-copy valid
  38. - BootROM starts B-copy
  39. - END
  40. - if B-copy NOT valid
  41. - System hangs
  42. - END
  43. Setup
  44. -----
  45. The bootloader A-copy must be placed at predetermined offset in SD/eMMC. The
  46. bootloader B-copy area offset is determined by an offset stored in Secondary
  47. Image Table (SIT). The SIT must be placed at predetermined offset in SD/eMMC.
  48. The following table contains offset of SIT, bootloader A-copy and recommended
  49. bootloader B-copy offset. The offsets are in 512 Byte sector units (that is
  50. offset 0x1 means 512 Bytes from the start of SD/eMMC card data partition).
  51. For details on the addition of two numbers in recommended B-copy offset, see
  52. SIT format below.
  53. +----------+-----------------------------+--------------------+-----------------------+-----------------------------+
  54. | SoC | Boot Device Type | SIT offset (fixed) | A-copy offset (fixed) | B-copy offset (recommended) |
  55. +----------+-----------------------------+--------------------+-----------------------+-----------------------------+
  56. | iMX7D | | 0x1 | 0x2 | 0x800+0x2 |
  57. +----------+-----------------------------+--------------------+-----------------------+-----------------------------+
  58. | iMX8MM | SD/eSD/MMC/eMMC normal boot | 0x41 | 0x42 | 0x1000+0x42 |
  59. +----------+-----------------------------+--------------------+-----------------------+-----------------------------+
  60. | iMX8MM | eMMC Fast boot fuse blown | 0x1 | 0x2 | 0x1000+0x2 |
  61. +----------+-----------------------------+--------------------+-----------------------+-----------------------------+
  62. SIT format
  63. ~~~~~~~~~~
  64. SIT is a 20 byte long structure containing of 5 32-bit words. Those encode
  65. bootloader B-copy area offset (called "firstSectorNumber"), magic value
  66. (called "tag") that is always 0x00112233, and three unused words set to 0.
  67. SIT is documented in [1]_ and [2]_. Example SIT are below::
  68. $ hexdump -vC sit-mx7d.bin
  69. 00000000 00 00 00 00
  70. 00000004 00 00 00 00
  71. 00000008 33 22 11 00 <--- This is the "tag"
  72. 0000000c 00 08 00 00 <--- This is the "firstSectorNumber"
  73. 00000010 00 00 00 00
  74. $ hexdump -vC sit-mx8mm.bin
  75. 00000000 00 00 00 00
  76. 00000004 00 00 00 00
  77. 00000008 33 22 11 00 <--- This is the "tag"
  78. 0000000c 00 10 00 00 <--- This is the "firstSectorNumber"
  79. 00000010 00 00 00 00
  80. B-copy area offset ("firstSectorNumber") is offset, in units of 512 Byte
  81. sectors, that is added to the start of boot media when switching between
  82. A-copy and B-copy. For A-copy, this offset is 0x0. For B-copy, this offset
  83. is determined by SIT (e.g. if firstSectorNumber is 0x1000 as it is above
  84. in sit-mx8mm.bin, then the B-copy offset is 0x1000 sectors = 2 MiB).
  85. Bootloader A-copy (e.g. u-boot.imx or flash.bin) is placed at fixed offset
  86. from A-copy area offset (e.g. 0x2 sectors from sector 0x0 for iMX7D, which
  87. means u-boot.imx A-copy must be written to sector 0x2).
  88. The same applies to bootloader B-copy, which is placed at fixed offset from
  89. B-copy area offset determined by SIT (e.g. 0x2 sectors from sector 0x800 [see
  90. sit-mx7d.bin example above, this can be changed in SIT firstSectorNumber] for
  91. iMX7D, which means u-boot.imx B-copy must be written to sector 0x802)
  92. **WARNING:**
  93. B-copy area offset ("firstSectorNumber") is NOT equal to bootloader
  94. (image, which is u-boot.imx or flash.bin) B-copy offset.
  95. To generate SIT, use for example the following bourne shell printf command::
  96. $ printf '\x0\x0\x0\x0\x0\x0\x0\x0\x33\x22\x11\x00\x00\x08\x00\x00\x0\x0\x0\x0' > sit-mx7d.bin
  97. $ printf '\x0\x0\x0\x0\x0\x0\x0\x0\x33\x22\x11\x00\x00\x10\x00\x00\x0\x0\x0\x0' > sit-mx8mm.bin
  98. Write bootloader A/B copy and SIT to SD/eMMC
  99. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100. Examples of writing SIT and two copies of bootloader to SD or eMMC:
  101. - iMX8MM, SD card at /dev/sdX, Linux command line
  102. ::
  103. $ dd if=sit-mx8mm.bin of=/dev/sdX bs=512 seek=65
  104. $ dd if=flash.bin of=/dev/sdX bs=512 seek=66
  105. $ dd if=flash.bin of=/dev/sdX bs=512 seek=4162
  106. - iMX8MM, eMMC 1 data partition, U-Boot command line
  107. ::
  108. => mmc partconf 1 0 0 0
  109. => dhcp ${loadaddr} sit-mx8mm.bin
  110. => mmc dev 1
  111. => mmc write ${loadaddr} 0x41 0x1
  112. => dhcp ${loadaddr} flash.bin
  113. => setexpr blkcnt ${filesize} + 0x1ff && setexpr blkcnt ${blkcnt} / 0x200
  114. => mmc dev 1
  115. => mmc write ${loadaddr} 0x42 ${blkcnt}
  116. => mmc write ${loadaddr} 0x1042 ${blkcnt}
  117. WARM reset into B-copy using WDT
  118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. To perform a reboot into B-copy, the PERSIST_SECONDARY_BOOT must be set
  120. in SRC_GPR10 register. Example on iMX8MM::
  121. => mw 0x30390098 0x40000000
  122. A WARM reset can be triggered using WDT as follows::
  123. => mw.w 0x30280000 0x25
  124. References
  125. ----------
  126. .. [1] i.MX 7Dual Applications Processor Reference Manual, Rev. 1, 01/2018 ; section 6.6.5.3.5 Redundant boot support for expansion device
  127. .. [2] i.MX 8M Mini Applications Processor Reference Manual, Rev. 3, 11/2020 ; section 6.1.5.4.5 Redundant boot support for expansion device