从 UEFI 应用程序内部运行 UEFI shell 命令 [英] Run a UEFI shell command from inside UEFI application

查看:42
本文介绍了从 UEFI 应用程序内部运行 UEFI shell 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to UEFI application development.

我的要求是,

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

I need to run an UEFI shell command from my UEFI application (app.efi) source code. Need guidance on how I can do this.

例子,

cp 命令用于将文件从一个路径复制到其他.我想在我的应用程序中以编程方式执行此操作(app.efi) 源代码.

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"); 功能的东西在 Linux 中.

I'm looking for something similar to system("command"); function in Linux.

如何做到这一点?

推荐答案

从 UEFI 应用程序调用 UEFI shell 命令可以使用 EFI_SHELL_PROTOCOLEFI_SHELL_EXECUTE 函数来完成,在 MdePkg/Include/Protocol/Shell.h 下定义.

Calling a UEFI shell command from a UEFI application can be done using the EFI_SHELL_EXECUTE function of EFI_SHELL_PROTOCOL, defined under MdePkg/Include/Protocol/Shell.h.

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

You need to include the protocol GUID in the inf file of your UEFI application:

[Protocols]
  gEfiShellProtocolGuid                  ## CONSUMES

然后你可以像下面的例子那样调用一个shell命令:

Then you can call a shell command like in the following example:

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 库类有一种更简单(可能更正确)的方法:

There's an easier (and probably a more correct) way of doing it using ShellLib Library Class:

#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;
}

这篇关于从 UEFI 应用程序内部运行 UEFI shell 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆