From patchwork Wed Apr 17 10:19:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 789312 Delivered-To: patch@linaro.org Received: by 2002:a5d:4dc5:0:b0:346:15ad:a2a with SMTP id f5csp204725wru; Wed, 17 Apr 2024 03:20:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUcbPYd2lLOy6/RIF058Frm2HRt4+Ko6IjSFllLHoLdgVwrz8swMpo4CJTjwRlGxH4+0zaPxQ1DTMhHDkaVv6JT X-Google-Smtp-Source: AGHT+IGfn4ZLkFDf5/iUVXdi/xkWyqj2NVYm6NGxWt2Ft7sAMcu4+6kJXRwjtDKyTDcPmTFEwdef X-Received: by 2002:a50:cd83:0:b0:56e:2273:6548 with SMTP id p3-20020a50cd83000000b0056e22736548mr10191758edi.8.1713349222437; Wed, 17 Apr 2024 03:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713349222; cv=none; d=google.com; s=arc-20160816; b=uWJtZSaLga2UFndENCYZQt42nlEQwRLraAB0sEskayEDJim1ZwGIp6sM1F5QvRRLDb uDeL6Glloz4mqnINRjn80PpGfOn66WbPGh19jT+YZrksyqmdKnFivzBnde4/Mv1fCLoU IVk/K0fyRW65iUDTrb2qn+eqjqzzu286h8fs0aiYBLbmgWBvzcdo2PATRJXekaHr9RXt k9T5/KceavvYmX8nOMfKVcwkVN+6s6PbgMUO4qsT+UVThmTSa7zGujg2VU51vyXLuZQ3 PyBc36ktl0M8yPLUsmS9At1bixc5s1SsXCPvgrST1A7w6yV6p3bqBxLHg5FMuuBbrj2z mvpA== 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=5mbi9CNku5RtmM+MIL6L/pSl5j85cc0WaO0GSnvMbtk=; fh=JBBHjr/RopCk7HeUJN2nEgM+qKO5PM8EJI/WLLoTcKg=; b=ltHZQrl93w3HmmM9CyYX8gkko9/cxWcx3W3mB4eDffJq69IISAxqfKuZ2D1568Q5dw vh0Eyl6i4t0sTFr29sfK/WIepvEuhDmkGgZ4/l0R0nbeCXRuFcqjPgseC7w5i3TcAe0u Y5Mun4cChmZsaQvcrUzJZzGtUfGq8hwEmGZtNLjKTvuRIyBvxFsK1rZlqBYOT74hBKCI iW96meZofUHea9EcH2y0rPlddD11y+rANsdJtCJOO7OtXmBFH470MUBBgyRTAZL3lFnY GtX5LI2GhOhr9NcgoS2TPhQzLEgotUOsD0iqaZBwzMzMgHC6GGICI/Tw/G9XokgozPvI ypng==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ybad0dnA; 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 j29-20020a508a9d000000b0056fe540f559si6571762edj.95.2024.04.17.03.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:20:22 -0700 (PDT) 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=ybad0dnA; 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 3747888476; Wed, 17 Apr 2024 12:20:01 +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="ybad0dnA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6249088467; Wed, 17 Apr 2024 12:19:59 +0200 (CEST) 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-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) (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 19BA18847B for ; Wed, 17 Apr 2024 12:19:56 +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=ilias.apalodimas@linaro.org Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-516d487659bso6533137e87.2 for ; Wed, 17 Apr 2024 03:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713349195; x=1713953995; darn=lists.denx.de; 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=5mbi9CNku5RtmM+MIL6L/pSl5j85cc0WaO0GSnvMbtk=; b=ybad0dnAKmCCm6AVHWu24AxKcxp/3R/8+jEIwhzGMrg4qBk/xXZMxmGK+eo0GGbVYW 5Gc46tK0M9UboMTa1OmqzmYD6o1cly7z3CJ7elGhY4SdJVQxj2IFNEVRAS5+OO+9LGvZ XtJs3TCufC+ml85hyeiRjJDzLFMbCedoJT1x29G8tWEw7vrse+J0CBvQVQA8FW6u6g7F sT6tlN3esVHna+B7DMvj8tk6caFXVwQEMsaYxpaZg11m3gGD5uypbKP4L/HQHpy77Esi tP0y4GZrca8Ibvh35rk85P8hXB78LB/SKpLZazeGdRc+yz/rgvftB/jyaJpEZReP2ne+ G60Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713349195; x=1713953995; 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=5mbi9CNku5RtmM+MIL6L/pSl5j85cc0WaO0GSnvMbtk=; b=s7BFDdHfiJJmeMQvqcds5E5OsoAbrWpGfVSDeDD14X9ZJz58ZCm7NreANWHQPIgP2s 3ZwKxC8Uhe4wD6AzyddmXbWtDNCcq3K+2usrnL3J0N3ZFsC+d/BLeyQG3xJWTaIdGifT iQD4n2F/F2/YHfDeRTIBenXtuD47HuWCRv4rPZWykHVK9DKbbppFxa3BVNAFs9sUxPed w7ZuBoId6F8arwNY7K/142MAvU8GWhQ+2D4J9gSJbzDNUvNXPXV+VKbGWWgULiycBEyQ 6dLxCKtybtfVRK+xJRyL6PdctXURD99M7Xcc0md4ngj49o4IQSJnIYt2HjMlQ2ytpcXb YdbA== X-Forwarded-Encrypted: i=1; AJvYcCWO2V4bfrJ4mF/D40jz2c8cqn0mV6WKo4PLGoP6q7k3dFlTg55QPMxedDQMB09pX5puj2FHHWVrqnVS8MODUQV0DMMI2Q== X-Gm-Message-State: AOJu0Ywjgt3vyQFuP6rKxE4QYQxUoNgNgHilCDj69yU4qQDgzgp49oC5 38cZVfKyK97I/a1CtzcRCjSHCG2HPeP3LSNiL33LKcHvE+uKW7z4ae+iMiOGpPg= X-Received: by 2002:ac2:4e15:0:b0:519:1eba:6381 with SMTP id e21-20020ac24e15000000b005191eba6381mr3256954lfr.49.1713349195404; Wed, 17 Apr 2024 03:19:55 -0700 (PDT) Received: from hades.. (ppp089210071137.access.hol.gr. [89.210.71.137]) by smtp.gmail.com with ESMTPSA id g12-20020a5d488c000000b003472489d26fsm13567780wrq.19.2024.04.17.03.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 03:19:54 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de, kettenis@openbsd.org Cc: caleb.connolly@linaro.org, sumit.garg@linaro.org, quic_llindhol@quicinc.com, ardb@kernel.org, pbrobinson@gmail.com, pjones@redhat.com, Ilias Apalodimas , Tom Rini , Masahisa Kojima , AKASHI Takahiro , Raymond Mao , Matthias Schiffer , Janne Grunau , Simon Glass , Abdellatif El Khlifi , Alper Nebi Yasak , Sughosh Ganu , Sam Edwards , Richard Henderson , Weizhao Ouyang , u-boot@lists.denx.de Subject: [PATCH v2 4/4] efi_selftest: add tests for setvariableRT Date: Wed, 17 Apr 2024 13:19:25 +0300 Message-Id: <20240417101928.119115-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240417101928.119115-1-ilias.apalodimas@linaro.org> References: <20240417101928.119115-1-ilias.apalodimas@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.8 at phobos.denx.de X-Virus-Status: Clean Since we support SetVariableRT now add the relevant tests - Search for the RTStorageVolatile and VarToFile variables after EBS - Try to update with invalid variales (BS, RT only) - Try to write a variable bigger than our backend storage - Write a variable that fits and check VarToFile has been updated correclty - Append to the variable and check VarToFile changes - Try to delete VarToFile which is write protected Signed-off-by: Ilias Apalodimas --- .../efi_selftest_variables_runtime.c | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c b/lib/efi_selftest/efi_selftest_variables_runtime.c index 4c9405c0a7c7..e492b50a43c2 100644 --- a/lib/efi_selftest/efi_selftest_variables_runtime.c +++ b/lib/efi_selftest/efi_selftest_variables_runtime.c @@ -10,6 +10,7 @@ */ #include +#include #define EFI_ST_MAX_DATA_SIZE 16 #define EFI_ST_MAX_VARNAME_SIZE 40 @@ -17,6 +18,8 @@ static struct efi_boot_services *boottime; static struct efi_runtime_services *runtime; static const efi_guid_t guid_vendor0 = EFI_GLOBAL_VARIABLE_GUID; +static const efi_guid_t __efi_runtime_data efi_rt_var_guid = + U_BOOT_EFI_RT_VAR_FILE_GUID; /* * Setup unit test. @@ -45,11 +48,14 @@ static int execute(void) u32 attr; u8 v[16] = {0x5d, 0xd1, 0x5e, 0x51, 0x5a, 0x05, 0xc7, 0x0c, 0x35, 0x4a, 0xae, 0x87, 0xa5, 0xdf, 0x0f, 0x65,}; + u8 v2[CONFIG_EFI_VAR_BUF_SIZE]; u8 data[EFI_ST_MAX_DATA_SIZE]; + u8 data2[CONFIG_EFI_VAR_BUF_SIZE]; u16 varname[EFI_ST_MAX_VARNAME_SIZE]; efi_guid_t guid; u64 max_storage, rem_storage, max_size; + memset(v2, 0x1, sizeof(v2)); ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, &max_storage, &rem_storage, &max_size); @@ -63,10 +69,107 @@ static int execute(void) EFI_VARIABLE_RUNTIME_ACCESS, 3, v + 4); if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) { + efi_uintn_t prev_len, delta; + if (ret != EFI_INVALID_PARAMETER) { efi_st_error("SetVariable failed\n"); return EFI_ST_FAILURE; } + + len = sizeof(data); + ret = runtime->get_variable(u"RTStorageVolatile", + &efi_rt_var_guid, + &attr, &len, data); + if (ret != EFI_SUCCESS) { + efi_st_error("GetVariable failed\n"); + return EFI_ST_FAILURE; + } + + len = sizeof(data2); + ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid, + &attr, &len, data2); + if (ret != EFI_SUCCESS) { + efi_st_error("GetVariable failed\n"); + return EFI_ST_FAILURE; + } + /* + * VarToFile will size must change once a variable is inserted + * Store it now, we'll use it later + */ + prev_len = len; + ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_NON_VOLATILE, + sizeof(v2), + v2); + /* + * This will try to update VarToFile as well and must fail, + * without changing or deleting VarToFile + */ + if (ret != EFI_OUT_OF_RESOURCES) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + len = sizeof(data2); + ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid, + &attr, &len, data2); + if (ret != EFI_SUCCESS || prev_len != len) { + efi_st_error("Get/SetVariable failed\n"); + return EFI_ST_FAILURE; + } + + /* SetVariableRT updates VarToFile with efi_st_var0 */ + ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_NON_VOLATILE, + sizeof(v), v); + if (ret != EFI_SUCCESS) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + len = sizeof(data2); + delta = 2 * (u16_strlen(u"efi_st_var0") + 1) + sizeof(v) + + sizeof(struct efi_var_entry); + ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid, + &attr, &len, data2); + if (ret != EFI_SUCCESS || prev_len + delta != len) { + efi_st_error("Get/SetVariable failed\n"); + return EFI_ST_FAILURE; + } + + /* append on an existing variable will updateVarToFile */ + ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_APPEND_WRITE | + EFI_VARIABLE_NON_VOLATILE, + sizeof(v), v); + if (ret != EFI_SUCCESS) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + prev_len = len; + delta = sizeof(v); + len = sizeof(data2); + ret = runtime->get_variable(u"VarToFile", &efi_rt_var_guid, + &attr, &len, data2); + if (ret != EFI_SUCCESS || prev_len + delta != len) { + efi_st_error("Get/SetVariable failed\n"); + return EFI_ST_FAILURE; + } + + /* Variables that are BS, RT and volatile are RO after EBS */ + ret = runtime->set_variable(u"VarToFile", &efi_rt_var_guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_NON_VOLATILE, + sizeof(v), v); + if (ret != EFI_WRITE_PROTECTED) { + efi_st_error("Get/SetVariable failed\n"); + return EFI_ST_FAILURE; + } } else { if (ret != EFI_UNSUPPORTED) { efi_st_error("SetVariable failed\n");