[U-Boot] [PATCH 1/2] cmd: efidebug: add memmap command

Meenakshi Aggarwal meenakshi.aggarwal at nxp.com
Wed Feb 27 03:29:43 UTC 2019


Please ignore, it is sent by mistake.


> -----Original Message-----
> From: U-Boot <u-boot-bounces at lists.denx.de> On Behalf Of Meenakshi
> Aggarwal
> Sent: Wednesday, February 27, 2019 2:41 PM
> To: u-boot at lists.denx.de; Prabhakar Kushwaha
> <prabhakar.kushwaha at nxp.com>
> Subject: [U-Boot] [PATCH 1/2] cmd: efidebug: add memmap command
> 
> From: AKASHI Takahiro <takahiro.akashi at linaro.org>
> 
> "memmap" command prints uefi-specific memory map information.
> => efi memmap
> Type             Start            End              Attributes
> ================ ================ ================ ==========
> CONVENTIONAL     0000000040000000-000000007de27000 WB
> RUNTIME DATA     000000007de27000-000000007de28000 WB|RT
> RESERVED         000000007de28000-000000007de2a000 WB
> RUNTIME DATA     000000007de2a000-000000007de2b000 WB|RT
> RESERVED         000000007de2b000-000000007de2c000 WB
> RUNTIME DATA     000000007de2c000-000000007de2d000 WB|RT
> LOADER DATA      000000007de2d000-000000007ff37000 WB
> RUNTIME CODE     000000007ff37000-000000007ff38000 WB|RT
> LOADER DATA      000000007ff38000-0000000080000000 WB
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
> Reviewed-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> ---
>  cmd/efidebug.c | 127
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 126 insertions(+), 1 deletion(-)
> 
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c index e3a2d09..5072a7b 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -335,6 +335,127 @@ static int do_efi_show_images(cmd_tbl_t *cmdtp, int
> flag,
>  	return CMD_RET_SUCCESS;
>  }
> 
> +static const char * const efi_mem_type_string[] = {
> +	[EFI_RESERVED_MEMORY_TYPE] = "RESERVED",
> +	[EFI_LOADER_CODE] = "LOADER CODE",
> +	[EFI_LOADER_DATA] = "LOADER DATA",
> +	[EFI_BOOT_SERVICES_CODE] = "BOOT CODE",
> +	[EFI_BOOT_SERVICES_DATA] = "BOOT DATA",
> +	[EFI_RUNTIME_SERVICES_CODE] = "RUNTIME CODE",
> +	[EFI_RUNTIME_SERVICES_DATA] = "RUNTIME DATA",
> +	[EFI_CONVENTIONAL_MEMORY] = "CONVENTIONAL",
> +	[EFI_UNUSABLE_MEMORY] = "UNUSABLE MEM",
> +	[EFI_ACPI_RECLAIM_MEMORY] = "ACPI RECLAIM MEM",
> +	[EFI_ACPI_MEMORY_NVS] = "ACPI NVS",
> +	[EFI_MMAP_IO] = "IO",
> +	[EFI_MMAP_IO_PORT] = "IO PORT",
> +	[EFI_PAL_CODE] = "PAL",
> +};
> +
> +static const struct efi_mem_attrs {
> +	const u64 bit;
> +	const char *text;
> +} efi_mem_attrs[] = {
> +	{EFI_MEMORY_UC, "UC"},
> +	{EFI_MEMORY_UC, "UC"},
> +	{EFI_MEMORY_WC, "WC"},
> +	{EFI_MEMORY_WT, "WT"},
> +	{EFI_MEMORY_WB, "WB"},
> +	{EFI_MEMORY_UCE, "UCE"},
> +	{EFI_MEMORY_WP, "WP"},
> +	{EFI_MEMORY_RP, "RP"},
> +	{EFI_MEMORY_XP, "WP"},
> +	{EFI_MEMORY_NV, "NV"},
> +	{EFI_MEMORY_MORE_RELIABLE, "REL"},
> +	{EFI_MEMORY_RO, "RO"},
> +	{EFI_MEMORY_RUNTIME, "RT"},
> +};
> +
> +/**
> + * print_memory_attributes() - print memory map attributes
> + * @attributes:	Attribute value
> + *
> + * Print memory map attributes
> + */
> +static void print_memory_attributes(u64 attributes) {
> +	int sep, i;
> +
> +	for (sep = 0, i = 0; i < ARRAY_SIZE(efi_mem_attrs); i++)
> +		if (attributes & efi_mem_attrs[i].bit) {
> +			if (sep) {
> +				putc('|');
> +			} else {
> +				putc(' ');
> +				sep = 1;
> +			}
> +			puts(efi_mem_attrs[i].text);
> +		}
> +}
> +
> +#define EFI_PHYS_ADDR_WIDTH (int)(sizeof(efi_physical_addr_t) * 2)
> +
> +/**
> + * do_efi_show_memmap() - show UEFI memory map
> + *
> + * @cmdtp:	Command table
> + * @flag:	Command flag
> + * @argc:	Number of arguments
> + * @argv:	Argument array
> + * Return:	CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on
> failure
> + *
> + * Implement efidebug "memmap" sub-command.
> + * Show UEFI memory map.
> + */
> +static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag,
> +			      int argc, char * const argv[]) {
> +	struct efi_mem_desc *memmap = NULL, *map;
> +	efi_uintn_t map_size = 0;
> +	const char *type;
> +	int i;
> +	efi_status_t ret;
> +
> +	ret = EFI_CALL(BS->get_memory_map(&map_size, memmap, NULL,
> NULL, NULL));
> +	if (ret == EFI_BUFFER_TOO_SMALL) {
> +		map_size += sizeof(struct efi_mem_desc); /* for my own */
> +		ret = EFI_CALL(BS->allocate_pool(EFI_LOADER_DATA,
> +						 map_size, (void
> *)&memmap));
> +		if (ret != EFI_SUCCESS)
> +			return CMD_RET_FAILURE;
> +		ret = EFI_CALL(BS->get_memory_map(&map_size, memmap,
> +						  NULL, NULL, NULL));
> +	}
> +	if (ret != EFI_SUCCESS) {
> +		EFI_CALL(BS->free_pool(memmap));
> +		return CMD_RET_FAILURE;
> +	}
> +
> +	printf("Type             Start%.*s End%.*s Attributes\n",
> +	       EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc);
> +	printf("================ %.*s %.*s ==========\n",
> +	       EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
> +	for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
> +		if (map->type < EFI_MAX_MEMORY_TYPE)
> +			type = efi_mem_type_string[map->type];
> +		else
> +			type = "(unknown)";
> +
> +		printf("%-16s %.*llx-%.*llx", type,
> +		       EFI_PHYS_ADDR_WIDTH,
> +		       map->physical_start,
> +		       EFI_PHYS_ADDR_WIDTH,
> +		       map->physical_start + map->num_pages * EFI_PAGE_SIZE);
> +
> +		print_memory_attributes(map->attribute);
> +		putc('\n');
> +	}
> +
> +	EFI_CALL(BS->free_pool(memmap));
> +
> +	return CMD_RET_SUCCESS;
> +}
> +
>  /**
>   * do_efi_boot_add() - set UEFI load option
>   *
> @@ -845,6 +966,8 @@ static cmd_tbl_t cmd_efidebug_sub[] = {
>  			 "", ""),
>  	U_BOOT_CMD_MKENT(images, CONFIG_SYS_MAXARGS, 1,
> do_efi_show_images,
>  			 "", ""),
> +	U_BOOT_CMD_MKENT(memmap, CONFIG_SYS_MAXARGS, 1,
> do_efi_show_memmap,
> +			 "", ""),
>  };
> 
>  /**
> @@ -911,7 +1034,9 @@ static char efidebug_help_text[] =
>  	"efidebug dh\n"
>  	"  - show uefi handles\n"
>  	"efidebug images\n"
> -	"  - show loaded images\n";
> +	"  - show loaded images\n"
> +	"efidebug memmap\n"
> +	"  - show uefi memory map\n";
>  #endif
> 
>  U_BOOT_CMD(
> --
> 1.9.1
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.de
> nx.de%2Flistinfo%2Fu-
> boot&data=02%7C01%7Cmeenakshi.aggarwal%40nxp.com%7Cf6d2c8270
> 9004cdb237708d69c634a7f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C
> 0%7C636868347604262106&sdata=5uxeibcyDGCCEu1yYYp3gXqz8huNvnoc
> GqFVj5lumd8%3D&reserved=0


More information about the U-Boot mailing list