Printing serial number in qemu gives null

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
tiggu
Posts: 1
Joined: Wed May 29, 2024 3:07 am

Printing serial number in qemu gives null

Post by tiggu »

Hi all, this is my first post in this forum. I am using gnu-efi and QEMU as an emulator. X64 is the arch and uefi is targeted.
I am trying to print the serial number but it gives null, so far the manufacturer and product name prints out fine.
Is there anything I am doing wrong?

Code: Select all

#include <efi.h>
#include <efilib.h>

EFI_STATUS
EFIAPI
efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
	EFI_STATUS Status;
	SMBIOS_STRUCTURE_POINTER Smbios;
	SMBIOS_STRUCTURE_TABLE *SmbiosTable;
	UINTN MaximumSize, ProcessedSize = 0;
	UINT8 Found = 0, *Raw;

	InitializeLib(ImageHandle, SystemTable);

	Print(L"Hello!\n");
	Status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, (VOID **)&SmbiosTable);
	if (Status == EFI_SUCCESS)
	{
		Print(L"yay!\n");
		Smbios.Hdr = (SMBIOS_HEADER *)(UINTN)SmbiosTable->TableAddress;
		MaximumSize = (UINTN)SmbiosTable->TableLength;
	}
	while ((Smbios.Hdr->Type != 0x7F) && (Found < 2))
	{
		Raw = Smbios.Raw;
		if (Smbios.Hdr->Type == 1)
		{
			Print(L"%a, %a, %a \n", LibGetSmbiosString(&Smbios, Smbios.Type1->Manufacturer),
				  LibGetSmbiosString(&Smbios, Smbios.Type1->ProductName), LibGetSmbiosString(&Smbios, Smbios.Type1->SerialNumber));
			Found++;
		}
		LibGetSmbiosString(&Smbios, -1);
		ProcessedSize += (UINTN)Smbios.Raw - (UINTN)Raw;
		if (ProcessedSize > MaximumSize)
		{
			Print(L"%EAborting system report due to noncompliant SMBIOS%N\n");
			return EFI_ABORTED;
		}
	}

	return EFI_SUCCESS;
}

Octocontrabass
Member
Member
Posts: 5497
Joined: Mon Mar 25, 2013 7:01 pm

Re: Printing serial number in qemu gives null

Post by Octocontrabass »

QEMU has default text for the manufacturer and product names, but not the serial number. Did you tell QEMU to put a serial number in the SMBIOS tables?
Post Reply