All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cmd: cat: add new command
@ 2022-05-22  8:37 Roger Knecht
  0 siblings, 0 replies; only message in thread
From: Roger Knecht @ 2022-05-22  8:37 UTC (permalink / raw)
  To: u-boot; +Cc: rknecht

Add cat command to print file content to standard out

Signed-off-by: Roger Knecht <rknecht@pm.me>
---
 cmd/Kconfig  |  6 ++++++
 cmd/Makefile |  1 +
 cmd/cat.c    | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 cmd/cat.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 69c1814d24..2cb719795c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -385,6 +385,12 @@ config CMD_ABOOTIMG

 	  See doc/android/boot-image.rst for details.

+config CMD_CAT
+	bool "cat"
+	default y
+	help
+	  print file to standard output
+
 config CMD_ELF
 	bool "bootelf, bootvx"
 	default y
diff --git a/cmd/Makefile b/cmd/Makefile
index 5e43a1e022..589b9680ba 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_CMD_BOOTZ) += bootz.o
 obj-$(CONFIG_CMD_BOOTI) += booti.o
 obj-$(CONFIG_CMD_BTRFS) += btrfs.o
 obj-$(CONFIG_CMD_BUTTON) += button.o
+obj-$(CONFIG_CMD_CAT) += cat.o
 obj-$(CONFIG_CMD_CACHE) += cache.o
 obj-$(CONFIG_CMD_CBFS) += cbfs.o
 obj-$(CONFIG_CMD_CLK) += clk.o
diff --git a/cmd/cat.c b/cmd/cat.c
new file mode 100644
index 0000000000..4ba3b611aa
--- /dev/null
+++ b/cmd/cat.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022
+ * Roger Knecht <rknecht@pm.de>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <malloc.h>
+
+static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc,
+		  char *const argv[])
+{
+	char *data;
+	loff_t index;
+	loff_t size;
+	int ret;
+
+	if (argc < 4)
+		return CMD_RET_USAGE;
+
+	ret = fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY);
+	if (ret)
+		return ret;
+
+	ret = fs_size(argv[3], &size);
+	if (ret)
+		return ret;
+
+	data = malloc(size);
+	if (!data)
+		return -ENOMEM;
+
+	ret = fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY);
+	if (ret)
+		return ret;
+
+	ret = fs_read(argv[3], (ulong)data, 0, 0, &size);
+	if (ret)
+		return ret;
+
+	for (index = 0; index < size; index++)
+		putc(data[index]);
+
+	free(data);
+
+	return 0;
+}
+
+U_BOOT_CMD(cat, 4, 1, do_cat,
+	   "print file to standard output",
+	   "<interface> <dev[:part]> file\n"
+	   "	- print file from 'dev' on 'interface' to standard output");
--
2.17.1



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-23 13:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-22  8:37 [PATCH] cmd: cat: add new command Roger Knecht

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.