UEFI 基础教程 (十四) - 设置默认启动项为UEFI Shell

一 编写源代码

OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c

UINTN
BootOptionPriority (
  CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption
  )
{
  DEBUG ((EFI_D_ERROR," [CSDN] BootOptionPriority  %S .\n", BootOption->Description));

  if (StrCmp (BootOption->Description, L"Boot Device List") == 0) {
      return 4;
  }

  //
  // Make sure Shell is last
  //
  if ( StrStr (BootOption->Description, L"EFI Internal Shell" ) != NULL) {
      return 1;
  }
  return 30;
}

/**

    GC_TODO: add routine description

    @param Left  - GC_TODO: add arg description
    @param Right - GC_TODO: add arg description

    @retval (BOOLEAN) (BootOptionPriority (Left) < BootOptionPriority (Right)) - GC_TODO: add retval description

**/

INTN
EFIAPI
CompareBootOption (
  IN CONST VOID                 *Buffer1,
  IN CONST VOID                 *Buffer2
  )

{
  return (BOOLEAN) (BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION  *) Buffer1) > BootOptionPriority ((EFI_BOOT_MANAGER_LOAD_OPTION  *) Buffer2));
}

VOID
EFIAPI
PlatformBootManagerAfterConsole (
  VOID
  )
  {
  //
  // Register UEFI Shell
  //
  PlatformRegisterFvBootOption (
    &gUefiShellFileGuid, L"EFI Internal Shell", LOAD_OPTION_ACTIVE
    );
    
  ...

  //Add default boot first option as uefi shell
  DEBUG ((EFI_D_ERROR," [CSDN]: EfiBootManagerSortLoadOptionVariable before.\n"));
  EfiBootManagerSortLoadOptionVariable (LoadOptionTypeBoot, CompareBootOption);
  DEBUG ((EFI_D_ERROR," [CSDN]: EfiBootManagerSortLoadOptionVariable after.\n"));
  ...
  
  }

二、 编译生成EFI文件 & 运行

在这里插入图片描述
在这里插入图片描述

设置Shell为默认启动项后,BIOS启动会优先加载Shell(对于OVMD而言就不用等待前面的PXE、QEMU USB加载了, 可以节省时间)。 当然如果需要设置其他的启动项为默认项,只需要修改BootOptionPriority StrCmp (BootOption->Description, L"EFI Internal Shell")StrCmp (BootOption->Description, L"XXXX")

UEFI Shell Default Boot Order DEMO源码

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值