shell - 从 UEFI 应用程序内部运行 UEFI shell 命令

标签 shell command bootloader uefi

我是 UEFI 应用程序开发的新手。

我的要求是,

我需要从我的 UEFI 应用程序 (app.efi) 源代码中运行 UEFI shell 命令。
需要有关如何执行此操作的指导。

例子,

cp command in UEFI shell is used to copy a file from one path to another. I want to do this programmatically inside my application (app.efi) source code.



编辑:我正在寻找类似于 system("command"); function in Linux 的东西.

如何做到这一点?

最佳答案

可以使用 EFI_SHELL_EXECUTE 从 UEFI 应用程序调用 UEFI shell 命令。 EFI_SHELL_PROTOCOL的功能, 在 MdePkg/Include/Protocol/Shell.h 下定义.

您需要在 UEFI 应用程序的 inf 文件中包含协议(protocol) GUID:

[Protocols]
  gEfiShellProtocolGuid                  ## CONSUMES

然后您可以调用 shell 命令,如下例所示:
EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE                            ImageHandle,
  IN EFI_SYSTEM_TABLE                      *SystemTable
  )
{
  EFI_SHELL_PROTOCOL    *EfiShellProtocol;
  EFI_STATUS            Status;

  Status = gBS->LocateProtocol (&gEfiShellProtocolGuid,
                                NULL,
                                (VOID **) &EfiShellProtocol);

  if (EFI_ERROR (Status)) {
    return Status; 
  }

  EfiShellProtocol->Execute (&ImageHandle,
                             L"echo Hello World!",
                             NULL,
                             &Status);

  return Status;
}

编辑:使用 ShellLib 库类有一种更简单(可能更正确)的方法:
#include <Library/ShellLib.h>

EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE                            ImageHandle,
  IN EFI_SYSTEM_TABLE                      *SystemTable
  )
{
  EFI_STATUS            Status;

  ShellExecute (&ImageHandle,
                L"echo Hello World!",
                FALSE,
                NULL,
                &Status);

  return Status;
}

关于shell - 从 UEFI 应用程序内部运行 UEFI shell 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38738862/

相关文章:

c - Clion-如何将txt文件的地址作为参数传递给main?

Linux 内核引导在 Uncompressing Linux 处停止...好的,引导内核

assembly - 为什么我的根目录没有被加载? (FAT12)

linux - ubuntu 12.04的启动和停止脚本

linux - Grep 查找具有特定名称的文件

C# MySQL注册系统-Select命令

wpf - Window 中的 CommandBinding 无法捕获 ContextMenu 中命令的执行

assembly - 引导加载程序中的 Masm 字符串变量导致 : Undefined symbol error

Linux find -exec 权限被拒绝

linux - Unix 通配符扩展/正则表达式