From patchwork Thu May 17 05:57:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 915092 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40mgZp0YCkz9s1B for ; Thu, 17 May 2018 15:58:09 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 87DDFC21DF8; Thu, 17 May 2018 05:57:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_LOW autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 72AC3C21DCA; Thu, 17 May 2018 05:57:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 65A59C21DB5; Thu, 17 May 2018 05:57:26 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id B19E1C21BE5 for ; Thu, 17 May 2018 05:57:24 +0000 (UTC) Received: from LPT2.fritz.box ([95.223.128.184]) by mail.gmx.com (mrgmx103 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MI5rO-1fGRHx0GS6-003trA; Thu, 17 May 2018 07:57:15 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Thu, 17 May 2018 07:57:05 +0200 Message-Id: <20180517055706.30467-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180517055706.30467-1-xypron.glpk@gmx.de> References: <20180517055706.30467-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:TS+79FxjxeXoiQhLBc4XoBkM2VCj8zjV83JzbMZ4cQeOJjTPPSm 08EC5Ulz9QZXBqdmeZWn3tWwJy1Pc0cIu0jwvnWZzsvhNsHlY56Z8xL+7gsUQuDyIEC9ywK vg1kQr/xH1ewmkCOmAoPOH+8ZD/3TFsmSofuDAobO5tFBLjb71VdG7t3GM3k1K6YjcegeDs 5w/D6AEi07ytk5JB+oo4A== X-UI-Out-Filterresults: notjunk:1; V01:K0:MpNix2hUjdc=:MyJzIv8IrB+DHzwdLvGwIh iTj0qMPIE04OJhbIN85iwzhTbstIuCI9dbXVOE8WTEXnHeb9flfefbOBOopEAsshUZRosJoQQ bULldc8lHXAmOu1d7j8I+srFcmmTunUsdgP2o9gUP7iSg60zrl8oRLWEvU5jAqv3Far8A5D2k o3ZYLdQGc38x7b3uAOPzKVHCI9lMmow9NBydm45B1VcEU9cQBIm4Yd6ZmHC8QJVYGjmWuJG3g Bc87qFW5ZD0TVPHVGM1DGbZ1KuVB/ZGryiGY0uzoR+HwMgO8MfbKRB0d2ttoSd7SoYFevUy7N rQcsigab7CtqKD8S4M+4jftaBrqVJMAvTkHxpRGEoPucNu8Vz2hVYBIP8vNthNbJA2lXid1C7 B5rQzW519AqrUw9/E4Eq/v9jE7AOOBjSgwphFMztdvKgLZwWcc97+/yi5wBNh9caM4OE1y0u/ 6tkW8QiiXq/CZk8YSdz/cAFY0Xlhafsn7Frb3B9wsUsNOh9oC6RBPUHdKJvoUkxwd0u90e3x/ YcluxtRmR/0QhhCF4J2obyNoMwW666NUJwpwDdR4AfGOa7hUvL/26GdVad1cMFdHxWQ8xJGmH u3fzgUrk4QyHyZIMPY6McGR3JPbpO6529pLE/D2S/JiTIGAiXXfc4nngvsmpfCXg0HYwtJuP9 EeAp4Ah6jeILHpXLbIP8ddtKv4EsH+G+m/WVWGPj0aydCyiATxCzFGzGHfkfxWtyUTaoOgoV8 Zk2k98KNfEq1sx3hupMWLf5P9WA2NqhIF8KQml81Gd2qzrV2+bmFnJoTnUE= Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 1/2] efi_loader: adjust definitions of variable services X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The definitons of the variable services are adjusted: - use efi_uintn_t instead of unsigned long - use u16 * instead of s16 * for Unicode strings - correct definition of QueryVariableInfo - rename efi_get_next_variable to efi_get_next_variable_name Signed-off-by: Heinrich Schuchardt --- v2 no change --- include/efi_api.h | 24 ++++++++++++------------ include/efi_loader.h | 18 +++++++++--------- lib/efi_loader/efi_bootmgr.c | 10 +++++----- lib/efi_loader/efi_runtime.c | 10 +++++----- lib/efi_loader/efi_variable.c | 24 ++++++++++++------------ 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index 64c27e494bc..094be6edf9b 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -214,15 +214,15 @@ struct efi_runtime_services { uint32_t descriptor_version, struct efi_mem_desc *virtmap); efi_status_t (*convert_pointer)(unsigned long dbg, void **address); - efi_status_t (EFIAPI *get_variable)(s16 *variable_name, - efi_guid_t *vendor, u32 *attributes, - unsigned long *data_size, void *data); - efi_status_t (EFIAPI *get_next_variable)( - unsigned long *variable_name_size, - s16 *variable_name, efi_guid_t *vendor); - efi_status_t (EFIAPI *set_variable)(s16 *variable_name, - efi_guid_t *vendor, u32 attributes, - unsigned long data_size, void *data); + efi_status_t (EFIAPI *get_variable)(u16 *variable_name, + efi_guid_t *vendor, u32 *attributes, + efi_uintn_t *data_size, void *data); + efi_status_t (EFIAPI *get_next_variable_name)( + efi_uintn_t *variable_name_size, + u16 *variable_name, efi_guid_t *vendor); + efi_status_t (EFIAPI *set_variable)(u16 *variable_name, + efi_guid_t *vendor, u32 attributes, + efi_uintn_t data_size, void *data); efi_status_t (EFIAPI *get_next_high_mono_count)( uint32_t *high_count); void (EFIAPI *reset_system)(enum efi_reset_type reset_type, @@ -239,9 +239,9 @@ struct efi_runtime_services { u32 reset_type); efi_status_t (EFIAPI *query_variable_info)( u32 attributes, - u64 maximum_variable_storage_size, - u64 remaining_variable_storage_size, - u64 maximum_variable_size); + u64 *maximum_variable_storage_size, + u64 *remaining_variable_storage_size, + u64 *maximum_variable_size); }; /* EFI event group GUID definitions */ diff --git a/include/efi_loader.h b/include/efi_loader.h index 2868ca25abb..4e9e9d05c76 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -415,15 +415,15 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, struct efi_system_table *systab); #endif -efi_status_t EFIAPI efi_get_variable(s16 *variable_name, - efi_guid_t *vendor, u32 *attributes, - unsigned long *data_size, void *data); -efi_status_t EFIAPI efi_get_next_variable( - unsigned long *variable_name_size, - s16 *variable_name, efi_guid_t *vendor); -efi_status_t EFIAPI efi_set_variable(s16 *variable_name, - efi_guid_t *vendor, u32 attributes, - unsigned long data_size, void *data); +efi_status_t EFIAPI efi_get_variable(u16 *variable_name, efi_guid_t *vendor, + u32 *attributes, efi_uintn_t *data_size, + void *data); +efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, + u16 *variable_name, + efi_guid_t *vendor); +efi_status_t EFIAPI efi_set_variable(u16 *variable_name, efi_guid_t *vendor, + u32 attributes, efi_uintn_t data_size, + void *data); void *efi_bootmgr_load(struct efi_device_path **device_path, struct efi_device_path **file_path); diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 153e1737573..853358ab937 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -70,17 +70,17 @@ static void parse_load_option(struct load_option *lo, void *ptr) /* free() the result */ static void *get_var(u16 *name, const efi_guid_t *vendor, - unsigned long *size) + efi_uintn_t *size) { efi_guid_t *v = (efi_guid_t *)vendor; efi_status_t ret; void *buf = NULL; *size = 0; - EFI_CALL(ret = rs->get_variable((s16 *)name, v, NULL, size, buf)); + EFI_CALL(ret = rs->get_variable(name, v, NULL, size, buf)); if (ret == EFI_BUFFER_TOO_SMALL) { buf = malloc(*size); - EFI_CALL(ret = rs->get_variable((s16 *)name, v, NULL, size, buf)); + EFI_CALL(ret = rs->get_variable(name, v, NULL, size, buf)); } if (ret != EFI_SUCCESS) { @@ -104,7 +104,7 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, u16 varname[] = L"Boot0000"; u16 hexmap[] = L"0123456789ABCDEF"; void *load_option, *image = NULL; - unsigned long size; + efi_uintn_t size; varname[4] = hexmap[(n & 0xf000) >> 12]; varname[5] = hexmap[(n & 0x0f00) >> 8]; @@ -147,7 +147,7 @@ void *efi_bootmgr_load(struct efi_device_path **device_path, struct efi_device_path **file_path) { uint16_t *bootorder; - unsigned long size; + efi_uintn_t size; void *image = NULL; int i, num; diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 779e1e1d78d..9ea9493c8b5 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -200,7 +200,7 @@ static const struct efi_runtime_detach_list_struct efi_runtime_detach_list[] = { .ptr = &efi_runtime_services.get_variable, .patchto = &efi_device_error, }, { - .ptr = &efi_runtime_services.get_next_variable, + .ptr = &efi_runtime_services.get_next_variable_name, .patchto = &efi_device_error, }, { .ptr = &efi_runtime_services.set_variable, @@ -420,9 +420,9 @@ efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps( efi_status_t __efi_runtime EFIAPI efi_query_variable_info( u32 attributes, - u64 maximum_variable_storage_size, - u64 remaining_variable_storage_size, - u64 maximum_variable_size) + u64 *maximum_variable_storage_size, + u64 *remaining_variable_storage_size, + u64 *maximum_variable_size) { return EFI_UNSUPPORTED; } @@ -440,7 +440,7 @@ struct efi_runtime_services __efi_runtime_data efi_runtime_services = { .set_virtual_address_map = &efi_set_virtual_address_map, .convert_pointer = (void *)&efi_invalid_parameter, .get_variable = efi_get_variable, - .get_next_variable = efi_get_next_variable, + .get_next_variable_name = efi_get_next_variable_name, .set_variable = efi_set_variable, .get_next_high_mono_count = (void *)&efi_device_error, .reset_system = &efi_reset_system_boottime, diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 45454118f2a..90b637215e4 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -101,8 +101,8 @@ static char *mem2hex(char *hexstr, const u8 *mem, int count) return hexstr; } -static efi_status_t efi_to_native(char *native, s16 *variable_name, - efi_guid_t *vendor) +static efi_status_t efi_to_native(char *native, u16 *variable_name, + efi_guid_t *vendor) { size_t len; @@ -164,9 +164,9 @@ static const char *parse_attr(const char *str, u32 *attrp) } /* http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#GetVariable.28.29 */ -efi_status_t EFIAPI efi_get_variable(s16 *variable_name, - efi_guid_t *vendor, u32 *attributes, - unsigned long *data_size, void *data) +efi_status_t EFIAPI efi_get_variable(u16 *variable_name, efi_guid_t *vendor, + u32 *attributes, efi_uintn_t *data_size, + void *data) { char native_name[MAX_NATIVE_VAR_NAME + 1]; efi_status_t ret; @@ -242,9 +242,9 @@ efi_status_t EFIAPI efi_get_variable(s16 *variable_name, } /* http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#GetNextVariableName.28.29 */ -efi_status_t EFIAPI efi_get_next_variable( - unsigned long *variable_name_size, - s16 *variable_name, efi_guid_t *vendor) +efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size, + u16 *variable_name, + efi_guid_t *vendor) { EFI_ENTRY("%p \"%ls\" %pUl", variable_name_size, variable_name, vendor); @@ -252,16 +252,16 @@ efi_status_t EFIAPI efi_get_next_variable( } /* http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#SetVariable.28.29 */ -efi_status_t EFIAPI efi_set_variable(s16 *variable_name, - efi_guid_t *vendor, u32 attributes, - unsigned long data_size, void *data) +efi_status_t EFIAPI efi_set_variable(u16 *variable_name, efi_guid_t *vendor, + u32 attributes, efi_uintn_t data_size, + void *data) { char native_name[MAX_NATIVE_VAR_NAME + 1]; efi_status_t ret = EFI_SUCCESS; char *val, *s; u32 attr; - EFI_ENTRY("\"%ls\" %pUl %x %lu %p", variable_name, vendor, attributes, + EFI_ENTRY("\"%ls\" %pUl %x %zu %p", variable_name, vendor, attributes, data_size, data); if (!variable_name || !vendor) From patchwork Thu May 17 05:57:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 915094 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40mgbY400qz9s1B for ; Thu, 17 May 2018 15:58:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 31D3CC21DF8; Thu, 17 May 2018 05:58:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 47C0CC21E34; Thu, 17 May 2018 05:57:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 84E72C21E42; Thu, 17 May 2018 05:57:31 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lists.denx.de (Postfix) with ESMTPS id 1F5DDC21DD7 for ; Thu, 17 May 2018 05:57:27 +0000 (UTC) Received: from LPT2.fritz.box ([95.223.128.184]) by mail.gmx.com (mrgmx103 [212.227.17.174]) with ESMTPSA (Nemesis) id 0M3i8r-1eSKB01b0r-00rJNr; Thu, 17 May 2018 07:57:15 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Thu, 17 May 2018 07:57:06 +0200 Message-Id: <20180517055706.30467-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180517055706.30467-1-xypron.glpk@gmx.de> References: <20180517055706.30467-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K1:dOqJzxGEa/sE1M9DlmhlId99YnsMf8X/n87+uv+9NCD9ksM9GB8 LILeVM3UVKHT5mabIWZ4calTJwnQQoI2JxyNIRI9B8VEpJDMykdlbuk39zDzFVCF8ckbcxD T74mvffDDMP3hhmPwCLzGbx3OHE5lrDS++rNYYUb8GvC2lbzp/FWAhMirsFR0z0/5E5Rddz BLTRDRT5ylGjt11xv0jNQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:0kXZWT3X8Pw=:QdBxMoriao+uFODNcLUjiR Zqxjb16fJ58h7FzfzBy3Nt2OU6O2QdFtMMiYWOZt2npbvl7gfwCS5DnHDZkX8v4r14mdDC39S 1s61InHdJgsi7kqol+Sl2ZYAywD5sNJoLuhw3aGwoXHi2BUzz4HEAAvhaYYzyKQkkn1d8CF6n vuUdvwpFIgcrHoLBQs5YlQIfRxd5m54UGLzaWziW43mbemphTSlM9RHqgZJp56sGKsyto/TBr p2AY4bLX4D3CMgOruKBvV1SqhqueZc2BXN+M6VmAtWLW+zS3lvCI1n9FKDFXWHyuKqOrJYRUU F8M5hGoM/1oIcKn0Txjkvilla8P0qU7RMKOdBXuZNlCX/r83kFK/50ec7+B9CCMQUcVmcDr5z Av7VvvTAFDxy9OSw2EwTDoI3V44oDFBztsJ1cNtrlqOjS2OKLmqlOYvXzMPYBq0LoUyWxT5hL c7+rHQCxpDjYr/3RHJkgZ54yqHtsgSXYRnVuuuKy/fG6s63AU5oQIGK/LVW9GhEWV5crtHHjz SD1mQJq2ORmXGEP0EjuGCKhlisKCXSqAKDmI/hXGDX/PWYg40emJ9Z8kahWyWQZarM7CMVrBU 7bOUpyfWY2+uNR6VKV1YnIkczdDP19hRMHcXSu+m15NlWlw7b/quldSOytG3tK6WUdIirjuCa CQjzgRd6m6ItcZQOw0lLKjuK0FKGCY83WlFQiDTw6zlHBc/Wifa2+TpOCMODjxn9+WLdBqptX uOQycIzwcflMeM1RwnFWBBVfetFjuESTmoBMIlK/HERbB2mxgcry8rq+rPY= Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 2/2] efi_selftest: unit test for variable services X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Provide a unit test for variable services. Signed-off-by: Heinrich Schuchardt --- v2 fix warning when building on 64bit architecture --- lib/efi_selftest/Makefile | 1 + lib/efi_selftest/efi_selftest_variables.c | 180 ++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 lib/efi_selftest/efi_selftest_variables.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index 8c416178478..5dbe3363b30 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -28,6 +28,7 @@ efi_selftest_textinput.o \ efi_selftest_textoutput.o \ efi_selftest_tpl.o \ efi_selftest_util.o \ +efi_selftest_variables.o \ efi_selftest_watchdog.o ifeq ($(CONFIG_BLK)$(CONFIG_PARTITIONS),yy) diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c new file mode 100644 index 00000000000..f5e8eb6231c --- /dev/null +++ b/lib/efi_selftest/efi_selftest_variables.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_variables + * + * Copyright (c) 2018 Heinrich Schuchardt + * + * This unit test checks the following protocol services: + * ConnectController, DisconnectController, + * InstallProtocol, ReinstallProtocol, UninstallProtocol, + * OpenProtocol, CloseProtcol, OpenProtocolInformation + */ + +#include + +#define EFI_ST_MAX_DATA_SIZE 16 +#define EFI_ST_MAX_VARNAME_SIZE 40 + +static struct efi_boot_services *boottime; +static struct efi_runtime_services *runtime; +static efi_guid_t guid_vendor0 = + EFI_GUID(0x67029eb5, 0x0af2, 0xf6b1, + 0xda, 0x53, 0xfc, 0xb5, 0x66, 0xdd, 0x1c, 0xe6); +static efi_guid_t guid_vendor1 = + EFI_GUID(0xff629290, 0x1fc1, 0xd73f, + 0x8f, 0xb1, 0x32, 0xf9, 0x0c, 0xa0, 0x42, 0xea); + +/* + * Setup unit test. + * + * @handle handle of the loaded image + * @systable system table + */ +static int setup(const efi_handle_t img_handle, + const struct efi_system_table *systable) +{ + boottime = systable->boottime; + runtime = systable->runtime; + + return EFI_ST_SUCCESS; +} + +/* + * Execute unit test. + */ +static int execute(void) +{ + efi_status_t ret; + efi_uintn_t len; + u32 attr; + u8 v[16] = {0x5d, 0xd1, 0x5e, 0x51, 0x5a, 0x05, 0xc7, 0x0c, + 0x35, 0x4a, 0xae, 0x87, 0xa5, 0xdf, 0x0f, 0x65,}; + u8 *data[EFI_ST_MAX_DATA_SIZE]; + u16 varname[EFI_ST_MAX_VARNAME_SIZE]; + int flag; + efi_guid_t guid; + u64 max_storage, rem_storage, max_size; + + ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, + &max_storage, &rem_storage, + &max_size); + if (ret != EFI_SUCCESS) { + efi_st_todo("QueryVariableInfo failed\n"); + } else if (!max_storage || !rem_storage || !max_size) { + efi_st_error("QueryVariableInfo: wrong info\n"); + return EFI_ST_FAILURE; + } + /* Set variable 0 */ + ret = runtime->set_variable(L"efi_st_var0", &guid_vendor0, + EFI_VARIABLE_BOOTSERVICE_ACCESS, + 3, v + 4); + if (ret != EFI_SUCCESS) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + /* Set variable 1 */ + ret = runtime->set_variable(L"efi_st_var1", &guid_vendor1, + EFI_VARIABLE_BOOTSERVICE_ACCESS, + 8, v); + if (ret != EFI_SUCCESS) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + len = EFI_ST_MAX_DATA_SIZE; + ret = runtime->get_variable(L"efi_st_var1", &guid_vendor1, + &attr, &len, data); + if (ret != EFI_SUCCESS) { + efi_st_error("GetVariable failed\n"); + return EFI_ST_FAILURE; + } + if (len != 8) { + efi_st_error("GetVariable returned wrong length %u\n", + (unsigned int)len); + return EFI_ST_FAILURE; + } + if (efi_st_memcmp(data, v, 8)) { + efi_st_error("GetVariable returned wrong value\n"); + return EFI_ST_FAILURE; + } + /* Append variable 1 */ + ret = runtime->set_variable(L"efi_st_var1", &guid_vendor1, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_APPEND_WRITE, + 7, v + 8); + if (ret != EFI_SUCCESS) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + len = EFI_ST_MAX_DATA_SIZE; + ret = runtime->get_variable(L"efi_st_var1", &guid_vendor1, + &attr, &len, data); + if (ret != EFI_SUCCESS) { + efi_st_error("GetVariable failed\n"); + return EFI_ST_FAILURE; + } + if (len != 15) + efi_st_todo("GetVariable returned wrong length %u\n", + (unsigned int)len); + if (efi_st_memcmp(data, v, len)) + efi_st_todo("GetVariable returned wrong value\n"); + /* Enumerate variables */ + boottime->set_mem(&guid, 16, 0); + *varname = 0; + flag = 0; + for (;;) { + len = EFI_ST_MAX_VARNAME_SIZE; + ret = runtime->get_next_variable_name(&len, varname, &guid); + if (ret == EFI_NOT_FOUND) + break; + if (ret != EFI_SUCCESS) { + efi_st_todo("GetNextVariableName failed\n"); + break; + } + if (!efi_st_memcmp(&guid, &guid_vendor0, sizeof(efi_guid_t)) && + !efi_st_strcmp_16_8(varname, "efi_st_var0")) + flag |= 2; + if (!efi_st_memcmp(&guid, &guid_vendor1, sizeof(efi_guid_t)) && + !efi_st_strcmp_16_8(varname, "efi_st_var1")) + flag |= 2; + } + if (flag != 3) + efi_st_todo( + "GetNextVariableName did not return all variables\n"); + /* Delete variable 1 */ + ret = runtime->set_variable(L"efi_st_var1", &guid_vendor1, + 0, 0, NULL); + if (ret != EFI_SUCCESS) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + len = EFI_ST_MAX_DATA_SIZE; + ret = runtime->get_variable(L"efi_st_var1", &guid_vendor1, + &attr, &len, data); + if (ret != EFI_NOT_FOUND) { + efi_st_error("Variable was not deleted\n"); + return EFI_ST_FAILURE; + } + /* Delete variable 0 */ + ret = runtime->set_variable(L"efi_st_var0", &guid_vendor0, + 0, 0, NULL); + if (ret != EFI_SUCCESS) { + efi_st_error("SetVariable failed\n"); + return EFI_ST_FAILURE; + } + len = EFI_ST_MAX_DATA_SIZE; + ret = runtime->get_variable(L"efi_st_var0", &guid_vendor0, + &attr, &len, data); + if (ret != EFI_NOT_FOUND) { + efi_st_error("Variable was not deleted\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(variables) = { + .name = "variables", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, +};