3 * Copyright (c) 2011-2017, ARM Limited. All rights reserved.
4 * Copyright (c) 2017, Linaro, Ltd. All rights reserved.
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/DebugAgentLib.h>
19 #include <Library/PrePiLib.h>
20 #include <Library/PrintLib.h>
21 #include <Library/PeCoffGetEntryPointLib.h>
22 #include <Library/PrePiHobListPointerLib.h>
23 #include <Library/TimerLib.h>
24 #include <Library/PerformanceLib.h>
26 #include <Ppi/GuidedSectionExtraction.h>
27 #include <Ppi/ArmMpCoreInfo.h>
28 #include <Ppi/SecPerformance.h>
29 #include <Guid/LzmaDecompress.h>
32 #include "LzmaDecompress.h"
34 #define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \
35 ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) < FixedPcdGet64 (PcdSystemMemoryBase)))
37 UINT64 mSystemMemoryEnd
= FixedPcdGet64(PcdSystemMemoryBase
) +
38 FixedPcdGet64(PcdSystemMemorySize
) - 1;
48 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
52 ArmPlatformGetPlatformPpiList (&PpiListSize
, &PpiList
);
53 PpiListCount
= PpiListSize
/ sizeof(EFI_PEI_PPI_DESCRIPTOR
);
54 for (Index
= 0; Index
< PpiListCount
; Index
++, PpiList
++) {
55 if (CompareGuid (PpiList
->Guid
, PpiGuid
) == TRUE
) {
66 IN UINTN UefiMemoryBase
,
68 IN UINT64 StartTimeStamp
71 EFI_HOB_HANDOFF_INFO_TABLE
* HobList
;
76 FIRMWARE_SEC_PERFORMANCE Performance
;
78 // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
80 ((FixedPcdGet64 (PcdFdBaseAddress
) >= FixedPcdGet64 (PcdSystemMemoryBase
)) &&
81 ((UINT64
)(FixedPcdGet64 (PcdFdBaseAddress
) + FixedPcdGet32 (PcdFdSize
)) <= (UINT64
)mSystemMemoryEnd
)));
83 // Initialize the architecture specific bits
86 // Initialize the Serial Port
87 SerialPortInitialize ();
88 CharCount
= AsciiSPrint (Buffer
,sizeof (Buffer
),"UEFI firmware (version %s built at %a on %a)\n\r",
89 (CHAR16
*)PcdGetPtr(PcdFirmwareVersionString
), __TIME__
, __DATE__
);
90 SerialPortWrite ((UINT8
*) Buffer
, CharCount
);
92 // Initialize the Debug Agent for Source Level Debugging
93 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
94 SaveAndSetDebugTimerInterrupt (TRUE
);
96 // Declare the PI/UEFI memory region
97 HobList
= HobConstructor (
98 (VOID
*)UefiMemoryBase
,
99 FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
),
100 (VOID
*)UefiMemoryBase
,
101 (VOID
*)StacksBase
// The top of the UEFI Memory is reserved for the stacks
103 PrePeiSetHobList (HobList
);
105 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
106 Status
= MemoryPeim (UefiMemoryBase
, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
107 ASSERT_EFI_ERROR (Status
);
109 StacksSize
= PcdGet32 (PcdCPUCorePrimaryStackSize
);
110 BuildStackHob (StacksBase
, StacksSize
);
112 //TODO: Call CpuPei as a library
113 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize
), PcdGet8 (PcdPrePiCpuIoSize
));
115 // Store timer value logged at the beginning of firmware image execution
116 Performance
.ResetEnd
= GetTimeInNanoSecond (StartTimeStamp
);
118 // Build SEC Performance Data Hob
119 BuildGuidDataHob (&gEfiFirmwarePerformanceGuid
, &Performance
, sizeof (Performance
));
122 SetBootMode (ArmPlatformGetBootMode ());
124 // Initialize Platform HOBs (CpuHob and FvHob)
125 Status
= PlatformPeim ();
126 ASSERT_EFI_ERROR (Status
);
128 // Now, the HOB List has been initialized, we can register performance information
129 PERF_START (NULL
, "PEI", NULL
, StartTimeStamp
);
131 // SEC phase needs to run library constructors by hand.
132 ProcessLibraryConstructorList ();
134 // Build HOBs to pass up our version of stuff the DXE Core needs to save space
135 BuildPeCoffLoaderHob ();
136 BuildExtractSectionHob (
137 &gLzmaCustomDecompressGuid
,
138 LzmaGuidedSectionGetInfo
,
139 LzmaGuidedSectionExtraction
142 // Assume the FV that contains the SEC (our code) also contains a compressed FV.
143 Status
= DecompressFirstFv ();
144 ASSERT_EFI_ERROR (Status
);
146 // Load the DXE Core and transfer control to it
147 Status
= LoadDxeCoreFromFv (NULL
, 0);
148 ASSERT_EFI_ERROR (Status
);
154 IN UINTN UefiMemoryBase
,
158 UINT64 StartTimeStamp
;
160 // Initialize the platform specific controllers
161 ArmPlatformInitialize (MpId
);
163 if (PerformanceMeasurementEnabled ()) {
164 // Initialize the Timer Library to setup the Timer HW controller
166 // We cannot call yet the PerformanceLib because the HOB List has not been initialized
167 StartTimeStamp
= GetPerformanceCounter ();
172 // Data Cache enabled on Primary core when MMU is enabled.
173 ArmDisableDataCache ();
174 // Invalidate Data cache
175 ArmInvalidateDataCache ();
176 // Invalidate instruction cache
177 ArmInvalidateInstructionCache ();
178 // Enable Instruction Caches on all cores.
179 ArmEnableInstructionCache ();
181 PrimaryMain (UefiMemoryBase
, StacksBase
, StartTimeStamp
);
183 // DXE Core should always load and never return