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