]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fpga: xilinx: Add support for loading encrypted bitstreams
authorSiva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
Tue, 14 Feb 2017 10:27:20 +0000 (15:57 +0530)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 20 Feb 2017 14:42:46 +0000 (15:42 +0100)
This patch adds support to load encrypted bitstreams using
new command "fpga loads".

Signed-off-by: Siva Durga Prasad Paladugu <sivadur@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
cmd/fpga.c
drivers/fpga/fpga.c
drivers/fpga/xilinx.c
include/fpga.h
include/xilinx.h

index 8956eb1b654adf4caef2681b8f8a6b93e1245583..1904dc00fb512655f77fe682b7e6065d8a37a60a 100644 (file)
@@ -27,6 +27,7 @@ static int fpga_get_op(char *opstr);
 #define FPGA_LOADP  5
 #define FPGA_LOADBP 6
 #define FPGA_LOADFS 7
+#define FPGA_LOADS  8
 
 /* ------------------------------------------------------------------------- */
 /* command form:
@@ -53,6 +54,10 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
        fpga_fs_info fpga_fsinfo;
        fpga_fsinfo.fstype = FS_TYPE_ANY;
 #endif
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+       fpga_secure_info fpga_sec_info;
+       memset(&fpga_sec_info, 0, sizeof(fpga_sec_info));
+#endif
 
        if (devstr)
                dev = (int) simple_strtoul(devstr, NULL, 16);
@@ -67,6 +72,11 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                fpga_fsinfo.interface = argv[6];
                fpga_fsinfo.dev_part = argv[7];
                fpga_fsinfo.filename = argv[8];
+#endif
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+       case 7:
+               fpga_sec_info.ivaddr_size = argv[6];
+               fpga_sec_info.keyaddr_size = argv[5];
 #endif
        case 5:         /* fpga <op> <dev> <data> <datasize> */
                data_size = simple_strtoul(argv[4], NULL, 16);
@@ -142,6 +152,11 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                if (!fpga_fsinfo.interface || !fpga_fsinfo.dev_part ||
                    !fpga_fsinfo.filename)
                        wrong_parms = 1;
+#endif
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+       case FPGA_LOADS:
+               if (!fpga_sec_info.keyaddr_size || !fpga_sec_info.keyaddr_size)
+                       wrong_parms = 1;
 #endif
        case FPGA_LOAD:
        case FPGA_LOADP:
@@ -198,6 +213,12 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                break;
 #endif
 
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+       case FPGA_LOADS:
+               rc = fpga_loads(dev, fpga_data, data_size, &fpga_sec_info);
+               break;
+#endif
+
 #if defined(CONFIG_CMD_FPGA_LOADMK)
        case FPGA_LOADMK:
                switch (genimg_get_format(fpga_data)) {
@@ -331,6 +352,10 @@ static int fpga_get_op(char *opstr)
 #endif
        else if (!strcmp("dump", opstr))
                op = FPGA_DUMP;
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+       else if (!strcmp("loads", opstr))
+               op = FPGA_LOADS;
+#endif
 
        if (op == FPGA_NONE)
                printf("Unknown fpga operation \"%s\"\n", opstr);
@@ -341,7 +366,7 @@ static int fpga_get_op(char *opstr)
 #if defined(CONFIG_CMD_FPGA_LOADFS)
 U_BOOT_CMD(fpga, 9, 1, do_fpga,
 #else
-U_BOOT_CMD(fpga, 6, 1, do_fpga,
+U_BOOT_CMD(fpga, 7, 1, do_fpga,
 #endif
           "loadable FPGA image support",
           "[operation type] [device number] [image address] [image size]\n"
@@ -373,4 +398,8 @@ U_BOOT_CMD(fpga, 6, 1, do_fpga,
           "\tsubimage unit name in the form of addr:<subimg_uname>"
 #endif
 #endif
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+          "Load encrypted bitstream (Xilinx only)\n"
+          "  loads [dev] [address] [size] [keyaddr:size] [IVaddr:size]\n"
+#endif
 );
index e0fb1b4e783b7527bf43185cf7c053fc7c3fa0d9..e98b9bd219395699dea62a8ad9b782423cbc92ec 100644 (file)
@@ -208,6 +208,34 @@ int fpga_fsload(int devnum, const void *buf, size_t size,
 }
 #endif
 
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+int fpga_loads(int devnum, const void *buf, size_t size,
+              fpga_secure_info *fpga_sec_info)
+{
+       int ret_val = FPGA_FAIL;           /* assume failure */
+       const fpga_desc *desc = fpga_validate(devnum, buf, size,
+                                             (char *)__func__);
+
+       if (desc) {
+               switch (desc->devtype) {
+               case fpga_xilinx:
+#if defined(CONFIG_FPGA_XILINX)
+                       ret_val = xilinx_loads(desc->devdesc, buf, size,
+                                              fpga_sec_info);
+#else
+                       fpga_no_sup((char *)__func__, "Xilinx devices");
+#endif
+                       break;
+               default:
+                       printf("%s: Invalid or unsupported device type %d\n",
+                              __func__, desc->devtype);
+               }
+       }
+
+       return ret_val;
+}
+#endif
+
 /*
  * Generic multiplexing code
  */
index 2cd0104d8b154b35f8c85de42e50028ad614d57a..c622b159e7bb7733f987134e68c6f4179cee0417 100644 (file)
@@ -165,6 +165,24 @@ int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
 }
 #endif
 
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+int xilinx_loads(xilinx_desc *desc, const void *buf, size_t bsize,
+                fpga_secure_info *fpga_sec_info)
+{
+       if (!xilinx_validate(desc, (char *)__func__)) {
+               printf("%s: Invalid device descriptor\n", __func__);
+               return FPGA_FAIL;
+       }
+
+       if (!desc->operations || !desc->operations->loads) {
+               printf("%s: Missing loade operation\n", __func__);
+               return FPGA_FAIL;
+       }
+
+       return desc->operations->loads(desc, buf, bsize, fpga_sec_info);
+}
+#endif
+
 int xilinx_dump(xilinx_desc *desc, const void *buf, size_t bsize)
 {
        if (!xilinx_validate (desc, (char *)__FUNCTION__)) {
index d768fb14171af5744b799e9e81f65e03ca95e6ab..a5742a1d6a2d311cf728ea206cac22cbef0c421e 100644 (file)
@@ -43,6 +43,11 @@ typedef struct {                /* typedef fpga_desc */
        int fstype;
 } fpga_fs_info;
 
+typedef struct {
+       char *keyaddr_size;
+       char *ivaddr_size;
+} fpga_secure_info;
+
 typedef enum {
        BIT_FULL = 0,
        BIT_PARTIAL,
@@ -58,6 +63,8 @@ int fpga_load(int devnum, const void *buf, size_t bsize,
              bitstream_type bstype);
 int fpga_fsload(int devnum, const void *buf, size_t size,
                fpga_fs_info *fpga_fsinfo);
+int fpga_loads(int devnum, const void *buf, size_t size,
+              fpga_secure_info *fpga_sec_info);
 int fpga_loadbitstream(int devnum, char *fpgadata, size_t size,
                       bitstream_type bstype);
 int fpga_dump(int devnum, const void *buf, size_t bsize);
index d2a2ea71e1211a4b8382c3ec29297e86b9288984..e94a955f8eeebd75e039ed3ada49183d7f7dca95 100644 (file)
@@ -49,6 +49,7 @@ typedef struct {              /* typedef xilinx_desc */
 struct xilinx_fpga_op {
        int (*load)(xilinx_desc *, const void *, size_t, bitstream_type);
        int (*loadfs)(xilinx_desc *, const void *, size_t, fpga_fs_info *);
+       int (*loads)(xilinx_desc *, const void *, size_t, fpga_secure_info *);
        int (*dump)(xilinx_desc *, const void *, size_t);
        int (*info)(xilinx_desc *);
 };
@@ -61,6 +62,9 @@ int xilinx_dump(xilinx_desc *desc, const void *buf, size_t bsize);
 int xilinx_info(xilinx_desc *desc);
 int xilinx_loadfs(xilinx_desc *desc, const void *buf, size_t bsize,
                  fpga_fs_info *fpga_fsinfo);
+int xilinx_loads(xilinx_desc *desc, const void *buf, size_t bsize,
+                fpga_secure_info *fpga_sec_info);
+
 
 /* Board specific implementation specific function types
  *********************************************************************/