xref: /aosp_15_r20/external/arm-trusted-firmware/docs/plat/warp7.rst (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong ParkNXP i.MX7 WaRP7
2*54fd6939SJiyong Park===============
3*54fd6939SJiyong Park
4*54fd6939SJiyong ParkThe Trusted Firmware-A port for the i.MX7Solo WaRP7 implements BL2 at EL3.
5*54fd6939SJiyong ParkThe i.MX7S contains a BootROM with a High Assurance Boot (HAB) functionality.
6*54fd6939SJiyong ParkThis functionality provides a mechanism for establishing a root-of-trust from
7*54fd6939SJiyong Parkthe reset vector to the command-line in user-space.
8*54fd6939SJiyong Park
9*54fd6939SJiyong ParkBoot Flow
10*54fd6939SJiyong Park---------
11*54fd6939SJiyong Park
12*54fd6939SJiyong ParkBootROM --> TF-A BL2 --> BL32(OP-TEE) --> BL33(U-Boot) --> Linux
13*54fd6939SJiyong Park
14*54fd6939SJiyong ParkIn the WaRP7 port we encapsulate OP-TEE, DTB and U-Boot into a FIP. This FIP is
15*54fd6939SJiyong Parkexpected and required
16*54fd6939SJiyong Park
17*54fd6939SJiyong ParkBuild Instructions
18*54fd6939SJiyong Park------------------
19*54fd6939SJiyong Park
20*54fd6939SJiyong ParkWe need to use a file generated by u-boot in order to generate a .imx image the
21*54fd6939SJiyong ParkBootROM will boot. It is therefore _required_ to build u-boot before TF-A and
22*54fd6939SJiyong Parkfurthermore it is _recommended_ to use the mkimage in the u-boot/tools directory
23*54fd6939SJiyong Parkto generate the TF-A .imx image.
24*54fd6939SJiyong Park
25*54fd6939SJiyong ParkU-Boot
26*54fd6939SJiyong Park~~~~~~
27*54fd6939SJiyong Park
28*54fd6939SJiyong Parkhttps://git.linaro.org/landing-teams/working/mbl/u-boot.git
29*54fd6939SJiyong Park
30*54fd6939SJiyong Park.. code:: shell
31*54fd6939SJiyong Park
32*54fd6939SJiyong Park    git checkout -b rms-atf-optee-uboot linaro-mbl/rms-atf-optee-uboot
33*54fd6939SJiyong Park    make warp7_bl33_defconfig;
34*54fd6939SJiyong Park    make u-boot.imx arch=ARM CROSS_COMPILE=arm-linux-gnueabihf-
35*54fd6939SJiyong Park
36*54fd6939SJiyong ParkOP-TEE
37*54fd6939SJiyong Park~~~~~~
38*54fd6939SJiyong Park
39*54fd6939SJiyong Parkhttps://github.com/OP-TEE/optee_os.git
40*54fd6939SJiyong Park
41*54fd6939SJiyong Park.. code:: shell
42*54fd6939SJiyong Park
43*54fd6939SJiyong Park    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
44*54fd6939SJiyong Park
45*54fd6939SJiyong ParkTF-A
46*54fd6939SJiyong Park~~~~
47*54fd6939SJiyong Park
48*54fd6939SJiyong Parkhttps://github.com/ARM-software/arm-trusted-firmware.git
49*54fd6939SJiyong Park
50*54fd6939SJiyong ParkThe following commands assume that a directory exits in the top-level TFA build
51*54fd6939SJiyong Parkdirectory "fiptool_images". "fiptool_images" contains
52*54fd6939SJiyong Park
53*54fd6939SJiyong Park- u-boot.bin
54*54fd6939SJiyong Park  The binary output from the u-boot instructions above
55*54fd6939SJiyong Park
56*54fd6939SJiyong Park- tee-header_v2.bin
57*54fd6939SJiyong Park- tee-pager_v2.bin
58*54fd6939SJiyong Park- tee-pageable_v2.bin
59*54fd6939SJiyong Park  Binary outputs from the previous OPTEE build steps
60*54fd6939SJiyong Park
61*54fd6939SJiyong ParkIt is also assumed copy of mbedtls is available on the path path ../mbedtls
62*54fd6939SJiyong Park  https://github.com/ARMmbed/mbedtls.git
63*54fd6939SJiyong Park  At the time of writing HEAD points to 0592ea772aee48ca1e6d9eb84eca8e143033d973
64*54fd6939SJiyong Park
65*54fd6939SJiyong Park.. code:: shell
66*54fd6939SJiyong Park
67*54fd6939SJiyong Park    mkdir fiptool_images
68*54fd6939SJiyong Park    cp /path/to/optee/out/arm-plat-imx/core/tee-header_v2.bin fiptool_images
69*54fd6939SJiyong Park    cp /path/to/optee/out/arm-plat-imx/core/tee-pager_v2.bin fiptool_images
70*54fd6939SJiyong Park    cp /path/to/optee/out/arm-plat-imx/core/tee-pageable_v2.bin fiptool_images
71*54fd6939SJiyong Park
72*54fd6939SJiyong Park    make CROSS_COMPILE=${CROSS_COMPILE} PLAT=warp7 ARCH=aarch32 ARM_ARCH_MAJOR=7 \
73*54fd6939SJiyong Park         ARM_CORTEX_A7=yes AARCH32_SP=optee PLAT_WARP7_UART=1 GENERATE_COT=1 \
74*54fd6939SJiyong Park         TRUSTED_BOARD_BOOT=1 USE_TBBR_DEFS=1 MBEDTLS_DIR=../mbedtls \
75*54fd6939SJiyong Park         NEED_BL32=yes BL32=fiptool_images/tee-header_v2.bin \
76*54fd6939SJiyong Park         BL32_EXTRA1=fiptool_images/tee-pager_v2.bin \
77*54fd6939SJiyong Park         BL32_EXTRA2=fiptool_images/tee-pageable_v2.bin \
78*54fd6939SJiyong Park         BL33=fiptool_images/u-boot.bin certificates all
79*54fd6939SJiyong Park
80*54fd6939SJiyong Park    /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
81*54fd6939SJiyong Park
82*54fd6939SJiyong ParkFIP
83*54fd6939SJiyong Park~~~
84*54fd6939SJiyong Park
85*54fd6939SJiyong Park.. code:: shell
86*54fd6939SJiyong Park
87*54fd6939SJiyong Park    cp /path/to/uboot/u-boot.bin fiptool_images
88*54fd6939SJiyong Park    cp /path/to/linux/arch/boot/dts/imx7s-warp.dtb fiptool_images
89*54fd6939SJiyong Park
90*54fd6939SJiyong Park    tools/cert_create/cert_create -n --rot-key "build/warp7/debug/rot_key.pem" \
91*54fd6939SJiyong Park               --tfw-nvctr 0 \
92*54fd6939SJiyong Park               --ntfw-nvctr 0 \
93*54fd6939SJiyong Park               --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \
94*54fd6939SJiyong Park               --tb-fw=build/warp7/debug/bl2.bin \
95*54fd6939SJiyong Park               --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt\
96*54fd6939SJiyong Park               --tos-fw fiptool_images/tee-header_v2.bin \
97*54fd6939SJiyong Park               --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \
98*54fd6939SJiyong Park               --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \
99*54fd6939SJiyong Park               --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \
100*54fd6939SJiyong Park               --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \
101*54fd6939SJiyong Park               --nt-fw fiptool_images/u-boot.bin \
102*54fd6939SJiyong Park               --nt-fw-cert fiptool_images/u-boot.bin.crt \
103*54fd6939SJiyong Park               --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \
104*54fd6939SJiyong Park               --hw-config fiptool_images/imx7s-warp.dtb
105*54fd6939SJiyong Park
106*54fd6939SJiyong Park    tools/fiptool/fiptool create --tos-fw fiptool_images/tee-header_v2.bin \
107*54fd6939SJiyong Park              --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \
108*54fd6939SJiyong Park              --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \
109*54fd6939SJiyong Park              --nt-fw fiptool_images/u-boot.bin \
110*54fd6939SJiyong Park              --hw-config fiptool_images/imx7s-warp.dtb \
111*54fd6939SJiyong Park              --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \
112*54fd6939SJiyong Park              --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \
113*54fd6939SJiyong Park              --nt-fw-cert fiptool_images/u-boot.bin.crt \
114*54fd6939SJiyong Park              --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \
115*54fd6939SJiyong Park              --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \
116*54fd6939SJiyong Park              --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt warp7.fip
117*54fd6939SJiyong Park
118*54fd6939SJiyong ParkDeploy Images
119*54fd6939SJiyong Park-------------
120*54fd6939SJiyong Park
121*54fd6939SJiyong ParkFirst place the WaRP7 into UMS mode in u-boot this should produce an entry in
122*54fd6939SJiyong Park/dev like /dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0
123*54fd6939SJiyong Park
124*54fd6939SJiyong Park.. code:: shell
125*54fd6939SJiyong Park
126*54fd6939SJiyong Park    => ums 0 mmc 0
127*54fd6939SJiyong Park
128*54fd6939SJiyong ParkNext flash bl2.imx and warp7.fip
129*54fd6939SJiyong Park
130*54fd6939SJiyong Parkbl2.imx is flashed @ 1024 bytes
131*54fd6939SJiyong Parkwarp7.fip is flash @ 1048576 bytes
132*54fd6939SJiyong Park
133*54fd6939SJiyong Park.. code:: shell
134*54fd6939SJiyong Park
135*54fd6939SJiyong Park    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
136*54fd6939SJiyong Park    # Offset is 1MB 1048576 => 1048576 / 512 = 2048
137*54fd6939SJiyong Park    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
138*54fd6939SJiyong Park
139*54fd6939SJiyong ParkRemember to umount the USB device pefore proceeding
140*54fd6939SJiyong Park
141*54fd6939SJiyong Park.. code:: shell
142*54fd6939SJiyong Park
143*54fd6939SJiyong Park    sudo umount /dev/disk/by-id/usb-Linux_UMS_disk_0_WaRP7-0xf42400d3000001d4-0\:0*
144*54fd6939SJiyong Park
145*54fd6939SJiyong Park
146*54fd6939SJiyong ParkSigning BL2
147*54fd6939SJiyong Park-----------
148*54fd6939SJiyong Park
149*54fd6939SJiyong ParkA further step is to sign BL2.
150*54fd6939SJiyong Park
151*54fd6939SJiyong ParkThe image_sign.sh and bl2_sign.csf files alluded to blow are available here.
152*54fd6939SJiyong Park
153*54fd6939SJiyong Parkhttps://github.com/bryanodonoghue/atf-code-signing
154*54fd6939SJiyong Park
155*54fd6939SJiyong ParkIt is suggested you use this script plus the example CSF file in order to avoid
156*54fd6939SJiyong Parkhard-coding data into your CSF files.
157*54fd6939SJiyong Park
158*54fd6939SJiyong ParkDownload both "image_sign.sh" and "bl2_sign.csf" to your
159*54fd6939SJiyong Parkarm-trusted-firmware top-level directory.
160*54fd6939SJiyong Park
161*54fd6939SJiyong Park.. code:: shell
162*54fd6939SJiyong Park
163*54fd6939SJiyong Park    #!/bin/bash
164*54fd6939SJiyong Park    SIGN=image_sign.sh
165*54fd6939SJiyong Park    TEMP=`pwd`/temp
166*54fd6939SJiyong Park    BL2_CSF=bl2_sign.csf
167*54fd6939SJiyong Park    BL2_IMX=bl2.bin.imx
168*54fd6939SJiyong Park    CST_PATH=/path/to/cst-2.3.2
169*54fd6939SJiyong Park    CST_BIN=${CST_PATH}/linux64/cst
170*54fd6939SJiyong Park
171*54fd6939SJiyong Park    #Remove temp
172*54fd6939SJiyong Park    rm -rf ${TEMP}
173*54fd6939SJiyong Park    mkdir ${TEMP}
174*54fd6939SJiyong Park
175*54fd6939SJiyong Park    # Generate IMX header
176*54fd6939SJiyong Park    /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
177*54fd6939SJiyong Park
178*54fd6939SJiyong Park    # Copy required items to $TEMP
179*54fd6939SJiyong Park    cp build/warp7/debug/bl2.bin.imx ${TEMP}
180*54fd6939SJiyong Park    cp ${CST_PATH}/keys/* ${TEMP}
181*54fd6939SJiyong Park    cp ${CST_PATH}/crts/* ${TEMP}
182*54fd6939SJiyong Park    cp ${BL2_CSF} ${TEMP}
183*54fd6939SJiyong Park
184*54fd6939SJiyong Park    # Generate signed BL2 image
185*54fd6939SJiyong Park    ./${SIGN} image_sign_mbl_binary ${TEMP} ${BL2_CSF} ${BL2_IMX} ${CST_BIN}
186*54fd6939SJiyong Park
187*54fd6939SJiyong Park    # Copy signed BL2 to top-level directory
188*54fd6939SJiyong Park    cp ${TEMP}/${BL2_IMX}-signed .
189*54fd6939SJiyong Park    cp ${BL2_RECOVER_CSF} ${TEMP}
190*54fd6939SJiyong Park
191*54fd6939SJiyong Park
192*54fd6939SJiyong ParkThe resulting bl2.bin.imx-signed can replace bl2.bin.imx in the Deploy
193*54fd6939SJiyong ParkImages section above, once done.
194*54fd6939SJiyong Park
195*54fd6939SJiyong ParkSuggested flow for verifying.
196*54fd6939SJiyong Park
197*54fd6939SJiyong Park1. Followed all previous steps above and verify a non-secure ATF boot
198*54fd6939SJiyong Park2. Down the NXP Code Singing Tool
199*54fd6939SJiyong Park3. Generate keys
200*54fd6939SJiyong Park4. Program the fuses on your board
201*54fd6939SJiyong Park5. Replace bl2.bin.imx with bl2.bin.imx-signed
202*54fd6939SJiyong Park6. Verify inside u-boot that "hab_status" shows no events
203*54fd6939SJiyong Park7. Subsequently close your board.
204*54fd6939SJiyong Park
205*54fd6939SJiyong ParkIf you have HAB events @ step 6 - do not lock your board.
206*54fd6939SJiyong Park
207*54fd6939SJiyong ParkTo get a good over-view of generating keys and programming the fuses on the
208*54fd6939SJiyong Parkboard read "High Assurance Boot for Dummies" by Boundary Devices.
209*54fd6939SJiyong Park
210*54fd6939SJiyong Parkhttps://boundarydevices.com/high-assurance-boot-hab-dummies/
211