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