Secure boot refers to a two-stage process of successive authentication of the U-Boot and Linux kernel images. This process requires a "root of trust", which is known to be secure. In this case, the root of trust is HSE itself.
Each image is authenticated by the preceding step. Thus, the secure boot flow is the following:
BootROM passes control over to HSE FW;
HSE FW authenticates the U-Boot image;
U-Boot authenticates the Kernel image.
U-Boot authentication is currently only supported when booting from an SD card
How uboot gets verified:
To authenticate the U-Boot image, HSE uses Advanced Secure Boot (ASB). The system configuration is saved as a System Image (SYS_IMG), which contains data related to imported keys, Secure Memory Region (SMR) configuration and Core Reset (CR) entry configuration.
The SYS_IMG is signed with a device-specific key.
The keys used for ASB are stored in a NVM key catalog, which contains multiple slots for multiple key types and authentication schemes.
The Secure Memory Region entry is used to define which data needs to be authenticated from the boot media, which key and authentication scheme is required, and where to place the data in memory after authentication.
The Core Reset entry is used to define which core should be enabled and what address to jump to after authentication, as well as what action to take in case authentication fails.
The steps to enable secure boot:
1. Read the IVT from the boot media;
2. Configure the HSE NVM and RAM key catalogs if no SYS_IMG;
3. Import the RSA public key into the NVM key catalog;
4. Configure and install the Core Reset entry;
5. Configure and install the Secure Memory Region entry;
6. Generate the signed SYS_IMG and Write the SYS_IMG back onto the boot media;
7. Set the BOOT_SEQ bit and Write the IVT back onto the boot media;
8. reboot board
in uboot, hse_secboot_enable is provided to enable secure boot
do_hse_secboot_enable (arch/arm/mach-s32/s32-cc/hse_adv_secboot.c)
The boot image signature is located in “tb-fw-cert” entry of the boot image which is read only. the verification RSA public key is copied in boot partition of SD card . Also a certificate can be used to verify the boot image signature. the certificate is signed by the device specific key. In the step 3 of enable secure boot, when the public key is imported to HSM, the device specific key is used to check the authenticate of the certificate.
How S32g uboot authenticate Linux kernel:
Kernel image authentication is provided by U-Boot, using the upstream verified boot method. This method will use an .its file, which defines a dtb/kernel configuration and a signing scheme.
this is a sample its file. the output is an ITB file which should be copied to boot partition of SD card. the signature is embedded in ITB file.
# command to start LINUX from uboot
# load itb file
fatload mmc 0:1 0x80000000 itb_file
# call bootm
bootm 0x80000000
# the call stack of bootm
bootm (cmd/bootm.c)
do_bootm (cmd/bootm.c)
do_bootm_states (common/bootm.c)
bootm_find_os (common/bootm.c)
boot_get_kernel (common/bootm.c)
fit_image_load (common/image-fit.c)
fit_config_verify (common/image-sig.c)
fit_config_verify_required_sigs (common/image-sig.c)
fit_config_verify_sig (common/image-sig.c)
fit_config_check_sig (common/image-sig.c)
in fit_config_check_sig
// call fit_image_setup_verify to get crypto/has settting
// call crypto->verify to verify the signature
currently uboot provides the RSA verification alog.
struct checksum_algo checksum_algos[] = {
{
.name = "sha1",
.checksum_len = SHA1_SUM_LEN,
.der_len = SHA1_DER_LEN,
.der_prefix = sha1_der_prefix,
.calculate = hash_calculate,
}
};
struct crypto_algo crypto_algos[] = {
{
.name = "rsa2048",
.key_len = RSA2048_BYTES,
.sign = rsa_sign,
.add_verify_data = rsa_add_verify_data,
.verify = rsa_verify,
}
}
struct padding_algo padding_algos[] = {
{
.name = "pkcs-1.5",
.verify = padding_pkcs_15_verify,
}
};
they are defined in common/lib/rsa/rsa_verify.c, rsa_sign.c
RSA verify retrieves the public key from bootloader device tree blob
and call rsa_verify to verify the signture.
This RSA verification is pure software. we can take advantage of HSE on S32g, either use prev-loaded public key or import the public key from device tree and call HSM service to verify the signature.