From patchwork Thu Feb 10 08:11:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 541408 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp2039751imo; Thu, 10 Feb 2022 00:14:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0EQVfAoKjSrNd0pwna3yWrqyB/VzZJMFgNO4eqwd/YMionVxvKiTLRtyFc6NDrruH3v54 X-Received: by 2002:a17:906:c14d:: with SMTP id dp13mr5623705ejc.188.1644480896978; Thu, 10 Feb 2022 00:14:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644480896; cv=none; d=google.com; s=arc-20160816; b=S74s4fF5O/3eadhaIwlYTSfAUyqVe6N/AqiZtdGFnEtwMRtYPjtmvBZ1H6af9fScT8 NNmMJBaC5bLXFpFN4Ra7RGV1VzPbvD9gWVY4XERptZYyJl59bl40b/6q7q10PbqHi2SH zaYEXlqRtFXB4MnMLItP0L9/pNdS9MXFOyyb4OckPpEoQI12jqLV+lJ98PVNqWZUqGZ5 eD3rLbfwvZ/yNzafueMdn0fRWI4+y1MV9w+Eg/1fBqq3R/rxKGHLSvPeq45mi3R44kZ3 0oQOZDRHCD5CwoKhr3iFg58U8tKVHNSUEkdqFXttuhzDH53xNNeA++NeymViAFabwOfR 1uUw== 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=PU1xvhXim6h4QTgvNe88h+8+FqTOVNivCMssvdV35uU=; b=1DPFhcN7tsNPi5fxNi8gHo65Ttk2NP8JxGA8sxFWd45IndF2IwbDFZk93w9sMXhrlI fox40k8SE6NA62XqXqlOIP6krM7WL+IyPJT3P8TnThXyk+ULsrPclThmDEGycfM1BaK1 ifxsXye3hebcNdv7G//ri3iGmEUCGGcH7RSt2PtILQq/6/wsIp/ws0IhnzWkYifwmQzg 0GHgDSXs9OJi/QDiUz8FUw/Aqw3cUuwp38Alr+GGQCrkz1uJ5PZu8640zbzGggqJ6Sqa 6fYuDxTevekEQCg7oLbrd6Wd0F7cW8rG9NXNBiCTOk7CDBrTbTAyhL01GTU7d9qJHKZk urXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="rya4iB/C"; 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 qw2si2772331ejc.267.2022.02.10.00.14.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 00:14:56 -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="rya4iB/C"; 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 E5E9783A08; Thu, 10 Feb 2022 09:13:45 +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="rya4iB/C"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C510283041; Thu, 10 Feb 2022 09:13:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 9CB378319C for ; Thu, 10 Feb 2022 09:13: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=takahiro.akashi@linaro.org Received: by mail-pl1-x629.google.com with SMTP id y17so1185656plg.7 for ; Thu, 10 Feb 2022 00:13:04 -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=PU1xvhXim6h4QTgvNe88h+8+FqTOVNivCMssvdV35uU=; b=rya4iB/C6es2VMaIez0DzKvsC5zo2rWM034U98GUp7EojmgQiOqNXOijddAeXU4eHv U95GkASZDLo+R11a6zP4b3vL8HYHGmht3sY+OOgG2k6y+eeZ8H3OR7rK6/OUqhpJSdu2 6YAtvh/xxQOFlx82h07l1trXmMnsuK5NNUUlOdj5YY7VEhNO74WBIli3vjpsHDDybJkR eFSsCxQwV86xGQm6LJpZjQ4pwlz5BhKHj42uU//M5eYHa5M0TtMm8aLC6AJgS3uuoUp/ hofq54aWTWwzGNPakkKy/ie9IwO7+RcT5dgxUm1H5ef5emRU65YKRzRM9L54PoYh7kiB 0RFA== 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=PU1xvhXim6h4QTgvNe88h+8+FqTOVNivCMssvdV35uU=; b=S7L9LWdOa5uoklunAr1Y1WsVKhF18YccvdCrxnH9loM2VFesuQbtTae4NHxWWM6ala dRGnb7HWsmv17ZO0DRgpbOCOq7U3lQ27OHZzYweOqcLVI35xzIAxn7vGsGveO/68ln5l 6RbZBppomYqucAobfG4DYO5hXlfsvdN/mFmilEHKWaWXPZMpl5xp4x7LhZ+aubaN1KGV qMkMznCvpsUfx3C+6Pem8Kv/5EPN00pbPK0Q52FrW1Mf6PnGewyKo6NwjUpr/kgtcuF8 2dNFnbA0IuInlj/+QmaAcQBxy7nxPnBkzPcJI2Ocvz18EGbqGDRZQAUT4nSxKT6PUBdy c/1w== X-Gm-Message-State: AOAM5326qP0nqbJ1+L5zpgMPHi/UN87MSpIqU3HQaGOXYoGg+Aj+jnQl 5WIiNSSKS70ULlTqTtrL8dZyPQ== X-Received: by 2002:a17:90a:601:: with SMTP id j1mr1594148pjj.192.1644480782618; Thu, 10 Feb 2022 00:13:02 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:412e:384:fab9:f24]) by smtp.gmail.com with ESMTPSA id lk8sm1529208pjb.40.2022.02.10.00.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 00:13:02 -0800 (PST) From: AKASHI Takahiro To: lukma@denx.de, peng.fan@nxp.com, jh80.chung@samsung.com, bmeng.cn@gmail.com, peng.ma@nxp.com, sr@denx.de, 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 v2 14/20] efi_loader: split efi_init_obj_list() into two stages Date: Thu, 10 Feb 2022 17:11:18 +0900 Message-Id: <20220210081124.86612-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220210081124.86612-1-takahiro.akashi@linaro.org> References: <20220210081124.86612-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 c24d9b4e220b..7b004b8ae9af 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -789,7 +789,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 4e50f2d0c368..58b661d5c4c6 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -491,6 +491,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 380adc15c886..74b4d2623f88 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)