UEFI shell - 简单认识

1. UEFI shell作用

EFI Shell是EFI提供的一个交互式的命令行Shell环境,在这里你可以执行一些efi应用程序,加载efi设备驱动程序.

一般从Setup下面的Boot Manager或者快捷启动进入,其画风如下:
在这里插入图片描述
在这里插入图片描述

2. UEFI shell的加载

在edk2下面的ShellPkg就是UEFI shell对应的开源包
从开发者角度讲其实就是一个UEFI_APPLICATION类型的应用程序,只是它的功能比较特殊而已.
其工程文件ShellPkg/Application/Shell/Shell.inf

[Defines]
  INF_VERSION                    = 0x00010006
  BASE_NAME                      = Shell
  FILE_GUID                      = 7C04A583-9E3E-4f1c-AD65-E05268D0B4D1 # gUefiShellFileGuid
  MODULE_TYPE                    = UEFI_APPLICATION
  VERSION_STRING                 = 1.0
  ENTRY_POINT                    = UefiMain

在我们build的OvmfPkg的dsc文件已经把shell加进去了

!if $(TOOL_CHAIN_TAG) != "XCODE5"
INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
!endif
INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
INF  ShellPkg/Application/Shell/Shell.inf

在Build/OvmfX64/DEBUG_GCC5/X64/ShellPkg/Application/Shell/Shell/OUTPUT这个目录下面把Shell.efi取出来,在虚拟机的uefi shell执行下
在这里插入图片描述在这里插入图片描述这里就有一个疑问我们是在UEFI shell去执行这个shell.efi,但是UEFI是怎么执行到UEFI shell的呢?这个问题我们要看下BDS部分:
UEFI系统在启动的时候,会去根据对应GUID找到shell.efi,并且创建UEFI shell的启动项,再由BDS调用
edk2/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c

//
  // Register UEFI Shell
  //
  PlatformRegisterFvBootOption (
    &gUefiShellFileGuid, L"EFI Internal Shell", LOAD_OPTION_ACTIVE
    );

3. UEFI shell的代码实现

shell.efi的入口函数在shell.c的UefiMain
首先会先init各种资源

省略...
//
    // Now initialize the shell library (it requires Shell Parameters protocol)
    //
    Status = ShellInitialize();
    ASSERT_EFI_ERROR(Status);

    Status = CommandInit();
    ASSERT_EFI_ERROR(Status);

    Status = ShellInitEnvVarList ();
省略...

然后根据cmd进行处理

CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;
    Status = RunCommand(CmdLine);
//
    // Depending on the first parameter we change the behavior
    //
    switch (Type = GetOperationType(FirstParameter)) {
      case   File_Sys_Change:
        Status = ChangeMappedDrive (FirstParameter);
        break;
      case   Internal_Command:
      case   Script_File_Name:
      case   Efi_Application:
        Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol, CommandStatus);
        break;
      default:
        //
        // Whatever was typed, it was invalid.
        //
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
        SetLastError(SHELL_NOT_FOUND);
        break;
    }

从上面看:
uefi shell下面处理主要分为两部分

  1. File_Sys_Change (改变目录)
  2. 具体操作
    1. Internal_Command (内置命令)
    2. Script_File_Name (脚本文件)
    3. Efi_Application (应用程序)
  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值