public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] Add unlzma command
@ 2012-08-17 20:59 Joe Hershberger
  2012-08-17 20:59 ` [U-Boot] [PATCH 2/2] Add unlzo command Joe Hershberger
  2012-08-17 23:28 ` [U-Boot] [PATCH 1/2] Add unlzma command Mike Frysinger
  0 siblings, 2 replies; 5+ messages in thread
From: Joe Hershberger @ 2012-08-17 20:59 UTC (permalink / raw)
  To: u-boot

Provide access to the lzma decompressor from the command line.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
---
 common/Makefile     |  3 +++
 common/cmd_unlzma.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
 create mode 100644 common/cmd_unlzma.c

diff --git a/common/Makefile b/common/Makefile
index 3d62775..b8568ba 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -153,6 +153,9 @@ COBJS-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
 COBJS-$(CONFIG_CMD_UBI) += cmd_ubi.o
 COBJS-$(CONFIG_CMD_UBIFS) += cmd_ubifs.o
 COBJS-$(CONFIG_CMD_UNIVERSE) += cmd_universe.o
+ifdef CONFIG_LZMA
+COBJS-$(CONFIG_CMD_UNLZMA) += cmd_unlzma.o
+endif
 COBJS-$(CONFIG_CMD_UNZIP) += cmd_unzip.o
 ifdef CONFIG_CMD_USB
 COBJS-y += cmd_usb.o
diff --git a/common/cmd_unlzma.c b/common/cmd_unlzma.c
new file mode 100644
index 0000000..c724607
--- /dev/null
+++ b/common/cmd_unlzma.c
@@ -0,0 +1,69 @@
+/*
+ * (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 <lzma/LzmaTypes.h>
+#include <lzma/LzmaDec.h>
+#include <lzma/LzmaTools.h>
+
+int do_unlzma(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 = lzmaBuffToBuffDecompress((void *)dst, &dst_len, (void *)src,
+		src_len);
+	if (ret != SZ_OK) {
+		printf("unlzma: 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(
+	unlzma,	5,	1,	do_unlzma,
+	"unlzma a memory region",
+	"srcaddr srcsize dstaddr [dstsize]"
+);
+
-- 
1.7.11.5

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

* [U-Boot] [PATCH 2/2] Add unlzo command
  2012-08-17 20:59 [U-Boot] [PATCH 1/2] Add unlzma command Joe Hershberger
@ 2012-08-17 20:59 ` Joe Hershberger
  2012-08-17 23:26   ` Mike Frysinger
  2012-08-17 23:28 ` [U-Boot] [PATCH 1/2] Add unlzma command Mike Frysinger
  1 sibling, 1 reply; 5+ messages in thread
From: Joe Hershberger @ 2012-08-17 20:59 UTC (permalink / raw)
  To: u-boot

Provide access to the lzo decompressor from the command line.

Signed-off-by: Joe Hershberger <joe.hershberger@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

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

* [U-Boot] [PATCH 2/2] Add unlzo command
  2012-08-17 20:59 ` [U-Boot] [PATCH 2/2] Add unlzo command Joe Hershberger
@ 2012-08-17 23:26   ` Mike Frysinger
  2012-09-18 21:25     ` Joe Hershberger
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Frysinger @ 2012-08-17 23:26 UTC (permalink / raw)
  To: u-boot

On Friday 17 August 2012 16:59:44 Joe Hershberger wrote:
> --- a/common/Makefile
> +++ b/common/Makefile
>
>  ifdef CONFIG_LZMA
>  COBJS-$(CONFIG_CMD_UNLZMA) += cmd_unlzma.o
>  endif
> +ifdef CONFIG_LZO
> +COBJS-$(CONFIG_CMD_UNLZO) += cmd_unlzo.o
> +endif

imo, these ifdefs shouldn't exist.  the commands shouldn't get silently 
ignored because someone omitted an option.  add an #ifdef check to the .c file 
and have it #error out if the necessary config options aren't defined.

> --- /dev/null
> +++ b/common/cmd_unlzo.c
>
> +int do_unlzo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])

static

> +	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;

how about returning ret ?

> +	sprintf(buf, "%lX", (unsigned long) dst_len);
> +	setenv("filesize", buf);

setenv_ulong() ?

> +U_BOOT_CMD(
> +	unlzo,	5,	1,	do_unlzo,
> +	"unlzo a memory region",
> +	"srcaddr srcsize dstaddr [dstsize]"
> +);

isn't there a way you could "stream" this so you don't need the srcsize ?  or 
does the lzop API not support that ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120817/e71f188e/attachment.pgp>

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

* [U-Boot] [PATCH 1/2] Add unlzma command
  2012-08-17 20:59 [U-Boot] [PATCH 1/2] Add unlzma command Joe Hershberger
  2012-08-17 20:59 ` [U-Boot] [PATCH 2/2] Add unlzo command Joe Hershberger
@ 2012-08-17 23:28 ` Mike Frysinger
  1 sibling, 0 replies; 5+ messages in thread
From: Mike Frysinger @ 2012-08-17 23:28 UTC (permalink / raw)
  To: u-boot

On Friday 17 August 2012 16:59:43 Joe Hershberger wrote:
> Provide access to the lzma decompressor from the command line.

same feedback for this file as the unlzo command feedback
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120817/a16107d4/attachment.pgp>

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

* [U-Boot] [PATCH 2/2] Add unlzo command
  2012-08-17 23:26   ` Mike Frysinger
@ 2012-09-18 21:25     ` Joe Hershberger
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Hershberger @ 2012-09-18 21:25 UTC (permalink / raw)
  To: u-boot

Hi Mike,

On Fri, Aug 17, 2012 at 6:26 PM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Friday 17 August 2012 16:59:44 Joe Hershberger wrote:
>> --- a/common/Makefile
>> +++ b/common/Makefile
>>
>>  ifdef CONFIG_LZMA
>>  COBJS-$(CONFIG_CMD_UNLZMA) += cmd_unlzma.o
>>  endif
>> +ifdef CONFIG_LZO
>> +COBJS-$(CONFIG_CMD_UNLZO) += cmd_unlzo.o
>> +endif
>
> imo, these ifdefs shouldn't exist.  the commands shouldn't get silently
> ignored because someone omitted an option.  add an #ifdef check to the .c file
> and have it #error out if the necessary config options aren't defined.

OK

>> --- /dev/null
>> +++ b/common/cmd_unlzo.c
>>
>> +int do_unlzo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>
> static

OK

>> +     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;
>
> how about returning ret ?

OK

>> +     sprintf(buf, "%lX", (unsigned long) dst_len);
>> +     setenv("filesize", buf);
>
> setenv_ulong() ?

OK

>> +U_BOOT_CMD(
>> +     unlzo,  5,      1,      do_unlzo,
>> +     "unlzo a memory region",
>> +     "srcaddr srcsize dstaddr [dstsize]"
>> +);
>
> isn't there a way you could "stream" this so you don't need the srcsize ?  or
> does the lzop API not support that ?

The lzo API uses the source size to check if the input is complete at
the end of the file.  I could pass in ~0 optionally and it would stop
at the end.  (It's not as clear how unlzma will handle it.)

So it would look like "unlzo srcaddr dstaddr [dstsize]"

Thanks,
-Joe

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

end of thread, other threads:[~2012-09-18 21:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-17 20:59 [U-Boot] [PATCH 1/2] Add unlzma command Joe Hershberger
2012-08-17 20:59 ` [U-Boot] [PATCH 2/2] Add unlzo command Joe Hershberger
2012-08-17 23:26   ` Mike Frysinger
2012-09-18 21:25     ` Joe Hershberger
2012-08-17 23:28 ` [U-Boot] [PATCH 1/2] Add unlzma command Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox