From patchwork Thu Feb 16 16:30:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 654044 Delivered-To: patch@linaro.org Received: by 2002:adf:9bcd:0:0:0:0:0 with SMTP id e13csp62483wrc; Thu, 16 Feb 2023 08:30:53 -0800 (PST) X-Google-Smtp-Source: AK7set8CnkNexKj1If4WULo3Y5/lFsCBnqcdkd612EH/0kOKV8fCbR6LRXttUrF2/47A06u37iQJ X-Received: by 2002:a05:6870:80d1:b0:163:bd7f:bc27 with SMTP id r17-20020a05687080d100b00163bd7fbc27mr3840328oab.6.1676565053623; Thu, 16 Feb 2023 08:30:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676565053; cv=none; d=google.com; s=arc-20160816; b=fWC2dcpPggs5EDv1ltLcn+8+MEjBQHS6cGDiSHqu1ZJ/uqnnKilnVeyFnGIt6F6Aox vHIK17mNZO5KryIO4F5a4aTbwfiNC9EClSAIuMu+lIScoREY5zBo5pqn9/L8zF6ZE3hV D7Z3iRnhAcptZ6QRttyVTY8UTOkSCODA6DcXhlu5bkmwdE2LxwIvXxZGT4Pv1aPHUIyT zn4/RkIdXeQL2N2ff6B/R3otbZmQCt2xa4xRlMaPDAKNq/9sEQdnvlQ4tgT/DUJhA221 n+teGV6wLScgQPYWNjJk01YiAVohETaC7tGnTW6yRl57IWtZ+MZvwQ478HGMCZrKiClX Rf5A== 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=kuo/U4HAYC6xYMqri8y+rYYL/jx1LrqfPOv6o3xtSjA=; b=ivCS8tsiZYI7zUC6EOckjJmsaCOIDnPC41I5dWxjJX4wHmmMFXpTkqZaaZJarb9gsX ZD1rQulLxiMuA5PyLvN2UsFx4rTrIOhfXCpy0dKwuJ78u2Yh4bopVyIG9Qc9+2oWytyh 95DXbw7uRblkTMuYodXJ8on6ZQyz59EaZxKlVlhW/XnRnv+n/FAYK+xkNtk9HpnUshOu ZftUNi+OA4OKNwnCIbUlXQsZHPDVSaHfPKza5ABvSeGmNVuidSbEi1UVJvEYTTp4mTxR F3B5G6PiSSpNrBUnvIT384LxjOnUdDdCKtA5IplB9SUQN5OD/bGcMs7kJCZfYbHZulSa Te/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pT8hwVv1; 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 21-20020a056870005500b0016e119f8499si2511062oaz.70.2023.02.16.08.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 08:30:53 -0800 (PST) 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=pT8hwVv1; 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 1CD4A85B7A; Thu, 16 Feb 2023 17:30:22 +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="pT8hwVv1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6B69C85B77; Thu, 16 Feb 2023 17:30:15 +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-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) (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 E98B785B75 for ; Thu, 16 Feb 2023 17:30:08 +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-x535.google.com with SMTP id u21so4990455edv.3 for ; Thu, 16 Feb 2023 08:30:08 -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=kuo/U4HAYC6xYMqri8y+rYYL/jx1LrqfPOv6o3xtSjA=; b=pT8hwVv18BdxOGzXS5Q6LbrU7hO/D03pGXChxwo4oFZ8FxiiwXxS8VD7q9iE6IH8Q2 Tcg5dIKUWn7f4tW6sxJHBBP3scG0ew0nAb3CQ2EKikK1S7UNWpNUoo4RrP7VL51YsQ16 zWzU6C0cdJ3XqkdAJJMO8KFOREkpozVpUaltT/bvqxDSFZcMNkWItmDlpQKXEzozfgHM 0TesKQAzNmeUS2CcPqgAfWeox1IVJ6u+LT5z6ohh8dOECuX5tW9CqjqD2hFap8kNp150 8TH39tAwRPUQsZMMeIQ+ieKQbfg0RlqrY8Onk3KCCbmep+mWYyX9vZuvOf0elnp1BX1R E6WQ== 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=kuo/U4HAYC6xYMqri8y+rYYL/jx1LrqfPOv6o3xtSjA=; b=OeHcDX0p+2maU1RR5T9AsgZFI9finXCNFX0ZhHVFpRKtkXmHaE6UqS52c3yB2LYB5p 5Dst52qQL48lrVbmhwpz/SIM42iJcba+YnllUy2++brw7/E3UQDQ/A3y5JRiHrDoXW6y PpY14i5YAOsBJE+sE1sn9v0JREq2LV1/lY2XgAAz/qntFWMaXEj46MlaD2edh/0+zHYe IRaUIxEsZ+n5eczUehN0gaubvKbFV52xIuOdWbceqFrbpCBDcN75iFeYicGCcGOAxrXj L0+LLP/Y43Y85Jelf/hiMX5nWE2QZt4cfOetWbd7l9nRdwmHBYCM+3eTM2SVu2cn+MPu eXnA== X-Gm-Message-State: AO0yUKVVy3X6mkoOhzUJEQeqrE3O4ExLQrPORGE7ZhUrDzov0uE9vC1X tC2YBHVa8Qjv4zuAT4Tok8qLqfVCSzhFszY2 X-Received: by 2002:a17:906:d932:b0:8af:9c84:9412 with SMTP id rn18-20020a170906d93200b008af9c849412mr6468483ejb.71.1676565008176; Thu, 16 Feb 2023 08:30:08 -0800 (PST) Received: from lmecxl1178.lme.st.com ([80.215.224.41]) by smtp.gmail.com with ESMTPSA id lt13-20020a170906fa8d00b00888d593ce76sm998944ejb.72.2023.02.16.08.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 08:30:07 -0800 (PST) From: Etienne Carriere To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Etienne Carriere Subject: [PATCH] efi_loader: set CapsuleMax from CONFIG_EFI_CAPSULE_MAX Date: Thu, 16 Feb 2023 17:30:03 +0100 Message-Id: <20230216163003.2343218-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 --- 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..69bb66e09c 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 65535 + 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"); }