Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA32BEB64D9 for ; Mon, 19 Jun 2023 21:24:35 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 87EA0861AA; Mon, 19 Jun 2023 23:24:12 +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="wLCwYDZo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A66DE862E2; Mon, 19 Jun 2023 23:24:07 +0200 (CEST) Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) (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 A11A386181 for ; Mon, 19 Jun 2023 23:24:04 +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=raymond.mao@linaro.org Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6300510605bso21136556d6.0 for ; Mon, 19 Jun 2023 14:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687209843; x=1689801843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=srWPAS+gCw2uoZMzXezbpwAh2wCNQj/pANl/zH2EHls=; b=wLCwYDZoGDd1InxPkBG5t8vHOUTulz9awBei3nkSHFSqSjUBChUq19K7ep5KfFgKFk 2/2ZZhszo7JGUXyeCXa44k0eb5jfEBhEOI6DPdi7MiU58VANWtrceO8HaOtfAYPEHddB JA/FjwA84RRDDA9+ami5R88wLwjgRWWXhdjVTb6AznIdjD++4uMGJqTLekQNW0PssY44 37f2abFDV95Z54+u6u+gEMbfoE+qxvltGtzgD1CjYkgzhhFSWKhuYTLY5AfQwg8Z3SoT DAANZoeo6p1eHO9KUTp4rvS/Z29GJQ/0O6toL3qYrYEW8PrrqJQ94Zg791np9/ddCJF5 8jpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687209843; x=1689801843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=srWPAS+gCw2uoZMzXezbpwAh2wCNQj/pANl/zH2EHls=; b=Jg0QdKbAypC40KEIYNrmheOZroJlNXQJfbr2dCU3ko+swsYUXZ3C8iUB1FKNSO3oTN KdUIibXCLQ/QwNRYt6dJHXQn97dbEw3jlD1wewomiiUIHULm3WYxJpG78t7lQqReVCDt MKF/TIN1SE3hQcBkmTPcoiuB2Zbth+AGhg8Bu7Ub8Htyb3zffABFga9rZHIUP9dofT2d C+u+pmCjM948RmswnNqobizhOAyZL+IB7arZOfkxEQZm5WzRmgdHaWHCWZyKOVZpp9Ud cyYVYXquKWSca5vaPdQ9ISrTSXR+LD6VqsaJqE7lNwZLAyWEMKFctln3MJfm2JVVK7PO gXrQ== X-Gm-Message-State: AC+VfDy6PcbEgHtmQE7SuitU/cSucr74Krx9bd5IWczsmpgHCYp1EWTf B45rJwlJaMISs8+xxlhRGJ77pWgfnDRutQ7KmFI= X-Google-Smtp-Source: ACHHUZ6JFsT7P6zAenLZg2SB4gwWmhLCiMdO47HoxpJIGdu/uU+Ns6W2k5ZKvcFWvDym+2N7khuBlA== X-Received: by 2002:ad4:5b81:0:b0:628:4d91:78af with SMTP id 1-20020ad45b81000000b006284d9178afmr11959216qvp.62.1687209843223; Mon, 19 Jun 2023 14:24:03 -0700 (PDT) Received: from ubuntu.localdomain (cpe688f2e182063-cm688f2e182060.sdns.net.rogers.com. [174.114.251.9]) by smtp.gmail.com with ESMTPSA id e8-20020a0ce3c8000000b005ef442226bbsm412407qvl.8.2023.06.19.14.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 14:24:02 -0700 (PDT) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima Subject: [PATCH v10 3/4] Boot var automatic management for removable medias Date: Mon, 19 Jun 2023 14:23:00 -0700 Message-Id: <20230619212303.128288-4-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230619212303.128288-1-raymond.mao@linaro.org> References: <20230619212303.128288-1-raymond.mao@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.8 at phobos.denx.de X-Virus-Status: Clean Changes for complying to EFI spec ยง3.5.1.1 'Removable Media Boot Behavior'. Boot variables can be automatically generated during a removable media is probed. At the same time, unused boot variables will be detected and removed. Please note that currently the function 'efi_disk_remove' has no ability to distinguish below two scenarios a) Unplugging of a removable media under U-Boot b) U-Boot exiting and booting an OS Thus currently the boot variables management is not added into 'efi_disk_remove' to avoid boot options being added/erased repeatedly under scenario b) during power cycles See TODO comments under function 'efi_disk_remove' for more details Signed-off-by: Raymond Mao --- Changes in v3 - Split the patch into moving and renaming functions and individual patches for each changed functionality Changes in v5 - Move function call of efi_bootmgr_update_media_device_boot_option() from efi_init_variables() to efi_init_obj_list() Changes in v6 - Revert unrelated changes Changes in v7 - adapt the return code of function efi_bootmgr_update_media_device_boot_option() Changes in v8 - add a note in the commit message for future reference Changes in v9 - amend the note text in the commit message - add a TODO comment in 'efi_disk_remove' Changes in v10 - fix typo and build failures with 'CONFIG_CMD_BOOTEFI_BOOTMGR=n' lib/efi_loader/efi_disk.c | 18 ++++++++++++++++++ lib/efi_loader/efi_setup.c | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index d2256713a8..911a4adfb1 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -687,6 +687,13 @@ int efi_disk_probe(void *ctx, struct event *event) return -1; } + /* only do the boot option management when UEFI sub-system is initialized */ + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR) && efi_obj_list_initialized == EFI_SUCCESS) { + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + return -1; + } + return 0; } @@ -773,6 +780,17 @@ int efi_disk_remove(void *ctx, struct event *event) return efi_disk_delete_part(dev); else return 0; + + /* + * TODO A flag to distinguish below 2 different scenarios of this + * function call is needed: + * a) Unplugging of a removable media under U-Boot + * b) U-Boot exiting and booting an OS + * In case of scenario a), efi_bootmgr_update_media_device_boot_option() + * needs to be invoked here to update the boot options and remove the + * unnecessary ones. + */ + } /** diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 58d4e13402..69c8b27730 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -245,6 +245,13 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) { + /* update boot option after variable service initialized */ + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS) + goto out; + } + /* Define supported languages */ ret = efi_init_platform_lang(); if (ret != EFI_SUCCESS) -- 2.25.1