From patchwork Fri Apr 15 07:15:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 561942 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp115443map; Fri, 15 Apr 2022 00:17:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6i1tacjrkxlpj4FRx0NAoIH9QE2Vg+ULJ0jDT3WzCUwRQJb5PLGn1nA552OmaT0JdIDjx X-Received: by 2002:a17:907:3da5:b0:6e8:c2c8:1f18 with SMTP id he37-20020a1709073da500b006e8c2c81f18mr5240080ejc.728.1650007040233; Fri, 15 Apr 2022 00:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650007040; cv=none; d=google.com; s=arc-20160816; b=H6iaxYwuSzDVlNtQNbzqXl0G/aH6mTLpE9m/iKNzT3B2dlf7ic0jvuslqALDlURLgc i5IQoVcbk73AEspc82EAdpKk4CcJ9Chzt8ngQbBG9TbZ+GI93Iyh+bjc5b1lLFVMvB+U JmJ0BqoUY0CfaHhupKaP5QgTiPU8vaUe2Lp4212ecq6u40k7OFKmeRSIiD+F8k1/B8J4 VzWkm6RTmpzTOi1dmquSy/84YjNfgstBbwkbhHOUzP/Y7E3NfNjKq+MXb7GSHZuHlfHx x3butMeta4JnRgp1YR6ykY/w5CL8ZaD1MatVQZtB+vSGfIkwt4DGER5FJk1htpWSA5Sb bEaw== 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=cbFzoCA87IcKmFGTSIc0nYbRxTMR3twfvdohAUjaIdA=; b=K/uIW2eDYDCF2O6uzdT1K9BUdZQP3qErGdxo3iybBtQ9v5+JPyeoE0ABT8H6Gwcsap lQzSkladhM983Mz3oXvuDWYeQnD48aZURNdJt6OEJJc4qVPxt15n1grX+AjEk3aQMgFG QnFodEDvb2t5PLH4EenX9hZJ2vSYeXpombxj3/3SDKxKX+VvONr3C9GPL4FLlt/EhDOe B1Rx0ncdekgpGnVjPuBxSp2Wjy8m6+kTGSrnFf/AG70o1i+MZW642Pa8pOl4ry9ZOii5 SIa+6TitRCIiBSmxR2WbEt7v1VvLrF9M4qg9Sdm0Y4gk4s489/BDV+AKroE67Fagu4Zm Yu4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=er+IAaZv; 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 m15-20020a170906258f00b006e748e41ceasi552694ejb.308.2022.04.15.00.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:17:20 -0700 (PDT) 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=er+IAaZv; 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 B143783D8B; Fri, 15 Apr 2022 09:16:39 +0200 (CEST) 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="er+IAaZv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C748C83B4E; Fri, 15 Apr 2022 09:16:34 +0200 (CEST) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (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 2A49183AE6 for ; Fri, 15 Apr 2022 09:16:30 +0200 (CEST) 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-pg1-x534.google.com with SMTP id t13so6706848pgn.8 for ; Fri, 15 Apr 2022 00:16:30 -0700 (PDT) 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=cbFzoCA87IcKmFGTSIc0nYbRxTMR3twfvdohAUjaIdA=; b=er+IAaZvwoQeo6gpUCOkHz0zKeWo6f6bbDdNhZ68Ky/Kl0j8/9Ng1QaEu9yFDEOyPl NAet538R3p+XH8OD/rhnpCSHmccRmxE1S2gJP61TqqIMaF3urD3sAytViGXqTEWTBCgX JnwTn8jueCOMjqsKia8q/LbK+zd7ZP/rd49ZWmYf9efrxPGgVGyBqSA/Lfowcuhzc4oY GMod6LY2/mOWOf+Qwur3rIrQg0J18XGq6eCcUqMexJRkOF+nKbujhYC0c0HtjMhk/uSX F442OgNvSgilsPTK0R524vO8y+Z5U/vjQZZzsFHWJgHXcy2VYFak563xQQ7pxkruwpux EhAQ== 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=cbFzoCA87IcKmFGTSIc0nYbRxTMR3twfvdohAUjaIdA=; b=N/EItUeT08TvEMVu7wc3b757oshZiw02epoGIpkZdmkkPiHWqTflJP70f21Fu6PyPC NB9leIMX6iK0OWuTmOsVyT2YNA1+nHujK749+thgWInlYjiXVpREwhqw3V5kBJm7ba5S YMl//XCtAnkSYmmipUQJmWCqY0Fve/XVX5WdbZhIVgDea/hLq9ub36aDOY0dW4HwV6gX uiwEBvR+q/OxHCiIUW9sr3hlN7R1rguoJk+E6imJO0/FdV9KwqLaEywpRkmT7Wt9d9tc qri2a0kd31BLiZVBdTOusUU5Wb6Ea8XeUiP2eUS+C6k4GgI8y7hazYNWwuVziSsKec2S mJhw== X-Gm-Message-State: AOAM533QqrYgWpajAFcRwNvTm0zMafaTecvLrMInEFBHDkm6u6abfDvy K84N7LsR96mJBW54pbkrJQohhw== X-Received: by 2002:a63:d149:0:b0:384:b288:8704 with SMTP id c9-20020a63d149000000b00384b2888704mr5280034pgj.112.1650006988529; Fri, 15 Apr 2022 00:16:28 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c3e1:100:18f3:1e4:6c4:6ea3]) by smtp.gmail.com with ESMTPSA id p1-20020a17090a0e4100b001ce188720e5sm3566921pja.53.2022.04.15.00.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:16:28 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v4 06/12] efi_loader: split efi_init_obj_list() into two stages Date: Fri, 15 Apr 2022 16:15:40 +0900 Message-Id: <20220415071546.122475-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220415071546.122475-1-takahiro.akashi@linaro.org> References: <20220415071546.122475-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean In the next commit, CONFIG_EFI_SETUP_EARLY will become mandated in order to support dynamic enumeration of efi_disk objects. This can, however, be problematic particularly in case of file-based variable storage (efi_variable.c, default). Non-volatile variables are to be restored from EFI system partition by efi_init_variables() in efi_init_obj_list(). When efi_init_obj_list() is called in board_init_r(), we don't know yet what disk devices we have since none of device probing commands (say, scsi rescan) has not been executed at that stage. So in this commit, a preparatory change is made; efi_init_obj_list() is broken into the two functions; * efi_init_early(), and * new efi_init_obj_list() Only efi_init_early() will be called in board_init_r(), which allows us to execute any of device probing commands, either though "preboot" variable or normal command line, before calling efi_init_obj_list() which is to be invoked at the first execution of an efi-related command (or at efi_launch_capsules()) as used to be. Signed-off-by: AKASHI Takahiro --- common/board_r.c | 2 +- common/main.c | 7 +++-- include/efi_loader.h | 2 ++ lib/efi_loader/efi_setup.c | 58 ++++++++++++++++++++++++++++++++------ 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/common/board_r.c b/common/board_r.c index 8dc87ed2be4c..7d0281f5447e 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -795,7 +795,7 @@ static init_fnc_t init_sequence_r[] = { initr_mem, #endif #ifdef CONFIG_EFI_SETUP_EARLY - (init_fnc_t)efi_init_obj_list, + efi_init_early, #endif run_main_loop, }; diff --git a/common/main.c b/common/main.c index 3f5214fd44b8..682f3359ea38 100644 --- a/common/main.c +++ b/common/main.c @@ -54,8 +54,11 @@ void main_loop(void) if (IS_ENABLED(CONFIG_UPDATE_TFTP)) update_tftp(0UL, NULL, NULL); - if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) - efi_launch_capsules(); + if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) { + /* efi_init_early() already called */ + if (efi_init_obj_list() == EFI_SUCCESS) + efi_launch_capsules(); + } s = bootdelay_process(); if (cli_process_fdt(&s)) diff --git a/include/efi_loader.h b/include/efi_loader.h index af36639ec6a7..3dedb2c5299d 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -493,6 +493,8 @@ struct efi_register_notify_event { /* List of all events registered by RegisterProtocolNotify() */ extern struct list_head efi_register_notify_events; +/* called at pre-initialization */ +int efi_init_early(void); /* Initialize efi execution environment */ efi_status_t efi_init_obj_list(void); /* Install device tree */ diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index eee54e48784f..de2f34bab537 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -174,20 +174,18 @@ static efi_status_t efi_init_os_indications(void) &os_indications_supported, false); } - /** - * efi_init_obj_list() - Initialize and populate EFI object list + * __efi_init_early() - handle initialization at early stage + * + * This function is called in efi_init_obj_list() only if + * !CONFIG_EFI_SETUP_EARLY. * * Return: status code */ -efi_status_t efi_init_obj_list(void) +static efi_status_t __efi_init_early(void) { efi_status_t ret = EFI_SUCCESS; - /* Initialize once only */ - if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) - return efi_obj_list_initialized; - /* Allow unaligned memory access */ allow_unaligned(); @@ -202,9 +200,51 @@ efi_status_t efi_init_obj_list(void) #ifdef CONFIG_PARTITIONS ret = efi_disk_register(); - if (ret != EFI_SUCCESS) - goto out; #endif +out: + return ret; +} + +/** + * efi_init_early() - handle initialization at early stage + * + * external version of __efi_init_early(); expected to be called in + * board_init_r(). + * + * Return: status code + */ +int efi_init_early(void) +{ + efi_status_t ret; + + ret = __efi_init_early(); + if (ret != EFI_SUCCESS) { + /* never re-init UEFI subsystem */ + efi_obj_list_initialized = ret; + return -1; + } + return 0; +} + +/** + * efi_init_obj_list() - Initialize and populate EFI object list + * + * Return: status code + */ +efi_status_t efi_init_obj_list(void) +{ + efi_status_t ret = EFI_SUCCESS; + + /* Initialize once only */ + if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) + return efi_obj_list_initialized; + + if (!IS_ENABLED(CONFIG_EFI_SETUP_EARLY)) { + ret = __efi_init_early(); + if (ret != EFI_SUCCESS) + goto out; + } + if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) { ret = efi_rng_register(); if (ret != EFI_SUCCESS)