I\'m new to UEFI application development.
My requirement is that,
I need to run an UEFI shell command from my UEFI application (app.efi
) source
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
.
You need to include the protocol GUID in the inf file of your UEFI application:
[Protocols]
gEfiShellProtocolGuid ## CONSUMES
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;
}
EDIT: There's an easier (and probably a more correct) way of doing it using ShellLib Library Class:
#include
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;
}