From patchwork Tue Apr 19 01:05:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 563299 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp2860600map; Mon, 18 Apr 2022 18:06:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8TRXLVw/TR+iSPchwyPdSa9UAgLu6WPnc5Rbk/l/dwpD2P3OtcATb04SasnvsCt7mD/b4 X-Received: by 2002:a05:6402:1d4b:b0:416:13bf:4fc5 with SMTP id dz11-20020a0564021d4b00b0041613bf4fc5mr10752434edb.115.1650330407472; Mon, 18 Apr 2022 18:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650330407; cv=none; d=google.com; s=arc-20160816; b=wWhPogLLZejchsNiwGBSQNDkKPDjNegpjG8hQJBJYZlLofnRXiTONCWtJyNRdbkvWy TIJ2ILQKKsTSFZTbw/xXbJcRwocO4xhKfMhYByNCi3cri7GcFjCU6XycguaciFATauQ+ CNIKsP4XsuFvEyvJls+oWqhMxO51LVwkXsjEAnMnqBtUKMZmUOkr0Nikrkoxt27GeuS4 pbPCBp/vm1K3vOETaZZ2fIvA8Fz+FbT6vAOqKN7+HL9+R3Xh//JLkyvAFdQVOyFaT8Md GsD8kzPN43Ggc+noqYUcLmOjNZcxgk9UAoL80W6PqCSVRLPUfgwzwIa1PqCR+0bbi6s8 CwVw== 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=UQgQUXH6/e3P5T+GBMNREsegS1VF3JwCWSwgCegxL1I=; b=VNxGcwtjTnCrgTXqsf6Wv46qbZnYp0PsVmwmTKIqV1suQkBSwy6eT6O8wO+CuqoTSE j984yRB+HDIB9VLqAP6qQsrwKp/shbj9YdGsTjz4XNXgQgLCw4R2kvtDJJKXJKsiM9K2 WFGi6LlmWqAILA40mhIUpGF5pl4IGKEXBRjcBN4pn0aYRTpgbt9He+76F7ITAr8bOLsJ wDibecVDOG6t4VeFnRvt1ZXAyHQy9RJNihe25RJlz3Now32dLsoU1wEwxVdnlW7QqMqp 3nYGRiAaprXNocOXf4LgsM7Ywwv/mYlNHsWnIqu+tYiYUNvudkBabkQAuNuJ/Ef0476Y B6sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ovv5H9BB; 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 ci17-20020a170906c35100b006e7f31adf04si7229309ejb.442.2022.04.18.18.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:06:47 -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=Ovv5H9BB; 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 D9DDC83D92; Tue, 19 Apr 2022 03:06:16 +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="Ovv5H9BB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D103583D07; Tue, 19 Apr 2022 03:05:58 +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-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (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 610D783B4E for ; Tue, 19 Apr 2022 03:05:54 +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-x530.google.com with SMTP id q12so21956433pgj.13 for ; Mon, 18 Apr 2022 18:05:54 -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=UQgQUXH6/e3P5T+GBMNREsegS1VF3JwCWSwgCegxL1I=; b=Ovv5H9BBmdwMPMMt5Gqn6iyTqp/2LIA3TBeivaPVUWGSbmC5Q5JjuFy1T/bL3lbo8d 79rVXp0puO4gzmEUTRWmK7ZSekvuCyNP7rDO/y1wRX3hu0JuDaz3YQnjt1nRGPtr20DN bZsvWaDmtJ4nHKQBKIJ7b40dcUpqKCcH7gmuThcNeZdbwb6Ichg0eN0W1mc78qNHDsI2 qhYjS05cJHERXxICBZmYqsfKU41diDlPE2kxemkhGN3e192olr6sCXP2oycqkVKgjDeZ HdxZEd5CPkzIM0Yu1vSOhqU6cURd3DzJfddFszZ5MgTmR0V0Wr+p6JdkvvBn2BLYg9bI NwSQ== 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=UQgQUXH6/e3P5T+GBMNREsegS1VF3JwCWSwgCegxL1I=; b=1h0YdEasGPjuHcezmkiUjR1VGxs6NpTNXVp/S+kxDGIemSxoavbkObY8VL09nB5Edy rgVUbTslS3STm0vHfLfvbvQVMg4It5XXK3V0g/W/BoyrTi8UMLfr85DWWDt8jIA7fR4D GEhOqyDkutwHADh//4Wp9vcvYVZTGGR1Udd2/dKTgCUFWn05VW9NqLPIXmeSeM2Bbv77 T5noiBut0WpQN58LpGgYT2L1HTFr26pfyY/rIwXM5HVgSoL7RGqi48STHiqcYup7k5p5 DURopktagn48cL1cH+ytThIe07VNnKVRgew6NZtTMstQ3UXRQuc4iQfwsC0zooqWeVWA VfEg== X-Gm-Message-State: AOAM532G4aWAamanKh3nzsWAGB7lF8Ghu6Ui+yqbSMu6OY3S8AJMaQqc vjy7NZOzFozx707pWfLSZi1odQ== X-Received: by 2002:a63:4862:0:b0:385:fb1d:fc54 with SMTP id x34-20020a634862000000b00385fb1dfc54mr12467966pgk.57.1650330352795; Mon, 18 Apr 2022 18:05:52 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c3e1:100:5858:d3a6:5cad:ceeb]) by smtp.gmail.com with ESMTPSA id k137-20020a633d8f000000b0039800918b00sm14043756pga.77.2022.04.18.18.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:52 -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 v5 06/12] efi_loader: split efi_init_obj_list() into two stages Date: Tue, 19 Apr 2022 10:05:11 +0900 Message-Id: <20220419010517.47175-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220419010517.47175-1-takahiro.akashi@linaro.org> References: <20220419010517.47175-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 c52ea59ec7ae..5bb8fb2acd04 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)