Patchwork [U-Boot,2/2] Add XZ compressed uImage support

login
register
mail settings
Submitter luigi.mantellini@idf-hit.com
Date Dec. 5, 2010, 3:16 p.m.
Message ID <1291562184-27126-2-git-send-email-luigi.mantellini@idf-hit.com>
Download mbox | patch
Permalink /patch/74300/
State Changes Requested
Headers show

Comments

luigi.mantellini@idf-hit.com - Dec. 5, 2010, 3:16 p.m.
This patch permits to use XZ compressed uImages using the XZ embedded library
code.

Signed-off-by: Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>
---
 common/cmd_bootm.c |   27 +++++++++++++++++++++++++--
 common/image.c     |    1 +
 include/image.h    |    1 +
 3 files changed, 27 insertions(+), 2 deletions(-)

Patch

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 1a024f1..066b908 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -61,6 +61,10 @@ 
 #include <linux/lzo.h>
 #endif /* CONFIG_LZO */
 
+#ifdef CONFIG_XZ
+#include <unxz.h>
+#endif /* CONFIG_XZ */
+
 DECLARE_GLOBAL_DATA_PTR;
 
 #ifndef CONFIG_SYS_BOOTM_LEN
@@ -338,9 +342,9 @@  static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 	ulong image_start = os.image_start;
 	ulong image_len = os.image_len;
 	uint unc_len = CONFIG_SYS_BOOTM_LEN;
-#if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
+#if defined(CONFIG_LZMA) || defined(CONFIG_LZO) || defined(CONFIG_XZ)
 	int ret;
-#endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
+#endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) || defined(CONFIG_XZ) */
 
 	const char *type_name = genimg_get_type_name (os.type);
 
@@ -430,6 +434,25 @@  static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 		*load_end = load + unc_len;
 		break;
 #endif /* CONFIG_LZO */
+#ifdef CONFIG_XZ
+	case IH_COMP_XZ: {
+		int in_used = unc_len;
+		printf ("   Uncompressing %s ... ", type_name);
+		ret = unxz(
+			(unsigned char *)image_start, image_len,
+			(unsigned char *)load, &in_used);
+		unc_len = in_used;
+		if (ret != 0) {
+			printf ("XZ: uncompress or overwrite error %d "
+				"- must RESET board to recover\n", ret);
+			show_boot_progress (-6);
+			return BOOTM_ERR_RESET;
+		}
+		*load_end = load + unc_len;
+		break;
+	}
+		break;
+#endif /* CONFIG_XZ */
 	default:
 		printf ("Unimplemented compression type %d\n", comp);
 		return BOOTM_ERR_UNIMPLEMENTED;
diff --git a/common/image.c b/common/image.c
index 42f5b79..4e31691 100644
--- a/common/image.c
+++ b/common/image.c
@@ -150,6 +150,7 @@  static table_entry_t uimage_comp[] = {
 	{	IH_COMP_GZIP,	"gzip",		"gzip compressed",	},
 	{	IH_COMP_LZMA,	"lzma",		"lzma compressed",	},
 	{	IH_COMP_LZO,	"lzo",		"lzo compressed",	},
+	{	IH_COMP_XZ,	"xz",		"xz compressed",	},
 	{	-1,		"",		"",			},
 };
 
diff --git a/include/image.h b/include/image.h
index 49d6280..5ba5afa 100644
--- a/include/image.h
+++ b/include/image.h
@@ -166,6 +166,7 @@ 
 #define IH_COMP_BZIP2		2	/* bzip2 Compression Used	*/
 #define IH_COMP_LZMA		3	/* lzma  Compression Used	*/
 #define IH_COMP_LZO		4	/* lzo   Compression Used	*/
+#define IH_COMP_XZ		5	/* xz    Compression Used       */
 
 #define IH_MAGIC	0x27051956	/* Image Magic Number		*/
 #define IH_NMLEN		32	/* Image Name Length		*/