Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for new UEFI releases (mppark) #4

Merged
merged 3 commits into from
Aug 31, 2020
Merged
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
2 changes: 2 additions & 0 deletions contrib/msvc/uefi-simple.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@
<ClInclude Include="..\..\include\scm.h" />
<ClInclude Include="..\..\include\suptypes.h" />
<ClInclude Include="..\..\include\xplatprimitives.h" />
<ClInclude Include="..\..\include\BlBootConfiguration.h" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\PreloaderEnvironment.h" />
<ClCompile Include="..\..\src\BlApplicationEntry.c" />
<ClCompile Include="..\..\src\BlBootConfiguration.c" />
<ClCompile Include="..\..\src\Context.c" />
<ClCompile Include="..\..\src\EFIApp.c" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions contrib/msvc/uefi-simple.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<ClInclude Include="..\..\include\PreloaderEnvironment.h">
<Filter>Header Files\Application</Filter>
</ClInclude>
<ClInclude Include="..\..\include\BlBootConfiguration.h">
<Filter>Header Files\Application</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\EFIApp.c">
Expand All @@ -88,6 +91,9 @@
<ClCompile Include="..\..\src\BlApplicationEntry.c">
<Filter>Source Files\BootApp</Filter>
</ClCompile>
<ClCompile Include="..\..\src\BlBootConfiguration.c">
<Filter>Source Files\BootApp</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<MASM Include="..\..\src\ARM\ProcessorSupport.asm">
Expand Down
42 changes: 42 additions & 0 deletions include/BlBootConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
#ifndef _BOOTCONFIG_H_

#include <efi.h>
#include <efilib.h>

// Sup types
#include "suptypes.h"

// Bootloader
#include "bl.h"
#include "context.h"

typedef struct _BcdElementType
{
union {
ULONG PackedValue;
struct {
ULONG SubType : 24;
ULONG Format : 4;
ULONG Class : 4;
};
};
} BcdElementType, * PBcdElementType;

EFI_STATUS BlGetBootOptionBoolean(
PBL_BCD_OPTION List,
ULONG Type,
BOOLEAN* Value
);

EFI_STATUS BlGetBootOptionInteger(
PBL_BCD_OPTION List,
ULONG Type,
UINT64* Value
);

EFI_STATUS BlGetLoadedApplicationEntry(
PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters,
PBL_LOADED_APPLICATION_ENTRY BlpApplicationEntry
);
#endif
26 changes: 23 additions & 3 deletions include/PreloaderEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,36 @@
#define PRELOADER_ENV_ADDR 0xb0000000
#define PRELOADER_HEADER SIGNATURE_32('B', 'S', 'E', 'N')

typedef struct _PRELOADER_ENVIRONMENT {
typedef enum _PRELOADER_ENVIRONMENT_BOOT_MODE {
BOOT_MODE_PSCI = 0,
BOOT_MODE_MPPARK,
BOOT_MODE_MPPARK_EL2,
BOOT_MODE_MAX
} PRELOADER_ENVIRONMENT_BOOT_MODE;

typedef struct _PRELOADER_ENVIRONMENT_VERSION_1 {
UINT32 Header;
UINT32 PreloaderVersion;
CHAR8 PreloaderRelease[64];
EFI_TIME BootTimeEpoch;
UINT32 UefiDisplayInfo[30];
UINT32 Crc32;
} PRELOADER_ENVIRONMENT_VERSION_1, * PPRELOADER_ENVIRONMENT_VERSION_1;

typedef struct _PRELOADER_ENVIRONMENT_VERSION_2 {
UINT32 Header;
UINT32 PreloaderVersion;
CHAR8 PreloaderRelease[64];
EFI_TIME BootTimeEpoch;
UINT32 UefiDisplayInfo[30];
UINT32 Crc32;
} PRELOADER_ENVIRONMENT, *PPRELOADER_ENVIRONMENT;
UINT32 BootMode;
UINT32 EnablePlatformSdCardBoot;
UINT32 UseQuadCoreConfiguration;
UINT32 Crc32v2;
} PRELOADER_ENVIRONMENT_VERSION_2, *PPRELOADER_ENVIRONMENT_VERSION_2;

#endif

#define PRELOADER_VERSION 0x1000
#define PRELOADER_VERSION 0x2000
#define PRELOADER_RELEASE "PreLoader Unknown Release"
4 changes: 4 additions & 0 deletions include/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
// Status enum
#include "ntstatus.h"

// BCD
#include "BlBootConfiguration.h"

// Exports
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
EFI_STATUS EFIApp_Main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable, PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters);
7 changes: 4 additions & 3 deletions src/BlApplicationEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ NTSTATUS BlApplicationEntry(
// Do what ever you want now
if (FirmwareDescriptor->SystemTable)
{
efi_main(
FirmwareDescriptor->ImageHandle,
FirmwareDescriptor->SystemTable
EFIApp_Main(
FirmwareDescriptor->ImageHandle,
FirmwareDescriptor->SystemTable,
BootAppParameters
);
}

Expand Down
139 changes: 139 additions & 0 deletions src/BlBootConfiguration.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include <efi.h>
#include <efilib.h>

#include "application.h"

EFI_STATUS MiscGetBootOption(
_In_ PBL_BCD_OPTION List,
_In_ ULONG Type)
{
uint32_t NextOption = 0, ListOption;
PBL_BCD_OPTION Option, FoundOption;

/* No options, bail out */
if (!List)
{
return EFI_SUCCESS;
}

/* Loop while we find an option */
FoundOption = NULL;
do
{
/* Get the next option and see if it matches the type */
Option = (PBL_BCD_OPTION)((uint32_t)List + NextOption);
if ((Option->Type == Type) && !(Option->Empty))
{
FoundOption = Option;
break;
}

/* Store the offset of the next option */
NextOption = Option->NextEntryOffset;

/* Failed to match. Check for list options */
ListOption = Option->ListOffset;
if (ListOption)
{
/* Try to get a match in the associated option */
Option = MiscGetBootOption((PBL_BCD_OPTION)((uint32_t)Option +
ListOption),
Type);
if (Option)
{
/* Return it */
FoundOption = Option;
break;
}
}
} while (NextOption);

/* Return the option that was found, if any */
return FoundOption;
}

EFI_STATUS BlGetLoadedApplicationEntry(
_In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters,
_Out_ PBL_LOADED_APPLICATION_ENTRY BlpApplicationEntry)
{
PBL_APPLICATION_ENTRY AppEntry;
uint32_t ParamPointer;

ParamPointer = (uint32_t)BootAppParameters;
AppEntry = (PBL_APPLICATION_ENTRY)(ParamPointer + BootAppParameters->AppEntryOffset);

/* Check if the caller sent us their internal BCD options */
if (AppEntry->Flags & BL_APPLICATION_ENTRY_BCD_OPTIONS_INTERNAL)
{
/* These are external to us now, as far as we are concerned */
AppEntry->Flags &= ~BL_APPLICATION_ENTRY_BCD_OPTIONS_INTERNAL;
AppEntry->Flags |= BL_APPLICATION_ENTRY_BCD_OPTIONS_EXTERNAL;
}

/* Save the application entry flags */
BlpApplicationEntry->Flags = AppEntry->Flags;

/* Copy the GUID and point to the options */
BlpApplicationEntry->EFI_GUID = AppEntry->EFI_GUID;
BlpApplicationEntry->BcdData = &AppEntry->BcdData;

return EFI_SUCCESS;
}

EFI_STATUS BlGetBootOptionInteger(
_In_ PBL_BCD_OPTION List,
_In_ ULONG Type,
_Out_ UINT64* Value)
{
NTSTATUS Status;
PBL_BCD_OPTION Option;
BcdElementType ElementType;

/* Make sure this is a BCD_TYPE_INTEGER */
ElementType.PackedValue = Type;
if (ElementType.Format != 0x05)
{
return STATUS_INVALID_PARAMETER;
}

/* Return the data */
Option = MiscGetBootOption(List, Type);
if (Option)
{
*Value = *(UINT64*)((uint32_t)Option + Option->DataOffset);
}

/* Option found */
Status = Option ? STATUS_SUCCESS : STATUS_NOT_FOUND;

return Status;
}

EFI_STATUS BlGetBootOptionBoolean(
_In_ PBL_BCD_OPTION List,
_In_ ULONG Type,
_Out_ BOOLEAN* Value)
{
NTSTATUS Status;
PBL_BCD_OPTION Option;
BcdElementType ElementType;

/* Make sure this is a BCD_TYPE_BOOLEAN */
ElementType.PackedValue = Type;
if (ElementType.Format != 0x06)
{
return STATUS_INVALID_PARAMETER;
}

/* Return the data */
Option = MiscGetBootOption(List, Type);
if (Option)
{
*Value = *(BOOLEAN*)((uint32_t)Option + Option->DataOffset);
}

/* Option found */
Status = Option ? STATUS_SUCCESS : STATUS_NOT_FOUND;

return Status;
}
72 changes: 70 additions & 2 deletions src/EFIApp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "scm.h"
#include "PCIe.h"
#include "PreloaderEnvironment.h"
#include "BlBootConfiguration.h"
#include "application.h"

VOID JumpToAddressAArch64(
EFI_HANDLE ImageHandle,
Expand Down Expand Up @@ -230,7 +232,15 @@ EFI_STATUS efi_main(
EFI_SYSTEM_TABLE *SystemTable
)
{
return EFIApp_Main(ImageHandle, SystemTable, NULL);
}

EFI_STATUS EFIApp_Main(
EFI_HANDLE ImageHandle,
EFI_SYSTEM_TABLE* SystemTable,
PBOOT_APPLICATION_PARAMETER_BLOCK BootAppParameters
)
{
EFI_STATUS Status = EFI_SUCCESS;

UINTN NumHandles = 0;
Expand All @@ -256,12 +266,16 @@ EFI_STATUS efi_main(

QCOM_PCIE_PROTOCOL *PCIExpressProtocol;

PRELOADER_ENVIRONMENT PreloaderEnv;
PRELOADER_ENVIRONMENT_VERSION_2 PreloaderEnv;
UINT32 PreloaderEnvCrc32;
UINTN VarSize;
VOID* PreloaderEnvFinalDest;
EFI_PHYSICAL_ADDRESS PreloaderEnvAddr = PRELOADER_ENV_ADDR;

BL_LOADED_APPLICATION_ENTRY BlpApplicationEntry;
UINT64 BcdIntegerValue = 0;
BOOLEAN BcdBoolValue = FALSE;

#if defined(_GNU_EFI)
InitializeLib(
ImageHandle,
Expand Down Expand Up @@ -528,10 +542,52 @@ EFI_STATUS efi_main(
goto exit;
}

PreloaderEnv.BootMode = BOOT_MODE_PSCI;
PreloaderEnv.EnablePlatformSdCardBoot = 1;
PreloaderEnv.UseQuadCoreConfiguration = 0;

if (BootAppParameters != NULL)
{
BlGetLoadedApplicationEntry(BootAppParameters,
&BlpApplicationEntry);

// Boot mode
Status = BlGetBootOptionInteger(BlpApplicationEntry.BcdData,
0x25133701,
(UINT64*)&BcdIntegerValue);
if (!EFI_ERROR(Status))
{
if (BcdIntegerValue >= 0 && BcdIntegerValue < BOOT_MODE_MAX)
{
PreloaderEnv.BootMode = (UINT32)BcdIntegerValue;
}
}

// Sd card support
Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
0x26133701,
(BOOLEAN*)&BcdBoolValue);
if (!EFI_ERROR(Status))
{
PreloaderEnv.EnablePlatformSdCardBoot = BcdBoolValue;
}

// Force Quad Core for MPPARK EL2
Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
0x26133702,
(BOOLEAN*)&BcdBoolValue);
if (!EFI_ERROR(Status))
{
PreloaderEnv.UseQuadCoreConfiguration = BcdBoolValue;
}
}

PreloaderEnv.Crc32 = 0x0;
PreloaderEnv.Crc32v2 = 0x0;

Status = gBS->CalculateCrc32(
&PreloaderEnv,
sizeof(PreloaderEnv),
sizeof(PRELOADER_ENVIRONMENT_VERSION_1),
&PreloaderEnvCrc32
);
if (EFI_ERROR(Status))
Expand All @@ -541,6 +597,18 @@ EFI_STATUS efi_main(
}
PreloaderEnv.Crc32 = PreloaderEnvCrc32;

Status = gBS->CalculateCrc32(
&PreloaderEnv,
sizeof(PreloaderEnv),
&PreloaderEnvCrc32
);
if (EFI_ERROR(Status))
{
Print(L"CRC32v2 calc failed \n");
goto exit;
}
PreloaderEnv.Crc32v2 = PreloaderEnvCrc32;

// Relocate HOB
Status = gBS->AllocatePages(
AllocateAddress,
Expand Down