From 3ebe09d09a407f93022d945a205c5318239eb3f6 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 5 Mar 2019 04:25:54 +0100 Subject: lib: fdt: Split fdtdec_setup_mem_size_base() Split fdtdec_setup_mem_size_base() into fdtdec_setup_mem_size_base_fdt(), which allows the caller to pass custom blob into the function and the original fdtdec_setup_mem_size_base(), which uses the gd->fdt_blob. This is useful when configuring the DRAM properties from a FDT blob fragment passed in by the firmware. Signed-off-by: Marek Vasut Cc: Nobuhiro Iwamatsu Cc: Simon Glass Cc: Tom Rini Reviewed-by: Simon Glass --- lib/fdtdec.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 09a7e133a53..3f29e9d6475 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1088,18 +1088,18 @@ int fdtdec_decode_display_timing(const void *blob, int parent, int index, return ret; } -int fdtdec_setup_mem_size_base(void) +int fdtdec_setup_mem_size_base_fdt(const void *blob) { int ret, mem; struct fdt_resource res; - mem = fdt_path_offset(gd->fdt_blob, "/memory"); + mem = fdt_path_offset(blob, "/memory"); if (mem < 0) { debug("%s: Missing /memory node\n", __func__); return -EINVAL; } - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", 0, &res); + ret = fdt_get_resource(blob, mem, "reg", 0, &res); if (ret != 0) { debug("%s: Unable to decode first memory bank\n", __func__); return -EINVAL; @@ -1113,6 +1113,11 @@ int fdtdec_setup_mem_size_base(void) return 0; } +int fdtdec_setup_mem_size_base(void) +{ + return fdtdec_setup_mem_size_base_fdt(gd->fdt_blob); +} + #if defined(CONFIG_NR_DRAM_BANKS) static int get_next_memory_node(const void *blob, int mem) -- cgit v1.3.1 From 118f4d4559a4386fa87a1e2509e84a1986b24a34 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 5 Mar 2019 04:25:55 +0100 Subject: lib: fdt: Split fdtdec_setup_memory_banksize() Split fdtdec_setup_memory_banksize() into fdtdec_setup_memory_banksize_fdt(), which allows the caller to pass custom blob into the function and the original fdtdec_setup_memory_banksize(), which uses the gd->fdt_blob. This is useful when configuring the DRAM properties from a FDT blob fragment passed in by the firmware. Signed-off-by: Marek Vasut Cc: Nobuhiro Iwamatsu Cc: Simon Glass Cc: Tom Rini Reviewed-by: Simon Glass --- include/fdtdec.h | 19 +++++++++++++++++++ lib/fdtdec.c | 18 ++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/include/fdtdec.h b/include/fdtdec.h index 3e681099a86..ad00f79f203 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -955,6 +955,25 @@ int fdtdec_setup_mem_size_base_fdt(const void *blob); */ int fdtdec_setup_mem_size_base(void); +/** + * fdtdec_setup_memory_banksize_fdt() - decode and populate gd->bd->bi_dram + * + * Decode the /memory 'reg' property to determine the address and size of the + * memory banks. Use this data to populate the global data board info with the + * phys address and size of memory banks. + * + * This function should be called from a boards dram_init_banksize(). This + * helper function allows for boards to query the device tree for memory bank + * information instead of hard coding the information in cases where it cannot + * be detected automatically. + * + * @param blob FDT blob + * + * @return 0 if OK, -EINVAL if the /memory node or reg property is missing or + * invalid + */ +int fdtdec_setup_memory_banksize_fdt(const void *blob); + /** * fdtdec_setup_memory_banksize() - decode and populate gd->bd->bi_dram * diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 3f29e9d6475..79915b59bdf 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1123,33 +1123,33 @@ int fdtdec_setup_mem_size_base(void) static int get_next_memory_node(const void *blob, int mem) { do { - mem = fdt_node_offset_by_prop_value(gd->fdt_blob, mem, + mem = fdt_node_offset_by_prop_value(blob, mem, "device_type", "memory", 7); } while (!fdtdec_get_is_enabled(blob, mem)); return mem; } -int fdtdec_setup_memory_banksize(void) +int fdtdec_setup_memory_banksize_fdt(const void *blob) { int bank, ret, mem, reg = 0; struct fdt_resource res; - mem = get_next_memory_node(gd->fdt_blob, -1); + mem = get_next_memory_node(blob, -1); if (mem < 0) { debug("%s: Missing /memory node\n", __func__); return -EINVAL; } for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); + ret = fdt_get_resource(blob, mem, "reg", reg++, &res); if (ret == -FDT_ERR_NOTFOUND) { reg = 0; - mem = get_next_memory_node(gd->fdt_blob, mem); + mem = get_next_memory_node(blob, mem); if (mem == -FDT_ERR_NOTFOUND) break; - ret = fdt_get_resource(gd->fdt_blob, mem, "reg", reg++, &res); + ret = fdt_get_resource(blob, mem, "reg", reg++, &res); if (ret == -FDT_ERR_NOTFOUND) break; } @@ -1169,6 +1169,12 @@ int fdtdec_setup_memory_banksize(void) return 0; } + +int fdtdec_setup_memory_banksize(void) +{ + return fdtdec_setup_memory_banksize_fdt(gd->fdt_blob); + +} #endif #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) -- cgit v1.3.1 From 1fd303543aef9c4641bd578e6e52284f5a69df67 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 13 Mar 2019 21:11:22 +0100 Subject: lib: fdt: Allow enabling both LZO and GZIP DT compression Allow enabling both LZO and GZIP DT compression in SPL and fix a bug where if the GZIP decompression failed, the LZO decompression would not even be attempted. Signed-off-by: Marek Vasut Cc: Nobuhiro Iwamatsu Cc: Simon Glass Cc: Tom Rini --- lib/fdtdec.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 79915b59bdf..d5e8b5a4200 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1183,16 +1183,21 @@ int fdtdec_setup_memory_banksize(void) static int uncompress_blob(const void *src, ulong sz_src, void **dstp) { size_t sz_out = CONFIG_SPL_MULTI_DTB_FIT_UNCOMPRESS_SZ; + bool gzip = 0, lzo = 0; ulong sz_in = sz_src; void *dst; int rc; if (CONFIG_IS_ENABLED(GZIP)) - if (gzip_parse_header(src, sz_in) < 0) - return -1; + if (gzip_parse_header(src, sz_in) >= 0) + gzip = 1; if (CONFIG_IS_ENABLED(LZO)) - if (!lzop_is_valid_header(src)) - return -EBADMSG; + if (!gzip && lzop_is_valid_header(src)) + lzo = 1; + + if (!gzip && !lzo) + return -EBADMSG; + if (CONFIG_IS_ENABLED(MULTI_DTB_FIT_DYN_ALLOC)) { dst = malloc(sz_out); @@ -1208,10 +1213,12 @@ static int uncompress_blob(const void *src, ulong sz_src, void **dstp) # endif } - if (CONFIG_IS_ENABLED(GZIP)) + if (CONFIG_IS_ENABLED(GZIP) && gzip) rc = gunzip(dst, sz_out, (u8 *)src, &sz_in); - else if (CONFIG_IS_ENABLED(LZO)) + else if (CONFIG_IS_ENABLED(LZO) && lzo) rc = lzop_decompress(src, sz_in, dst, &sz_out); + else + hang(); if (rc < 0) { /* not a valid compressed blob */ -- cgit v1.3.1 From 95f4bbd581cfde45d4bd1fa5e56c2d880dae7ced Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 8 Mar 2019 16:06:55 +0100 Subject: lib: fdt: Allow LZO and GZIP DT compression in U-Boot Add required Kconfig symbols, Makefile bits and macro fixes in a few places to support LZO and DT compression in U-Boot. This can save a lot of space with multi-DTB fitImages. Signed-off-by: Marek Vasut Cc: Nobuhiro Iwamatsu Cc: Simon Glass Cc: Tom Rini Signed-off-by: Marek Vasut --- Makefile | 16 ++++++++++++- dts/Kconfig | 57 +++++++++++++++++++++++++++++++++++++++++++++++ include/config_defaults.h | 3 --- lib/Kconfig | 13 +++++++++++ lib/fdtdec.c | 2 +- 5 files changed, 86 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/Makefile b/Makefile index aedc2ea4d93..4e4a33d99b0 100644 --- a/Makefile +++ b/Makefile @@ -1020,6 +1020,20 @@ quiet_cmd_copy = COPY $@ ifeq ($(CONFIG_MULTI_DTB_FIT),y) +ifeq ($(CONFIG_MULTI_DTB_FIT_LZO),y) +FINAL_DTB_CONTAINER = fit-dtb.blob.lzo +else ifeq ($(CONFIG_MULTI_DTB_FIT_GZIP),y) +FINAL_DTB_CONTAINER = fit-dtb.blob.gz +else +FINAL_DTB_CONTAINER = fit-dtb.blob +endif + +fit-dtb.blob.gz: fit-dtb.blob + @gzip -kf9 $< > $@ + +fit-dtb.blob.lzo: fit-dtb.blob + @lzop -f9 $< > $@ + fit-dtb.blob: dts/dt.dtb FORCE $(call if_changed,mkimage) @@ -1027,7 +1041,7 @@ MKIMAGEFLAGS_fit-dtb.blob = -f auto -A $(ARCH) -T firmware -C none -O u-boot \ -a 0 -e 0 -E \ $(patsubst %,-b arch/$(ARCH)/dts/%.dtb,$(subst ",,$(CONFIG_OF_LIST))) -d /dev/null -u-boot-fit-dtb.bin: u-boot-nodtb.bin fit-dtb.blob +u-boot-fit-dtb.bin: u-boot-nodtb.bin $(FINAL_DTB_CONTAINER) $(call if_changed,cat) u-boot.bin: u-boot-fit-dtb.bin FORCE diff --git a/dts/Kconfig b/dts/Kconfig index 3e85914d115..a5f30c8fd03 100644 --- a/dts/Kconfig +++ b/dts/Kconfig @@ -130,6 +130,63 @@ config OF_LIST device tree files (without the directory or .dtb suffix) separated by . +choice + prompt "SPL OF LIST compression" + depends on MULTI_DTB_FIT + default MULTI_DTB_FIT_NO_COMPRESSION + +config MULTI_DTB_FIT_LZO + bool "LZO" + depends on SYS_MALLOC_F + select LZO + help + Compress the FIT image containing the DTBs available for the SPL + using LZO compression. (requires lzop on host). + +config MULTI_DTB_FIT_GZIP + bool "GZIP" + depends on SYS_MALLOC_F + select GZIP + help + Compress the FIT image containing the DTBs available for the SPL + using GZIP compression. (requires gzip on host) + +config MULTI_DTB_FIT_NO_COMPRESSION + bool "No compression" + help + Do not compress the FIT image containing the DTBs available for the SPL. + Use this options only if LZO is not available and the DTBs are very small. +endchoice + +choice + prompt "Location of uncompressed DTBs" + depends on (MULTI_DTB_FIT_GZIP || MULTI_DTB_FIT_LZO) + default MULTI_DTB_FIT_DYN_ALLOC if SYS_MALLOC_F + +config MULTI_DTB_FIT_DYN_ALLOC + bool "Dynamically allocate the memory" + depends on SYS_MALLOC_F + +config MULTI_DTB_FIT_USER_DEFINED_AREA + bool "User-defined location" +endchoice + +config MULTI_DTB_FIT_UNCOMPRESS_SZ + hex "Size of memory reserved to uncompress the DTBs" + depends on (MULTI_DTB_FIT_GZIP || MULTI_DTB_FIT_LZO) + default 0x8000 + help + This is the size of this area where the DTBs are uncompressed. + If this area is dynamically allocated, make sure that + SYS_MALLOC_F_LEN is big enough to contain it. + +config MULTI_DTB_FIT_USER_DEF_ADDR + hex "Address of memory where dtbs are uncompressed" + depends on MULTI_DTB_FIT_USER_DEFINED_AREA + help + the FIT image containing the DTBs is uncompressed in an area defined + at compilation time. This is the address of this area. It must be + aligned on 2-byte boundary. config DTB_RESELECT bool "Support swapping dtbs at a later point in boot" diff --git a/include/config_defaults.h b/include/config_defaults.h index 7ef928bbe14..4ed09683b65 100644 --- a/include/config_defaults.h +++ b/include/config_defaults.h @@ -16,7 +16,4 @@ #define CONFIG_BOOTM_RTEMS 1 #define CONFIG_BOOTM_VXWORKS 1 -#define CONFIG_GZIP 1 -#define CONFIG_ZLIB 1 - #endif diff --git a/lib/Kconfig b/lib/Kconfig index 366d164cd76..8fe5d85a050 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -301,6 +301,19 @@ config LZO help This enables support for LZO compression algorithm.r +config GZIP + bool "Enable gzip decompression support for SPL build" + select ZLIB + default y + help + This enables support for GZIP compression algorithm. + +config ZLIB + bool + default y + help + This enables ZLIB compression lib. + config SPL_LZ4 bool "Enable LZ4 decompression support in SPL" help diff --git a/lib/fdtdec.c b/lib/fdtdec.c index d5e8b5a4200..a51dc5e9867 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1182,7 +1182,7 @@ int fdtdec_setup_memory_banksize(void) CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO) static int uncompress_blob(const void *src, ulong sz_src, void **dstp) { - size_t sz_out = CONFIG_SPL_MULTI_DTB_FIT_UNCOMPRESS_SZ; + size_t sz_out = CONFIG_VAL(MULTI_DTB_FIT_UNCOMPRESS_SZ); bool gzip = 0, lzo = 0; ulong sz_in = sz_src; void *dst; -- cgit v1.3.1