Skip to content
Open

Demo #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 99 additions & 55 deletions Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,15 @@ TrampolineBareflank(
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_GUID BareflankGuid = {0x78563412, 0x3412, 0x7856, {0x90, 0x12, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12}}; //TODO: use proper GUID
EFI_GUID BareflankGuid = {0xcd018687, 0xb2c0, 0x4099, {0xb7, 0xc1, 0x0f, 0xda, 0xe2, 0xf7, 0xd0, 0x97}};
EFI_STATUS Status;
EFI_STATUS CleanupStatus;
EFI_HANDLE NewHandle;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
MEMMAP_DEVICE_PATH MemPath[2];
UINTN FvHandleCount;
EFI_HANDLE *FvHandleBuffer;
EFI_FV_FILETYPE Type;
UINTN Size;
EFI_FV_FILE_ATTRIBUTES Attributes;
UINT32 AuthenticationStatus;
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
VOID *Buffer;
Expand All @@ -357,26 +355,19 @@ TrampolineBareflank(
(VOID **) &Fv
);

Status = Fv->ReadFile (
Status = Fv->ReadSection(
Fv,
&BareflankGuid,
EFI_SECTION_PE32,
0,
&Buffer,
&Size,
&Type,
&Attributes,
&AuthenticationStatus
);
if (Status == EFI_NOT_FOUND) {
Print(L"Image not found in Fv[%d]\n", i);
continue;
}
else if (Status == EFI_SUCCESS) {
Print(L"Image found in Fv[%d]\n", i);
Print(L"\tBuffer %x\n", Buffer);
Print(L"\tSize %x\n", Size);
Print(L"\tType %x\n", Type);
Print(L"\tAttributes %x\n", Attributes);
Print(L"\tAuthenticationStatus %x\n", AuthenticationStatus);
break;
}
else {
Expand All @@ -395,8 +386,7 @@ TrampolineBareflank(
MemPath[0].Header.Length[1] = (UINT8)(sizeof(MEMMAP_DEVICE_PATH) >> 8);
MemPath[0].MemoryType = EfiLoaderCode;

// Buffer+4 - header of PE32 **section**. TODO: is it defined anywhere in the code?
MemPath[0].StartingAddress = ((UINTN)Buffer)+4;
MemPath[0].StartingAddress = ((UINTN)Buffer);
MemPath[0].EndingAddress = MemPath[0].StartingAddress + Size;

MemPath[1].Header.Type = END_DEVICE_PATH_TYPE;
Expand Down Expand Up @@ -632,34 +622,96 @@ Trampoline(

SHELL_STATUS
EFIAPI
TestBF(
Cpuid(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
UINTN rax = 0xbf00;
UINT64 rax;
EFI_STATUS Status;

if (ShellInfoObject.NewShellParametersProtocol->Argc < 2) {
ShellPrintEx(-1, -1, L"Not enough arguments\r\n");
return SHELL_INVALID_PARAMETER;
}

ShellPrintEx(-1, -1, L"Testing for Bareflank: ");
Status = StrHexToUint64S(ShellInfoObject.NewShellParametersProtocol->Argv[1],
NULL, &rax);
if (Status != EFI_SUCCESS || rax == 0) {
ShellPrintEx(-1, -1, L"Not a valid hex number: %s\r\n",
ShellInfoObject.NewShellParametersProtocol->Argv[1]);
return SHELL_INVALID_PARAMETER;
}

asm volatile (
"cpuid\n\t"
: "+a"(rax));

if (rax == 0xbf01) {
ShellPrintEx(-1, -1, L"success\r\n");
} else {
ShellPrintEx(-1, -1, L"error (%x)\r\n\
Trying vmcall (this will hang if Bareflank isn't started): ", rax);
asm volatile ("vmcall\n\t");
ShellPrintEx(-1, -1, L"success\r\n");
}
return SHELL_SUCCESS;
}

SHELL_STATUS
EFIAPI
Demo(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
UINT64 rax;

ShellPrintEx(-1, -1, L"This is sample application.\n\
It prints some text and does CPUID to talk to Bareflank based hypervisor.\n");

ShellPrintEx(-1, -1, L"\nTest String Number 1.\n");
gBS->Stall (1000000);
ShellPrintEx(-1, -1, L"cpuid (RAX=0x4BF00101)\n");
rax = 0x4BF00101;
asm volatile (
"cpuid\n\t"
: "+a"(rax));

ShellPrintEx(-1, -1, L"\nTest String Number 2.\n");
gBS->Stall (1000000);
ShellPrintEx(-1, -1, L"cpuid (RAX=0x4BF00102)\n");
rax = 0x4BF00102;
asm volatile (
"cpuid\n\t"
: "+a"(rax));

ShellPrintEx(-1, -1, L"\nTest String Number 3.\n");
gBS->Stall (1000000);
ShellPrintEx(-1, -1, L"cpuid (RAX=0x4BF00103)\n");
rax = 0x4BF00103;
asm volatile (
"cpuid\n\t"
: "+a"(rax));

ShellPrintEx(-1, -1, L"\nTest String Number 4.\n");
gBS->Stall (1000000);
ShellPrintEx(-1, -1, L"cpuid (RAX=0x4BF00104)\n");
rax = 0x4BF00104;
asm volatile (
"cpuid\n\t"
: "+a"(rax));

ShellPrintEx(-1, -1, L"\nTest String Number 5.\n");
gBS->Stall (1000000);
ShellPrintEx(-1, -1, L"cpuid (RAX=0x4BF00100)\n");
rax = 0x4BF00100;
asm volatile (
"cpuid\n\t"
: "+a"(rax));

ShellPrintEx(-1, -1, L"\nTest String Number 6.\n");
gBS->Stall (1000000);
ShellPrintEx(-1, -1, L"\n\nThat's all, returning to Shell.\n");

return SHELL_SUCCESS;
}

CONST CHAR16*
EFIAPI
RtnicGetManFileName (
DummyGetManFileName (
VOID
)
{
Expand Down Expand Up @@ -943,53 +995,45 @@ UefiMain (
ConInHandle = NULL;
}

if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {
//
// process the startup script or launch the called app.
//
Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
}

if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {

ShellCommandRegisterCommandName(L"rtnic", //*CommandString,
&Trampoline, //CommandHandler,
RtnicGetManFileName, //GetManFileName,
ShellCommandRegisterCommandName(L"bareflank", //*CommandString,
&TrampolineBareflank, //CommandHandler,
DummyGetManFileName, //GetManFileName,
3, //ShellMinSupportLevel,
L"", //*ProfileName,
TRUE, //CanAffectLE,
ShellInfoObject.HiiHandle, //HiiHandle,
STRING_TOKEN(STR_GET_HELP_RTNIC) //ManFormatHelp
STRING_TOKEN(STR_SHELL_CRLF) //ManFormatHelp
);
if (Status == EFI_SUCCESS) {
//
// Uncomment the following line to run embedded application on startup
//
//RunCommand(L"rtnic /efuse /r");
} else {
ShellPrintEx(-1, -1, L"\r\nShellCommandRegisterCommandName error: %x\r\n", Status);
}

ShellCommandRegisterCommandName(L"bareflank", //*CommandString,
&TrampolineBareflank, //CommandHandler,
RtnicGetManFileName, //GetManFileName,
ShellCommandRegisterCommandName(L"cpuid", //*CommandString,
&Cpuid, //CommandHandler,
DummyGetManFileName, //GetManFileName,
3, //ShellMinSupportLevel,
L"", //*ProfileName,
TRUE, //CanAffectLE,
ShellInfoObject.HiiHandle, //HiiHandle,
STRING_TOKEN(STR_SHELL_CRLF) //ManFormatHelp
);

ShellCommandRegisterCommandName(L"testbf", //*CommandString,
&TestBF, //CommandHandler,
RtnicGetManFileName, //GetManFileName,
ShellCommandRegisterCommandName(L"demo", //*CommandString,
&Demo, //CommandHandler,
DummyGetManFileName, //GetManFileName,
3, //ShellMinSupportLevel,
L"", //*ProfileName,
TRUE, //CanAffectLE,
ShellInfoObject.HiiHandle, //HiiHandle,
STRING_TOKEN(STR_SHELL_CRLF) //ManFormatHelp
);

if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {
//
// process the startup script or launch the called app.
//
Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);
}

if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {

//
// begin the UI waiting loop
//
Expand Down Expand Up @@ -1322,7 +1366,7 @@ ProcessCommandLine(
ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay = FALSE;
ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit = FALSE;
ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest = FALSE;
ShellInfoObject.ShellInitSettings.Delay = 5;
ShellInfoObject.ShellInitSettings.Delay = 2;

//
// Start LoopVar at 0 to parse only optional arguments at Argv[0]
Expand Down
21 changes: 0 additions & 21 deletions Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.uni
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,3 @@
#string STR_SHELL_NO_IN_EX #language en-US "No SimpleTextInputEx was found. CTRL-based features are not usable.\r\n"

#string STR_SHELL_IMAGE_NOT_APP #language en-US "The image is not an application.\r\n"

#string STR_GET_HELP_RTNIC #language en-US ""
".TH rtnic 0 "start a memory-mapped application"\r\n"
".SH NAME\r\n"
"Starts a memory-mapped application. \r\n"
".SH SYNOPSIS\r\n"
" \r\n"
"rtnic [arguments]\r\n"
".SH OPTIONS\r\n"
" \r\n"
" arguments - Arguments that are passed to the underlying application\r\n"
".SH DESCRIPTION\r\n"
" \r\n"
"NOTES:\r\n"
" 1. This command starts an embedded application. Arguments are passed without\r\n"
" modification, so they are depending on specific application.\r\n"
".SH RETURNVALUES\r\n"
" \r\n"
"RETURN VALUES:\r\n"
" exit-code The return value of started application.\r\n"

14 changes: 2 additions & 12 deletions Vlv2TbltDevicePkg/PlatformPkgGcc.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ DEFINE FLASH_REGION_AZALIABIN_BASE = 0xFFD08000
!endif

DEFINE FLASH_REGION_FVMAIN_OFFSET = 0x00110000
DEFINE FLASH_REGION_FVMAIN_SIZE = 0x00215000

DEFINE FLASH_REGION_BINARY_FIRMWARE_OFFSET = 0x00325000
DEFINE FLASH_REGION_BINARY_FIRMWARE_SIZE = 0x00083000
DEFINE FLASH_REGION_FVMAIN_SIZE = 0x00298000

DEFINE FLASH_REGION_FV_RECOVERY2_OFFSET = 0x003A8000
DEFINE FLASH_REGION_FV_RECOVERY2_SIZE = 0x00020000
Expand Down Expand Up @@ -156,13 +153,6 @@ $(FLASH_REGION_FVMAIN_OFFSET)|$(FLASH_REGION_FVMAIN_SIZE)
gPlatformModuleTokenSpaceGuid.PcdFlashFvMainBase|gPlatformModuleTokenSpaceGuid.PcdFlashFvMainSize
FV = FVMAIN_COMPACT

#
# Binary Firmware
#
$(FLASH_REGION_BINARY_FIRMWARE_OFFSET)|$(FLASH_REGION_BINARY_FIRMWARE_SIZE)
gPlatformModuleTokenSpaceGuid.PcdFlashBinFwBase|gPlatformModuleTokenSpaceGuid.PcdFlashBinFwSize
FILE = target_binary.efi

#
# FV Recovery#2
#
Expand Down Expand Up @@ -660,7 +650,7 @@ FILE DRIVER = 961578FE-B6B7-44c3-AF35-6BC705CD2B1F {
#
# Bareflank
#
FILE APPLICATION = 78563412-3412-7856-9012-123456789012 {
FILE APPLICATION = cd018687-b2c0-4099-b7c1-0fdae2f7d097 {
SECTION PE32 = bareflank.efi
}

Expand Down
2 changes: 1 addition & 1 deletion Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSystemRebootAfterCapsuleProcessFlag|0x0001
###############################################################################################

[PcdsDynamicHii.common.DEFAULT]
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|5 # Variable: L"Timeout"
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|0 # Variable: L"Timeout"
gEfiMdePkgTokenSpaceGuid.PcdHardwareErrorRecordLevel|L"HwErrRecSupport"|gEfiGlobalVariableGuid|0x0|1 # Variable: L"HwErrRecSupport"
gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdBootState|L"BootState"|gEfiBootStateGuid|0x0|TRUE

Expand Down
Loading