0

I have setup the UDK2014 and EDK2 source and am successfully building an EFI application that runs fine in the SecMain emulator. However when I transfer the application to a real UEFI system and run it the system hangs. I've tried just a simple application that prints hello world:

#include <Uefi.h>
#include <Library/PcdLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiApplicationEntryPoint.h>


EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
    SystemTable->ConOut->OutputString(SystemTable->ConOut, (CHAR16*)L"Hello World22\r\n");
    SystemTable->ConOut->OutputString(SystemTable->ConOut, SystemTable->FirmwareVendor);

  return EFI_SUCCESS;
}

It is a UEFI 32 bit system that I'm testing on, and I'm targeting 32 bit in my UDK/EDK2 build.

Do I need to do anything special to build for targeting a real system versus the SecMain test environment that comes with UDK/EDK2?

Without Me It Just Aweso
  • 4,593
  • 10
  • 35
  • 53

2 Answers2

1

You should not need to do anything special, applications that use the standard UEFI APIs and protocols should work in real systems same as in emulated environment. I do not have a 32-bit platform to try, but I did the opposite - built for 64-bit and tried your code on a 64-bit system - all works.

Are you sure you have a 32-bit system with the 32-bit UEFI BIOS? Your symptoms do look like running under 64-bit UEFI BIOS and most of the commercial systems out there are 64-bit with 64-bit UEFI BIOSes in them.

I would try to comment-out the two SystemTable->ConOut->OutputString lines to see if the application still hangs. If the app loads properly and exits then the problem may be related to emulated environment building with different libraries. I did notice that my 64-bit app is ~1K long and the 32-bit app built in emulated environment is ~24K long.

sun2sirius
  • 455
  • 2
  • 10
1

There are several reasons for an UEFI app working correctly under SecMain while failing in a real system i.e.

  1. Different initialization conditions. When using display routines the display must be set correctly. i.e. it could be necessary invoking something like:

    {
      SystemTable->ConOut->Reset(SystemTable->ConOut, FALSE);
      SystemTable->ConOut->OutputString(SystemTable->ConOut, (CHAR16*)L"Hello World22\r\n");
      SystemTable->ConOut->OutputString(SystemTable->ConOut, SystemTable->FirmwareVendor);
      return EFI_SUCCESS;
    }
    
  2. Partial UEFI implementation. If your real system partially implements the EFI SIMPLE TEXT OUTPUT PROTOCOL i.e. the FirmwareVendor pointer might be undefined; if that happens you would be de-referencing a bad pointer what leads to a crash.

      SystemTable->ConOut->OutputString(SystemTable->ConOut, SystemTable->FirmwareVendor);
    
Pat
  • 2,670
  • 18
  • 27