From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 3/6] commands: iomem: print human readable sizes by default
Date: Mon, 16 Jun 2025 09:16:31 +0200 [thread overview]
Message-ID: <20250616071634.811000-3-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250616071634.811000-1-a.fatoum@barebox.org>
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@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
next prev parent reply other threads:[~2025-06-16 7:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 7:16 [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 2/6] lib: display_options: constify pointer to static size_human_readable buf Ahmad Fatoum
2025-06-16 7:16 ` Ahmad Fatoum [this message]
2025-06-16 7:16 ` [PATCH 4/6] commands: iomemport: support showing info for particular argument Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 5/6] commands: iomem: add support for printing type/attributes Ahmad Fatoum
2025-06-16 7:16 ` [PATCH 6/6] efi: payload: iomem: populate resource type/attributes Ahmad Fatoum
2025-06-17 7:13 ` [PATCH 1/6] resource: mark normal memory as supporting being uncacheable 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=20250616071634.811000-3-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