From patchwork Wed Nov 6 09:45:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1190196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477M8w3cwCz9sQy; Wed, 6 Nov 2019 20:45:36 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iSHsb-0002Zr-Vt; Wed, 06 Nov 2019 09:45:33 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsa-0002ZW-Je for fwts-devel@lists.ubuntu.com; Wed, 06 Nov 2019 09:45:32 +0000 Received: from [106.104.115.126] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsZ-000136-Nh; Wed, 06 Nov 2019 09:45:32 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/5] lib: add function for check the RuntimeServicesSupported variable Date: Wed, 6 Nov 2019 17:45:13 +0800 Message-Id: <20191106094516.15762-3-ivan.hu@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191106094516.15762-1-ivan.hu@canonical.com> References: <20191106094516.15762-1-ivan.hu@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" First check the getvariable runtime service supported or not Signed-off-by: Ivan Hu --- src/lib/include/fwts_uefi.h | 17 ++++++++++++++++ src/lib/src/fwts_uefi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/lib/include/fwts_uefi.h b/src/lib/include/fwts_uefi.h index 418b881..dd8799d 100644 --- a/src/lib/include/fwts_uefi.h +++ b/src/lib/include/fwts_uefi.h @@ -122,6 +122,21 @@ enum { #define LAST_ATTEMPT_STATUS_ERR_PWR_EVT_AC 0x00000006 #define LAST_ATTEMPT_STATUS_ERR_PWR_EVT_BATT 0x00000007 +#define EFI_RT_SUPPORTED_GET_TIME 0x0001 +#define EFI_RT_SUPPORTED_SET_TIME 0x0002 +#define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004 +#define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008 +#define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010 +#define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020 +#define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040 +#define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080 +#define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100 +#define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200 +#define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400 +#define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800 +#define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000 +#define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000 + #define EFI_CERT_SHA256_GUID \ { 0xc1c41626, 0x504c, 0x4092, { 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28 }} @@ -665,6 +680,8 @@ char *fwts_uefi_attribute_info(uint32_t attr); bool fwts_uefi_efivars_iface_exist(void); +void fwts_uefi_rt_support_status_get(int fd, bool *getvar_supported, uint32_t *var_rtsupported); + PRAGMA_POP #endif diff --git a/src/lib/src/fwts_uefi.c b/src/lib/src/fwts_uefi.c index 80285f1..f133cc1 100644 --- a/src/lib/src/fwts_uefi.c +++ b/src/lib/src/fwts_uefi.c @@ -29,9 +29,11 @@ #include #include #include +#include #include "fwts.h" #include "fwts_uefi.h" +#include "fwts_efi_runtime.h" /* Old sysfs uefi packed binary blob variables */ typedef struct { @@ -536,3 +538,48 @@ bool fwts_uefi_efivars_iface_exist(void) return (fwts_uefi_get_interface(&path) == UEFI_IFACE_EFIVARS); } + +/* + * fwts_uefi_rt_support_status_get() + * get the status of runtime service support and the value of + * the RuntimeServicesSupported variable + */ +void fwts_uefi_rt_support_status_get(int fd, bool *getvar_supported, uint32_t *var_rtsupported) +{ + long ioret; + struct efi_getvariable getvariable; + uint64_t status = ~0ULL; + uint8_t data[512]; + uint64_t getdatasize = sizeof(data); + *var_rtsupported = 0xFFFF; + + uint32_t attributes = FWTS_UEFI_VAR_NON_VOLATILE | + FWTS_UEFI_VAR_BOOTSERVICE_ACCESS | + FWTS_UEFI_VAR_RUNTIME_ACCESS; + uint16_t varname[] = {'R', 'u', 'n', 't', 'i', 'm', 'e', 'S', 'e', + 'r', 'v', 'i', 'c', 'e', 's', 'S', 'u', 'p', + 'p', 'o', 'r', 't', 'e', 'd', '\0'}; + EFI_GUID global_var_guid = EFI_GLOBAL_VARIABLE; + getvariable.VariableName = varname; + getvariable.VendorGuid = &global_var_guid; + getvariable.Attributes = &attributes; + getvariable.DataSize = &getdatasize; + getvariable.Data = data; + getvariable.status = &status; + + ioret = ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable); + if (ioret == -1) { + if (status == EFI_NOT_FOUND) { + *getvar_supported = true; + } else { + *getvar_supported = false; + } + return; + } + + *getvar_supported = true; + *var_rtsupported = data[0] | data[1] << 8; + + return; + +} From patchwork Wed Nov 6 09:45:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1190197 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477M915dB0z9sP6; Wed, 6 Nov 2019 20:45:41 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iSHsh-0002ar-1u; Wed, 06 Nov 2019 09:45:39 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHse-0002aX-Lw for fwts-devel@lists.ubuntu.com; Wed, 06 Nov 2019 09:45:36 +0000 Received: from [106.104.115.126] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsd-00013L-T4; Wed, 06 Nov 2019 09:45:36 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 3/5] uefirttime: add unsupported checking with RuntimeServicesSupported variable Date: Wed, 6 Nov 2019 17:45:14 +0800 Message-Id: <20191106094516.15762-4-ivan.hu@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191106094516.15762-1-ivan.hu@canonical.com> References: <20191106094516.15762-1-ivan.hu@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" UEFI spec 2.8 introduced the variable RuntimeServicesSupported, which is Bitmask of which calls are implemented by the firmware during runtime services. Add tests for checking time services with RuntimeServicesSupported variable. Signed-off-by: Ivan Hu --- src/uefi/uefirttime/uefirttime.c | 149 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 1 deletion(-) diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c index ccd9acb..c6ffb64 100644 --- a/src/uefi/uefirttime/uefirttime.c +++ b/src/uefi/uefirttime/uefirttime.c @@ -1152,6 +1152,153 @@ static int uefirttime_test37(fwts_framework *fw) } #endif +static int uefirttime_test38(fwts_framework *fw) +{ + bool getvar_supported; + uint32_t var_runtimeservicessupported; + + struct efi_settime settime; + uint64_t status = ~0ULL; + struct efi_gettime gettime; + struct efi_getwakeuptime getwakeuptime; + uint8_t enabled, pending; + struct efi_setwakeuptime setwakeuptime; + + EFI_TIME efi_time; + EFI_TIME_CAPABILITIES efi_time_cap; + + fwts_uefi_rt_support_status_get(fd, &getvar_supported, + &var_runtimeservicessupported); + + if (!getvar_supported || (var_runtimeservicessupported == 0xFFFF)) { + fwts_skipped(fw, "Cannot get the RuntimeServicesSupported " + "variable, maybe the runtime service " + "GetVariable is not supported or " + "RuntimeServicesSupported not provided by " + "firmware."); + return FWTS_SKIP; + } + + gettime.Capabilities = &efi_time_cap; + gettime.Time = &efi_time; + gettime.status = &status; + ioctl(fd, EFI_RUNTIME_GET_TIME, &gettime); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime", + "Get the GetTime runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI GetTime runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI GetTime runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetTime", + "Get the GetTime runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + settime.Time = &efi_time; + status = ~0ULL; + settime.status = &status; + + ioctl(fd, EFI_RUNTIME_SET_TIME, &settime); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime", + "Get the SetTime runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI SetTime runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI SetTime runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetTime", + "Get the SetTime runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + setwakeuptime.Time = &efi_time; + status = ~0ULL; + setwakeuptime.status = &status; + setwakeuptime.Enabled = false; + + ioctl(fd, EFI_RUNTIME_SET_WAKETIME, &setwakeuptime); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime", + "Get the SetWakeupTime runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware"); + + } else { + fwts_passed(fw, "UEFI SetWakeupTime runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_WAKEUP_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI SetWakeupTime runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetWakeupTime", + "Get the SetWakeupTime runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + getwakeuptime.Enabled = &enabled; + getwakeuptime.Pending = &pending; + getwakeuptime.Time = &efi_time; + getwakeuptime.status = &status; + + ioctl(fd, EFI_RUNTIME_GET_WAKETIME, &getwakeuptime); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime", + "Get the GetWakeupTime runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware"); + } else { + fwts_passed(fw, "UEFI GetWakeupTime runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_WAKEUP_TIME) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI GetWakeupTime runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetWakeupTime", + "Get the GetWakeupTime runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware"); + } + } + return FWTS_OK; +} + static fwts_framework_minor_test uefirttime_tests[] = { { uefirttime_test1, "Test UEFI RT service get time interface." }, { uefirttime_test2, "Test UEFI RT service get time interface, NULL time parameter." }, @@ -1197,7 +1344,7 @@ static fwts_framework_minor_test uefirttime_tests[] = { #if UEFI_IGNORE_UNSET_BITS { uefirttime_test37, "Test UEFI RT service set wakeup time interface, invalid daylight 0xfc." }, #endif - + { uefirttime_test38, "Test UEFI RT time services supported status." }, { NULL, NULL } }; From patchwork Wed Nov 6 09:45:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1190198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477M954s8Jz9sP6; Wed, 6 Nov 2019 20:45:45 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iSHsl-0002bv-3x; Wed, 06 Nov 2019 09:45:43 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsj-0002bV-0c for fwts-devel@lists.ubuntu.com; Wed, 06 Nov 2019 09:45:41 +0000 Received: from [106.104.115.126] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsh-00014U-Nu; Wed, 06 Nov 2019 09:45:40 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 4/5] uefirtvariable: add unsupported checking with RuntimeServicesSupported variable Date: Wed, 6 Nov 2019 17:45:15 +0800 Message-Id: <20191106094516.15762-5-ivan.hu@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191106094516.15762-1-ivan.hu@canonical.com> References: <20191106094516.15762-1-ivan.hu@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" UEFI spec 2.8 introduced the variable RuntimeServicesSupported, which is Bitmask of which calls are implemented by the firmware during runtime services. Add tests for checking variable services with RuntimeServicesSupported variable. Signed-off-by: Ivan Hu --- src/uefi/uefirtvariable/uefirtvariable.c | 180 +++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c index bb7c602..55a9b1d 100644 --- a/src/uefi/uefirtvariable/uefirtvariable.c +++ b/src/uefi/uefirtvariable/uefirtvariable.c @@ -2030,6 +2030,185 @@ static int uefirtvariable_test8(fwts_framework *fw) return FWTS_OK; } +static int uefirtvariable_test9(fwts_framework *fw) +{ + + bool getvar_supported; + uint32_t var_runtimeservicessupported; + + struct efi_getvariable getvariable; + struct efi_setvariable setvariable; + struct efi_getnextvariablename getnextvariablename; + struct efi_queryvariableinfo queryvariableinfo; + + EFI_GUID guid; + uint64_t status = ~0ULL; + uint8_t data = 1; + uint64_t datasize = 1; + uint64_t variablenamesize = MAX_DATA_LENGTH; + uint16_t *variablename; + uint64_t remvarstoragesize; + uint64_t maxvariablesize; + uint64_t maxvarstoragesize; + uint8_t testdata[MAX_DATA_LENGTH]; + uint64_t getdatasize = sizeof(testdata); + uint32_t attr; + + fwts_uefi_rt_support_status_get(fd, &getvar_supported, + &var_runtimeservicessupported); + + if (!getvar_supported || (var_runtimeservicessupported == 0xFFFF)) { + fwts_skipped(fw, "Cannot get the RuntimeServicesSupported " + "variable, maybe the runtime service " + "GetVariable is not supported or " + "RuntimeServicesSupported not provided by " + "firmware."); + return FWTS_SKIP; + } + + setvariable.VariableName = variablenametest; + setvariable.VendorGuid = >estguid1; + setvariable.Attributes = attributes; + setvariable.DataSize = datasize; + setvariable.Data = &data; + setvariable.status = &status; + + ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_VARIABLE) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable", + "Get the Setvariable runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI SetVariable runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_SET_VARIABLE) || + (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI SetVariable runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeSetVariable", + "Get the SetVariable runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + getvariable.VariableName = variablenametest; + getvariable.VendorGuid = >estguid1; + getvariable.Attributes = &attr; + getvariable.DataSize = &getdatasize; + getvariable.Data = testdata; + getvariable.status = &status; + + ioctl(fd, EFI_RUNTIME_GET_VARIABLE, &getvariable); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_VARIABLE) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetVariable", + "Get the GetVariable runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI GetVariable runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_VARIABLE) || + (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI GetVariable runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetVariable", + "Get the GetVariable runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + /* delete the variable which was set */ + setvariable.DataSize = 0; + status = ~0ULL; + ioctl(fd, EFI_RUNTIME_SET_VARIABLE, &setvariable); + + variablename = malloc(sizeof(uint16_t) * variablenamesize); + if (!variablename) { + fwts_skipped(fw, "Unable to alloc memory for variable name"); + return FWTS_SKIP; + } + getnextvariablename.VariableNameSize = &variablenamesize; + getnextvariablename.VariableName = variablename; + getnextvariablename.VendorGuid = &guid; + getnextvariablename.status = &status; + + variablename[0] = '\0'; + status = ~0ULL; + ioctl(fd, EFI_RUNTIME_GET_NEXTVARIABLENAME, &getnextvariablename); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVarName", + "Get the GetNextVarName runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI GetNextVarName runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI GetNextVarName runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeGetNextVarName", + "Get the GetNextVarName runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + queryvariableinfo.Attributes = attributes; + queryvariableinfo.MaximumVariableStorageSize = &maxvarstoragesize; + queryvariableinfo.RemainingVariableStorageSize = &remvarstoragesize; + queryvariableinfo.MaximumVariableSize = &maxvariablesize; + queryvariableinfo.status = &status; + status = ~0ULL; + + ioctl(fd, EFI_RUNTIME_QUERY_VARIABLEINFO, &queryvariableinfo); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeQueryVarInfo", + "Get the QueryVarInfo runtime service supported " + "via RuntimeServicesSupported variable. " + "But actually is not supported by firmware."); + } else { + fwts_passed(fw, "UEFI QueryVarInfo runtime service " + "supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI QueryVarInfo runtime service " + "supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, "UEFIRuntimeQueryVarInfo", + "Get the QueryVarInfo runtime service unsupported " + "via RuntimeServicesSupported variable. " + "But actually is supported by firmware."); + } + } + + + return FWTS_OK; + +} + static int options_check(fwts_framework *fw) { FWTS_UNUSED(fw); @@ -2101,6 +2280,7 @@ static fwts_framework_minor_test uefirtvariable_tests[] = { { uefirtvariable_test6, "Test UEFI RT service set variable interface stress test." }, { uefirtvariable_test7, "Test UEFI RT service query variable info interface stress test." }, { uefirtvariable_test8, "Test UEFI RT service get variable interface, invalid parameters." }, + { uefirtvariable_test9, "Test UEFI RT variable services supported status." }, { NULL, NULL } }; From patchwork Wed Nov 6 09:45:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1190199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477M995mjzz9sP6; Wed, 6 Nov 2019 20:45:49 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iSHsp-0002d9-6v; Wed, 06 Nov 2019 09:45:47 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsn-0002ch-1n for fwts-devel@lists.ubuntu.com; Wed, 06 Nov 2019 09:45:45 +0000 Received: from [106.104.115.126] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iSHsm-00014f-2T; Wed, 06 Nov 2019 09:45:44 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 5/5] uefirtmisc: add unsupported checking with RuntimeServicesSupported variable Date: Wed, 6 Nov 2019 17:45:16 +0800 Message-Id: <20191106094516.15762-6-ivan.hu@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191106094516.15762-1-ivan.hu@canonical.com> References: <20191106094516.15762-1-ivan.hu@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" UEFI spec 2.8 introduced the variable RuntimeServicesSupported, which is Bitmask of which calls are implemented by the firmware during runtime services. Add tests for checking GetNextHighMonotonicCount services with RuntimeServicesSupported variable. Currently, won't test with QueryCapsuleCapabilities becasue QueryCapsuleCapabilities may return unsupported due to the update flag of firmware behavior unsupported, not runtime service unsupported. Signed-off-by: Ivan Hu --- src/uefi/uefirtmisc/uefirtmisc.c | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/uefi/uefirtmisc/uefirtmisc.c b/src/uefi/uefirtmisc/uefirtmisc.c index b3fdf5f..4cda778 100644 --- a/src/uefi/uefirtmisc/uefirtmisc.c +++ b/src/uefi/uefirtmisc/uefirtmisc.c @@ -254,11 +254,66 @@ static int uefirtmisc_test3(fwts_framework *fw) return FWTS_ERROR; } +static int uefirtmisc_test4(fwts_framework *fw) +{ + uint64_t status; + bool getvar_supported; + uint32_t var_runtimeservicessupported; + + struct efi_getnexthighmonotoniccount getnexthighmonotoniccount; + uint32_t highcount; + + fwts_uefi_rt_support_status_get(fd, &getvar_supported, + &var_runtimeservicessupported); + if (!getvar_supported || (var_runtimeservicessupported == 0xFFFF)) { + fwts_skipped(fw, "Cannot get the RuntimeServicesSupported " + "variable, maybe the runtime service " + "GetVariable is not supported or " + "RuntimeServicesSupported not provided by " + "firmware."); + return FWTS_SKIP; + } + + getnexthighmonotoniccount.HighCount = &highcount; + getnexthighmonotoniccount.status = &status; + status = ~0ULL; + ioctl(fd, EFI_RUNTIME_GET_NEXTHIGHMONOTONICCOUNT, &getnexthighmonotoniccount); + if (status == EFI_UNSUPPORTED) { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT) + || (var_runtimeservicessupported == 0)) { + fwts_failed(fw, LOG_LEVEL_HIGH, + "UEFIRuntimeGetNextHighMonotonicCount", + "Get the GetNextHighMonotonicCount runtime " + "service supported via RuntimeServicesSupported " + "variable. But actually is not supported by " + "firmware."); + } else { + fwts_passed(fw, "UEFI GetNextHighMonotonicCount runtime " + "service supported status test passed."); + } + } else { + if ((var_runtimeservicessupported & EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT) + || (var_runtimeservicessupported == 0)) { + fwts_passed(fw, "UEFI GetNextHighMonotonicCount runtime " + "service supported status test passed."); + } else { + fwts_failed(fw, LOG_LEVEL_HIGH, + "UEFIRuntimeGetNextHighMonotonicCount", + "Get the GetNextHighMonotonicCount runtime " + "service unsupported via RuntimeServicesSupported " + "variable. But actually is supported by firmware."); + } + } + + return FWTS_OK; +} + static fwts_framework_minor_test uefirtmisc_tests[] = { { uefirtmisc_test1, "Test for UEFI miscellaneous runtime service interfaces." }, { uefirtmisc_test2, "Stress test for UEFI miscellaneous runtime service interfaces." }, { uefirtmisc_test3, "Test GetNextHighMonotonicCount with invalid NULL parameter." }, + { uefirtmisc_test4, "Test UEFI miscellaneous runtime services supported status." }, { NULL, NULL } };