From patchwork Tue Dec 18 05:05:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 154066 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3282583ljp; Mon, 17 Dec 2018 21:08:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/VmQS2zW9i9Ml/ugbivaTJrhCZLuKmfgXJNbEjdVTuWFf1XooAEdlpHN6D456XYVGuypNg1 X-Received: by 2002:a17:906:41cc:: with SMTP id g12-v6mr6112081ejl.219.1545109703338; Mon, 17 Dec 2018 21:08:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545109703; cv=none; d=google.com; s=arc-20160816; b=bX/VJsbD/Ynsmu73SKyYZDC9uOXJTVSkbAOBwPEiORrx6VhGWzKeNW1+PXVqt/zYeH +0rUSwixj0PvEWz+oyvVDIQ1Xk85qK7+dkJ+mDjQuu9qNojenmlLvomQ4EooqfJmgUHx EHt4P9K4zjsTEMSCmrgkBo4hbRsLz6iFtmeujJy+61U35VUcg5iS9COGGZJsgR2Yf3zF lsC0iR2iLGgwGfdfxxf/WdD3aEeh90UQncorpwwnBlQHXHoqz0oCo4b/MOsFYa4MyVYx Ak9NZ1dC4p6xZtq1FzRYfLLcDVqpJIAhlXEiRjjEnoJBYSSOZPQ8V/3/GZQXhICywUfG hXWg== 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=E4E2NpfCnwhIz/0U1cw/CWpxgt9lz928BGyOouSKMnk=; b=NqxuCksjmLLrNXdGRV8htzcpzvMg43Avew553BHA92wOPCn/+8OgtDpcfDGvn96Rvn UgByTgdu/qSosrDHsEyTdsLzAineaUGoXhhEHODScSbtunXKp8hDqLsr0HKwYknZxvlF 2HvT78eaecpwo8TW5ECa3zV8fGHe+1NCeFepiKKUJlQ4Olc2AMP5HzacvdR+za8fNDLW 5zOeah2CO6FYFR/q2k1MhBs7TcB/bi7wkZ/cX7kE/2A6G4TRtKzHhjtOgg95DUMmoxI8 IQT0K9Ypxle97W/9tcb9RfdzQyhot1JeS0pPhWdOgjmDZ7dAlbyvFuYokzC7oDlUTSVy jZqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JRszKcgY; 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 f23-v6si1019145ejw.244.2018.12.17.21.08.23; Mon, 17 Dec 2018 21:08:23 -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=JRszKcgY; 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 F0CC3C220D4; Tue, 18 Dec 2018 05:03:47 +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, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 6AE0CC22018; Tue, 18 Dec 2018 05:03:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EF89EC21F79; Tue, 18 Dec 2018 05:01:53 +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 C057EC22090 for ; Tue, 18 Dec 2018 05:01:52 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id t13so6160529ywe.13 for ; Mon, 17 Dec 2018 21:01: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=GkOKcesXtrMMOz/HEXSUHscvhN/70+P641W507gQ7yQ=; b=JRszKcgY7DdCVDN+xp14A2Aag6hGqu3cYCoAtDKC3k9KHVJusXubtpvruePmlDueo2 T9+pXbWAggUUJiGMtvN8UqDGzqUKjzjDD3p8K2YlrXo3MfLAh0k3GLvP+pKpaK6J5paU IsqrtKqQOaGMPHDCkf0g39zdjp9I5X33JoDhQ= 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=GkOKcesXtrMMOz/HEXSUHscvhN/70+P641W507gQ7yQ=; b=Sb0pv+XuijAY+fsWpsbhMMClgLhsZITgqb8FXAOsW7GI1NEQev7jM6RsYZJxfxC1NV UAPKbs11Fq8Cnfbozgn9Rn2wZWH8uvwd27TOpjGVZe1rhCfPQRPWeRCPmskM/49RDHo0 uijorVqjrE0WJjXpyNbIpwVcCAO0PFOI9w4QZUIP1vziQv3v4b1Fft+czI4waGCjCzt5 aazvlNH2vbdQYopFZmuEc9NY7dPt+sFm5p+7vdzDKM2tOl2/EL9PhuuVsNZw975scwZ5 Z2a7PuZKX5XwMiYo8VJH6tNLGmGm1Dl3So4XVGKd4dgr6UhlFDHd5WLMt34/hqiNHOnh VOPw== X-Gm-Message-State: AA+aEWalViYH7do1bRwKBTGokdBWM2qD/VsL6k1KQc1k9AGwQLs0KGsy mjBCEWY58tXHWj0ow8bITjQtOg== X-Received: by 2002:a81:b184:: with SMTP id p126mr16223406ywh.157.1545109311726; Mon, 17 Dec 2018 21:01:51 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r188sm4372529ywb.30.2018.12.17.21.01.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 21:01:51 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 18 Dec 2018 14:05:04 +0900 Message-Id: <20181218050510.20308-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181218050510.20308-1-takahiro.akashi@linaro.org> References: <20181218050510.20308-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 2/8] 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 5819e52cf575..929b6343b1b2 100644 --- a/cmd/efishell.c +++ b/cmd/efishell.c @@ -18,6 +18,8 @@ #include #include +static const struct efi_boot_services *bs; + static void dump_var_data(char *data, unsigned long len) { char *start, *end, *p; @@ -263,6 +265,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(