xref: /rk3399_ARM-atf/docs/plat/warp7.rst (revision ced1711297347f24fee45e75e73c7767507a0982)
1*24dba2b3SPaul BeesleyNXP i.MX7 WaRP7
2*24dba2b3SPaul Beesley===============
3b182a5d9SBryan O'Donoghue
4b182a5d9SBryan O'DonoghueThe Trusted Firmware-A port for the i.MX7Solo WaRP7 implements BL2 at EL3.
5b182a5d9SBryan O'DonoghueThe i.MX7S contains a BootROM with a High Assurance Boot (HAB) functionality.
6b182a5d9SBryan O'DonoghueThis functionality provides a mechanism for establishing a root-of-trust from
7b182a5d9SBryan O'Donoghuethe reset vector to the command-line in user-space.
8b182a5d9SBryan O'Donoghue
9b182a5d9SBryan O'DonoghueBoot Flow
10*24dba2b3SPaul Beesley---------
11b182a5d9SBryan O'Donoghue
12b182a5d9SBryan O'DonoghueBootROM --> TF-A BL2 --> BL32(OP-TEE) --> BL33(U-Boot) --> Linux
13b182a5d9SBryan O'Donoghue
14b182a5d9SBryan O'DonoghueIn the WaRP7 port we encapsulate OP-TEE, DTB and U-Boot into a FIP. This FIP is
15b182a5d9SBryan O'Donoghueexpected and required
16b182a5d9SBryan O'Donoghue
17*24dba2b3SPaul BeesleyBuild Instructions
18*24dba2b3SPaul Beesley------------------
19b182a5d9SBryan O'Donoghue
20b182a5d9SBryan O'DonoghueWe need to use a file generated by u-boot in order to generate a .imx image the
21b182a5d9SBryan O'DonoghueBootROM will boot. It is therefore _required_ to build u-boot before TF-A and
22b182a5d9SBryan O'Donoghuefurthermore it is _recommended_ to use the mkimage in the u-boot/tools directory
23b182a5d9SBryan O'Donoghueto generate the TF-A .imx image.
24b182a5d9SBryan O'Donoghue
25*24dba2b3SPaul BeesleyU-Boot
26*24dba2b3SPaul Beesley~~~~~~
27b182a5d9SBryan O'Donoghue
28b182a5d9SBryan O'Donoghuehttps://git.linaro.org/landing-teams/working/mbl/u-boot.git
29b182a5d9SBryan O'Donoghue
30b182a5d9SBryan O'Donoghue.. code:: shell
31b182a5d9SBryan O'Donoghue
32b182a5d9SBryan O'Donoghue    git checkout -b rms-atf-optee-uboot linaro-mbl/rms-atf-optee-uboot
33b182a5d9SBryan O'Donoghue    make warp7_bl33_defconfig;
34b182a5d9SBryan O'Donoghue    make u-boot.imx arch=ARM CROSS_COMPILE=arm-linux-gnueabihf-
35b182a5d9SBryan O'Donoghue
36*24dba2b3SPaul BeesleyOP-TEE
37*24dba2b3SPaul Beesley~~~~~~
38b182a5d9SBryan O'Donoghue
39b182a5d9SBryan O'Donoghuehttps://github.com/OP-TEE/optee_os.git
40b182a5d9SBryan O'Donoghue
41b182a5d9SBryan O'Donoghue.. code:: shell
42b182a5d9SBryan O'Donoghue
43b182a5d9SBryan O'Donoghue    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
44b182a5d9SBryan O'Donoghue
45*24dba2b3SPaul BeesleyTF-A
46*24dba2b3SPaul Beesley~~~~
4731e4c20dSBryan O'Donoghue
4831e4c20dSBryan O'Donoghuehttps://github.com/ARM-software/arm-trusted-firmware.git
4931e4c20dSBryan O'Donoghue
5031e4c20dSBryan O'DonoghueThe following commands assume that a directory exits in the top-level TFA build
5131e4c20dSBryan O'Donoghuedirectory "fiptool_images". "fiptool_images" contains
5231e4c20dSBryan O'Donoghue
5331e4c20dSBryan O'Donoghue- u-boot.bin
5431e4c20dSBryan O'Donoghue  The binary output from the u-boot instructions above
5531e4c20dSBryan O'Donoghue
5631e4c20dSBryan O'Donoghue- tee-header_v2.bin
5731e4c20dSBryan O'Donoghue- tee-pager_v2.bin
5831e4c20dSBryan O'Donoghue- tee-pageable_v2.bin
5931e4c20dSBryan O'Donoghue  Binary outputs from the previous OPTEE build steps
6031e4c20dSBryan O'Donoghue
6131e4c20dSBryan O'DonoghueIt is also assumed copy of mbedtls is available on the path path ../mbedtls
6231e4c20dSBryan O'Donoghue  https://github.com/ARMmbed/mbedtls.git
6331e4c20dSBryan O'Donoghue  At the time of writing HEAD points to 0592ea772aee48ca1e6d9eb84eca8e143033d973
6431e4c20dSBryan O'Donoghue
6531e4c20dSBryan O'Donoghue.. code:: shell
6631e4c20dSBryan O'Donoghue
6731e4c20dSBryan O'Donoghue    mkdir fiptool_images
6831e4c20dSBryan O'Donoghue    cp /path/to/optee/out/arm-plat-imx/core/tee-header_v2.bin fiptool_images
6931e4c20dSBryan O'Donoghue    cp /path/to/optee/out/arm-plat-imx/core/tee-pager_v2.bin fiptool_images
7031e4c20dSBryan O'Donoghue    cp /path/to/optee/out/arm-plat-imx/core/tee-pageable_v2.bin fiptool_images
7131e4c20dSBryan O'Donoghue
7231e4c20dSBryan O'Donoghue    make CROSS_COMPILE=${CROSS_COMPILE} PLAT=warp7 ARCH=aarch32 ARM_ARCH_MAJOR=7 \
7331e4c20dSBryan O'Donoghue         ARM_CORTEX_A7=yes AARCH32_SP=optee PLAT_WARP7_UART=1 GENERATE_COT=1 \
7431e4c20dSBryan O'Donoghue         TRUSTED_BOARD_BOOT=1 USE_TBBR_DEFS=1 MBEDTLS_DIR=../mbedtls \
7531e4c20dSBryan O'Donoghue         NEED_BL32=yes BL32=fiptool_images/tee-header_v2.bin \
7631e4c20dSBryan O'Donoghue         BL32_EXTRA1=fiptool_images/tee-pager_v2.bin \
7731e4c20dSBryan O'Donoghue         BL32_EXTRA2=fiptool_images/tee-pageable_v2.bin \
7831e4c20dSBryan O'Donoghue         BL33=fiptool_images/u-boot.bin certificates all
7931e4c20dSBryan O'Donoghue
8031e4c20dSBryan O'Donoghue    /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
81b182a5d9SBryan O'Donoghue
82*24dba2b3SPaul BeesleyFIP
83*24dba2b3SPaul Beesley~~~
84b182a5d9SBryan O'Donoghue
85b182a5d9SBryan O'Donoghue.. code:: shell
86b182a5d9SBryan O'Donoghue
87b182a5d9SBryan O'Donoghue    cp /path/to/uboot/u-boot.bin fiptool_images
88b182a5d9SBryan O'Donoghue    cp /path/to/linux/arch/boot/dts/imx7s-warp.dtb fiptool_images
89b182a5d9SBryan O'Donoghue
9031e4c20dSBryan O'Donoghue    tools/cert_create/cert_create -n --rot-key "build/warp7/debug/rot_key.pem" \
9131e4c20dSBryan O'Donoghue               --tfw-nvctr 0 \
9231e4c20dSBryan O'Donoghue               --ntfw-nvctr 0 \
9331e4c20dSBryan O'Donoghue               --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \
9431e4c20dSBryan O'Donoghue               --tb-fw=build/warp7/debug/bl2.bin \
9531e4c20dSBryan O'Donoghue               --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt\
9631e4c20dSBryan O'Donoghue               --tos-fw fiptool_images/tee-header_v2.bin \
9731e4c20dSBryan O'Donoghue               --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \
9831e4c20dSBryan O'Donoghue               --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \
9931e4c20dSBryan O'Donoghue               --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \
10031e4c20dSBryan O'Donoghue               --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \
10131e4c20dSBryan O'Donoghue               --nt-fw fiptool_images/u-boot.bin \
10231e4c20dSBryan O'Donoghue               --nt-fw-cert fiptool_images/u-boot.bin.crt \
10331e4c20dSBryan O'Donoghue               --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \
10431e4c20dSBryan O'Donoghue               --hw-config fiptool_images/imx7s-warp.dtb
10531e4c20dSBryan O'Donoghue
10631e4c20dSBryan O'Donoghue    tools/fiptool/fiptool create --tos-fw fiptool_images/tee-header_v2.bin \
10731e4c20dSBryan O'Donoghue              --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \
10831e4c20dSBryan O'Donoghue              --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \
10931e4c20dSBryan O'Donoghue              --nt-fw fiptool_images/u-boot.bin \
11031e4c20dSBryan O'Donoghue              --hw-config fiptool_images/imx7s-warp.dtb \
11131e4c20dSBryan O'Donoghue              --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \
11231e4c20dSBryan O'Donoghue              --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \
11331e4c20dSBryan O'Donoghue              --nt-fw-cert fiptool_images/u-boot.bin.crt \
11431e4c20dSBryan O'Donoghue              --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \
11531e4c20dSBryan O'Donoghue              --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \
11631e4c20dSBryan O'Donoghue              --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt warp7.fip
117b182a5d9SBryan O'Donoghue
118*24dba2b3SPaul BeesleyDeploy Images
119*24dba2b3SPaul Beesley-------------
120b182a5d9SBryan O'Donoghue
121b182a5d9SBryan O'DonoghueFirst place the WaRP7 into UMS mode in u-boot this should produce an entry in
122b182a5d9SBryan O'Donoghue/dev like /dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0
123b182a5d9SBryan O'Donoghue
124b182a5d9SBryan O'Donoghue.. code:: shell
125b182a5d9SBryan O'Donoghue
126b182a5d9SBryan O'Donoghue    => ums 0 mmc 0
127b182a5d9SBryan O'Donoghue
128b182a5d9SBryan O'DonoghueNext flash bl2.imx and warp7.fip
129b182a5d9SBryan O'Donoghue
130b182a5d9SBryan O'Donoghuebl2.imx is flashed @ 1024 bytes
131b182a5d9SBryan O'Donoghuewarp7.fip is flash @ 1048576 bytes
132b182a5d9SBryan O'Donoghue
133b182a5d9SBryan O'Donoghue.. code:: shell
134b182a5d9SBryan O'Donoghue
135b182a5d9SBryan O'Donoghue    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
136b182a5d9SBryan O'Donoghue    # Offset is 1MB 1048576 => 1048576 / 512 = 2048
137b182a5d9SBryan O'Donoghue    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
138b182a5d9SBryan O'Donoghue
139b182a5d9SBryan O'DonoghueRemember to umount the USB device pefore proceeding
140b182a5d9SBryan O'Donoghue
141b182a5d9SBryan O'Donoghue.. code:: shell
142b182a5d9SBryan O'Donoghue
143b182a5d9SBryan O'Donoghue    sudo umount /dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0*
144b182a5d9SBryan O'Donoghue
145b182a5d9SBryan O'Donoghue
146*24dba2b3SPaul BeesleySigning BL2
147*24dba2b3SPaul Beesley-----------
148b182a5d9SBryan O'Donoghue
149b182a5d9SBryan O'DonoghueA further step is to sign BL2.
150b182a5d9SBryan O'Donoghue
151b182a5d9SBryan O'DonoghueThe image_sign.sh and bl2_sign.csf files alluded to blow are available here.
152b182a5d9SBryan O'Donoghue
153b182a5d9SBryan O'Donoghuehttps://github.com/bryanodonoghue/atf-code-signing
154b182a5d9SBryan O'Donoghue
155b182a5d9SBryan O'DonoghueIt is suggested you use this script plus the example CSF file in order to avoid
156b182a5d9SBryan O'Donoghuehard-coding data into your CSF files.
157b182a5d9SBryan O'Donoghue
158b182a5d9SBryan O'DonoghueDownload both "image_sign.sh" and "bl2_sign.csf" to your
159b182a5d9SBryan O'Donoghuearm-trusted-firmware top-level directory.
160b182a5d9SBryan O'Donoghue
161b182a5d9SBryan O'Donoghue.. code:: shell
162b182a5d9SBryan O'Donoghue
163b182a5d9SBryan O'Donoghue    #!/bin/bash
164b182a5d9SBryan O'Donoghue    SIGN=image_sign.sh
165b182a5d9SBryan O'Donoghue    TEMP=`pwd`/temp
166b182a5d9SBryan O'Donoghue    BL2_CSF=bl2_sign.csf
167b182a5d9SBryan O'Donoghue    BL2_IMX=bl2.bin.imx
168b182a5d9SBryan O'Donoghue    CST_PATH=/path/to/cst-2.3.2
169b182a5d9SBryan O'Donoghue    CST_BIN=${CST_PATH}/linux64/cst
170b182a5d9SBryan O'Donoghue
171b182a5d9SBryan O'Donoghue    #Remove temp
172b182a5d9SBryan O'Donoghue    rm -rf ${TEMP}
173b182a5d9SBryan O'Donoghue    mkdir ${TEMP}
174b182a5d9SBryan O'Donoghue
175b182a5d9SBryan O'Donoghue    # Generate IMX header
176b182a5d9SBryan O'Donoghue    /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
177b182a5d9SBryan O'Donoghue
178b182a5d9SBryan O'Donoghue    # Copy required items to $TEMP
179b182a5d9SBryan O'Donoghue    cp build/warp7/debug/bl2.bin.imx ${TEMP}
180b182a5d9SBryan O'Donoghue    cp ${CST_PATH}/keys/* ${TEMP}
181b182a5d9SBryan O'Donoghue    cp ${CST_PATH}/crts/* ${TEMP}
182b182a5d9SBryan O'Donoghue    cp ${BL2_CSF} ${TEMP}
183b182a5d9SBryan O'Donoghue
184b182a5d9SBryan O'Donoghue    # Generate signed BL2 image
185b182a5d9SBryan O'Donoghue    ./${SIGN} image_sign_mbl_binary ${TEMP} ${BL2_CSF} ${BL2_IMX} ${CST_BIN}
186b182a5d9SBryan O'Donoghue
187b182a5d9SBryan O'Donoghue    # Copy signed BL2 to top-level directory
188b182a5d9SBryan O'Donoghue    cp ${TEMP}/${BL2_IMX}-signed .
189b182a5d9SBryan O'Donoghue    cp ${BL2_RECOVER_CSF} ${TEMP}
190b182a5d9SBryan O'Donoghue
191b182a5d9SBryan O'Donoghue
192b182a5d9SBryan O'DonoghueThe resulting bl2.bin.imx-signed can replace bl2.bin.imx in the Deploy
193b182a5d9SBryan O'DonoghueImages section above, once done.
194b182a5d9SBryan O'Donoghue
195b182a5d9SBryan O'DonoghueSuggested flow for verifying.
196b182a5d9SBryan O'Donoghue
197b182a5d9SBryan O'Donoghue1. Followed all previous steps above and verify a non-secure ATF boot
198b182a5d9SBryan O'Donoghue2. Down the NXP Code Singing Tool
199b182a5d9SBryan O'Donoghue3. Generate keys
200b182a5d9SBryan O'Donoghue4. Program the fuses on your board
201b182a5d9SBryan O'Donoghue5. Replace bl2.bin.imx with bl2.bin.imx-signed
202b182a5d9SBryan O'Donoghue6. Verify inside u-boot that "hab_status" shows no events
203b182a5d9SBryan O'Donoghue7. Subsequently close your board.
204b182a5d9SBryan O'Donoghue
205b182a5d9SBryan O'DonoghueIf you have HAB events @ step 6 - do not lock your board.
206b182a5d9SBryan O'Donoghue
207b182a5d9SBryan O'DonoghueTo get a good over-view of generating keys and programming the fuses on the
208b182a5d9SBryan O'Donoghueboard read "High Assurance Boot for Dummies" by Boundary Devices.
209b182a5d9SBryan O'Donoghue
210b182a5d9SBryan O'Donoghuehttps://boundarydevices.com/high-assurance-boot-hab-dummies/
211