From patchwork Tue Jan 15 02:55:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 155603 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4385226jaa; Mon, 14 Jan 2019 18:57:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN6rZ8dnhR2dcpRP/q5TQirYSZCjRJZGeeSgxjlFNZX5P9RYWft0u/NbJjES6Vutk7Prr3XV X-Received: by 2002:a17:906:7692:: with SMTP id o18-v6mr1434883ejm.63.1547521070742; Mon, 14 Jan 2019 18:57:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547521070; cv=none; d=google.com; s=arc-20160816; b=tH9fI+erBzam9RROcThf0syhXUDtx6FqCSOUb+cTDBCqweIHvMxcHKCJpeKyp+RvzJ jwEAoZCzoddL3uZjvL2+HIJo3M7YUcAigNmWOzP5+k5m2ngEUKcMIwpm2lXxcslsWIjk h/BZHeSrtq9oYvLp0xTroS0DLddRFL7Lx69u8AjLGn29SlRPkIsrcdaqG/2FJ4aR6Xrl FMxmM69664SJf5+13QXZT5Oot1qIp0MTpGv9zz0x4iHut+tn86d7HI76Wx6OA4Mu1aNd fsuIzBlok9I88SWUs9o8sLc8Mdiag8uiBWZ+O8qFTMd3MQn9cn0mrTmVEKHinizpI0an a84Q== 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=som+Y5hHSM28eUK97VOdJyggoQ60auQwkFBPRvHvOb8=; b=Scpzjk327W0TY5jmjsIWmKI0/acneCJH4byW1wLMP9LGzt+/Z41yQe+my6fW1c+nyQ RXx2wMQdXPJDYErvG0rifVUWXD0x4VvtOfTHNfQaCrm7jMxTrJkjT5wuYjPKpUzT9Gfw e3t00KjH0Y6xeV3fSfnp4Wc7MyovfEx06A8zIiqxmsB3ljHSYogtYBwBzehKM1qISbkh jkLpjDIfssi6+l+wIyXIUov/eimOyrorCmBP6YKvbOIryJfgfF/FK3t+fOaXIStbTmf/ y1EqQ6YCHx8qOfrkqWHImNKYIOGdU6RTwIMY9GVfVio4pi4YUUeTpFRoQxfN3HeNZLoa E2Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bTGl5I3p; 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 90si201281edb.180.2019.01.14.18.57.50; Mon, 14 Jan 2019 18:57:50 -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=bTGl5I3p; 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 49B30C21FC3; Tue, 15 Jan 2019 02:57:04 +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 17038C21FA0; Tue, 15 Jan 2019 02:56:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 38344C22008; Tue, 15 Jan 2019 02:55:44 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 04649C21FD4 for ; Tue, 15 Jan 2019 02:55:41 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id x9so500760ybj.5 for ; Mon, 14 Jan 2019 18:55:40 -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=4wnqAd/PWY2olh3yTZbA4fQAAqoRq4jvliXukccaaEM=; b=bTGl5I3pc5LO7pOAsMAQw1zi7H/grDPVmwFENNqnibcfcySA6zXyh//W7CeDKnzAPr LnnHgeYFXx8QREf2UhJClDDUgyo1bkmq/y/H5eigbMAzwR3j0WbIr2nozde/CjLscKNs pLDcudb4oaaUPA9lDCctj+NUFR/bxiultAaV8= 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=4wnqAd/PWY2olh3yTZbA4fQAAqoRq4jvliXukccaaEM=; b=YLOJE6PkmM2KdXfap6IqOcXgf0rlQ7oHAdOKU/BJ8aEiMiBgABStQ8TxWYXoKzpCF0 cswwoZEZSe0NLo+6WeMRTQl+duw+Yu0R+6OjpUYWFGnY90S8lnn7qR3+DFEf8KX4Hgk2 KYkJgZaQXW7qqcsOT9LCU87nZHBs4T7xM2cjBwXMY7qdfr/bcDVu+bahaf7HWbIwf5tR o8R8bxHEK0w2ozSR92qpPzVFS2rxxKUwHwqbe3lnqELKptazkL6zwLl3kZczqvVPnv5K sLYQ8rPHbtalzAZ5Hh8+QE/StJDl3P6aKjgZVuqZWyTh+Zd35PucbjdBG9wCSzbjcapZ kiQQ== X-Gm-Message-State: AJcUukckw/IQxNFfNknpF5CtHRFYUFAFcaScGVfME52dkvVvtmYVhH7C 6bYoxn6wt29RK0GV1wQDFgV67Q== X-Received: by 2002:a25:fc1a:: with SMTP id v26mr1259124ybd.145.1547520939903; Mon, 14 Jan 2019 18:55:39 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l74sm947435ywl.99.2019.01.14.18.55.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 18:55:39 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 15 Jan 2019 11:55:15 +0900 Message-Id: <20190115025522.12060-3-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 2/9] cmd: efitool: 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. => efi devices Scanning disk ahci_scsi.id0lun0... Scanning disk ahci_scsi.id1lun0... Found 4 disks D e v Device Path ================ ==================== 7ef3bfa0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b) 7ef3cca0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0) 7ef3d070 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0) 7ef3d1b0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(1,MBR,0x086246ba,0x800,0x40000) 7ef3d3e0 /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(1,0)/HD(2,MBR,0x086246ba,0x40800,0x3f800) Signed-off-by: AKASHI Takahiro --- cmd/efitool.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/cmd/efitool.c b/cmd/efitool.c index c7dc2c11f2e7..6b2df1beedb5 100644 --- a/cmd/efitool.c +++ b/cmd/efitool.c @@ -18,6 +18,8 @@ #include #include +#define BS systab.boottime + static void dump_var_data(char *data, unsigned long len) { char *start, *end, *p; @@ -266,6 +268,96 @@ out: return ret; } +static int efi_get_handles_by_proto(efi_guid_t *guid, efi_handle_t **handlesp, + int *num) +{ + 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 -1; + + ret = BS->locate_handle(BY_PROTOCOL, guid, NULL, &size, + handles); + } + if (ret != EFI_SUCCESS) { + free(handles); + return -1; + } + } else { + ret = BS->locate_handle(ALL_HANDLES, NULL, NULL, &size, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + handles = calloc(1, size); + if (!handles) + return -1; + + ret = BS->locate_handle(ALL_HANDLES, NULL, NULL, &size, + handles); + } + if (ret != EFI_SUCCESS) { + free(handles); + return -1; + } + } + + *handlesp = handles; + *num = size / sizeof(efi_handle_t); + + return 0; +} + +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; + u16 *devname; + int num, i; + + handles = NULL; + num = 0; + if (efi_get_handles_by_proto(NULL, &handles, &num)) + return CMD_RET_FAILURE; + + if (!num) + return CMD_RET_SUCCESS; + + printf("D\n"); + printf("e\n"); + printf("v Device Path\n"); + printf("================ ====================\n"); + for (i = 0; i < num; i++) { + if (!efi_get_device_handle_info(handles[i], &devname)) { + printf("%16p %ls\n", handles[i], devname); + efi_free_pool(devname); + } + } + + free(handles); + + return CMD_RET_SUCCESS; +} + static int do_efi_boot_add(int argc, char * const argv[]) { int id; @@ -673,6 +765,8 @@ static int do_efitool(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; } @@ -697,7 +791,9 @@ static char efitool_help_text[] = " - show UEFI variable's value\n" "efitool setvar []\n" " - set/delete uefi variable's value\n" - " may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n"; + " may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" + "efitool devices\n" + " - show uefi devices\n"; #endif U_BOOT_CMD(