From c957edf8c74291bf4179de8b393fc9c568bb7a5f Mon Sep 17 00:00:00 2001 From: Bingxing Wang Date: Wed, 27 Jun 2018 12:00:14 -0700 Subject: [PATCH] ARM64: Public release. Should only work for 8992/8994 (because it initializes PCIe too). --- include/EFIApp.h | 13 +++----- include/lk.h | 1 - include/scm.h | 4 +-- src/EFIApp.c | 79 ++++++------------------------------------------ 4 files changed, 15 insertions(+), 82 deletions(-) diff --git a/include/EFIApp.h b/include/EFIApp.h index d494d76..cab88cb 100644 --- a/include/EFIApp.h +++ b/include/EFIApp.h @@ -30,7 +30,10 @@ #define GIC_DIST_CTRL GIC_DIST_REG(0x000) -BOOLEAN CheckElf64Header(Elf64_Ehdr * bl_elf_hdr); +BOOLEAN CheckElf64Header( + Elf64_Ehdr * bl_elf_hdr +); + VOID JumpToAddressAArch64( EFI_HANDLE ImageHandle, EFI_PHYSICAL_ADDRESS Address, @@ -38,12 +41,4 @@ VOID JumpToAddressAArch64( UINT64 PayloadLength ); -VOID JumpToAddressAArch32( - EFI_HANDLE ImageHandle, - EFI_PHYSICAL_ADDRESS AArch32Address, - EFI_PHYSICAL_ADDRESS AArch64Address, - VOID* AArch64PayloadBuffer, - UINT64 AArch64PayloadLength -); - #endif \ No newline at end of file diff --git a/include/lk.h b/include/lk.h index f3ef95d..7df74c8 100644 --- a/include/lk.h +++ b/include/lk.h @@ -4,7 +4,6 @@ #define _LK_DEFINITION_H_ #define PAYLOAD_BINARY_NAME L"UEFI.elf" -#define LK_BINARY_NAME L"emmc_appsboot.mbn" #define PAYLOAD_ENTRY_POINT_ADDR_INVALID 0x00000000 #endif \ No newline at end of file diff --git a/include/scm.h b/include/scm.h index 9b3e173..8fff7e7 100644 --- a/include/scm.h +++ b/include/scm.h @@ -37,7 +37,7 @@ typedef struct { uint64_t el1_x7; uint64_t el1_x8; uint64_t el1_elr; -} el1_system_param; +} EL1_SYSTEM_PARAM; enum { @@ -45,7 +45,7 @@ enum SMC_PARAM_TYPE_BUFFER_READ, SMC_PARAM_TYPE_BUFFER_READWRITE, SMC_PARAM_TYPE_BUFFER_VALIDATION, -} scm_arg_type; +} SCM_ARG_TYPE; #define SIP_SVC_CALLS 0x02000000 #define MAKE_SIP_SCM_CMD(svc_id, cmd_id) ((((svc_id << 8) | (cmd_id)) & 0xFFFF) | SIP_SVC_CALLS) diff --git a/src/EFIApp.c b/src/EFIApp.c index eaacf46..d984904 100644 --- a/src/EFIApp.c +++ b/src/EFIApp.c @@ -18,10 +18,11 @@ VOID JumpToAddressAArch64( UINT32 DesVersion = 0; UINT32 PayloadAddress32 = (UINT32) Address; UINT32 PayloadLength32 = (UINT32) PayloadLength; - EFI_PHYSICAL_ADDRESS DynamicEl1ParamAddress = 0xA0000000; - el1_system_param* DynamicEl1Param; + EL1_SYSTEM_PARAM* DynamicEl1Param; + // This is a bit hacky, but it can save me some time + // on the call convention. Status = gBS->AllocatePages( AllocateAddress, EfiRuntimeServicesData, @@ -92,73 +93,9 @@ VOID JumpToAddressAArch64( while (TRUE) { } } -VOID JumpToAddressAArch32( - EFI_HANDLE ImageHandle, - EFI_PHYSICAL_ADDRESS AArch32Address, - EFI_PHYSICAL_ADDRESS AArch64Address, - VOID* AArch64PayloadBuffer, - UINT64 AArch64PayloadLength +BOOLEAN CheckElf64Header( + Elf64_Ehdr * bl_elf_hdr ) -{ - - EFI_STATUS Status; - UINTN MemMapSize = 0; - EFI_MEMORY_DESCRIPTOR* MemMap = 0; - UINTN MapKey = 0; - UINTN DesSize = 0; - UINT32 DesVersion = 0; - UINT32 PayloadAddress32 = (UINT32) AArch64Address; - UINT32 PayloadLength32 = (UINT32) AArch64PayloadLength; - - /* Entry */ - VOID(*entry)() = (VOID*) AArch32Address; - - Print(L"Exiting boot services... \n"); - - gBS->GetMemoryMap( - &MemMapSize, - MemMap, - &MapKey, - &DesSize, - &DesVersion - ); - - /* Shutdown */ - Status = gBS->ExitBootServices( - ImageHandle, - MapKey - ); - - if (EFI_ERROR(Status)) - { - Print(L"Failed to exit BS\n"); - return; - } - - /* Move LOAD section to actual location */ - SetMem( - (VOID*)PayloadAddress32, - PayloadLength32, - 0xFF); - - CopyMem( - (VOID*)PayloadAddress32, - AArch64PayloadBuffer, - PayloadLength32 - ); - - /* De-initialize */ - ArmDeInitialize(); - - /* Disable GIC */ - writel(0, GIC_DIST_CTRL); - - /* Lets go */ - entry(); - -} - -BOOLEAN CheckElf64Header(Elf64_Ehdr * bl_elf_hdr) { EFI_PHYSICAL_ADDRESS ElfEntryPoint; @@ -222,7 +159,9 @@ BOOLEAN CheckElf64Header(Elf64_Ehdr * bl_elf_hdr) return TRUE; } -static BOOLEAN PCIExpressIsPhyReady(VOID) +static BOOLEAN PCIExpressIsPhyReady( + VOID +) { if (readl(MSM_PCIE_PHY + PCIE_PHY_PCS_STATUS) & BIT(6)) return FALSE; @@ -326,7 +265,7 @@ EFI_STATUS efi_main( continue; } - // Read image and parse ELF32 file + // Read image and parse ELF64 file Print(L"Opened payload image\n"); Status = PayloadFileProtocol->GetInfo(