From patchwork Thu Feb 16 17:21:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 654076 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp90163wrc; Thu, 16 Feb 2023 09:22:00 -0800 (PST) X-Google-Smtp-Source: AK7set8Y1hdEjndR0+lUZQV7QMI04ZabJ72cdaSFOBvUNCQfSgCOYlQe6lTQAmfhSWXaffBd0T2y X-Received: by 2002:a05:6871:71f:b0:169:b676:d643 with SMTP id f31-20020a056871071f00b00169b676d643mr3699723oap.59.1676568120300; Thu, 16 Feb 2023 09:22:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676568120; cv=none; d=google.com; s=arc-20160816; b=jgKYANs/10k+jZ4BQ2FL4LphKtqReLNMeqZ4R1cvA3YNPObLLVGNjiTtmQJsI2kRoy WogoyT2Bj4PjKnJosBAEGwDpQOAmoZL12fKswo8f8kY8Y23A8bRp8i0rTKOOJb/T7yoP qjayR/Kl+sq6lbIUw6GRB1XMnyqPXEVSxM/xYdaxsJytq17AYimu1hPn9IZ56QXXL6kk GA4GAqQpnnB+YcVWYyKaoYBMpDylW31HKPS3q0hSf+Buky7UTHhcngrVV7cTu16+AkP1 VIktIYqDYgGd3WKm1YqLEuI3Bt15Wk+OyxaRBocqzTZGjIHS9KbvqBViMwacNpYOKvL8 +X2g== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=9sNJEDG8/I33h8B3bJMX77dneudUszEJUOA39yWKw4c=; b=Iq2AOjY2bPbmZ2eSZ1pAJUUGjc3mnzdWB50uVZYZj1Oh7+BQRpgAsyX7xCYrULnI+g MvOgF/dCyuaE+BBHM1z5xMaAUtgTo71DNi+Hitn94dMFBXeXO2rRAskdZi5G8x63H5Ue nwXBE33/znk4GRNsOqXuEgz35Q1dgHIXtdp06yLAPi3gKzFGfGDRe6Y+GPfi/csYiG0d AeMU1RNAGYZ+/lLSqSRWeS4rrNZDm5U2FZS9wcrK48cor4eXdenlMNyQbl7qEGZTG/RZ WRk7kQtunkHjZy9C/+P9nP/gOCZb4WT/xRN2GspBqFRPlcozVY/VdS3QZZ3Y0nt+oP7q bYlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C94xch+5; 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 xt6-20020a05687185c600b0016e3845cc25si2259586oab.316.2023.02.16.09.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 09:22:00 -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=C94xch+5; 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 028CE85B77; Thu, 16 Feb 2023 18:21:55 +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="C94xch+5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3FFEE85B7A; Thu, 16 Feb 2023 18:21:53 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (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 0896285B27 for ; Thu, 16 Feb 2023 18:21:50 +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=etienne.carriere@linaro.org Received: by mail-ed1-x52b.google.com with SMTP id a10so5513071edu.9 for ; Thu, 16 Feb 2023 09:21:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9sNJEDG8/I33h8B3bJMX77dneudUszEJUOA39yWKw4c=; b=C94xch+5sIvae9zRFLD3zyyyBx+3gOL34gfE8VcsB7glQUMJ93dFLu+IVjk21m2o5i 0KCCsIwINmgdXBv1l35AcxI0tvH4n2JFD68m0RuuK+1YqiqWqOdSZ41U7tAFAjeVqANZ a9TLk7nLDuA7blU/yFE9X3a0x8BW9WMqNY6bXKKlXE4Zse05uXYveWLehqmRGzmc1xik godf4WwSdqM/P/Q+JXM9shcArYYILNAw4xIUfuZGCIKHblR+7S8OX7QJIpSJCdk/ixtf UHhWSoJ6A8pPasArBXWsgxLJAiOOT5LeFlzSvjBRnjMubQrZud8+P5kjNHKtToABeFYs fimw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9sNJEDG8/I33h8B3bJMX77dneudUszEJUOA39yWKw4c=; b=ME0ZtIo65+5+IrhMZ4w5gRAoiUIiOsxdPjj2JkUoHsrS33vm90SbXe37pcrpBXn4F3 fkGH3+uk7lvVJxgA8fgY/6NK4SmHQbQ81GbqJhSpmeoyztgM3gPJFvpPan+lSol19qEq PQ1Ao1lJ7ofShfuqIuPhBwBZ7SgyFEo43CDl1kvfO1cryXsHWQ9aIwaei5SNX1GfqkJx HzFAFjRgsz/5DwUE96k1JOs37nkASAWfjm7N8IijJIpBDVsP4LIZqCOqwjSlfgtTPI2a e3HqlyiSJHil01/27JsJ6F7qiukk6cnfyKZk5J/s4DetNR1n9t3H9iqD7wsx0X97BRlY tUBQ== X-Gm-Message-State: AO0yUKWv36jpYlnh+fFPjZRi2vrbkltXtLwcISDA4pCaqg9D7yXjf2Qy BRjy+dJm8Yx/Y1xmYSRVByAhHWj6va65aufw X-Received: by 2002:a17:906:9455:b0:8a4:7fb9:5658 with SMTP id z21-20020a170906945500b008a47fb95658mr7790830ejx.55.1676568109233; Thu, 16 Feb 2023 09:21:49 -0800 (PST) Received: from lmecxl1178.lme.st.com ([80.215.240.33]) by smtp.gmail.com with ESMTPSA id t19-20020a1709066bd300b008b133f9a197sm1028383ejs.198.2023.02.16.09.21.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 09:21:48 -0800 (PST) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Etienne Carriere Subject: [PATCH v2] efi_loader: set CapsuleMax from CONFIG_EFI_CAPSULE_MAX Date: Thu, 16 Feb 2023 18:21:41 +0100 Message-Id: <20230216172141.2357759-1-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 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.6 at phobos.denx.de X-Virus-Status: Clean Adds CONFIG_EFI_CAPSULE_MAX to configure the max index value used in EFI capsule reports. The config default value is 65535 as the index max value used before this change. Platforms with limited storage capacity can set a lower configuration value to prevent storage capacity overflow or even waste of storage space. Signed-off-by: Etienne Carriere --- Changes since v1 - Changed CONFIG_EFI_CAPSULE_MAX default value from 65535 to 15. --- lib/efi_loader/Kconfig | 8 ++++++ lib/efi_loader/efi_capsule.c | 48 +++++++++++++++++++++++++----------- lib/efi_loader/efi_setup.c | 7 +++++- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index c56904afc2..727241dc9c 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -226,6 +226,14 @@ config EFI_CAPSULE_AUTHENTICATE Select this option if you want to enable capsule authentication +config EFI_CAPSULE_MAX + int "Max value for capsule index" + default 15 + range 0 65535 + help + Select the max capsule index value used for capsule report + variables. This value is used to create CapsuleMax variable. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 0997cd248f..d5d3ede7ae 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -45,17 +45,7 @@ const efi_guid_t fwu_guid_os_request_fw_accept = static struct efi_file_handle *bootdev_root; #endif -/** - * get_last_capsule - get the last capsule index - * - * Retrieve the index of the capsule invoked last time from "CapsuleLast" - * variable. - * - * Return: - * * > 0 - the last capsule index invoked - * * 0xffff - on error, or no capsule invoked yet - */ -static __maybe_unused unsigned int get_last_capsule(void) +static __maybe_unused unsigned int get_capsule_index(const u16 *variable_name) { u16 value16[11]; /* "CapsuleXXXX": non-null-terminated */ char value[5]; @@ -65,7 +55,7 @@ static __maybe_unused unsigned int get_last_capsule(void) int i; size = sizeof(value16); - ret = efi_get_variable_int(u"CapsuleLast", &efi_guid_capsule_report, + ret = efi_get_variable_int(variable_name, &efi_guid_capsule_report, NULL, &size, value16, NULL); if (ret != EFI_SUCCESS || size != 22 || u16_strncmp(value16, u"Capsule", 7)) @@ -84,6 +74,35 @@ err: return index; } +/** + * get_last_capsule - get the last capsule index + * + * Retrieve the index of the capsule invoked last time from "CapsuleLast" + * variable. + * + * Return: + * * > 0 - the last capsule index invoked + * * 0xffff - on error, or no capsule invoked yet + */ +static __maybe_unused unsigned int get_last_capsule(void) +{ + return get_capsule_index(u"CapsuleLast"); +} + +/** + * get_max_capsule - get the max capsule index + * + * Retrieve the max capsule index value from "CapsuleMax" variable. + * + * Return: + * * > 0 - the max capsule index + * * 0xffff - on error, or "CapsuleMax" variable does not exist + */ +static __maybe_unused unsigned int get_max_capsule(void) +{ + return get_capsule_index(u"CapsuleMax"); +} + /** * set_capsule_result - set a result variable * @capsule: Capsule @@ -1290,7 +1309,7 @@ efi_status_t efi_launch_capsules(void) { struct efi_capsule_header *capsule = NULL; u16 **files; - unsigned int nfiles, index, i; + unsigned int nfiles, index, index_max, i; efi_status_t ret; bool capsule_update = true; bool update_status = true; @@ -1299,6 +1318,7 @@ efi_status_t efi_launch_capsules(void) if (check_run_capsules() != EFI_SUCCESS) return EFI_SUCCESS; + index_max = get_max_capsule(); index = get_last_capsule(); /* @@ -1317,7 +1337,7 @@ efi_status_t efi_launch_capsules(void) /* Launch capsules */ for (i = 0, ++index; i < nfiles; i++, index++) { log_debug("Applying %ls\n", files[i]); - if (index > 0xffff) + if (index > index_max) index = 0; ret = efi_capsule_read_file(files[i], &capsule); if (ret == EFI_SUCCESS) { diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index f0f01d3b1d..04da4cf14d 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -129,12 +129,17 @@ static efi_status_t efi_init_capsule(void) efi_status_t ret = EFI_SUCCESS; if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) { + u16 var_name16[12]; + + efi_create_indexed_name(var_name16, sizeof(var_name16), + "Capsule", CONFIG_EFI_CAPSULE_MAX); + ret = efi_set_variable_int(u"CapsuleMax", &efi_guid_capsule_report, EFI_VARIABLE_READ_ONLY | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - 22, u"CapsuleFFFF", false); + 22, var_name16, false); if (ret != EFI_SUCCESS) printf("EFI: cannot initialize CapsuleMax variable\n"); }