From 359e78336d72fba2a2e4324f1a5026518b3247bc Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Wed, 8 Jan 2020 13:18:46 +0100 Subject: [PATCH] MdeModulePkg/Universal/Variable/EmuRuntimeDxe: Check SMM store return codes Check SMM store return code and return on error. Fixes significant boot delay in case no SMM store is present. This can happend quite often if the tianocore payload is build standalone and patched into a coreboot ROM. Signed-off-by: Patrick Rudolph --- .../Universal/Variable/EmuRuntimeDxe/EmuVariable.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c index 3585f106db..ec38f94aae 100644 --- a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c +++ b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c @@ -944,6 +944,7 @@ UpdateVariable ( UINTN VarSize; VARIABLE_GLOBAL *Global; UINTN NonVolatileVarableStoreSize; + UINT32 Result; Global = &mVariableModuleGlobal->VariableGlobal[Physical]; @@ -1108,7 +1109,10 @@ UpdateVariable ( CopyMem (keydata + sizeof (EFI_GUID), VariableName, VarNameSize); CopyMem (valdata, Data, DataSize); - call_smm(SMMSTORE_APM_CNT, SMMSTORE_CMD_APPEND, (UINT32)rt_buffer_phys); + Result = call_smm(SMMSTORE_APM_CNT, SMMSTORE_CMD_APPEND, (UINT32)rt_buffer_phys); + if (Result != SMMSTORE_RET_SUCCESS) { + return EFI_DEVICE_ERROR; + } /* call into SMM through EFI_ISA_IO_PROTOCOL to write to 0xb2: * set registers (how?) * UINT8 Data = ...; @@ -1875,7 +1879,7 @@ VariableCommonInitialize ( ) { EFI_STATUS Status; - + UINT32 Result; // // Allocate memory for mVariableModuleGlobal // @@ -1928,7 +1932,11 @@ VariableCommonInitialize ( .bufsize = sizeof(buf), }; ASSERT((UINTN)&read_cmd <= 0x100000000 - sizeof(read_cmd)); - call_smm(SMMSTORE_APM_CNT, SMMSTORE_CMD_READ, (UINT32)(UINTN)&read_cmd); + Result = call_smm(SMMSTORE_APM_CNT, SMMSTORE_CMD_READ, (UINT32)(UINTN)&read_cmd); + if (Result != SMMSTORE_RET_SUCCESS) { + // The SMM store hasn't been compiled in. There's nothing we can do. + return EFI_SUCCESS; + } DEBUG ((DEBUG_WARN, "Initialize buffer from 0x%x bytes of flash\n", read_cmd.bufsize)); int i = 0;