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 | |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 12 | #include <command.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 13 | #include <env.h> |
Joe Hershberger | 65b905b | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 14 | #include <mapmem.h> |
Tom Rini | 5c1444f | 2024-04-27 08:10:59 -0600 | [diff] [blame] | 15 | #include <vsprintf.h> |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | |
| 18 | #include <lzma/LzmaTools.h> |
| 19 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 20 | static int do_lzmadec(struct cmd_tbl *cmdtp, int flag, int argc, |
| 21 | char *const argv[]) |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 22 | { |
| 23 | unsigned long src, dst; |
Simon Glass | 345fd88 | 2016-07-22 09:22:46 -0600 | [diff] [blame] | 24 | SizeT src_len = ~0UL, dst_len = ~0UL; |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 25 | int ret; |
| 26 | |
| 27 | switch (argc) { |
| 28 | case 4: |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 29 | dst_len = hextoul(argv[3], NULL); |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 30 | /* fall through */ |
| 31 | case 3: |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 32 | src = hextoul(argv[1], NULL); |
| 33 | dst = hextoul(argv[2], NULL); |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 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 Glass | 345fd88 | 2016-07-22 09:22:46 -0600 | [diff] [blame] | 44 | printf("Uncompressed size: %ld = %#lX\n", (ulong)src_len, |
| 45 | (ulong)src_len); |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 46 | env_set_hex("filesize", src_len); |
Patrice Bouchand | bd1f7ef | 2014-02-15 22:19:57 -0700 | [diff] [blame] | 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | U_BOOT_CMD( |
| 52 | lzmadec, 4, 1, do_lzmadec, |
| 53 | "lzma uncompress a memory region", |
| 54 | "srcaddr dstaddr [dstsize]" |
| 55 | ); |