xref: /rk3399_rockchip-uboot/doc/README.mxc_hab (revision 43ade93bdb0c8bd57382be810a05b3793749ce85)
10187c985SStefano BabicHigh Assurance Boot (HAB) for i.MX6 CPUs
20187c985SStefano Babic
38148b824SUlises CardenasTo enable the authenticated or encrypted boot mode of U-Boot, it is
48148b824SUlises Cardenasrequired to set the proper configuration for the target board. This
5*7a037cc9SFabio Estevamis done by adding the following configuration in the defconfig file:
68148b824SUlises Cardenas
7*7a037cc9SFabio EstevamCONFIG_SECURE_BOOT=y
88148b824SUlises Cardenas
98148b824SUlises CardenasIn addition, the U-Boot image to be programmed into the
100187c985SStefano Babicboot media needs to be properly constructed, i.e. it must contain a
110187c985SStefano Babicproper Command Sequence File (CSF).
120187c985SStefano Babic
130187c985SStefano BabicThe Initial Vector Table contains a pointer to the CSF. Please see
140187c985SStefano Babicdoc/README.imximage for how to prepare u-boot.imx.
150187c985SStefano Babic
160187c985SStefano BabicThe CSF itself is being generated by Freescale HAB tools.
170187c985SStefano Babic
180187c985SStefano Babicmkimage will output additional information about "HAB Blocks"
190187c985SStefano Babicwhich can be used in the Freescale tooling to authenticate U-Boot
200187c985SStefano Babic(entries in the CSF file).
210187c985SStefano Babic
220187c985SStefano BabicImage Type:   Freescale IMX Boot Image
230187c985SStefano BabicImage Ver:    2 (i.MX53/6 compatible)
240187c985SStefano BabicData Size:    327680 Bytes = 320.00 kB = 0.31 MB
250187c985SStefano BabicLoad Address: 177ff420
260187c985SStefano BabicEntry Point:  17800000
270187c985SStefano BabicHAB Blocks:   177ff400 00000000 0004dc00
280187c985SStefano Babic	      ^^^^^^^^ ^^^^^^^^ ^^^^^^^^
290187c985SStefano Babic		|	|	   |
300187c985SStefano Babic		|	|	   -------- (1)
310187c985SStefano Babic		|	|
320187c985SStefano Babic		|	------------------- (2)
330187c985SStefano Babic		|
340187c985SStefano Babic		--------------------------- (3)
350187c985SStefano Babic
360187c985SStefano Babic(1)	Size of area in file u-boot.imx to sign
370187c985SStefano Babic	This area should include the IVT, the Boot Data the DCD
380187c985SStefano Babic	and U-Boot itself.
390187c985SStefano Babic(2)	Start of area in u-boot.imx to sign
400187c985SStefano Babic(3)	Start of area in RAM to authenticate
410187c985SStefano Babic
420187c985SStefano BabicCONFIG_SECURE_BOOT currently enables only an additional command
430187c985SStefano Babic'hab_status' in U-Boot to retrieve the HAB status and events. This
440187c985SStefano Babiccan be useful while developing and testing HAB.
450187c985SStefano Babic
460187c985SStefano BabicCommands to generate a signed U-Boot using Freescale HAB tools:
470187c985SStefano Babiccst --o U-Boot_CSF.bin < U-Boot.CSF
480187c985SStefano Babicobjcopy -I binary -O binary --pad-to 0x2000 --gap-fill=0x00 \
490187c985SStefano Babic	U-Boot_CSF.bin U-Boot_CSF_pad.bin
500187c985SStefano Babiccat u-boot.imx U-Boot_CSF_pad.bin > u-boot-signed.imx
510187c985SStefano Babic
520187c985SStefano BabicNOTE: U-Boot_CSF.bin needs to be padded to the value specified in
530187c985SStefano Babicthe imximage.cfg file.
540200020bSRaul Cardenas
550200020bSRaul CardenasSetup U-Boot Image for Encrypted Boot
560200020bSRaul Cardenas-------------------------------------
570200020bSRaul CardenasAn authenticated U-Boot image is used as starting point for
580200020bSRaul CardenasEncrypted Boot. The image is encrypted by Freescale's Code
590200020bSRaul CardenasSigning Tool (CST). The CST replaces only the image data of
600200020bSRaul Cardenasu-boot.imx with the encrypted data. The Initial Vector Table,
610200020bSRaul CardenasDCD, and Boot data, remains in plaintext.
620200020bSRaul Cardenas
630200020bSRaul CardenasThe image data is encrypted with a Encryption Key (DEK).
640200020bSRaul CardenasTherefore, this key is needed to decrypt the data during the
650200020bSRaul Cardenasbooting process. The DEK is protected by wrapping it in a Blob,
660200020bSRaul Cardenaswhich needs to be appended to the U-Boot image and specified in
670200020bSRaul Cardenasthe CSF file.
680200020bSRaul Cardenas
690200020bSRaul CardenasThe DEK blob is generated by an authenticated U-Boot image with
700200020bSRaul Cardenasthe dek_blob cmd enabled. The image used for DEK blob generation
710200020bSRaul Cardenasneeds to have the following configurations enabled:
720200020bSRaul Cardenas
730200020bSRaul CardenasCONFIG_SECURE_BOOT
740200020bSRaul CardenasCONFIG_SYS_FSL_SEC_COMPAT    4 /* HAB version */
750200020bSRaul CardenasCONFIG_FSL_CAAM
760200020bSRaul CardenasCONFIG_CMD_DEKBLOB
778148b824SUlises CardenasCONFIG_SYS_FSL_SEC_LE
780200020bSRaul Cardenas
790200020bSRaul CardenasNote: The encrypted boot feature is only supported by HABv4 or
800200020bSRaul Cardenasgreater.
810200020bSRaul Cardenas
820200020bSRaul CardenasThe dek_blob command then can be used to generate the DEK blob of
830200020bSRaul Cardenasa DEK previously loaded in memory. The command is used as follows:
840200020bSRaul Cardenas
850200020bSRaul Cardenasdek_blob <DEK address> <Output Address> <Key Size in Bits>
860200020bSRaul Cardenasexample: dek_blob 0x10800000 0x10801000 192
870200020bSRaul Cardenas
880200020bSRaul CardenasThe resulting DEK blob then is used to construct the encrypted
890200020bSRaul CardenasU-Boot image. Note that the blob needs to be transferred back
900200020bSRaul Cardenasto the host.Then the following commands are used to construct
910200020bSRaul Cardenasthe final image.
920200020bSRaul Cardenas
930200020bSRaul Cardenasobjcopy -I binary -O binary --pad-to 0x2000 --gap-fill=0x00 \
940200020bSRaul Cardenas    U-Boot_CSF.bin U-Boot_CSF_pad.bin
950200020bSRaul Cardenascat u-boot.imx U-Boot_CSF_pad.bin > u-boot-signed.imx
960200020bSRaul Cardenasobjcopy -I binary -O binary --pad-to <blob_dst> --gap-fill=0x00 \
970200020bSRaul Cardenas    u-boot-signed.imx u-boot-signed-pad.bin
980200020bSRaul Cardenascat u-boot-signed-pad.imx DEK_blob.bin > u-boot-encrypted.imx
990200020bSRaul Cardenas
1000200020bSRaul Cardenas    NOTE: u-boot-signed.bin needs to be padded to the value
1010200020bSRaul Cardenas    equivalent to the address in which the DEK blob is specified
1020200020bSRaul Cardenas    in the CSF.
103