diff --git a/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.c b/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.c index 618dda27a11..bd8aade9cf9 100644 --- a/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.c +++ b/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.c @@ -325,7 +325,7 @@ 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; @@ -333,9 +333,7 @@ TrampolineBareflank( 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; @@ -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 { @@ -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; @@ -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 ) { @@ -943,36 +995,19 @@ 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, @@ -980,9 +1015,9 @@ UefiMain ( 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, @@ -990,6 +1025,15 @@ UefiMain ( 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 // @@ -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] diff --git a/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.uni b/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.uni index c650ba52e8f..60a64a22e66 100644 --- a/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.uni +++ b/Vlv2TbltDevicePkg/CustomShellPkg/Application/Shell/Shell.uni @@ -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" - diff --git a/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf b/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf index 63ce4300767..c57c296e061 100644 --- a/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf +++ b/Vlv2TbltDevicePkg/PlatformPkgGcc.fdf @@ -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 @@ -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 # @@ -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 } diff --git a/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc b/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc index 8e02b8c87ac..ef1e27068cf 100644 --- a/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc +++ b/Vlv2TbltDevicePkg/PlatformPkgGccX64.dsc @@ -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 diff --git a/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.c b/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.c new file mode 100644 index 00000000000..a7d87629d5b --- /dev/null +++ b/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.c @@ -0,0 +1,83 @@ +/** @file + * + * Sample UEFI Application + * + * Copyright (c) 2019, 3mdeb Embedded Systems Consulting + * +**/ + +#include +#include +#include +#include + +/** + The user Entry Point for Application. The user code starts with this function + as the real entry point for the application. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry point. + +**/ + +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + UINT64 rax; + + Print(L"This is sample application.\n\ +It prints some text and does CPUID to talk to Bareflank based hypervisor.\n"); + + Print(L"\nTest String Number 1.\n"); + gBS->Stall (1000000); + Print(L"cpuid (RAX=0x4BF00101)\n"); + rax = 0x4BF00101; + asm volatile ( + "cpuid\n\t" + : "+a"(rax)); + + Print(L"\nTest String Number 2.\n"); + gBS->Stall (1000000); + Print(L"cpuid (RAX=0x4BF00102)\n"); + rax = 0x4BF00102; + asm volatile ( + "cpuid\n\t" + : "+a"(rax)); + + Print(L"\nTest String Number 3.\n"); + gBS->Stall (1000000); + Print(L"cpuid (RAX=0x4BF00103)\n"); + rax = 0x4BF00103; + asm volatile ( + "cpuid\n\t" + : "+a"(rax)); + + Print(L"\nTest String Number 4.\n"); + gBS->Stall (1000000); + Print(L"cpuid (RAX=0x4BF00104)\n"); + rax = 0x4BF00104; + asm volatile ( + "cpuid\n\t" + : "+a"(rax)); + + Print(L"\nTest String Number 5.\n"); + gBS->Stall (1000000); + Print(L"cpuid (RAX=0x4BF00100)\n"); + rax = 0x4BF00100; + asm volatile ( + "cpuid\n\t" + : "+a"(rax)); + + Print(L"\nTest String Number 6.\n"); + gBS->Stall (1000000); + Print(L"\n\nThat's all, returning to Shell.\n"); + + return EFI_SUCCESS; +} diff --git a/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.dsc b/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.dsc new file mode 100644 index 00000000000..6c04f6de00e --- /dev/null +++ b/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.dsc @@ -0,0 +1,45 @@ +## @file +# SampleApplication Package +# +# Copyright (c) 2019, 3mdeb Embedded Systems Consulting
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + PLATFORM_NAME = SampleApplication + PLATFORM_GUID = 006ff62f-5cdd-49be-b9b8-d4131cc5d313 + PLATFORM_VERSION = 1.0 + DSC_SPECIFICATION = 0x00010006 + OUTPUT_DIRECTORY = Build/SampleApplication + SUPPORTED_ARCHITECTURES = IA32|X64 + BUILD_TARGETS = DEBUG|RELEASE|NOOPT + SKUID_IDENTIFIER = DEFAULT + +[LibraryClasses.common] + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf +!if $(TARGET) == RELEASE + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf +!else + DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf +!endif + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + +[Components] + Vlv2TbltDevicePkg/SampleApplication/SampleApplication.inf diff --git a/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.inf b/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.inf new file mode 100644 index 00000000000..1dae74a6a93 --- /dev/null +++ b/Vlv2TbltDevicePkg/SampleApplication/SampleApplication.inf @@ -0,0 +1,32 @@ +## @file +# +# Sample UEFI Application +# +# Copyright (c) 2019, 3mdeb Embedded Systems Consulting +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SampleApplication + FILE_GUID = d8e12272-b675-4c43-b6c9-ca970c952c15 + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = UefiMain + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources] + SampleApplication.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiApplicationEntryPoint + UefiLib