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