blob: e3b9cc75ac2b9a90a383baa1e7e3b3b4f87ea2d8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Patrice Bouchand5527f832014-02-15 22:19:57 -07002/*
3 * (C) Copyright 2013 Patrice Bouchand <pbfwdlist_gmail_com>
4 * lzma uncompress command in Uboot
5 *
6 * made from existing cmd_unzip.c file of Uboot
7 *
8 * (C) Copyright 2000
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Patrice Bouchand5527f832014-02-15 22:19:57 -070010 */
11
12#include <common.h>
13#include <command.h>
Simon Glassc7694dd2019-08-01 09:46:46 -060014#include <env.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050015#include <mapmem.h>
Patrice Bouchand5527f832014-02-15 22:19:57 -070016#include <asm/io.h>
17
18#include <lzma/LzmaTools.h>
19
20static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
21{
22 unsigned long src, dst;
Simon Glass1bb718c2016-07-22 09:22:46 -060023 SizeT src_len = ~0UL, dst_len = ~0UL;
Patrice Bouchand5527f832014-02-15 22:19:57 -070024 int ret;
25
26 switch (argc) {
27 case 4:
28 dst_len = simple_strtoul(argv[3], NULL, 16);
29 /* fall through */
30 case 3:
31 src = simple_strtoul(argv[1], NULL, 16);
32 dst = simple_strtoul(argv[2], NULL, 16);
33 break;
34 default:
35 return CMD_RET_USAGE;
36 }
37
38 ret = lzmaBuffToBuffDecompress(map_sysmem(dst, dst_len), &src_len,
39 map_sysmem(src, 0), dst_len);
40
41 if (ret != SZ_OK)
42 return 1;
Simon Glass1bb718c2016-07-22 09:22:46 -060043 printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len,
44 (ulong)src_len);
Simon Glass018f5302017-08-03 12:22:10 -060045 env_set_hex("filesize", src_len);
Patrice Bouchand5527f832014-02-15 22:19:57 -070046
47 return 0;
48}
49
50U_BOOT_CMD(
51 lzmadec, 4, 1, do_lzmadec,
52 "lzma uncompress a memory region",
53 "srcaddr dstaddr [dstsize]"
54);