[U-Boot] [PATCH 2/2] Add unlzo command

Joe Hershberger joe.hershberger at ni.com
Fri Aug 17 22:59:44 CEST 2012


Provide access to the lzo decompressor from the command line.

Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
---
 common/Makefile    |  3 +++
 common/cmd_unlzo.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
 create mode 100644 common/cmd_unlzo.c

diff --git a/common/Makefile b/common/Makefile
index b8568ba..0793e50 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -156,6 +156,9 @@ COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o
 ifdef CONFIG_LZMA
 COBJS-$(CONFIG_CMD_UNLZMA) += cmd_unlzma.o
 endif
+ifdef CONFIG_LZO
+COBJS-$(CONFIG_CMD_UNLZO) += cmd_unlzo.o
+endif
 COBJS-$(CONFIG_CMD_UNZIP) += cmd_unzip.o
 ifdef CONFIG_CMD_USB
 COBJS-y += cmd_usb.o
diff --git a/common/cmd_unlzo.c b/common/cmd_unlzo.c
new file mode 100644
index 0000000..f7312c5
--- /dev/null
+++ b/common/cmd_unlzo.c
@@ -0,0 +1,65 @@
+/*
+ * (C) Copyright 2011
+ * Joe Hershberger, National Instruments, joe.hershberger at ni.com
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <linux/lzo.h>
+
+int do_unlzo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	unsigned long src, dst;
+	unsigned long src_len = ~0UL;
+	size_t dst_len = ~0UL;
+	int ret;
+	char buf[32];
+
+	switch (argc) {
+	case 5:
+		dst_len = simple_strtoul(argv[4], NULL, 16);
+		/* fall through */
+	case 4:
+		src = simple_strtoul(argv[1], NULL, 16);
+		src_len = simple_strtoul(argv[2], NULL, 16);
+		dst = simple_strtoul(argv[3], NULL, 16);
+		break;
+	default:
+		return CMD_RET_USAGE;
+	}
+
+	ret = lzop_decompress((void *)src, src_len, (void *)dst, &dst_len);
+	if (ret != LZO_E_OK) {
+		printf("unlzo: uncompress or overwrite error %d\n", ret);
+		return -1;
+	}
+	printf("Uncompressed size: %u\n", dst_len);
+	sprintf(buf, "%lX", (unsigned long) dst_len);
+	setenv("filesize", buf);
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	unlzo,	5,	1,	do_unlzo,
+	"unlzo a memory region",
+	"srcaddr srcsize dstaddr [dstsize]"
+);
-- 
1.7.11.5



More information about the U-Boot mailing list