Running an EFI application automatically on boot

情到浓时终转凉″ 提交于 2019-12-03 15:49:01

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.

Piotr Król

@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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!