diff options
-rw-r--r-- | arch/arm/cpu/armv8/sec_firmware.c | 52 | ||||
-rw-r--r-- | board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c | 28 | ||||
-rw-r--r-- | boot/image-fit.c | 37 | ||||
-rw-r--r-- | cmd/fpga.c | 24 | ||||
-rw-r--r-- | drivers/net/fm/fm.c | 18 | ||||
-rw-r--r-- | drivers/net/fsl-mc/mc.c | 30 | ||||
-rw-r--r-- | drivers/net/pfe_eth/pfe_firmware.c | 40 | ||||
-rw-r--r-- | include/configs/p1_p2_bootsrc.h | 20 | ||||
-rw-r--r-- | include/configs/p1_p2_rdb_pc.h | 17 | ||||
-rw-r--r-- | include/image.h | 70 |
10 files changed, 204 insertions, 132 deletions
diff --git a/arch/arm/cpu/armv8/sec_firmware.c b/arch/arm/cpu/armv8/sec_firmware.c index 7e6e406..540436b 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 @@ -46,46 +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 *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); - if (conf_node_off < 0) { - printf("SEC Firmware: %s: no such config\n", conf_node_name); - 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); } /* @@ -124,18 +83,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; } 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 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, " "); @@ -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; } 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 <common.h> #include <env.h> +#include <image.h> #include <malloc.h> #include <asm/io.h> #include <linux/errno.h> @@ -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) 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); } /* 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..d201c72 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 @@ -80,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 @@ -465,10 +478,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 \ 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); |