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>
27 #include <Guid/LzmaDecompress.h>
28 #include <Omap3530/Omap3530.h>
30 #include "LzmaDecompress.h"
39 DeCygwinPathIfNeeded (
58 UINTN Timer
= FixedPcdGet32(PcdBeagleFreeTimer
);
59 UINT32 TimerBaseAddress
= TimerBase(Timer
);
61 // Set source clock for GPT3 & GPT4 to SYS_CLK
62 MmioOr32(CM_CLKSEL_PER
, CM_CLKSEL_PER_CLKSEL_GPT3_SYS
63 | CM_CLKSEL_PER_CLKSEL_GPT4_SYS
);
65 // Set count & reload registers
66 MmioWrite32 (TimerBaseAddress
+ GPTIMER_TCRR
, 0x00000000);
67 MmioWrite32 (TimerBaseAddress
+ GPTIMER_TLDR
, 0x00000000);
70 MmioWrite32 (TimerBaseAddress
+ GPTIMER_TIER
, TIER_TCAR_IT_DISABLE
| TIER_OVF_IT_DISABLE
| TIER_MAT_IT_DISABLE
);
73 MmioWrite32 (TimerBaseAddress
+ GPTIMER_TCLR
, TCLR_AR_AUTORELOAD
| TCLR_ST_ON
);
75 //Disable OMAP Watchdog timer (WDT2)
76 MmioWrite32 (WDTIMER2_BASE
+ WSPR
, 0xAAAA);
77 DEBUG ((EFI_D_ERROR
, "Magic delay to disable watchdog timers properly.\n"));
78 MmioWrite32 (WDTIMER2_BASE
+ WSPR
, 0x5555);
86 UINTN Uart
= FixedPcdGet32(PcdBeagleConsoleUart
);
87 UINT32 UartBaseAddress
= UartBase(Uart
);
89 // Set MODE_SELECT=DISABLE before trying to initialize or modify DLL, DLH registers.
90 MmioWrite32 (UartBaseAddress
+ UART_MDR1_REG
, UART_MDR1_MODE_SELECT_DISABLE
);
92 // Put device in configuration mode.
93 MmioWrite32 (UartBaseAddress
+ UART_LCR_REG
, UART_LCR_DIV_EN_ENABLE
);
95 // Programmable divisor N = 48Mhz/16/115200 = 26
96 MmioWrite32 (UartBaseAddress
+ UART_DLL_REG
, 3000000/FixedPcdGet64 (PcdUartDefaultBaudRate
)); // low divisor
97 MmioWrite32 (UartBaseAddress
+ UART_DLH_REG
, 0); // high divisor
99 // Enter into UART operational mode.
100 MmioWrite32 (UartBaseAddress
+ UART_LCR_REG
, UART_LCR_DIV_EN_DISABLE
| UART_LCR_CHAR_LENGTH_8
);
102 // Force DTR and RTS output to active
103 MmioWrite32 (UartBaseAddress
+ UART_MCR_REG
, UART_MCR_RTS_FORCE_ACTIVE
| UART_MCR_DTR_FORCE_ACTIVE
);
105 // Clear & enable fifos
106 MmioWrite32 (UartBaseAddress
+ UART_FCR_REG
, UART_FCR_TX_FIFO_CLEAR
| UART_FCR_RX_FIFO_CLEAR
| UART_FCR_FIFO_ENABLE
);
108 // Restore MODE_SELECT
109 MmioWrite32 (UartBaseAddress
+ UART_MDR1_REG
, UART_MDR1_MODE_SELECT_UART_16X
);
114 IN UINT32 MemoryBase
,
115 IN UINT32 MemoryLength
120 ExtractGuidedSectionLibConstructor (
126 LzmaDecompressLibConstructor (
131 If the build is done on cygwin the paths are cygpaths.
132 /cygdrive/c/tmp.txt vs c:\tmp.txt so we need to convert
133 them to work with RVD commands
135 This is just code to help print out RVD symbol load command.
136 If you build with cygwin paths aren't compatible with RVD.
138 @param Name Path to convert if needed
142 SecDeCygwinPathIfNeeded (
150 Ptr
= AsciiStrStr (Name
, "/cygdrive/");
155 Len
= AsciiStrLen (Ptr
);
157 // convert "/cygdrive" to spaces
158 for (Index
= 0; Index
< 9; Index
++) {
166 // switch path seperators
167 for (Index
= 11; Index
< Len
; Index
++) {
168 if (Ptr
[Index
] == '/') {
187 // Build a basic HOB list
188 HobBase
= (VOID
*)(UINTN
)(FixedPcdGet32(PcdEmbeddedFdBaseAddress
) + FixedPcdGet32(PcdEmbeddedFdSize
));
189 CreateHobList (MemoryBase
, MemorySize
, HobBase
, StackBase
);
194 // Set up system clocking
198 // Enable program flow prediction, if supported.
199 ArmEnableBranchPrediction ();
201 // Initialize CPU cache
202 InitCache ((UINT32
)MemoryBase
, (UINT32
)MemorySize
);
204 // Add memory allocation hob for relocated FD
205 BuildMemoryAllocationHob (FixedPcdGet32(PcdEmbeddedFdBaseAddress
), FixedPcdGet32(PcdEmbeddedFdSize
), EfiBootServicesData
);
207 // Add the FVs to the hob list
208 BuildFvHob (PcdGet32(PcdFlashFvMainBase
), PcdGet32(PcdFlashFvMainSize
));
212 DEBUG ((EFI_D_ERROR
, "UART Enabled\n"));
216 // On a debug build print out information about the SEC. This is really info about
217 // the PE/COFF file we are currently running from. Useful for loading symbols in a
218 // debugger. Remember our image is really part of the FV.
220 RETURN_STATUS Status
;
221 EFI_PEI_FV_HANDLE VolumeHandle
;
222 EFI_PEI_FILE_HANDLE FileHandle
;
226 FfsAnyFvFindFirstFile (EFI_FV_FILETYPE_SECURITY_CORE
, &VolumeHandle
, &FileHandle
);
227 Status
= FfsFindSectionData (EFI_SECTION_TE
, FileHandle
, &PeCoffImage
);
228 if (EFI_ERROR (Status
)) {
229 // Usually is a TE (PI striped down PE/COFF), but could be a full PE/COFF
230 Status
= FfsFindSectionData (EFI_SECTION_PE32
, FileHandle
, &PeCoffImage
);
232 if (!EFI_ERROR (Status
)) {
233 Offset
= PeCoffGetSizeOfHeaders (PeCoffImage
);
234 FilePath
= PeCoffLoaderGetPdbPointer (PeCoffImage
);
235 if (FilePath
!= NULL
) {
238 // In general you should never have to use #ifdef __CC_ARM in the code. It
239 // is hidden in the away in the MdePkg. But here we would like to print differnt things
240 // for different toolchains.
243 // Print out the command for the RVD debugger to load symbols for this image
244 DEBUG ((EFI_D_ERROR
, "load /a /ni /np %a &0x%08x\n", SecDeCygwinPathIfNeeded (FilePath
), (CHAR8
*)PeCoffImage
+ Offset
));
246 // This may not work correctly if you generate PE/COFF directlyas then the Offset would not be required
247 DEBUG ((EFI_D_ERROR
, "add-symbol-file %a 0x%08x\n", FilePath
, PeCoffImage
+ Offset
));
249 DEBUG ((EFI_D_ERROR
, "SEC starts at 0x%08x with an entry point at 0x%08x %a\n", PeCoffImage
, _ModuleEntryPoint
, FilePath
));
259 // Start up a free running time so that the timer lib will work
262 // SEC phase needs to run library constructors by hand.
263 ExtractGuidedSectionLibConstructor ();
264 LzmaDecompressLibConstructor ();
266 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
267 BuildPeCoffLoaderHob ();
268 BuildExtractSectionHob (
269 &gLzmaCustomDecompressGuid
,
270 LzmaGuidedSectionGetInfo
,
271 LzmaGuidedSectionExtraction
274 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
275 DecompressFirstFv ();
277 // Load the DXE Core and transfer control to it
278 LoadDxeCoreFromFv (NULL
, 0);
280 // DXE Core should always load and never return