[PATCH 3/6] commands: iomem: print human readable sizes by default
Ahmad Fatoum
a.fatoum at barebox.org
Mon Jun 16 00:16:31 PDT 2025
We already print start and end in hexadecimal, so print a size of e.g.,
905.6 KiB doesn't lose any information when copy-pasting, but makes it
easier for quick sanity checks.
The newly introduced -v flag can be used to restore the old behavior.
For I/O ports, printing a size in bytes doesn't make sense, so we
exclude it via the FLAG_IOPORT flag.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
commands/iomemport.c | 51 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 43 insertions(+), 8 deletions(-)
diff --git a/commands/iomemport.c b/commands/iomemport.c
index bbe41f571b48..2246868c2818 100644
--- a/commands/iomemport.c
+++ b/commands/iomemport.c
@@ -6,9 +6,17 @@
#include <asm/io.h>
#include <common.h>
#include <command.h>
+#include <getopt.h>
+#include <range.h>
-static void __print_resources(struct resource *res, int indent)
+#define FLAG_VERBOSE BIT(0)
+#define FLAG_IOPORT BIT(1)
+
+static void __print_resources(struct resource *res, int indent,
+ unsigned flags)
{
+ const char *size_str;
+ char buf[64];
struct resource *r;
resource_size_t size = resource_size(res);
int i;
@@ -16,24 +24,50 @@ static void __print_resources(struct resource *res, int indent)
for (i = 0; i < indent; i++)
printf(" ");
- printf("%pa - %pa (size %pa) %s%s\n",
- &res->start, &res->end, &size,
+ if (flags & (FLAG_VERBOSE | FLAG_IOPORT)) {
+ snprintf(buf, sizeof(buf), "%pa", &size);
+ size_str = buf;
+ } else {
+ size_str = size_human_readable(size);
+ }
+
+ printf("%pa - %pa (size %9s) %s%s\n",
+ &res->start, &res->end, size_str,
is_reserved_resource(res) ? "[R] " : "",
res->name);
list_for_each_entry(r, &res->children, sibling) {
- __print_resources(r, indent + 1);
+ __print_resources(r, indent + 1, flags);
}
}
-static void print_resources(struct resource *res)
+static void print_resources(struct resource *res, unsigned flags)
{
- __print_resources(res, 0);
+ __print_resources(res, 0, flags);
}
static int do_iomem(int argc, char *argv[])
{
- print_resources(&iomem_resource);
+ unsigned flags = 0;
+ int opt;
+
+ while((opt = getopt(argc, argv, "v")) > 0) {
+ switch(opt) {
+ case 'v':
+ flags |= FLAG_VERBOSE;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ argv += optind;
+ argc -= optind;
+
+ if (argc > 0)
+ return COMMAND_ERROR_USAGE;
+
+ print_resources(&iomem_resource, flags);
return 0;
}
@@ -41,13 +75,14 @@ static int do_iomem(int argc, char *argv[])
BAREBOX_CMD_START(iomem)
.cmd = do_iomem,
BAREBOX_CMD_DESC("show IO memory usage")
+ BAREBOX_CMD_OPTS("[-v]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
BAREBOX_CMD_END
#if IO_SPACE_LIMIT > 0
static int do_ioport(int argc, char *argv[])
{
- print_resources(&ioport_resource);
+ print_resources(&ioport_resource, FLAG_IOPORT);
return 0;
}
--
2.39.5
More information about the barebox
mailing list