warp7.rst 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. NXP i.MX7 WaRP7
  2. ===============
  3. The Trusted Firmware-A port for the i.MX7Solo WaRP7 implements BL2 at EL3.
  4. The i.MX7S contains a BootROM with a High Assurance Boot (HAB) functionality.
  5. This functionality provides a mechanism for establishing a root-of-trust from
  6. the reset vector to the command-line in user-space.
  7. Boot Flow
  8. ---------
  9. BootROM --> TF-A BL2 --> BL32(OP-TEE) --> BL33(U-Boot) --> Linux
  10. In the WaRP7 port we encapsulate OP-TEE, DTB and U-Boot into a FIP. This FIP is
  11. expected and required
  12. Build Instructions
  13. ------------------
  14. We need to use a file generated by u-boot in order to generate a .imx image the
  15. BootROM will boot. It is therefore _required_ to build u-boot before TF-A and
  16. furthermore it is _recommended_ to use the mkimage in the u-boot/tools directory
  17. to generate the TF-A .imx image.
  18. U-Boot
  19. ~~~~~~
  20. https://git.linaro.org/landing-teams/working/mbl/u-boot.git
  21. .. code:: shell
  22. git checkout -b rms-atf-optee-uboot linaro-mbl/rms-atf-optee-uboot
  23. make warp7_bl33_defconfig;
  24. make u-boot.imx arch=ARM CROSS_COMPILE=arm-linux-gnueabihf-
  25. OP-TEE
  26. ~~~~~~
  27. https://github.com/OP-TEE/optee_os.git
  28. .. code:: shell
  29. make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- PLATFORM=imx PLATFORM_FLAVOR=mx7swarp7 ARCH=arm CFG_PAGEABLE_ADDR=0 CFG_DT_ADDR=0x83000000 CFG_NS_ENTRY_ADDR=0x87800000
  30. TF-A
  31. ~~~~
  32. https://github.com/ARM-software/arm-trusted-firmware.git
  33. The following commands assume that a directory exits in the top-level TFA build
  34. directory "fiptool_images". "fiptool_images" contains
  35. - u-boot.bin
  36. The binary output from the u-boot instructions above
  37. - tee-header_v2.bin
  38. - tee-pager_v2.bin
  39. - tee-pageable_v2.bin
  40. Binary outputs from the previous OPTEE build steps
  41. It is also assumed copy of mbedtls is available on the path path ../mbedtls
  42. https://github.com/ARMmbed/mbedtls.git
  43. At the time of writing HEAD points to 0592ea772aee48ca1e6d9eb84eca8e143033d973
  44. .. code:: shell
  45. mkdir fiptool_images
  46. cp /path/to/optee/out/arm-plat-imx/core/tee-header_v2.bin fiptool_images
  47. cp /path/to/optee/out/arm-plat-imx/core/tee-pager_v2.bin fiptool_images
  48. cp /path/to/optee/out/arm-plat-imx/core/tee-pageable_v2.bin fiptool_images
  49. make CROSS_COMPILE=${CROSS_COMPILE} PLAT=warp7 ARCH=aarch32 ARM_ARCH_MAJOR=7 \
  50. ARM_CORTEX_A7=yes AARCH32_SP=optee PLAT_WARP7_UART=1 GENERATE_COT=1 \
  51. TRUSTED_BOARD_BOOT=1 USE_TBBR_DEFS=1 MBEDTLS_DIR=../mbedtls \
  52. NEED_BL32=yes BL32=fiptool_images/tee-header_v2.bin \
  53. BL32_EXTRA1=fiptool_images/tee-pager_v2.bin \
  54. BL32_EXTRA2=fiptool_images/tee-pageable_v2.bin \
  55. BL33=fiptool_images/u-boot.bin certificates all
  56. /path/to/u-boot/tools/mkimage -n /path/to/u-boot/u-boot.cfgout -T imximage -e 0x9df00000 -d ./build/warp7/debug/bl2.bin ./build/warp7/debug/bl2.bin.imx
  57. FIP
  58. ~~~
  59. .. code:: shell
  60. cp /path/to/uboot/u-boot.bin fiptool_images
  61. cp /path/to/linux/arch/boot/dts/imx7s-warp.dtb fiptool_images
  62. tools/cert_create/cert_create -n --rot-key "build/warp7/debug/rot_key.pem" \
  63. --tfw-nvctr 0 \
  64. --ntfw-nvctr 0 \
  65. --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \
  66. --tb-fw=build/warp7/debug/bl2.bin \
  67. --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt\
  68. --tos-fw fiptool_images/tee-header_v2.bin \
  69. --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \
  70. --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \
  71. --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \
  72. --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \
  73. --nt-fw fiptool_images/u-boot.bin \
  74. --nt-fw-cert fiptool_images/u-boot.bin.crt \
  75. --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \
  76. --hw-config fiptool_images/imx7s-warp.dtb
  77. tools/fiptool/fiptool create --tos-fw fiptool_images/tee-header_v2.bin \
  78. --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \
  79. --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \
  80. --nt-fw fiptool_images/u-boot.bin \
  81. --hw-config fiptool_images/imx7s-warp.dtb \
  82. --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \
  83. --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \
  84. --nt-fw-cert fiptool_images/u-boot.bin.crt \
  85. --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \
  86. --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \
  87. --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt warp7.fip
  88. Deploy Images
  89. -------------
  90. First place the WaRP7 into UMS mode in u-boot this should produce an entry in
  91. /dev like /dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0
  92. .. code:: shell
  93. => ums 0 mmc 0
  94. Next flash bl2.imx and warp7.fip
  95. bl2.imx is flashed @ 1024 bytes
  96. warp7.fip is flash @ 1048576 bytes
  97. .. code:: shell
  98. sudo dd if=bl2.bin.imx of=/dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0 bs=512 seek=2 conv=notrunc
  99. # Offset is 1MB 1048576 => 1048576 / 512 = 2048
  100. sudo dd if=./warp7.fip of=/dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0 bs=512 seek=2048 conv=notrunc
  101. Remember to umount the USB device pefore proceeding
  102. .. code:: shell
  103. sudo umount /dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0*
  104. Signing BL2
  105. -----------
  106. A further step is to sign BL2.
  107. The image_sign.sh and bl2_sign.csf files alluded to blow are available here.
  108. https://github.com/bryanodonoghue/atf-code-signing
  109. It is suggested you use this script plus the example CSF file in order to avoid
  110. hard-coding data into your CSF files.
  111. Download both "image_sign.sh" and "bl2_sign.csf" to your
  112. arm-trusted-firmware top-level directory.
  113. .. code:: shell
  114. #!/bin/bash
  115. SIGN=image_sign.sh
  116. TEMP=`pwd`/temp
  117. BL2_CSF=bl2_sign.csf
  118. BL2_IMX=bl2.bin.imx
  119. CST_PATH=/path/to/cst-2.3.2
  120. CST_BIN=${CST_PATH}/linux64/cst
  121. #Remove temp
  122. rm -rf ${TEMP}
  123. mkdir ${TEMP}
  124. # Generate IMX header
  125. /path/to/u-boot/tools/mkimage -n u-boot.cfgout.warp7 -T imximage -e 0x9df00000 -d ./build/warp7/debug/bl2.bin ./build/warp7/debug/bl2.bin.imx > ${TEMP}/${BL2_IMX}.log
  126. # Copy required items to $TEMP
  127. cp build/warp7/debug/bl2.bin.imx ${TEMP}
  128. cp ${CST_PATH}/keys/* ${TEMP}
  129. cp ${CST_PATH}/crts/* ${TEMP}
  130. cp ${BL2_CSF} ${TEMP}
  131. # Generate signed BL2 image
  132. ./${SIGN} image_sign_mbl_binary ${TEMP} ${BL2_CSF} ${BL2_IMX} ${CST_BIN}
  133. # Copy signed BL2 to top-level directory
  134. cp ${TEMP}/${BL2_IMX}-signed .
  135. cp ${BL2_RECOVER_CSF} ${TEMP}
  136. The resulting bl2.bin.imx-signed can replace bl2.bin.imx in the Deploy
  137. Images section above, once done.
  138. Suggested flow for verifying.
  139. 1. Followed all previous steps above and verify a non-secure ATF boot
  140. 2. Down the NXP Code Singing Tool
  141. 3. Generate keys
  142. 4. Program the fuses on your board
  143. 5. Replace bl2.bin.imx with bl2.bin.imx-signed
  144. 6. Verify inside u-boot that "hab_status" shows no events
  145. 7. Subsequently close your board.
  146. If you have HAB events @ step 6 - do not lock your board.
  147. To get a good over-view of generating keys and programming the fuses on the
  148. board read "High Assurance Boot for Dummies" by Boundary Devices.
  149. https://boundarydevices.com/high-assurance-boot-hab-dummies/