Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 2 | /* |
| 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 Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <command.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 14 | #include <mapmem.h> |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | |
| 17 | #include <lzma/LzmaTools.h> |
| 18 | |
| 19 | static int do_lzmadec(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 20 | { |
| 21 | unsigned long src, dst; |
Simon Glass | 345fd88 | 2016-07-22 09:22:46 -0600 | [diff] [blame] | 22 | SizeT src_len = ~0UL, dst_len = ~0UL; |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 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; |
Simon Glass | 345fd88 | 2016-07-22 09:22:46 -0600 | [diff] [blame] | 42 | printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len, |
| 43 | (ulong)src_len); |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 44 | env_set_hex("filesize", src_len); |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | U_BOOT_CMD( |
| 50 | lzmadec, 4, 1, do_lzmadec, |
| 51 | "lzma uncompress a memory region", |
| 52 | "srcaddr dstaddr [dstsize]" |
| 53 | ); |