From: Alexey Ignatov <lexszero@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] cmd/imxtract: Move decompression part to separate function
Date: Sat, 20 May 2017 09:50:19 +0300 [thread overview]
Message-ID: <20170520065020.28287-1-lexszero@gmail.com> (raw)
Signed-off-by: Alexey Ignatov <lexszero@gmail.com>
---
cmd/ximg.c | 142 +++++++++++++++++++++++++++++++++----------------------------
1 file changed, 76 insertions(+), 66 deletions(-)
diff --git a/cmd/ximg.c b/cmd/ximg.c
index d033c15b62..73a571b52b 100644
--- a/cmd/ximg.c
+++ b/cmd/ximg.c
@@ -28,6 +28,81 @@
#define CONFIG_SYS_XIMG_LEN 0x800000
#endif
+static int decompress_data(ulong dest, ulong data, ulong len,
+ uint8_t comp, int part)
+{
+#ifdef CONFIG_GZIP
+ uint unc_len = CONFIG_SYS_XIMG_LEN;
+#endif
+
+ switch (comp) {
+ case IH_COMP_NONE:
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+ {
+ size_t l = len;
+ size_t tail;
+ void *to = (void *) dest;
+ void *from = (void *)data;
+
+ printf(" Loading part %d ... ", part);
+
+ while (l > 0) {
+ tail = (l > CHUNKSZ) ? CHUNKSZ : l;
+ WATCHDOG_RESET();
+ memmove(to, from, tail);
+ to += tail;
+ from += tail;
+ l -= tail;
+ }
+ }
+#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
+ printf(" Loading part %d ... ", part);
+ memmove((char *) dest, (char *)data, len);
+#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
+ break;
+#ifdef CONFIG_GZIP
+ case IH_COMP_GZIP:
+ printf(" Uncompressing part %d ... ", part);
+ if (gunzip((void *) dest, unc_len,
+ (uchar *) data, &len) != 0) {
+ puts("GUNZIP ERROR - image not loaded\n");
+ return 1;
+ }
+ break;
+#endif
+#if defined(CONFIG_BZIP2) && defined(CONFIG_IMAGE_FORMAT_LEGACY)
+ case IH_COMP_BZIP2:
+ {
+ int i;
+
+ printf(" Uncompressing part %d ... ", part);
+ /*
+ * If we've got less than 4 MB of malloc()
+ * space, use slower decompression algorithm
+ * which requires at most 2300 KB of memory.
+ */
+ i = BZ2_bzBuffToBuffDecompress(
+ map_sysmem(ntohl(hdr->ih_load), 0),
+ &unc_len, (char *)data, len,
+ CONFIG_SYS_MALLOC_LEN < (4096 * 1024),
+ 0);
+ if (i != BZ_OK) {
+ printf("BUNZIP2 ERROR %d - "
+ "image not loaded\n", i);
+ return 1;
+ }
+ }
+ break;
+#endif /* CONFIG_BZIP2 */
+ default:
+ printf("Unimplemented compression type %d\n", comp);
+ return 1;
+ }
+ puts("OK\n");
+
+ return 0;
+}
+
static int
do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
@@ -47,9 +122,6 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
const void *fit_data;
size_t fit_len;
#endif
-#ifdef CONFIG_GZIP
- uint unc_len = CONFIG_SYS_XIMG_LEN;
-#endif
uint8_t comp;
verify = getenv_yesno("verify");
@@ -183,70 +255,8 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
}
if (argc > 3) {
- switch (comp) {
- case IH_COMP_NONE:
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
- {
- size_t l = len;
- size_t tail;
- void *to = (void *) dest;
- void *from = (void *)data;
-
- printf(" Loading part %d ... ", part);
-
- while (l > 0) {
- tail = (l > CHUNKSZ) ? CHUNKSZ : l;
- WATCHDOG_RESET();
- memmove(to, from, tail);
- to += tail;
- from += tail;
- l -= tail;
- }
- }
-#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
- printf(" Loading part %d ... ", part);
- memmove((char *) dest, (char *)data, len);
-#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
- break;
-#ifdef CONFIG_GZIP
- case IH_COMP_GZIP:
- printf(" Uncompressing part %d ... ", part);
- if (gunzip((void *) dest, unc_len,
- (uchar *) data, &len) != 0) {
- puts("GUNZIP ERROR - image not loaded\n");
- return 1;
- }
- break;
-#endif
-#if defined(CONFIG_BZIP2) && defined(CONFIG_IMAGE_FORMAT_LEGACY)
- case IH_COMP_BZIP2:
- {
- int i;
-
- printf(" Uncompressing part %d ... ", part);
- /*
- * If we've got less than 4 MB of malloc()
- * space, use slower decompression algorithm
- * which requires at most 2300 KB of memory.
- */
- i = BZ2_bzBuffToBuffDecompress(
- map_sysmem(ntohl(hdr->ih_load), 0),
- &unc_len, (char *)data, len,
- CONFIG_SYS_MALLOC_LEN < (4096 * 1024),
- 0);
- if (i != BZ_OK) {
- printf("BUNZIP2 ERROR %d - "
- "image not loaded\n", i);
- return 1;
- }
- }
- break;
-#endif /* CONFIG_BZIP2 */
- default:
- printf("Unimplemented compression type %d\n", comp);
+ if (!decompress_data(dest, data, len, comp, part))
return 1;
- }
- puts("OK\n");
}
flush_cache(dest, len);
--
2.12.2
next reply other threads:[~2017-05-20 6:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-20 6:50 Alexey Ignatov [this message]
2017-05-20 6:50 ` [U-Boot] [PATCH 2/2] cmd: fsfitxtract: Extract a part of a FIT multi-image stored on a filesystem Alexey Ignatov
2017-05-22 14:07 ` Tom Rini
2017-05-22 14:07 ` [U-Boot] [PATCH 1/2] cmd/imxtract: Move decompression part to separate function Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170520065020.28287-1-lexszero@gmail.com \
--to=lexszero@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.