blob: 3b8db0a8538584f7520392e600f85d9af8809e97 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Patrice Bouchandbd1f7ef2014-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 Bouchandbd1f7ef2014-02-15 22:19:57 -070010 */
11
12#include <common.h>
13#include <command.h>
Simon Glass313112a2019-08-01 09:46:46 -060014#include <env.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050015#include <mapmem.h>
Patrice Bouchandbd1f7ef2014-02-15 22:19:57 -070016#include <asm/io.h>
17
18#include <lzma/LzmaTools.h>
19
Simon Glassed38aef2020-05-10 11:40:03 -060020static int do_lzmadec(struct cmd_tbl *cmdtp, int flag, int argc,
21 char *const argv[])
Patrice Bouchandbd1f7ef2014-02-15 22:19:57 -070022{
23 unsigned long src, dst;
Simon Glass345fd882016-07-22 09:22:46 -060024 SizeT src_len = ~0UL, dst_len = ~0UL;
Patrice Bouchandbd1f7ef2014-02-15 22:19:57 -070025 int ret;
26
27 switch (argc) {
28 case 4:
29 dst_len = simple_strtoul(argv[3], NULL, 16);
30 /* fall through */
31 case 3:
32 src = simple_strtoul(argv[1], NULL, 16);
33 dst = simple_strtoul(argv[2], NULL, 16);
34 break;
35 default:
36 return CMD_RET_USAGE;
37 }
38
39 ret = lzmaBuffToBuffDecompress(map_sysmem(dst, dst_len), &src_len,
40 map_sysmem(src, 0), dst_len);
41
42 if (ret != SZ_OK)
43 return 1;
Simon Glass345fd882016-07-22 09:22:46 -060044 printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len,
45 (ulong)src_len);
Simon Glass4d949a22017-08-03 12:22:10 -060046 env_set_hex("filesize", src_len);
Patrice Bouchandbd1f7ef2014-02-15 22:19:57 -070047
48 return 0;
49}
50
51U_BOOT_CMD(
52 lzmadec, 4, 1, do_lzmadec,
53 "lzma uncompress a memory region",
54 "srcaddr dstaddr [dstsize]"
55);