From patchwork Tue Jan 15 02:55:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 155606 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4386562jaa; Mon, 14 Jan 2019 18:59:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN4C1wJMHxaMKxBT42R6eXrHCaC9g0f4ILbs2hNiThVOIVr7JUnZKDYYjkAKK3PHQaGbqo38 X-Received: by 2002:a17:906:41cc:: with SMTP id g12-v6mr1416769ejl.219.1547521191126; Mon, 14 Jan 2019 18:59:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547521191; cv=none; d=google.com; s=arc-20160816; b=DzW+ktFN6y+yImDcztlSLdviE6CZKELPLogSfRVAZhUiramBNwYuiZBMVWXOUUyxK6 paefp8nzsQOo6pfiK2ydyfcGBCkmqIYDcEEAPil5RI1PWry2kUJK9VjZx5pk8dquO+OD tk6DT1hXS2r5q/ivob8TvinTYo8PkB8HzBCxveQgrWx8hUzBGmdb6zQK9ov3PfA9GECS xikfn5zj/lkgCZ+8lukhSNUarwluU6JJ2nCDpCYCTEF76MdRpnaFYz1xf1MCjbDlneBt 3uZK19o9ZCXgqyQYe8n+pflaV/ZedStbUREPALi0aDXk7ubuhkcqvfqGKvlLXY+1td7Z cUxw== 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=icUDDg8AnwHa7LIEHQtje2rrcLPu5sjCt4K20pYFKFk=; b=SHNWn5vmpi9azKJqEHd7i0Kz3dLhCia1XpIUGGIh0WFEGI5bg3kmpcwpTwlt8cfmso 7B/ashELlCI8JNrFfvM4RaXsci9NuPGSil4aGj1oD33ofMz3msLXimAlwCQFID1QeMnf mSBCCKSDzTayHaa2+jPhwpXjkRFNMcWVT2YShCjH7fCz/yBDu1yN6Fdxl7FyY+1Bek4O v3qLnUa1wj8qllTTQ/+L5GFt15jJxW6dBc5wIRHjC6y8Tb9s05n7noKLI6H6SgTfoWPz 7C8b87+qKJQATJruSHuHDnYyRjHopCI/7pJLZj9xLSUpwOyIr9bl8jmdgWMOt+aa8JNq Sl1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=F0TbIxeg; 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 2-v6si375663ejt.89.2019.01.14.18.59.50; Mon, 14 Jan 2019 18:59:51 -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=F0TbIxeg; 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 B6DFAC21FBD; Tue, 15 Jan 2019 02:58:42 +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, 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 05FF5C21FBD; Tue, 15 Jan 2019 02:58:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 29305C21D65; Tue, 15 Jan 2019 02:55:57 +0000 (UTC) Received: from mail-yb1-f194.google.com (mail-yb1-f194.google.com [209.85.219.194]) by lists.denx.de (Postfix) with ESMTPS id 88EB6C21FCA for ; Tue, 15 Jan 2019 02:55:52 +0000 (UTC) Received: by mail-yb1-f194.google.com with SMTP id j10so490107ybj.8 for ; Mon, 14 Jan 2019 18:55:52 -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=LfBfOQAIjg4/pTzC5ZjyGGfvTq21VwlLiBXJCVG3TfM=; b=F0TbIxegbqpgN2SMRUVIrjbDEVQM2oPQ5KdnodJkwcA8os703PoUtPB3+MP3i0CxkE giHxVizHYLhtRhMwYAFqSOtvxAmqZtgzGZJmB0NIf9BVrB8QW+NnTHq45K9m6pmTH+ZP 5CaR3Tyb8V/DWIrChu+sFNBdPGYmlCAGwvNkA= 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=LfBfOQAIjg4/pTzC5ZjyGGfvTq21VwlLiBXJCVG3TfM=; b=mrzIxIGzdOv1KY56mYlfKlcWf10DPn+cMv9mzTc8DvQQzrT8JDNYtvyzf6QdqHZ5gz DdXKa1+9wMaMJzp8TeOlF2mgNNNQjBG3CMiZDOSkDPNlK25MS8WwUKHLn1r/isSJ7nnh Cksia8ofl2zSEjon/CxaZQTPyaTSyviA2O3hzA6q6N8rsBM6gkNlVdAPfl5I+pDvFRmu /c60jaj2H+3ccGen9g9RyDZyb5kE9ZgWc232kNOs0LALrPC8z06dFvKaRmq23e8T/JeK r0p1k3ww19nPX22vmTOe5WabC1wC8BoU5g4N+1FBKwHu+EPAfzRU1yUEko+53HJokeCq l1NA== X-Gm-Message-State: AJcUukcGpWLi1bghbur6fCkmXMwG1MGtXRnas7EXsQk83qo2RzHplYyM xjdIPmPZvl+/sHQttZzcztPnAg== X-Received: by 2002:a25:2389:: with SMTP id j131mr1314756ybj.20.1547520951453; Mon, 14 Jan 2019 18:55:51 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id i13sm805473ywe.53.2019.01.14.18.55.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 18:55:50 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 15 Jan 2019 11:55:20 +0900 Message-Id: <20190115025522.12060-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190115025522.12060-1-takahiro.akashi@linaro.org> References: <20190115025522.12060-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v4 7/9] cmd: efitool: 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/efitool.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/cmd/efitool.c b/cmd/efitool.c index e77273fc6e1e..f06718ea580d 100644 --- a/cmd/efitool.c +++ b/cmd/efitool.c @@ -540,6 +540,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 *memmap = NULL, *map; + efi_uintn_t map_size = 0; + int i, sep; + efi_status_t ret; + + ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + memmap = malloc(map_size); + if (!memmap) + return CMD_RET_FAILURE; + ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); + } + if (ret != EFI_SUCCESS) { + free(memmap); + return CMD_RET_FAILURE; + } + + printf("Type Start End Attributes\n"); + printf("================ ================ ================ ==========\n"); + for (i = 0, map = memmap; 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(memmap); + + return CMD_RET_SUCCESS; +} + static int do_efi_boot_add(int argc, char * const argv[]) { int id; @@ -955,6 +1027,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag, return do_efi_show_handles(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; } @@ -987,7 +1061,9 @@ static char efitool_help_text[] = "efitool dh\n" " - show uefi handles\n" "efitool images\n" - " - show loaded images\n"; + " - show loaded images\n" + "efitool memmap\n" + " - show uefi memory map\n"; #endif U_BOOT_CMD(