[U-Boot] [PATCH 1/2] Add unlzma command

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@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]" +); +

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@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]" +);

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

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
participants (3)
-
Joe Hershberger
-
Joe Hershberger
-
Mike Frysinger