Message ID | 20191106094516.15762-3-ivan.hu@canonical.com |
---|---|
State | Superseded |
Headers | show |
Series | Add tests for runtime services unsupported check | expand |
On 06/11/2019 09:45, Ivan Hu wrote: > First check the getvariable runtime service supported or not > > Signed-off-by: Ivan Hu <ivan.hu@canonical.com> > --- > 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 <inttypes.h> > #include <errno.h> > #include <string.h> > +#include <sys/ioctl.h> > > #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'}; Could varname be static (or static const)? Making it static saves populating it on the stack on each call. Ignore this comment if it can't be static. > + 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; > + > +} >
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 <inttypes.h> #include <errno.h> #include <string.h> +#include <sys/ioctl.h> #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; + +}
First check the getvariable runtime service supported or not Signed-off-by: Ivan Hu <ivan.hu@canonical.com> --- src/lib/include/fwts_uefi.h | 17 ++++++++++++++++ src/lib/src/fwts_uefi.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+)