From patchwork Thu Nov 7 07:46:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1190948 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 477wTM6PB6zB3x1; Thu, 7 Nov 2019 18:46: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 1iScV7-0006bI-GA; Thu, 07 Nov 2019 07:46:41 +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 1iScV5-0006b9-8j for fwts-devel@lists.ubuntu.com; Thu, 07 Nov 2019 07:46:39 +0000 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] 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 1iScV4-0000bS-JB; Thu, 07 Nov 2019 07:46:39 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 2/5 V2] lib: add function for check the RuntimeServicesSupported variable Date: Thu, 7 Nov 2019 15:46:30 +0800 Message-Id: <1573112794-4284-1-git-send-email-ivan.hu@canonical.com> X-Mailer: git-send-email 2.7.4 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 Acked-by: Colin Ian King Acked-by: Alex Hung --- 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..02b16da 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; + static 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; + +}