diff mbox series

[RFC,31/31] temp: cmd: efi: add a command to dump EFI memory map

Message ID 20240607185240.1892031-32-sughosh.ganu@linaro.org
State New
Headers show
Series Make U-Boot memory reservations coherent | expand

Commit Message

Sughosh Ganu June 7, 2024, 6:52 p.m. UTC
Add a command to dump the EFI memory map.

Not for committing.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---
 cmd/Makefile                |  1 +
 cmd/efi_map_dump.c          | 28 ++++++++++++++++++++++++++++
 include/efi_loader.h        |  2 ++
 lib/efi_loader/efi_memory.c | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 63 insertions(+)
 create mode 100644 cmd/efi_map_dump.c

Comments

Heinrich Schuchardt June 8, 2024, 3:28 a.m. UTC | #1
Am 7. Juni 2024 20:52:40 MESZ schrieb Sughosh Ganu <sughosh.ganu@linaro.org>:
>Add a command to dump the EFI memory map.

What are you missing in 'efidebug memmap'?

Best regards

Heinrich

>
>Not for committing.
>
>Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
>---
> cmd/Makefile                |  1 +
> cmd/efi_map_dump.c          | 28 ++++++++++++++++++++++++++++
> include/efi_loader.h        |  2 ++
> lib/efi_loader/efi_memory.c | 32 ++++++++++++++++++++++++++++++++
> 4 files changed, 63 insertions(+)
> create mode 100644 cmd/efi_map_dump.c
>
>diff --git a/cmd/Makefile b/cmd/Makefile
>index 35fcc4af5a..315046def6 100644
>--- a/cmd/Makefile
>+++ b/cmd/Makefile
>@@ -11,6 +11,7 @@ obj-y += help.o
> obj-y += panic.o
> obj-y += version.o
> obj-y += efi_memory.o
>+obj-y += efi_map_dump.o
> 
> # command
> obj-$(CONFIG_CMD_ARMFFA) += armffa.o
>diff --git a/cmd/efi_map_dump.c b/cmd/efi_map_dump.c
>new file mode 100644
>index 0000000000..f2a5932767
>--- /dev/null
>+++ b/cmd/efi_map_dump.c
>@@ -0,0 +1,28 @@
>+// SPDX-License-Identifier: GPL-2.0+
>+/*
>+ *  Allocate and Free EFI memory
>+ *
>+ *  Copyright (c) 2024 Linaro Limited
>+ */
>+
>+#include <command.h>
>+#include <efi_loader.h>
>+
>+static int do_efi_map_dump(struct cmd_tbl *cmdtp, int flag, int argc,
>+			   char *const argv[])
>+{
>+//	printf("%s: argc => %d\n", __func__, argc);
>+
>+	if (argc != 1)
>+		return CMD_RET_USAGE;
>+
>+	dump_efi_memory_map();
>+
>+	return CMD_RET_SUCCESS;
>+}
>+
>+U_BOOT_CMD(
>+	efi_map_dump, 1, 0, do_efi_map_dump,
>+	"Dump the EFI memory map",
>+	""
>+);
>diff --git a/include/efi_loader.h b/include/efi_loader.h
>index 9600941aa3..40f894f182 100644
>--- a/include/efi_loader.h
>+++ b/include/efi_loader.h
>@@ -791,6 +791,8 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
> 				uint32_t *descriptor_version);
> /* Adds a range into the EFI memory map */
> efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type);
>+/* Dump the contents of the EFI memory map */
>+void dump_efi_memory_map(void);
> /* Adds a conventional range into the EFI memory map */
> efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end,
> 					     u64 ram_top);
>diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
>index 93244161b0..7ab1b86140 100644
>--- a/lib/efi_loader/efi_memory.c
>+++ b/lib/efi_loader/efi_memory.c
>@@ -47,6 +47,8 @@ static LIST_HEAD(efi_mem);
> void *efi_bounce_buffer;
> #endif
> 
>+static uint64_t desc_get_end(struct efi_mem_desc *desc);
>+
> /**
>  * struct efi_pool_allocation - memory block allocated from pool
>  *
>@@ -118,6 +120,36 @@ static int lmb_mem_map_update_sync(void *ctx, struct event *event)
> EVENT_SPY_FULL(EVT_LMB_MAP_UPDATE, lmb_mem_map_update_sync);
> #endif /* MEM_MAP_UPDATE_NOTIFY */
> 
>+static void dump_efi_mem_desc(struct efi_mem_desc *desc)
>+{
>+	u64 end;
>+
>+	end = desc_get_end(desc);
>+
>+	printf("-----------------------------------\n");
>+	printf("Memory Range   [0x%llx - 0x%llx]\n",
>+	       desc->physical_start, end);
>+	printf("Num Pages      [0x%llx]\n", desc->num_pages);
>+	printf("Memory Type    [0x%x]\n", desc->type);
>+	printf("Attribute      [0x%llx]\n", desc->attribute);
>+	printf("-----------------------------------\n");
>+}
>+
>+void dump_efi_memory_map(void)
>+{
>+	struct list_head *lhandle;
>+
>+	list_for_each(lhandle, &efi_mem) {
>+		struct efi_mem_list *lmem;
>+		struct efi_mem_desc *desc;
>+
>+		lmem = list_entry(lhandle, struct efi_mem_list, link);
>+		desc = &lmem->desc;
>+
>+		dump_efi_mem_desc(desc);
>+	}
>+}
>+
> /**
>  * checksum() - calculate checksum for memory allocated from pool
>  *
Sughosh Ganu June 10, 2024, 6:45 a.m. UTC | #2
On Sat, 8 Jun 2024 at 09:03, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
>
>
> Am 7. Juni 2024 20:52:40 MESZ schrieb Sughosh Ganu <sughosh.ganu@linaro.org>:
> >Add a command to dump the EFI memory map.
>
> What are you missing in 'efidebug memmap'?

Nothing. I wasn't aware of this sub-command. Thanks for pointing it out.

-sughosh

>
> Best regards
>
> Heinrich
>
> >
> >Not for committing.
> >
> >Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> >---
> > cmd/Makefile                |  1 +
> > cmd/efi_map_dump.c          | 28 ++++++++++++++++++++++++++++
> > include/efi_loader.h        |  2 ++
> > lib/efi_loader/efi_memory.c | 32 ++++++++++++++++++++++++++++++++
> > 4 files changed, 63 insertions(+)
> > create mode 100644 cmd/efi_map_dump.c
> >
> >diff --git a/cmd/Makefile b/cmd/Makefile
> >index 35fcc4af5a..315046def6 100644
> >--- a/cmd/Makefile
> >+++ b/cmd/Makefile
> >@@ -11,6 +11,7 @@ obj-y += help.o
> > obj-y += panic.o
> > obj-y += version.o
> > obj-y += efi_memory.o
> >+obj-y += efi_map_dump.o
> >
> > # command
> > obj-$(CONFIG_CMD_ARMFFA) += armffa.o
> >diff --git a/cmd/efi_map_dump.c b/cmd/efi_map_dump.c
> >new file mode 100644
> >index 0000000000..f2a5932767
> >--- /dev/null
> >+++ b/cmd/efi_map_dump.c
> >@@ -0,0 +1,28 @@
> >+// SPDX-License-Identifier: GPL-2.0+
> >+/*
> >+ *  Allocate and Free EFI memory
> >+ *
> >+ *  Copyright (c) 2024 Linaro Limited
> >+ */
> >+
> >+#include <command.h>
> >+#include <efi_loader.h>
> >+
> >+static int do_efi_map_dump(struct cmd_tbl *cmdtp, int flag, int argc,
> >+                         char *const argv[])
> >+{
> >+//    printf("%s: argc => %d\n", __func__, argc);
> >+
> >+      if (argc != 1)
> >+              return CMD_RET_USAGE;
> >+
> >+      dump_efi_memory_map();
> >+
> >+      return CMD_RET_SUCCESS;
> >+}
> >+
> >+U_BOOT_CMD(
> >+      efi_map_dump, 1, 0, do_efi_map_dump,
> >+      "Dump the EFI memory map",
> >+      ""
> >+);
> >diff --git a/include/efi_loader.h b/include/efi_loader.h
> >index 9600941aa3..40f894f182 100644
> >--- a/include/efi_loader.h
> >+++ b/include/efi_loader.h
> >@@ -791,6 +791,8 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
> >                               uint32_t *descriptor_version);
> > /* Adds a range into the EFI memory map */
> > efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type);
> >+/* Dump the contents of the EFI memory map */
> >+void dump_efi_memory_map(void);
> > /* Adds a conventional range into the EFI memory map */
> > efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end,
> >                                            u64 ram_top);
> >diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> >index 93244161b0..7ab1b86140 100644
> >--- a/lib/efi_loader/efi_memory.c
> >+++ b/lib/efi_loader/efi_memory.c
> >@@ -47,6 +47,8 @@ static LIST_HEAD(efi_mem);
> > void *efi_bounce_buffer;
> > #endif
> >
> >+static uint64_t desc_get_end(struct efi_mem_desc *desc);
> >+
> > /**
> >  * struct efi_pool_allocation - memory block allocated from pool
> >  *
> >@@ -118,6 +120,36 @@ static int lmb_mem_map_update_sync(void *ctx, struct event *event)
> > EVENT_SPY_FULL(EVT_LMB_MAP_UPDATE, lmb_mem_map_update_sync);
> > #endif /* MEM_MAP_UPDATE_NOTIFY */
> >
> >+static void dump_efi_mem_desc(struct efi_mem_desc *desc)
> >+{
> >+      u64 end;
> >+
> >+      end = desc_get_end(desc);
> >+
> >+      printf("-----------------------------------\n");
> >+      printf("Memory Range   [0x%llx - 0x%llx]\n",
> >+             desc->physical_start, end);
> >+      printf("Num Pages      [0x%llx]\n", desc->num_pages);
> >+      printf("Memory Type    [0x%x]\n", desc->type);
> >+      printf("Attribute      [0x%llx]\n", desc->attribute);
> >+      printf("-----------------------------------\n");
> >+}
> >+
> >+void dump_efi_memory_map(void)
> >+{
> >+      struct list_head *lhandle;
> >+
> >+      list_for_each(lhandle, &efi_mem) {
> >+              struct efi_mem_list *lmem;
> >+              struct efi_mem_desc *desc;
> >+
> >+              lmem = list_entry(lhandle, struct efi_mem_list, link);
> >+              desc = &lmem->desc;
> >+
> >+              dump_efi_mem_desc(desc);
> >+      }
> >+}
> >+
> > /**
> >  * checksum() - calculate checksum for memory allocated from pool
> >  *
diff mbox series

Patch

diff --git a/cmd/Makefile b/cmd/Makefile
index 35fcc4af5a..315046def6 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -11,6 +11,7 @@  obj-y += help.o
 obj-y += panic.o
 obj-y += version.o
 obj-y += efi_memory.o
+obj-y += efi_map_dump.o
 
 # command
 obj-$(CONFIG_CMD_ARMFFA) += armffa.o
diff --git a/cmd/efi_map_dump.c b/cmd/efi_map_dump.c
new file mode 100644
index 0000000000..f2a5932767
--- /dev/null
+++ b/cmd/efi_map_dump.c
@@ -0,0 +1,28 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  Allocate and Free EFI memory
+ *
+ *  Copyright (c) 2024 Linaro Limited
+ */
+
+#include <command.h>
+#include <efi_loader.h>
+
+static int do_efi_map_dump(struct cmd_tbl *cmdtp, int flag, int argc,
+			   char *const argv[])
+{
+//	printf("%s: argc => %d\n", __func__, argc);
+
+	if (argc != 1)
+		return CMD_RET_USAGE;
+
+	dump_efi_memory_map();
+
+	return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(
+	efi_map_dump, 1, 0, do_efi_map_dump,
+	"Dump the EFI memory map",
+	""
+);
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 9600941aa3..40f894f182 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -791,6 +791,8 @@  efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
 				uint32_t *descriptor_version);
 /* Adds a range into the EFI memory map */
 efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type);
+/* Dump the contents of the EFI memory map */
+void dump_efi_memory_map(void);
 /* Adds a conventional range into the EFI memory map */
 efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end,
 					     u64 ram_top);
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index 93244161b0..7ab1b86140 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -47,6 +47,8 @@  static LIST_HEAD(efi_mem);
 void *efi_bounce_buffer;
 #endif
 
+static uint64_t desc_get_end(struct efi_mem_desc *desc);
+
 /**
  * struct efi_pool_allocation - memory block allocated from pool
  *
@@ -118,6 +120,36 @@  static int lmb_mem_map_update_sync(void *ctx, struct event *event)
 EVENT_SPY_FULL(EVT_LMB_MAP_UPDATE, lmb_mem_map_update_sync);
 #endif /* MEM_MAP_UPDATE_NOTIFY */
 
+static void dump_efi_mem_desc(struct efi_mem_desc *desc)
+{
+	u64 end;
+
+	end = desc_get_end(desc);
+
+	printf("-----------------------------------\n");
+	printf("Memory Range   [0x%llx - 0x%llx]\n",
+	       desc->physical_start, end);
+	printf("Num Pages      [0x%llx]\n", desc->num_pages);
+	printf("Memory Type    [0x%x]\n", desc->type);
+	printf("Attribute      [0x%llx]\n", desc->attribute);
+	printf("-----------------------------------\n");
+}
+
+void dump_efi_memory_map(void)
+{
+	struct list_head *lhandle;
+
+	list_for_each(lhandle, &efi_mem) {
+		struct efi_mem_list *lmem;
+		struct efi_mem_desc *desc;
+
+		lmem = list_entry(lhandle, struct efi_mem_list, link);
+		desc = &lmem->desc;
+
+		dump_efi_mem_desc(desc);
+	}
+}
+
 /**
  * checksum() - calculate checksum for memory allocated from pool
  *