From patchwork Mon Jan 21 07:49:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 156165 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6087147jaa; Sun, 20 Jan 2019 23:50:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN7zsUBNyZHEMhdtTY0wj+Fcm56wTW2Ex/+NTikU/bvgxh5+dumYtIoz2aLQkB+4xBpMgbbC X-Received: by 2002:a50:a974:: with SMTP id m49mr26570429edc.220.1548057019853; Sun, 20 Jan 2019 23:50:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548057019; cv=none; d=google.com; s=arc-20160816; b=wFHYFq59fPVPwnL4F3avNKTuxrdwTTZh6RZD9W7y51qSV2a/u5B2jHAn1hfX2Zttfy UetMp9gn4LrkCiadQ9nNIPTKlAH79yqr+/DUdVf08QPYqDuaAuCtcqdYnXDgnHnuGe8V oMX3OvUyu5q377ghTrod4V5ctexBaG7TIVM0LONSVIcovf0LzRTq0v1Z8VAFBAETnvpB 5e1vqY/AE0PRBrXTaMMouY7E3u5NH6vbrrF5C3c94Uny2/KQcF4/+w+3RunQ61xE5s/D 4FSo+1kHAUCE9NrRmawvpEG17ZMC7+wC1Xzfu43AQOLMOtc+VET/ohBNER4fckVu9tXq AsHQ== 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=XTgGUIJbJqitfgVhOe+qb0f+L+Hns14PxfSvJMY5fK0=; b=oD12TZdFJtMwD8Qsfzch1caOBu7lhRI2gRffZJNOUkgG9cn0cCZz68jUnG+CstzM8u nsxuay9S2IXk84eKebVz7mjvRRPqoNMa9WMvQA9iAvWCVWTG1YjQ0s3RwMc9OoLuy0Dy nG641sEBp/ECe6dibveXIcir8+BlGHQssBp11QprkELP99GuTZLwLX55GLy57Zo0EWEY /J1InNmG11xVjNO1wNuVjg1I+GMiRkRjcH0bE3fVQW9MX5I5E+IsXqDUdDuPvV2Yl2nx qSJjnM6LUhLWEEUVSdXK1vklpl1GMZsmL6+EhHvIVG/6GKOEEFK1zPSkiw46mkvJcWRo qdbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Zi+8WRY9; 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 y6si5417753edi.116.2019.01.20.23.50.19; Sun, 20 Jan 2019 23:50:19 -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=Zi+8WRY9; 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 66EC7C21E7F; Mon, 21 Jan 2019 07:49:41 +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 3B645C21E5B; Mon, 21 Jan 2019 07:49:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 863BBC21E57; Mon, 21 Jan 2019 07:49:27 +0000 (UTC) Received: from mail-yw1-f65.google.com (mail-yw1-f65.google.com [209.85.161.65]) by lists.denx.de (Postfix) with ESMTPS id C692DC21E57 for ; Mon, 21 Jan 2019 07:49:23 +0000 (UTC) Received: by mail-yw1-f65.google.com with SMTP id g75so7721096ywb.1 for ; Sun, 20 Jan 2019 23:49:23 -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=B6J57SmjhpAe+LrWunUQI72te7MFqlm5x3yxTLE7Zpk=; b=Zi+8WRY96Rt/v9VfjmuG4LJrUA2QYeZl4chVt1WPF338gTKAbrW5pOCeVx6ekf3z76 tn2kOHqSN1tq/GjjrQmz5Cius5lyC2q1bca7ZUrdh1AJU9xIdyjjAB+gh22RM2J8Kq/w Z7uDhen6aju0qUqoy+lmXACxvA28AeOX1XJHE= 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=B6J57SmjhpAe+LrWunUQI72te7MFqlm5x3yxTLE7Zpk=; b=PSsrRXe4utoKfmv/5LA0hi6blZycBUV7WF5DnkLyZUXQFfUz16f0zwsCGeVbCkGTue Jrzvz3bxF3wyCH89APU3eixHP8wSDGiT8KnLycgi5kl2X1y8LdFpw1/PX3d0YcJF7cDj /xqBlcSBbSRceBVgcmlbTcZKcXrsBlpW0q8+D1dUUnKIKrzkkwRaAdoko2R3tQLEZRab SGM+vph6o6Yhg2GA+wvpTgQcl5g5Fr388S5M29IwqGybBBALaIAkj9Q4hL9GeiOGCKCZ wPURxBUo8ghyqumtkZuSzUChOrA/JSFB5r0xnfWGYGzrOxT8ot+ysWYMte5C7j01jcR5 oWrA== X-Gm-Message-State: AJcUukcAJgXm7bQ71JKZ+vC5BmRAj8bhv0jhyBToeCYzssfxQrFJICHm 9/kuNiG9FcY5wSyuVFd7DwR9XRicPd0= X-Received: by 2002:a0d:c182:: with SMTP id c124mr26982423ywd.190.1548056962785; Sun, 20 Jan 2019 23:49:22 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id k83sm6430384ywe.90.2019.01.20.23.49.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 23:49:22 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Mon, 21 Jan 2019 16:49:18 +0900 Message-Id: <20190121074923.29959-3-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 2/7] cmd: efidebug: 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/efidebug.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index c54fb6cfa101..0c7b51364753 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.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; @@ -301,6 +303,97 @@ int do_efi_set_var_ext(cmd_tbl_t *cmdtp, int flag, } #ifdef CONFIG_CMD_EFIDEBUG +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 **dev_path_text) +{ + 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) { + *dev_path_text = efi_dp_str(dp); + return 0; + } else { + return -1; + } +} + +static int do_efi_show_devices(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + efi_handle_t *handles; + u16 *dev_path_text; + 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], &dev_path_text)) { + printf("%16p %ls\n", handles[i], dev_path_text); + efi_free_pool(dev_path_text); + } + } + + free(handles); + + return CMD_RET_SUCCESS; +} + static int do_efi_boot_add(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -694,6 +787,8 @@ static cmd_tbl_t cmd_efidebug_sub[] = { U_BOOT_CMD_MKENT(dumpvar, CONFIG_SYS_MAXARGS, 1, do_efi_dump_var, "", ""), U_BOOT_CMD_MKENT(setvar, CONFIG_SYS_MAXARGS, 1, do_efi_set_var, "", ""), + U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices, + "", ""), }; /* Interpreter command to configure UEFI environment */ @@ -744,7 +839,9 @@ static char efidebug_help_text[] = " - show UEFI variable's value\n" "efidebug 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" + "efidebug devices\n" + " - show uefi devices\n"; #endif U_BOOT_CMD(