2 C Entry point for the SEC. First C code after the reset vector.
4 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
6 All rights reserved. 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/OmapLib.h>
23 #include <Library/ArmLib.h>
24 #include <Library/PeCoffGetEntryPointLib.h>
26 #include <Ppi/GuidedSectionExtraction.h>
28 #include <Omap3530/Omap3530.h>
37 DeCygwinPathIfNeeded (
56 UINTN Timer
= FixedPcdGet32(PcdBeagleFreeTimer
);
57 UINT32 TimerBaseAddress
= TimerBase(Timer
);
59 // Set source clock for GPT3 & GPT4 to SYS_CLK
60 MmioOr32(CM_CLKSEL_PER
, CM_CLKSEL_PER_CLKSEL_GPT3_SYS
61 | CM_CLKSEL_PER_CLKSEL_GPT4_SYS
);
63 // Set count & reload registers
64 MmioWrite32(TimerBaseAddress
+ GPTIMER_TCRR
, 0x00000000);
65 MmioWrite32(TimerBaseAddress
+ GPTIMER_TLDR
, 0x00000000);
68 MmioWrite32(TimerBaseAddress
+ GPTIMER_TIER
, TIER_TCAR_IT_DISABLE
| TIER_OVF_IT_DISABLE
| TIER_MAT_IT_DISABLE
);
71 MmioWrite32(TimerBaseAddress
+ GPTIMER_TCLR
, TCLR_AR_AUTORELOAD
| TCLR_ST_ON
);
73 //Disable OMAP Watchdog timer (WDT2)
74 MmioWrite32(WDTIMER2_BASE
+ WSPR
, 0xAAAA);
75 DEBUG ((EFI_D_ERROR
, "Magic delay to disable watchdog timers properly.\n"));
76 MmioWrite32(WDTIMER2_BASE
+ WSPR
, 0x5555);
84 UINTN Uart
= FixedPcdGet32(PcdBeagleConsoleUart
);
85 UINT32 UartBaseAddress
= UartBase(Uart
);
87 // Set MODE_SELECT=DISABLE before trying to initialize or modify DLL, DLH registers.
88 MmioWrite32(UartBaseAddress
+ UART_MDR1_REG
, UART_MDR1_MODE_SELECT_DISABLE
);
90 // Put device in configuration mode.
91 MmioWrite32(UartBaseAddress
+ UART_LCR_REG
, UART_LCR_DIV_EN_ENABLE
);
93 // Programmable divisor N = 48Mhz/16/115200 = 26
94 MmioWrite32(UartBaseAddress
+ UART_DLL_REG
, 26); // low divisor
95 MmioWrite32(UartBaseAddress
+ UART_DLH_REG
, 0); // high divisor
97 // Enter into UART operational mode.
98 MmioWrite32(UartBaseAddress
+ UART_LCR_REG
, UART_LCR_DIV_EN_DISABLE
| UART_LCR_CHAR_LENGTH_8
);
100 // Force DTR and RTS output to active
101 MmioWrite32(UartBaseAddress
+ UART_MCR_REG
, UART_MCR_RTS_FORCE_ACTIVE
| UART_MCR_DTR_FORCE_ACTIVE
);
103 // Clear & enable fifos
104 MmioWrite32(UartBaseAddress
+ UART_FCR_REG
, UART_FCR_TX_FIFO_CLEAR
| UART_FCR_RX_FIFO_CLEAR
| UART_FCR_FIFO_ENABLE
);
106 // Restore MODE_SELECT
107 MmioWrite32(UartBaseAddress
+ UART_MDR1_REG
, UART_MDR1_MODE_SELECT_UART_16X
);
112 IN UINT32 MemoryBase
,
113 IN UINT32 MemoryLength
118 ExtractGuidedSectionLibConstructor (
124 LzmaDecompressLibConstructor (
129 If the build is done on cygwin the paths are cygpaths.
130 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
131 them to work with RVD commands
133 This is just code to help print out RVD symbol load command.
134 If you build with cygwin paths aren't compatible with RVD.
136 @param Name Path to convert if needed
140 SecDeCygwinPathIfNeeded (
148 Ptr
= AsciiStrStr (Name
, "/cygdrive/");
153 Len
= AsciiStrLen (Ptr
);
155 // convert "/cygdrive" to spaces
156 for (Index
= 0; Index
< 9; Index
++) {
164 // switch path seperators
165 for (Index
= 11; Index
< Len
; Index
++) {
166 if (Ptr
[Index
] == '/') {
188 // Set up system clocking
191 // Build a basic HOB list
192 HobBase
= (VOID
*)(UINTN
)(FixedPcdGet32(PcdEmbeddedFdBaseAddress
) + FixedPcdGet32(PcdEmbeddedFdSize
));
193 CreateHobList(MemoryBase
, MemorySize
, HobBase
, StackBase
);
195 // Enable program flow prediction, if supported.
196 ArmEnableBranchPrediction();
198 // Initialize CPU cache
199 InitCache((UINT32
)MemoryBase
, (UINT32
)MemorySize
);
201 // Add memory allocation hob for relocated FD
202 BuildMemoryAllocationHob(FixedPcdGet32(PcdEmbeddedFdBaseAddress
), FixedPcdGet32(PcdEmbeddedFdSize
), EfiBootServicesData
);
204 // Add the FVs to the hob list
205 BuildFvHob(PcdGet32(PcdFlashFvMainBase
), PcdGet32(PcdFlashFvMainSize
));
209 DEBUG((EFI_D_ERROR
, "UART Enabled\n"));
213 // On a debug build print out information about the SEC. This is really info about
214 // the PE/COFF file we are currently running from. Useful for loading symbols in a
215 // debugger. Remember our image is really part of the FV.
217 RETURN_STATUS Status
;
218 EFI_PEI_FV_HANDLE VolumeHandle
;
219 EFI_PEI_FILE_HANDLE FileHandle
;
224 FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_SECURITY_CORE
, &VolumeHandle
, &FileHandle
);
225 Status
= FfsFindSectionData (EFI_SECTION_TE
, FileHandle
, &PeCoffImage
);
226 if (EFI_ERROR (Status
)) {
227 // Usually is a TE (PI striped down PE/COFF), but could be a full PE/COFF
228 Status
= FfsFindSectionData (EFI_SECTION_PE32
, FileHandle
, &PeCoffImage
);
230 if (!EFI_ERROR (Status
)) {
231 Offset
= PeCoffGetSizeOfHeaders (PeCoffImage
);
232 FilePath
= PeCoffLoaderGetPdbPointer (PeCoffImage
);
233 if (FilePath
!= NULL
) {
236 // In general you should never have to use #ifdef __CC_ARM in the code. It
237 // is hidden in the away in the MdePkg. But here we would like to print differnt things
238 // for different toolchains.
241 // Print out the command for the RVD debugger to load symbols for this image
242 DEBUG ((EFI_D_ERROR
, "load /a /ni /np %a &0x%08x\n", SecDeCygwinPathIfNeeded (FilePath
), (CHAR8
*)PeCoffImage
+ Offset
));
244 // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
245 DEBUG ((EFI_D_ERROR
, "add-symbol-file %a 0x%08x\n", FilePath
, PeCoffImage
+ Offset
));
247 DEBUG ((EFI_D_ERROR
, "SEC starts at 0x%08x with an entry point at 0x%08x %a\n", PeCoffImage
, _ModuleEntryPoint
, FilePath
));
256 // Start up a free running time so that the timer lib will work
259 // SEC phase needs to run library constructors by hand.
260 ExtractGuidedSectionLibConstructor();
261 LzmaDecompressLibConstructor();
263 // Load the DXE Core and transfer control to it
264 LoadDxeCoreFromFv(NULL
, 0);
266 // DXE Core should always load and never return