From patchwork Mon Nov 5 09:06:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 150163 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2359552ljp; Mon, 5 Nov 2018 01:12:47 -0800 (PST) X-Google-Smtp-Source: AJdET5djc1qYcSvdVI2hOuzMvf/c6LWJ2e4eI58cGO3UjT3Clm/0Rp8aEwYAxRGNGeV9BLXuHDFg X-Received: by 2002:a50:9250:: with SMTP id j16-v6mr16966684eda.259.1541409167842; Mon, 05 Nov 2018 01:12:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541409167; cv=none; d=google.com; s=arc-20160816; b=ZmCugQ+6b7O9FvTRQBz9EhndP2NOFn+aDFQU896/EOe8wZWSZzjp2xpxPPCTSCwMl2 tReUUb1SoKdMsps55KoXITad7mbIbB70M49FFO79SZJgPGwu70WaSD/jkqGpB5YEWVEw Bnls2t1xn8CRMnqV4GCgVJgXGJ7nGq+W9mmePNfJyJPZi+uJoLguuHWVAEUK82P/vmyz 3yRYRyELGbF0xTvETG7CBnXo/pcNQNAMfqNy+qL+gZaU81+qH0DyqV1KVyhUx0Gcpo4+ Dsoqv8aPMBpLHaza35OL8So9p03JrS6zZ1QZAc1S56JJbq/HddKmvjrTVmHovvp07Ow9 yVYA== 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=6CAKTuFIPeOjI+UGDu+eNbIZcqvn3hf3PbwgXyKatLE=; b=CFh+Fua1eUgvSwnpffVrUwPZ2PvJK5JBtF4BoKHX4Qb7ULEGCi2TTE9LkV6IekSvTU FA78psd99rV7tdkMm+EEYiMLkH6AJf3q4Ew8GuoGR1P1SuibJAP3izTpda4lCZ6qf4Gm q7XE/dUtfa74X/Ai9yhKEbY2ReHRgcigNVxMsCRwkwwFtpXfLJnhTHWLWdAQukwwICqs j40QI0QHXl/WeMCUmXPh4jfF0Q/cz+xmKtf0DUWgL3UUMAyOL04dzXHDjzfaKYBxacy/ LMvTmnqBx+8JpPWyWjyadeloqtVTHkSfOGVhYqSuT+J8y1/4+Hv27SlIBNBD71zx/JMW z6ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=HFkjWjNL; 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 c19si2181333edv.143.2018.11.05.01.12.47; Mon, 05 Nov 2018 01:12:47 -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=HFkjWjNL; 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 7807EC2220F; Mon, 5 Nov 2018 09:06:26 +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 73514C22239; Mon, 5 Nov 2018 09:05:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0E130C22210; Mon, 5 Nov 2018 09:04:59 +0000 (UTC) Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by lists.denx.de (Postfix) with ESMTPS id 97B14C22200 for ; Mon, 5 Nov 2018 09:04:55 +0000 (UTC) Received: by mail-yb1-f196.google.com with SMTP id f15-v6so3460875ybq.13 for ; Mon, 05 Nov 2018 01:04:55 -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=hzmHBxeB+0KoSkEdC0woZQdhYSmvFpdqj3sbt2LLGpU=; b=HFkjWjNLhv3bl0djj3Aw3tX5FolnvHibQ4zawe6JsK/g83ZGW/bCX78F0qX/8XIVJo cN0GsyMxK10zj0U0sp9NFKtVTthEZJIUNnC4zvJkvT5RyovKcRXv6NsAClKSZu8BkoaE QxDWhmqr3+ylnPujf3k33MXUMD/RvZdWMN6qE= 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=hzmHBxeB+0KoSkEdC0woZQdhYSmvFpdqj3sbt2LLGpU=; b=Lm+F9mMMONf6GU8ibx4E21uXBGjg6oOUoQXnYvcqoMG+eZoj8Kqa4pgpN10kRM0EuQ BkJHgOAh+R4B99DDZEnFNBNfirstkIjYk32AS8DqxBF/r0Fd9himEdbTdI7wQL5wdQBL UpNP56BZz2GJK+EMX4bcInWWONC0va29MpfxQ+H7Qwj+FmIrllAdtkTtFSfqG+JExyRE d6H7BwBiRjrZkvab9jY3YYWbPtVw8ZTrb3GQBOkqh/3kocqAGE24mjjI20vlgW6cehj3 JOrkYyENAhtNngqizoaufDtTxObW9uaMzSOUhCxMmYmdny5ndMQzfYmjMwWdpVriLYjB NFBw== X-Gm-Message-State: AGRZ1gL+hx5G4+b197XVyv0TcozmNl1SIf8VSgzi5wizsl8Y7ESrpv+8 IsiDy7wjj/4h3NbLbJHXofhr7w== X-Received: by 2002:a5b:291:: with SMTP id x17-v6mr20407245ybl.258.1541408694475; Mon, 05 Nov 2018 01:04:54 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 205-v6sm11506998ywd.1.2018.11.05.01.04.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 01:04:54 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Mon, 5 Nov 2018 18:06:44 +0900 Message-Id: <20181105090653.7409-6-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 05/14] cmd: efishell: add devices 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" "devices" command prints all the uefi variables on the system. => efishell devices Device Name ============================================ /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/\ HD(2,MBR,0x086246ba,0x40800,0x3f800) /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/SD(0)/SD(0)/\ HD(1,MBR,0x086246ba,0x800,0x40000) Signed-off-by: AKASHI Takahiro --- cmd/efishell.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/cmd/efishell.c b/cmd/efishell.c index abc8216c7bd6..f4fa3fdf28a7 100644 --- a/cmd/efishell.c +++ b/cmd/efishell.c @@ -21,6 +21,8 @@ DECLARE_GLOBAL_DATA_PTR; +static const struct efi_boot_services *bs; + static void dump_var_data(char *data, unsigned long len) { char *start, *end, *p; @@ -266,6 +268,84 @@ out: return ret; } +static efi_handle_t *efi_get_handles_by_proto(efi_guid_t *guid) +{ + efi_handle_t *handles = NULL; + efi_uintn_t size = 0; + efi_status_t ret; + + if (guid) { + ret = bs->locate_handle(BY_PROTOCOL, guid, NULL, &size, + handles); + if (ret == EFI_BUFFER_TOO_SMALL) { + handles = calloc(1, size); + if (!handles) + return NULL; + + ret = bs->locate_handle(BY_PROTOCOL, guid, NULL, &size, + handles); + } + if (ret != EFI_SUCCESS) { + free(handles); + return NULL; + } + } else { + ret = bs->locate_handle(ALL_HANDLES, NULL, NULL, &size, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + handles = calloc(1, size); + if (!handles) + return NULL; + + ret = bs->locate_handle(ALL_HANDLES, NULL, NULL, &size, + handles); + } + if (ret != EFI_SUCCESS) { + free(handles); + return NULL; + } + } + + return handles; +} + +static int efi_get_device_handle_info(efi_handle_t handle, u16 **name) +{ + struct efi_device_path *dp; + efi_status_t ret; + + ret = bs->open_protocol(handle, &efi_guid_device_path, + (void **)&dp, NULL /* FIXME */, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret == EFI_SUCCESS) { + *name = efi_dp_str(dp); + return 0; + } else { + return -1; + } +} + +static int do_efi_show_devices(int argc, char * const argv[]) +{ + efi_handle_t *handles = NULL, *handle; + u16 *devname; + + handles = efi_get_handles_by_proto(NULL); + if (!handles) + return CMD_RET_SUCCESS; + + printf("Device Name\n"); + printf("============================================\n"); + for (handle = handles; *handle; handle++) { + if (!efi_get_device_handle_info(*handle, &devname)) { + printf("%ls\n", devname); + efi_free_pool(devname); + } + handle++; + } + + return CMD_RET_SUCCESS; +} + static int do_efi_boot_add(int argc, char * const argv[]) { int id; @@ -625,6 +705,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag, if (argc < 2) return CMD_RET_USAGE; + bs = systab.boottime; + argc--; argv++; command = argv[0]; @@ -642,6 +724,8 @@ static int do_efishell(cmd_tbl_t *cmdtp, int flag, return do_efi_dump_var(argc, argv); else if (!strcmp(command, "setvar")) return do_efi_set_var(argc, argv); + else if (!strcmp(command, "devices")) + return do_efi_show_devices(argc, argv); else return CMD_RET_USAGE; } @@ -663,7 +747,9 @@ static char efishell_help_text[] = " - get uefi variable's value\n" "efishell setvar []\n" " - set/delete uefi variable's value\n" - " may be \"=\"...\"\", \"=0x...\" (set) or \"=\" (delete)\n"; + " may be \"=\"...\"\", \"=0x...\" (set) or \"=\" (delete)\n" + "efishell devices\n" + " - show uefi devices\n"; #endif U_BOOT_CMD(