【UEFI Spec笔记】Boot Manager


Boot Manager

UEFI Boot Manager是一个固件策略引擎,Boot Manager按照全局NVRAM变量定义的顺序加载UEFI drivers程序和UEFI applications程序(包括UEFI OS boot loaders)。

1.boot order list 定义了一个NVRAM变量列表,其中包含关于要引导的内容的信息。
2.每个NVRAM变量为可以显示给用户的启动选项定义了一个名称。
3.该变量还包含一个指向硬件设备和硬件设备上包含要加载的UEFI映像的文件的指针。
4.该变量还可能包含到OS分区和目录的路径,以及其他特定于配置的目录。


一、Firmware Boot Manager

1. Boot Manager 设计

因为boot manager是从nvram里面获取的启动项列表,所以可以通过Setvariable()修改。

每个加载选项条目都位于Boot####、Driver####、SysPrep####、OsRecovery####或PlatformRecovery####变量中,其中####由一个可打印的十六进制数字(0-9)和字符a - f的大写版本替换(0000-FFFF)。

DriverOrder是Driver####加载顺序。BootOrder是Boot####加载顺序。

可以通过添加、删除或修改Boot####去操作新的引导选项,BootOrder也会更新顺序。

Boot manager会根据BootOrder顺序去load启动项,如果load失败,则按顺序load下一个,如果返回EFI_SUCCESS则load进启动项。

Secure Boot会影响Boot manager行为。

2. Load Option 流程

Boot manager需要在启动加载选项项之前处理驱动程序加载选项项。

如果在osindicators中设置了EFI_OS_INDICATIONS_START_OS_RECOVERY位,则固件将尝试操作系统定义的恢复(参见3.4.1节),而不是正常的启动处理。如果在osindicators中设置了EFI_OS_INDICATIONS_START_PLATFORM_RECOVERY位,固件将尝试平台定义的恢复(见3.4.2节),而不是正常的引导处理EFI_OS_INDICATIONS_START_OS_RECOVERY位的处理。在任何一种情况下,两个比特都应该被清除。

Boot manager会先引导BootNext启动项,引导失败才会使用BootOrder列表,在将控制转移到预选的引导选项之前删除BootNext。

Boot manager如果LoadImage()成功,在StartImage()之前,必须先使用EFI_BOOT_SERVICES. setwatchdogtimer()启动看门狗定时器,启动时间为5分钟。如果引导选项将控制返回给引导管理器,则引导管理器必须通过额外调用SetWatchdogTimer()引导服务来禁用看门狗定时器。

UEFI引导管理器支持USB WWID或USB Class设备路径,硬盘介质设备路径,File path Media device path,URI设备路径。

3. Load Options

每个Load Options variable包含一个EFI_LOAD_OPTION描述符。

typedef struct _EFI_LOAD_OPTION {
UINT32 Attributes;
UINT16 FilePathListLength;
// CHAR16 Description[];
// EFI_DEVICE_PATH_PROTOCOL FilePathList[];
// UINT8 OptionalData[];
} EFI_LOAD_OPTION;

4. Boot Manager 功能

definevalue描述
EFI_BOOT_OPTION_SUPPORT_KEY0x00000001支持按键启动
EFI_BOOT_OPTION_SUPPORT_APP0x00000002详见spec
EFI_BOOT_OPTION_SUPPORT_SYSPREP0x00000010支持SysPrep####形式启动
EFI_BOOT_OPTION_SUPPORT_COUNT0x00000300按键启动最大次数

EFI_BOOT_OPTION_SUPPORT_APP可以创建单独的Boot ####。
EFI_BOOT_OPTION_SUPPORT_KEY 设置之后可以设置热键,匹配Key####来使用热键启动启动项。
SysPrep####指定UEFI应用程序,该应用程序需要执行,以便在处理任何Boot####变量之前完成系统准备。SysPrep####应用程序的执行顺序由变量SysPrepOrder的内容决定。

所有SysPrep####变量启动并退出后,平台通知EFI_EVENT_GROUP_READY_TO_BOOT和EFI_EVENT_GROUP_AFTER_READY_TO_BOOT事件组,并根据BootOrder定义的顺序开始对属性设置为LOAD_OPTION_CATEGORY_BOOT的Boot####变量进行求值。标记为LOAD_OPTION_CATEGORY_BOOT的变量的FilePathList在EFI_EVENT_GROUP_AFTER_READY_TO_BOOT事件组处理完成之前不被评估。

二、Boot Manager Policy Protocol

EFI_BOOT_MANAGER_POLICY_PROTOCOL

struct _EFI_BOOT_MANAGER_POLICY_PROTOCOL {
UINT64 Revision; 
EFI_BOOT_MANAGER_POLICY_CONNECT_DEVICE_PATH ConnectDevicePath;
EFI_BOOT_MANAGER_POLICY_CONNECT_DEVICE_CLASS ConnectDeviceClass;
};

三、Globally Defined Variables

定义了一些全局变量供开发者使用:

全局变量意义
Boot####启动项
BootCurrent当前启动项
BootNext下次启动启动项
ConIn默认输入控制台设备路径

更多可使用变量请查看spec

四、Boot Option 恢复

启动选项失败恢复机制

五、Boot 机制

1.使用EFI_SIMPLE_FILE_SYSTEM_PROTOCOL 或者EFI_LOAD_FILE_PROTOCOL启动


总结

后续有更深理解,会继续补充。
学艺不精,错误请指正;
如有侵权,请联系删除。

参考文档: 《UEFI_Spec_2_9_2021_03_18》

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
This Unified Extensible Firmware Interface (hereafter known as UEFI) Specification describes an interface between the operating system (OS) and the platform firmware. UEFI was preceded by the Extensible Firmware Interface Specification 1.10 (EFI). As a result, some code and certain protocol names retain the EFI designation. Unless otherwise noted, EFI designations in this specification may be assumed to be part of UEFI. The interface is in the form of data tables that contain platform-related information, and boot and runtime service calls that are available to the OS loader and the OS. Together, these provide a standard environment for booting an OS. This specification is designed as a pure interface specification. As such, the specification defines the set of interfaces and structures that platform firmware must implement. Similarly, the specification defines the set of interfaces and structures that the OS may use in booting. How either the firmware developer chooses to implement the required elements or the OS developer chooses to make use of those interfaces and structures is an implementation decision left for the developer. The intent of this specification is to define a way for the OS and platform firmware to communicate only information necessary to support the OS boot process. This is accomplished through a formal and complete abstract specification of the software-visible interface presented to the OS by the platform and firmware. Using this formal definition, a shrink-wrap OS intended to run on platforms compatible with supported processor specifications will be able to boot on a variety of system designs without further platform or OS customization. The definition will also allow for platform innovation to introduce new features and functionality that enhance platform capability without requiring new code to be written in the OS boot sequence. Furthermore, an abstract specification opens a route to replace legacy devices and firmware code over time. New device types and associated code can provide equivalent functionality through the same defined abstract interface, again without impact on the OS boot support code. The specification is applicable to a full range of hardware platforms from mobile systems to servers. The specification provides a core set of services along with a selection of protocol interfaces. The selection of protocol interfaces can evolve over time to be optimized for various platform market segments. At the same time, the specification allows maximum extensibility and customization abilities for OEMs to allow differentiation. In this, the purpose of UEFI is to define an evolutionary path from the traditional “PC-AT”- style boot world into a legacy-API free environment.
统一可扩展固件接口(UEFI)规范描述了操作系统和平台固件之间的接口。UEFI之前是可扩展固件接口规范1.10 (EFI)。因此,一些代码和某些协议名称保留了EFI名称。除非另有说明,本规范中的EFI名称可能被认为是UEFI的一部分。 接口采用数据表的形式,其中包含与平台相关的信息,以及OS加载器和OS可用的引导和运行时服务调用。它们共同提供了一个引导操作系统的标准环境。本规范是作为一个纯粹的接口规范设计的。因此,该规范定义了平台固件必须实现的接口和结构集。类似地,该规范定义了操作系统在引导时可能使用的一组接口和结构。固件开发人员如何选择实现所需的元素,或者操作系统开发人员如何选择利用这些接口和结构,这是留给开发人员的实现决策。 该规范的目的是定义一种方法,使操作系统和平台固件仅通信支持操作系统引导过程所必需的信息。这是通过平台和固件提供给操作系统的软件可见接口的正式和完整的抽象规范来实现的。 使用这一正式定义,旨在运行在与受支持的处理器规范兼容的平台上的收缩包装操作系统将能够在各种系统设计上启动,而无需进一步的平台或操作系统定制。该定义还允许平台创新引入新特性和功能,以增强平台的能力,而不需要按照操作系统的引导顺序编写新代码。 此外,抽象规范开辟了一条替代遗留设备和固件代码的路径。新的设备类型和相关代码可以通过相同定义的抽象接口提供同等的功能,同样不会影响OS引导支持代码。 该规范适用于从移动系统到服务器的所有硬件平台。该规范提供了一组核心服务以及一组协议接口。协议接口的选择可以随着时间的推移而发展,并针对不同的平台市场细分进行优化。与此同时,该规范允许oem提供最大限度的可扩展性和定制能力,以实现差异化。在这方面,UEFI的目的是定义一个从传统的“PC-AT”风格的引导世界到一个没有遗留api的环境的进化路径。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值