diff mbox series

cmd: Add unlz4 command

Message ID 20200220114801.4292-1-ashiduka@fujitsu.com
State Accepted
Commit a17322329b3b1526b23f8e1f6573a5d4f737c573
Headers show
Series cmd: Add unlz4 command | expand

Commit Message

ashiduka@fujitsu.com Feb. 20, 2020, 11:48 a.m. UTC
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 at fujitsu.com>
---
 cmd/Kconfig  |  7 +++++++
 cmd/Makefile |  1 +
 cmd/unlz4.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 cmd/unlz4.c

Comments

Tom Rini April 21, 2020, 12:25 p.m. UTC | #1
On Thu, Feb 20, 2020 at 08:48:01PM +0900, Yusuke Ashiduka wrote:

> 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 at fujitsu.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6403bc45a5..3607edd2d2 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -769,6 +769,13 @@  config CMD_LZMADEC
 	  Support decompressing an LZMA (Lempel-Ziv-Markov chain algorithm)
 	  image from memory.
 
+config CMD_UNLZ4
+	bool "unlz4"
+	default y if CMD_BOOTI
+	select LZ4
+	help
+	  Support decompressing an LZ4 image from memory region.
+
 config CMD_UNZIP
 	bool "unzip"
 	default y if CMD_BOOTI
diff --git a/cmd/Makefile b/cmd/Makefile
index f1dd513a4b..6692ed96c6 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -144,6 +144,7 @@  obj-$(CONFIG_CMD_TSI148) += tsi148.o
 obj-$(CONFIG_CMD_UBI) += ubi.o
 obj-$(CONFIG_CMD_UBIFS) += ubifs.o
 obj-$(CONFIG_CMD_UNIVERSE) += universe.o
+obj-$(CONFIG_CMD_UNLZ4) += unlz4.o
 obj-$(CONFIG_CMD_UNZIP) += unzip.o
 obj-$(CONFIG_CMD_VIRTIO) += virtio.o
 obj-$(CONFIG_CMD_WDT) += wdt.o
diff --git a/cmd/unlz4.c b/cmd/unlz4.c
new file mode 100644
index 0000000000..4d3af53fea
--- /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: %ld = 0x%lX\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"
+);