Running an EFI application automatically on boot
Asked Answered
S

2

8

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?

Stevenson answered 25/3, 2014 at 17:6 Comment(0)
T
10

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.

Tysontyumen answered 26/3, 2014 at 18:17 Comment(2)
This answer is awesome. Please Nicholas, could you tell me more about the second and third option?Ronnieronny
link is dead :/Plumbago
J
3

@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

Jig answered 11/1, 2016 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.