diff mbox series

[13/26] cmd: Add a command to display the address map

Message ID 1612710687-56493-14-git-send-email-bmeng.cn@gmail.com
State Superseded
Delegated to: Priyanka Jain
Headers show
Series ppc: qemu: Convert qemu-ppce500 to driver model | expand

Commit Message

Bin Meng Feb. 7, 2021, 3:11 p.m. UTC
This adds a new command 'addrmap' to display the address map for
non-identity virtual-physical memory mappings.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---

 cmd/Kconfig   |  7 +++++++
 cmd/Makefile  |  1 +
 cmd/addrmap.c | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 cmd/addrmap.c

Comments

Simon Glass Feb. 8, 2021, 4:20 a.m. UTC | #1
On Sun, 7 Feb 2021 at 08:12, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> This adds a new command 'addrmap' to display the address map for
> non-identity virtual-physical memory mappings.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
>  cmd/Kconfig   |  7 +++++++
>  cmd/Makefile  |  1 +
>  cmd/addrmap.c | 35 +++++++++++++++++++++++++++++++++++
>  3 files changed, 43 insertions(+)
>  create mode 100644 cmd/addrmap.c

This should have a test (e.g. see mem_search.c) and doc/usage file.

Regards,
Simon
Bin Meng Feb. 8, 2021, 5:12 a.m. UTC | #2
Hi Simon,

On Mon, Feb 8, 2021 at 12:20 PM Simon Glass <sjg@chromium.org> wrote:
>
> On Sun, 7 Feb 2021 at 08:12, Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > This adds a new command 'addrmap' to display the address map for
> > non-identity virtual-physical memory mappings.
> >
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
> >
> >  cmd/Kconfig   |  7 +++++++
> >  cmd/Makefile  |  1 +
> >  cmd/addrmap.c | 35 +++++++++++++++++++++++++++++++++++
> >  3 files changed, 43 insertions(+)
> >  create mode 100644 cmd/addrmap.c
>
> This should have a test (e.g. see mem_search.c) and doc/usage file.

I am not sure how that is useful to add a test for this command,
because this command only prints some value from an array.

Regards,
Bin
Simon Glass Feb. 8, 2021, 2:13 p.m. UTC | #3
Hi Bin,

On Sun, 7 Feb 2021 at 22:12, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Simon,
>
> On Mon, Feb 8, 2021 at 12:20 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > On Sun, 7 Feb 2021 at 08:12, Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > This adds a new command 'addrmap' to display the address map for
> > > non-identity virtual-physical memory mappings.
> > >
> > > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > > ---
> > >
> > >  cmd/Kconfig   |  7 +++++++
> > >  cmd/Makefile  |  1 +
> > >  cmd/addrmap.c | 35 +++++++++++++++++++++++++++++++++++
> > >  3 files changed, 43 insertions(+)
> > >  create mode 100644 cmd/addrmap.c
> >
> > This should have a test (e.g. see mem_search.c) and doc/usage file.
>
> I am not sure how that is useful to add a test for this command,
> because this command only prints some value from an array.

Right but then it will only be a short test:

console_record_reset();
ut_assertok(run_command("...", 0));
ut_assert_nextline()
..
ut_assert_console_end();

Then if someone expands it later they will feel obligated to add to the test.

I feel that a lot of things look too trivial to test when started, but
it is often that first trivial test that determines whether we have
tests ever. That is why we have the patman check about adding tests
for new commands.

Regards,
Simon
diff mbox series

Patch

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 928a2a0..2021939 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -97,6 +97,13 @@  config CMD_ACPI
 	  between the firmware and OS, and is particularly useful when you
 	  want to make hardware changes without the OS needing to be adjusted.
 
+config CMD_ADDRMAP
+	bool "addrmap"
+	depends on ADDR_MAP
+	default y
+	help
+	  List non-identity virtual-physical memory mappings for 32-bit CPUs.
+
 config CMD_BDI
 	bool "bdinfo"
 	default y
diff --git a/cmd/Makefile b/cmd/Makefile
index 176bf92..567e2b7 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -13,6 +13,7 @@  obj-y += version.o
 
 # command
 obj-$(CONFIG_CMD_ACPI) += acpi.o
+obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
 obj-$(CONFIG_CMD_AES) += aes.o
 obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o
 obj-$(CONFIG_CMD_ADC) += adc.o
diff --git a/cmd/addrmap.c b/cmd/addrmap.c
new file mode 100644
index 0000000..bd23549
--- /dev/null
+++ b/cmd/addrmap.c
@@ -0,0 +1,35 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021, Bin Meng <bmeng.cn@gmail.com>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <addr_map.h>
+
+static int do_addrmap(struct cmd_tbl *cmdtp, int flag, int argc,
+		      char *const argv[])
+{
+	int i;
+
+	printf("           vaddr            paddr             size\n");
+	printf("================ ================ ================\n");
+
+	for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
+		if (address_map[i].size == 0)
+			continue;
+
+		printf("%16.8lx %16.8llx %16.8llx\n",
+		       address_map[i].vaddr,
+		       (unsigned long long)address_map[i].paddr,
+		       (unsigned long long)address_map[i].size);
+	}
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	addrmap,	1,	1,	do_addrmap,
+	"List non-identity virtual-physical memory mappings for 32-bit CPUs",
+	""
+);