diff options
author | Yusuke Ashiduka <ashiduka@fujitsu.com> | 2020-02-20 20:48:01 +0900 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-04-17 12:32:12 -0400 |
commit | a17322329b3b1526b23f8e1f6573a5d4f737c573 (patch) | |
tree | 2ca66046f91dec36d6b610416c84d0e5f5f8a0b0 /cmd/unlz4.c | |
parent | 46d9d1c306967780d7afbfcbf942daf9ab33c466 (diff) | |
download | u-boot-socfpga-a17322329b3b1526b23f8e1f6573a5d4f737c573.tar.gz |
cmd: Add unlz4 command
This command is a new command called "unlz4" that decompresses from memory
into memory.
Used with the CONFIG_CMD_UNLZ4 optionenabled.
Signed-off-by: Yusuke Ashiduka <ashiduka@fujitsu.com>
[trini: Use %zd / %zX not %ld / %lX in printf]
Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'cmd/unlz4.c')
-rw-r--r-- | cmd/unlz4.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cmd/unlz4.c b/cmd/unlz4.c new file mode 100644 index 0000000000..5320b378d3 --- /dev/null +++ b/cmd/unlz4.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 + * FUJITSU COMPUTERTECHNOLOGIES LIMITED. All rights reserved. + */ + +#include <common.h> +#include <command.h> +#include <env.h> +#include <lz4.h> + +static int do_unlz4(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + unsigned long src, dst; + size_t src_len = ~0UL, dst_len = ~0UL; + int ret; + + switch (argc) { + case 4: + src = simple_strtoul(argv[1], NULL, 16); + dst = simple_strtoul(argv[2], NULL, 16); + dst_len = simple_strtoul(argv[3], NULL, 16); + break; + default: + return CMD_RET_USAGE; + } + + ret = ulz4fn((void *)src, src_len, (void *)dst, &dst_len); + if (ret) { + printf("Uncompressed err :%d\n", ret); + return 1; + } + + printf("Uncompressed size: %zd = 0x%zX\n", dst_len, dst_len); + env_set_hex("filesize", dst_len); + + return 0; +} + +U_BOOT_CMD(unlz4, 4, 1, do_unlz4, + "lz4 uncompress a memory region", + "srcaddr dstaddr dstsize\n" + "NOTE: Specify the destination size that is sufficiently larger\n" + " than the source size.\n" +); |