]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
xilinx: zynqmp: Add support for loading encrypted images
authorSiva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Fri, 17 Feb 2017 10:46:02 +0000 (16:16 +0530)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 20 Feb 2017 14:53:09 +0000 (15:53 +0100)
This patch adds support for loading encrypted images by
decrypting and load back to memory.

Signed-off-by: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
board/xilinx/zynqmp/zynqmp.c

index 3da02c933cdc85904de1534a1d01cda1fb37b6bb..d22950e0d146a7e19f54deb59d729b5626695a29 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <aes.h>
 #include <sata.h>
 #include <ahci.h>
 #include <scsi.h>
@@ -310,6 +311,42 @@ int board_late_init(void)
        return 0;
 }
 
+#if defined(CONFIG_AES)
+
+#define KEY_LEN                                64
+#define IV_LEN                         24
+#define ZYNQMP_SIP_SVC_PM_SECURE_LOAD  0xC2000019
+#define ZYNQMP_PM_SECURE_AES           0x1
+
+int aes_decrypt_hw(u8 *key_ptr, u8 *src_ptr, u8 *dst_ptr, u32 len)
+{
+       int ret;
+       u32 src_lo, src_hi, wlen;
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+
+       if ((ulong)src_ptr != ALIGN((ulong)src_ptr,
+                                   CONFIG_SYS_CACHELINE_SIZE)) {
+               debug("FAIL: Source address not aligned:%p\n", src_ptr);
+               return -EINVAL;
+       }
+
+       src_lo = (u32)(ulong)src_ptr;
+       src_hi = upper_32_bits((ulong)src_ptr);
+       wlen = DIV_ROUND_UP(len, 4);
+
+       memcpy(src_ptr + len, key_ptr, KEY_LEN + IV_LEN);
+       len = ROUND(len + KEY_LEN + IV_LEN, CONFIG_SYS_CACHELINE_SIZE);
+       flush_dcache_range((ulong)src_ptr, (ulong)(src_ptr + len));
+
+       ret = invoke_smc(ZYNQMP_SIP_SVC_PM_SECURE_LOAD, src_lo, src_hi, wlen,
+                        ZYNQMP_PM_SECURE_AES, ret_payload);
+       if (ret)
+               debug("aes_decrypt_hw fail\n");
+
+       return ret;
+}
+#endif
+
 int checkboard(void)
 {
        puts("Board: Xilinx ZynqMP\n");