Commit 1fd303543aef9c4641bd578e6e52284f5a69df67
Committed by
Marek Vasut
1 parent
4fa8375ffe
Exists in
smarc_8mq_lf_v2020.04
and in
9 other branches
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 <marek.vasut+renesas@gmail.com> Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org> Cc: Simon Glass <sjg@chromium.org> Cc: Tom Rini <trini@konsulko.com>
Showing 1 changed file with 13 additions and 6 deletions Side-by-side Diff
lib/fdtdec.c
... | ... | @@ -1183,17 +1183,22 @@ |
1183 | 1183 | static int uncompress_blob(const void *src, ulong sz_src, void **dstp) |
1184 | 1184 | { |
1185 | 1185 | size_t sz_out = CONFIG_SPL_MULTI_DTB_FIT_UNCOMPRESS_SZ; |
1186 | + bool gzip = 0, lzo = 0; | |
1186 | 1187 | ulong sz_in = sz_src; |
1187 | 1188 | void *dst; |
1188 | 1189 | int rc; |
1189 | 1190 | |
1190 | 1191 | if (CONFIG_IS_ENABLED(GZIP)) |
1191 | - if (gzip_parse_header(src, sz_in) < 0) | |
1192 | - return -1; | |
1192 | + if (gzip_parse_header(src, sz_in) >= 0) | |
1193 | + gzip = 1; | |
1193 | 1194 | if (CONFIG_IS_ENABLED(LZO)) |
1194 | - if (!lzop_is_valid_header(src)) | |
1195 | - return -EBADMSG; | |
1195 | + if (!gzip && lzop_is_valid_header(src)) | |
1196 | + lzo = 1; | |
1196 | 1197 | |
1198 | + if (!gzip && !lzo) | |
1199 | + return -EBADMSG; | |
1200 | + | |
1201 | + | |
1197 | 1202 | if (CONFIG_IS_ENABLED(MULTI_DTB_FIT_DYN_ALLOC)) { |
1198 | 1203 | dst = malloc(sz_out); |
1199 | 1204 | if (!dst) { |
1200 | 1205 | |
1201 | 1206 | |
... | ... | @@ -1208,10 +1213,12 @@ |
1208 | 1213 | # endif |
1209 | 1214 | } |
1210 | 1215 | |
1211 | - if (CONFIG_IS_ENABLED(GZIP)) | |
1216 | + if (CONFIG_IS_ENABLED(GZIP) && gzip) | |
1212 | 1217 | rc = gunzip(dst, sz_out, (u8 *)src, &sz_in); |
1213 | - else if (CONFIG_IS_ENABLED(LZO)) | |
1218 | + else if (CONFIG_IS_ENABLED(LZO) && lzo) | |
1214 | 1219 | rc = lzop_decompress(src, sz_in, dst, &sz_out); |
1220 | + else | |
1221 | + hang(); | |
1215 | 1222 | |
1216 | 1223 | if (rc < 0) { |
1217 | 1224 | /* not a valid compressed blob */ |