From 61fed3155f85059a25e71c44b9da5f6753fc84a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 25 Apr 2022 16:50:43 +0200 Subject: board: freescale: p1_p2_rdb_pc: Add env commands norlowerboot, norupperboot, sd2boot and defboot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All *boot env commands overrides default boot source location via i2c. After board reset without power off, BootROM then starts booting U-Boot from this specified location instead of the default one. Add new env command defboot which reverts boot location to the default value, which in most cases is configurable by HW DIP switches. And add new env commands norlowerboot, norupperboot, sd2boot to boot from other locations. norlowerboot would instruct BootROM to boot from lower NOR bank, norupperboot from upper NOR bank and sd2boot from SD card with alternative configuration. Signed-off-by: Pali Rohár Signed-off-by: Peng Fan --- include/configs/p1_p2_bootsrc.h | 20 ++++++++++++++++++++ include/configs/p1_p2_rdb_pc.h | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/configs/p1_p2_bootsrc.h b/include/configs/p1_p2_bootsrc.h index 13e4fdb..d155e55 100644 --- a/include/configs/p1_p2_bootsrc.h +++ b/include/configs/p1_p2_bootsrc.h @@ -34,6 +34,18 @@ #define RST_NOR_CMD(var, ...) "" #endif +#ifdef __SW_BOOT_NOR_BANK_LO +#define RST_NOR_LO_CMD(var, ...) __VAR_CMD_RST(var, __VA_ARGS__ __BOOTSRC_CMD(__SW_BOOT_NOR_BANK_LO, __SW_BOOT_MASK)) +#else +#define RST_NOR_LO_CMD(var, ...) "" +#endif + +#ifdef __SW_BOOT_NOR_BANK_UP +#define RST_NOR_UP_CMD(var, ...) __VAR_CMD_RST(var, __VA_ARGS__ __BOOTSRC_CMD(__SW_BOOT_NOR_BANK_UP, __SW_BOOT_MASK)) +#else +#define RST_NOR_UP_CMD(var, ...) "" +#endif + #ifdef __SW_BOOT_SPI #define RST_SPI_CMD(var, ...) __VAR_CMD_RST(var, __VA_ARGS__ __BOOTSRC_CMD(__SW_BOOT_SPI, __SW_BOOT_MASK)) #else @@ -46,6 +58,12 @@ #define RST_SD_CMD(var, ...) "" #endif +#ifdef __SW_BOOT_SD2 +#define RST_SD2_CMD(var, ...) __VAR_CMD_RST(var, __VA_ARGS__ __BOOTSRC_CMD(__SW_BOOT_SD2, __SW_BOOT_MASK)) +#else +#define RST_SD2_CMD(var, ...) "" +#endif + #ifdef __SW_BOOT_NAND #define RST_NAND_CMD(var, ...) __VAR_CMD_RST(var, __VA_ARGS__ __BOOTSRC_CMD(__SW_BOOT_NAND, __SW_BOOT_MASK)) #else @@ -57,3 +75,5 @@ #else #define RST_PCIE_CMD(var, ...) "" #endif + +#define RST_DEF_CMD(var, ...) __VAR_CMD_RST(var, __VA_ARGS__ __BOOTSRC_CMD(0x00, 0xff)) diff --git a/include/configs/p1_p2_rdb_pc.h b/include/configs/p1_p2_rdb_pc.h index f7d8723..bd2d657 100644 --- a/include/configs/p1_p2_rdb_pc.h +++ b/include/configs/p1_p2_rdb_pc.h @@ -24,6 +24,9 @@ #define __SW_NOR_BANK_MASK 0xfd #define __SW_NOR_BANK_UP 0x00 #define __SW_NOR_BANK_LO 0x02 +#define __SW_BOOT_NOR_BANK_UP 0x5c /* (__SW_BOOT_NOR | __SW_NOR_BANK_UP) */ +#define __SW_BOOT_NOR_BANK_LO 0x5e /* (__SW_BOOT_NOR | __SW_NOR_BANK_LO) */ +#define __SW_BOOT_NOR_BANK_MASK 0x01 /* (__SW_BOOT_MASK & __SW_NOR_BANK_MASK) */ #define CONFIG_SYS_L2_SIZE (256 << 10) #endif @@ -52,6 +55,9 @@ #define __SW_NOR_BANK_MASK 0xfd #define __SW_NOR_BANK_UP 0x00 #define __SW_NOR_BANK_LO 0x02 +#define __SW_BOOT_NOR_BANK_UP 0x64 /* (__SW_BOOT_NOR | __SW_NOR_BANK_UP) */ +#define __SW_BOOT_NOR_BANK_LO 0x66 /* (__SW_BOOT_NOR | __SW_NOR_BANK_LO) */ +#define __SW_BOOT_NOR_BANK_MASK 0x01 /* (__SW_BOOT_MASK & __SW_NOR_BANK_MASK) */ #define CONFIG_SYS_L2_SIZE (256 << 10) /* * Dynamic MTD Partition support with mtdparts @@ -70,6 +76,9 @@ #define __SW_NOR_BANK_MASK 0xfd #define __SW_NOR_BANK_UP 0x00 #define __SW_NOR_BANK_LO 0x02 +#define __SW_BOOT_NOR_BANK_UP 0xc8 /* (__SW_BOOT_NOR | __SW_NOR_BANK_UP) */ +#define __SW_BOOT_NOR_BANK_LO 0xca /* (__SW_BOOT_NOR | __SW_NOR_BANK_LO) */ +#define __SW_BOOT_NOR_BANK_MASK 0x01 /* (__SW_BOOT_MASK & __SW_NOR_BANK_MASK) */ #define CONFIG_SYS_L2_SIZE (512 << 10) /* * Dynamic MTD Partition support with mtdparts @@ -465,10 +474,14 @@ __VSCFW_ADDR \ MAP_NOR_LO_CMD(map_lowernorbank) \ MAP_NOR_UP_CMD(map_uppernorbank) \ RST_NOR_CMD(norboot) \ +RST_NOR_LO_CMD(norlowerboot) \ +RST_NOR_UP_CMD(norupperboot) \ RST_SPI_CMD(spiboot) \ RST_SD_CMD(sdboot) \ +RST_SD2_CMD(sd2boot) \ RST_NAND_CMD(nandboot) \ RST_PCIE_CMD(pciboot) \ +RST_DEF_CMD(defboot) \ "" #define CONFIG_USB_FAT_BOOT \ -- cgit v1.1 From 645993bdd758067941c1e121ec218027ad0ece68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 1 Aug 2022 15:35:43 +0200 Subject: board: freescale: p1_p2_rdb_pc: Delete watchdog max6370 node in load_default mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CPLD in load_default mode ignores watchdog reset signal. It does not reset board when watchdog triggers reset signal. Detect load_default mode by GPIO7 - LOAD_DEFAULT_N and delete watchdog max6370 node from device to prevent registering driver for non-working watchdog. Signed-off-by: Pali Rohár Signed-off-by: Peng Fan --- board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c index 25906d3..b301491 100644 --- a/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c +++ b/board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c @@ -414,6 +414,24 @@ int board_eth_init(struct bd_info *bis) } #endif +#if defined(CONFIG_OF_BOARD_SETUP) || defined(CONFIG_OF_BOARD_FIXUP) +static void fix_max6370_watchdog(void *blob) +{ + int off = fdt_node_offset_by_compatible(blob, -1, "maxim,max6370"); + ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR); + u32 gpioval = in_be32(&pgpio->gpdat); + + /* + * Delete watchdog max6370 node in load_default mode (detected by + * GPIO7 - LOAD_DEFAULT_N) because CPLD in load_default mode ignores + * watchdog reset signal. CPLD in load_default mode does not reset + * board when watchdog triggers reset signal. + */ + if (!(gpioval & BIT(31-7)) && off >= 0) + fdt_del_node(blob, off); +} +#endif + #ifdef CONFIG_OF_BOARD_SETUP int ft_board_setup(void *blob, struct bd_info *bd) { @@ -439,6 +457,8 @@ int ft_board_setup(void *blob, struct bd_info *bd) sizeof("okay"), 0); #endif + fix_max6370_watchdog(blob); + #if defined(CONFIG_HAS_FSL_DR_USB) fsl_fdt_fixup_dr_usb(blob, bd); #endif @@ -490,3 +510,11 @@ int ft_board_setup(void *blob, struct bd_info *bd) return 0; } #endif + +#ifdef CONFIG_OF_BOARD_FIXUP +int board_fix_fdt(void *blob) +{ + fix_max6370_watchdog(blob); + return 0; +} +#endif -- cgit v1.1 From 33043b396cae4d6b464592dd17bba075c9215826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Mon, 1 Aug 2022 14:50:12 +0200 Subject: board: freescale: p1_p2_rdb_pc: Calculate offsets for eSDHC boot sector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correctly calculate offsets between SPL and proper U-Boot when new config option CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR for generating eSDHC boot sector is enabled. Otherwise SPL would not be able to boot proper U-Boot. Signed-off-by: Pali Rohár Signed-off-by: Peng Fan --- include/configs/p1_p2_rdb_pc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/configs/p1_p2_rdb_pc.h b/include/configs/p1_p2_rdb_pc.h index bd2d657..d201c72 100644 --- a/include/configs/p1_p2_rdb_pc.h +++ b/include/configs/p1_p2_rdb_pc.h @@ -89,7 +89,11 @@ #define CONFIG_SYS_MMC_U_BOOT_SIZE (768 << 10) #define CONFIG_SYS_MMC_U_BOOT_DST CONFIG_SYS_TEXT_BASE #define CONFIG_SYS_MMC_U_BOOT_START CONFIG_SYS_TEXT_BASE +#ifdef CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR +#define CONFIG_SYS_MMC_U_BOOT_OFFS (CONFIG_SPL_PAD_TO - CONFIG_FSL_PREPBL_ESDHC_BOOT_SECTOR_DATA*512) +#else #define CONFIG_SYS_MMC_U_BOOT_OFFS CONFIG_SPL_PAD_TO +#endif #elif defined(CONFIG_SPIFLASH) #define CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE (768 << 10) #define CONFIG_SYS_SPI_FLASH_U_BOOT_DST CONFIG_SYS_TEXT_BASE -- cgit v1.1 From 1b0e98221d826776adc8e3c5d939cfee1890398e Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 16 Aug 2022 11:16:02 -0400 Subject: ARMv8/sec_firmware: Remove SEC_FIRMWARE_FIT_CNF_NAME The config to use for FIT images can be better specified by enabling CONFIG_MULTI_DTB_FIT and implementing board_fit_config_name_match. Signed-off-by: Sean Anderson Signed-off-by: Peng Fan --- arch/arm/cpu/armv8/sec_firmware.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/arch/arm/cpu/armv8/sec_firmware.c b/arch/arm/cpu/armv8/sec_firmware.c index 7e6e406..bbd3f2d 100644 --- a/arch/arm/cpu/armv8/sec_firmware.c +++ b/arch/arm/cpu/armv8/sec_firmware.c @@ -36,9 +36,6 @@ phys_addr_t sec_firmware_addr; #ifndef SEC_FIRMWARE_FIT_IMAGE #define SEC_FIRMWARE_FIT_IMAGE "firmware" #endif -#ifndef SEC_FIRMWARE_FIT_CNF_NAME -#define SEC_FIRMWARE_FIT_CNF_NAME "config-1" -#endif #ifndef SEC_FIRMWARE_TARGET_EL #define SEC_FIRMWARE_TARGET_EL 2 #endif @@ -47,15 +44,12 @@ static int sec_firmware_get_data(const void *sec_firmware_img, const void **data, size_t *size) { int conf_node_off, fw_node_off; - char *conf_node_name = NULL; char *desc; int ret; - conf_node_name = SEC_FIRMWARE_FIT_CNF_NAME; - - conf_node_off = fit_conf_get_node(sec_firmware_img, conf_node_name); + conf_node_off = fit_conf_get_node(sec_firmware_img, NULL); if (conf_node_off < 0) { - printf("SEC Firmware: %s: no such config\n", conf_node_name); + puts("SEC Firmware: no config\n"); return -ENOENT; } @@ -124,18 +118,15 @@ static int sec_firmware_check_copy_loadable(const void *sec_firmware_img, { phys_addr_t sec_firmware_loadable_addr = 0; int conf_node_off, ld_node_off, images; - char *conf_node_name = NULL; const void *data; size_t size; ulong load; const char *name, *str, *type; int len; - conf_node_name = SEC_FIRMWARE_FIT_CNF_NAME; - - conf_node_off = fit_conf_get_node(sec_firmware_img, conf_node_name); + conf_node_off = fit_conf_get_node(sec_firmware_img, NULL); if (conf_node_off < 0) { - printf("SEC Firmware: %s: no such config\n", conf_node_name); + puts("SEC Firmware: no config\n"); return -ENOENT; } -- cgit v1.1 From 37feaf2f72788263b767136065794f80485bb5ff Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 16 Aug 2022 11:16:03 -0400 Subject: image: fit: Add some helpers for getting data Several different firmware users have repetitive code to extract the firmware data from a FIT. Add some helper functions to reduce the amount of repetition. fit_conf_get_prop_node (eventually) calls fdt_check_node_offset_, so we can avoid an explicit if. In general, this version avoids printing on error because the callers are typically library functions, and because the FIT code generally has (debug) prints of its own. One difference in these helpers is that they use fit_image_get_data_and_size instead of fit_image_get_data, as the former handles external data correctly. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Signed-off-by: Peng Fan --- boot/image-fit.c | 37 ++++++++++++++++++++++++++++++ include/image.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/boot/image-fit.c b/boot/image-fit.c index 21dbd05..f16eab9 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -1916,6 +1916,43 @@ int fit_conf_get_prop_node(const void *fit, int noffset, return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0); } +static int fit_get_data_tail(const void *fit, int noffset, + const void **data, size_t *size) +{ + char *desc; + + if (noffset < 0) + return noffset; + + if (!fit_image_verify(fit, noffset)) + return -EINVAL; + + if (fit_image_get_data_and_size(fit, noffset, data, size)) + return -ENOENT; + + if (!fit_get_desc(fit, noffset, &desc)) + printf("%s\n", desc); + + return 0; +} + +int fit_get_data_node(const void *fit, const char *image_uname, + const void **data, size_t *size) +{ + int noffset = fit_image_get_node(fit, image_uname); + + return fit_get_data_tail(fit, noffset, data, size); +} + +int fit_get_data_conf_prop(const void *fit, const char *prop_name, + const void **data, size_t *size) +{ + int noffset = fit_conf_get_node(fit, NULL); + + noffset = fit_conf_get_prop_node(fit, noffset, prop_name); + return fit_get_data_tail(fit, noffset, data, size); +} + static int fit_image_select(const void *fit, int rd_noffset, int verify) { fit_image_print(fit, rd_noffset, " "); diff --git a/include/image.h b/include/image.h index e4c6a50..d7d756c 100644 --- a/include/image.h +++ b/include/image.h @@ -1014,6 +1014,76 @@ int fit_image_get_data_size_unciphered(const void *fit, int noffset, int fit_image_get_data_and_size(const void *fit, int noffset, const void **data, size_t *size); +/** + * fit_get_data_node() - Get verified image data for an image + * @fit: Pointer to the FIT format image header + * @image_uname: The name of the image node + * @data: A pointer which will be filled with the location of the image data + * @size: A pointer which will be filled with the size of the image data + * + * This function looks up the location and size of an image specified by its + * name. For example, if you had a FIT like:: + * + * images { + * my-firmware { + * ... + * }; + * }; + * + * Then you could look up the data location and size of the my-firmware image + * by calling this function with @image_uname set to "my-firmware". This + * function also verifies the image data (if enabled) before returning. The + * image description is printed out on success. @data and @size will not be + * modified on faulure. + * + * Return: + * * 0 on success + * * -EINVAL if the image could not be verified + * * -ENOENT if there was a problem getting the data/size + * * Another negative error if there was a problem looking up the image node. + */ +int fit_get_data_node(const void *fit, const char *image_uname, + const void **data, size_t *size); + +/** + * fit_get_data_conf_prop() - Get verified image data for a property in /conf + * @fit: Pointer to the FIT format image header + * @prop_name: The name of the property in /conf referencing the image + * @data: A pointer which will be filled with the location of the image data + * @size: A pointer which will be filled with the size of the image data + * + * This function looks up the location and size of an image specified by a + * property in /conf. For example, if you had a FIT like:: + * + * images { + * my-firmware { + * ... + * }; + * }; + * + * configurations { + * default = "conf-1"; + * conf-1 { + * some-firmware = "my-firmware"; + * }; + * }; + * + * Then you could look up the data location and size of the my-firmware image + * by calling this function with @prop_name set to "some-firmware". This + * function also verifies the image data (if enabled) before returning. The + * image description is printed out on success. @data and @size will not be + * modified on faulure. + * + * Return: + * * 0 on success + * * -EINVAL if the image could not be verified + * * -ENOENT if there was a problem getting the data/size + * * Another negative error if there was a problem looking up the configuration + * or image node. + */ +int fit_get_data_conf_prop(const void *fit, const char *prop_name, + const void **data, size_t *size); + int fit_image_hash_get_algo(const void *fit, int noffset, const char **algo); int fit_image_hash_get_value(const void *fit, int noffset, uint8_t **value, int *value_len); -- cgit v1.1 From bdbdaede671c5ad7b71737bd345e03eb7e99266d Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 16 Aug 2022 11:16:04 -0400 Subject: ARMv8/sec_firmware: Convert to use fit_get_data_conf_prop This reduces sec_firmware_get_data to a single call to fit_get_data_conf_prop. I think sec_firmware_check_copy_loadable could also be converted, but it does not map as straightforwardly, so I have left it for a future cleanup. Signed-off-by: Sean Anderson Signed-off-by: Peng Fan --- arch/arm/cpu/armv8/sec_firmware.c | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/arch/arm/cpu/armv8/sec_firmware.c b/arch/arm/cpu/armv8/sec_firmware.c index bbd3f2d..540436b 100644 --- a/arch/arm/cpu/armv8/sec_firmware.c +++ b/arch/arm/cpu/armv8/sec_firmware.c @@ -43,43 +43,8 @@ phys_addr_t sec_firmware_addr; static int sec_firmware_get_data(const void *sec_firmware_img, const void **data, size_t *size) { - int conf_node_off, fw_node_off; - char *desc; - int ret; - - conf_node_off = fit_conf_get_node(sec_firmware_img, NULL); - if (conf_node_off < 0) { - puts("SEC Firmware: no config\n"); - return -ENOENT; - } - - fw_node_off = fit_conf_get_prop_node(sec_firmware_img, conf_node_off, - SEC_FIRMWARE_FIT_IMAGE); - if (fw_node_off < 0) { - printf("SEC Firmware: No '%s' in config\n", - SEC_FIRMWARE_FIT_IMAGE); - return -ENOLINK; - } - - /* Verify secure firmware image */ - if (!(fit_image_verify(sec_firmware_img, fw_node_off))) { - printf("SEC Firmware: Bad firmware image (bad CRC)\n"); - return -EINVAL; - } - - if (fit_image_get_data(sec_firmware_img, fw_node_off, data, size)) { - printf("SEC Firmware: Can't get %s subimage data/size", - SEC_FIRMWARE_FIT_IMAGE); - return -ENOENT; - } - - ret = fit_get_desc(sec_firmware_img, fw_node_off, &desc); - if (ret) - printf("SEC Firmware: Can't get description\n"); - else - printf("%s\n", desc); - - return ret; + return fit_get_data_conf_prop(sec_firmware_img, SEC_FIRMWARE_FIT_IMAGE, + data, size); } /* -- cgit v1.1 From 7b42bde075c9cec85aa200d2e093d3b2b5641d94 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 16 Aug 2022 11:16:05 -0400 Subject: cmd: fpga: Convert to use fit_get_data_node This converts the FIT loading process of the fpga command to use fit_get_data_node. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Signed-off-by: Peng Fan --- cmd/fpga.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/cmd/fpga.c b/cmd/fpga.c index c4651dd..9cf7651 100644 --- a/cmd/fpga.c +++ b/cmd/fpga.c @@ -322,7 +322,7 @@ static int do_fpga_loadmk(struct cmd_tbl *cmdtp, int flag, int argc, case IMAGE_FORMAT_FIT: { const void *fit_hdr = (const void *)fpga_data; - int noffset; + int err; const void *fit_data; if (!fit_uname) { @@ -335,23 +335,11 @@ static int do_fpga_loadmk(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_FAILURE; } - /* get fpga component image node offset */ - noffset = fit_image_get_node(fit_hdr, fit_uname); - if (noffset < 0) { - printf("Can't find '%s' FIT subimage\n", fit_uname); - return CMD_RET_FAILURE; - } - - /* verify integrity */ - if (!fit_image_verify(fit_hdr, noffset)) { - puts("Bad Data Hash\n"); - return CMD_RET_FAILURE; - } - - /* get fpga subimage/external data address and length */ - if (fit_image_get_data_and_size(fit_hdr, noffset, - &fit_data, &data_size)) { - puts("Fpga subimage data not found\n"); + err = fit_get_data_node(fit_hdr, fit_uname, &fit_data, + &data_size); + if (err) { + printf("Could not load '%s' subimage (err %d)\n", + fit_uname, err); return CMD_RET_FAILURE; } -- cgit v1.1 From f1061c570112670be3259fff7966caad96c6e2cf Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Tue, 16 Aug 2022 11:16:06 -0400 Subject: net: Convert fit verification to use fit_get_data_* Several ethernet drivers load firmware from FIT images. Convert them to use the fit_get_data helpers. Signed-off-by: Sean Anderson Reviewed-by: Simon Glass Signed-off-by: Peng Fan --- drivers/net/fsl-mc/mc.c | 30 +++------------------------- drivers/net/pfe_eth/pfe_firmware.c | 40 +------------------------------------- 2 files changed, 4 insertions(+), 66 deletions(-) diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c index bc1c31d..68833f9 100644 --- a/drivers/net/fsl-mc/mc.c +++ b/drivers/net/fsl-mc/mc.c @@ -137,13 +137,7 @@ int parse_mc_firmware_fit_image(u64 mc_fw_addr, size_t *raw_image_size) { int format; - void *fit_hdr; - int node_offset; - const void *data; - size_t size; - const char *uname = "firmware"; - - fit_hdr = (void *)mc_fw_addr; + void *fit_hdr = (void *)mc_fw_addr; /* Check if Image is in FIT format */ format = genimg_get_format(fit_hdr); @@ -158,26 +152,8 @@ int parse_mc_firmware_fit_image(u64 mc_fw_addr, return -EINVAL; } - node_offset = fit_image_get_node(fit_hdr, uname); - - if (node_offset < 0) { - printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n"); - return -ENOENT; - } - - /* Verify MC firmware image */ - if (!(fit_image_verify(fit_hdr, node_offset))) { - printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n"); - return -EINVAL; - } - - /* Get address and size of raw image */ - fit_image_get_data(fit_hdr, node_offset, &data, &size); - - *raw_image_addr = data; - *raw_image_size = size; - - return 0; + return fit_get_data_node(fit_hdr, "firmware", raw_image_addr, + raw_image_size); } #endif diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c index 82a4aa8..da4f2ca 100644 --- a/drivers/net/pfe_eth/pfe_firmware.c +++ b/drivers/net/pfe_eth/pfe_firmware.c @@ -104,45 +104,7 @@ err: static int pfe_get_fw(const void **data, size_t *size, char *fw_name) { - int conf_node_off, fw_node_off; - char *conf_node_name = NULL; - char *desc; - int ret = 0; - - conf_node_name = PFE_FIRMWARE_FIT_CNF_NAME; - - conf_node_off = fit_conf_get_node(pfe_fit_addr, conf_node_name); - if (conf_node_off < 0) { - printf("PFE Firmware: %s: no such config\n", conf_node_name); - return -ENOENT; - } - - fw_node_off = fit_conf_get_prop_node(pfe_fit_addr, conf_node_off, - fw_name); - if (fw_node_off < 0) { - printf("PFE Firmware: No '%s' in config\n", - fw_name); - return -ENOLINK; - } - - if (!(fit_image_verify(pfe_fit_addr, fw_node_off))) { - printf("PFE Firmware: Bad firmware image (bad CRC)\n"); - return -EINVAL; - } - - if (fit_image_get_data(pfe_fit_addr, fw_node_off, data, size)) { - printf("PFE Firmware: Can't get %s subimage data/size", - fw_name); - return -ENOENT; - } - - ret = fit_get_desc(pfe_fit_addr, fw_node_off, &desc); - if (ret) - printf("PFE Firmware: Can't get description\n"); - else - printf("%s\n", desc); - - return ret; + return fit_get_data_conf_prop(pfe_fit_addr, fw_name, data, size); } /* -- cgit v1.1 From 857e313a3d44618e09fc64816fd5e561e2189ab7 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Wed, 7 Sep 2022 13:44:55 +0800 Subject: net: fm: Add support for FIT firmware Fman microcode is executable code (AFAICT) loaded into a coprocessor. As such, if verified boot is enabled, it must be verified like other executable code. However, this is not currently done. This commit adds verified boot functionality by encapsulating the microcode in a FIT, which can then be signed/verified as normal. By default we allow fallback to unencapsulated firmware, but if CONFIG_FIT_SIGNATURE is enabled, then we make it mandatory. Because existing Layerscape do not use this config (instead enabling CONFIG_CHAIN_OF_TRUST), this should not break any existing boards. An example (mildly-abbreviated) its is provided below: / { #address-cells = <1>; images { firmware { data = /incbin/(/path/to/firmware); type = "firmware"; arch = "arm64"; compression = "none"; signature { algo = "sha256,rsa2048"; key-name-hint = "your key name"; }; }; }; configurations { default = "conf"; conf { description = "Load FMAN microcode"; fman = "firmware"; }; }; }; Reviewed-by: Simon Glass Signed-off-by: Sean Anderson Signed-off-by: Peng Fan --- drivers/net/fm/fm.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c index d0b492b..ee96abb 100644 --- a/drivers/net/fm/fm.c +++ b/drivers/net/fm/fm.c @@ -5,6 +5,7 @@ */ #include #include +#include #include #include #include @@ -513,6 +514,23 @@ int fm_init_common(int index, struct ccsr_fman *reg) void *addr = NULL; #endif + rc = fit_check_format(addr, CONFIG_SYS_QE_FMAN_FW_LENGTH); + if (!rc) { + size_t unused; + const void *new_addr; + + rc = fit_get_data_conf_prop(addr, "fman", &new_addr, &unused); + if (rc) + return rc; + addr = (void *)new_addr; + } else if (CONFIG_IS_ENABLED(FIT_SIGNATURE)) { + /* + * Using a (signed) FIT wrapper is mandatory if we are + * doing verified boot. + */ + return rc; + } + /* Upload the Fman microcode if it's present */ rc = fman_upload_firmware(index, ®->fm_imem, addr); if (rc) -- cgit v1.1