From: Siva Durga Prasad Paladugu Date: Tue, 14 Feb 2017 10:27:20 +0000 (+0530) Subject: fpga: xilinx: Add support for loading encrypted bitstreams X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7abfec8e31e8b4721a6c050cca6d3f1235765279;p=thirdparty%2Fu-boot.git fpga: xilinx: Add support for loading encrypted bitstreams This patch adds support to load encrypted bitstreams using new command "fpga loads". Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- diff --git a/cmd/fpga.c b/cmd/fpga.c index 8956eb1b654..1904dc00fb5 100644 --- a/cmd/fpga.c +++ b/cmd/fpga.c @@ -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 */ 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:" #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 ); diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c index e0fb1b4e783..e98b9bd2193 100644 --- a/drivers/fpga/fpga.c +++ b/drivers/fpga/fpga.c @@ -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 */ diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c index 2cd0104d8b1..c622b159e7b 100644 --- a/drivers/fpga/xilinx.c +++ b/drivers/fpga/xilinx.c @@ -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__)) { diff --git a/include/fpga.h b/include/fpga.h index d768fb14171..a5742a1d6a2 100644 --- a/include/fpga.h +++ b/include/fpga.h @@ -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); diff --git a/include/xilinx.h b/include/xilinx.h index d2a2ea71e12..e94a955f8ee 100644 --- a/include/xilinx.h +++ b/include/xilinx.h @@ -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 *********************************************************************/