common: relocate fdt_blob in global_data for FDTSRC_EMBED case
[u-boot.git] / cmd / lzmadec.c
blobc40b96941b477b035b4551e34345c80c8e0f28cb
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2013 Patrice Bouchand <pbfwdlist_gmail_com>
4 * lzma uncompress command in Uboot
6 * made from existing cmd_unzip.c file of Uboot
8 * (C) Copyright 2000
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 #include <command.h>
13 #include <env.h>
14 #include <mapmem.h>
15 #include <vsprintf.h>
16 #include <asm/io.h>
18 #include <lzma/LzmaTools.h>
20 static int do_lzmadec(struct cmd_tbl *cmdtp, int flag, int argc,
21 char *const argv[])
23 unsigned long src, dst;
24 SizeT src_len = ~0UL, dst_len = ~0UL;
25 int ret;
27 switch (argc) {
28 case 4:
29 dst_len = hextoul(argv[3], NULL);
30 /* fall through */
31 case 3:
32 src = hextoul(argv[1], NULL);
33 dst = hextoul(argv[2], NULL);
34 break;
35 default:
36 return CMD_RET_USAGE;
39 ret = lzmaBuffToBuffDecompress(map_sysmem(dst, dst_len), &src_len,
40 map_sysmem(src, 0), dst_len);
42 if (ret != SZ_OK)
43 return 1;
44 printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len,
45 (ulong)src_len);
46 env_set_hex("filesize", src_len);
48 return 0;
51 U_BOOT_CMD(
52 lzmadec, 4, 1, do_lzmadec,
53 "lzma uncompress a memory region",
54 "srcaddr dstaddr [dstsize]"