From patchwork Tue May 12 06:48:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 245618 List-Id: U-Boot discussion From: michal.simek at xilinx.com (Michal Simek) Date: Tue, 12 May 2020 08:48:26 +0200 Subject: [PATCH 1/5] fpga: zynqpl: Correct PL bitstream loading sequence for zynqaes In-Reply-To: References: Message-ID: <9c2a724799cf243beb848dad55328db36d07de65.1589266106.git.michal.simek@xilinx.com> From: Siva Durga Prasad Paladugu Correct the PL bitstream loading sequence for zynqaes command by clearing the loaded PL bitstream before loading the new encrypted bitstream using the zynq aes command. This was done by setting the PROG_B same as in case of fpgaload commands. This patch fixes the issue of loading the encrypted PL bitstream onto the PL in which a bitstream has already been loaded successfully. Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- board/xilinx/zynq/cmds.c | 7 +++++-- drivers/fpga/zynqpl.c | 7 ++++--- include/zynqpl.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/board/xilinx/zynq/cmds.c b/board/xilinx/zynq/cmds.c index 27d44b760daf..ebefbf22120c 100644 --- a/board/xilinx/zynq/cmds.c +++ b/board/xilinx/zynq/cmds.c @@ -396,7 +396,8 @@ static int zynq_verify_image(u32 src_ptr) status = zynq_decrypt_load(part_load_addr, part_img_len, part_dst_addr, - part_data_len); + part_data_len, + BIT_NONE); if (status != 0) { printf("DECRYPTION_FAIL\n"); return -1; @@ -435,6 +436,7 @@ static int zynq_decrypt_image(cmd_tbl_t *cmdtp, int flag, int argc, char *endp; u32 srcaddr, srclen, dstaddr, dstlen; int status; + u8 imgtype = BIT_NONE; if (argc < 5 && argc > cmdtp->maxargs) return CMD_RET_USAGE; @@ -461,7 +463,8 @@ static int zynq_decrypt_image(cmd_tbl_t *cmdtp, int flag, int argc, if (dstlen % 4) dstlen = roundup(dstlen, 4); - status = zynq_decrypt_load(srcaddr, srclen >> 2, dstaddr, dstlen >> 2); + status = zynq_decrypt_load(srcaddr, srclen >> 2, dstaddr, + dstlen >> 2, imgtype); if (status != 0) return CMD_RET_FAILURE; diff --git a/drivers/fpga/zynqpl.c b/drivers/fpga/zynqpl.c index 21624f715ba0..90a1f09f15e2 100644 --- a/drivers/fpga/zynqpl.c +++ b/drivers/fpga/zynqpl.c @@ -201,7 +201,7 @@ static int zynq_dma_xfer_init(bitstream_type bstype) /* Clear loopback bit */ clrbits_le32(&devcfg_base->mctrl, DEVCFG_MCTRL_PCAP_LPBK); - if (bstype != BIT_PARTIAL) { + if (bstype != BIT_PARTIAL && bstype != BIT_NONE) { zynq_slcr_devcfg_disable(); /* Setting PCFG_PROG_B signal to high */ @@ -508,7 +508,8 @@ struct xilinx_fpga_op zynq_op = { * Load the encrypted image from src addr and decrypt the image and * place it back the decrypted image into dstaddr. */ -int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen) +int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen, + u8 bstype) { if (srcaddr < SZ_1M || dstaddr < SZ_1M) { printf("%s: src and dst addr should be > 1M\n", @@ -516,7 +517,7 @@ int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen) return FPGA_FAIL; } - if (zynq_dma_xfer_init(BIT_NONE)) { + if (zynq_dma_xfer_init(bstype)) { printf("%s: zynq_dma_xfer_init FAIL\n", __func__); return FPGA_FAIL; } diff --git a/include/zynqpl.h b/include/zynqpl.h index 766e6918cd38..d7dc064585ea 100644 --- a/include/zynqpl.h +++ b/include/zynqpl.h @@ -12,7 +12,8 @@ #include #ifdef CONFIG_CMD_ZYNQ_AES -int zynq_decrypt_load(u32 srcaddr, u32 dstaddr, u32 srclen, u32 dstlen); +int zynq_decrypt_load(u32 srcaddr, u32 dstaddr, u32 srclen, u32 dstlen, + u8 bstype); #endif extern struct xilinx_fpga_op zynq_op; From patchwork Tue May 12 06:48:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 245619 List-Id: U-Boot discussion From: michal.simek at xilinx.com (Michal Simek) Date: Tue, 12 May 2020 08:48:27 +0200 Subject: [PATCH 2/5] fpga: zynqpl: Check fpga config completion In-Reply-To: References: Message-ID: <6c0c227f3c3536e08b4fec29293f7158f07858ab.1589266106.git.michal.simek@xilinx.com> From: T Karthik Reddy This patch checks fpga config completion when a bitstream is loaded into PL. Signed-off-by: T Karthik Reddy Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- drivers/fpga/zynqpl.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/fpga/zynqpl.c b/drivers/fpga/zynqpl.c index 90a1f09f15e2..3f3c97e144cd 100644 --- a/drivers/fpga/zynqpl.c +++ b/drivers/fpga/zynqpl.c @@ -511,6 +511,8 @@ struct xilinx_fpga_op zynq_op = { int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen, u8 bstype) { + u32 isr_status, ts; + if (srcaddr < SZ_1M || dstaddr < SZ_1M) { printf("%s: src and dst addr should be > 1M\n", __func__); @@ -541,8 +543,21 @@ int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen, if (zynq_dma_transfer(srcaddr | 1, srclen, dstaddr | 1, dstlen)) return FPGA_FAIL; - writel((readl(&devcfg_base->ctrl) & ~DEVCFG_CTRL_PCAP_RATE_EN_MASK), - &devcfg_base->ctrl); + if (bstype == BIT_FULL) { + isr_status = readl(&devcfg_base->int_sts); + /* Check FPGA configuration completion */ + ts = get_timer(0); + while (!(isr_status & DEVCFG_ISR_PCFG_DONE)) { + if (get_timer(ts) > CONFIG_SYS_FPGA_WAIT) { + printf("%s: Timeout wait for FPGA to config\n", + __func__); + return FPGA_FAIL; + } + isr_status = readl(&devcfg_base->int_sts); + } + printf("%s: FPGA config done\n", __func__); + zynq_slcr_devcfg_enable(); + } return FPGA_SUCCESS; } From patchwork Tue May 12 06:48:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 245620 List-Id: U-Boot discussion From: michal.simek at xilinx.com (Michal Simek) Date: Tue, 12 May 2020 08:48:28 +0200 Subject: [PATCH 3/5] fpga: zynqpl: Check if aes engine is enabled In-Reply-To: References: Message-ID: <203ffd1c3730bd2abc3c28cfc6fcbf10480cc198.1589266106.git.michal.simek@xilinx.com> From: Ibai Erkiaga AES engine cannot be used if has not been enabled at boot time with an encrypted boot image. Signed-off-by: Ibai Erkiaga Acked-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- drivers/fpga/zynqpl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/fpga/zynqpl.c b/drivers/fpga/zynqpl.c index 3f3c97e144cd..a323733ef363 100644 --- a/drivers/fpga/zynqpl.c +++ b/drivers/fpga/zynqpl.c @@ -19,6 +19,7 @@ #define DEVCFG_CTRL_PCFG_PROG_B 0x40000000 #define DEVCFG_CTRL_PCFG_AES_EFUSE_MASK 0x00001000 #define DEVCFG_CTRL_PCAP_RATE_EN_MASK 0x02000000 +#define DEVCFG_CTRL_PCFG_AES_EN_MASK 0x00000E00 #define DEVCFG_ISR_FATAL_ERROR_MASK 0x00740040 #define DEVCFG_ISR_ERROR_FLAGS_MASK 0x00340840 #define DEVCFG_ISR_RX_FIFO_OV 0x00040000 @@ -519,6 +520,13 @@ int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen, return FPGA_FAIL; } + /* Check AES engine is enabled */ + if (!(readl(&devcfg_base->ctrl) & + DEVCFG_CTRL_PCFG_AES_EN_MASK)) { + printf("%s: AES engine is not enabled\n", __func__); + return FPGA_FAIL; + } + if (zynq_dma_xfer_init(bstype)) { printf("%s: zynq_dma_xfer_init FAIL\n", __func__); return FPGA_FAIL; From patchwork Tue May 12 06:48:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 245621 List-Id: U-Boot discussion From: michal.simek at xilinx.com (Michal Simek) Date: Tue, 12 May 2020 08:48:29 +0200 Subject: [PATCH 4/5] fpga: zynqpl: Flush dcache only for non-bitstream data In-Reply-To: References: Message-ID: From: T Karthik Reddy In case of aes decryption destination address range must be flushed before transferring decrypted data to destination. Signed-off-by: T Karthik Reddy Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- drivers/fpga/zynqpl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/fpga/zynqpl.c b/drivers/fpga/zynqpl.c index a323733ef363..6fc5cf57238e 100644 --- a/drivers/fpga/zynqpl.c +++ b/drivers/fpga/zynqpl.c @@ -545,8 +545,9 @@ int zynq_decrypt_load(u32 srcaddr, u32 srclen, u32 dstaddr, u32 dstlen, * Flush destination address range only if image is not * bitstream. */ - flush_dcache_range((u32)dstaddr, (u32)dstaddr + - roundup(dstlen << 2, ARCH_DMA_MINALIGN)); + if (bstype == BIT_NONE && dstaddr != 0xFFFFFFFF) + flush_dcache_range((u32)dstaddr, (u32)dstaddr + + roundup(dstlen << 2, ARCH_DMA_MINALIGN)); if (zynq_dma_transfer(srcaddr | 1, srclen, dstaddr | 1, dstlen)) return FPGA_FAIL; From patchwork Tue May 12 06:48:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 245622 List-Id: U-Boot discussion From: michal.simek at xilinx.com (Michal Simek) Date: Tue, 12 May 2020 08:48:30 +0200 Subject: [PATCH 5/5] fpga: zynqpl: Add zynq aes load & loadp commands In-Reply-To: References: Message-ID: <34d4abcb386647b6d478d6d82a5876b5b0667e14.1589266106.git.michal.simek@xilinx.com> From: T Karthik Reddy Added support for zynq aes load & loadp commands. Signed-off-by: T Karthik Reddy Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- board/xilinx/zynq/cmds.c | 47 ++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/board/xilinx/zynq/cmds.c b/board/xilinx/zynq/cmds.c index ebefbf22120c..ee690a1e23a7 100644 --- a/board/xilinx/zynq/cmds.c +++ b/board/xilinx/zynq/cmds.c @@ -441,18 +441,37 @@ static int zynq_decrypt_image(cmd_tbl_t *cmdtp, int flag, int argc, if (argc < 5 && argc > cmdtp->maxargs) return CMD_RET_USAGE; - srcaddr = simple_strtoul(argv[2], &endp, 16); - if (*argv[2] == 0 || *endp != 0) - return CMD_RET_USAGE; - srclen = simple_strtoul(argv[3], &endp, 16); - if (*argv[3] == 0 || *endp != 0) - return CMD_RET_USAGE; - dstaddr = simple_strtoul(argv[4], &endp, 16); - if (*argv[4] == 0 || *endp != 0) - return CMD_RET_USAGE; - dstlen = simple_strtoul(argv[5], &endp, 16); - if (*argv[5] == 0 || *endp != 0) - return CMD_RET_USAGE; + if (argc == 5) { + if (!strcmp("load", argv[2])) + imgtype = BIT_FULL; + else if (!strcmp("loadp", argv[2])) + imgtype = BIT_PARTIAL; + else + return CMD_RET_USAGE; + + srcaddr = simple_strtoul(argv[3], &endp, 16); + if (*argv[3] == 0 || *endp != 0) + return CMD_RET_USAGE; + srclen = simple_strtoul(argv[4], &endp, 16); + if (*argv[4] == 0 || *endp != 0) + return CMD_RET_USAGE; + + dstaddr = 0xFFFFFFFF; + dstlen = srclen; + } else { + srcaddr = simple_strtoul(argv[2], &endp, 16); + if (*argv[2] == 0 || *endp != 0) + return CMD_RET_USAGE; + srclen = simple_strtoul(argv[3], &endp, 16); + if (*argv[3] == 0 || *endp != 0) + return CMD_RET_USAGE; + dstaddr = simple_strtoul(argv[4], &endp, 16); + if (*argv[4] == 0 || *endp != 0) + return CMD_RET_USAGE; + dstlen = simple_strtoul(argv[5], &endp, 16); + if (*argv[5] == 0 || *endp != 0) + return CMD_RET_USAGE; + } /* * Roundup source and destination lengths to @@ -516,6 +535,10 @@ static char zynq_help_text[] = " - Decrypts the encrypted image present in source\n" " address and places the decrypted image at\n" " destination address\n" + "aes load \n" + "aes loadp \n" + " if operation type is load or loadp, it loads the encrypted\n" + " full or partial bitstream on to PL respectively.\n" #endif ; #endif