EFI_STATUS LibSmbiosInit ( VOID ) /*++ Routine Description: Init the SMBIOS VIEW API's environment. Arguments: None Returns: EFI_SUCCESS - Successful to init the SMBIOS VIEW Lib Others - Cannot get SMBIOS Table --*/ { EFI_STATUS Status; // // Init only once // if (mInit == 1) { return EFI_SUCCESS; } // // Get SMBIOS table from System Configure table // Status = LibGetSystemConfigurationTable (&gEfiSmbiosTableGuid, &mSmbiosTable); if (mSmbiosTable == NULL) { PrintToken (STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), HiiHandle); return EFI_NOT_FOUND; } if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_GET_TABLE_ERROR), HiiHandle, Status); return Status; } // // Init SMBIOS structure table address // mSmbiosStruct->Raw = (UINT8 *) (UINTN) (mSmbiosTable->TableAddress); mInit = 1; return EFI_SUCCESS; }
EFI_STATUS LibInitSalAndPalProc ( VOID ) /*++ Routine Description: Initialize SAL and PAL procedure calling. Arguments: None Returns: EFI_SUCCESS - Always return success. --*/ { SAL_ST_ENTRY_POINT_DESCRIPTOR *SalEpDesc; EFI_PLABEL *PlabelPtr; UINT8 Checksum; UINT8 *TableByte; UINTN Offset; EFI_STATUS Status; if (!SalPalLibInitialized) { SalPalLibInitialized = TRUE; mSalProc = NULL; mPalProc = NULL; mSalSystemTable = NULL; Status = LibGetSystemConfigurationTable (>EfiSalSystemTableGuid, (VOID **) (&mSalSystemTable)); if (EFI_ERROR (Status)) { Print (L"Error : Sal System Table NOT found\r\n"); return EFI_SUCCESS; } // // Check signature, number of entries and size. Then checksum the table. // if (((EntsCompareMem (&mSalSystemTable->Signature, EFI_SAL_ST_HEADER_SIGNATURE, 4)) != 0) && (mSalSystemTable->EntryCount == 0) && (mSalSystemTable->Length == 0) ) { return EFI_SUCCESS; } TableByte = (UINT8 *) mSalSystemTable; Checksum = 0; for (Offset = 0; Offset < mSalSystemTable->Length; Offset++, TableByte++) { Checksum = Checksum +*TableByte; } if (Checksum != 0) { Print (L"Error : Sal System Table checksum is invalid\r\n"); return EFI_SUCCESS; } SalEpDesc = NULL; SalEpDesc = (SAL_ST_ENTRY_POINT_DESCRIPTOR *) LibSearchSalSystemTable (EFI_SAL_ST_ENTRY_POINT); if (SalEpDesc == NULL) { Print (L"Error : Sal entry point not found\r\n"); return EFI_SUCCESS; } mSalProcPlabel.EntryPoint = SalEpDesc->SalProcEntry; mSalProcPlabel.GP = SalEpDesc->SalGlobalDataPointer; PlabelPtr = &mSalProcPlabel; mSalProc = *(SAL_PROC *) (&PlabelPtr); if ((mSalProc == NULL) || (mSalProcPlabel.EntryPoint == 0)) { Print (L"Error : Sal entry point invalid\r\n"); return EFI_SUCCESS; } mPalProcPlabel.EntryPoint = SalEpDesc->PalProcEntry; mPalProcPlabel.GP = SalEpDesc->SalGlobalDataPointer; PlabelPtr = &mPalProcPlabel; mPalProc = *(PAL_PROC *) (&PlabelPtr); if (mPalProcPlabel.EntryPoint == 0) { Print (L"Error : PAL entry point invalid\r\n"); return EFI_SUCCESS; } } return EFI_SUCCESS; }
EFI_STATUS efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *systab) { EFI_STATUS status = EFI_SUCCESS; EFI_GUID Guid = EFI_GLOBAL_VARIABLE; CHAR16 *ptr; CHAR8 *str; UINT16 Handle; UINTN Index; UINT16 Length; UINT8 *Buffer; SMBIOS_STRUCTURE_POINTER SmbiosStruct; SMBIOS_TABLE_TYPE0 *SmbiosType0; InitializeLib(image, systab); status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID**)&mSmbiosTable); if ((status != EFI_SUCCESS || mSmbiosTable == NULL) || (CompareMem (mSmbiosTable->AnchorString, "_SM_", 4) != 0)) { Print(L"ERROR: SMBIOS table not found.\n"); return status; } mSmbiosStruct->Raw = (UINT8 *) (UINTN) (mSmbiosTable->TableAddress); Print(L"SMBIOS Ver: %x.%x Rev: %x Table Count: %d\n", mSmbiosTable->MajorVersion, mSmbiosTable->MinorVersion, mSmbiosTable->EntryPointRevision, mSmbiosTable->NumberOfSmbiosStructures); Handle = INVALID_HANDLE; LibGetSmbiosStructure (&Handle, NULL, NULL); // loop though the tables looking for a type 0 table. for (Index = 0; Index < mSmbiosTable->NumberOfSmbiosStructures; Index++) { if (Handle == INVALID_HANDLE) { break; } if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) { break; } SmbiosStruct.Raw = Buffer; if (SmbiosStruct.Hdr->Type == 0) { // Type 0 - BIOS /* vendor string */ str = LibGetSmbiosString(&SmbiosStruct, 1); ptr = ASCII_to_UCS2(str, Strlen(str)); Print(L"Firmware Vendor: %s\n", ptr); FreePool(ptr); /* version string */ str = LibGetSmbiosString(&SmbiosStruct, 2); ptr = ASCII_to_UCS2(str, Strlen(str)); Print(L"Firmware Version: %s\n", ptr); FreePool(ptr); /* release string */ str = LibGetSmbiosString(&SmbiosStruct, 3); ptr = ASCII_to_UCS2(str, Strlen(str)); Print(L"Firmware Release: %s\n", ptr); FreePool(ptr); break; } } return status; }
EFI_STATUS LibGetSmbiosSystemGuidAndSerialNumber ( IN EFI_GUID *SystemGuid, OUT CHAR8 **SystemSerialNumber ) { EFI_STATUS Status; SMBIOS_STRUCTURE_TABLE *SmbiosTable; SMBIOS_STRUCTURE_POINTER Smbios; SMBIOS_STRUCTURE_POINTER SmbiosEnd; UINT16 Index; Status = LibGetSystemConfigurationTable(>EfiSMBIOSTableGuid, (VOID **)&SmbiosTable); if (EFI_ERROR(Status)) { return EFI_NOT_FOUND; } // // BUGBUG: Disabled warnings 4306, converting a 32 bit pointer into a // 64 bit pointer. In SMBIOS tables, the addresses are 32 bit, and // causes warning:4306 with 64 bit pointers. Probably need a better // solution. // #pragma warning ( disable : 4306 ) Smbios.Hdr = (SMBIOS_HEADER *)SmbiosTable->TableAddress; SmbiosEnd.Raw = (UINT8 *)(SmbiosTable->TableAddress + SmbiosTable->TableLength); for (Index = 0; Index < SmbiosTable->TableLength ; Index++) { if (Smbios.Hdr->Type == 1) { if (Smbios.Hdr->Length < 0x19) { // // Older version did not support Guid and Serial number // continue; } // // SMBIOS tables are byte packed so we need to do a byte copy to // prevend alignment faults on Itanium-based platform. // CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof(EFI_GUID)); *SystemSerialNumber = LibGetSmbiosString(&Smbios, Smbios.Type1->SerialNumber); return EFI_SUCCESS; } // // Make Smbios point to the next record // LibGetSmbiosString (&Smbios, (UINT16)(-1)); if (Smbios.Raw >= SmbiosEnd.Raw) { // // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e. // given this we must double check against the lenght of /// the structure. My home PC has this bug.ruthard // return EFI_SUCCESS; } } return EFI_SUCCESS; }