]> git.proxmox.com Git - mirror_edk2.git/blob - ArmEbPkg/Sec/Sec.c
8b161ef4c7aa66a1fc427a464939d19727b824c1
[mirror_edk2.git] / ArmEbPkg / Sec / Sec.c
1 /** @file
2 C Entry point for the SEC. First C code after the reset vector.
3
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5
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
10
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.
13
14 **/
15
16 #include <PiPei.h>
17
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>
25
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Guid/LzmaDecompress.h>
28
29 #include <ArmEb/ArmEb.h>
30
31 #include "LzmaDecompress.h"
32
33 VOID
34 EFIAPI
35 _ModuleEntryPoint(
36 VOID
37 );
38
39 CHAR8 *
40 DeCygwinPathIfNeeded (
41 IN CHAR8 *Name
42 );
43
44 RETURN_STATUS
45 EFIAPI
46 SerialPortInitialize (
47 VOID
48 );
49
50
51 VOID
52 UartInit (
53 VOID
54 )
55 {
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 ();
60 }
61
62 VOID
63 TimerInit (
64 VOID
65 )
66 {
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);
69 // Enable
70 MmioOr32 (EB_SP810_CTRL_BASE + SP810_SYS_CTRL_REG, SP810_SYS_CTRL_TIMER2_EN);
71
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);
74
75 // preload the timer count register
76 MmioWrite32 (EB_SP804_TIMER2_BASE + SP804_TIMER_LOAD_REG, 1);
77
78 // enable the timer
79 MmioOr32 (EB_SP804_TIMER2_BASE + SP804_TIMER_CONTROL_REG, SP804_TIMER_CTRL_ENABLE);
80 }
81
82
83 VOID
84 InitCache (
85 IN UINT32 MemoryBase,
86 IN UINT32 MemoryLength
87 );
88
89 EFI_STATUS
90 EFIAPI
91 ExtractGuidedSectionLibConstructor (
92 VOID
93 );
94
95 EFI_STATUS
96 EFIAPI
97 LzmaDecompressLibConstructor (
98 VOID
99 );
100
101
102 VOID
103 CEntryPoint (
104 IN VOID *MemoryBase,
105 IN UINTN MemorySize,
106 IN VOID *StackBase,
107 IN UINTN StackSize
108 )
109 {
110 VOID *HobBase;
111
112 // Build a basic HOB list
113 HobBase = (VOID *)(UINTN)(FixedPcdGet32(PcdEmbeddedFdBaseAddress) + FixedPcdGet32(PcdEmbeddedFdSize));
114 CreateHobList (MemoryBase, MemorySize, HobBase, StackBase);
115
116
117 // Enable program flow prediction, if supported.
118 ArmEnableBranchPrediction ();
119
120 // Initialize CPU cache
121 InitCache ((UINT32)MemoryBase, (UINT32)MemorySize);
122
123 // Add memory allocation hob for relocated FD
124 BuildMemoryAllocationHob (FixedPcdGet32(PcdEmbeddedFdBaseAddress), FixedPcdGet32(PcdEmbeddedFdSize), EfiBootServicesData);
125
126 // Add the FVs to the hob list
127 BuildFvHob (PcdGet32(PcdFlashFvMainBase), PcdGet32(PcdFlashFvMainSize));
128
129 // Start talking
130 UartInit ();
131
132 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, NULL);
133 SaveAndSetDebugTimerInterrupt (TRUE);
134
135 DEBUG ((EFI_D_ERROR, "UART Enabled\n"));
136
137 // Start up a free running timer so that the timer lib will work
138 TimerInit ();
139
140 // SEC phase needs to run library constructors by hand.
141 ExtractGuidedSectionLibConstructor ();
142 LzmaDecompressLibConstructor ();
143
144 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
145 BuildPeCoffLoaderHob ();
146 BuildExtractSectionHob (
147 &gLzmaCustomDecompressGuid,
148 LzmaGuidedSectionGetInfo,
149 LzmaGuidedSectionExtraction
150 );
151
152 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
153 DecompressFirstFv ();
154
155 // Load the DXE Core and transfer control to it
156 LoadDxeCoreFromFv (NULL, 0);
157
158 // DXE Core should always load and never return
159 ASSERT (FALSE);
160 }
161