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下面处理主要分为两部分
- File_Sys_Change (改变目录)
- 具体操作
- Internal_Command (内置命令)
- Script_File_Name (脚本文件)
- Efi_Application (应用程序)
版权声明:本文为zhangliang19950813原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。