From patchwork Wed Dec 30 15:07:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355271 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11403080jai; Wed, 30 Dec 2020 07:07:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3nRVP8w9WQDn56GFVJz8g3wQe0amGNtNTcyDjQS1KhOGr65VtBORpLstJaSdaeXDxty0/ X-Received: by 2002:a50:b765:: with SMTP id g92mr50878421ede.317.1609340868025; Wed, 30 Dec 2020 07:07:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340868; cv=none; d=google.com; s=arc-20160816; b=ahcC8AMB7thvLSEOkwdPlhwwLsQBzXuMvcqTztcZovWoC+7dMXt7nIxigLko4rhFz/ OxJf02W2TLxwNjR5aM7SICCUvMHMFjpfzflwhG/Hp3dNcOHvHQcbbzAmJm8GHqWXgS5u A/oYL+tvcw0DqvZmd3WDkBXN48gF82eI9S9Rcn2DkMSE0XDe0iPWznClW9vkazd4bkHe 4744hAFjzlvVzBu86BDoQnKdHJwlZvUC5Cn5GSFa21MtCPTNinB8HVnhbAR3syhLjU+/ WUDLE7sqAa2OClEHHOl6EbFmLjcckKjFu7oda1MdlNvBolOr7AyodfGzD/Paz5YRxpBZ v0ew== 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=/M6b/q2P+MXsm3Fkct5weN+0t6afmm06p0xLR+/53uU=; b=ptgSfno7qhhJU9N/QPj6UXEWxlC5CSTY5QxjQGXPfLcbZovsxlILvSll+3j1u0hV+Y eiHs7mFv2MKbapa5lR04/DPK4ewiNFbVgriLSHpvj91d0uk+vF3TFakifW3+KVGtCJ2z Iy5sGVqyhaSW/Jr0988SnyYZvpko+HNFVgK463zPHaPVS+eTBSpYrYOHnNLIw9Cfi2Rr 3HKr+1OJwILsjnFKKSbkGDPUfYFifl/Jqwj0713a5aqAYtd5HQhkC8YyQ3ScvcKCkI6I n0v7KTblo5NFwz/pdH64UdmpzpmxsaTyZAHqqtf5sShletQibVNSLx9kjOl4WkU+eSMn ESxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rt0ICfEI; 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 g9si20344882ejj.456.2020.12.30.07.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:47 -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=rt0ICfEI; 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 56F66825F1; Wed, 30 Dec 2020 16:07:40 +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="rt0ICfEI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DE5A82573; Wed, 30 Dec 2020 16:07:31 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 D7CBA82540 for ; Wed, 30 Dec 2020 16:07: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=ilias.apalodimas@linaro.org Received: by mail-wm1-x32f.google.com with SMTP id q75so4958184wme.2 for ; Wed, 30 Dec 2020 07:07: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=/M6b/q2P+MXsm3Fkct5weN+0t6afmm06p0xLR+/53uU=; b=rt0ICfEITin7Kf3CJ4aRmSL8wGaAfIb69rHGoMjcbdg8o59E0tItvTR5cTIiET/zWe UBP1MumHB765RBol838YDW73I/Qyj5Xc07sadXEmLWLY7wpAPU9tIfuqGXGmpN3ZIC4G hwAfNkfg1zG+xqFWh5Qxdp6iQPvaAuRITPXGxm/nqwCFmIZc2WbQF9bEcg37GP047qKT dnNVZGDuv8cXYWGd6toOfKasDg0qMHTAcMa74NQxlzbeewbNCNutqO6suzafYTtLxW5Q A2tRNkk0GqfoTOgZqx10ld8feYHjLmEkTAdskWa6YcKta7+cfp8VX7mqct+mJjbFFd3B MDOQ== 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=/M6b/q2P+MXsm3Fkct5weN+0t6afmm06p0xLR+/53uU=; b=Z8mSm8dY9R2mmIMR/sr2Ets1KbHm+qBqcrQB3eN3unyHHYjZeD7rXI5+D5QltynM9H X/6kloZSDEGEyYLdOEgJ7SPMz+LKJ+YOIVNhMM4P90m9ZgTnept2obQCZJdOAtaSgqmr Ixiac81yK765Dd8moebfwhj7pvXkCaJ1In7GBFT0mazaZtxoLWqsy61IAIeoxbI1BqNQ RmwWjVUB3pvU5K/fOnjIn+zlD2Qdc9w0kIL4Om8z5hmxXxLTkzgGaWxnLgJZ8dYkvUcG pflqE+juhCuMEOz8C+Frj5Yav7SnyRTdXJ1MPgn8pdq3F9BDUz4fzhglSxEPf5u63R+O oA4Q== X-Gm-Message-State: AOAM531dn5Qmz3E55y6DdhFw2JvNyUhEUTKdh8scft5L+5CFvIoTTBl/ yMpWmxh9medxYRt7ITWL8C+BdA== X-Received: by 2002:a1c:5410:: with SMTP id i16mr8138541wmb.30.1609340848534; Wed, 30 Dec 2020 07:07:28 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:28 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 1/8 v2] efi_loader: Remove unused headers from efi_load_initrd.c Date: Wed, 30 Dec 2020 17:07:13 +0200 Message-Id: <20201230150722.154663-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean dm.h and env.h serve no purpose here. Remove them and sort the remaining in alphabetical order. Signed-off-by: Ilias Apalodimas Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_load_initrd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 2.30.0 diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index d517d686c330..4ec55d70979d 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -4,13 +4,11 @@ */ #include -#include -#include -#include -#include -#include #include #include +#include +#include +#include static const efi_guid_t efi_guid_load_file2_protocol = EFI_LOAD_FILE2_PROTOCOL_GUID; From patchwork Wed Dec 30 15:07:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355272 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11403249jai; Wed, 30 Dec 2020 07:07:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlSFwDWgF9C2JO1E36Q8ABQAE8Zl8GV/yi0u2gN6PetdDkg8hDqpsF2HaSBD3tp+Sbf6DF X-Received: by 2002:a05:6402:40e:: with SMTP id q14mr50822109edv.85.1609340879385; Wed, 30 Dec 2020 07:07:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340879; cv=none; d=google.com; s=arc-20160816; b=iV2BPesHscwLBFLXrDhWUWo1cKtDK5Ke/xlVBGICXtWC61gHX+HwfYA/q0GQeZhEEy m+riGt3UuCO1HtR21NJ8Pw9eB3nZYMgX706anda6fr2ggCAsje0smiXfCg+kLRPblAlp EKzmIjfljH9fSfR3YwDeoA0IFKxWSey/goTgcMe+nXZZCsrfYDxGRAjB9ZrJhy7nnISp /0ZVqyD/VGnN7ViUkj0Abhh/qaF25pCes1jfAt/+sGob+1Dno7OJdmjAOkxKTZ711UpM /PPwMJ2minivdqR5UKQvuwFfZz4JSEJyntxpoij7gEwdL9woUZES4N+fXtyO3CDs7lw9 ijzQ== 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=o8CxNN6z9S6qCMV4F25SQ5mR/YH8CYxBTHwuJKsM48E=; b=GRH8ikTcHhs5Qb/t0BiB9QY+LVZT4bDAK+ha/sZEvlbXaEPpikHE75YNIyDiJvmhnj cU8W/JQZ0OiellfptAef5DXXgylPOYm+nPC9ghsx/oiKELvQ64IPKMkT+6bRheni4dpk 7BCVobceZTAiqhlrFIpw/hz2SPupxUVYixtdwmTsnTmppmTGZdSlM4QvRYFKaANuRQDq L8J970mJS63N+cocOZ+Expz87KF07r76rEur7LFfb4ZhFY3O2CGE6j7RAh7aEhNsSpy2 6W37usOWxKBagS07NUo/KuIVZ27MoaYXFpfoH4ct5N7JQafnwhI3Q4Gt8+ZvT+f+56QY Csdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X4qUw21S; 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 ak15si21549042ejc.654.2020.12.30.07.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:59 -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=X4qUw21S; 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 1B45E8260A; Wed, 30 Dec 2020 16:07:43 +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="X4qUw21S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 66564825DC; Wed, 30 Dec 2020 16:07: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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (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 ECBD08257D for ; Wed, 30 Dec 2020 16:07:31 +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=ilias.apalodimas@linaro.org Received: by mail-wr1-x434.google.com with SMTP id c5so17674466wrp.6 for ; Wed, 30 Dec 2020 07:07:31 -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=o8CxNN6z9S6qCMV4F25SQ5mR/YH8CYxBTHwuJKsM48E=; b=X4qUw21SGcak3axj5xz4ZDj2PMbMJfQWJJhB/1nEy3OQGUH9mAEEemyLvx9YGQ2an4 t/h3wLrU6eNY5gSwwypTWUQfDBikG/GobI0L92BgYypkIwjGdSM1uUDEkaEWGsKvUs2W dNcmP3k15sZuuJQAYFhwkO300VQa9HmGix1ZDGPe9yCEZc1Udw5Y0w0Le27rSeTxxk4S 2+Ck22FHW0HPSf+kXLIos91/VdQohwmSLk17ASzNXpRmTQvAzuwMAI4fUIwHZcv+2dzF FAcbXlW+0+fC49jIeNXn+HevYE+s7QtDLSxkduJ9a5oJB8QiwOoawccI2I8154Kr0xu7 6D/g== 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=o8CxNN6z9S6qCMV4F25SQ5mR/YH8CYxBTHwuJKsM48E=; b=kJQMdrplMbZE776aHNnDdniCDm3gkclHl8QEgrKEfzHMuqb/bT5/rlzj1SCW0OCKPl k5b6R4+JKP/FyQ3E/TRR/RnCHuFSnspeICAuX7WwXr9PNEXz8p0nXUz1gKGN8vPYv4tp XHopGXfT+9BRXCWhXoLi+/hygeHm14P1uzrlx/5ahRV7RslU/m5uamkYXWZ1gvSA7roi WONZOCas+NwQQ3nHkg917Gq27r3hyXaV+MgyTAR2dhbpTfqH1Su8nYi0yrQUDm2jSTpr 17y342xEfs2DqBL9bvsiKAlSUYBt1ZtrQOJwsz3mVrPgAHa5hkZ7Pc4L9pECprtIUyRr unAQ== X-Gm-Message-State: AOAM530OvLpCKPoQcqrFznkt1WsARGQxyaCZUU4bs21qAFgsZqcYQLO3 /8Y22u0vTlmkHPP1juBuu90UTUEg7UgA06Ut X-Received: by 2002:adf:a1d5:: with SMTP id v21mr60707607wrv.24.1609340851567; Wed, 30 Dec 2020 07:07:31 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:31 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 2/8 v2] efi_loader: Remove unconditional installation of file2 protocol for initrd Date: Wed, 30 Dec 2020 17:07:14 +0200 Message-Id: <20201230150722.154663-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean Up to now we install the EFI_LOAD_FILE2_PROTOCOL to load an initrd unconditionally. Although we correctly return various EFI exit codes depending on the file status (i.e EFI_NO_MEDIA, EFI_NOT_FOUND etc), the kernel loader only falls back to the cmdline interpreted initrd if the protocol is not installed. This creates a problem for EFI installers, since they won't be able to load their own initrd and start the installation. A following patch introduces a different logic where we search for an initrd path defined in an EFI variable named 'Initrd####'. If the bootmgr is used to launch the EFI payload, we'll will try to match the BootCurrent value and find the corresponding initrd (i.e Boot0000 -> Initrd0000 etc). If the file is found, we'll install the required protocol which the kernel's efi-stub can use and load our initrd. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_setup.c | 5 ----- 1 file changed, 5 deletions(-) -- 2.30.0 Reviewed-by: Heinrich Schuchardt diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index e206b60bb82c..d7f880921268 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -209,11 +209,6 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; #endif -#ifdef CONFIG_EFI_LOAD_FILE2_INITRD - ret = efi_initrd_register(); - if (ret != EFI_SUCCESS) - goto out; -#endif #ifdef CONFIG_NET ret = efi_net_register(); if (ret != EFI_SUCCESS) From patchwork Wed Dec 30 15:07:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355273 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11403482jai; Wed, 30 Dec 2020 07:08:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/YTwHBrPuImkWmWk3YQKojZ1lrlWsJdZpKLKoc52Johm5yT8NqwlZoikSHfdTX11IH4Qf X-Received: by 2002:aa7:c1c6:: with SMTP id d6mr50996526edp.275.1609340893912; Wed, 30 Dec 2020 07:08:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340893; cv=none; d=google.com; s=arc-20160816; b=z6UxFwILycp8DbYyL+PWngzO9zuczG57DjHbBCsZ/CazyqbNNRdykScPPxHmbDrm4P 0cNTVAp0EMPNHb9tIPaD88w0ehi0M4qCMu3JXmeay2GBsFonNWDpXEtRANiSZ3DrP3yg lubWfddXWdplRtq9jYERImHEyYWKsJNqwp8AFBsuQQzs9S/xnqo2BpA+oxEEDWEUQ4K2 PSPjiAsDo4DoUdRWeTaphldSOh51CDhN+/3ywAxRhTmpAaSk/8HxWAxlSDhbvmoUwJfp PY3nsX9jwphVaQ7wivClHmRiP4spiegcHgt0dv2DDPVYt927W4ICxWvhbrEpNupBUXHt Ym3g== 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=wHXIKZTfXfsCHLDMg+j1KPalqqVckKw12E3GnWEqAWU=; b=cnX1xBlVssijTCzte/3DYgC5Y3S8jK/qEfAeLIecWHouZsiyuyQ1Dhxkv1mv0Rr6tt X3uRfYx67SjNB2VnNHxxIKMIhgNEuySHHV5GJHeKbayj23fuPDdkdOrVWUemN3S0xYQL frbaDherdEasizGlJ7EaAs3egBhQT4J3pUP/5eMKlpBULo1F3qvlY/cqXOEW1mkufwwx /Y1/nv+PPFnW0z3Ttpt1bw41Mcc0BjshHTf42fqsEGSDXrw2+8PnnYVM9yWtHturp3y9 e8x8DLTJtJi9bcBZ6DoJJmNRFUte/d+T3uBqqBjxs707mIBDA2DIQVirmt5m7a1klOmB WHzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jmwf91Tz; 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 y10si21957575ejw.156.2020.12.30.07.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:08:13 -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=Jmwf91Tz; 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 B5BF882627; Wed, 30 Dec 2020 16:07:46 +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="Jmwf91Tz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 818DC825DC; Wed, 30 Dec 2020 16:07:38 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (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 F035D825BF for ; Wed, 30 Dec 2020 16:07:34 +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=ilias.apalodimas@linaro.org Received: by mail-wr1-x432.google.com with SMTP id w5so17658736wrm.11 for ; Wed, 30 Dec 2020 07:07:34 -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=wHXIKZTfXfsCHLDMg+j1KPalqqVckKw12E3GnWEqAWU=; b=Jmwf91TzCWUF5xFVg/MjPmtFGtNzCgSIq5j8rVbeKCRjde/Ry0FEZnY8U+5Z/aLppM VqD16GCcARO6Eh96Sw0HmTHnNqrJ4HH+lGPbALjV+QO3yktQNNqZBhPmI7hGuvSKjZ1w I+rb+ztyTS5sB6R+TbgLQ5kaZSgwK1aG27WlVusdtE1Et0tI0Z2GpyxZWhalYosGNIg2 9DC5BH6s3o9OY431gw5ox6CMDDSOY5QiI3+SbJPkIvQg31RgyQvLQFaXQTNqBloWw8pw Y3omouWd6PTMX96Mz2Mxj4jlRMTLLgb855hpuVduBs1X+5bUey+W4o3Cj+ILJMjSnmX/ bcgw== 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=wHXIKZTfXfsCHLDMg+j1KPalqqVckKw12E3GnWEqAWU=; b=i7GVuScUpJOPL8wN7LPsWumuPxggS679U2p0HeWCrdPvH3g8BaOKL+wcaw2KigLewI FbUO3fRC6JdVkh4bbsnX/gZaipfgLlFtoWDATwRaUZu8t3n4lOqgtaLim8b9Plla5ORY jLnDddVraDnzu9KFTQbzT7OLDOQ4u4+rKXotCe2mWs34HH/jpGT75eSo4+FlCe5P5oSL XNtpfBpjTNF7s+Uj891D2BD2ZFKK1rz2QptC6EayHqjTVu9jvt8Ke0h5Nbdt9cCz8VvS mk5mMH1g5F6ft4UGaoph8ZQvxxpBz5w6zsUZFl03wgnjXN+5QbPQ1av8lH0Z4OnMi0ks C+YQ== X-Gm-Message-State: AOAM5310DgfC58npIW+WbOyY39fSruyYBeo1pivVw1pCJOxWjFI00E0T R14d5Ct7/9jtyE8cPis88TbiDw== X-Received: by 2002:a5d:6a83:: with SMTP id s3mr62260584wru.334.1609340854587; Wed, 30 Dec 2020 07:07:34 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:34 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 3/8 v2] efi_loader: Add size checks to efi_create_indexed_name() Date: Wed, 30 Dec 2020 17:07:15 +0200 Message-Id: <20201230150722.154663-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean Although the function description states the caller must provide a sufficient buffer, it's better to have in function checks and ensure the destination buffer can hold the intended variable name. So let's add an extra argument with the buffer size and check that before copying. Signed-off-by: Ilias Apalodimas --- include/efi_loader.h | 3 ++- lib/efi_loader/efi_string.c | 10 ++++++++-- test/unicode_ut.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) -- 2.30.0 diff --git a/include/efi_loader.h b/include/efi_loader.h index 3c68b85b68e9..af30dbafab77 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -810,7 +810,8 @@ bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp, void efi_memcpy_runtime(void *dest, const void *src, size_t n); /* commonly used helper function */ -u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int index); +u16 *efi_create_indexed_name(u16 *buffer, size_t buffer_size, const char *name, + unsigned int index); #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ diff --git a/lib/efi_loader/efi_string.c b/lib/efi_loader/efi_string.c index 3de721f06c7f..962724228866 100644 --- a/lib/efi_loader/efi_string.c +++ b/lib/efi_loader/efi_string.c @@ -23,13 +23,19 @@ * Return: A pointer to the next position after the created string * in @buffer, or NULL otherwise */ -u16 *efi_create_indexed_name(u16 *buffer, const char *name, unsigned int index) +u16 *efi_create_indexed_name(u16 *buffer, size_t buffer_size, const char *name, + unsigned int index) { u16 *p = buffer; char index_buf[5]; + size_t size; + size = (utf8_utf16_strlen(name) * sizeof(u16) + + sizeof(index_buf) * sizeof(u16)); + if (buffer_size < size) + return NULL; utf8_utf16_strcpy(&p, name); - sprintf(index_buf, "%04X", index); + snprintf(index_buf, sizeof(index_buf), "%04X", index); utf8_utf16_strcpy(&p, index_buf); return p; diff --git a/test/unicode_ut.c b/test/unicode_ut.c index 33fc8b0ee1e2..6130ef0b5497 100644 --- a/test/unicode_ut.c +++ b/test/unicode_ut.c @@ -603,7 +603,7 @@ static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts) u16 *pos; memset(buf, 0xeb, sizeof(buf)); - pos = efi_create_indexed_name(buf, "Capsule", 0x0af9); + pos = efi_create_indexed_name(buf, sizeof(buf), "Capsule", 0x0af9); ut_asserteq_mem(expected, buf, sizeof(expected)); ut_asserteq(pos - buf, u16_strnlen(buf, SIZE_MAX)); From patchwork Wed Dec 30 15:07:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355274 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11403674jai; Wed, 30 Dec 2020 07:08:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzxJNt03hqOXKGYMQLv3LlmsnjaxtK86OLvrgdsnXYNYWQQVPhZMFYuYx/1sv6/iVtFV/1 X-Received: by 2002:aa7:cb16:: with SMTP id s22mr52388400edt.53.1609340906029; Wed, 30 Dec 2020 07:08:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340906; cv=none; d=google.com; s=arc-20160816; b=AaH1Q0ddOJCB5UILDIHCNatoVYpNtu9wDh96P7B/nVUbHNim8fHWjDsqc5NJApX4n5 EiYIPFMDmdSvLSh93jidytDG57OuszTdEtZYJmpUygH2A6ICMVr1PgGVCybmnMk2geL2 x+6hSO3E1DeL9HxSq+1FcKmDq26pu1VzpA+ZpFmvEpnowU4fIOkTElIzDqQ9EyTO67ne nriJprUDv9bzGxn1UQ4ErZA3G1SbyuaCRgHcL4DdplHHT/qulsO2787W6mn0M7H1+i02 3s00DpPAP/D8HB6D7sXWS29OVoP6208Gm1eqDGHbRiP+i/1Jv5Lyw3ARPgyXXNLkFUs5 aGxA== 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=I0jzps4L2oZBIthJ7ddQ0geOL1wWUE/nbLZWhXu6c7c=; b=DWzG0IVsjpS8n/nL4Ut7NQWy7lpsQw8wd2mn8wWUZjyf/kjgZQ0IlNgn8wUHktERX/ jp56oC/V6NVkWXRrkj5zFRpiz3Jbkk09Z9XL3HDCsylAYBCGdMF+tv6j6T2keUG6Oh5V o7x6ogWxcGfe6TjxYpBrigR0S3zmUCfCe0VDiS1R8p4C/4Xa+7EU4QhitPjjgh9S9479 2fHRJH67Haic5oIsr9VI0P3gbIkt3CKQdgxM8q31oB6xs7ZQnNbwnPBTvMRZ2wmQWXQY QTMS6w7wqlaFmJ8BCGvAshbVbp6yRvHbqjat7xa9CcLQykUXFYwAMXXB27YvAgHCGd2Q hi5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lJEwYNNW; 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 v1si23328003edf.22.2020.12.30.07.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:08:26 -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=lJEwYNNW; 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 ACCE482607; Wed, 30 Dec 2020 16:07:58 +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="lJEwYNNW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C6D568260A; Wed, 30 Dec 2020 16:07:41 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (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 0850C825AE for ; Wed, 30 Dec 2020 16:07:38 +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=ilias.apalodimas@linaro.org Received: by mail-wr1-x436.google.com with SMTP id d13so17649715wrc.13 for ; Wed, 30 Dec 2020 07:07:37 -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=I0jzps4L2oZBIthJ7ddQ0geOL1wWUE/nbLZWhXu6c7c=; b=lJEwYNNWIK+bkZlcWAiTqp7sS1bu3XNsWT6u6Ml/D69CkPWmL+cyvrc/Qt1EHMuJTL XXKveJtcM14CWTRroW+J5LIrfkC6hCG5mupEpTY00nc7MoqxEWSQ9WR2xT/BxdTheaRJ Y+YuYG6bw1ZD+tDDBoCcJhceX2zs0bCBWojbFdRCTJR3v6I3QlEetFTQfVTDL2R8vaqz +e+xXkCCp3LNzkQZzmDhuam0pZLWo0B4TJy8cdQaUNOg+VSwCo8MZ6Cat2f+zjxsb0i/ kFlfKx3eH0LQwt2/UIBaxvpkCZmG3252arZ16MC7x0LmuDXdOkhd/Ohw8fQv5hkUufuz 82OQ== 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=I0jzps4L2oZBIthJ7ddQ0geOL1wWUE/nbLZWhXu6c7c=; b=athZFRxJHUaYmTGkNgcnevtfslYj1ZUvhTTLnXJ0XIuY+tue+YJ1/Y0wuM8ePX3nXF JOLv2MXRP+jU+PQwbfc/tZfNfCvMnNGyHDtw0NWTBACGA4ibdHPZBxCwCsG7R/BAWrYi walEE9S8Lz1ozw+rzUdAGDqB/d9JFHa7xzPsdu3e6t6DZhQ8f+txqLccFWmyPXnvp94m 1HA9wRYmCCJYd8KnmJZIvQTSx7mvFODv8uPFo+cYtkYVzkx6AxMlUQxiaUVgZ/xB31Tm w7XPQwSFEk2wolijIEF4OLgJCmezkXlSFwJxv+mws91f6iqzlak8X9ieQl21bt4kGc03 a6cw== X-Gm-Message-State: AOAM533ZSEUhzEt2Z+Q+uNLz6xZFv3wlOMne2/ukDES6VqPF1IKVwTrj 0XluOUnGxRrwm9mezQdztbuGCA== X-Received: by 2002:adf:a551:: with SMTP id j17mr60093330wrb.217.1609340857638; Wed, 30 Dec 2020 07:07:37 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:37 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 4/8 v2] efi_loader: Introduce helper functions for EFI Date: Wed, 30 Dec 2020 17:07:16 +0200 Message-Id: <20201230150722.154663-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean A following patch introduces a different logic for loading initrd's based on the EFI_LOAD_FILE2_PROTOCOL. Since similar logic can be applied in the future for other system files (i.e DTBs), let's add some helper functions which will retrieve and parse file paths stored in EFI variables. Signed-off-by: Ilias Apalodimas --- include/efi_helper.h | 28 ++++++ lib/efi_loader/efi_helper.c | 180 ++++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 include/efi_helper.h create mode 100644 lib/efi_loader/efi_helper.c -- 2.30.0 diff --git a/include/efi_helper.h b/include/efi_helper.h new file mode 100644 index 000000000000..5d3a43364619 --- /dev/null +++ b/include/efi_helper.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#if !defined _EFI_HELPER_H_ +#define _EFI_HELPER_H + +#include +#include + +/* + * @dev: device string i.e 'mmc' + * @part: partition string i.e '0:2' + * @filename: name of the file + */ +struct load_file_info { + char dev[32]; + char part[16]; + char filename[256]; +}; + +loff_t get_file_size(const struct load_file_info *file_loc, + efi_status_t *status); +efi_status_t efi_get_fp_from_var(const char *name, struct load_file_info *loc); +void *get_var_efi(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size); + +#endif diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c new file mode 100644 index 000000000000..e5919343a5cc --- /dev/null +++ b/lib/efi_loader/efi_helper.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * get_file_size() - retrieve the size of initramfs, set efi status on error + * + * @dev: device to read from, e.g. "mmc" + * @part: device partition, e.g. "0:1" + * @file: name of file + * @status: EFI exit code in case of failure + * + * Return: size of file + */ +loff_t get_file_size(const struct load_file_info *info, efi_status_t *status) +{ + loff_t sz = 0; + int ret; + + ret = fs_set_blk_dev(info->dev, info->part, FS_TYPE_ANY); + if (ret) { + *status = EFI_NO_MEDIA; + goto out; + } + + ret = fs_size(info->filename, &sz); + if (ret) { + sz = 0; + *status = EFI_NOT_FOUND; + goto out; + } + +out: + return sz; +} + +/* + * string_to_load_args() - Fill in a struct load_file_info with the file info + * parsed from an EFI variable + * + * @args: value of the EFI variable i.e "mmc 0 initrd" + * @info: struct to fill in with file specific info + * + * Return: Status code + */ +static efi_status_t string_to_load_args(char *args, struct load_file_info *info) +{ + efi_status_t status = EFI_SUCCESS; + char *p; + + /* + * expect a string with three space separated parts: + * - block device type, e.g. "mmc" + * - device and partition identifier, e.g. "0:1" + * - file path on the block device, e.g. "/boot/initrd.cpio.gz" + */ + p = strsep(&args, " "); + if (!p) { + status = EFI_NO_MEDIA; + goto out; + } + strncpy(info->dev, p, sizeof(info->dev)); + info->dev[sizeof(info->dev) - 1] = 0; + + p = strsep(&args, " "); + if (!p) { + status = EFI_NO_MEDIA; + goto out; + } + strncpy(info->part, p, sizeof(info->part)); + info->part[sizeof(info->part) - 1] = 0; + + p = strsep(&args, " "); + if (!p) { + status = EFI_NOT_FOUND; + goto out; + } + strncpy(info->filename, p, sizeof(info->filename)); + info->filename[sizeof(info->filename) - 1] = 0; + +out: + return status; +} + +/** + * get_var_efi() - read value of an EFI variable + * + * @name: variable name + * @start: vendor GUID + * @size: size of allocated buffer + * + * Return: buffer with variable data or NULL + */ +void *get_var_efi(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size) +{ + efi_status_t ret; + void *buf = NULL; + + *size = 0; + ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + buf = malloc(*size); + ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); + } + + if (ret != EFI_SUCCESS) { + free(buf); + *size = 0; + return NULL; + } + + return buf; +} + +/** + * efi_get_fp_from_var() - Retrieve a file path from an EFI variable + * + * @name: variable name + * @info: struct to fill in with file specific info + */ +efi_status_t efi_get_fp_from_var(const char *name, struct load_file_info *info) +{ + efi_uintn_t boot_cur_size; + void *var_value = NULL; + efi_uintn_t size; + efi_status_t ret; + u16 boot_cur; + u16 var_name[16]; + u16 *pos; + + memset(info, 0, sizeof(*info)); + + boot_cur_size = sizeof(boot_cur); + ret = efi_get_variable_int(L"BootCurrent", + &efi_global_variable_guid, NULL, + &boot_cur_size, &boot_cur, NULL); + if (ret != EFI_SUCCESS) + goto out; + + pos = efi_create_indexed_name(var_name, sizeof(var_name), name, + boot_cur); + if (!pos) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + var_value = get_var_efi(var_name, &efi_global_variable_guid, &size); + if (!var_value) { + ret = EFI_NOT_FOUND; + goto out; + } + + ret = string_to_load_args(var_value, info); + if (ret != EFI_SUCCESS) + goto out; + + if (fs_set_blk_dev(info->dev, info->part, FS_TYPE_ANY)) { + ret = EFI_NO_MEDIA; + goto out; + } + + if (!fs_exists(info->filename)) { + ret = EFI_NOT_FOUND; + goto out; + } + +out: + free(var_value); + return ret; +} From patchwork Wed Dec 30 15:07:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355275 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11403875jai; Wed, 30 Dec 2020 07:08:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCTrUtUveVsogrn3kVkWit3uy3RxTWjp4fBGoiFFFL0pfyOhfAjmFdGB7a8cDqFgZk7Rs9 X-Received: by 2002:a17:907:20cc:: with SMTP id qq12mr52175706ejb.316.1609340918969; Wed, 30 Dec 2020 07:08:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340918; cv=none; d=google.com; s=arc-20160816; b=ODRGzRKbwq8bAYZnONX245uQTgNPqZO4Fb9xmMu6zQaI7S5QFyd7TcZjrD8U2W59NO M5Q5j/z+rSZ1kf6+DMXfIz7Y34+lX6BHGbqgYJaqh0oUC4IAXOQr0iwqwLO99bclbNLC muLDVFzv4EM+ZObvz8UsxZAAko25kEBH7XZeEfsRx4nsZ3kd3G+UHI8z6GaG7uojj67/ FLHdETuovQAQu3GwSDs/HuV5isyEc0xJNkxUTcwenpFZkBqdaEZxxn27Gj86JZ5BxUZV IARoXMsO9pTKDDBbFb10YO/RTSIJviYQD7w0EBj4DCl3gCcLrJSBR/voQfyNe1HoAO6q pwJQ== 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=XbvGNj9JiPMOw6hIAfTTsU/7r+RZQTIgZIIQru7dizA=; b=x0o5P306hNhZQsLl86u77+tSpO7CL23Y5WtxbA3OSCQ5SmRZAi+6HZfMx03I9vJdK+ SdgDWWmTaJYMHbYTm6GH2/83PVmgctR5bSmqkFj+0V0tfKqlQYjx4pcdkJ3f9pcJ5y0m TlAL68HRlJ5uTvDOoQrC7v34srAYX64Jh+Wz4FeJu7HNqpD+JkNhZaxlpqMnHzrbsopX Eoc1cjfsTttkkyFcR0cKzDuF7YU+41BTqD1b8qcFxLBsaL7unsGMgPgMcchzeBG0SXtn RwObiGTNiXy0/QgUjqa46crfE0HbGfWfFdCXOVocaoj1ffwfGw6Th2mX4onswPBWKIpm 0EYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xKZakAaR; 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 30si24001144edv.385.2020.12.30.07.08.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:08:38 -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=xKZakAaR; 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 65EA98263F; Wed, 30 Dec 2020 16:08:04 +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="xKZakAaR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 38CB882625; Wed, 30 Dec 2020 16:07:47 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 06CE182608 for ; Wed, 30 Dec 2020 16:07:41 +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=ilias.apalodimas@linaro.org Received: by mail-wm1-x32a.google.com with SMTP id e25so4965517wme.0 for ; Wed, 30 Dec 2020 07:07:41 -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=XbvGNj9JiPMOw6hIAfTTsU/7r+RZQTIgZIIQru7dizA=; b=xKZakAaRgD/julKobcTaFDSk6sMx8dAFOSQDv/B/yowtTVeecAeJ/4Nyeu2saIA3Zb AsLQjUrB6q9LiB7ZRzVJsqfOQnaMW6N3YR4vlGfPHTmCyGivok6CIEZ9gLXa5jWFT46S KdexshYM8u+fC5z5KhedRI48BfkEgjAzTgiunvAAFTW0ZECdPzI4YYDpBx10Wg9pmLmO Qm3m8Gc/ymkldb40ICFT5PKwz73cjK4pmsFEMiYxBm9G7cCNbhhagjEY/WTDXIv89lxg FMLoayqWoIVfReY4uJA9v8YBnKO7UT9LPjXSrvRc4KIzJNbFI388srXKPwOL0465SgKd IYWQ== 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=XbvGNj9JiPMOw6hIAfTTsU/7r+RZQTIgZIIQru7dizA=; b=FuEcSZum6g5boZrLSeK6cWdPv2PXDIvfdICnDIGboDq3xMItDRcCMYPYqWZUQ2kQQe ez8aV6zQMXhOO1iqd9BZ3DKTBHjGgkCsBumqdrfLeLB7gJ2B4Asme3u+RvrmG+wBpNbD 5REGt+pYVsgsPOuGhCSlbzIqHmzjw7ChE9/d5lhPC0M2kgLvdnY3k3yr6dPOtJ8qRG6T 4z4XJc8sQUsoWjtuHCosbZtNxNjLH3xCj8qe7g+g5EoCwd8QCNHylMwql5vv0cfAEj/n v00wSwFlrgYRkONbL4gbDpS01ZPvI3gMSs+JqTu+7zV8Dv38FAYgl8ygS0aVm/QL16cz uWZA== X-Gm-Message-State: AOAM531S7LRmPUxbhBJz3lQoziLeDrV9RsN2Us6gADrk8G0pCX/FzEDg 8p+z4W99iiHWLs8rinpIULCTtg== X-Received: by 2002:a7b:c8da:: with SMTP id f26mr8066334wml.50.1609340860673; Wed, 30 Dec 2020 07:07:40 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:40 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 5/8 v2] efi_loader: bootmgr: Use get_var from efi_helper file Date: Wed, 30 Dec 2020 17:07:17 +0200 Message-Id: <20201230150722.154663-6-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean A few patches before we introduced a file which includes the get_var_efi() function defined in the efi bootmanager. So let's replace it here and use the common function as much as we can. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_bootmgr.c | 37 +++--------------------------------- 2 files changed, 4 insertions(+), 35 deletions(-) -- 2.30.0 diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index cd4b252a417c..a47160189c42 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -21,7 +21,7 @@ targets += helloworld.o endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o -obj-y += efi_bootmgr.o +obj-y += efi_helper.o efi_bootmgr.o obj-y += efi_boottime.o obj-y += efi_console.o obj-y += efi_device_path.o diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 61dc72a23da8..0221fd1261b3 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -165,38 +166,6 @@ unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data) return size; } -/** - * get_var() - get UEFI variable - * - * It is the caller's duty to free the returned buffer. - * - * @name: name of variable - * @vendor: vendor GUID of variable - * @size: size of allocated buffer - * Return: buffer with variable data or NULL - */ -static void *get_var(u16 *name, const efi_guid_t *vendor, - efi_uintn_t *size) -{ - efi_status_t ret; - void *buf = NULL; - - *size = 0; - ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); - if (ret == EFI_BUFFER_TOO_SMALL) { - buf = malloc(*size); - ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); - } - - if (ret != EFI_SUCCESS) { - free(buf); - *size = 0; - return NULL; - } - - return buf; -} - /** * try_load_entry() - try to load image for boot option * @@ -224,7 +193,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, varname[6] = hexmap[(n & 0x00f0) >> 4]; varname[7] = hexmap[(n & 0x000f) >> 0]; - load_option = get_var(varname, &efi_global_variable_guid, &size); + load_option = get_var_efi(varname, &efi_global_variable_guid, &size); if (!load_option) return EFI_LOAD_ERROR; @@ -336,7 +305,7 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) } /* BootOrder */ - bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size); + bootorder = get_var_efi(L"BootOrder", &efi_global_variable_guid, &size); if (!bootorder) { log_info("BootOrder not defined\n"); ret = EFI_NOT_FOUND; From patchwork Wed Dec 30 15:07:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355276 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11404045jai; Wed, 30 Dec 2020 07:08:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdNGcCbmV/VaRsZiBp59a2jMOY5JQz10rtn1+bkG4iFslY4djfJAFaQx+49LOE3LJtgXxJ X-Received: by 2002:a05:6402:3048:: with SMTP id bu8mr50989309edb.49.1609340932660; Wed, 30 Dec 2020 07:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340932; cv=none; d=google.com; s=arc-20160816; b=vLoJ5yNaYBbfosL+GDmmGrdz6j+vAMdPt19gOTCAvQ1RsoBnvECWztPWIdUxa5xThR q5gjzWHb+maAwDel/zUKCalEs5RKX+mWIcpbenTTbhVMl9ZwL//u28llePQpnYXTpfhg jzOJPNf+M3O5eLeJw4DZxqhuLzdIoNC6l1PnU+dQoFulGSQwundC8S0Ze0TkQNOli/m8 SNpfodlm8itX0B2ya9H8hznBY5GQ1ZZGMibHID36ha7+USZNxYZtzrGsSr+xLSKWjqnh QSE1ku32NALWFD8JKqzVtHsHCUFDC6fJmiCKS0RCtQdX0K6kDcdodayA2nGwq12PEcaP DW0A== 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=X96u6EoOrgEIPVFvysoAV+fvMN1BK+7emh0RCN4v4nA=; b=00E9Mg440+bdeb8ZS4FJD3G4SxTgbcMLthqExMwyuLvzzK6zO+t3YhKZYBZjnks6kc whYbTRaEUkEwgJ3hViBrwvRxqwn/0OoHuuK5UmdkLqnBiIz0shq9Zn8YldvKTBdUYhaM FdU4KIXnaBdyDgheUwpoHHbKIThPS66bbgIW5tkZdgjVlgFMoxbaULh50qRS6CB62WG4 /XAQrNJsZROC5IFID0vEKZGoxC8yetpjW4tmbG7YcGSPzYFRH9Ey1q+raEPoadzDdt5s YmYTokjgMQHpCoK25Xmbn/Qz/O/38kDF6zDfuZZIFCCUVUYYJMnyLDE2POgmHeYHn9YV wN2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pgfuppBJ; 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 f15si21510120ejr.2.2020.12.30.07.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:08:52 -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=pgfuppBJ; 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 5EE6782636; Wed, 30 Dec 2020 16:08:09 +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="pgfuppBJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 208AF82626; Wed, 30 Dec 2020 16:07:50 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) (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 34F7C82623 for ; Wed, 30 Dec 2020 16:07: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=ilias.apalodimas@linaro.org Received: by mail-wm1-x32b.google.com with SMTP id k10so5176910wmi.3 for ; Wed, 30 Dec 2020 07:07:44 -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=X96u6EoOrgEIPVFvysoAV+fvMN1BK+7emh0RCN4v4nA=; b=pgfuppBJkdBAvtnSPsE4euXJtuI6teCoqvm4ZWwlQbVqBEhp+T2Ebt1d26OiG6X3QK +04I56a9XUouZzn40LOc4/poNTERue6Hrw7ENCqQ1ugnS2Mu3o4jjCrJ1JXvbM1wsBIG 13WTr6H3Q8zBu3i5/m7w2pm+aVHSGczL+fk/zoLEcCunlC7EibqFwxrkr3ZkjFYF1KKg 50AuXxObWCWanfu9QbePP4+E9c2MM/tuzpgwvoQCo5HxNn/YEy2s/XZ1Mr1UXw6mc9pH 8uv/DzGLM+mHBquKaDyCoSxJwrTfXJmCU2hZGKUZrnEfcgDhAeoOjEdZT46Df1GwvRTO QGNQ== 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=X96u6EoOrgEIPVFvysoAV+fvMN1BK+7emh0RCN4v4nA=; b=X1aoxT38ZnLxkf45c3cCDgu9HA5iYm5QJnC3MUpfQeZh1FzdqG/yw2Wwru9MBr7pYh Y1qXQ3HPOSSGoESIuFuzwFE1E6Dsbzv/Y5XdGb3zhbDM/wlERSHkHQ0kFIEjDIUze3pR MlFhjN5hH3hpIlCY8C18iPQ3jW8QgCSXKZUXOGnsHA1RCkKjAVflHC4vgFtmZBeTT1k1 8KkSBpPA7pjEQ1PhghOGb+UxiJ/2QtQu/R1ijAbWoeCdoA4hAylSZj597E3np+tcmMCT sJKUm/BtiGWbngNYDrx29TVbZ5AAcQ9kLcA54xRZZxN3pH4uumOJpBBfyAjy4/U6CO9x 9QoA== X-Gm-Message-State: AOAM531U2tcu4dvCkCKUSFi8PfmlD6XFY254CidYsRKzmIRU6Uzm6tzo NSC3EgWZ/qTv4LDREoReYLf9fw== X-Received: by 2002:a1c:7c09:: with SMTP id x9mr8077696wmc.98.1609340863787; Wed, 30 Dec 2020 07:07:43 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:43 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 6/8 v2] efi_loader: Replace config option with EFI variable for initrd loading Date: Wed, 30 Dec 2020 17:07:18 +0200 Message-Id: <20201230150722.154663-7-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean Up to now we install EFI_LOAD_FILE2_PROTOCOL to load an initrd unconditionally. Although we correctly return various EFI exit codes depending on the file status (i.e EFI_NO_MEDIA, EFI_NOT_FOUND etc), the kernel loader, only falls back to the cmdline interpreted initrd if the protocol is not installed. This creates a problem for EFI installers, since they won't be able to load their own initrd and continue the installation. It also makes the feature hard to use, since we can either have a single initrd or we have to recompile u-boot if the filename changes. So let's introduce a different logic that will decouple the initrd path from the config option we currently have. When the EFI application is launched through the bootmgr, we'll try to match the BootCurrent value to an Initrd#### EFI variable. e.g Boot0000 -> Initrd0000, Boot0010 -> Initrd0010 etc. The Initrd#### EFI variable is expected to include the full file path, i.e 'mmc 0:1 initrd'. If the file is found, we'll install the appropriate protocol so the kernel's efi-stub can use it and load our initrd. If the file is not found the kernel will still try to load an initrd parsing the kernel cmdline, since the protocol won't be installed. This opens up another path using U-Boot and defines a new boot flow. A user will be able to control the kernel/initrd pairs without explicit cmdline args or GRUB. So we can base the whole boot flow on the Boot#### and Initrd#### paired values. Suggested-by: Heinrich Schuchardt Signed-off-by: Ilias Apalodimas --- cmd/bootefi.c | 13 +++++ include/efi_loader.h | 2 +- lib/efi_loader/Kconfig | 13 ++--- lib/efi_loader/efi_load_initrd.c | 93 ++++++++++---------------------- 4 files changed, 46 insertions(+), 75 deletions(-) -- 2.30.0 diff --git a/cmd/bootefi.c b/cmd/bootefi.c index fdf909f8da2c..0234b0df2258 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -377,6 +377,19 @@ static int do_efibootmgr(void) return CMD_RET_FAILURE; } + /* efi_exit() will delete all protocols and the handle itself on exit */ + if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) { + ret = efi_initrd_register(&handle); + /* Just warn the user. If the installation fails, the kernel + * either load an initrd specificied in the cmdline or fail + * to boot. + * If we decide to fail the command here we need to uninstall + * the protocols efi_bootmgr_load() installed + */ + if (ret != EFI_SUCCESS) + log_warning("EFI boot manager: Failed to install Loadfile2 for initrd\n"); + } + ret = do_bootefi_exec(handle, load_options); if (ret != EFI_SUCCESS) diff --git a/include/efi_loader.h b/include/efi_loader.h index af30dbafab77..000cc942e31c 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -422,7 +422,7 @@ efi_status_t efi_gop_register(void); efi_status_t efi_net_register(void); /* Called by bootefi to make the watchdog available */ efi_status_t efi_watchdog_register(void); -efi_status_t efi_initrd_register(void); +efi_status_t efi_initrd_register(efi_handle_t *initrd_handle); /* Called by bootefi to make SMBIOS tables available */ /** * efi_acpi_register() - write out ACPI tables diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index dd8b93bd3c5a..96b5934a221d 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -212,14 +212,11 @@ config EFI_LOAD_FILE2_INITRD help Expose a EFI_FILE_LOAD2_PROTOCOL that the Linux UEFI stub can use to load the initial ramdisk. Once this is enabled using - initrd= will stop working. - -config EFI_INITRD_FILESPEC - string "initramfs path" - default "host 0:1 initrd" - depends on EFI_LOAD_FILE2_INITRD - help - Full path of the initramfs file, e.g. mmc 0:2 initramfs.cpio.gz. + initrd= will stop working. The protocol will only be + installed if bootmgr is used and the file is found on the defined + path. A boot entry of Boot0001 will try to match Initrd0001 and use + it. Initrd EFI variable format should be ' ' + i.e 'mmc 0:1 boot/initrd' config EFI_SECURE_BOOT bool "Enable EFI secure boot support" diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index 4ec55d70979d..6289957c97bc 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include #include @@ -43,40 +45,7 @@ static const struct efi_initrd_dp dp = { }; /** - * get_file_size() - retrieve the size of initramfs, set efi status on error - * - * @dev: device to read from, e.g. "mmc" - * @part: device partition, e.g. "0:1" - * @file: name of file - * @status: EFI exit code in case of failure - * - * Return: size of file - */ -static loff_t get_file_size(const char *dev, const char *part, const char *file, - efi_status_t *status) -{ - loff_t sz = 0; - int ret; - - ret = fs_set_blk_dev(dev, part, FS_TYPE_ANY); - if (ret) { - *status = EFI_NO_MEDIA; - goto out; - } - - ret = fs_size(file, &sz); - if (ret) { - sz = 0; - *status = EFI_NOT_FOUND; - goto out; - } - -out: - return sz; -} - -/** - * efi_load_file2initrd() - load initial RAM disk + * efi_load_file2_initrd() - load initial RAM disk * * This function implements the LoadFile service of the EFI_LOAD_FILE2_PROTOCOL * in order to load an initial RAM disk requested by the Linux kernel stub. @@ -96,21 +65,15 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this, struct efi_device_path *file_path, bool boot_policy, efi_uintn_t *buffer_size, void *buffer) { - char *filespec; efi_status_t status = EFI_NOT_FOUND; loff_t file_sz = 0, read_sz = 0; - char *dev, *part, *file; - char *pos; int ret; + struct load_file_info info; + char initrd[] = "Initrd"; EFI_ENTRY("%p, %p, %d, %p, %p", this, file_path, boot_policy, buffer_size, buffer); - filespec = strdup(CONFIG_EFI_INITRD_FILESPEC); - if (!filespec) - goto out; - pos = filespec; - if (!this || this != &efi_lf2_protocol || !buffer_size) { status = EFI_INVALID_PARAMETER; @@ -128,24 +91,11 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this, goto out; } - /* - * expect a string with three space separated parts: - * - * * a block device type, e.g. "mmc" - * * a device and partition identifier, e.g. "0:1" - * * a file path on the block device, e.g. "/boot/initrd.cpio.gz" - */ - dev = strsep(&pos, " "); - if (!dev) - goto out; - part = strsep(&pos, " "); - if (!part) - goto out; - file = strsep(&pos, " "); - if (!file) + status = efi_get_fp_from_var(initrd, &info); + if (status != EFI_SUCCESS) goto out; - file_sz = get_file_size(dev, part, file, &status); + file_sz = get_file_size(&info, &status); if (!file_sz) goto out; @@ -153,23 +103,25 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this, status = EFI_BUFFER_TOO_SMALL; *buffer_size = file_sz; } else { - ret = fs_set_blk_dev(dev, part, FS_TYPE_ANY); + ret = fs_set_blk_dev(info.dev, info.part, + FS_TYPE_ANY); if (ret) { status = EFI_NO_MEDIA; goto out; } - ret = fs_read(file, map_to_sysmem(buffer), 0, *buffer_size, - &read_sz); - if (ret || read_sz != file_sz) + ret = fs_read(info.filename, map_to_sysmem(buffer), 0, + *buffer_size, &read_sz); + if (ret || read_sz != file_sz) { + status = EFI_DEVICE_ERROR; goto out; + } *buffer_size = read_sz; status = EFI_SUCCESS; } out: - free(filespec); return EFI_EXIT(status); } @@ -183,13 +135,22 @@ out: * * Return: status code */ -efi_status_t efi_initrd_register(void) +efi_status_t efi_initrd_register(efi_handle_t *efi_initrd_handle) { - efi_handle_t efi_initrd_handle = NULL; efi_status_t ret; + struct load_file_info info; + char initrd[] = "Initrd"; + + ret = efi_get_fp_from_var(initrd, &info); + /* + * Don't fail here. If we don't install the protocol the efi-stub will + * try to load and initrd parsing the kernel cmdline + */ + if (ret != EFI_SUCCESS) + return EFI_SUCCESS; ret = EFI_CALL(efi_install_multiple_protocol_interfaces - (&efi_initrd_handle, + (efi_initrd_handle, /* initramfs */ &efi_guid_device_path, &dp, /* LOAD_FILE2 */ From patchwork Wed Dec 30 15:07:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355277 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11404262jai; Wed, 30 Dec 2020 07:09:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuiaBFbqWYTj+NiYGzmrxykoV5SHLTuZeVtfYrV/v0/NvTbVBCCnZbaWYXZSayh7TGp+2Q X-Received: by 2002:a17:906:1a4e:: with SMTP id j14mr49511649ejf.507.1609340946129; Wed, 30 Dec 2020 07:09:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340946; cv=none; d=google.com; s=arc-20160816; b=E7RTgYMQJGl9J7m80V/vCrRlCRhjANSmPh44j8Dhdiab10UuUS7m3Hl0U+nRksFpbJ 8+l7g/gcp6N1OsHU8EJ0Kj2ft6dBNv3HZUx2xtd7W2svZAZP5jQA3nupMeYwizs7XY6S Vx1pPoMPnNZyUYM6awrsAIOtv2gmj2nESZYnFdONA3iGLxNYe/H379Yv9YmnnUF1ySXY RLLuCP1ty6pzggemGiLzmLUVmQjdNKhNxYJDQtlv/2M4gpky2a1tMmiwJSpo/xgFrJbk hsCA29zxEycrEO05YHVM2muaYJk/RcQf0My5nXF85Cw+B61gaGwZOEWFoNi41YEY8uYX G5HA== 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=Y7Zaw8cm3AC5QmPJgi6OxAtDshoSK79ytn2OB2lCse8=; b=rYB/bM2pNs7JYp2BHTD81HKwcoWNYj2n2smYpUwn9XjMrl6qq66jmkVhSmEuJ4YGt8 eMhYHvxFncCDJRh/z5B9ijAdmJQm/phWsNu9goXSuFv5Bo3gXlVRZIPzjDF8Gy6gLVFP jnzU9NbdnCwkQc3lvAGwuxGWCNzLp2XWG0yDbfY+KhNCR2ATY8XEBfSnQj4VdC5Yab6m rsO3+jVtJVNqjb2vSQmh1+cotUXHaF5qrqiRpSUVCZl4wq46bvSBtLmIYQ+s7Ny2ige3 RbfY5co0xXR5aQuXfGXX+qM3IUDdazl4fCl2Y0cgV4zHeG2bQES4cp3R/jh49stEMrBX O5Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YT9M6xN1; 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 y13si21842872ejw.564.2020.12.30.07.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:09:06 -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=YT9M6xN1; 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 BE35E82603; Wed, 30 Dec 2020 16:08:12 +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="YT9M6xN1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D0FA182628; Wed, 30 Dec 2020 16:07:51 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) (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 6591E8257D for ; Wed, 30 Dec 2020 16:07:47 +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=ilias.apalodimas@linaro.org Received: by mail-wr1-x435.google.com with SMTP id t16so17694812wra.3 for ; Wed, 30 Dec 2020 07:07:47 -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=Y7Zaw8cm3AC5QmPJgi6OxAtDshoSK79ytn2OB2lCse8=; b=YT9M6xN1cHIUpA64dHB3R1HpZTttrc/2yzpJ3ZFNVy+DSJ26ksYlKQdkY4LX5rXzyg 0ClM5w9o5IW0tvIiNvRhhcBUiZHoICBioBtosI63kf15KomWH+72NEEOJWBtEI7C8t9N GWFEiwOk2MgQ2NQoX/QzzQX0dMbmNgnIyM5LDBGC7s1quZYfo2hlQOVsnoW83cxhGLRf 2zrCV6IMSEkJjyfKtrmXgco8TN1CXAum8Ge87PQVFPfLPHF6Vwu58ZYm3JunnvMeVeQn DD5r3M5Pz3AQ5vopYW0XmE6ep0w1rQ6IgGfgPxCivO680IKs4M62ph3I8951GmmTvF+o qiDg== 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=Y7Zaw8cm3AC5QmPJgi6OxAtDshoSK79ytn2OB2lCse8=; b=gwnvrDpR36RshHIlIlkhxcdOfZnhkoGRjHLeZ5yBSC2bdd8FoLT+6fIs2JxIyrXNaH XBCHNaNpKc4ie6rOvFjw40M05q3Bb4V1eGKTMkaxtnYG2rFly5o2ZDd1NmLqMCKTnmox PUkE3C2dssPDToMuSZeqET8oodcOlK8WMx5GVQ1divsi1yknBdtOwUp5JYv/oQ4g0A7O 9WYHCcnzNFXNpmFkcEm5k4LictYeTCwj3uVns9cJSBUGrdopcEWFEi6tJ4rMlkDw/Cx3 0ziuzTcNBfSg9zvXfbZpboIDyztLNPK2IdPdvd/NGiE40z/5QILxTk5CThLHZKwsVZTl EjfQ== X-Gm-Message-State: AOAM532x9218q15Pmvq6mLpgxluUAvTSkdErMQy4LVgFz2VZ5c/EB2HW hmACwGoF0Nkxc/fft4h7n/uQlg== X-Received: by 2002:a5d:58d3:: with SMTP id o19mr9071747wrf.250.1609340866841; Wed, 30 Dec 2020 07:07:46 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:46 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 7/8 v2] efi_selftest: Modify self-tests for initrd loading via Loadfile2 Date: Wed, 30 Dec 2020 17:07:19 +0200 Message-Id: <20201230150722.154663-8-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean We changed the logic of the initrd discovery and the installation of the protocol in the previous patch. Instead of a config now option it now resides in an EFI variable. Adjust the existing tests accordingly and add self-tests which will cover the new features. Signed-off-by: Ilias Apalodimas --- lib/efi_selftest/efi_selftest_load_initrd.c | 100 +++++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) -- 2.30.0 diff --git a/lib/efi_selftest/efi_selftest_load_initrd.c b/lib/efi_selftest/efi_selftest_load_initrd.c index fe060a664402..1534c2ba24fa 100644 --- a/lib/efi_selftest/efi_selftest_load_initrd.c +++ b/lib/efi_selftest/efi_selftest_load_initrd.c @@ -14,10 +14,12 @@ * * CONFIG_EFI_SELFTEST=y * CONFIG_EFI_LOAD_FILE2_INITRD=y - * CONFIG_EFI_INITRD_FILESPEC="host 0:1 initrd" * - * * Run ./u-boot and execute + * * Create files + * mkdir init_test && cp initrd init_test/ + * virt-make-fs -t ext4 init_test test.img * + * * Run ./u-boot and execute * host bind 0 image * setenv efi_selftest load initrd * bootefi selftest @@ -43,6 +45,7 @@ #include static struct efi_boot_services *boottime; +static struct efi_runtime_services *runtime; static struct efi_initrd_dp dp = { .vendor = { @@ -76,10 +79,13 @@ static struct efi_initrd_dp dp_invalid = { } }; +static efi_handle_t handle; + static int setup(const efi_handle_t handle, const struct efi_system_table *systable) { boottime = systable->boottime; + runtime = systable->runtime; return EFI_ST_SUCCESS; } @@ -87,16 +93,97 @@ static int setup(const efi_handle_t handle, static int execute(void) { efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID; + efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID; struct efi_load_file_protocol *lf2; struct efi_device_path *dp2, *dp2_invalid; efi_status_t status; - efi_handle_t handle; char buffer[64]; efi_uintn_t buffer_size; void *buf; u32 crc32; + u16 boot_current = 0; + efi_uintn_t boot_current_size = sizeof(boot_current); + char path[] = "host 0 initrd"; + char invalid_path[] = "host 1 initrd"; + efi_uintn_t path_size = sizeof(path); + efi_uintn_t invalid_path_size = sizeof(invalid_path); + u32 attrs = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; memset(buffer, 0, sizeof(buffer)); + /* Set variable BootCurrent and Initrd#### to a wrong value */ + status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid, + attrs, boot_current_size, &boot_current); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for BootCurrent failed\n"); + return EFI_ST_FAILURE; + } + + /* + * We don't need NV for Initrd here. + * Set the file to an invalid file path + */ + status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid, + attrs, invalid_path_size, invalid_path); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for Initrd failed\n"); + return EFI_ST_FAILURE; + } + + /* We only install the protocol during efibootmgr */ + status = efi_initrd_register(&handle); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to install initrd protocol\n"); + return EFI_ST_FAILURE; + } + + /* + * We should only install the protocol if the file's found + * Right now both BootCurrent and file path are invalid + */ + dp2 = (struct efi_device_path *)&dp; + status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); + if (status != EFI_NOT_FOUND) { + efi_st_error("Initrd protocol should't be installed\n"); + return EFI_ST_FAILURE; + } + + /* Update BootCurrent to the correct value */ + boot_current = 0x0010; + status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid, + attrs, boot_current_size, &boot_current); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for BootCurrent failed\n"); + return EFI_ST_FAILURE; + } + + /* re-install with invalid file path */ + status = efi_initrd_register(&handle); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to install initrd protocol\n"); + return EFI_ST_FAILURE; + } + + /* file path is invalid */ + dp2 = (struct efi_device_path *)&dp; + status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); + if (status != EFI_NOT_FOUND) { + efi_st_error("Initrd protocol should't be installed\n"); + return EFI_ST_FAILURE; + } + + /* re-install with correct values now */ + status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid, + attrs, path_size, path); + if (status != EFI_SUCCESS) { + efi_st_error("SetVariable for Initrd failed\n"); + return EFI_ST_FAILURE; + } + + status = efi_initrd_register(&handle); + if (status != EFI_SUCCESS) { + efi_st_error("Failed to install initrd protocol\n"); + return EFI_ST_FAILURE; + } dp2 = (struct efi_device_path *)&dp; status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle); @@ -211,10 +298,17 @@ static int execute(void) return EFI_ST_SUCCESS; } +static int teardown(void) +{ + efi_delete_handle(handle); + return EFI_ST_SUCCESS; +} + EFI_UNIT_TEST(load_initrd) = { .name = "load initrd", .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, .setup = setup, .execute = execute, + .teardown = teardown, .on_request = true, }; From patchwork Wed Dec 30 15:07:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 355278 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11404452jai; Wed, 30 Dec 2020 07:09:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPBRL/fYnR0vA8dnB1ngyzTuum2IhFNDkhIwhAFL4cfeI5VcqzUMAHjKA+jrQe1YVMbPg3 X-Received: by 2002:a17:906:2c54:: with SMTP id f20mr50343935ejh.318.1609340959225; Wed, 30 Dec 2020 07:09:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609340959; cv=none; d=google.com; s=arc-20160816; b=nE3O2Jm5m7AvHBtaGwJOEZweEGlsK1RRpikRv0XeGvswnHPpFhWC1F/O4e0O37S8kg DGcG1bo+PWzPTN4sPcoQiJD9Us2Epb7NluUl6g9vUk7neKYF8lpWj8IIJWiFCbmqRSd/ 1riuH1WwMIlwPn0m5mIyZq3PHL7rzUQiVLZzCceks/XvRZW3xGG6rRG7CJXrHCo5Zobz 7EVYJ9oEjqAcyCIsX2rt3+Lo0cbx7+5qt2RE54TBqkYumyqs0+Nc4bcA1B7W+6rtYhr/ bmhqyjTDq63g2HIZTedK0K+HcG6lGA0xbnmhWcuFZaxi0RDlKGA0LX1H/3LmIcsILab3 e7cQ== 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=JaKlNDunRnnOWx+/hakVPjMC3GFXUfk4GZEwHFx7HyA=; b=Tadk75l0B6KFoBZFlnR5+/cCuXxgJ+9YbtSN+JoImFz+O3hbEGe97UVtpwYC2DHPZH M9u68ZraoV9hRHRn8n4j8YRQXHYu/breRTjhuUn8tOU9thjZaBj4ZNP4p6sBkkNW70Ij OejWIFUTc/SMGO38FAePBWYb218AJAqS7JBPU35QP3wsNb2CL6mvXCJpTjzzTY9oxp35 Ev3EwncjlAAsi5SzESxPvaoW02SGhVA9mKAOGjrHNFLyj0Qmy4LLIqEs4dPmT3kQjUtA H04yBcwqK6lsvDfwcI8aXoEYQoPuOfH1iOquLggFkWt9kvVD0izWrh4h74ki+2+a/qnC KWmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jccB3H2L; 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 d8si21480073ejw.38.2020.12.30.07.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:09:19 -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=jccB3H2L; 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 93AC382652; Wed, 30 Dec 2020 16:08:16 +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="jccB3H2L"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7C01682636; Wed, 30 Dec 2020 16:07:53 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (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 485AA82607 for ; Wed, 30 Dec 2020 16:07:50 +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=ilias.apalodimas@linaro.org Received: by mail-wr1-x436.google.com with SMTP id q18so17730988wrn.1 for ; Wed, 30 Dec 2020 07:07:50 -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=JaKlNDunRnnOWx+/hakVPjMC3GFXUfk4GZEwHFx7HyA=; b=jccB3H2Lj3h/0oIdTyvLwA6BQkc46qTWy3+pUeCD3qiaEMk/caFxW3FOVuoiyqkkEn vzktt4LFLGuzfyp7duQDutbgRgF32puJDWM3HgbbdF7CmTQCTQZ18E5n3FCHHWt0vtI6 HMuIiJuQdr/9KBvFNuw5nO4h8hIk4kz2CaQCbSNSpYc5EB5dskpgOdfEF2ulqO4lEYmY TL+35twYxwUNLsx9TNwXJOqkvpM7aBMEoRV8+6E/p3AN7AhHdUY5Ykz0X2aMfn0+mcWH CePPX7+uOLf4yK/u2z3J4SZq3/wJvcEbDPtFx/b0wrusWMjTyyqI4w0Cexn9sddQ3J1j uuSA== 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=JaKlNDunRnnOWx+/hakVPjMC3GFXUfk4GZEwHFx7HyA=; b=tgr3C+LF2m1hCU6C4RpQhFPRvY90iM7qtKTvCUperoJvriXJOvZ53IwhvR1MUWZpRX 87KznErAuk9b58b1EjlWGMxGjOGhnvg4pbjykPn+v+mZv+qIHf3R11v7RA3Pp8kN8ri6 S4PtuglLFBU6FsggcgNXA05aWU8NlbHyC3WjGke5vRN608asBqoZyrEgYYP04XtIl5hX IHlzl92JzV8tiFsML6ag9O5tp2WLHzxwOQ9bigKHV85jyh/2dwKHhqeE0PPO6FW7p/3L 5f2j/whymeTY3wCLijgpcmf2WSR+xZlcJeLsHa3PX/7THRzYsa9Gon4fiXmi9nMM4Pp2 yxcQ== X-Gm-Message-State: AOAM532EdwTf8Wy76ER1suPLuQ/FXQHSf3x+wHeQxH04VS/+sLJmV+sB 7v4I2ooiN/xB8XU/0amv4/2NxQ== X-Received: by 2002:a5d:5401:: with SMTP id g1mr60081895wrv.93.1609340869937; Wed, 30 Dec 2020 07:07:49 -0800 (PST) Received: from localhost.localdomain (athedsl-4484548.home.otenet.gr. [94.71.57.204]) by smtp.gmail.com with ESMTPSA id k10sm62062721wrq.38.2020.12.30.07.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:07:49 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , u-boot@lists.denx.de Subject: [PATCH 8/8 v2] doc: uefi: Add instruction for initrd loading Date: Wed, 30 Dec 2020 17:07:20 +0200 Message-Id: <20201230150722.154663-9-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20201230150722.154663-1-ilias.apalodimas@linaro.org> References: <20201230150722.154663-1-ilias.apalodimas@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.102.3 at phobos.denx.de X-Virus-Status: Clean Add a description of the EFI variables needed to match a Boot#### entry with an initrd. Signed-off-by: Ilias Apalodimas --- doc/uefi/uefi.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 2.30.0 diff --git a/doc/uefi/uefi.rst b/doc/uefi/uefi.rst index dc930d924022..d8b083ffa708 100644 --- a/doc/uefi/uefi.rst +++ b/doc/uefi/uefi.rst @@ -229,6 +229,21 @@ UEFI variables. Booting according to these variables is possible via:: As of U-Boot v2020.10 UEFI variables cannot be set at runtime. The U-Boot command 'efidebug' can be used to set the variables. +Initrd with the boot manager +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Kernel versions >= 5.6 can use EFI_LOAD_FILE2_PROTOCOL to load an initramfs. +When U-Boot is configured with CONFIG_EFI_LOAD_FILE2_INITRD=y the boot manager +will install the protocol, if an EFI variable matching the BootCurrent value +is found and contains a valid file path. The EFI variable name is 'Initrd####' +and the file path format is ' '. + +This allows users to pair a kernel with a specific initramfs. + +Example: +Boot0010 will search for Initrd0010 and try to install the protocol with +the file path specified in Initrd0010. + Executing the built in hello world application ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~