From patchwork Sat Apr 6 14:01:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 786483 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1101:b0:343:f27d:c44e with SMTP id z1csp628221wrw; Sat, 6 Apr 2024 07:03:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV1k3OEbiQhxOgr7Tpi4PM6tiLUp480/G5JkQA54P2t8+xpTfEIpY7R3I/wxx4s1CEGX41tQ4+01ZNTDPvoPMZm X-Google-Smtp-Source: AGHT+IFuHJxPaavuVqpwNwG5VSWi6bmx1Uq3Ei/TjXVGHccwT9rt3Z+nkRroUW7d9lLlTOfAhTXx X-Received: by 2002:a05:6512:484a:b0:516:9f1a:929d with SMTP id ep10-20020a056512484a00b005169f1a929dmr2569001lfb.1.1712412189565; Sat, 06 Apr 2024 07:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712412189; cv=none; d=google.com; s=arc-20160816; b=JeDG8p8lvf+3+5yf5WFqD1aUnieQu+3aQMHIM3kx+0pPF/UNL6DCdAMn0Vghfz7IUp 6Q8SZqBMDWnQvekIGaNW/EDUwuWPQecr0vCH2wAxRfeXWl9ufLkQT5bttEm8Cu7gfR0q gLZ4K887PGkqafVdR7J5Jz+6+BXK69gcsNqnIPWByOnfdAHSxKL257Kny/7V9gA5ne5D RufbhYE7lIgDfDgw2gmKX1RkcV8F5wWNkWgZBsGqUjgsbqmskcVQzfGeyVri0padXONw voyyPXeIuUZ2dRM7l5OhL8/PSPdkcRYrFraSNQ89JQOIuny95JXwoWYZWU8KDX6x4s3U Ez+w== 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=FMqfUdl76G4qBulxCLMeh65myWO0ylZWG10h5H0frZ8=; fh=g83CYsbJCPBSnn04Z4WpVeSgC5MY1X5OSXuu8//rqZg=; b=P9vRIN8N+ovKwQC3J04n7LfEpgRToLsNBNfbo/VNkIiKbjs5R/J2X1VMaYFzJ3xBoO lu/Moq7LpNVsWFbHw0Twala34BGq2EGP55BOiCdain5BBbTtrEYpYUNxtAHqITTf3D2e SIFa0xQpVBJCUAe9C4hQB3XjphG2XaKeQWBjeiijhXHTzXSYk3BAsXXzqeS+ov4QTZVO RESnvfOXpLzhKpTt4GzFQQ+GMtEHtuT0LGXPtdowwtLGdIV87yGsxdw6X/NMUISZyWq/ NyLMp8wIFZNAU/awjSLsa/KXa3nGdbZ0Sa1+1U/YsBPCq1y8qz6FAu3zCLSYUdlUVLtk 5Blw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ul92xvWT; 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 k26-20020a1709063e1a00b00a4746cdae10si1735263eji.720.2024.04.06.07.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 07:03:09 -0700 (PDT) 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=Ul92xvWT; 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 8E4A98824A; Sat, 6 Apr 2024 16:02:41 +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="Ul92xvWT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4098587FC8; Sat, 6 Apr 2024 16:02:40 +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-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (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 24B5087FC6 for ; Sat, 6 Apr 2024 16:02:38 +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-wr1-x434.google.com with SMTP id ffacd0b85a97d-33ff53528ceso2288429f8f.0 for ; Sat, 06 Apr 2024 07:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712412157; x=1713016957; 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=FMqfUdl76G4qBulxCLMeh65myWO0ylZWG10h5H0frZ8=; b=Ul92xvWTNhLDeRNrNwSbih/KvhQ6LYG9eT6wsIDqB54lE0O85AYssaTxbN4gGW44eN ylLTzlYG/UOSSGrULMNHqecX/9eydsTi2NKASl3038qP2vLNR969zhZIU83hUb6hl/0A Xyy2hKsSVyt1LBL+ROyegcSyYpCQEwG8AxmCF8RtcqDF503F9fybY+wyXrRC9B8crUBD jh3AUCC7Wx+i5ybsK9a57+YsL84O29xz6o6nYi0S98u9L9Hd9EP62Nw4kJPIQlsqS9T4 K3TdaY5etEGhyJwYzUfT1gvOY5ILvUMNdcJ42qT4Ay/wXJt1WyNX8Z2wt90amg2/Jpg6 Eygg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712412157; x=1713016957; 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=FMqfUdl76G4qBulxCLMeh65myWO0ylZWG10h5H0frZ8=; b=ls5mw3JBkDCohfDsSME01MpC/qUHg1g5DdTFQ9PRMt2aum83YW0SVQSIebbfzyZQ6P Zpgh+Z6fJ57G9sqXQzWNMGxU+jxyEGZKAWmfd2N8RBWPnfz5haTFG4so4SQImd8vpr/V sqLU7zrLwlNyXfMe3/5fVnayD824UPcENOiikvmCfsGKbIdzVb5IHHqXaHznc9j3pqE4 lzvWS+syq4h89C/eNEbAy5nMPSFY+VWPOEnR/b7bXt5I5Z+5jskH61bmlnzeA8TcoJvZ WrQKDKdg3fg9QzQR8yX+Yg/Se7fbfg1cqA56SnULkYaoQy2LNp7dXfd/gCNuF0pqwFSC Y7Kg== X-Forwarded-Encrypted: i=1; AJvYcCXlYqZHrSXH830bIozmzr2bdey0zhVXn54GtkOm6QVNXAGEWU66IYTBlge6cYS2Ub++i/y0QOrpu5QzlzH/nQfiQoHkCA== X-Gm-Message-State: AOJu0Yxw5JcIku2DDLhaVMhK45E/eCwTcMkf4x7iOmGvpz4CuKvJHmNg SfYgpybPyq0hNDD17chl2ZBFni9ySfm982M4KUbVT+nkQBP3Sbop9SmsubMfQJY= X-Received: by 2002:a05:600c:4505:b0:414:22e:1761 with SMTP id t5-20020a05600c450500b00414022e1761mr3138178wmo.16.1712412157614; Sat, 06 Apr 2024 07:02:37 -0700 (PDT) Received: from hades.. (ppp089210071137.access.hol.gr. [89.210.71.137]) by smtp.gmail.com with ESMTPSA id j19-20020a05600c1c1300b004163de6cfabsm1729756wms.11.2024.04.06.07.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 07:02:37 -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 , Bin Meng , Raymond Mao , Simon Glass , Abdellatif El Khlifi , Alper Nebi Yasak , Sughosh Ganu , Weizhao Ouyang , u-boot@lists.denx.de Subject: [PATCH v1 4/4] efi_selftest: add tests for setvariableRT Date: Sat, 6 Apr 2024 17:01:55 +0300 Message-Id: <20240406140203.248211-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20240406140203.248211-1-ilias.apalodimas@linaro.org> References: <20240406140203.248211-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..eb4820e7deab 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) / 2, + v2 + (sizeof(v2) / 2)); + /* + * 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");