RT1050 HAB Encrypted Image Generation and Analysis
RT1050 HAB Encrypted Image Generation and Analysis
RT1050 HAB Encrypted Image Generation and Analysis
1, Introduction
The NXP RT series can support multiple boot modes, it incluses: unsigned image mode,
HAB signed image mode, HAB encryption image mode, and BEE encryption image mode.
In order to understand the specific structure of the HAB encryption app, this article will
generate a non-XIP app image, then generate the relevant burning file through the
elftosb.exe tool in the flashloader i.MX-RT1050, and use MFGTOOL to enter the serial
download mode to download the .sb file.
This article will focus on the download steps of RT1050 HAB encryption related
operations, and analyze the structure of the HAB encrypted app image.
As you can see from the above, to implement the secure boot of RT1050, you need to
prepare these three files:
• ivt_flashlloader_signed.bin: it is the signed flashloader binary file
• enable_hab.sb: it is used to modify the SRK and HABmode in the fuse map
• boot_image.sb: HAB encrypted app program file
Here is a flow chart of the overall HAB encryption operation step, after checking
this figure, then we will follow it step by step.
1
Fig 2. MXRT1050 HAB encrypted image flow chart
The app image we used in this article is the RAM app, so, at first, we need to prepare
one RAM based app image. In this document, we are directly use the prepared RAM based
app image: evkbimxrt1050_led_softwarereset_0xa000.s19, this app code function is: After
download the code to the MIMXRT1050-EVKB(qspi flash) board, the on board led D18
will blinky and printf the information, after pressing the WAKEUP button SW8, the code
will implement software reset and printf the related information. The unsigned code test
print result are as follows:
BOARD RESET start.
Helloworld.
WAKEUP key pressed, will do software system reset.
2
Because the contains a lot of steps, then customer can refer to the following document
do the related configuration, this document, we won’t give the CST configuration detail
steps. Please check these documents:
https://www.cnblogs.com/henjay724/p/10219459.html
https://community.nxp.com/docs/DOC-340904
Security Application Note AN12079
After the CST tool configuration, please copy the cst.exe, crts filder, key folder from cst
folder to the same folder that holds elftosb executable files:
Flashloader_i.MXRT1050_GA\Flashloader_RT1050_1.1\Tools\elftosb\win
Please also copy SRK_1_2_3_4_fuse.bin and SRK_1_2_3_4_table.bin to the above folder.
This steps will generate the ivt_flashlaoder_signed.bin, which is needed to put under the
MFGtool OS Firmware folder, just used for enter the signed flashloader mode.
3
to this folder path:
Flashloader_i.MXRT1050_GA\Flashloader_RT1050_1.1\Tools\elftosb\win
Please refer to the chapter 2.1 generated SRK_1_2_3_4_fuse.bin, modify the
enable_hab.bd like the following picture:
Then, in the elftosb window, please input the following command, just used to generate
the enable_hab.sb program file:
elftosb.exe -f kinetis -V -c enable_hab.bd -o enable_hab.sb
4
Because the app file is the RAM files, then we also need the related RAM encrypted .bd
files, please copy imx-itcm-encrypted.bd from the folder path:
Flashloader_i.MXRT1050_GA\Flashloader_RT1050_1.1\Tools\bd_file\imx10xx
to this folder path:
Flashloader_i.MXRT1050_GA\Flashloader_RT1050_1.1\Tools\elftosb\win
Open imx-itcm-encrypted.bd, then modify the following content:
options {
flags = 0x0c;
# Note: This is an example address, it can be any non-zero address in ITCM region
startAddress = 0x8000;
ivtOffset = 0x1000;
initialLoadSize = 0x2000;
# Note: This is required if the cst and elftsb are not in the same folder
# Note: This is required if the default entrypoint is not the Reset_Handler
# Please set the entryPointAddress to Reset_Handler address
entryPointAddress = 0x0000a2dd;
}
5
Fig 7. App HAB Encrypted file generation
Please note, we need to record the generated key blob offset address, it is 0XA00, just like
the above data in the red frame, this address will be used in the next chapter’s .bd file. After
this step, it will generate 7 files:
(1) ivt_evkbimxrt1050_led_softwarereset_0xa000_encrypted.bin, this file includes the
FDCB which is filled with 0, IVT, BD, DCD, APP HAB encrypted image data, CSF data.
(2) ivt_evkbimxrt1050_led_softwarereset_0xa000_encrypted_nopadding.bin, compare
with ivt_evkbimxrt1050_led_softwarereset_0xa000_encrypted.bin, this file deletes the 0s
which is above IVT range.
(3) Csf.bin, it is the HAB data area, you can find the data contains the csf data, it is from
0X8000 to 0X8F80 in the generated
ivt_evkbimxrt1050_led_softwarereset_0xa000_encrypted.bin.
(4) dek.bin,
6
Fig 9. Dek data
DEK data is the AES-128 bits key, it is not defined by the customer, it is random
generated automatically by the HAB encrypted tool.
(5) input.csf
Open it, you can find the following content:
(6) rawbytes.bin, this is the app image plaintext data, it doesn’t contains the
FDCB,IVT,BOOTDATA, DCD, csf etc.
(7) temp.bin, it is the temperate file, compare with
ivt_evkbimxrt1050_led_softwarereset_0xa000_encrypted.bin, no csf files.
7
Here we need to prepare one program_flexspinor_image_qspinor_keyblob.bd file, and
put it under the same folder as elftosb, this file is used to generate the HAB encrypted
program .sb file. Because the flashloader package didn’t contains it, then we paste all the
related content, and I will also attach it in the attachment.
# The source block assign file name to identifiers
sources {
myBinFile = extern (0);
dekFile = extern (1);
}
constants {
kAbsAddr_Start= 0x60000000;
kAbsAddr_Ivt = 0x60001000;
kAbsAddr_App = 0x60002000;
}
# The section block specifies the sequence of boot commands to be written to the SB file
section (0) {
8
#5. Program image
load myBinFile > kAbsAddr_Ivt;
9
Fig 11. App HAB encrypted program file generation
Until now, we will find, all the related HAB encrypted files is prepared.
chip = MXRT105X
[platform]
board =
[LIST]
name = MXRT105X-SecureBoot
10
Then open the tool MfgTool2.exe, the board MIMXRT1050-EVKB(need to modify the
on board resistor, use the qspi flash) mode should be serial download mode, just modify
SW7:1-OFF,2-OFF,3-OFF, 4-ON, connect two usb cable between PC and the board J28
and J9. After the connection, you will find the MfgTool2.exe can detect the HID device:
After the program is finished, power off the board, modify the boot mode to internal boot,
it is SW7:1-OFF,2-OFF,3-ON, 4-OFF,connect the COM terminal, power on the EVKB
board, after reset, you will find the D18 led is blinking, after you press the SW8, you will
find the following printf information:
BOARD RESET start.
Helloworld.
WAKEUP key pressed, will do software system reset.
?
BOARD RESET start.
Helloworld.
So, the HAB encrypted image works OK now.
Compare the fuse map between do the HAB encrypted image and no HAB encrypted
image, we can find two difference:
• HAB mode, 0X460 bit1:0 open, 1 close
• SRK area
12
We can find, after program the HAB encrypted image, the SRK fuse data is the same as
the SRK data which is defined in the enable_hab.bd.
3.2 Readout HAB encrypted QSPI APP image structure analysis
From MCUBootUtility tool, we can find the HAB Encypted image structure should be
like this:
13
3): IVT: reserved
4): IVT: DCD, it is used for the DRAM SEMC configuration, in this example, we didn’t
use the SDDRAM, so the data is 0.
5): IVT: BOOT_DATA, used to indicate the BOOT_DATA RAM start address 0X9020.
6): IVT: self, ivt self RAM start address is 0X9000
7): IVT:CSF, it is used to indicate the CST start address, this example csf ram address is
0X00010000.
8): IVT:reserved
9): BOOT_DATA: RAM image start, the whole image RAM start address, this RAM
example BOOT_DATA is 0X8000,0XA000-0X2000=0X8000
10): BOOT_DATA: size, APP while size, it is 0X0000A200, after checking the while
generated HAB encrypted app image size, you can find the image end size is really 0XA200,
just lke the fig 16.
11): HAB Encypted app data, please check
ivt_evkbimxrt1050_led_softwarereset_0xa000_encrypted.bin file, the address 0X2000-
0X7250 data, you will find it is the same.
12): HAB data, it incluses the csf, certificate etc data, you can compare the file
ivt_evkbimxrt1050_led_softwarereset_0xa000_encrypted.bin address 0X8000-0x8f70 data, it is the
same.
13):DEK blob, it is the DEK key blob related data, the offset address is 0XA000, the same as fig 7.
FDCB,IVT,BOOT DATA are all plaintext, but app image area is the HAB encrypted
data, HAB and the DEK blocb is the generated data put in the related memory.
4. Conclusion
This document we mainly use the elftosb and the MFGTool to generate the HAB
encrypted image, and download it to the RT1050 EVKB board, document give the whole
detail steps, and us ethe MCUBootutility tool to read out the HAB encrypted image, and
analysis the HAB encrypted image structure with the examples. After compare with the
generated mid files, we can find all the data is consist, and all the encrypted data range is
the same. The test result also demonstrate the HAB encrypted code function works, the
HAB encrypted boot has no problems. All the related files is in the attachment.
14