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/fdtdec.c') 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.2.3 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 --- lib/fdtdec.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/fdtdec.c') 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.2.3 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/fdtdec.c') 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.2.3 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 --- lib/fdtdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/fdtdec.c') 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.2.3