0

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?

  • What commands are in your shells' `startup.nsh`? – fpmurphy May 04 '21 at 03:29
  • I tested without startup.nsh. Only later added some echo prints there, nothing more. – Alex Nemkovich May 04 '21 at 07:13
  • `Startup.nsh` I not the reason, I think. Because, as I described, loading same device in different ways (by default boot or manually from boot menu) gives different results, although same shell and same `startup.nsh` files are loaded. – Alex Nemkovich May 04 '21 at 07:24
  • Some uefi systems implement a "Fast boot" mode. When this mode is activ not all drivers are loaded. Check your uefi menu for such a setting. – MiSimon May 04 '21 at 11:07
  • Yes, you are right. In "Fast boot" mode some drivers are not loaded. So, next question: How I can load them by myself in this case from my efi app or driver? – Alex Nemkovich May 04 '21 at 12:12
  • Or maybe by shell – Alex Nemkovich May 04 '21 at 12:32
  • 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. – MiSimon May 04 '21 at 12:36
  • MiSimon, I've tried to load drivers, according to your advice, using EFI_FIRMWARE_VOLUME2_PROTOCOL, like that Status = gBS->LocateHandleBuffer(...&gEfiFirmwareVolume2ProtocolGuid... ... Status = gBS->HandleProtocol(...&gEfiFirmwareVolume2ProtocolGuid... ... NextStatus = Fv->GetNextFile(Fv, Key, &FileType, &NameGuid, &Attribute...; ... Status = Fv->ReadSection(...EFI_SECTION_USER_INTERFACE ... DevicePath = FvFileDevicePath(Buffer[Index], &NameGuid); ... Status = gBS->LoadImage(FALSE, gImageHandle, DevicePath, NULL, 0, &ImageHandle); ... Status = gBS->StartImage(ImageHandle – Alex Nemkovich May 06 '21 at 17:03
  • And it works, I loaded some drivers in this way, but Realtek UNDI driver and other UNDI drivers were not among them. Am I missing something? – Alex Nemkovich May 06 '21 at 17:09
  • It could also be stored inside a PCI option ROM (Specification 2.9, Chapter 14.4.2 PCI Option ROMs). When i run the "drivers" command in the efi shell is get the source of the image, in my case the Relatek UEFI Undi Driver was loaded from FV(xxxx)/FvFile(xxxx), what is the source of the driver on your system? – MiSimon May 07 '21 at 10:13
  • You were right! I didn't find Realtek UEFI Undi Driver by mistake, but it was there among other files, as you said. Thank you for your advice, I highly appreciate it!!! – Alex Nemkovich Jan 04 '22 at 07:22
  • @AlexNemkovich, do you have steps you try on the RtkUndiDxe.efi? How you get the RtkUndiDxe.efi to auto load into the UEFI shell? – Chau Chee Yang Sep 03 '22 at 14:48

1 Answers1

0

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 ...