All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] cmd/imxtract: Move decompression part to separate function
@ 2017-05-20  6:50 Alexey Ignatov
  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 ` [U-Boot] [PATCH 1/2] cmd/imxtract: Move decompression part to separate function Tom Rini
  0 siblings, 2 replies; 4+ messages in thread
From: Alexey Ignatov @ 2017-05-20  6:50 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-22 14:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-20  6:50 [U-Boot] [PATCH 1/2] cmd/imxtract: Move decompression part to separate function Alexey Ignatov
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

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.