Yusuke Ashiduka | a20545d | 2020-02-20 20:48:01 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2020 |
| 4 | * FUJITSU COMPUTERTECHNOLOGIES LIMITED. All rights reserved. |
| 5 | */ |
| 6 | |
Yusuke Ashiduka | a20545d | 2020-02-20 20:48:01 +0900 | [diff] [blame] | 7 | #include <command.h> |
| 8 | #include <env.h> |
Jonathan Liu | 069fd5f | 2024-05-25 18:10:53 +1000 | [diff] [blame] | 9 | #include <mapmem.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 10 | #include <vsprintf.h> |
Simon Glass | caf6267 | 2021-10-09 09:28:21 -0600 | [diff] [blame] | 11 | #include <u-boot/lz4.h> |
Yusuke Ashiduka | a20545d | 2020-02-20 20:48:01 +0900 | [diff] [blame] | 12 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 13 | static int do_unlz4(struct cmd_tbl *cmdtp, int flag, int argc, |
| 14 | char *const argv[]) |
Yusuke Ashiduka | a20545d | 2020-02-20 20:48:01 +0900 | [diff] [blame] | 15 | { |
| 16 | unsigned long src, dst; |
| 17 | size_t src_len = ~0UL, dst_len = ~0UL; |
| 18 | int ret; |
| 19 | |
| 20 | switch (argc) { |
| 21 | case 4: |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 22 | src = hextoul(argv[1], NULL); |
| 23 | dst = hextoul(argv[2], NULL); |
| 24 | dst_len = hextoul(argv[3], NULL); |
Yusuke Ashiduka | a20545d | 2020-02-20 20:48:01 +0900 | [diff] [blame] | 25 | break; |
| 26 | default: |
| 27 | return CMD_RET_USAGE; |
| 28 | } |
| 29 | |
Jonathan Liu | 069fd5f | 2024-05-25 18:10:53 +1000 | [diff] [blame] | 30 | ret = ulz4fn(map_sysmem(src, 0), src_len, map_sysmem(dst, dst_len), |
| 31 | &dst_len); |
Yusuke Ashiduka | a20545d | 2020-02-20 20:48:01 +0900 | [diff] [blame] | 32 | if (ret) { |
| 33 | printf("Uncompressed err :%d\n", ret); |
| 34 | return 1; |
| 35 | } |
| 36 | |
| 37 | printf("Uncompressed size: %zd = 0x%zX\n", dst_len, dst_len); |
| 38 | env_set_hex("filesize", dst_len); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | U_BOOT_CMD(unlz4, 4, 1, do_unlz4, |
| 44 | "lz4 uncompress a memory region", |
| 45 | "srcaddr dstaddr dstsize\n" |
| 46 | "NOTE: Specify the destination size that is sufficiently larger\n" |
| 47 | " than the source size.\n" |
| 48 | ); |