Nothing exercises the decompression in load_simple_fit(): create_fit() only ever writes compression = "none", and the canned LZMA blob is only used on the legacy uImage path.
Let create_fit() take a compression, and load a compressed FIT both ways: with the data inside the FIT and beside it, since only the latter stages it through CONFIG_SYS_LOAD_ADDR. Point that address at the same offset sandbox_noinst uses, since otherwise the staging corrupts what's currently at 0x0. Signed-off-by: Alexey Charkov <[email protected]> --- configs/sandbox_spl_defconfig | 2 +- include/test/spl.h | 8 +++++++ test/image/spl_load.c | 52 ++++++++++++++++++++++++++++++------------- test/image/spl_load_nor.c | 2 ++ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index 11f16f5d6220..bec02ce7bb1b 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -6,7 +6,7 @@ CONFIG_ENV_SIZE=0x2000 CONFIG_SPL_SYS_MALLOC_F_LEN=0x8000 CONFIG_SPL_SERIAL=y CONFIG_SPL_DRIVERS_MISC=y -CONFIG_SYS_LOAD_ADDR=0x0 +CONFIG_SYS_LOAD_ADDR=0x1000000 CONFIG_SPL=y CONFIG_PCI=y CONFIG_SANDBOX_SPL=y diff --git a/include/test/spl.h b/include/test/spl.h index c5349b06e290..ce0e636d2537 100644 --- a/include/test/spl.h +++ b/include/test/spl.h @@ -30,14 +30,18 @@ void generate_data(char *data, size_t size, const char *test_name); * @LEGACY_LZMA: "Legacy" uImages, LZMA compressed * @IMX8: i.MX8 Container images * @FIT_INTERNAL: FITs with internal data + * @FIT_INTERNAL_LZMA: FITs with internal data, LZMA compressed * @FIT_EXTERNAL: FITs with external data + * @FIT_EXTERNAL_LZMA: FITs with external data, LZMA compressed */ enum spl_test_image { LEGACY, LEGACY_LZMA, IMX8, FIT_INTERNAL, + FIT_INTERNAL_LZMA, FIT_EXTERNAL, + FIT_EXTERNAL_LZMA, }; /** @@ -131,6 +135,10 @@ static inline bool image_supported(enum spl_test_image type) return IS_ENABLED(CONFIG_SPL_LEGACY_IMAGE_FORMAT); case IMX8: return IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER); + case FIT_INTERNAL_LZMA: + case FIT_EXTERNAL_LZMA: + if (!IS_ENABLED(CONFIG_SPL_LZMA)) + return false; case FIT_INTERNAL: case FIT_EXTERNAL: return IS_ENABLED(CONFIG_SPL_LOAD_FIT); diff --git a/test/image/spl_load.c b/test/image/spl_load.c index 34ddc49d2463..1fc0b8e9552e 100644 --- a/test/image/spl_load.c +++ b/test/image/spl_load.c @@ -40,7 +40,25 @@ void *board_spl_fit_buffer_addr(ulong fit_size, int sectors, int bl_len) /* Local flags for spl_image; start from the "top" to avoid conflicts */ #define SPL_IMX_CONTAINER 0x80000000 -#define SPL_COMP_LZMA 0x40000000 +#define SPL_COMPRESSED 0x40000000 + +/** + * image_compression() - compression a test image carries its payload in + * @type: The type of image + * + * Return: the FIT "compression" name, or NULL for an uncompressed payload + */ +static const char *image_compression(enum spl_test_image type) +{ + switch (type) { + case LEGACY_LZMA: + case FIT_INTERNAL_LZMA: + case FIT_EXTERNAL_LZMA: + return "lzma"; + default: + return NULL; + } +} void generate_data(char *data, size_t size, const char *test_name) { @@ -77,7 +95,7 @@ static size_t create_legacy(void *dst, struct spl_image_info *spl_image, image_set_os(hdr, spl_image->os); image_set_arch(hdr, IH_ARCH_DEFAULT); image_set_type(hdr, IH_TYPE_FIRMWARE); - image_set_comp(hdr, spl_image->flags & SPL_COMP_LZMA ? IH_COMP_LZMA : + image_set_comp(hdr, spl_image->flags & SPL_COMPRESSED ? IH_COMP_LZMA : IH_COMP_NONE); image_set_name(hdr, spl_image->name); image_set_hcrc(hdr, crc32(0, (void *)hdr, sizeof(*hdr))); @@ -161,7 +179,7 @@ static size_t start_fit(void *dst, size_t fit_size, size_t data_size, } static size_t create_fit(void *dst, struct spl_image_info *spl_image, - size_t *data_offset, bool external) + size_t *data_offset, bool external, const char *comp) { /* * The name goes in twice, as the description of both the image and the @@ -219,7 +237,7 @@ static size_t create_fit(void *dst, struct spl_image_info *spl_image, return 0; if (fdt_property_string(dst, FIT_TYPE_PROP, "firmware")) return 0; - if (fdt_property_string(dst, FIT_COMP_PROP, "none")) + if (fdt_property_string(dst, FIT_COMP_PROP, comp)) return 0; if (fdt_property_u32(dst, FIT_DATA_SIZE_PROP, spl_image->size)) return 0; @@ -271,22 +289,23 @@ out: size_t create_image(void *dst, enum spl_test_image type, struct spl_image_info *info, size_t *data_offset) { + const char *comp = image_compression(type); bool external = false; info->os = IH_OS_U_BOOT; info->load_addr = CONFIG_TEXT_BASE; info->entry_point = CONFIG_TEXT_BASE + 0x100; - info->flags = 0; + info->flags = comp ? SPL_COMPRESSED : 0; switch (type) { case LEGACY_LZMA: - info->flags = SPL_COMP_LZMA; case LEGACY: return create_legacy(dst, info, data_offset); case IMX8: info->flags = SPL_IMX_CONTAINER; return create_imx8(dst, info, data_offset); case FIT_EXTERNAL: + case FIT_EXTERNAL_LZMA: /* * spl_fit_append_fdt will clobber external images with U-Boot's * FDT if the image doesn't have one. Just set the OS to @@ -296,8 +315,10 @@ size_t create_image(void *dst, enum spl_test_image type, info->os = IH_OS_TEE; external = true; case FIT_INTERNAL: - info->flags = SPL_FIT_FOUND; - return create_fit(dst, info, data_offset, external); + case FIT_INTERNAL_LZMA: + info->flags |= SPL_FIT_FOUND; + return create_fit(dst, info, data_offset, external, + comp ?: "none"); } return 0; @@ -325,7 +346,7 @@ int check_image_info(struct unit_test_state *uts, struct spl_image_info *info1, ut_asserteq(info1->load_addr, info2->load_addr); if (info1->flags & SPL_IMX_CONTAINER) ut_asserteq(0, info2->size); - else if (!(info1->flags & SPL_COMP_LZMA)) + else if (!(info1->flags & SPL_COMPRESSED)) ut_asserteq(info1->size, info2->size); } else { ut_asserteq(info1->load_addr - sizeof(struct legacy_img_hdr), @@ -781,10 +802,10 @@ int do_spl_test_load(struct unit_test_state *uts, const char *test_name, int (*write_image)(struct unit_test_state *, void *, size_t)) { size_t img_size, img_data, plain_size = SPL_TEST_DATA_SIZE; + bool compressed = image_compression(type); struct spl_image_info info_write = { .name = test_name, - .size = type == LEGACY_LZMA ? sizeof(lzma_compressed) : - plain_size, + .size = compressed ? lzma_compressed_size : plain_size, }, info_read = { }; struct spl_boot_device bootdev = { .boot_device = loader->boot_device, @@ -798,11 +819,12 @@ int do_spl_test_load(struct unit_test_state *uts, const char *test_name, ut_assertnonnull(img); data = img + img_data; - if (type == LEGACY_LZMA) { + if (compressed) { plain = malloc(plain_size); ut_assertnonnull(plain); + /* The canned blob holds what this seed generates */ generate_data(plain, plain_size, "lzma"); - memcpy(data, lzma_compressed, sizeof(lzma_compressed)); + memcpy(data, lzma_compressed, lzma_compressed_size); } else { plain = data; generate_data(plain, plain_size, test_name); @@ -815,11 +837,11 @@ int do_spl_test_load(struct unit_test_state *uts, const char *test_name, ut_assertok(loader->load_image(&info_read, &bootdev)); if (check_image_info(uts, &info_write, &info_read)) return CMD_RET_FAILURE; - if (type == LEGACY_LZMA) + if (compressed) ut_asserteq(plain_size, info_read.size); ut_asserteq_mem(plain, phys_to_virt(info_write.load_addr), plain_size); - if (type == LEGACY_LZMA) + if (compressed) free(plain); free(img); return 0; diff --git a/test/image/spl_load_nor.c b/test/image/spl_load_nor.c index f53a6724e27f..32265f6346f4 100644 --- a/test/image/spl_load_nor.c +++ b/test/image/spl_load_nor.c @@ -35,6 +35,8 @@ SPL_IMG_TEST(spl_test_nor, LEGACY, 0); SPL_IMG_TEST(spl_test_nor, LEGACY_LZMA, 0); SPL_IMG_TEST(spl_test_nor, IMX8, 0); SPL_IMG_TEST(spl_test_nor, FIT_INTERNAL, 0); +SPL_IMG_TEST(spl_test_nor, FIT_INTERNAL_LZMA, 0); #if !IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL) SPL_IMG_TEST(spl_test_nor, FIT_EXTERNAL, 0); +SPL_IMG_TEST(spl_test_nor, FIT_EXTERNAL_LZMA, 0); #endif -- 2.55.0
