mx6_mx7_spl_secure_boot.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. +===============================================================+
  2. + i.MX6, i.MX7 U-Boot HABv4 Secure Boot guide for SPL targets +
  3. +===============================================================+
  4. 1. HABv4 secure boot process
  5. -----------------------------
  6. This document is an addendum of mx6_mx7_secure_boot.txt guide describing a
  7. step-by-step procedure on how to sign and securely boot an U-Boot image for
  8. SPL targets.
  9. Details about HAB can be found in the application note AN4581[1] and in the
  10. introduction_habv4.txt document.
  11. 1.1 Building a SPL target supporting secure boot
  12. -------------------------------------------------
  13. The U-Boot provides Second Program Loader (SPL) support which generates two
  14. final images, SPL and U-Boot proper. The HABv4 can be used to authenticate
  15. both binaries.
  16. Out of reset the ROM code authenticates the SPL which is responsible for
  17. initializing essential features such as DDR, UART, PMIC and clock
  18. enablement. Once the DDR is available, the SPL code loads the U-Boot proper
  19. image to its specific execution address and call the HAB APIs to extend the
  20. root of trust.
  21. The U-Boot provides support to secure boot configuration and also provide
  22. access to the HAB APIs exposed by the ROM vector table, the support is
  23. enabled by selecting the CONFIG_IMX_HAB option.
  24. When built with this configuration the U-Boot correctly pads the final SPL
  25. image by aligning to the next 0xC00 address, so the CSF signature data
  26. generated by CST can be concatenated to the image.
  27. The U-Boot also append an Image Vector Table (IVT) in the final U-Boot proper
  28. binary (u-boot-ivt.img) so it can be used by HAB API in a post ROM stage.
  29. The diagram below illustrate a signed SPL image layout:
  30. ------- +-----------------------------+ <-- *start
  31. ^ | Image Vector Table |
  32. | +-----------------------------+ <-- *boot_data
  33. | | Boot Data |
  34. | +-----------------------------+
  35. Signed | | Padding |
  36. Data | +-----------------------------+ <-- *entry
  37. | | |
  38. | | SPL |
  39. | | |
  40. | +-----------------------------+
  41. v | Padding |
  42. ------- +-----------------------------+ <-- *csf
  43. | |
  44. | Command Sequence File (CSF) |
  45. | |
  46. +-----------------------------+
  47. | Padding (optional) |
  48. +-----------------------------+
  49. The diagram below illustrate a signed u-boot-ivt.img image layout:
  50. ------- +-----------------------------+ <-- *load_address
  51. ^ | |
  52. | | |
  53. | | u-boot.img |
  54. Signed | | |
  55. Data | | |
  56. | +-----------------------------+
  57. | | Padding Next Boundary |
  58. | +-----------------------------+ <-- *ivt
  59. v | Image Vector Table |
  60. ------- +-----------------------------+ <-- *csf
  61. | |
  62. | Command Sequence File (CSF) |
  63. | |
  64. +-----------------------------+
  65. | Padding (optional) |
  66. +-----------------------------+
  67. 1.2 Enabling the secure boot support
  68. -------------------------------------
  69. The first step is to generate an U-Boot image supporting the HAB features
  70. mentioned above, this can be achieved by adding CONFIG_IMX_HAB to the
  71. build configuration:
  72. - Defconfig:
  73. CONFIG_IMX_HAB=y
  74. - Kconfig:
  75. ARM architecture -> Support i.MX HAB features
  76. 1.3 Creating the CSF description file
  77. --------------------------------------
  78. The CSF contains all the commands that the HAB executes during the secure
  79. boot. These commands instruct the HAB code on which memory areas of the image
  80. to authenticate, which keys to install, use and etc.
  81. CSF examples are available under doc/imx/habv4/csf_examples/ directory.
  82. Build logs containing the "Authenticate Data" parameters are available after
  83. the U-Boot build, the example below is a log for mx6sabresd_defconfig target:
  84. - SPL build log:
  85. $ cat SPL.log
  86. Image Type: Freescale IMX Boot Image
  87. Image Ver: 2 (i.MX53/6/7 compatible)
  88. Mode: DCD
  89. Data Size: 69632 Bytes = 68.00 KiB = 0.07 MiB
  90. Load Address: 00907420
  91. Entry Point: 00908000
  92. HAB Blocks: 0x00907400 0x00000000 0x0000ec00
  93. - u-boot-ivt.img build log:
  94. $ cat u-boot-ivt.img.log
  95. Image Name: U-Boot 2019.01-00003-g78ee492eb3
  96. Created: Mon Jan 14 17:58:10 2019
  97. Image Type: ARM U-Boot Firmware with HABv4 IVT (uncompressed)
  98. Data Size: 458688 Bytes = 447.94 KiB = 0.44 MiB
  99. Load Address: 17800000
  100. Entry Point: 00000000
  101. HAB Blocks: 0x177fffc0 0x0000 0x0006e020
  102. As explained in section above the SPL is first authenticated by the ROM code
  103. and the root of trust is extended to the U-Boot image, hence two CSF files are
  104. necessary to completely sign a bootloader image.
  105. In "Authenticate Data" CSF command users can copy and past the output
  106. addresses, the csf_uboot.txt can be used as example:
  107. - In csf_SPL.txt:
  108. Block = 0x00907400 0x00000000 0x0000ec00 "SPL"
  109. - In csf_uboot-ivt.txt:
  110. Block = 0x177fffc0 0x0000 0x0006e020 "u-boot-ivt.img"
  111. 1.4 Signing the images
  112. -----------------------
  113. The CST tool is used for singing the U-Boot binary and generating a CSF binary,
  114. users should input the CSF description file created in the step above and
  115. receive a CSF binary, which contains the CSF commands, SRK table, signatures
  116. and certificates.
  117. - Create SPL CSF binary file:
  118. $ ./cst -i csf_SPL.txt -o csf_SPL.bin
  119. - Append CSF signature to the end of SPL image:
  120. $ cat SPL csf_SPL.bin > SPL-signed
  121. - Create U-Boot proper CSF binary file:
  122. $ ./cst -i csf_uboot-ivt.txt -o csf_uboot-ivt.bin
  123. - Append CSF signature to the end of U-Boot proper image:
  124. $ cat u-boot-ivt.img csf_uboot-ivt.bin > u-boot-signed.img
  125. The bootloader is signed and can be flashed into the boot media.
  126. 1.5 Closing the device
  127. -----------------------
  128. The procedure for closing the device is similar as in Non-SPL targets, for a
  129. complete procedure please refer to section "1.5 Programming SRK Hash" in
  130. mx6_mx7_secure_boot.txt document available under doc/imx/habv4/guides/
  131. directory.
  132. References:
  133. [1] AN4581: "Secure Boot on i.MX 50, i.MX 53, i.MX 6 and i.MX 7 Series using
  134. HABv4" - Rev 2.