Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running an EFI application automatically on boot

Tags:

uefi

efi

I can build and manually execute an EFI application in a UEFI environment. But, I'd like to have my application executed automatically at boot time.

Is there a way to tell the bootloader to do this or do I need to turn my application in to a driver to have it automatically executed? Is there maybe some entry in an FDF, DEC, DSC, or INF file I'm missing?

like image 846
PaulH Avatar asked Mar 25 '14 17:03

PaulH


People also ask

How do I boot with EFI?

You can boot from an EFI file by pressing the F9 key to launch the Boot Devices Options menu.

What is EFI boot entry?

EFIBOOTMGR(8) efibootmgr is a tool for managing UEFI boot entries. It is not a bootloader. It is a tool that interacts with the EFI firmware of the system, which itself is acting as a boot manager. Using efibootmgr boot entries can be created, reshuffled and removed.

What is the difference between Legacy and UEFI?

UEFI runs in 32-bit and 64-bit, allowing support for mouse and touch navigation. Legacy runs in 16-bit mode that only supports keyboard navigation. It allows a secure boot that prevents the loading of unauthorized applications. It may also hinder dual boot because it treats operating systems (OS) as applications.

What is EFI shell booting?

The UEFI interactive shell is a simple shell program (like bash) responsible for booting your operating system. You can also use the UEFI interactive shell to run EFI shell commands and scripts. It can be used to update the System Firmware of your motherboard as well.


2 Answers

You can add a startup.nsh script file to your UEFI Shell boot drive that calls you application.

The following link should serve as a handy reference for working with scripts in the shell: UEFI Shells and Scripting. Look at section 3 (EFI Shell Scripts) specifically.

However, if you are actually building your own firmware, you can also look at creating a bootable EFI image and set your default boot option to this binary. This is most useful if you are including the binary as a part of your ROM, but it might be a little involved to set up the filesystem so that it is seen as a normal boot option.

Also, if you have complete access to your firmware source, you could also just load and call your binary from your BDS driver. I don't recommend this route, unless you are specifically aiming to create a standalone device that will never boot any other image.

like image 59
Rose Lynn Embry Avatar answered Jan 04 '23 06:01

Rose Lynn Embry


@NicholasEmbry answer contain almost all what is needed, but I would like to clarify some things and add recent improvements in that area.

Adding UEFI application image to boot option is actually best known method when you don't have source code of your firmware, what is typical situation. You don't have to create any special bootable image it should be simple UEFI application image, what means that your INF should contain:

MODULE_TYPE           = UEFI_APPLICATION

This option is not just for Option ROMs this is for all UEFI readable medium. For example you can create FAT32 partition on your storage (no matter if it is USB, HDD, SSD, etc. it just have to be readable by firmware) and place application image on this partition. Then boot to UEFI Shell and use bcfg command to affect your boot order.

bcfg command can be blocked by you BIOS vendor. In that situation please follow procedure from this post. This is booting rEFInd using USB stick. rEFInd contain bcfg tool and give you ability to use it.

How to use bcfg ?

All is described in help help bcfg -b. -b is UEFI pager. For those who like shortcuts, this command will display all boot options in system:

bcfg boot dump -v

You can add your application using command:

bcfg boot add <boot_pos> <path_to_uefi_image> <boot_order_name>

<boot_pos> - position in boot order. Note you usually want to put your application before OS. If there is no free boot option number before your OS you can of course move your OS one option down bcfg boot mv <old_pos> <new_pos> and then add your application image in between.

<path_to_uefi_image> - path to your UEFI image. This is UEFI readable path ie. fs0:\foobar.efi

<boot_order_name> - this is how you application will be visible in boot BIOS menu

like image 45
Piotr Król Avatar answered Jan 04 '23 05:01

Piotr Król