Search code examples
network-programmingbiosuefiedk2

Realtek UEFI UNDI Driver not loaded


I am developing efi application that should work with network. I changed EFI\Boot\bootx64.efi file to efi shell to make starting efi shell on system start by default for convenience. When shell starts I run command ifconfig -l to view available network interfaces settings.

And I faced the following behavior.

When system by default boots my shell (EFI\Boot\bootx64.efi), I don't see any network interfaces, running command ifconfig -l. But. If I boot t same file (EFI\Boot\bootx64.efi) manually using (testing on HP Laptop)"boot menu/boot from file", shell starts and ifconfig -l shows network inteface eth0.

So, loading same efi file with default system boot or manually from boot menu gives me different results for network availability.

I decided to compare lists of loaded drivers in both cases and. I noticed, that when system boots in default mode (not by manually specifying device from boot menu) driver Realtek UEFI UNDI Driver is absent. When I manually boot from file (EFI\Boot\bootx64.efi), it's loaded.

I think absence of this driver 'Realtek UEFI UNDI Driver' is the reason. To check this I did following test:

  1. downloaded from network Realtek UNDI driver (RtkUndiDxe.efi)
  2. copied it to efi boot folder (EFI\Boot\)
  3. booted into shell by system default boot and loaded Realter UNDI driver manually by command load 'RtkUndiDxe.efi As result, network interfaces appeared.

Can somebody explain me, why by default system boot Realtek UEFI UNDI Driver is not loaded? Or how i can make system to load it's own Realtek UEFI UNDI Driver from my own efi app/driver?


Solution

  • Some drivers are not loaded in "Fast boot" option in BIOS. When I turned it off, now network drivers and some others are loaded.

    But also you can load needed drivers even with "Fast boot" option turned on on your own, using EFI Firmware Volume2 Protocol as said MiSimon in comments to my question.

    You can use the LoadImage and StartImage functions inside EFI_BOOT_SERVICE (gBS). You must provide the correct device path to the LoadImage function, you have to search the correct firmware file first using the EFI_FIRMWARE_VOLUME2_PROTOCOL protocol.

    Below is sample of code (without error handling and other stuff), that enumerates firmware driver files and loads them to memory.

    ... Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NoFvHandles, &FvHandleList);
    ... Status = gBS->HandleProtocol(FvHandleList[Index], &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv); 
    ... NextStatus = Fv->GetNextFile(Fv, Key, &FileType, &NameGuid, &Attributes, &FileSize); 
    ... Status = Fv->ReadSection(Fv, &NameGuid, EFI_SECTION_USER_INTERFACE ...
    ... DevicePath = FvFileDevicePath(FvHandleList[Index], &NameGuid); 
    ... Status = gBS->LoadImage(FALSE, gImageHandle, DevicePath, NULL, 0, &ImageHandle); 
    ... Status = gBS->StartImage(ImageHandle ...