From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH v2 01/13] common: introduce structured I/O
Date: Wed, 13 Aug 2025 16:33:33 +0200 [thread overview]
Message-ID: <20250813143345.3758653-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250813143345.3758653-1-a.fatoum@barebox.org>
Structured I/O is an alternative method for shell commands input and
output. Instead of consuming and producing lines of unstructured
strings, commands receive objects with dedicated attributes.
In the future, once enough commands support this, we could make it
available in the shell as the pipe operator.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
v1 -> v2:
- replace wrong select PARAM with select PARAMETER
---
common/Kconfig | 4 ++++
common/Makefile | 1 +
common/structio.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
include/structio.h | 44 ++++++++++++++++++++++++++++++++++++
4 files changed, 105 insertions(+)
create mode 100644 common/structio.c
create mode 100644 include/structio.h
diff --git a/common/Kconfig b/common/Kconfig
index 67aff85efc9b..b32a7cb2960b 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -55,6 +55,10 @@ config BLOCK_STATS
config FILETYPE
bool
+config STRUCTIO
+ bool
+ select PARAMETER
+
config BINFMT
bool
select FILETYPE
diff --git a/common/Makefile b/common/Makefile
index b50b92122293..7a91ef21f79b 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -2,6 +2,7 @@
obj-y += boards/
obj-y += memory.o
+obj-$(CONFIG_STRUCTIO) += structio.o
obj-y += memory_display.o
pbl-$(CONFIG_PBL_CONSOLE) += memory_display.o
obj-y += clock.o
diff --git a/common/structio.c b/common/structio.c
new file mode 100644
index 000000000000..935c4628dd77
--- /dev/null
+++ b/common/structio.c
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <structio.h>
+#include <command.h>
+#include <device.h>
+
+static struct bobject *active_capture;
+
+struct bobject *structio_active(void)
+{
+ return active_capture;
+}
+
+int structio_run_command(struct bobject **bret, const char *cmd)
+{
+ struct bobject *bobj;
+ int ret;
+
+ if (!bret)
+ return run_command(cmd);
+
+ active_capture = bobj = bobject_alloc("capture");
+ bobj->local = true;
+
+ ret = run_command(cmd);
+
+ active_capture = NULL;
+
+ if (ret) {
+ bobject_free(bobj);
+ return ret;
+ }
+
+ *bret = bobj;
+ return 0;
+}
+
+int structio_devinfo(struct bobject **bret, struct device *dev)
+{
+ struct bobject *bobj;
+
+ if (!bret) {
+ devinfo(dev);
+ return 0;
+ }
+
+ active_capture = bobj = bobject_alloc("devinfo");
+ bobj->local = true;
+
+ devinfo(dev);
+
+ active_capture = NULL;
+
+ *bret = bobj;
+ return 0;
+}
diff --git a/include/structio.h b/include/structio.h
new file mode 100644
index 000000000000..1c97b4c29b79
--- /dev/null
+++ b/include/structio.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __STRUCTIO_H_
+#define __STRUCTIO_H_
+
+#include <bobject.h>
+
+#ifdef CONFIG_STRUCTIO
+struct bobject *structio_active(void);
+int structio_run_command(struct bobject **, const char *cmd);
+int structio_devinfo(struct bobject **, struct device *dev);
+#else
+#define structio_active() NULL
+static inline int structio_run_command(struct bobject **bobj, const char *cmd)
+{
+ return -ENOSYS;
+}
+
+static inline int structio_devinfo(struct bobject **bobj, struct device *dev)
+{
+ return -ENOSYS;
+}
+#endif
+
+#define stprintf(name, fmt, ...) do { \
+ struct bobject *__bobj = structio_active(); \
+ if (__bobj) \
+ bobject_add_param_fixed(__bobj, name, fmt, ##__VA_ARGS__); \
+ else \
+ printf(name ": " fmt "\n", ##__VA_ARGS__); \
+} while (0)
+
+#define stprintf_prefix(name, prefix, fmt, ...) do { \
+ struct bobject *__bobj = structio_active(); \
+ if (__bobj) \
+ bobject_add_param_fixed(__bobj, name, fmt, ##__VA_ARGS__); \
+ else \
+ printf(prefix fmt "\n", ##__VA_ARGS__); \
+} while (0)
+
+#define stprintf_single(name, fmt...) stprintf_prefix(name, "", fmt)
+
+#define stnoprintf(args...) ({ structio_active() ? 0 : (printf(args), 1); })
+
+#endif
--
2.39.5
next prev parent reply other threads:[~2025-08-13 14:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 14:33 [PATCH v2 00/13] commands: add bfetch/buds of command redirection Ahmad Fatoum
2025-08-13 14:33 ` Ahmad Fatoum [this message]
2025-08-13 14:33 ` [PATCH v2 02/13] ARM: cpuinfo: support structio output Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 03/13] commands: uptime: enable structured I/O Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 04/13] string: implement strv_length helper Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 05/13] ARM: psci: client: add PSCI version/method parameters Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 06/13] net: move netmask_to_prefix into header Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 07/13] optee: add revision info to tee devinfo output Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 08/13] tee: enable structured I/O in devinfo handler Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 09/13] security: blobgen: add easy way to check for existent providers Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 10/13] clk: implement clk_have_nonfixed_providers Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 11/13] commands: introduce bfetch command Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 12/13] configs: enable bfetch in some popular defconfigs Ahmad Fatoum
2025-08-13 14:33 ` [PATCH v2 13/13] hush: structio: silence missing command error message Ahmad Fatoum
2025-08-14 10:53 ` [PATCH v2 00/13] commands: add bfetch/buds of command redirection Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250813143345.3758653-2-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox