From patchwork Tue Dec 18 05:05:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 154064 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3282368ljp; Mon, 17 Dec 2018 21:07:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xuddd1eSQI9rP/Bm2LE++gjSKxUaBOzP4FtJkC0iX0phksog8ZHPyjz+8UOrldZOUgbVc0 X-Received: by 2002:a17:906:b893:: with SMTP id hb19-v6mr11893224ejb.76.1545109678654; Mon, 17 Dec 2018 21:07:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545109678; cv=none; d=google.com; s=arc-20160816; b=UW5WBDkvgdkbXJi91E9Op9KXWiEVjZHTmtsYYuF6IVzZgaJF4eT2BUBpRHv+UggGet rATCS7kHSFDQf/I2Anz+zfaWcPDvt7Y2VcKFC6saqeH0f26gfoSqLUIFzj8S1uDDtBtG Qvo11VpN8uVhVHMeyQdYBxk3jn+lDrbzFYihxo8Vp4mID/6fATQre2Y0tzftQ0NAqLYR DF5A0CQ17579UzRnEMevsSVsQQa6bX5WMlPeH3sdPY7XfFirjyyT9uxF5my690eEuCZ8 WyoPPx0buIKxDC7jmyXyJa7w8A/G+ihRkMRTJHjr7Y9ToqDkggvSyl4oxyU56fHMGnfm 0zIQ== 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=vKmBBeF+ZC2UbpFd82dD4N2EDJD/wwQ5iT24abrxFzY=; b=0eYW/k/sfdmrDeG4sio9RuU1a0O8eUM2Im52jWLbyGZtHjyyhFMQRI7Q0vPlGE9h3s f5icuw/V26YaWiK0yEsbSzYqWzEJha+BlpGOKCKbUSi957Kai1YO+oGnmAizrYWAgE1x edd5nkCBIYGFUHCTYwlWdTtPtz2fKqJMdNVld3IJFwDYODduR1h2siL/9QjblVAHmX6L wsuOjWJE2BZqJiXSSv9sW+3+G2wprI1PTm4SNJYzpy7p8s709yb4FfY2GBt4fks24J+k qTKBgilTiGBaGC6zydsTCi2mo0CIo9ApnHjywLRHwEyekGkuBmIuwDTtv/USLHDZ7qn8 vmcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EGIvluNR; 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 x3si3342129edl.3.2018.12.17.21.07.58; Mon, 17 Dec 2018 21:07:58 -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=EGIvluNR; 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 43ABFC22033; Tue, 18 Dec 2018 05:06:20 +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_DNSWL_BLOCKED, 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 AD9E7C21ECC; Tue, 18 Dec 2018 05:06:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C7D27C2204E; Tue, 18 Dec 2018 05:02:04 +0000 (UTC) Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) by lists.denx.de (Postfix) with ESMTPS id 0EE1AC2207B for ; Tue, 18 Dec 2018 05:02:02 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id i73so5010505ywg.3 for ; Mon, 17 Dec 2018 21:02:02 -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=LeCkR3oLGf/AwLBp5EBcOfS8G5GJjrg876kNmDJQbts=; b=EGIvluNRKCUZTluj0T7wZUwmRuVnNJ+MCz98W7e7IIicsQhUFDvdUoh29LMkEVPhpP 0ai5E9WXTaVEEGOmfRhXw14vwZVTcWyO7G3vC3v39arosJZL2yxjipNtYlpc/ajdBHxY 3MolJrsGOM42lczVd83pUwqdN1ZdhlhGo0yrU= 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=LeCkR3oLGf/AwLBp5EBcOfS8G5GJjrg876kNmDJQbts=; b=ZJggkRQhLdMVOtlplyV0I+bE0vLeMRCF0pLTDQHuf4OqTQ2gmsRtbwJiGbWJdDkAQI JjYjH7U69x67MJes60Jt0ajWl2tZAmNjeStokkDmU15oewWgbWuh69dLJKxU8qOZK3Kf c6vpscXKJRTWnGeA3XTqMFDaLmmTr5kRGAF+EGnkmALbCDwRdMaD589T7RrLVyz/x/Tn OMWOjEgKLIZ3+0QKkU18Z66zOrYM52XwyjVe2ycXtOs/xCu4FSuvWO4IAMblahDqWCQ0 BNhpi0H3qOnwJaD1h9fGYk4fcUGr55HVwtpWEij3NRCfPTw9ktE37qZ2fGTN1gMXQ7dQ BWwQ== X-Gm-Message-State: AA+aEWYYwStaTv1pt2tBmzLDcOonMv3KVqMMa/6hHZOzTlBHCMt6W0ne hZ4gAgRWBaiujq67uU4TLvn6mw== X-Received: by 2002:a81:20d4:: with SMTP id g203mr16697131ywg.142.1545109320989; Mon, 17 Dec 2018 21:02:00 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 137sm5475481ywv.108.2018.12.17.21.02.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 21:02:00 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 18 Dec 2018 14:05:07 +0900 Message-Id: <20181218050510.20308-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181218050510.20308-1-takahiro.akashi@linaro.org> References: <20181218050510.20308-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 5/8] 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 010870df63c8..5a81a627d616 100644 --- a/cmd/efishell.c +++ b/cmd/efishell.c @@ -439,6 +439,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) { + free(map); + 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'); + } + + free(map); + + 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(