From patchwork Sun May 17 08:37:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayagonda Kokatanur X-Patchwork-Id: 245910 List-Id: U-Boot discussion From: rayagonda.kokatanur at broadcom.com (Rayagonda Kokatanur) Date: Sun, 17 May 2020 14:07:03 +0530 Subject: [PATCH v1 1/3] cmd: bcm: add nitro boot command In-Reply-To: <20200517083705.22508-1-rayagonda.kokatanur@broadcom.com> References: <20200517083705.22508-1-rayagonda.kokatanur@broadcom.com> Message-ID: <20200517083705.22508-2-rayagonda.kokatanur@broadcom.com> From: Trac Hoang Add command to boot nitro. Signed-off-by: Trac Hoang Signed-off-by: Rayagonda Kokatanur --- cmd/bcm/Makefile | 1 + cmd/bcm/chimp_boot.c | 36 ++++++++++++++++++++++++++++++++++++ include/brcm/chimp.h | 2 ++ 3 files changed, 39 insertions(+) create mode 100644 cmd/bcm/chimp_boot.c diff --git a/cmd/bcm/Makefile b/cmd/bcm/Makefile index 96dc8f7ad7..dc274f6b96 100644 --- a/cmd/bcm/Makefile +++ b/cmd/bcm/Makefile @@ -2,3 +2,4 @@ # Copyright 2020 Broadcom obj-$(CONFIG_CMD_BCM_LOGSETUP) += logsetup.o +obj-y += chimp_boot.o diff --git a/cmd/bcm/chimp_boot.c b/cmd/bcm/chimp_boot.c new file mode 100644 index 0000000000..dcab9a5bcb --- /dev/null +++ b/cmd/bcm/chimp_boot.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 Broadcom + */ + +#include +#include +#include + +static int do_chimp_fastboot_secure(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + u32 health = 0; + + if (chimp_health_status_optee(&health) != BCM_CHIMP_SUCCESS) { + pr_err("Chimp health command fail\n"); + return CMD_RET_FAILURE; + } + + if (health == BCM_CHIMP_RUNNIG_GOOD) { + printf("skip fastboot...\n"); + return CMD_RET_SUCCESS; + } + + if (chimp_fastboot_optee() != BCM_CHIMP_SUCCESS) { + pr_err("Failed to load secure ChiMP image\n"); + return CMD_RET_FAILURE; + } + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD + (chimp_ld_secure, 1, 0, do_chimp_fastboot_secure, + "Invoke chimp fw load via optee", + "chimp_ld_secure\n" +); diff --git a/include/brcm/chimp.h b/include/brcm/chimp.h index c3d4594c4b..9099a70ef5 100644 --- a/include/brcm/chimp.h +++ b/include/brcm/chimp.h @@ -13,6 +13,8 @@ #define BCM_CHIMP_SUCCESS 0 #define BCM_CHIMP_FAILURE (!BCM_CHIMP_SUCCESS) +#define BCM_CHIMP_RUNNIG_GOOD 0x8000 + #ifdef CONFIG_CHIMP_OPTEE int chimp_fastboot_optee(void); int chimp_health_status_optee(u32 *status); From patchwork Sun May 17 08:37:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayagonda Kokatanur X-Patchwork-Id: 245911 List-Id: U-Boot discussion From: rayagonda.kokatanur at broadcom.com (Rayagonda Kokatanur) Date: Sun, 17 May 2020 14:07:04 +0530 Subject: [PATCH v1 2/3] cmd: bcm: add nitro image load commands In-Reply-To: <20200517083705.22508-1-rayagonda.kokatanur@broadcom.com> References: <20200517083705.22508-1-rayagonda.kokatanur@broadcom.com> Message-ID: <20200517083705.22508-3-rayagonda.kokatanur@broadcom.com> From: Vikas Gupta Add nitro image load commands. Signed-off-by: Vikas Gupta Signed-off-by: Rayagonda Kokatanur Reviewed-by: Simon Glass --- cmd/bcm/Makefile | 1 + cmd/bcm/nitro_image_load.c | 99 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 cmd/bcm/nitro_image_load.c diff --git a/cmd/bcm/Makefile b/cmd/bcm/Makefile index dc274f6b96..671c0fbd43 100644 --- a/cmd/bcm/Makefile +++ b/cmd/bcm/Makefile @@ -3,3 +3,4 @@ obj-$(CONFIG_CMD_BCM_LOGSETUP) += logsetup.o obj-y += chimp_boot.o +obj-y += nitro_image_load.o diff --git a/cmd/bcm/nitro_image_load.c b/cmd/bcm/nitro_image_load.c new file mode 100644 index 0000000000..e460b91338 --- /dev/null +++ b/cmd/bcm/nitro_image_load.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 Broadcom + */ + +#include +#include + +#define NITRO_FW_IMAGE_SIG 0xFF123456 +#define NITRO_NS3_CFG_IMAGE_SIG 0xCF54321A + +/*structure for Nitro bin file + * signature: Nitro fw itb file + * size: Nitro fw itb file + * signature: Nitro NS3 config file + * size: Nitro NS3 config file + * Data: Nitro fw itb file + * ............................ + * ............................ + * Data: Nitro NS3 config file + * ............................ + * ............................ + */ + +static struct nitro_img_header { + u32 nitro_fw_bin_sig; + u32 nitro_fw_bin_size; + u32 nitro_fw_cfg1_sig; + u32 nitro_fw_cfg1_size; + u32 nitro_fw_cfg2_sig; + u32 nitro_fw_cfg2_size; +} *img_header; + +static int do_spi_nitro_images_addr(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + uintptr_t images_load_addr; + uintptr_t spi_load_addr; + u32 len; + u32 spi_data_offset = sizeof(struct nitro_img_header); + + if (argc != 3) + return CMD_RET_USAGE; + + /* convert command parameter to fastboot address (base 16), i.e. hex */ + images_load_addr = (uintptr_t)simple_strtoul(argv[1], NULL, 16); + if (!images_load_addr) { + pr_err("Invalid load address\n"); + return CMD_RET_USAGE; + } + + spi_load_addr = (uintptr_t)simple_strtoul(argv[2], NULL, 16); + if (!spi_load_addr) { + pr_err("Invalid spi load address\n"); + return CMD_RET_USAGE; + } + + img_header = (struct nitro_img_header *)images_load_addr; + + if (img_header->nitro_fw_bin_sig != NITRO_FW_IMAGE_SIG) { + pr_err("Invalid Nitro bin file\n"); + return CMD_RET_FAILURE; + } + + env_set_hex("spi_nitro_fw_itb_start_addr", (ulong)0); + env_set_hex("spi_nitro_fw_itb_len", (ulong)0); + env_set_hex("spi_nitro_fw_ns3_cfg_start_addr", (ulong)0); + env_set_hex("spi_nitro_fw_ns3_cfg_len", (ulong)0); + + len = img_header->nitro_fw_bin_size; + + env_set_hex("spi_nitro_fw_itb_start_addr", (ulong) + (spi_load_addr + spi_data_offset)); + env_set_hex("spi_nitro_fw_itb_len", (ulong) + img_header->nitro_fw_bin_size); + + spi_data_offset += len; + + if (img_header->nitro_fw_cfg1_sig == NITRO_NS3_CFG_IMAGE_SIG) { + len = img_header->nitro_fw_cfg1_size; + + env_set_hex("spi_nitro_fw_ns3_cfg_start_addr", (ulong) + (spi_load_addr + spi_data_offset)); + env_set_hex("spi_nitro_fw_ns3_cfg_len", (ulong)len); + + spi_data_offset += len; + } + + /* disable nitro secure boot */ + env_set_hex("nitro_fastboot_secure", (ulong)0); + + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD + (spi_nitro_images_addr, 3, 1, do_spi_nitro_images_addr, + "Load the nitro bin header and sets envs ", + "spi_nitro_images_addr \n" +); From patchwork Sun May 17 08:37:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayagonda Kokatanur X-Patchwork-Id: 245912 List-Id: U-Boot discussion From: rayagonda.kokatanur at broadcom.com (Rayagonda Kokatanur) Date: Sun, 17 May 2020 14:07:05 +0530 Subject: [PATCH v1 3/3] cmd: bcm: add command for chimp hand shake In-Reply-To: <20200517083705.22508-1-rayagonda.kokatanur@broadcom.com> References: <20200517083705.22508-1-rayagonda.kokatanur@broadcom.com> Message-ID: <20200517083705.22508-4-rayagonda.kokatanur@broadcom.com> From: Bharat Kumar Reddy Gooty Add command for chimp handshake. Signed-off-by: Bharat Kumar Reddy Gooty Signed-off-by: Rayagonda Kokatanur Reviewed-by: Simon Glass --- cmd/bcm/Makefile | 1 + cmd/bcm/chimp_handshake.c | 32 ++++++++++++++++++++++++++++++++ include/brcm/chimp.h | 6 ++++++ 3 files changed, 39 insertions(+) create mode 100644 cmd/bcm/chimp_handshake.c diff --git a/cmd/bcm/Makefile b/cmd/bcm/Makefile index 671c0fbd43..49a3f38357 100644 --- a/cmd/bcm/Makefile +++ b/cmd/bcm/Makefile @@ -3,4 +3,5 @@ obj-$(CONFIG_CMD_BCM_LOGSETUP) += logsetup.o obj-y += chimp_boot.o +obj-y += chimp_handshake.o obj-y += nitro_image_load.o diff --git a/cmd/bcm/chimp_handshake.c b/cmd/bcm/chimp_handshake.c new file mode 100644 index 0000000000..7b9c766dd3 --- /dev/null +++ b/cmd/bcm/chimp_handshake.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 Broadcom + */ + +#include +#include + +/* This command should be called after loading the nitro binaries */ +static int do_chimp_hs(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + int ret = CMD_RET_USAGE; + u32 hstatus; + + /* Returns 1, if handshake call is success */ + if (chimp_handshake_status_optee(0, &hstatus) == BCM_CHIMP_SUCCESS) + ret = CMD_RET_SUCCESS; + + if (hstatus == CHIMP_HANDSHAKE_SUCCESS) + printf("ChiMP Handshake successful\n"); + else + printf("ERROR: ChiMP Handshake status 0x%x\n", hstatus); + + return ret; +} + +U_BOOT_CMD + (chimp_hs, 1, 1, do_chimp_hs, + "Command to verify the Chimp hand shake", + "chimp_hs\n" +); diff --git a/include/brcm/chimp.h b/include/brcm/chimp.h index 9099a70ef5..f384603dc7 100644 --- a/include/brcm/chimp.h +++ b/include/brcm/chimp.h @@ -15,6 +15,12 @@ #define BCM_CHIMP_RUNNIG_GOOD 0x8000 +enum { + CHIMP_HANDSHAKE_SUCCESS = 0, + CHIMP_HANDSHAKE_WAIT_ERROR, + CHIMP_HANDSHAKE_WAIT_TIMEOUT, +}; + #ifdef CONFIG_CHIMP_OPTEE int chimp_fastboot_optee(void); int chimp_health_status_optee(u32 *status);