diff options
Diffstat (limited to 'arch/arm/mach-imx/imx8')
-rw-r--r-- | arch/arm/mach-imx/imx8/Kconfig | 13 | ||||
-rw-r--r-- | arch/arm/mach-imx/imx8/Makefile | 3 | ||||
-rw-r--r-- | arch/arm/mach-imx/imx8/ahab.c | 2 | ||||
-rw-r--r-- | arch/arm/mach-imx/imx8/image.c | 249 | ||||
-rw-r--r-- | arch/arm/mach-imx/imx8/parse-container.c | 208 |
5 files changed, 1 insertions, 474 deletions
diff --git a/arch/arm/mach-imx/imx8/Kconfig b/arch/arm/mach-imx/imx8/Kconfig index 71221d8d06..b43739e5c6 100644 --- a/arch/arm/mach-imx/imx8/Kconfig +++ b/arch/arm/mach-imx/imx8/Kconfig @@ -31,19 +31,6 @@ config IMX8QXP config SYS_SOC default "imx8" -config SPL_LOAD_IMX_CONTAINER - bool "Enable SPL loading U-Boot as a i.MX Container image" - depends on SPL - help - This is to let SPL could load i.MX8 Container image - -config IMX_CONTAINER_CFG - string "i.MX Container config file" - depends on SPL - help - This is to specific the cfg file for generating container - image which will be loaded by SPL. - config BOOTAUX_RESERVED_MEM_BASE hex "i.MX auxiliary core dram memory base" default 0 diff --git a/arch/arm/mach-imx/imx8/Makefile b/arch/arm/mach-imx/imx8/Makefile index bbb41adbe4..4ca4c14bdd 100644 --- a/arch/arm/mach-imx/imx8/Makefile +++ b/arch/arm/mach-imx/imx8/Makefile @@ -8,7 +8,4 @@ obj-y += cpu.o iomux.o misc.o lowlevel_init.o obj-$(CONFIG_OF_SYSTEM_SETUP) += fdt.o obj-$(CONFIG_AHAB_BOOT) += ahab.o -ifdef CONFIG_SPL_BUILD -obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += image.o parse-container.o -endif obj-$(CONFIG_IMX_SNVS_SEC_SC) += snvs_security_sc.o diff --git a/arch/arm/mach-imx/imx8/ahab.c b/arch/arm/mach-imx/imx8/ahab.c index 015267c8b2..5a4d39cdaa 100644 --- a/arch/arm/mach-imx/imx8/ahab.c +++ b/arch/arm/mach-imx/imx8/ahab.c @@ -13,7 +13,7 @@ #include <asm/mach-imx/sys_proto.h> #include <asm/arch-imx/cpu.h> #include <asm/arch/sys_proto.h> -#include <asm/arch/image.h> +#include <asm/mach-imx/image.h> #include <console.h> #include <cpu_func.h> diff --git a/arch/arm/mach-imx/imx8/image.c b/arch/arm/mach-imx/imx8/image.c deleted file mode 100644 index 5abc0d3a39..0000000000 --- a/arch/arm/mach-imx/imx8/image.c +++ /dev/null @@ -1,249 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2019 NXP - */ - -#include <common.h> -#include <errno.h> -#include <log.h> -#include <malloc.h> -#include <asm/io.h> -#include <mmc.h> -#include <spi_flash.h> -#include <nand.h> -#include <asm/arch/image.h> -#include <asm/arch/sys_proto.h> -#include <asm/mach-imx/boot_mode.h> - -#define MMC_DEV 0 -#define QSPI_DEV 1 -#define NAND_DEV 2 -#define QSPI_NOR_DEV 3 - -static int __get_container_size(ulong addr) -{ - struct container_hdr *phdr; - struct boot_img_t *img_entry; - struct signature_block_hdr *sign_hdr; - u8 i = 0; - u32 max_offset = 0, img_end; - - phdr = (struct container_hdr *)addr; - if (phdr->tag != 0x87 && phdr->version != 0x0) { - debug("Wrong container header\n"); - return -EFAULT; - } - - max_offset = sizeof(struct container_hdr); - - img_entry = (struct boot_img_t *)(addr + sizeof(struct container_hdr)); - for (i = 0; i < phdr->num_images; i++) { - img_end = img_entry->offset + img_entry->size; - if (img_end > max_offset) - max_offset = img_end; - - debug("img[%u], end = 0x%x\n", i, img_end); - - img_entry++; - } - - if (phdr->sig_blk_offset != 0) { - sign_hdr = (struct signature_block_hdr *)(addr + phdr->sig_blk_offset); - u16 len = sign_hdr->length_lsb + (sign_hdr->length_msb << 8); - - if (phdr->sig_blk_offset + len > max_offset) - max_offset = phdr->sig_blk_offset + len; - - debug("sigblk, end = 0x%x\n", phdr->sig_blk_offset + len); - } - - return max_offset; -} - -static int get_container_size(void *dev, int dev_type, unsigned long offset) -{ - u8 *buf = malloc(CONTAINER_HDR_ALIGNMENT); - int ret = 0; - - if (!buf) { - printf("Malloc buffer failed\n"); - return -ENOMEM; - } - -#ifdef CONFIG_SPL_MMC_SUPPORT - if (dev_type == MMC_DEV) { - unsigned long count = 0; - struct mmc *mmc = (struct mmc *)dev; - - count = blk_dread(mmc_get_blk_desc(mmc), - offset / mmc->read_bl_len, - CONTAINER_HDR_ALIGNMENT / mmc->read_bl_len, - buf); - if (count == 0) { - printf("Read container image from MMC/SD failed\n"); - return -EIO; - } - } -#endif - -#ifdef CONFIG_SPL_SPI_LOAD - if (dev_type == QSPI_DEV) { - struct spi_flash *flash = (struct spi_flash *)dev; - - ret = spi_flash_read(flash, offset, - CONTAINER_HDR_ALIGNMENT, buf); - if (ret != 0) { - printf("Read container image from QSPI failed\n"); - return -EIO; - } - } -#endif - -#ifdef CONFIG_SPL_NAND_SUPPORT - if (dev_type == NAND_DEV) { - ret = nand_spl_load_image(offset, CONTAINER_HDR_ALIGNMENT, - buf); - if (ret != 0) { - printf("Read container image from NAND failed\n"); - return -EIO; - } - } -#endif - -#ifdef CONFIG_SPL_NOR_SUPPORT - if (dev_type == QSPI_NOR_DEV) - memcpy(buf, (const void *)offset, CONTAINER_HDR_ALIGNMENT); -#endif - - ret = __get_container_size((ulong)buf); - - free(buf); - - return ret; -} - -static unsigned long get_boot_device_offset(void *dev, int dev_type) -{ - unsigned long offset = 0; - - if (dev_type == MMC_DEV) { - struct mmc *mmc = (struct mmc *)dev; - - if (IS_SD(mmc) || mmc->part_config == MMCPART_NOAVAILABLE) { - offset = CONTAINER_HDR_MMCSD_OFFSET; - } else { - u8 part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config); - - if (part == 1 || part == 2) { - if (is_imx8qxp() && is_soc_rev(CHIP_REV_B)) - offset = CONTAINER_HDR_MMCSD_OFFSET; - else - offset = CONTAINER_HDR_EMMC_OFFSET; - } else { - offset = CONTAINER_HDR_MMCSD_OFFSET; - } - } - } else if (dev_type == QSPI_DEV) { - offset = CONTAINER_HDR_QSPI_OFFSET; - } else if (dev_type == NAND_DEV) { - offset = CONTAINER_HDR_NAND_OFFSET; - } else if (dev_type == QSPI_NOR_DEV) { - offset = CONTAINER_HDR_QSPI_OFFSET + 0x08000000; - } - - return offset; -} - -static int get_imageset_end(void *dev, int dev_type) -{ - unsigned long offset1 = 0, offset2 = 0; - int value_container[2]; - - offset1 = get_boot_device_offset(dev, dev_type); - offset2 = CONTAINER_HDR_ALIGNMENT + offset1; - - value_container[0] = get_container_size(dev, dev_type, offset1); - if (value_container[0] < 0) { - printf("Parse seco container failed %d\n", value_container[0]); - return value_container[0]; - } - - debug("seco container size 0x%x\n", value_container[0]); - - value_container[1] = get_container_size(dev, dev_type, offset2); - if (value_container[1] < 0) { - debug("Parse scu container failed %d, only seco container\n", - value_container[1]); - /* return seco container total size */ - return value_container[0] + offset1; - } - - debug("scu container size 0x%x\n", value_container[1]); - - return value_container[1] + offset2; -} - -#ifdef CONFIG_SPL_SPI_LOAD -unsigned long spl_spi_get_uboot_offs(struct spi_flash *flash) -{ - int end; - - end = get_imageset_end(flash, QSPI_DEV); - end = ROUND(end, SZ_1K); - - printf("Load image from QSPI 0x%x\n", end); - - return end; -} -#endif - -#ifdef CONFIG_SPL_MMC_SUPPORT -unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc, - unsigned long raw_sect) -{ - int end; - - end = get_imageset_end(mmc, MMC_DEV); - end = ROUND(end, SZ_1K); - - printf("Load image from MMC/SD 0x%x\n", end); - - return end / mmc->read_bl_len; -} -#endif - -#ifdef CONFIG_SPL_NAND_SUPPORT -uint32_t spl_nand_get_uboot_raw_page(void) -{ - int end; - - end = get_imageset_end((void *)NULL, NAND_DEV); - end = ROUND(end, SZ_16K); - - printf("Load image from NAND 0x%x\n", end); - - return end; -} -#endif - -#ifdef CONFIG_SPL_NOR_SUPPORT -unsigned long spl_nor_get_uboot_base(void) -{ - int end; - - /* Calculate the image set end, - * if it is less than CONFIG_SYS_UBOOT_BASE(0x8281000), - * we use CONFIG_SYS_UBOOT_BASE - * Otherwise, use the calculated address - */ - end = get_imageset_end((void *)NULL, QSPI_NOR_DEV); - if (end <= CONFIG_SYS_UBOOT_BASE) - end = CONFIG_SYS_UBOOT_BASE; - else - end = ROUND(end, SZ_1K); - - printf("Load image from NOR 0x%x\n", end); - - return end; -} -#endif diff --git a/arch/arm/mach-imx/imx8/parse-container.c b/arch/arm/mach-imx/imx8/parse-container.c deleted file mode 100644 index 375098902f..0000000000 --- a/arch/arm/mach-imx/imx8/parse-container.c +++ /dev/null @@ -1,208 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2018-2019 NXP - */ - -#include <common.h> -#include <errno.h> -#include <log.h> -#include <spl.h> -#include <asm/arch/image.h> -#include <asm/arch/sci/sci.h> - -#define SEC_SECURE_RAM_BASE 0x31800000UL -#define SEC_SECURE_RAM_END_BASE (SEC_SECURE_RAM_BASE + 0xFFFFUL) -#define SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE 0x60000000UL - -#define SECO_PT 2U - -#ifdef CONFIG_AHAB_BOOT -static int authenticate_image(struct boot_img_t *img, int image_index) -{ - sc_faddr_t start, end; - sc_rm_mr_t mr; - int err; - int ret = 0; - - debug("img %d, dst 0x%x, src 0x%x, size 0x%x\n", - image_index, (uint32_t)img->dst, img->offset, img->size); - - /* Find the memreg and set permission for seco pt */ - err = sc_rm_find_memreg(-1, &mr, - img->dst & ~(CONFIG_SYS_CACHELINE_SIZE - 1), - ALIGN(img->dst + img->size, CONFIG_SYS_CACHELINE_SIZE) - 1); - - if (err) { - printf("can't find memreg for image %d load address 0x%x, error %d\n", - image_index, img->dst & ~(CONFIG_SYS_CACHELINE_SIZE - 1), err); - return -ENOMEM; - } - - err = sc_rm_get_memreg_info(-1, mr, &start, &end); - if (!err) - debug("memreg %u 0x%x -- 0x%x\n", mr, start, end); - - err = sc_rm_set_memreg_permissions(-1, mr, - SECO_PT, SC_RM_PERM_FULL); - if (err) { - printf("set permission failed for img %d, error %d\n", - image_index, err); - return -EPERM; - } - - err = sc_seco_authenticate(-1, SC_SECO_VERIFY_IMAGE, - 1 << image_index); - if (err) { - printf("authenticate img %d failed, return %d\n", - image_index, err); - ret = -EIO; - } - - err = sc_rm_set_memreg_permissions(-1, mr, - SECO_PT, SC_RM_PERM_NONE); - if (err) { - printf("remove permission failed for img %d, error %d\n", - image_index, err); - ret = -EPERM; - } - - return ret; -} -#endif - -static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image, - struct spl_load_info *info, - struct container_hdr *container, - int image_index, - u32 container_sector) -{ - struct boot_img_t *images; - ulong sector; - u32 sectors; - - if (image_index > container->num_images) { - debug("Invalid image number\n"); - return NULL; - } - - images = (struct boot_img_t *)((u8 *)container + - sizeof(struct container_hdr)); - - if (images[image_index].offset % info->bl_len) { - printf("%s: image%d offset not aligned to %u\n", - __func__, image_index, info->bl_len); - return NULL; - } - - sectors = roundup(images[image_index].size, info->bl_len) / - info->bl_len; - sector = images[image_index].offset / info->bl_len + - container_sector; - - debug("%s: container: %p sector: %lu sectors: %u\n", __func__, - container, sector, sectors); - if (info->read(info, sector, sectors, - (void *)images[image_index].entry) != sectors) { - printf("%s wrong\n", __func__); - return NULL; - } - -#ifdef CONFIG_AHAB_BOOT - if (authenticate_image(&images[image_index], image_index)) { - printf("Failed to authenticate image %d\n", image_index); - return NULL; - } -#endif - - return &images[image_index]; -} - -static int read_auth_container(struct spl_image_info *spl_image, - struct spl_load_info *info, ulong sector) -{ - struct container_hdr *container = NULL; - u16 length; - u32 sectors; - int i, size, ret = 0; - - size = roundup(CONTAINER_HDR_ALIGNMENT, info->bl_len); - sectors = size / info->bl_len; - - /* - * It will not override the ATF code, so safe to use it here, - * no need malloc - */ - container = (struct container_hdr *)spl_get_load_buffer(-size, size); - - debug("%s: container: %p sector: %lu sectors: %u\n", __func__, - container, sector, sectors); - if (info->read(info, sector, sectors, container) != sectors) - return -EIO; - - if (container->tag != 0x87 && container->version != 0x0) { - printf("Wrong container header"); - return -ENOENT; - } - - if (!container->num_images) { - printf("Wrong container, no image found"); - return -ENOENT; - } - - length = container->length_lsb + (container->length_msb << 8); - debug("Container length %u\n", length); - - if (length > CONTAINER_HDR_ALIGNMENT) { - size = roundup(length, info->bl_len); - sectors = size / info->bl_len; - - container = (struct container_hdr *)spl_get_load_buffer(-size, size); - - debug("%s: container: %p sector: %lu sectors: %u\n", - __func__, container, sector, sectors); - if (info->read(info, sector, sectors, container) != - sectors) - return -EIO; - } - -#ifdef CONFIG_AHAB_BOOT - memcpy((void *)SEC_SECURE_RAM_BASE, (const void *)container, - ALIGN(length, CONFIG_SYS_CACHELINE_SIZE)); - - ret = sc_seco_authenticate(-1, SC_SECO_AUTH_CONTAINER, - SECO_LOCAL_SEC_SEC_SECURE_RAM_BASE); - if (ret) { - printf("authenticate container hdr failed, return %d\n", ret); - return ret; - } -#endif - - for (i = 0; i < container->num_images; i++) { - struct boot_img_t *image = read_auth_image(spl_image, info, - container, i, - sector); - - if (!image) { - ret = -EINVAL; - goto end_auth; - } - - if (i == 0) { - spl_image->load_addr = image->dst; - spl_image->entry_point = image->entry; - } - } - -end_auth: -#ifdef CONFIG_AHAB_BOOT - if (sc_seco_authenticate(-1, SC_SECO_REL_CONTAINER, 0)) - printf("Error: release container failed!\n"); -#endif - return ret; -} - -int spl_load_imx_container(struct spl_image_info *spl_image, - struct spl_load_info *info, ulong sector) -{ - return read_auth_container(spl_image, info, sector); -} |