All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code
@ 2018-05-31  9:40 Siva Durga Prasad Paladugu
  2018-05-31  9:40 ` [U-Boot] [PATCH v2 2/3] cmd: fpga: Add support to load secure bitstreams Siva Durga Prasad Paladugu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Siva Durga Prasad Paladugu @ 2018-05-31  9:40 UTC (permalink / raw)
  To: u-boot

This patch modifies the arguments parsing code by parsing
based on requested operation for fpga loadfs and then
parses the most common/basic args for other fpga load
commands. This makes it easy for new command extensions
or additions especially the commands with more args.

Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
---
Changes for v2:
- Correct the argc check as per comment.
---
 cmd/fpga.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/cmd/fpga.c b/cmd/fpga.c
index 14ad4e5..3f09d42 100644
--- a/cmd/fpga.c
+++ b/cmd/fpga.c
@@ -60,15 +60,31 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
        if (datastr)
                fpga_data = (void *)simple_strtoul(datastr, NULL, 16);

-       switch (argc) {
+       if (argc > 9 || argc < 2) {
+               debug("%s: Too many or too few args (%d)\n", __func__, argc);
+               return CMD_RET_USAGE;
+       }
+
+       op = (int)fpga_get_op(argv[1]);
+
+       switch (op) {
 #if defined(CONFIG_CMD_FPGA_LOADFS)
-       case 9:
+       case FPGA_LOADFS:
+               if (argc < 9)
+                       return CMD_RET_USAGE;
                fpga_fsinfo.blocksize = (unsigned int)
-                                            simple_strtoul(argv[5], NULL, 16);
+                                       simple_strtoul(argv[5], NULL, 16);
                fpga_fsinfo.interface = argv[6];
                fpga_fsinfo.dev_part = argv[7];
                fpga_fsinfo.filename = argv[8];
+               argc = 5;
+               break;
 #endif
+       default:
+               break;
+       }
+
+       switch (argc) {
        case 5:         /* fpga <op> <dev> <data> <datasize> */
                data_size = simple_strtoul(argv[4], NULL, 16);

@@ -117,15 +133,6 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                              __func__, (ulong)fpga_data);
                        dev = FPGA_INVALID_DEVICE;      /* reset device num */
                }
-
-       case 2:         /* fpga <op> */
-               op = (int)fpga_get_op(argv[1]);
-               break;
-
-       default:
-               debug("%s: Too many or too few args (%d)\n", __func__, argc);
-               op = FPGA_NONE; /* force usage display */
-               break;
        }

        if (dev == FPGA_INVALID_DEVICE) {
--
2.7.4

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v2 2/3] cmd: fpga: Add support to load secure bitstreams
  2018-05-31  9:40 [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code Siva Durga Prasad Paladugu
@ 2018-05-31  9:40 ` Siva Durga Prasad Paladugu
  2018-05-31  9:40 ` [U-Boot] [PATCH v2 3/3] fpga: zynqmp: Add secure bitstream loading for ZynqMP Siva Durga Prasad Paladugu
  2018-06-01 13:24 ` [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code Michal Simek
  2 siblings, 0 replies; 4+ messages in thread
From: Siva Durga Prasad Paladugu @ 2018-05-31  9:40 UTC (permalink / raw)
  To: u-boot

This patch adds support to load secure bitstreams(authenticated or
encrypted or both). As of now, this feature is added and tested only
for xilinx bitstreams and the secure bitstream was generated using
xilinx bootgen tool, but the command is defined in more generic way.

Command example to load authenticated and device key
encrypted bitstream is as follows
"fpga loads 0 100000 2000000 0 1"

Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
---
Changes for v2:
- None
---
 cmd/Kconfig         |  7 ++++++
 cmd/fpga.c          | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 drivers/fpga/fpga.c | 29 +++++++++++++++++++++++++
 include/fpga.h      | 11 ++++++++++
 4 files changed, 108 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 38406fc..9b9eb94 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -697,6 +697,13 @@ config CMD_FPGA_LOADP
          Supports loading an FPGA device from a bitstream buffer containing
          a partial bitstream.

+config CMD_FPGA_LOAD_SECURE
+       bool "fpga loads - loads secure bitstreams (Xilinx only)"
+       depends on CMD_FPGA
+       help
+         Enables the fpga loads command which is used to load secure
+         (authenticated or encrypted or both) bitstreams on to FPGA.
+
 config CMD_FPGAD
        bool "fpgad - dump FPGA registers"
        help
diff --git a/cmd/fpga.c b/cmd/fpga.c
index 3f09d42..74ae80c 100644
--- a/cmd/fpga.c
+++ b/cmd/fpga.c
@@ -27,6 +27,7 @@ enum {
        FPGA_LOADP,
        FPGA_LOADBP,
        FPGA_LOADFS,
+       FPGA_LOADS,
 };

 /* ------------------------------------------------------------------------- */
@@ -54,6 +55,11 @@ 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)
+       struct 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);
@@ -80,6 +86,19 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                argc = 5;
                break;
 #endif
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+       case FPGA_LOADS:
+               if (argc < 7)
+                       return CMD_RET_USAGE;
+               if (argc == 8)
+                       fpga_sec_info.userkey_addr = (u8 *)(uintptr_t)
+                                                    simple_strtoull(argv[7],
+                                                                    NULL, 16);
+               fpga_sec_info.encflag = (u8)simple_strtoul(argv[6], NULL, 16);
+               fpga_sec_info.authflag = (u8)simple_strtoul(argv[5], NULL, 16);
+               argc = 5;
+               break;
+#endif
        default:
                break;
        }
@@ -150,6 +169,22 @@ 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;
+               break;
+#endif
+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE)
+       case FPGA_LOADS:
+               if (fpga_sec_info.authflag >= FPGA_NO_ENC_OR_NO_AUTH &&
+                   fpga_sec_info.encflag >= FPGA_NO_ENC_OR_NO_AUTH) {
+                       puts("ERR: use <fpga load> for NonSecure bitstream\n");
+                       wrong_parms = 1;
+               }
+
+               if (fpga_sec_info.encflag == FPGA_ENC_USR_KEY &&
+                   !fpga_sec_info.userkey_addr) {
+                       wrong_parms = 1;
+                       puts("ERR:User key not provided\n");
+               }
+               break;
 #endif
        case FPGA_LOAD:
        case FPGA_LOADP:
@@ -206,6 +241,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)) {
@@ -339,6 +380,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);
@@ -346,7 +391,7 @@ static int fpga_get_op(char *opstr)
        return op;
 }

-#if defined(CONFIG_CMD_FPGA_LOADFS)
+#if defined(CONFIG_CMD_FPGA_LOADFS) || defined(CONFIG_CMD_FPGA_LOAD_SECURE)
 U_BOOT_CMD(fpga, 9, 1, do_fpga,
 #else
 U_BOOT_CMD(fpga, 6, 1, do_fpga,
@@ -381,4 +426,19 @@ 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] [auth-OCM-0/DDR-1/noauth-2]\n"
+          "        [enc-devkey(0)/userkey(1)/nenc(2) [Userkey address]\n"
+          "Loads the secure bistreams(authenticated/encrypted/both\n"
+          "authenticated and encrypted) of [size] from [address].\n"
+          "The auth-OCM/DDR flag specifies to perform authentication\n"
+          "in OCM or in DDR. 0 for OCM, 1 for DDR, 2 for no authentication.\n"
+          "The enc flag specifies which key to be used for decryption\n"
+          "0-device key, 1-user key, 2-no encryption.\n"
+          "The optional Userkey address specifies from which address key\n"
+          "has to be used for decryption if user key is selected.\n"
+          "NOTE: the sceure bitstream has to be created using xilinx\n"
+          "bootgen tool only.\n"
+#endif
 );
diff --git a/drivers/fpga/fpga.c b/drivers/fpga/fpga.c
index 55bdf9e..7e8bd7e 100644
--- a/drivers/fpga/fpga.c
+++ b/drivers/fpga/fpga.c
@@ -217,6 +217,35 @@ 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,
+              struct fpga_secure_info *fpga_sec_info)
+{
+       int ret_val = FPGA_FAIL;
+
+       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/include/fpga.h b/include/fpga.h
index f444093..195f0bd 100644
--- a/include/fpga.h
+++ b/include/fpga.h
@@ -20,6 +20,9 @@
 /* device numbers must be non-negative */
 #define FPGA_INVALID_DEVICE    -1

+#define FPGA_ENC_USR_KEY       1
+#define FPGA_NO_ENC_OR_NO_AUTH 2
+
 /* root data type defintions */
 typedef enum {                 /* typedef fpga_type */
        fpga_min_type,          /* range check value */
@@ -42,6 +45,12 @@ typedef struct {                /* typedef fpga_desc */
        int fstype;
 } fpga_fs_info;

+struct fpga_secure_info {
+       u8 *userkey_addr;
+       u8 authflag;
+       u8 encflag;
+};
+
 typedef enum {
        BIT_FULL = 0,
        BIT_PARTIAL,
@@ -58,6 +67,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,
+              struct 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);
--
2.7.4

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v2 3/3] fpga: zynqmp: Add secure bitstream loading for ZynqMP
  2018-05-31  9:40 [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code Siva Durga Prasad Paladugu
  2018-05-31  9:40 ` [U-Boot] [PATCH v2 2/3] cmd: fpga: Add support to load secure bitstreams Siva Durga Prasad Paladugu
@ 2018-05-31  9:40 ` Siva Durga Prasad Paladugu
  2018-06-01 13:24 ` [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code Michal Simek
  2 siblings, 0 replies; 4+ messages in thread
From: Siva Durga Prasad Paladugu @ 2018-05-31  9:40 UTC (permalink / raw)
  To: u-boot

This patch adds support for loading secure bitstreams on ZynqMP
platforms. The secure bitstream images has to be generated using
Xilinx bootgen tool.

Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
---
Changes for v2:
- None
---
 arch/arm/include/asm/arch-zynqmp/sys_proto.h  |  6 ++++
 configs/xilinx_zynqmp_zcu102_rev1_0_defconfig |  1 +
 drivers/fpga/xilinx.c                         | 18 ++++++++++
 drivers/fpga/zynqmppl.c                       | 48 +++++++++++++++++++++++++++
 include/xilinx.h                              |  4 +++
 include/zynqmppl.h                            |  3 ++
 6 files changed, 80 insertions(+)

diff --git a/arch/arm/include/asm/arch-zynqmp/sys_proto.h b/arch/arm/include/asm/arch-zynqmp/sys_proto.h
index 6056bc6..773b930 100644
--- a/arch/arm/include/asm/arch-zynqmp/sys_proto.h
+++ b/arch/arm/include/asm/arch-zynqmp/sys_proto.h
@@ -13,8 +13,14 @@
 #define ZYNQMP_SIP_SVC_PM_SECURE_IMG_LOAD      0xC200002D
 #define KEY_PTR_LEN    32

+#define ZYNQMP_FPGA_BIT_AUTH_DDR       1
+#define ZYNQMP_FPGA_BIT_AUTH_OCM       2
+#define ZYNQMP_FPGA_BIT_ENC_USR_KEY    3
+#define ZYNQMP_FPGA_BIT_ENC_DEV_KEY    4
 #define ZYNQMP_FPGA_BIT_NS             5

+#define ZYNQMP_FPGA_AUTH_DDR   1
+
 enum {
        IDCODE,
        VERSION,
diff --git a/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig b/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig
index 4cb3959..1379f14 100644
--- a/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig
+++ b/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig
@@ -31,6 +31,7 @@ CONFIG_CMD_DFU=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_FPGA_LOADBP=y
 CONFIG_CMD_FPGA_LOADP=y
+CONFIG_CMD_FPGA_LOAD_SECURE=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
diff --git a/drivers/fpga/xilinx.c b/drivers/fpga/xilinx.c
index 724304a..f513550 100644
--- a/drivers/fpga/xilinx.c
+++ b/drivers/fpga/xilinx.c
@@ -171,6 +171,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,
+                struct 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 loads 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/drivers/fpga/zynqmppl.c b/drivers/fpga/zynqmppl.c
index b57623b..03ffa8c 100644
--- a/drivers/fpga/zynqmppl.c
+++ b/drivers/fpga/zynqmppl.c
@@ -223,6 +223,51 @@ static int zynqmp_load(xilinx_desc *desc, const void *buf, size_t bsize,
        return ret;
 }

+#if defined(CONFIG_CMD_FPGA_LOAD_SECURE) && !defined(CONFIG_SPL_BUILD)
+static int zynqmp_loads(xilinx_desc *desc, const void *buf, size_t bsize,
+                       struct fpga_secure_info *fpga_sec_info)
+{
+       int ret;
+       u32 buf_lo, buf_hi;
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+       u8 flag = 0;
+
+       flush_dcache_range((ulong)buf, (ulong)buf +
+                          ALIGN(bsize, CONFIG_SYS_CACHELINE_SIZE));
+
+       if (!fpga_sec_info->encflag)
+               flag |= BIT(ZYNQMP_FPGA_BIT_ENC_DEV_KEY);
+
+       if (fpga_sec_info->userkey_addr &&
+           fpga_sec_info->encflag == FPGA_ENC_USR_KEY) {
+               flush_dcache_range((ulong)fpga_sec_info->userkey_addr,
+                                  (ulong)fpga_sec_info->userkey_addr +
+                                  ALIGN(KEY_PTR_LEN,
+                                        CONFIG_SYS_CACHELINE_SIZE));
+               flag |= BIT(ZYNQMP_FPGA_BIT_ENC_USR_KEY);
+       }
+
+       if (!fpga_sec_info->authflag)
+               flag |= BIT(ZYNQMP_FPGA_BIT_AUTH_OCM);
+
+       if (fpga_sec_info->authflag == ZYNQMP_FPGA_AUTH_DDR)
+               flag |= BIT(ZYNQMP_FPGA_BIT_AUTH_DDR);
+
+       buf_lo = lower_32_bits((ulong)buf);
+       buf_hi = upper_32_bits((ulong)buf);
+
+       ret = invoke_smc(ZYNQMP_SIP_SVC_PM_FPGA_LOAD, buf_lo, buf_hi,
+                        (u32)(uintptr_t)fpga_sec_info->userkey_addr,
+                        flag, ret_payload);
+       if (ret)
+               puts("PL FPGA LOAD fail\n");
+       else
+               puts("Bitstream successfully loaded\n");
+
+       return ret;
+}
+#endif
+
 static int zynqmp_pcap_info(xilinx_desc *desc)
 {
        int ret;
@@ -238,5 +283,8 @@ static int zynqmp_pcap_info(xilinx_desc *desc)

 struct xilinx_fpga_op zynqmp_op = {
        .load = zynqmp_load,
+#if defined CONFIG_CMD_FPGA_LOAD_SECURE
+       .loads = zynqmp_loads,
+#endif
        .info = zynqmp_pcap_info,
 };
diff --git a/include/xilinx.h b/include/xilinx.h
index 9429f51..af40bef 100644
--- a/include/xilinx.h
+++ b/include/xilinx.h
@@ -48,6 +48,8 @@ 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 *desc, const void *buf, size_t bsize,
+                    struct fpga_secure_info *fpga_sec_info);
        int (*dump)(xilinx_desc *, const void *, size_t);
        int (*info)(xilinx_desc *);
 };
@@ -60,6 +62,8 @@ 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,
+                struct fpga_secure_info *fpga_sec_info);

 /* Board specific implementation specific function types
  *********************************************************************/
diff --git a/include/zynqmppl.h b/include/zynqmppl.h
index a0f4e68..5214db9 100644
--- a/include/zynqmppl.h
+++ b/include/zynqmppl.h
@@ -16,6 +16,9 @@
 #define ZYNQMP_FPGA_OP_LOAD                    (1 << 1)
 #define ZYNQMP_FPGA_OP_DONE                    (1 << 2)

+#define ZYNQMP_FPGA_FLAG_AUTHENTICATED         BIT(2)
+#define ZYNQMP_FPGA_FLAG_ENCRYPTED             BIT(3)
+
 #define ZYNQMP_CSU_IDCODE_DEVICE_CODE_SHIFT    15
 #define ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK     (0xf << \
                                        ZYNQMP_CSU_IDCODE_DEVICE_CODE_SHIFT)
--
2.7.4

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code
  2018-05-31  9:40 [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code Siva Durga Prasad Paladugu
  2018-05-31  9:40 ` [U-Boot] [PATCH v2 2/3] cmd: fpga: Add support to load secure bitstreams Siva Durga Prasad Paladugu
  2018-05-31  9:40 ` [U-Boot] [PATCH v2 3/3] fpga: zynqmp: Add secure bitstream loading for ZynqMP Siva Durga Prasad Paladugu
@ 2018-06-01 13:24 ` Michal Simek
  2 siblings, 0 replies; 4+ messages in thread
From: Michal Simek @ 2018-06-01 13:24 UTC (permalink / raw)
  To: u-boot

On 31.5.2018 11:40, Siva Durga Prasad Paladugu wrote:
> This patch modifies the arguments parsing code by parsing
> based on requested operation for fpga loadfs and then
> parses the most common/basic args for other fpga load
> commands. This makes it easy for new command extensions
> or additions especially the commands with more args.
> 
> Signed-off-by: Siva Durga Prasad Paladugu <siva.durga.paladugu@xilinx.com>
> ---
> Changes for v2:
> - Correct the argc check as per comment.
> ---
>  cmd/fpga.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/cmd/fpga.c b/cmd/fpga.c
> index 14ad4e5..3f09d42 100644
> --- a/cmd/fpga.c
> +++ b/cmd/fpga.c
> @@ -60,15 +60,31 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
>  	if (datastr)
>  		fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
>  
> -	switch (argc) {
> +	if (argc > 9 || argc < 2) {
> +		debug("%s: Too many or too few args (%d)\n", __func__, argc);
> +		return CMD_RET_USAGE;
> +	}
> +
> +	op = (int)fpga_get_op(argv[1]);
> +
> +	switch (op) {
>  #if defined(CONFIG_CMD_FPGA_LOADFS)
> -	case 9:
> +	case FPGA_LOADFS:
> +		if (argc < 9)
> +			return CMD_RET_USAGE;
>  		fpga_fsinfo.blocksize = (unsigned int)
> -					     simple_strtoul(argv[5], NULL, 16);
> +					simple_strtoul(argv[5], NULL, 16);
>  		fpga_fsinfo.interface = argv[6];
>  		fpga_fsinfo.dev_part = argv[7];
>  		fpga_fsinfo.filename = argv[8];
> +		argc = 5;
> +		break;
>  #endif
> +	default:
> +		break;
> +	}
> +
> +	switch (argc) {
>  	case 5:		/* fpga <op> <dev> <data> <datasize> */
>  		data_size = simple_strtoul(argv[4], NULL, 16);
>  
> @@ -117,15 +133,6 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
>  			      __func__, (ulong)fpga_data);
>  			dev = FPGA_INVALID_DEVICE;	/* reset device num */
>  		}
> -
> -	case 2:		/* fpga <op> */
> -		op = (int)fpga_get_op(argv[1]);
> -		break;
> -
> -	default:
> -		debug("%s: Too many or too few args (%d)\n", __func__, argc);
> -		op = FPGA_NONE;	/* force usage display */
> -		break;
>  	}
>  
>  	if (dev == FPGA_INVALID_DEVICE) {
> 


Applied all.

Thanks,
Michal

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-01 13:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-31  9:40 [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code Siva Durga Prasad Paladugu
2018-05-31  9:40 ` [U-Boot] [PATCH v2 2/3] cmd: fpga: Add support to load secure bitstreams Siva Durga Prasad Paladugu
2018-05-31  9:40 ` [U-Boot] [PATCH v2 3/3] fpga: zynqmp: Add secure bitstream loading for ZynqMP Siva Durga Prasad Paladugu
2018-06-01 13:24 ` [U-Boot] [PATCH v2 1/3] cmd: fpga: Reorder the arguments parsing code Michal Simek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.