2009-12-06 02:57:05 +01:00
|
|
|
/** @file
|
|
|
|
C Entry point for the SEC. First C code after the reset vector.
|
|
|
|
|
2010-04-29 14:24:22 +02:00
|
|
|
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
2009-12-06 02:57:05 +01:00
|
|
|
|
2010-04-29 14:24:22 +02:00
|
|
|
This program and the accompanying materials
|
2009-12-06 02:57:05 +01:00
|
|
|
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.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <PiPei.h>
|
|
|
|
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/PrePiLib.h>
|
|
|
|
#include <Library/PcdLib.h>
|
|
|
|
#include <Library/IoLib.h>
|
|
|
|
#include <Library/OmapLib.h>
|
|
|
|
#include <Library/ArmLib.h>
|
2010-01-15 00:39:29 +01:00
|
|
|
#include <Library/PeCoffGetEntryPointLib.h>
|
2010-04-14 23:52:26 +02:00
|
|
|
#include <Library/DebugAgentLib.h>
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
#include <Ppi/GuidedSectionExtraction.h>
|
2010-01-31 02:39:20 +01:00
|
|
|
#include <Guid/LzmaDecompress.h>
|
2009-12-06 02:57:05 +01:00
|
|
|
#include <Omap3530/Omap3530.h>
|
|
|
|
|
2010-01-31 02:39:20 +01:00
|
|
|
#include "LzmaDecompress.h"
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
VOID
|
|
|
|
PadConfiguration (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
ClockInit (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
2010-04-14 23:52:26 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
VOID
|
|
|
|
TimerInit (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2010-04-13 19:39:52 +02:00
|
|
|
UINTN Timer = FixedPcdGet32(PcdOmap35xxFreeTimer);
|
2009-12-06 02:57:05 +01:00
|
|
|
UINT32 TimerBaseAddress = TimerBase(Timer);
|
|
|
|
|
|
|
|
// Set source clock for GPT3 & GPT4 to SYS_CLK
|
2010-04-14 23:52:26 +02:00
|
|
|
MmioOr32 (CM_CLKSEL_PER, CM_CLKSEL_PER_CLKSEL_GPT3_SYS | CM_CLKSEL_PER_CLKSEL_GPT4_SYS);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Set count & reload registers
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (TimerBaseAddress + GPTIMER_TCRR, 0x00000000);
|
|
|
|
MmioWrite32 (TimerBaseAddress + GPTIMER_TLDR, 0x00000000);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Disable interrupts
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (TimerBaseAddress + GPTIMER_TIER, TIER_TCAR_IT_DISABLE | TIER_OVF_IT_DISABLE | TIER_MAT_IT_DISABLE);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Start Timer
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (TimerBaseAddress + GPTIMER_TCLR, TCLR_AR_AUTORELOAD | TCLR_ST_ON);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
//Disable OMAP Watchdog timer (WDT2)
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (WDTIMER2_BASE + WSPR, 0xAAAA);
|
2009-12-06 02:57:05 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "Magic delay to disable watchdog timers properly.\n"));
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (WDTIMER2_BASE + WSPR, 0x5555);
|
2009-12-06 02:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
UartInit (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2010-04-13 19:39:52 +02:00
|
|
|
UINTN Uart = FixedPcdGet32(PcdOmap35xxConsoleUart);
|
2009-12-06 02:57:05 +01:00
|
|
|
UINT32 UartBaseAddress = UartBase(Uart);
|
|
|
|
|
|
|
|
// Set MODE_SELECT=DISABLE before trying to initialize or modify DLL, DLH registers.
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (UartBaseAddress + UART_MDR1_REG, UART_MDR1_MODE_SELECT_DISABLE);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Put device in configuration mode.
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (UartBaseAddress + UART_LCR_REG, UART_LCR_DIV_EN_ENABLE);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Programmable divisor N = 48Mhz/16/115200 = 26
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (UartBaseAddress + UART_DLL_REG, 3000000/FixedPcdGet64 (PcdUartDefaultBaudRate)); // low divisor
|
|
|
|
MmioWrite32 (UartBaseAddress + UART_DLH_REG, 0); // high divisor
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Enter into UART operational mode.
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (UartBaseAddress + UART_LCR_REG, UART_LCR_DIV_EN_DISABLE | UART_LCR_CHAR_LENGTH_8);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Force DTR and RTS output to active
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (UartBaseAddress + UART_MCR_REG, UART_MCR_RTS_FORCE_ACTIVE | UART_MCR_DTR_FORCE_ACTIVE);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Clear & enable fifos
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (UartBaseAddress + UART_FCR_REG, UART_FCR_TX_FIFO_CLEAR | UART_FCR_RX_FIFO_CLEAR | UART_FCR_FIFO_ENABLE);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Restore MODE_SELECT
|
2010-02-15 21:40:51 +01:00
|
|
|
MmioWrite32 (UartBaseAddress + UART_MDR1_REG, UART_MDR1_MODE_SELECT_UART_16X);
|
2009-12-06 02:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
InitCache (
|
|
|
|
IN UINT32 MemoryBase,
|
|
|
|
IN UINT32 MemoryLength
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
ExtractGuidedSectionLibConstructor (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
LzmaDecompressLibConstructor (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
2010-01-15 00:39:29 +01:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
VOID
|
|
|
|
CEntryPoint (
|
|
|
|
IN VOID *MemoryBase,
|
|
|
|
IN UINTN MemorySize,
|
|
|
|
IN VOID *StackBase,
|
|
|
|
IN UINTN StackSize
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VOID *HobBase;
|
|
|
|
|
2010-02-24 18:22:03 +01:00
|
|
|
// Build a basic HOB list
|
|
|
|
HobBase = (VOID *)(UINTN)(FixedPcdGet32(PcdEmbeddedFdBaseAddress) + FixedPcdGet32(PcdEmbeddedFdSize));
|
|
|
|
CreateHobList (MemoryBase, MemorySize, HobBase, StackBase);
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
//Set up Pin muxing.
|
2010-02-15 21:40:51 +01:00
|
|
|
PadConfiguration ();
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Set up system clocking
|
2010-02-15 21:40:51 +01:00
|
|
|
ClockInit ();
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
// Enable program flow prediction, if supported.
|
2010-02-15 21:40:51 +01:00
|
|
|
ArmEnableBranchPrediction ();
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Initialize CPU cache
|
2010-02-15 21:40:51 +01:00
|
|
|
InitCache ((UINT32)MemoryBase, (UINT32)MemorySize);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Add memory allocation hob for relocated FD
|
2010-02-15 21:40:51 +01:00
|
|
|
BuildMemoryAllocationHob (FixedPcdGet32(PcdEmbeddedFdBaseAddress), FixedPcdGet32(PcdEmbeddedFdSize), EfiBootServicesData);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Add the FVs to the hob list
|
2010-02-15 21:40:51 +01:00
|
|
|
BuildFvHob (PcdGet32(PcdFlashFvMainBase), PcdGet32(PcdFlashFvMainSize));
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Start talking
|
2010-02-15 21:40:51 +01:00
|
|
|
UartInit ();
|
2010-04-14 23:52:26 +02:00
|
|
|
|
|
|
|
InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL);
|
|
|
|
SaveAndSetDebugTimerInterrupt (TRUE);
|
2010-01-15 00:39:29 +01:00
|
|
|
|
2010-04-14 23:52:26 +02:00
|
|
|
DEBUG ((EFI_D_ERROR, "UART Enabled\n"));
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// Start up a free running time so that the timer lib will work
|
2010-02-15 21:40:51 +01:00
|
|
|
TimerInit ();
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// SEC phase needs to run library constructors by hand.
|
2010-02-15 21:40:51 +01:00
|
|
|
ExtractGuidedSectionLibConstructor ();
|
|
|
|
LzmaDecompressLibConstructor ();
|
2009-12-06 02:57:05 +01:00
|
|
|
|
2010-01-31 02:39:20 +01:00
|
|
|
// Build HOBs to pass up our version of stuff the DXE Core needs to save space
|
|
|
|
BuildPeCoffLoaderHob ();
|
|
|
|
BuildExtractSectionHob (
|
|
|
|
&gLzmaCustomDecompressGuid,
|
|
|
|
LzmaGuidedSectionGetInfo,
|
|
|
|
LzmaGuidedSectionExtraction
|
|
|
|
);
|
|
|
|
|
2010-02-24 18:22:03 +01:00
|
|
|
// Assume the FV that contains the SEC (our code) also contains a compressed FV.
|
2010-01-29 00:45:38 +01:00
|
|
|
DecompressFirstFv ();
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
// Load the DXE Core and transfer control to it
|
2010-02-15 21:40:51 +01:00
|
|
|
LoadDxeCoreFromFv (NULL, 0);
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// DXE Core should always load and never return
|
2010-02-15 21:40:51 +01:00
|
|
|
ASSERT (FALSE);
|
2009-12-06 02:57:05 +01:00
|
|
|
}
|
|
|
|
|