blob: 5320b378d33a953248cbade2a297714d3ef25bef [file] [log] [blame]
Yusuke Ashidukaa20545d2020-02-20 20:48:01 +09001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020
4 * FUJITSU COMPUTERTECHNOLOGIES LIMITED. All rights reserved.
5 */
6
7#include <common.h>
8#include <command.h>
9#include <env.h>
10#include <lz4.h>
11
12static int do_unlz4(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
13{
14 unsigned long src, dst;
15 size_t src_len = ~0UL, dst_len = ~0UL;
16 int ret;
17
18 switch (argc) {
19 case 4:
20 src = simple_strtoul(argv[1], NULL, 16);
21 dst = simple_strtoul(argv[2], NULL, 16);
22 dst_len = simple_strtoul(argv[3], NULL, 16);
23 break;
24 default:
25 return CMD_RET_USAGE;
26 }
27
28 ret = ulz4fn((void *)src, src_len, (void *)dst, &dst_len);
29 if (ret) {
30 printf("Uncompressed err :%d\n", ret);
31 return 1;
32 }
33
34 printf("Uncompressed size: %zd = 0x%zX\n", dst_len, dst_len);
35 env_set_hex("filesize", dst_len);
36
37 return 0;
38}
39
40U_BOOT_CMD(unlz4, 4, 1, do_unlz4,
41 "lz4 uncompress a memory region",
42 "srcaddr dstaddr dstsize\n"
43 "NOTE: Specify the destination size that is sufficiently larger\n"
44 " than the source size.\n"
45);