From patchwork Tue Nov 9 01:32:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 518029 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1052674iml; Mon, 8 Nov 2021 17:33:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyIW2MRerOxx4To2KYjfuqMdtN2CLCZHgnCAHqDoP6p2J5pIklWO5LjYP08sz3SAB7BeRJ5 X-Received: by 2002:a17:906:4787:: with SMTP id cw7mr4827994ejc.311.1636421612271; Mon, 08 Nov 2021 17:33:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636421612; cv=none; d=google.com; s=arc-20160816; b=uWcIZ2mraYh/4VIAud1yCnURMZDyEzvOf2OPzI2nkuRmRGB39BShMnIim3+I8YtYjJ PrKtdoZlqzdD6IuIIWVipTF52ncRQPgMpIBxfveXQTG63l+fiz27MjXGMcFxJpmelvuf el/X2yf8SWbE8d4XcWXI6A9S1zCACgOxlhuEM7kTAlUX1MmExkEa0lInuQhiJ7LH8kQz DBL2VcA8fE/aVShmdKtgXTxOn4xbhRzPbAhlSFdLvilrdIOU4F23JNdE6ObLp889VrWQ X3r/LvxdEWu/2Z+Ow1/6kp6SRPsvEMrKzrTJOT9ErVE6KeuUyix+SBorNGXaazLKki2o bypA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TGkz7b7wt+AMOnQeNHSUZ6RWPJih8dTqzsEYhg6sQ3Q=; b=Mtb5TchUQfhxp0kzxKc3PRnNtX66iDdkoD9i32Phcs6k9bAf2W8mp8Fyr2sUmctcsF hjCTc/gY1FZVyHRLtxhjp1FU6ijxbE7uGLV9AeeRGv91BitB4e9IPIJTWmr7aQlf/9xf Ka+F04CXytNtSUQQ6bnqX9cikj4apLn7XNvT0xPK0C0Pf6rwEfZ+rVpkBpnp7beSHanQ mzDHuZO9ipLvnR2MaltqEkaWp4IEkFgsRBFPEmLrVvjhN8lSMqlEwlmCEm12VTg3lM8E alNq0Zn0ZmMhWOeGR/xPP6Daj9v1QmOpv7EluamUIt68OTiB9Y5GZYzC9rSCYHdADOJQ ZAWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ysG0bJhr; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id o13si15763863ejy.527.2021.11.08.17.33.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:32 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ysG0bJhr; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 48979838E4; Tue, 9 Nov 2021 02:33:30 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ysG0bJhr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2513A83886; Tue, 9 Nov 2021 02:33:28 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 12C4F83883 for ; Tue, 9 Nov 2021 02:33:23 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x433.google.com with SMTP id o4so3778304pfp.13 for ; Mon, 08 Nov 2021 17:33:22 -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=TGkz7b7wt+AMOnQeNHSUZ6RWPJih8dTqzsEYhg6sQ3Q=; b=ysG0bJhrvAMVURNDKadKvGLgvyy7XMynLgzNgk/xO/IxBdFtMwpH5ursRoYTZ08ioR lB3qmnwKbgRfqjx2qBJVoiqQSoiRZHghlr/8GHP8P/KyrEkniSAdxFOYt7KGlav+AiO7 d4LUAdU+ev4lkvrnzxrgaWQr2998oEhcN1zG95BD74+49Mf6RadULSFQ5QOnQzflwrcp sbK3s5FU8iv0TJeguHhvh3TvIxYHLyK7rhq9bSPz8aIWyGNR1zWNPMmf4AvngPFkJ03x pxHKOSZg1yR1ejpNdXKAweNlCRQRZRmQqsOefnGcHlvHjz3xoDoN5oPsE9i9aFX2dns7 ohlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TGkz7b7wt+AMOnQeNHSUZ6RWPJih8dTqzsEYhg6sQ3Q=; b=mJG6GZV2pD6MxWTm0dm41zv4RRaVmVTiAC28f7BxhIVBJ792G0oncDm+U62L+Pg6qW lcw7IP7q94eO0hlMQmZN8ZTIqaRIzmrcS/hnOA7c2cAM0xogaa6ovpd4Gl4MT8AsNfuq OEsz2VLq6q6cwVoFZ6FlguSMQ0Dv32oO0D0WHFOf1M9+wflCAckrYzuLIUXhx2y3m7mv jMBrYnLP1dj5BkL9Yole6UBTxMtcCfWOlCveCZBTaWGnncvDJpvE4r23pPywtiCxt2LO V1C+7EXarmeN40G21CLVQhI8unUZ4tHa/izviShgPbpq1w0AP8jW0Rduzl7Bhjyd4Gj7 4hgQ== X-Gm-Message-State: AOAM533oaMRgGnn8TE17EmFpx4cLKomG8PxoZibw7UXeQDYeauu1D3s0 ZnVWoqzxwNdf/hM03+bDUQ9jMA== X-Received: by 2002:aa7:83c9:0:b0:481:1d47:3362 with SMTP id j9-20020aa783c9000000b004811d473362mr3976387pfn.5.1636421601395; Mon, 08 Nov 2021 17:33:21 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:e857:cfcb:a6ed:9a8]) by smtp.gmail.com with ESMTPSA id v10sm4946589pfg.162.2021.11.08.17.33.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:21 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Cc: sjg@chromium.org, ilias.apalodimas@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 1/3] efi_loader: export efi_locate_device_handle() Date: Tue, 9 Nov 2021 10:32:31 +0900 Message-Id: <20211109013233.72902-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211109013233.72902-1-takahiro.akashi@linaro.org> References: <20211109013233.72902-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This function will be used in the next commit where some behavior of EFI boot manager will be expanded. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 4 ++++ lib/efi_loader/efi_boottime.c | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index d52e399841ba..65236fa64616 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -587,6 +587,10 @@ efi_status_t efi_create_handle(efi_handle_t *handle); void efi_delete_handle(efi_handle_t obj); /* Call this to validate a handle and find the EFI object for it */ struct efi_object *efi_search_obj(const efi_handle_t handle); +/* Locate device_path handle */ +efi_status_t EFIAPI efi_locate_device_path(const efi_guid_t *protocol, + struct efi_device_path **device_path, + efi_handle_t *device); /* Load image */ efi_status_t EFIAPI efi_load_image(bool boot_policy, efi_handle_t parent_image, diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 1823990d9bd5..d5b764e1a1e1 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1796,10 +1796,9 @@ failure: * * Return: status code */ -static efi_status_t EFIAPI efi_locate_device_path( - const efi_guid_t *protocol, - struct efi_device_path **device_path, - efi_handle_t *device) +efi_status_t EFIAPI efi_locate_device_path(const efi_guid_t *protocol, + struct efi_device_path **device_path, + efi_handle_t *device) { struct efi_device_path *dp; size_t i; From patchwork Tue Nov 9 01:32:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 518030 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1052896iml; Mon, 8 Nov 2021 17:33:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJziuvZiZPoydpDC+2HVei4qVwVAW6kKc5mOsde5sgzSz/I0gwIIQDFSdJe6gV0H7vQgj24D X-Received: by 2002:a17:907:9723:: with SMTP id jg35mr4911747ejc.329.1636421625405; Mon, 08 Nov 2021 17:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636421625; cv=none; d=google.com; s=arc-20160816; b=LbBshKdbVY48/UO/C2PCAjf8bc7X2gG+p6tuxp2hcSB9rbnt7/5UJyBMb6mA1Zi8d2 mkBZQ/RMCxXdjZzF5sJFB3Pe1/VqH2Wcc/IN1cMf7Cq4EQjqYILJOy9fjBkHqIDeiF41 N9p7upHeejYsxK+81dsfVVu216w/SwpPZ9jTBCu4EhpYi0DRTGpYOPy/FcRIaH1TUwqL ik144epkO78qX6dWGJ0EvRADmxXyzBM3aGXGOo0vYropQIigWbNLkofY7fJBgZjxlH2h z9pWhVbfhEJ2SPUZxJlF4KgRXd9HiK3SGJ4zXlE5wTqyBS9RsGRl3+ImekDkuMCna8eA 3o5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F9DOx3uElvZGGYKZ1NnUJKaxOFOmNphkke/IFoVulBE=; b=YJBOsSeNuGWpIHvMZ40E4OHKJrNJrY9DDdFGWAX3jIhdsTwqOmD1WigjCDmA1AB9Bo EVAITXmzKfoFaY7e9ePvxDsw/mSlH17DaDdIMlYaZXbIR08kM+SOrxj11O2K8MK74779 tBRMW2cGYglW8tbI0Y0PzhPzKYDcK3D9YUL8PmFI1OXAyegexetophoj16VU2cPocTeQ 7go95/iVrfBwBX+BJG+tCeBhxpO36K0kWrSZmxu1p/R30CIqZpDSaNwoZq761FqQYaSy qPDDizege0nhBpCfqiv0/fRyrdF+uxwhZUKyvtRhj8DuDpnbVYyZYWSpo6ZR/eaUQR9/ dN5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S+ZvW0Oo; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id w14si37685682edd.141.2021.11.08.17.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:45 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S+ZvW0Oo; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 48B01838F6; Tue, 9 Nov 2021 02:33:44 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="S+ZvW0Oo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67393838EE; Tue, 9 Nov 2021 02:33:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 88A89838E9 for ; Tue, 9 Nov 2021 02:33:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x636.google.com with SMTP id k4so17911869plx.8 for ; Mon, 08 Nov 2021 17:33:25 -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=F9DOx3uElvZGGYKZ1NnUJKaxOFOmNphkke/IFoVulBE=; b=S+ZvW0OoG6/NuzxD28SE+zNopOI4vAaAp9sD4tAmuwMweejTsaw5puSmfHMAZ4a1bq L+/aDv3XOGRKbzUZYos3Xavz4Sf1dv6hgKqEdbK+af1FHOwXUJDq0FVXTpd8ZyysKvGO Yq9QzzyZVCYfkUwKYUDev88nk9cLWOkk19gcxM0tB+IIGZs1QkdU0YteW1rhBubPbEHi vF+kBGTnFaEm5BtjRkrRtNB7w75e9w4YhhVxT2v7QaEXnM6QesNLXVbWBTrS+k9BRnGP x9Jn72CsEsX4Wre4GWEBvwmczMsWSNBzrOkj+xYsUo9rw0b3etnURdeB73+2rueGfQfc QeiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F9DOx3uElvZGGYKZ1NnUJKaxOFOmNphkke/IFoVulBE=; b=OYZV5GNel1CiW6rFrF3P0lvxyawOzyaynm7na8mhjwAKGOtlR7sZwolpOEaUanyuvE XO2bzDUYawTTyw9KNKRIBta91jBo6UwJmeIwvBNISRSeFsPgT4vdPsmrgMoY5s3vre7s ifFOLoAPr+imIppJGGtbZpKKR3wmJJnl3k2VchleqYcexNJSMTITLPpm9isSlgsI5BE6 WS8QuPq/mvU7O2+W/ApX7IjBQQwIC4uWb5r9G8uQYoV2plwi+kBLYEhhb3hM3FFHxMEz 5C8YRJPxSktWj7da7rbBriL6UqVPZMzMkp0jPpGos+XT+4gPBFITxHXzfJAS/erkhRkY GDyg== X-Gm-Message-State: AOAM531vyeYKXqlrALeEVM6H+n71xYwWog4q4BYxmWMdDQ4BqPZY2Cvb x4JkxVjWMdnO8I7FJVME5W8joQ== X-Received: by 2002:a17:902:694b:b0:143:722f:91c1 with SMTP id k11-20020a170902694b00b00143722f91c1mr41351plt.68.1636421603885; Mon, 08 Nov 2021 17:33:23 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:e857:cfcb:a6ed:9a8]) by smtp.gmail.com with ESMTPSA id v10sm4946589pfg.162.2021.11.08.17.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:23 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Cc: sjg@chromium.org, ilias.apalodimas@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 2/3] efi_loader: bootmgr: add booting from removable media Date: Tue, 9 Nov 2021 10:32:32 +0900 Message-Id: <20211109013233.72902-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211109013233.72902-1-takahiro.akashi@linaro.org> References: <20211109013233.72902-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Under the current implementation, booting from removal media using a architecture-specific default image name, say BOOTAA64.EFI, is supported only in distro_bootcmd script. See the commit 74522c898b35 ("efi_loader: Add distro boot script for removable media"). This is, however, half-baked implementation because 1) UEFI specification requires this feature to be implemented as part of Boot Manager's responsibility: 3 - Boot Manager 3.5.1 Boot via the Simple File Protocol When booting via the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, the FilePath will start with a device path that points to the device that implements the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL or the EFI_BLOCK_IO_PROTOCOL. The next part of the FilePath may point to the file name, including subdirectories, which contain the bootable image. If the file name is a null device path, the file name must be generated from the rules defined below. ... 3.5.1.1 Removable Media Boot Behavior To generate a file name when none is present in the FilePath, the firmware must append a default file name in the form \EFI\BOOT\BOOT{machine type short-name}.EFI ... 2) So (1) entails the hehavior that the user's preference of boot media order should be determined by Boot#### and BootOrder variables. With this patch, the semantics mentioned above is fully implemented. For example, if you want to boot the system from USB and SCSI in this order, * define Boot0001 which contains only a device path to the USB device (without any file path/name) * define Boot0002 which contains only a device path to the SCSI device, and * set BootOrder to Boot0001:Boot0002 Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_bootmgr.c | 65 +++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 1fe19237f9a6..1d9d5858561f 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -30,6 +30,66 @@ static const struct efi_runtime_services *rs; * should do normal or recovery boot. */ +#if defined(CONFIG_ARM64) +#define BOOTEFI_NAME "bootaa64.efi" +#elif defined(CONFIG_ARM) +#define BOOTEFI_NAME "bootarm.efi" +#elif defined(CONFIG_X86_RUN_32BIT) +#define BOOTEFI_NAME "bootia32.efi" +#elif defined(CONFIG_X86_RUN_64BIT) +#define BOOTEFI_NAME "bootx64.efi" +#elif defined(CONFIG_ARCH_RV32I) +#define BOOTEFI_NAME "bootriscv32.efi" +#elif defined(CONFIG_ARCH_RV64I) +#define BOOTEFI_NAME "bootriscv64.efi" +#else +#define BOOTEFI_NAME "dummy.efi" +#endif + +/** + * expand_media_path() - expand a device path for default file name + * @device_path: device path to check against + * + * If @device_path is a media or disk partition which houses a file + * system, this function returns a full device path which contains + * an architecture-specific default file name for removable media. + * + * Return: a newly allocated device path + */ +static +struct efi_device_path *expand_media_path(struct efi_device_path *device_path) +{ + struct efi_device_path *dp, *full_path; + efi_handle_t handle; + efi_status_t ret; + + if (!device_path) + return NULL; + + /* + * If device_path is a (removable) media or partition which provides + * simple file system protocol, append a default file name to support + * booting from removable media. + */ + dp = device_path; + ret = efi_locate_device_path(&efi_simple_file_system_protocol_guid, + &dp, &handle); + if (ret == EFI_SUCCESS) { + if (dp->type == DEVICE_PATH_TYPE_END) { + dp = efi_dp_from_file(NULL, 0, + "/efi/boot/" BOOTEFI_NAME); + full_path = efi_dp_append(device_path, dp); + } else { + full_path = efi_dp_dup(device_path); + } + efi_free_pool(dp); + } else { + full_path = efi_dp_dup(device_path); + } + + return full_path; +} + /** * try_load_entry() - try to load image for boot option * @@ -68,13 +128,16 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, } if (lo.attributes & LOAD_OPTION_ACTIVE) { + struct efi_device_path *file_path; u32 attributes; log_debug("%s: trying to load \"%ls\" from %pD\n", __func__, lo.label, lo.file_path); - ret = EFI_CALL(efi_load_image(true, efi_root, lo.file_path, + file_path = expand_media_path(lo.file_path); + ret = EFI_CALL(efi_load_image(true, efi_root, file_path, NULL, 0, handle)); + efi_free_pool(file_path); if (ret != EFI_SUCCESS) { log_warning("Loading %ls '%ls' failed\n", varname, lo.label); From patchwork Tue Nov 9 01:32:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 518031 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1053025iml; Mon, 8 Nov 2021 17:33:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwplpwJnG+b7OlyQRqrZ0t2zsjC0CQrnorZOBvDwF4N6cBYZrslUJo33fBzCyxFsU9Sh3y2 X-Received: by 2002:a17:906:4fc5:: with SMTP id i5mr4729905ejw.475.1636421635757; Mon, 08 Nov 2021 17:33:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636421635; cv=none; d=google.com; s=arc-20160816; b=tJjZK3DYSn1yemXrpTtzPWoWsuhuT5KsvMdi1rxJA6cMil7x1UWlsDrJ0R9YJ1M5WY ++/qOaywSYmT1eZCgtAP09cTtOCYZ80/Po/Eg8WOkAp4N9TtxMTMIDOAFOPkH7tu6NlC byo+gYN0i0crgseQ8v8CvDggd+I8XaJZYl+I5WE9a+wjADKn88wcGFJy5D92Y0bCOBih 7m7wHKrCMQ0Nm+DlKTTevnUXcnemj/l8AcNokWBxKsG/6ytc7hsrgjAZOk3gqXUtcVIF xqKsF9k27oWAYkt8/2jdnVqIYlrxre3WB1y4oBR15TzWrIGEypyQO/z3GgvSOS7mXZUx aVhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VTV++eOpBNzq43eetG78sqEJvDdgV6wIwIKieQLUhy4=; b=HyP+Zqo1uTriun0UVCs8P2xYCvIpVnx+hiWGAo5Qqd9xVXoqLROMcYuxUBoaVkxoGB YhiQ+tfurZRzzEOi+zyCkaJ2Woyniyw4WIAbicwJ3zx8RDJY6x+zAcMbhMnADi7Lgw+C 4ECXVXHwsr4HfOsulH3aIqi15zU6PjFplTVFq2VytxpIHMP1ssNK6aGPj0hxsLm8phU7 OkRtH6WuDKqDYZafawiebsOJKK+DWZpiDZJSWQDXr8g+DpUR2p51j0Leq52Xse9YBVqO 3dr+8IUV4r0BeYdZdkzRwocEv+DjkKgwlYl+NZyn493/xZvJJTTYlwUTKyLGrJn60mp4 fBSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P8PSXjSV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id z10si16368329ejr.293.2021.11.08.17.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:55 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P8PSXjSV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6326B838FC; Tue, 9 Nov 2021 02:33:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="P8PSXjSV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8B304838E9; Tue, 9 Nov 2021 02:33:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 29CAD83883 for ; Tue, 9 Nov 2021 02:33:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pf1-x42d.google.com with SMTP id c4so6068101pfj.2 for ; Mon, 08 Nov 2021 17:33:28 -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=VTV++eOpBNzq43eetG78sqEJvDdgV6wIwIKieQLUhy4=; b=P8PSXjSVHENvVvk7lfyfVHia2/Wbs36PfV0bebRRiGDKe0/dN5dULEHyzY7xXhBIOG NSqGM5J3RVsXWLx4IA3ZS/G9wIArYouJW/ITVV30R+pKJbZc9rhqBzgoahKecbYIR1RU WAs7t90t26aJAcOomu5bBBdU4dB2YM9Ok+CLEAY6p2MJPfmapIQoa+DfFDMs/Bkl3H6y OLxrVoYWyjYAFztWIM+tI6E4YMfDYP+Q/cLzV4e1qCYdqTi7DzzqUOA06DQCQ9E3rnza yHVoumuZs2UVochhI30PCy92WcL/WyOU4Ku/NnWELjxJY3eVOnFuiRQ++yNDn94KxaPQ 8h8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VTV++eOpBNzq43eetG78sqEJvDdgV6wIwIKieQLUhy4=; b=XhK7dwgFxOCzr2VdP1uGoPfZZbqWPN4cd3WmB6gS2mge3IH5/VtMHZgO0PhYcT81Ks t+wkzXe19rofsJXyQtx+D9Wyle8mX3vZGFgbceSbl9edJU1Dw89wuoSWu8UDhrL4LTam vxJcUEyTqt2rRkzob9tfMkjTtpqyf7rKu4Ug7ATS7UTisYcp0YoeII34dvaOZK0LLGLC 6+8wfzk7y7WXNTSKXQHqtsoGwp+3GmFGXMNnT713/pr9jrKadQ1yhOvEFwgVy+KN1Ryp 7tMSacCeCAjZ+pgOm1UfA58eDzI0wHi0/MzSnfLrHHCVCHmDhtqHZ6iHxuDWC7AnHrkI o47A== X-Gm-Message-State: AOAM5311RuEmy1iAC0N5xYgActu8Y43fr4IEZ0J3oBdY1YoWxpnjCsde BYm8leaFbnA639wagrVI0WslGw== X-Received: by 2002:a63:3c4c:: with SMTP id i12mr2966711pgn.447.1636421606494; Mon, 08 Nov 2021 17:33:26 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:e857:cfcb:a6ed:9a8]) by smtp.gmail.com with ESMTPSA id v10sm4946589pfg.162.2021.11.08.17.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 17:33:26 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Cc: sjg@chromium.org, ilias.apalodimas@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 3/3] cmd: efidebug: handle booting from removable media Date: Tue, 9 Nov 2021 10:32:33 +0900 Message-Id: <20211109013233.72902-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211109013233.72902-1-takahiro.akashi@linaro.org> References: <20211109013233.72902-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Support for booting from removable media is now added to UEFI boot manager. Here we should modify efidebug command in order to define a proper "BootXXXX" variable. With this patch applied, you will be able to specify the boot order, usb and scsi: => efidebug -b 1 SCSI scsi 0:1 => efidebug boot dump Boot0001: attributes: A-- (0x00000001) label: SCSI file_path: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/Scsi(0,0)/ HD(1,GPT,0ed48d12-1b4c-4e08-b3ee-decf20428036,0x800,0xa000) data: 00000000: 00 00 => efideubg -b 2 USB usb 0:1 => efidebug boot order 2 1 => bootefi bootmgr Signed-off-by: AKASHI Takahiro --- cmd/efidebug.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index a977ca9c72f5..aaf269cdf47d 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -933,6 +933,29 @@ out: return initrd_dp; } +/** + * count_arguments - count the number of arguments + * @argc: Total number of arguments + * @argv: Argument array + * Return: Number of arguments + * + * Count the number of arguments for a given option, "-?" + * Specifically if the first argument is not "-?", return 0; + */ +static int count_arguments(int argc, char *const argv[]) +{ + int i; + + if (argv[0][0] != '-') + return 0; + + for (i = 1; i < argc; i++) + if (argv[i][0] == '-') + break; + + return i; +} + /** * do_efi_boot_add() - set UEFI load option * @@ -945,7 +968,7 @@ out: * * Implement efidebug "boot add" sub-command. Create or change UEFI load option. * - * efidebug boot add -b