[ZYNQ] Loading an Encrypted Linux kernel at U-Boot with a KUP Key

Zynq MPSoC devices support loading an image encrypted with the user key (KUP key) at run time. Users can encrypt any data with their own key and provide the encrypted image and key at the U-Boot stage to decrypt the image. Moreover, the DMA and CPU caches (D-Cache/I-Cache) have been enabled, so these hardware mechanisms can improve the running speed. This blog is intended to show how to load an encrypted image at the U-Boot stage.

Key Update Register:

The key update register is used during boot to support the key rolling feature, where the different AES key must be loaded multiple times. After boot, any key can be loaded into this register via APB by software running on the PS. A 256-bit KUP key is stored in the eight AES key update registers. You can refer to the https://app.gitbook.com/o/eTBeA3vhkOtihTJASkhd/s/tqiX1ZbXhRorHX3bwk1r/~/changes/25/ecus/zynq_documents/zynq-encrypt-external-files-based-on-file-system-using-puf-key

Load the encrypted image and KUP key onto DDR at U-Boot from the SD card.

Bif file to create an encrypted image with a KUP key:

the_ROM_image:
{
[keysrc_encryption]kup_key
[encryption=aes, aeskeyfile=kup_key.nky, load=0x10000000]image.ub
}

Bootgen command to generate the encrypted image:

bootgen -arch zynqmp -image output.bif -o linux.bin -w on -log error

At U-Boot, use the below command to decrypt the image:

zynqmp secure <encrypted_img_addr> <size_of_img> <KUP_key_addr>

Where:

  • encrypted_img_addr is the DDR address where the encrypted image is loaded.

  • Size_of_img is the size of the encrypted image in bytes.

  • KUP_Key_addr is the DDR address of the KUP key (note: this needs to be loaded as plain text).

Please copy the boot image and encrypted image and key file (a text file containing plain text key in hex format). Power on the board and stop the boot flow at U-Boot. Load the encrypted image and KUP key onto the DDR from the SD using fatload commands.

Example of loading the encrypted image and KUP key:

Once you have loaded the encrypted image and KUP key onto DDR, perform the decryption with the above-mentioned secure command. See the below image for an example:

The U-Boot returns the start address of the decrypted image once it has decrypted successfully. If it fails, it returns an error code. Please check the XilSecure library for error codes.If the load address is specified when encrypting the image, then the decrypted image is loaded at the given address. If the load address is not provided, then the decrypted image is available at the 0x2800 offset where the encrypted image

loaded.UART log:

When we entered the Linux kernel address to boot, the kernel can be booted.

When we load the encrypted linux kernel directly, the kernel cannot be booted.

最后更新于