1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
22e192b24SSimon Glass /*
32e192b24SSimon Glass * (C) Copyright 2013 Patrice Bouchand <pbfwdlist_gmail_com>
42e192b24SSimon Glass * lzma uncompress command in Uboot
52e192b24SSimon Glass *
62e192b24SSimon Glass * made from existing cmd_unzip.c file of Uboot
72e192b24SSimon Glass *
82e192b24SSimon Glass * (C) Copyright 2000
92e192b24SSimon Glass * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
102e192b24SSimon Glass */
112e192b24SSimon Glass
122e192b24SSimon Glass #include <common.h>
132e192b24SSimon Glass #include <command.h>
142e192b24SSimon Glass #include <mapmem.h>
152e192b24SSimon Glass #include <asm/io.h>
162e192b24SSimon Glass
172e192b24SSimon Glass #include <lzma/LzmaTools.h>
182e192b24SSimon Glass
do_lzmadec(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])192e192b24SSimon Glass static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
202e192b24SSimon Glass {
212e192b24SSimon Glass unsigned long src, dst;
221bb718cdSSimon Glass SizeT src_len = ~0UL, dst_len = ~0UL;
232e192b24SSimon Glass int ret;
242e192b24SSimon Glass
252e192b24SSimon Glass switch (argc) {
262e192b24SSimon Glass case 4:
272e192b24SSimon Glass dst_len = simple_strtoul(argv[3], NULL, 16);
282e192b24SSimon Glass /* fall through */
292e192b24SSimon Glass case 3:
302e192b24SSimon Glass src = simple_strtoul(argv[1], NULL, 16);
312e192b24SSimon Glass dst = simple_strtoul(argv[2], NULL, 16);
322e192b24SSimon Glass break;
332e192b24SSimon Glass default:
342e192b24SSimon Glass return CMD_RET_USAGE;
352e192b24SSimon Glass }
362e192b24SSimon Glass
372e192b24SSimon Glass ret = lzmaBuffToBuffDecompress(map_sysmem(dst, dst_len), &src_len,
382e192b24SSimon Glass map_sysmem(src, 0), dst_len);
392e192b24SSimon Glass
402e192b24SSimon Glass if (ret != SZ_OK)
412e192b24SSimon Glass return 1;
421bb718cdSSimon Glass printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len,
431bb718cdSSimon Glass (ulong)src_len);
44018f5303SSimon Glass env_set_hex("filesize", src_len);
452e192b24SSimon Glass
462e192b24SSimon Glass return 0;
472e192b24SSimon Glass }
482e192b24SSimon Glass
492e192b24SSimon Glass U_BOOT_CMD(
502e192b24SSimon Glass lzmadec, 4, 1, do_lzmadec,
512e192b24SSimon Glass "lzma uncompress a memory region",
522e192b24SSimon Glass "srcaddr dstaddr [dstsize]"
532e192b24SSimon Glass );
54