From patchwork Tue Jan 15 02:55:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 155611 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4389509jaa; Mon, 14 Jan 2019 19:03:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN77D5bYugwBdUmrHL4fCMrxEGiuw47q6v3ae+h2+0s/ifZaEQVl8E/k/Q/r0l0q2BrbDrsW X-Received: by 2002:a50:94f4:: with SMTP id t49mr1667458eda.24.1547521390621; Mon, 14 Jan 2019 19:03:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547521390; cv=none; d=google.com; s=arc-20160816; b=o29uRchiYKMOBL3Z6yhfm2XRkN0yZAF5m6Ve1rKv3zEsBA9COgtO9vzVxf6n0JtFyD fcVPSr5sXi/5t3F64hO4dZBNbLtCvuIeNV+XtXjFrQEN1J0cWgD82/cIxvhAAevGZIVW Nx+3hcGwaVq9RLZSxOjq98VI0qw3XYn4l3tkeZNwiBW96OEj0z5SCo0+ALKkdAUJk7vB ItLJPTr/+XyfRfTyl4ca5/iCQ5ovkZDaMuGMITgT50iohsXlAdPvFcRbFWSfWAcEvA7G Y0J6YnWcYG6oa8SJaPX4PaBBOcRM4WNR66+/c7dHusejP1uYs3CILTDfGDV0tY0oQnA9 2G7w== 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=MEW0CBXUL75GZuQjOOM3TxOZoceTyprjkD3cdIm+WJs=; b=Go+lCy/J4/WGpXDsnPtwKeRq0LfIsE5d0z9afPu4p61FecqyNFglUmTYGcPv9Xfy0f dPUoF8eVc02YzvznqzXaPNjL8VogIVulJbAKFp6YK9RcaZXEHxH0oElqXTERwJzVZFqJ 8kOYaoDPokInO4d/KC2xO+ZWqemfCZx9yQUgpZhLU5gOB9aBnFKM4x42Pm80Bl+ipaPg VoyHDAwxi+fnecDGIveA6REgmTN+P2zGMHJ1XY3aKk2qhj+h/G51yxGtBTaRHC5ugZ/j i+aQdAKNvRiOWisWJFZwl2aNxawWNAP1LivARbNG2Sx+1WWOUNZ5fjh/GKX+Oi6hKafS lcmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="I5J/d/IP"; 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 g16-v6si4260332ejf.225.2019.01.14.19.03.10; Mon, 14 Jan 2019 19:03:10 -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="I5J/d/IP"; 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 40724C222BB; Tue, 15 Jan 2019 02:59:27 +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 E7CFAC21FD3; Tue, 15 Jan 2019 02:59:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AA5D6C221B9; Tue, 15 Jan 2019 02:55:50 +0000 (UTC) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) by lists.denx.de (Postfix) with ESMTPS id 7EBDAC2214B for ; Tue, 15 Jan 2019 02:55:45 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id p65so526909ywe.0 for ; Mon, 14 Jan 2019 18:55:45 -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=uGF5l613MW6d0K0m+SnxVjReBQiFBra5gTtKcjD35+4=; b=I5J/d/IP+LttuUN9Px9jbTz/eUYcE/wVcRbtZGXaKjMidB/26Wm1um1X/SeM06HdHn w7I08f/mjIDP4ZcNEtWhOGEtFCES+5gyyN75Qj9xZmh8OZNVBNsanPxiRcyIxOSOsqrl g4Tn8uKwE8i+yQm9YtEXUm4/HPfErOYKIu17k= 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=uGF5l613MW6d0K0m+SnxVjReBQiFBra5gTtKcjD35+4=; b=a63rzL10LM4cNEIPqD+SS8ln0l1jhGfoAkksF0+Zy5tNHfpjv0sy62dDMi7qryQvO1 2VGscYK6R6hQ3oaaFtLNskHByiFq3dvqpavDBPgZpvur6CihJKz/Z64+ETSDgc2WFoBy r4QprReGfuFxw7pTVzp5EgbUT1fAyj/5S2OL4sDr+DtS6TbXee981SUKUpQEibnicmEv ftCHpQ9kgEMWIKQRX4fFMuLpVR4lx0SHp38VxLE52qSuW5WppamKc66M2F7BaIeYl9ID bL61HNyVGxHYcp/c/Ur0srh4oWJyE/uq+xzM5tPTpkIoNIsvJx7U/9LyobF4T6qt8ieH Aw6w== X-Gm-Message-State: AJcUukdK8w5qKtQcY4Y/+mxBlFvbw01rbXBL4ByYJ6/A4camGNGUrXFW DDvqQhOj2XYMf8tKFdwmrSQNhg== X-Received: by 2002:a81:1d44:: with SMTP id d65mr1272744ywd.483.1547520944465; Mon, 14 Jan 2019 18:55:44 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b129sm737787ywc.106.2019.01.14.18.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 18:55:44 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 15 Jan 2019 11:55:17 +0900 Message-Id: <20190115025522.12060-5-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 4/9] cmd: efitool: add drivers 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" "drivers" command prints all the uefi drivers on the system. => efi drivers D r v Driver Name Image Path ================ ==================== ========== 7ef31d30 EFI block driver Signed-off-by: AKASHI Takahiro --- cmd/efitool.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/cmd/efitool.c b/cmd/efitool.c index 6b2df1beedb5..4d46721fbf91 100644 --- a/cmd/efitool.c +++ b/cmd/efitool.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include #include #define BS systab.boottime @@ -358,6 +360,82 @@ static int do_efi_show_devices(int argc, char * const argv[]) return CMD_RET_SUCCESS; } +static int efi_get_driver_handle_info(efi_handle_t handle, u16 **name, + u16 **devname, u16 **filename) +{ + struct efi_handler *handler; + struct efi_driver_binding_extended_protocol *bp; + efi_status_t ret; + + ret = efi_search_protocol(handle, &efi_guid_driver_binding_protocol, + &handler); + if (ret != EFI_SUCCESS) + return -1; + bp = handler->protocol_interface; + + *name = malloc((strlen(bp->name) + 1) * sizeof(u16)); + if (*name) + ascii2unicode(*name, bp->name); + + /* + * TODO: + * handle image->device_handle, + * use append_device_path() + */ + *devname = NULL; + *filename = NULL; + + return 0; +} + +static int do_efi_show_drivers(int argc, char * const argv[]) +{ + efi_handle_t *handles = NULL, *handle; + efi_uintn_t size = 0; + u16 *drvname, *devname, *filename; + efi_status_t ret; + int i; + + ret = BS->locate_handle(BY_PROTOCOL, &efi_guid_driver_binding_protocol, + NULL, &size, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + handles = calloc(1, size); + if (!handles) + return CMD_RET_FAILURE; + + ret = BS->locate_handle(BY_PROTOCOL, + &efi_guid_driver_binding_protocol, + NULL, &size, handles); + } + if (ret != EFI_SUCCESS) { + free(handles); + return CMD_RET_FAILURE; + } + + printf("D\n"); + printf("r\n"); + printf("v Driver Name Image Path\n"); + printf("================ ==================== ==========\n"); + handle = handles; + for (i = 0; i < size / sizeof(*handle); i++) { + if (!efi_get_driver_handle_info(*handle, &drvname, &devname, + &filename)) { + if (filename) + printf("%16p %-20ls %ls/%ls\n", + *handle, drvname, devname, filename); + else + printf("%16p %-20ls \n", + *handle, drvname); + free(drvname); + free(devname); + free(filename); + } + handle++; + } + + return CMD_RET_SUCCESS; +} + static int do_efi_boot_add(int argc, char * const argv[]) { int id; @@ -767,6 +845,8 @@ static int do_efitool(cmd_tbl_t *cmdtp, int flag, return do_efi_set_var(argc, argv); else if (!strcmp(command, "devices")) return do_efi_show_devices(argc, argv); + else if (!strcmp(command, "drivers")) + return do_efi_show_drivers(argc, argv); else return CMD_RET_USAGE; } @@ -793,7 +873,9 @@ static char efitool_help_text[] = " - set/delete uefi variable's value\n" " may be \"=\"...\"\", \"=0x...\", \"=H...\", (set) or \"=\" (delete)\n" "efitool devices\n" - " - show uefi devices\n"; + " - show uefi devices\n" + "efitool drivers\n" + " - show uefi drivers\n"; #endif U_BOOT_CMD(