README.mxc_hab 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 1. High Assurance Boot (HAB) for i.MX CPUs
  2. ------------------------------------------
  3. To enable the authenticated or encrypted boot mode of U-Boot, it is
  4. required to set the proper configuration for the target board. This
  5. is done by adding the following configuration in the defconfig file:
  6. CONFIG_SECURE_BOOT=y
  7. In addition, the U-Boot image to be programmed into the
  8. boot media needs to be properly constructed, i.e. it must contain a
  9. proper Command Sequence File (CSF).
  10. The CSF itself is generated by the i.MX High Assurance Boot Reference
  11. Code Signing Tool.
  12. https://www.nxp.com/webapp/sps/download/license.jsp?colCode=IMX_CST_TOOL
  13. More information about the CSF and HAB can be found in the AN4581.
  14. https://www.nxp.com/docs/en/application-note/AN4581.pdf
  15. We don't want to explain how to create a PKI tree or SRK table as
  16. this is well explained in the Application Note.
  17. 2. Secure Boot on non-SPL targets
  18. ---------------------------------
  19. On non-SPL targets a singe U-Boot binary is generated, mkimage will
  20. output additional information about "HAB Blocks" which can be used
  21. in the CST to authenticate the U-Boot image (entries in the CSF file).
  22. Image Type: Freescale IMX Boot Image
  23. Image Ver: 2 (i.MX53/6 compatible)
  24. Data Size: 327680 Bytes = 320.00 kB = 0.31 MB
  25. Load Address: 177ff420
  26. Entry Point: 17800000
  27. HAB Blocks: 0x177ff400 0x00000000 0x0004dc00
  28. ^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^
  29. | | |
  30. | | ----- (1)
  31. | |
  32. | ---------------- (2)
  33. |
  34. --------------------------- (3)
  35. (1) Size of area in file u-boot-dtb.imx to sign
  36. This area should include the IVT, the Boot Data the DCD
  37. and U-Boot itself.
  38. (2) Start of area in u-boot-dtb.imx to sign
  39. (3) Start of area in RAM to authenticate
  40. CONFIG_SECURE_BOOT currently enables only an additional command
  41. 'hab_status' in U-Boot to retrieve the HAB status and events. This
  42. can be useful while developing and testing HAB.
  43. Commands to generate a signed U-Boot using i.MX HAB CST tool:
  44. # Compile CSF and create signature
  45. cst --o csf-u-boot.bin --i command_sequence_uboot.csf
  46. # Append compiled CSF to Binary
  47. cat u-boot-dtb.imx csf-u-boot.bin > u-boot-signed.imx
  48. 3. Secure Boot on SPL targets
  49. -----------------------------
  50. This version of U-Boot is able to build a signable version of the SPL
  51. as well as a signable version of the U-Boot image. The signature can
  52. be verified through High Assurance Boot (HAB).
  53. After building, you need to create a command sequence file and use
  54. i.MX HAB Code Signing Tool to sign both binaries. After creation,
  55. the mkimage tool outputs the required information about the HAB Blocks
  56. parameter for the CSF. During the build, the information is preserved
  57. in log files named as the binaries. (SPL.log and u-boot-ivt.log).
  58. Example Output of the SPL (imximage) creation:
  59. Image Type: Freescale IMX Boot Image
  60. Image Ver: 2 (i.MX53/6/7 compatible)
  61. Mode: DCD
  62. Data Size: 61440 Bytes = 60.00 kB = 0.06 MB
  63. Load Address: 00907420
  64. Entry Point: 00908000
  65. HAB Blocks: 0x00907400 0x00000000 0x0000cc00
  66. Example Output of the u-boot-ivt.img (firmware_ivt) creation:
  67. Image Name: U-Boot 2016.11-rc1-31589-g2a4411
  68. Created: Sat Nov 5 21:53:28 2016
  69. Image Type: ARM U-Boot Firmware with HABv4 IVT (uncompressed)
  70. Data Size: 352192 Bytes = 343.94 kB = 0.34 MB
  71. Load Address: 17800000
  72. Entry Point: 00000000
  73. HAB Blocks: 0x177fffc0 0x0000 0x00054020
  74. # Compile CSF and create signature
  75. cst --o csf-u-boot.bin --i command_sequence_uboot.csf
  76. cst --o csf-SPL.bin --i command_sequence_spl.csf
  77. # Append compiled CSF to Binary
  78. cat SPL csf-SPL.bin > SPL-signed
  79. cat u-boot-ivt.img csf-u-boot.bin > u-boot-signed.img
  80. These two signed binaries can be used on an i.MX in closed
  81. configuration when the according SRK Table Hash has been flashed.
  82. 4. Setup U-Boot Image for Encrypted Boot
  83. ----------------------------------------
  84. An authenticated U-Boot image is used as starting point for
  85. Encrypted Boot. The image is encrypted by i.MX Code Signing
  86. Tool (CST). The CST replaces only the image data of
  87. u-boot-dtb.imx with the encrypted data. The Initial Vector Table,
  88. DCD, and Boot data, remains in plaintext.
  89. The image data is encrypted with a Encryption Key (DEK).
  90. Therefore, this key is needed to decrypt the data during the
  91. booting process. The DEK is protected by wrapping it in a Blob,
  92. which needs to be appended to the U-Boot image and specified in
  93. the CSF file.
  94. The DEK blob is generated by an authenticated U-Boot image with
  95. the dek_blob cmd enabled. The image used for DEK blob generation
  96. needs to have the following configurations enabled in Kconfig:
  97. CONFIG_SECURE_BOOT=y
  98. CONFIG_CMD_DEKBLOB=y
  99. Note: The encrypted boot feature is only supported by HABv4 or
  100. greater.
  101. The dek_blob command then can be used to generate the DEK blob of
  102. a DEK previously loaded in memory. The command is used as follows:
  103. dek_blob <DEK address> <Output Address> <Key Size in Bits>
  104. example: dek_blob 0x10800000 0x10801000 192
  105. The resulting DEK blob then is used to construct the encrypted
  106. U-Boot image. Note that the blob needs to be transferred back
  107. to the host.Then the following commands are used to construct
  108. the final image.
  109. cat u-boot-dtb.imx csf-u-boot.bin > u-boot-signed.imx
  110. objcopy -I binary -O binary --pad-to <blob_dst> --gap-fill=0x00 \
  111. u-boot-signed.imx u-boot-signed-pad.bin
  112. cat u-boot-signed-pad.imx DEK_blob.bin > u-boot-encrypted.imx
  113. NOTE: u-boot-signed.bin needs to be padded to the value
  114. equivalent to the address in which the DEK blob is specified
  115. in the CSF.