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 B959EC77B75 for ; Tue, 23 May 2023 20:10:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F2C7485EE5; Tue, 23 May 2023 22:10: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=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="SxZ2BBZR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0C7E185FF3; Tue, 23 May 2023 21:27:33 +0200 (CEST) Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) (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 87C2085DCE for ; Tue, 23 May 2023 21:27: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=raymond.mao@linaro.org Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-3f392680773so510931cf.0 for ; Tue, 23 May 2023 12:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684870049; x=1687462049; 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=llWvz/VPU3kNfdzNmnSXtJGdb+Z9/SODoaLLvaLS26o=; b=SxZ2BBZRGNRE8vpWxaUjMSWmkrx9hRxYSJpktvKaQL2bE5is4seOuUsDfXdk9AA4H3 qreizTQ80qVilk/NTJVtydzJTaNStYpr6MjQlEV/3iAE9mKhLmTgjC+JQDPV2p0G0vf1 u8JHVGC/qF0yqbnNRb4LX5mg23AJT8Uqv37Xs/SMXdlfapoRgEX/MLg4DhuoITLBq38e 9P2/e7OFgwruTOrxSJukUsHYlgCG5KvWrK5gUuhsQaeOGv6ujtxMA5rBqfSeWpnu2Vq7 n5eQTZqrsZ72hncb/azWK5VPfFHEsx+jgRqNd42sEhBCkhNPH186WQM3HRHgbLnBBwo/ hYGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684870049; x=1687462049; 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=llWvz/VPU3kNfdzNmnSXtJGdb+Z9/SODoaLLvaLS26o=; b=L8K5wsNXlqTe8KSz23Xd76oaS25bTS2Aw4OJkJ6apjyJBQ/tddU7Z1EShSzuxcagel 44V7y06OuDPJ8CfPcG2UvHd3jW8upHWuodCQ0VHt841jTlGFgZsJyU/YRvVftDixOs2W oAgrEYcQAZdzB9JzH21c6Q/ITLFXrsT4sC2PJ7PPaWld18RLqGc6aBE39K5P/uS8VvN0 nKZIH4cZiQgZLi5qhx+0PCqPn9aIQw1ET6h6ClaY0PkjXO8ooj6fTXOvbuHcztX5WP4+ 4yFp1tMwOV3rmmQzI5Vb6cgQjZpEORDo9LtK6zKy6oaKXEw4YMjGEUbNvTUt+IMqxGBY wx8w== X-Gm-Message-State: AC+VfDzXJSfy9NkYgWTgQ19IYhHlt66LBMhgdp8iKAjswuGXKM1ogOyO he9l2dyYZaKxqBwz6kCteiNHl8hY0pNYUBldb7Y= X-Google-Smtp-Source: ACHHUZ7KY1WNBgw6s8I0y/nJqtEraAuC94bg5+Wy83EQYnGMp6oHp657mFD0JGNhbeiVQQ8M8oi2nQ== X-Received: by 2002:ac8:5a4c:0:b0:3f3:8ddc:d760 with SMTP id o12-20020ac85a4c000000b003f38ddcd760mr20729834qta.12.1684870049096; Tue, 23 May 2023 12:27:29 -0700 (PDT) Received: from ubuntu.localdomain (cpe688f2e182063-cm688f2e182060.sdns.net.rogers.com. [174.114.251.9]) by smtp.gmail.com with ESMTPSA id mn21-20020a0562145ed500b006212a3d8cc1sm3017921qvb.32.2023.05.23.12.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 May 2023 12:27:28 -0700 (PDT) From: Raymond Mao To: u-boot@lists.denx.de Cc: Raymond Mao , Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima Subject: [PATCH v4 2/3] Boot var automatic management for removable medias Date: Tue, 23 May 2023 12:18:20 -0700 Message-Id: <20230523191819.80258-2-raymond.mao@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230523191819.80258-1-raymond.mao@linaro.org> References: <20230523191819.80258-1-raymond.mao@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 23 May 2023 22:10:27 +0200 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. Signed-off-by: Raymond Mao --- Changes in v2 - Ignore EFI_NOT_FOUND returned from efi_bootmgr_update_media_device_boot_option which means no boot options scanned. Changes in v3 - Split the patch into moving and renaming functions and individual patches for each changed functionality Changes in v4 - Revert the change of introducing a bool parameter when updating the boot option. Use short-form of device path by default lib/efi_loader/efi_disk.c | 7 +++++++ lib/efi_loader/efi_variable.c | 10 +++++++++- lib/efi_loader/efi_variable_tee.c | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index d2256713a8..ca5f07f2ec 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 (efi_obj_list_initialized == EFI_SUCCESS) { + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND) + return -1; + } + return 0; } diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index be95ed44e6..fe71144358 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -476,6 +476,14 @@ efi_status_t efi_init_variables(void) log_err("Invalid EFI variable seed\n"); } + ret = efi_init_secure_state(); + if (ret != EFI_SUCCESS) + return ret; - return efi_init_secure_state(); + /* update boot option management after variable service initialized */ + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND) + return ret; + + return EFI_SUCCESS; } diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index dfef18435d..2995d4a583 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -748,5 +748,10 @@ efi_status_t efi_init_variables(void) if (ret != EFI_SUCCESS) return ret; + /* update boot option management after variable service initialized */ + ret = efi_bootmgr_update_media_device_boot_option(); + if (ret != EFI_SUCCESS && ret != EFI_NOT_FOUND) + return ret; + return EFI_SUCCESS; } -- 2.25.1