blob: 7b0b3fdd901b75f7f3ab64fee03cdafe783420b0 [file] [log] [blame]
Patrice Bouchand5527f832014-02-15 22:19:57 -07001/*
2 * (C) Copyright 2013 Patrice Bouchand <pbfwdlist_gmail_com>
3 * lzma uncompress command in Uboot
4 *
5 * made from existing cmd_unzip.c file of Uboot
6 *
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
10 * SPDX-License-Identifier: GPL-2.0+
11 */
12
13#include <common.h>
14#include <command.h>
15#include <asm/io.h>
16
17#include <lzma/LzmaTools.h>
18
19static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
20{
21 unsigned long src, dst;
22 unsigned long src_len = ~0UL, dst_len = ~0UL;
23 int ret;
24
25 switch (argc) {
26 case 4:
27 dst_len = simple_strtoul(argv[3], NULL, 16);
28 /* fall through */
29 case 3:
30 src = simple_strtoul(argv[1], NULL, 16);
31 dst = simple_strtoul(argv[2], NULL, 16);
32 break;
33 default:
34 return CMD_RET_USAGE;
35 }
36
37 ret = lzmaBuffToBuffDecompress(map_sysmem(dst, dst_len), &src_len,
38 map_sysmem(src, 0), dst_len);
39
40 if (ret != SZ_OK)
41 return 1;
42 printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
43 setenv_hex("filesize", src_len);
44
45 return 0;
46}
47
48U_BOOT_CMD(
49 lzmadec, 4, 1, do_lzmadec,
50 "lzma uncompress a memory region",
51 "srcaddr dstaddr [dstsize]"
52);