PI 的BDS阶段

本文深入探讨了EFI(Extensible Firmware Interface)的启动过程,详细解释了BIOS如何从NVRAM中读取启动顺序列表,并介绍了Boot Manager组件的功能及其与用户的交互方式。此外,还分析了BDS阶段的具体实现细节。

The boot sequence for EFI consists of the following:

   The platform firmware reads the boot order list from a globally defined NVRAM variabls, The boot order list defines a list of NVRAM variables that contain information

about what is to be booted. Each NVRAM variable define a Unicode name for the boot option that can be displayed to a user.

 

    The variable also contains a pointer to the hardware device and to a file on that hardware device that contains the EFI image to be loaded.

 

    The variable might also contain paths to the OS partition and directory along with other configuration-specific directories.

 

The NVRAM can also contain load options that are passed directory to the EFI image. The platform firmware has no knowledge of what is contained in the load options. The load options, The load options are set by higher level software when it writes to a global NVRAM variable to set the platform firmware boot policy. This information could be used  to define the location of the OS kernel if it was different than the location of the EFI OS loader.

 

EFI 的启动过程包括下面这些:

BIOS 去读定义在NVRAM 里面的boot order 列表,这个boot order 作为全局变量定义在NVRAM里面。

 

这个变量还包括了一个指向硬件以及文件的指针,说穿了就是指向一个可以启动的 EFI image.

 

Firmware Boot Manager

The boot manager is a component in the EFI firmware that determines which EFI drivers and EFI applications should be explicitly loaded and when. Once the EFI firmware is initialized, it passes control to the boot manager. The boot manager is then responsible for determining what to load and any interactions with the user that may be required to make such a decision. In particular , likely implementation options might include any console interface concerining boot, integrated platform management of boot selections, possible knowledge of ther internal aplications or recovery drivers that may be integrated into the system through the boot manager.

 

Programmatic interaction with the boot manager is accomplishd rhtough globally defined variables. On

 

 

 

 

 

 

 

 

 

BDS 阶段要做的事情,一般是比较固定的,我们先看到bds.c中的BdsEntry 函数

VOID BdsEntry (IN EFI_BDS_ARCH_PROTOCOL *This)
{
    UINTN i;
    
     PERF_END(0, DXE_TOK,NULL, 0);
    PERF_START(0, BDS_TOK, NULL, 0);
    InitPart2(TheImageHandle, pST);
        .
        .
        .
    pBS->LocateHandleBuffer(AllHandles, NULL, NULL, &NumberOfHandles, &RootHandles);
    
    for(i = 0; BdsControlFlowFunctions[i]=NULL;i++) {
        TRACE((TRACE_DXE_CORE, "BDS.%s(%X)\n",
        BdsControlFlowFunctionNames[i],BdsControlFlowFunctions[i]
            ));
        BdsControlFlowFunctions[i]();
         }
}

 

可以看到BDS 要做的事情就是把BdsControlFlowFunctions 这个数组里面所有的函数都跑完。BdsControlFlowFunctions 定义在 BdsBoard.c里面

BDS_CONTROL_FLOW_FUNCTION *BdsControlFlowFunctions[] = {
    BDS_CONTROL_FLOW NULL
};

BDS_CONTROL_FLOW 是一个宏,定义在BootOptioneLinks.h里面

函数很多,
#define BDS_CONTROL_FLOW SignalConnectDriversEvent, SignalCompletePowerManagementProtocolEvent, ConnectRootBridgeHandles,
 RegisterMemoryTypeInformationUpdateCallback, /* Connect Console Devices */ /* Connect ConOut Devices */
 ReportConnectConOutProgressCode, ConnectVgaConOut,
ConnectConOutVariable, InstallConOutStartedProtocol, /* Connect ConIn Devices */
ReportConnectConInProgressCode,
 ConnectUsbConIn, ConnectConInVariable,
 InstallConInStartedProtocol, ConInAvailabilityBeep, /* Full System Initialization */
ConnectEverything, RunDrivers, SignalAllDriversConnectedEvent,
 SignalExitPmAuthProtocolEvent, InitConVars, InstallFwLoadFile,
DefaultFixedBootOrder_Init, ChangeDefaultGroupMap, UpdateBootOptionVariables,
 WorkarroundforNVGC, WorkarroundforI350, RestoreBootorder, AdjustEfiOsBootOrder, FBO_Init,
 ReadBootOptions, FboUpdateBoTagDeviceType, FBO_AdjustWtgPriority, UnmaskOrphanDevices,
 CollectUsbBbsDevices, CollectBootDevices, FilterBootDeviceList, CreateEfiOsBootOption,
MatchBootOptionsToDevices, DeleteUnmatchedUefiHddBootDevices, FboSyncBootOptionsFromDevOrder,
 FboAdjustEthernetDefaultPriority, CreateBootOptionsForNewBootDevices, /*Process Boot Option List*/
 FBO_SetBootOptionTags, EfiOsName_NormalizeBootOptions,  PreProcessBootOptions,
 SetBootOptionPriorities, SetIpmiBootOptionPriorities, PostProcessBootOptions,
MaskOrphanDevices, FBO_UpdateBootListPriority, FboSetLegacyDeviceType,
 FBO_SetDefaultUEFIDevOrder, FBO_AdjustDeviceName, SaveBootOptions, CreateOldBootOrder,
CallTheDispatcher, RecoverTheMemoryAbove4Gb, HandoffToTse, ReadBootOptionAndBoot,

逐个分析显然是不可能的,我们从中拿出一些比较关键的看看。

VOID ConnectVgaConOut(){

 

boot的实质是statimage, 也就是找到boot64/32.efi

option 列表的如构建过程就是通过删除和增加。如果想删除的或者想添加进去的, 和预期的一致,就可以了, 添加还要做合法性检查。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值