2 C Entry point for the SEC. First C code after the reset vector.
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/DebugLib.h>
19 #include <Library/PrePiLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/IoLib.h>
22 #include <Library/ArmLib.h>
23 #include <Library/PeCoffGetEntryPointLib.h>
24 #include <Library/DebugAgentLib.h>
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Guid/LzmaDecompress.h>
29 #include <ArmEb/ArmEb.h>
31 #include "LzmaDecompress.h"
40 DeCygwinPathIfNeeded (
46 SerialPortInitialize (
56 // SEC phase needs to run library constructors by hand.
57 // This assumes we are linked agains the SerialLib
58 // In non SEC modules the init call is in autogenerated code.
59 SerialPortInitialize ();
67 // configure SP810 to use 1MHz clock and disable
68 MmioAndThenOr32 (EB_SP810_CTRL_BASE
+ SP810_SYS_CTRL_REG
, ~SP810_SYS_CTRL_TIMER2_EN
, SP810_SYS_CTRL_TIMER2_TIMCLK
);
70 MmioOr32 (EB_SP810_CTRL_BASE
+ SP810_SYS_CTRL_REG
, SP810_SYS_CTRL_TIMER2_EN
);
72 // configure timer 2 for one shot operation, 32 bits, no prescaler, and interrupt disabled
73 MmioOr32 (EB_SP804_TIMER2_BASE
+ SP804_TIMER_CONTROL_REG
, SP804_TIMER_CTRL_ONESHOT
| SP804_TIMER_CTRL_32BIT
| SP804_PRESCALE_DIV_1
);
75 // preload the timer count register
76 MmioWrite32 (EB_SP804_TIMER2_BASE
+ SP804_TIMER_LOAD_REG
, 1);
79 MmioOr32 (EB_SP804_TIMER2_BASE
+ SP804_TIMER_CONTROL_REG
, SP804_TIMER_CTRL_ENABLE
);
86 IN UINT32 MemoryLength
91 ExtractGuidedSectionLibConstructor (
97 LzmaDecompressLibConstructor (
112 // HOB list is at bottom of stack area
113 // Stack grows from top-to-bottom towards HOB list
114 HobBase
= (VOID
*)StackBase
;
115 CreateHobList (MemoryBase
, MemorySize
, HobBase
, StackBase
);
117 // Turn off remapping NOR to 0. We can will now see DRAM in low memory
118 MmioOr32 (0x10001000 ,BIT8
); //EB_SP810_CTRL_BASE
120 // Enable program flow prediction, if supported.
121 ArmEnableBranchPrediction ();
123 // Initialize CPU cache
124 InitCache ((UINT32
)MemoryBase
, (UINT32
)MemorySize
);
126 // Add memory allocation hob for relocated FD
127 BuildMemoryAllocationHob (FixedPcdGet32(PcdEmbeddedFdBaseAddress
), FixedPcdGet32(PcdEmbeddedFdSize
), EfiBootServicesData
);
129 // Add the FVs to the hob list
130 BuildFvHob (PcdGet32(PcdFlashFvMainBase
), PcdGet32(PcdFlashFvMainSize
));
135 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, NULL
);
136 SaveAndSetDebugTimerInterrupt (TRUE
);
138 DEBUG ((EFI_D_ERROR
, "UART Enabled\n"));
140 // Start up a free running timer so that the timer lib will work
143 // SEC phase needs to run library constructors by hand.
144 ExtractGuidedSectionLibConstructor ();
145 LzmaDecompressLibConstructor ();
147 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
148 BuildPeCoffLoaderHob ();
149 BuildExtractSectionHob (
150 &gLzmaCustomDecompressGuid
,
151 LzmaGuidedSectionGetInfo
,
152 LzmaGuidedSectionExtraction
155 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
156 DecompressFirstFv ();
158 // Load the DXE Core and transfer control to it
159 LoadDxeCoreFromFv (NULL
, 0);
161 // DXE Core should always load and never return