From patchwork Mon Jan 21 07:49:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 156167 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6088051jaa; Sun, 20 Jan 2019 23:51:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN5eD5YiQQcD3QTuP3YtnMvmkW8y1i8thB7xNRnJd16PKsgup4jKM9L0Bw3CVpyvvlk5boCl X-Received: by 2002:a50:8ad9:: with SMTP id k25mr15872411edk.189.1548057108945; Sun, 20 Jan 2019 23:51:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548057108; cv=none; d=google.com; s=arc-20160816; b=DdHzC4KICdj9VfYuSh8e1XajpsNUl+3Z+gGz3Tunyks2NiiFvZwl2q6qMnDhbOrOEB OqsOmC6fTRuSyHP4uwc0R5Yg8nbZuC6h6xfB2ospjxw2PNVs/I5Xg+t/rT33tiHjdqWq jdQZykQwek+wc5yurm/HADhqLzECVQauhvB5q9PujOmzMALCSfW+khfsIVB4AUX6EczW 7dkDIknjP4rShCuyja4bZyZO1Q0LVHDXsYbl8I3hWMOY7kLG9pqvmG36qFIFjJp/+3Pg CIgKTnylwh5fsWQYbhz/6UFc10qNFXQnsSkOgCLgSoY3Ouo4OYgAaPP7Uc5wVDf/I/V+ rhyw== 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=oIsQRsiYl76Bmj7p6XAI+Eg6mcQX92h47fy3JSCRvFo=; b=ZmTXHPm+X+sN+nSE48Tf0FEXKVZlBprpwZl15xbQghc7wW4wXegmXnXgCDKIDKUemc r+vpXsNXniEJ4s83/RCuqUmcTPxCxFXsDUCmDYQZptaewv4hkAFE7r1W/9u2rpFegQvL gx3MWqAtmpZwvZ1V87sgTNJUliYpHfKL/DR8EzDDojwHBKtErj5vYm62WcB/Ki6ypHqJ kCnuOm2IwSXytNGA7DqPsqE4vFNxtJC0HYJ7X6en/z4T/q5sPlQBx+nloLZtga34mbMh aUt+5rDw+OtYFGMX7c/XyXm6kIfiMpZ6nmrNiwdcViCKUOpDCraCMrqIEe5IVVGbCcyD AxHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cMLcwNVb; 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 f52si3808878ede.346.2019.01.20.23.51.48; Sun, 20 Jan 2019 23:51:48 -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=cMLcwNVb; 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 6D22FC21E0D; Mon, 21 Jan 2019 07:50: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_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 CFA96C21E88; Mon, 21 Jan 2019 07:49:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9C70BC21E73; Mon, 21 Jan 2019 07:49:38 +0000 (UTC) Received: from mail-yw1-f68.google.com (mail-yw1-f68.google.com [209.85.161.68]) by lists.denx.de (Postfix) with ESMTPS id ACA94C21E73 for ; Mon, 21 Jan 2019 07:49:37 +0000 (UTC) Received: by mail-yw1-f68.google.com with SMTP id b63so7679253ywc.11 for ; Sun, 20 Jan 2019 23:49:37 -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=QM4ckjWXzjCX1UATTua0x7FsSwurUT0BOoJRA8SK31o=; b=cMLcwNVbDWPeYhxsljD6cpO9l5Aypkv7cvaARx/OEx3EIRLOJO9CWqbq+TFR5Uf+Yx OOlusRf6fX9ANfKIiVYQNWFoCckd/hIj4apIcdzKYfnwCyhf2KAHdKxmGkfaxmWEwnNr 63rW1M2+2wqk9lyTfBEwa3YrseVYwTe6VBC4Y= 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=QM4ckjWXzjCX1UATTua0x7FsSwurUT0BOoJRA8SK31o=; b=k8s49Dhh5o/4VsVBTXo7Ur7WKH8cI3WMfgJ+FwqXWvdLtUe82bw4C6g/Epmy6EbHTT cuwFwFIFV3iEDrMPfccUUyairP9ucq0CrEfWufPt6VWPKJuAleZThuXYEMNJ36+Ochp2 cBgI9jANOcOHmNk9qVoDmt3kur04GzxumVfcQG7+uSvtw39q05+67L9d+TtEh+qQDtE6 czSc5Jrkp44t/mE9rcIbYynndnAsRuFN4LHZeB4E4OvrLENGLyGQZQti3has7pH9dZ/T xCtW73Hr3qxbrhrnaNoNuEKqZB4nxPN6GnYG4ov089LMbMrdjBr4/j3rs5HcTGdYlbTD LrEg== X-Gm-Message-State: AJcUukfCDxdCRIC8skYXFPWNXMRaiJd2NKS6o6qY0/RgP3urQJcTWBHW Tog4uy6Q6yHrADs9chaHC0yLCQ== X-Received: by 2002:a81:2e57:: with SMTP id u84mr26921307ywu.222.1548056976622; Sun, 20 Jan 2019 23:49:36 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c140sm8129992ywa.74.2019.01.20.23.49.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 23:49:36 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Mon, 21 Jan 2019 16:49:22 +0900 Message-Id: <20190121074923.29959-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190121074923.29959-1-takahiro.akashi@linaro.org> References: <20190121074923.29959-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v5 6/7] cmd: efidebug: 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/efidebug.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 906e6b2d0295..bd6b095562e7 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -592,6 +592,95 @@ 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"}, +}; + +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); + } +} + +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; + int i; + 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++) { + printf("%-16s %016llx-%016llx", + efi_mem_type_string[map->type], + map->physical_start, + map->physical_start + map->num_pages * EFI_PAGE_SIZE); + + print_memory_attributes(map->attribute); + putc('\n'); + } + + free(memmap); + + return CMD_RET_SUCCESS; +} + static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -993,6 +1082,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, + "", ""), }; /* Interpreter command to configure UEFI environment */ @@ -1051,7 +1142,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(