From patchwork Mon Nov 5 09:06:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 150166 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2360601ljp; Mon, 5 Nov 2018 01:13:54 -0800 (PST) X-Google-Smtp-Source: AJdET5eqNBa613/t3fU9DoO1IVyb70LDRDb9pIaeAg5wW6H45NLk6tIA9Z/UMToskV5jX4XmXgRR X-Received: by 2002:a50:86ac:: with SMTP id r41-v6mr16874431eda.186.1541409234552; Mon, 05 Nov 2018 01:13:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541409234; cv=none; d=google.com; s=arc-20160816; b=mKrtJkrtu3UpJ3SmCws193m3wpFh9BEpXeNSzM/GNfb1u/C5W7LdXvPNl6d6/uVuJP iFevgsi/aU3Y+gna9//wEViDM/tsRB7EsGLe1iQbdAnoCp6jPSgZ3UozfZSR0ZtaEy8t /ArHPyInXeuD6v9eOdsA++Y2Xt9k7Blp+d6PdAAieT+/yVKDKZ84Rv8y0TN9DrxRjf1x BvQII6QNYlFdBCb7lkNa9V7EuIucl6PopbHrqTyfvT78gpxtFmZoRx66mSG2nr3iQdbK Fd+JhWfaLDXFGyXAoDwrdbgAwIis9G+Q/uLiiVU2kCvYRiqZwSEtF0PQ3Qb53BK63NJm yFhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=/CrzKHOcBn8tDaDrDBbfwxDRd4U6UDFO5tOsX2IRy9Q=; b=swUNDT32xPpJp9bWTJZuPLSmLseMTfnE1YsPgIcszN2a4u/t39ZIAVgSMnhbiIEp0a 7XRR3R7OPTGhmFVt5VgqjgbgnaWliGMbgmcQy4RyU9TYIduNWbPBpqhEpb4zyBnBhPFn PNc8QCI3GH79gJGACByXDc0T4/dDfrr8iEqN7AQAXBCovcG5jkyH5guNrGRn+4vYlr92 XgSwIIOHV31qxuy5D3vlgDeI07P4D8TZDj9xxWa1k1FgwLznm42OIIHmNei3D1g2VQZy 0TlUd997AKDGE3r61jzodTfHHmeNU4sN9r/kIUH/IaSNPsICSL4v1vKinzUxibY8GpkD o64Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=iYRMDKWj; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id z6-v6si3333915ejq.306.2018.11.05.01.13.54; Mon, 05 Nov 2018 01:13:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=iYRMDKWj; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 2212DC22453; Mon, 5 Nov 2018 09:08:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 13FB7C223F3; Mon, 5 Nov 2018 09:07:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 140D9C221BC; Mon, 5 Nov 2018 09:05:12 +0000 (UTC) Received: from mail-yb1-f193.google.com (mail-yb1-f193.google.com [209.85.219.193]) by lists.denx.de (Postfix) with ESMTPS id 3A24AC2220A for ; Mon, 5 Nov 2018 09:05:07 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id n140-v6so3491194yba.1 for ; Mon, 05 Nov 2018 01:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n2k42hzwwI9MhTb001xSXwgVmsgfAMsxe9xQraLK480=; b=iYRMDKWjhxhI9ubgr0aA0BE0Vbf5qAToAcdq0vSItYBNW+xv3A5zCQCBHmveIrqW7X qfe2MAlEIa8lc/23LusvBhWEanMNv6AAxJ5uuHZxHXE7FBtSMHjfmAw69XvZnUZcS32G 7WB4S9yBEp17ce8Z1hE6mUeqyYzXtUJICsvDI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n2k42hzwwI9MhTb001xSXwgVmsgfAMsxe9xQraLK480=; b=I8tuIjxJF1CqjDcDdnFcRtxvzH0bqDPJ/SbPHOXfIELf9pGoHqHNuTFfwi+nhKIY5I 5br6AvL9+daHDjMXkkDiLMsTRJyDesnU6Eq19+tQDjN10YnqS+8hgDYWY5tl173yfrgH l/C89enk9kSnYuMi1CS6bzOTuHPgUbrFkDQ6TXI84qjEJp71WjKZ2n26JQiwf4D54bze +40XmeIoLBVzzC0SamHkLKj270hVpjXqjI/rF4uNKF3vwj8irP6/KoKWjartwuKuD+KV skU/EM8XTX17rbfkPIttb1TSauZgvMPN+HGK3jIEvLMT8/Lc/Ryll5qvq3WUHR6viD2f ZTQw== X-Gm-Message-State: AGRZ1gIS+VMreWX0DIcaPn8YXkHrBnbqHVGFGCzVGnrCAwL8iJV0w/bl mLTmgKriG5LpTF9gObb/4/B9y10ITlg= X-Received: by 2002:a25:c887:: with SMTP id y129-v6mr20297233ybf.260.1541408706053; Mon, 05 Nov 2018 01:05:06 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r13-v6sm9661824ywc.52.2018.11.05.01.05.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 01:05:05 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Mon, 5 Nov 2018 18:06:47 +0900 Message-Id: <20181105090653.7409-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181105090653.7409-1-takahiro.akashi@linaro.org> References: <20181105090653.7409-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 08/14] cmd: efishell: add memmap command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" "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 --- cmd/efishell.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/cmd/efishell.c b/cmd/efishell.c index b5050d63fa22..3e1118a407ff 100644 --- a/cmd/efishell.c +++ b/cmd/efishell.c @@ -442,6 +442,78 @@ static int do_efi_show_images(int argc, char * const argv[]) 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", +}; + +#define EFI_MEM_ATTR(attribute, bit, string) \ + if ((attribute) & (bit)) { \ + if (sep) \ + putc('|'); \ + sep = 1; \ + printf(string); \ + } + +static int do_efi_show_memmap(int argc, char * const argv[]) +{ + struct efi_mem_desc *map = NULL; + efi_uintn_t map_size = 0; + int i, sep; + efi_status_t ret; + + ret = efi_get_memory_map(&map_size, map, NULL, NULL, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + map = malloc(map_size); + if (!map) + return CMD_RET_FAILURE; + ret = efi_get_memory_map(&map_size, map, NULL, NULL, NULL); + } + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + ret = efi_get_memory_map(&map_size, map, NULL, NULL, NULL); + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + printf("Type Start End Attributes\n"); + printf("================ ================ ================ ==========\n"); + for (i = 0; i < map_size / sizeof(*map); map++, i++) { + sep = 0; + printf("%-16s %016llx-%016llx ", + efi_mem_type_string[map->type], + map->physical_start, + map->physical_start + map->num_pages * EFI_PAGE_SIZE); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_UC, "UC"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WC, "WC"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WT, "WT"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WB, "WB"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_UCE, "UCE"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_WP, "WP"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_RP, "RP"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_XP, "WP"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_NV, "NV"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_MORE_RELIABLE, "REL"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_RO, "RO"); + EFI_MEM_ATTR(map->attribute, EFI_MEMORY_RUNTIME, "RT"); + putc('\n'); + } + + return CMD_RET_SUCCESS; +} + static int do_efi_boot_add(int argc, char * const argv[]) { int id; @@ -826,6 +898,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag, return do_efi_show_drivers(argc, argv); else if (!strcmp(command, "images")) return do_efi_show_images(argc, argv); + else if (!strcmp(command, "memmap")) + return do_efi_show_memmap(argc, argv); else return CMD_RET_USAGE; } @@ -853,7 +927,9 @@ static char efishell_help_text[] = "efishell drivers\n" " - show uefi drivers\n" "efishell images\n" - " - show loaded images\n"; + " - show loaded images\n" + "efishell memmap\n" + " - show uefi memory map\n"; #endif U_BOOT_CMD(