Compare commits
261 Commits
edk2-stabl
...
system76-c
Author | SHA1 | Date | |
---|---|---|---|
f40dc199c2 | |||
3f54e8f57a | |||
55849a4a46 | |||
74f2015276 | |||
6dff36c9b2 | |||
814c0fa862 | |||
a05aa4aff0 | |||
30c84e8277 | |||
2ba9869baa | |||
826b9d30cf | |||
b0e7e3919f | |||
976842130a | |||
52d5d1b2c5 | |||
7050fc3a26 | |||
0eca9e3c1a | |||
19304f2144 | |||
b062ed0c86 | |||
d9cf95c6a2 | |||
75a5161506 | |||
d193b18023 | |||
061df3962f | |||
f6e7c15556 | |||
95fb70f34d | |||
900debdeec | |||
33006e4f4e | |||
b8fbf69c16 | |||
ba13872223 | |||
eb1e7a0284 | |||
eba6c7c6ce | |||
a5f556c37b | |||
e9023ae655 | |||
cdd43b2533 | |||
d1a6917813 | |||
81e096bda1 | |||
42f99de779 | |||
a03327088a | |||
4ba839c5c8 | |||
6bd9d60b41 | |||
964f80253a | |||
47794944e6 | |||
8f008298cc | |||
783f22ecc3 | |||
81a93fb3a9 | |||
30dc65997f | |||
93f8c4a6d5 | |||
51be9d0425 | |||
31a4e13c19 | |||
9d32ca34d2 | |||
0f9b597012 | |||
19e12d66fe | |||
9332332724 | |||
239e19e391 | |||
c8a3cdb675 | |||
40147bbf14 | |||
cf2bde63a1 | |||
f6f2ff4904 | |||
a26aad44d1 | |||
3596140a69 | |||
9b7ce3b9a1 | |||
147c02d66e | |||
768fe7365f | |||
0f6978e314 | |||
0a8abc3c4d | |||
54b26ae48f | |||
9d72e4b922 | |||
7f094cdf45 | |||
b0f8ea3c9c | |||
731869826b | |||
a49a99ef5e | |||
d06545cd3d | |||
575764deeb | |||
ed1cf61e3e | |||
091f5d689f | |||
d944c24078 | |||
bdd22050f6 | |||
0286bfae44 | |||
735fae0452 | |||
8de2a8523d | |||
e4fc0fbacb | |||
fceee0d621 | |||
d67d692ee2 | |||
927fc0e4b5 | |||
04515ff368 | |||
439e7d2556 | |||
0554ac9dd0 | |||
0a679652e8 | |||
559a07d84e | |||
9bba10eb43 | |||
a18f784cfd | |||
7c4207e955 | |||
5a9b3eb8e5 | |||
6f42f9a54b | |||
ba808d11f6 | |||
d3b05936d9 | |||
5afabd5ec3 | |||
e3fa3d83e7 | |||
87b920fe22 | |||
4a1500db2b | |||
6bd42402f7 | |||
1c36f028fa | |||
76be882cdc | |||
36b0754712 | |||
67b8f806d2 | |||
5c8bc8be9e | |||
d05d5f6c85 | |||
3bdc111178 | |||
5f0b035f10 | |||
370544d116 | |||
458539fb75 | |||
b7652b7667 | |||
f2bc359ced | |||
111e6c920d | |||
aa8c6e2ad3 | |||
b62fe5708b | |||
073a76e662 | |||
7c3a1efd15 | |||
b4c012d873 | |||
643556fc48 | |||
4c6e6f9f75 | |||
778c764050 | |||
736c436e53 | |||
c8c3c53669 | |||
0a538ddab4 | |||
48e890457b | |||
9bf86b12ce | |||
5695877ec8 | |||
a9ff32909b | |||
9a67ba261f | |||
36deafb838 | |||
b048a2204d | |||
decaac5d0d | |||
580f4539df | |||
0d68ce514b | |||
e07092edca | |||
ded3c57623 | |||
de3c440e8a | |||
765fb87c2b | |||
f0574a194c | |||
f4c8c1bbf1 | |||
56fbaecb15 | |||
ee27f6eef3 | |||
366a7672cf | |||
0176af142e | |||
f7f94ffe88 | |||
34b1d7eafe | |||
0d1fb6cc8a | |||
16583ecc12 | |||
d495142506 | |||
f8943176f0 | |||
4ceb9c01f9 | |||
a5274cdc87 | |||
9601046bf4 | |||
bf9e636605 | |||
4e37570739 | |||
2f818ed0fb | |||
b3497bad12 | |||
34e733f200 | |||
72a1d77694 | |||
088a533480 | |||
bc39c5cbea | |||
ea55e37c36 | |||
4495792953 | |||
67938bcc9d | |||
6e8cad49a0 | |||
7702ceb8af | |||
9fb5c5c4a3 | |||
8efc6d84ca | |||
98a9519f1c | |||
c0b7379a31 | |||
4d393eb876 | |||
6e2d15e3c4 | |||
76e5f493d2 | |||
93afbd1595 | |||
64ab2c82e8 | |||
b1e5547551 | |||
85520ac6a3 | |||
51bb05c795 | |||
5e27deed43 | |||
aa1097921d | |||
36a87fec68 | |||
a2df8587bf | |||
bcf2a9db1f | |||
55342094fb | |||
175358e15e | |||
8b767aae65 | |||
32f79df36e | |||
ff3c97807a | |||
e0ec9a127f | |||
a3b6537144 | |||
e36b243c71 | |||
2f9b248af8 | |||
95d04ebca8 | |||
82379bf660 | |||
364eed8479 | |||
66e06a72bf | |||
9710639195 | |||
a21eb02d0a | |||
e979ea74aa | |||
03d3e7b2ed | |||
ae960002fe | |||
864cba9598 | |||
591a44c02d | |||
9ebef6c0a7 | |||
18a700945f | |||
5ee1bcae59 | |||
eed947be0b | |||
37b2516bff | |||
9d58430833 | |||
4c2f32ed1a | |||
767febf86f | |||
13d5d0a56e | |||
534efca06f | |||
277a3958d9 | |||
385c0bf55a | |||
72e514c907 | |||
32f5975770 | |||
8b9025345e | |||
4ef1135839 | |||
1ec194b21c | |||
e8f40b770f | |||
2098de6279 | |||
ed3951ebbd | |||
a2481def5d | |||
59e323822f | |||
a90c7df7ed | |||
a2c0496991 | |||
6556224e1f | |||
8611bf99e0 | |||
59222fe90b | |||
d8e702693a | |||
63f151aadb | |||
3cc9af5ce3 | |||
d021868ccf | |||
330e18555c | |||
9442266c70 | |||
1358ecb77f | |||
29d8a4d4ab | |||
7f3b0bad4b | |||
b7b803a6d5 | |||
a4708009cc | |||
49c9953425 | |||
115336ccaf | |||
de1e1195b3 | |||
90c5bc081d | |||
4187f79cf0 | |||
3d3416e892 | |||
81c6f1dfba | |||
0bcf71c13c | |||
316b3a719f | |||
8b1a4320b8 | |||
238fe4ded4 | |||
6caf954c1b | |||
6c15371695 | |||
2840bb5104 | |||
4b888334d2 | |||
f07afa3e26 | |||
cc5c08f9d6 | |||
5a16ba3ae1 | |||
90fa59f685 | |||
66127011a5 | |||
9cabe9d457 |
@ -42,6 +42,7 @@
|
||||
ArmMtlLib|ArmPlatformPkg/Include/Library/ArmMtlLib.h
|
||||
ArmSvcLib|Include/Library/ArmSvcLib.h
|
||||
OpteeLib|Include/Library/OpteeLib.h
|
||||
StandaloneMmMmuLib|Include/Library/StandaloneMmMmuLib.h
|
||||
|
||||
[Guids.common]
|
||||
gArmTokenSpaceGuid = { 0xBB11ECFE, 0x820F, 0x4968, { 0xBB, 0xA6, 0xF7, 0x6A, 0xFE, 0x30, 0x25, 0x96 } }
|
||||
@ -58,6 +59,7 @@
|
||||
## Arm System Control and Management Interface(SCMI) Clock management protocol
|
||||
## ArmPkg/Include/Protocol/ArmScmiClockProtocol.h
|
||||
gArmScmiClockProtocolGuid = { 0x91ce67a8, 0xe0aa, 0x4012, { 0xb9, 0x9f, 0xb6, 0xfc, 0xf3, 0x4, 0x8e, 0xaa } }
|
||||
gArmScmiClock2ProtocolGuid = { 0xb8d8caf2, 0x9e94, 0x462c, { 0xa8, 0x34, 0x6c, 0x99, 0xfc, 0x05, 0xef, 0xcf } }
|
||||
|
||||
## Arm System Control and Management Interface(SCMI) Clock management protocol
|
||||
## ArmPkg/Include/Protocol/ArmScmiPerformanceProtocol.h
|
||||
@ -79,10 +81,6 @@
|
||||
# it has been configured by the CPU DXE
|
||||
gArmTokenSpaceGuid.PcdDebuggerExceptionSupport|FALSE|BOOLEAN|0x00000032
|
||||
|
||||
# Define if the spin-table mechanism is used by the secondary cores when booting
|
||||
# Linux (instead of PSCI)
|
||||
gArmTokenSpaceGuid.PcdArmLinuxSpinTable|FALSE|BOOLEAN|0x00000033
|
||||
|
||||
# Define if the GICv3 controller should use the GICv2 legacy
|
||||
gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x00000042
|
||||
|
||||
@ -172,16 +170,6 @@
|
||||
# By default we do not do a transition to non-secure mode
|
||||
gArmTokenSpaceGuid.PcdArmNonSecModeTransition|0x0|UINT32|0x0000003E
|
||||
|
||||
# The Linux ATAGs are expected to be under 0x4000 (16KB) from the beginning of the System Memory
|
||||
gArmTokenSpaceGuid.PcdArmLinuxAtagMaxOffset|0x4000|UINT32|0x00000020
|
||||
|
||||
# If the fixed FDT address is not available, then it should be loaded below the kernel.
|
||||
# The recommendation from the Linux kernel is to have the FDT below 16KB.
|
||||
# (see the kernel doc: Documentation/arm/Booting)
|
||||
gArmTokenSpaceGuid.PcdArmLinuxFdtMaxOffset|0x4000|UINT32|0x00000023
|
||||
# The FDT blob must be loaded at a 64bit aligned address.
|
||||
gArmTokenSpaceGuid.PcdArmLinuxFdtAlignment|0x8|UINT32|0x00000026
|
||||
|
||||
# Non Secure Access Control Register
|
||||
# - BIT15 : NSASEDIS - Disable Non-secure Advanced SIMD functionality
|
||||
# - BIT14 : NSD32DIS - Disable Non-secure use of D16-D31
|
||||
@ -220,12 +208,6 @@
|
||||
# Other modes include using SP0 or switching to Aarch32, but these are
|
||||
# not currently supported.
|
||||
gArmTokenSpaceGuid.PcdArmNonSecModeTransition|0x3c9|UINT32|0x0000003E
|
||||
# If the fixed FDT address is not available, then it should be loaded above the kernel.
|
||||
# The recommendation from the AArch64 Linux kernel is to have the FDT below 512MB.
|
||||
# (see the kernel doc: Documentation/arm64/booting.txt)
|
||||
gArmTokenSpaceGuid.PcdArmLinuxFdtMaxOffset|0x20000000|UINT32|0x00000023
|
||||
# The FDT blob must be loaded at a 2MB aligned address.
|
||||
gArmTokenSpaceGuid.PcdArmLinuxFdtAlignment|0x00200000|UINT32|0x00000026
|
||||
|
||||
|
||||
#
|
||||
@ -240,6 +222,9 @@
|
||||
gArmTokenSpaceGuid.PcdSystemMemoryBase|0|UINT64|0x00000029
|
||||
gArmTokenSpaceGuid.PcdSystemMemorySize|0|UINT64|0x0000002A
|
||||
|
||||
gArmTokenSpaceGuid.PcdMmBufferBase|0|UINT64|0x00000045
|
||||
gArmTokenSpaceGuid.PcdMmBufferSize|0|UINT64|0x00000046
|
||||
|
||||
[PcdsFixedAtBuild.common, PcdsDynamic.common]
|
||||
#
|
||||
# ARM Architectural Timer
|
||||
|
@ -31,9 +31,6 @@
|
||||
SKUID_IDENTIFIER = DEFAULT
|
||||
|
||||
[BuildOptions]
|
||||
XCODE:*_*_ARM_PLATFORM_FLAGS == -arch armv7
|
||||
GCC:*_*_ARM_PLATFORM_FLAGS == -march=armv7-a -mfpu=neon
|
||||
|
||||
RELEASE_*_*_CC_FLAGS = -DMDEPKG_NDEBUG
|
||||
*_*_*_CC_FLAGS = -DDISABLE_NEW_DEPRECATED_INTERFACES
|
||||
|
||||
@ -152,3 +149,4 @@
|
||||
|
||||
[Components.AARCH64]
|
||||
ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf
|
||||
ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
|
||||
|
@ -66,7 +66,7 @@ ASM_FUNC(ArmGicV3EndOfInterrupt)
|
||||
// VOID
|
||||
// );
|
||||
ASM_FUNC(ArmGicV3AcknowledgeInterrupt)
|
||||
mrc p15, 0, r0, c12, c8, 0 //ICC_IAR1
|
||||
mrc p15, 0, r0, c12, c12, 0 //ICC_IAR1
|
||||
bx lr
|
||||
|
||||
//VOID
|
||||
|
@ -66,7 +66,7 @@
|
||||
// VOID
|
||||
// );
|
||||
RVCT_ASM_EXPORT ArmGicV3AcknowledgeInterrupt
|
||||
mrc p15, 0, r0, c12, c8, 0 //ICC_IAR1
|
||||
mrc p15, 0, r0, c12, c12, 0 //ICC_IAR1
|
||||
bx lr
|
||||
|
||||
//VOID
|
||||
|
@ -59,6 +59,13 @@ typedef struct {
|
||||
CLOCK_RATE_DWORD Rate;
|
||||
} CLOCK_RATE_SET_ATTRIBUTES;
|
||||
|
||||
|
||||
// Message parameters for CLOCK_CONFIG_SET command.
|
||||
typedef struct {
|
||||
UINT32 ClockId;
|
||||
UINT32 Attributes;
|
||||
} CLOCK_CONFIG_SET_ATTRIBUTES;
|
||||
|
||||
// if ClockAttr Bit[0] is set then clock device is enabled.
|
||||
#define CLOCK_ENABLE_MASK 0x1
|
||||
#define CLOCK_ENABLED(ClockAttr) ((ClockAttr & CLOCK_ENABLE_MASK) == 1)
|
||||
|
@ -46,6 +46,7 @@
|
||||
[Protocols]
|
||||
gArmScmiBaseProtocolGuid
|
||||
gArmScmiClockProtocolGuid
|
||||
gArmScmiClock2ProtocolGuid
|
||||
gArmScmiPerformanceProtocolGuid
|
||||
|
||||
[Depex]
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Protocol/ArmScmiClockProtocol.h>
|
||||
#include <Protocol/ArmScmiClock2Protocol.h>
|
||||
|
||||
#include "ArmScmiClockProtocolPrivate.h"
|
||||
#include "ScmiPrivate.h"
|
||||
@ -388,6 +389,53 @@ ClockRateSet (
|
||||
return Status;
|
||||
}
|
||||
|
||||
/** Enable/Disable specified clock.
|
||||
|
||||
@param[in] This A Pointer to SCMI_CLOCK_PROTOCOL Instance.
|
||||
@param[in] ClockId Identifier for the clock device.
|
||||
@param[in] Enable TRUE to enable, FALSE to disable.
|
||||
|
||||
@retval EFI_SUCCESS Clock enable/disable successful.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ClockEnable (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
IN UINT32 ClockId,
|
||||
IN BOOLEAN Enable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
CLOCK_CONFIG_SET_ATTRIBUTES *ClockConfigSetAttributes;
|
||||
SCMI_COMMAND Cmd;
|
||||
UINT32 PayloadLength;
|
||||
|
||||
Status = ScmiCommandGetPayload ((UINT32**)&ClockConfigSetAttributes);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Fill arguments for clock protocol command.
|
||||
ClockConfigSetAttributes->ClockId = ClockId;
|
||||
ClockConfigSetAttributes->Attributes = Enable ? BIT0 : 0;
|
||||
|
||||
Cmd.ProtocolId = SCMI_PROTOCOL_ID_CLOCK;
|
||||
Cmd.MessageId = SCMI_MESSAGE_ID_CLOCK_CONFIG_SET;
|
||||
|
||||
PayloadLength = sizeof (CLOCK_CONFIG_SET_ATTRIBUTES);
|
||||
|
||||
// Execute and wait for response on a SCMI channel.
|
||||
Status = ScmiCommandExecute (
|
||||
&Cmd,
|
||||
&PayloadLength,
|
||||
NULL
|
||||
);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Instance of the SCMI clock management protocol.
|
||||
STATIC CONST SCMI_CLOCK_PROTOCOL ScmiClockProtocol = {
|
||||
ClockGetVersion,
|
||||
@ -398,6 +446,18 @@ STATIC CONST SCMI_CLOCK_PROTOCOL ScmiClockProtocol = {
|
||||
ClockRateSet
|
||||
};
|
||||
|
||||
// Instance of the SCMI clock management protocol.
|
||||
STATIC CONST SCMI_CLOCK2_PROTOCOL ScmiClock2Protocol = {
|
||||
(SCMI_CLOCK2_GET_VERSION)ClockGetVersion,
|
||||
(SCMI_CLOCK2_GET_TOTAL_CLOCKS)ClockGetTotalClocks,
|
||||
(SCMI_CLOCK2_GET_CLOCK_ATTRIBUTES)ClockGetClockAttributes,
|
||||
(SCMI_CLOCK2_DESCRIBE_RATES)ClockDescribeRates,
|
||||
(SCMI_CLOCK2_RATE_GET)ClockRateGet,
|
||||
(SCMI_CLOCK2_RATE_SET)ClockRateSet,
|
||||
SCMI_CLOCK2_PROTOCOL_VERSION,
|
||||
ClockEnable
|
||||
};
|
||||
|
||||
/** Initialize clock management protocol and install protocol on a given handle.
|
||||
|
||||
@param[in] Handle Handle to install clock management protocol.
|
||||
@ -413,6 +473,8 @@ ScmiClockProtocolInit (
|
||||
Handle,
|
||||
&gArmScmiClockProtocolGuid,
|
||||
&ScmiClockProtocol,
|
||||
&gArmScmiClock2ProtocolGuid,
|
||||
&ScmiClock2Protocol,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
@ -457,6 +457,9 @@ GetMemoryRegion (
|
||||
|
||||
// Get the section at the given index
|
||||
SectionDescriptor = FirstLevelTable[TableIndex];
|
||||
if (!SectionDescriptor) {
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
// If 'BaseAddress' belongs to the section then round it to the section boundary
|
||||
if (((SectionDescriptor & TT_DESCRIPTOR_SECTION_TYPE_MASK) == TT_DESCRIPTOR_SECTION_TYPE_SECTION) ||
|
||||
|
@ -73,7 +73,7 @@ InitializeCpuPeim (
|
||||
ArmEnableBranchPrediction ();
|
||||
|
||||
// Publish the CPU memory and io spaces sizes
|
||||
BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
|
||||
BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
|
||||
|
||||
// Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
|
||||
Status = PeiServicesLocatePpi (&gArmMpCoreInfoPpiGuid, 0, NULL, (VOID**)&ArmMpCoreInfoPpi);
|
||||
|
@ -50,7 +50,6 @@
|
||||
gArmMpCoreInfoGuid
|
||||
|
||||
[FixedPcd]
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize
|
||||
|
||||
[Depex]
|
||||
|
@ -34,15 +34,17 @@
|
||||
#define TIME_UNITS_PER_SECOND 10000000
|
||||
|
||||
// Tick frequency of the generic timer basis of the generic watchdog.
|
||||
UINTN mTimerFrequencyHz = 0;
|
||||
STATIC UINTN mTimerFrequencyHz = 0;
|
||||
|
||||
/* In cases where the compare register was set manually, information about
|
||||
how long the watchdog was asked to wait cannot be retrieved from hardware.
|
||||
It is therefore stored here. 0 means the timer is not running. */
|
||||
UINT64 mNumTimerTicks = 0;
|
||||
STATIC UINT64 mNumTimerTicks = 0;
|
||||
|
||||
EFI_HARDWARE_INTERRUPT2_PROTOCOL *mInterruptProtocol;
|
||||
STATIC EFI_HARDWARE_INTERRUPT2_PROTOCOL *mInterruptProtocol;
|
||||
STATIC EFI_WATCHDOG_TIMER_NOTIFY mWatchdogNotify;
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
WatchdogWriteOffsetRegister (
|
||||
UINT32 Value
|
||||
@ -51,6 +53,7 @@ WatchdogWriteOffsetRegister (
|
||||
MmioWrite32 (GENERIC_WDOG_OFFSET_REG, Value);
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
WatchdogWriteCompareRegister (
|
||||
UINT64 Value
|
||||
@ -60,6 +63,7 @@ WatchdogWriteCompareRegister (
|
||||
MmioWrite32 (GENERIC_WDOG_COMPARE_VALUE_REG_HIGH, (Value >> 32) & MAX_UINT32);
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
WatchdogEnable (
|
||||
VOID
|
||||
@ -68,6 +72,7 @@ WatchdogEnable (
|
||||
MmioWrite32 (GENERIC_WDOG_CONTROL_STATUS_REG, GENERIC_WDOG_ENABLED);
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
WatchdogDisable (
|
||||
VOID
|
||||
@ -79,6 +84,7 @@ WatchdogDisable (
|
||||
/** On exiting boot services we must make sure the Watchdog Timer
|
||||
is stopped.
|
||||
**/
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
WatchdogExitBootServicesEvent (
|
||||
@ -93,6 +99,7 @@ WatchdogExitBootServicesEvent (
|
||||
/* This function is called when the watchdog's first signal (WS0) goes high.
|
||||
It uses the ResetSystem Runtime Service to reset the board.
|
||||
*/
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
WatchdogInterruptHandler (
|
||||
@ -101,17 +108,25 @@ WatchdogInterruptHandler (
|
||||
)
|
||||
{
|
||||
STATIC CONST CHAR16 ResetString[]= L"The generic watchdog timer ran out.";
|
||||
UINT64 TimerPeriod;
|
||||
|
||||
WatchdogDisable ();
|
||||
|
||||
mInterruptProtocol->EndOfInterrupt (mInterruptProtocol, Source);
|
||||
|
||||
gRT->ResetSystem (
|
||||
EfiResetCold,
|
||||
EFI_TIMEOUT,
|
||||
StrSize (ResetString),
|
||||
(VOID *) &ResetString
|
||||
);
|
||||
//
|
||||
// The notify function should be called with the elapsed number of ticks
|
||||
// since the watchdog was armed, which should exceed the timer period.
|
||||
// We don't actually know the elapsed number of ticks, so let's return
|
||||
// the timer period plus 1.
|
||||
//
|
||||
if (mWatchdogNotify != NULL) {
|
||||
TimerPeriod = ((TIME_UNITS_PER_SECOND / mTimerFrequencyHz) * mNumTimerTicks);
|
||||
mWatchdogNotify (TimerPeriod + 1);
|
||||
}
|
||||
|
||||
gRT->ResetSystem (EfiResetCold, EFI_TIMEOUT, StrSize (ResetString),
|
||||
(CHAR16 *)ResetString);
|
||||
|
||||
// If we got here then the reset didn't work
|
||||
ASSERT (FALSE);
|
||||
@ -141,16 +156,24 @@ WatchdogInterruptHandler (
|
||||
@retval EFI_UNSUPPORTED The code does not support NotifyFunction.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
WatchdogRegisterHandler (
|
||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
|
||||
)
|
||||
{
|
||||
// ERROR: This function is not supported.
|
||||
// The watchdog will reset the board
|
||||
return EFI_UNSUPPORTED;
|
||||
if (mWatchdogNotify == NULL && NotifyFunction == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (mWatchdogNotify != NULL && NotifyFunction != NULL) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
mWatchdogNotify = NotifyFunction;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,10 +190,11 @@ WatchdogRegisterHandler (
|
||||
in TimerPeriod 100ns units.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
WatchdogSetTimerPeriod (
|
||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN UINT64 TimerPeriod // In 100ns units
|
||||
)
|
||||
{
|
||||
@ -222,10 +246,11 @@ WatchdogSetTimerPeriod (
|
||||
@retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
WatchdogGetTimerPeriod (
|
||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
OUT UINT64 *TimerPeriod
|
||||
)
|
||||
{
|
||||
@ -270,13 +295,13 @@ WatchdogGetTimerPeriod (
|
||||
Retrieves the period of the timer interrupt in 100ns units.
|
||||
|
||||
**/
|
||||
EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {
|
||||
(EFI_WATCHDOG_TIMER_REGISTER_HANDLER)WatchdogRegisterHandler,
|
||||
(EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD)WatchdogSetTimerPeriod,
|
||||
(EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD)WatchdogGetTimerPeriod
|
||||
STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {
|
||||
WatchdogRegisterHandler,
|
||||
WatchdogSetTimerPeriod,
|
||||
WatchdogGetTimerPeriod
|
||||
};
|
||||
|
||||
EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;
|
||||
STATIC EFI_EVENT mEfiExitBootServicesEvent;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@ -288,6 +313,10 @@ GenericWatchdogEntry (
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE Handle;
|
||||
|
||||
Status = gBS->LocateProtocol (&gHardwareInterrupt2ProtocolGuid, NULL,
|
||||
(VOID **)&mInterruptProtocol);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
/* Make sure the Watchdog Timer Architectural Protocol has not been installed
|
||||
in the system yet.
|
||||
This will avoid conflicts with the universal watchdog */
|
||||
@ -296,51 +325,45 @@ GenericWatchdogEntry (
|
||||
mTimerFrequencyHz = ArmGenericTimerGetTimerFreq ();
|
||||
ASSERT (mTimerFrequencyHz != 0);
|
||||
|
||||
// Register for an ExitBootServicesEvent
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_SIGNAL_EXIT_BOOT_SERVICES,
|
||||
TPL_NOTIFY,
|
||||
WatchdogExitBootServicesEvent,
|
||||
NULL,
|
||||
&EfiExitBootServicesEvent
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
// Install interrupt handler
|
||||
Status = gBS->LocateProtocol (
|
||||
&gHardwareInterrupt2ProtocolGuid,
|
||||
NULL,
|
||||
(VOID **)&mInterruptProtocol
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Status = mInterruptProtocol->RegisterInterruptSource (
|
||||
mInterruptProtocol,
|
||||
Status = mInterruptProtocol->RegisterInterruptSource (mInterruptProtocol,
|
||||
FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum),
|
||||
WatchdogInterruptHandler
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
Status = mInterruptProtocol->SetTriggerType (
|
||||
mInterruptProtocol,
|
||||
FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum),
|
||||
EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING
|
||||
);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
// Install the Timer Architectural Protocol onto a new handle
|
||||
Handle = NULL;
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Handle,
|
||||
&gEfiWatchdogTimerArchProtocolGuid,
|
||||
&gWatchdogTimer,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
WatchdogInterruptHandler);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = mInterruptProtocol->SetTriggerType (mInterruptProtocol,
|
||||
FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum),
|
||||
EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto UnregisterHandler;
|
||||
}
|
||||
|
||||
// Install the Timer Architectural Protocol onto a new handle
|
||||
Handle = NULL;
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (&Handle,
|
||||
&gEfiWatchdogTimerArchProtocolGuid, &mWatchdogTimer,
|
||||
NULL);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto UnregisterHandler;
|
||||
}
|
||||
|
||||
// Register for an ExitBootServicesEvent
|
||||
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY,
|
||||
WatchdogExitBootServicesEvent, NULL,
|
||||
&mEfiExitBootServicesEvent);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
mNumTimerTicks = 0;
|
||||
WatchdogDisable ();
|
||||
|
||||
return EFI_SUCCESS;
|
||||
|
||||
UnregisterHandler:
|
||||
// Unregister the handler
|
||||
mInterruptProtocol->RegisterInterruptSource (mInterruptProtocol,
|
||||
FixedPcdGet32 (PcdGenericWatchdogEl2IntrNum),
|
||||
NULL);
|
||||
return Status;
|
||||
}
|
||||
|
@ -16,17 +16,16 @@
|
||||
FILE_GUID = 0619f5c2-4858-4caa-a86a-73a21a18df6b
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
ENTRY_POINT = GenericWatchdogEntry
|
||||
|
||||
[Sources.common]
|
||||
GenericWatchdogDxe.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
EmbeddedPkg/EmbeddedPkg.dec
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmPlatformPkg/ArmPlatformPkg.dec
|
||||
EmbeddedPkg/EmbeddedPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
ArmGenericTimerCounterLib
|
||||
@ -46,8 +45,8 @@
|
||||
gArmTokenSpaceGuid.PcdGenericWatchdogEl2IntrNum
|
||||
|
||||
[Protocols]
|
||||
gEfiWatchdogTimerArchProtocolGuid
|
||||
gHardwareInterrupt2ProtocolGuid
|
||||
gEfiWatchdogTimerArchProtocolGuid ## ALWAYS_PRODUCES
|
||||
gHardwareInterrupt2ProtocolGuid ## ALWAYS_CONSUMES
|
||||
|
||||
[Depex]
|
||||
gHardwareInterrupt2ProtocolGuid
|
||||
|
28
ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h
Normal file
28
ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h
Normal file
@ -0,0 +1,28 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2016-2018, ARM Limited. All rights reserved.
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#if !defined _MM_COMMUNICATE_H_
|
||||
#define _MM_COMMUNICATE_H_
|
||||
|
||||
#define MM_MAJOR_VER_MASK 0xEFFF0000
|
||||
#define MM_MINOR_VER_MASK 0x0000FFFF
|
||||
#define MM_MAJOR_VER_SHIFT 16
|
||||
|
||||
#define MM_MAJOR_VER(x) (((x) & MM_MAJOR_VER_MASK) >> MM_MAJOR_VER_SHIFT)
|
||||
#define MM_MINOR_VER(x) ((x) & MM_MINOR_VER_MASK)
|
||||
|
||||
#define MM_CALLER_MAJOR_VER 0x1UL
|
||||
#define MM_CALLER_MINOR_VER 0x0
|
||||
|
||||
#endif /* _MM_COMMUNICATE_H_ */
|
372
ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c
Normal file
372
ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c
Normal file
@ -0,0 +1,372 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2016-2018, ARM Limited. All rights reserved.
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <Library/ArmLib.h>
|
||||
#include <Library/ArmSmcLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/DxeServicesTableLib.h>
|
||||
#include <Library/HobLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
|
||||
#include <Protocol/MmCommunication.h>
|
||||
|
||||
#include <IndustryStandard/ArmStdSmc.h>
|
||||
|
||||
#include "MmCommunicate.h"
|
||||
|
||||
//
|
||||
// Address, Length of the pre-allocated buffer for communication with the secure
|
||||
// world.
|
||||
//
|
||||
STATIC ARM_MEMORY_REGION_DESCRIPTOR mNsCommBuffMemRegion;
|
||||
|
||||
// Notification event when virtual address map is set.
|
||||
STATIC EFI_EVENT mSetVirtualAddressMapEvent;
|
||||
|
||||
//
|
||||
// Handle to install the MM Communication Protocol
|
||||
//
|
||||
STATIC EFI_HANDLE mMmCommunicateHandle;
|
||||
|
||||
/**
|
||||
Communicates with a registered handler.
|
||||
|
||||
This function provides an interface to send and receive messages to the
|
||||
Standalone MM environment on behalf of UEFI services. This function is part
|
||||
of the MM Communication Protocol that may be called in physical mode prior to
|
||||
SetVirtualAddressMap() and in virtual mode after SetVirtualAddressMap().
|
||||
|
||||
@param[in] This The EFI_MM_COMMUNICATION_PROTOCOL
|
||||
instance.
|
||||
@param[in, out] CommBuffer A pointer to the buffer to convey
|
||||
into MMRAM.
|
||||
@param[in, out] CommSize The size of the data buffer being
|
||||
passed in. This is optional.
|
||||
|
||||
@retval EFI_SUCCESS The message was successfully posted.
|
||||
@retval EFI_INVALID_PARAMETER The CommBuffer was NULL.
|
||||
@retval EFI_BAD_BUFFER_SIZE The buffer size is incorrect for the MM
|
||||
implementation. If this error is
|
||||
returned, the MessageLength field in
|
||||
the CommBuffer header or the integer
|
||||
pointed by CommSize are updated to reflect
|
||||
the maximum payload size the
|
||||
implementation can accommodate.
|
||||
@retval EFI_ACCESS_DENIED The CommunicateBuffer parameter
|
||||
or CommSize parameter, if not omitted,
|
||||
are in address range that cannot be
|
||||
accessed by the MM environment
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
MmCommunicationCommunicate (
|
||||
IN CONST EFI_MM_COMMUNICATION_PROTOCOL *This,
|
||||
IN OUT VOID *CommBuffer,
|
||||
IN OUT UINTN *CommSize OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_MM_COMMUNICATE_HEADER *CommunicateHeader;
|
||||
ARM_SMC_ARGS CommunicateSmcArgs;
|
||||
EFI_STATUS Status;
|
||||
UINTN BufferSize;
|
||||
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
BufferSize = 0;
|
||||
|
||||
ZeroMem (&CommunicateSmcArgs, sizeof (ARM_SMC_ARGS));
|
||||
|
||||
//
|
||||
// Check parameters
|
||||
//
|
||||
if (CommBuffer == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
CommunicateHeader = CommBuffer;
|
||||
// CommBuffer is a mandatory parameter. Hence, Rely on
|
||||
// MessageLength + Header to ascertain the
|
||||
// total size of the communication payload rather than
|
||||
// rely on optional CommSize parameter
|
||||
BufferSize = CommunicateHeader->MessageLength +
|
||||
sizeof (CommunicateHeader->HeaderGuid) +
|
||||
sizeof (CommunicateHeader->MessageLength);
|
||||
|
||||
// If the length of the CommBuffer is 0 then return the expected length.
|
||||
if (CommSize) {
|
||||
// This case can be used by the consumer of this driver to find out the
|
||||
// max size that can be used for allocating CommBuffer.
|
||||
if ((*CommSize == 0) ||
|
||||
(*CommSize > mNsCommBuffMemRegion.Length)) {
|
||||
*CommSize = mNsCommBuffMemRegion.Length;
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
//
|
||||
// CommSize must match MessageLength + sizeof (EFI_MM_COMMUNICATE_HEADER);
|
||||
//
|
||||
if (*CommSize != BufferSize) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// If the buffer size is 0 or greater than what can be tolerated by the MM
|
||||
// environment then return the expected size.
|
||||
//
|
||||
if ((BufferSize == 0) ||
|
||||
(BufferSize > mNsCommBuffMemRegion.Length)) {
|
||||
CommunicateHeader->MessageLength = mNsCommBuffMemRegion.Length -
|
||||
sizeof (CommunicateHeader->HeaderGuid) -
|
||||
sizeof (CommunicateHeader->MessageLength);
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
// SMC Function ID
|
||||
CommunicateSmcArgs.Arg0 = ARM_SMC_ID_MM_COMMUNICATE_AARCH64;
|
||||
|
||||
// Cookie
|
||||
CommunicateSmcArgs.Arg1 = 0;
|
||||
|
||||
// Copy Communication Payload
|
||||
CopyMem ((VOID *)mNsCommBuffMemRegion.VirtualBase, CommBuffer, BufferSize);
|
||||
|
||||
// comm_buffer_address (64-bit physical address)
|
||||
CommunicateSmcArgs.Arg2 = (UINTN)mNsCommBuffMemRegion.PhysicalBase;
|
||||
|
||||
// comm_size_address (not used, indicated by setting to zero)
|
||||
CommunicateSmcArgs.Arg3 = 0;
|
||||
|
||||
// Call the Standalone MM environment.
|
||||
ArmCallSmc (&CommunicateSmcArgs);
|
||||
|
||||
switch (CommunicateSmcArgs.Arg0) {
|
||||
case ARM_SMC_MM_RET_SUCCESS:
|
||||
ZeroMem (CommBuffer, BufferSize);
|
||||
// On successful return, the size of data being returned is inferred from
|
||||
// MessageLength + Header.
|
||||
CommunicateHeader = (EFI_MM_COMMUNICATE_HEADER *)mNsCommBuffMemRegion.VirtualBase;
|
||||
BufferSize = CommunicateHeader->MessageLength +
|
||||
sizeof (CommunicateHeader->HeaderGuid) +
|
||||
sizeof (CommunicateHeader->MessageLength);
|
||||
|
||||
CopyMem (
|
||||
CommBuffer,
|
||||
(VOID *)mNsCommBuffMemRegion.VirtualBase,
|
||||
BufferSize
|
||||
);
|
||||
Status = EFI_SUCCESS;
|
||||
break;
|
||||
|
||||
case ARM_SMC_MM_RET_INVALID_PARAMS:
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
break;
|
||||
|
||||
case ARM_SMC_MM_RET_DENIED:
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
break;
|
||||
|
||||
case ARM_SMC_MM_RET_NO_MEMORY:
|
||||
// Unexpected error since the CommSize was checked for zero length
|
||||
// prior to issuing the SMC
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
ASSERT (0);
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
ASSERT (0);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// MM Communication Protocol instance
|
||||
//
|
||||
EFI_MM_COMMUNICATION_PROTOCOL mMmCommunication = {
|
||||
MmCommunicationCommunicate
|
||||
};
|
||||
|
||||
/**
|
||||
Notification callback on SetVirtualAddressMap event.
|
||||
|
||||
This function notifies the MM communication protocol interface on
|
||||
SetVirtualAddressMap event and converts pointers used in this driver
|
||||
from physical to virtual address.
|
||||
|
||||
@param Event SetVirtualAddressMap event.
|
||||
@param Context A context when the SetVirtualAddressMap triggered.
|
||||
|
||||
@retval EFI_SUCCESS The function executed successfully.
|
||||
@retval Other Some error occurred when executing this function.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
NotifySetVirtualAddressMap (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = gRT->ConvertPointer (
|
||||
EFI_OPTIONAL_PTR,
|
||||
(VOID **)&mNsCommBuffMemRegion.VirtualBase
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NotifySetVirtualAddressMap():"
|
||||
" Unable to convert MM runtime pointer. Status:0x%r\n", Status));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
GetMmCompatibility ()
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 MmVersion;
|
||||
ARM_SMC_ARGS MmVersionArgs;
|
||||
|
||||
// MM_VERSION uses SMC32 calling conventions
|
||||
MmVersionArgs.Arg0 = ARM_SMC_ID_MM_VERSION_AARCH32;
|
||||
|
||||
ArmCallSmc (&MmVersionArgs);
|
||||
|
||||
MmVersion = MmVersionArgs.Arg0;
|
||||
|
||||
if ((MM_MAJOR_VER(MmVersion) == MM_CALLER_MAJOR_VER) &&
|
||||
(MM_MINOR_VER(MmVersion) >= MM_CALLER_MINOR_VER)) {
|
||||
DEBUG ((DEBUG_INFO, "MM Version: Major=0x%x, Minor=0x%x\n",
|
||||
MM_MAJOR_VER(MmVersion), MM_MINOR_VER(MmVersion)));
|
||||
Status = EFI_SUCCESS;
|
||||
} else {
|
||||
DEBUG ((DEBUG_ERROR, "Incompatible MM Versions.\n Current Version: Major=0x%x, Minor=0x%x.\n Expected: Major=0x%x, Minor>=0x%x.\n",
|
||||
MM_MAJOR_VER(MmVersion), MM_MINOR_VER(MmVersion), MM_CALLER_MAJOR_VER, MM_CALLER_MINOR_VER));
|
||||
Status = EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
The Entry Point for MM Communication
|
||||
|
||||
This function installs the MM communication protocol interface and finds out
|
||||
what type of buffer management will be required prior to invoking the
|
||||
communication SMC.
|
||||
|
||||
@param ImageHandle The firmware allocated handle for the EFI image.
|
||||
@param SystemTable A pointer to the EFI System Table.
|
||||
|
||||
@retval EFI_SUCCESS The entry point is executed successfully.
|
||||
@retval Other Some error occurred when executing this entry point.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
MmCommunicationInitialize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
// Check if we can make the MM call
|
||||
Status = GetMmCompatibility ();
|
||||
if (EFI_ERROR(Status)) {
|
||||
goto ReturnErrorStatus;
|
||||
}
|
||||
|
||||
mNsCommBuffMemRegion.PhysicalBase = PcdGet64 (PcdMmBufferBase);
|
||||
// During boot , Virtual and Physical are same
|
||||
mNsCommBuffMemRegion.VirtualBase = mNsCommBuffMemRegion.PhysicalBase;
|
||||
mNsCommBuffMemRegion.Length = PcdGet64 (PcdMmBufferSize);
|
||||
|
||||
ASSERT (mNsCommBuffMemRegion.PhysicalBase != 0);
|
||||
|
||||
ASSERT (mNsCommBuffMemRegion.Length != 0);
|
||||
|
||||
Status = gDS->AddMemorySpace (
|
||||
EfiGcdMemoryTypeReserved,
|
||||
mNsCommBuffMemRegion.PhysicalBase,
|
||||
mNsCommBuffMemRegion.Length,
|
||||
EFI_MEMORY_WB |
|
||||
EFI_MEMORY_XP |
|
||||
EFI_MEMORY_RUNTIME
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "MmCommunicateInitialize: "
|
||||
"Failed to add MM-NS Buffer Memory Space\n"));
|
||||
goto ReturnErrorStatus;
|
||||
}
|
||||
|
||||
Status = gDS->SetMemorySpaceAttributes (
|
||||
mNsCommBuffMemRegion.PhysicalBase,
|
||||
mNsCommBuffMemRegion.Length,
|
||||
EFI_MEMORY_WB | EFI_MEMORY_XP | EFI_MEMORY_RUNTIME
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "MmCommunicateInitialize: "
|
||||
"Failed to set MM-NS Buffer Memory attributes\n"));
|
||||
goto CleanAddedMemorySpace;
|
||||
}
|
||||
|
||||
// Install the communication protocol
|
||||
Status = gBS->InstallProtocolInterface (
|
||||
&mMmCommunicateHandle,
|
||||
&gEfiMmCommunicationProtocolGuid,
|
||||
EFI_NATIVE_INTERFACE,
|
||||
&mMmCommunication
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "MmCommunicationInitialize: "
|
||||
"Failed to install MM communication protocol\n"));
|
||||
goto CleanAddedMemorySpace;
|
||||
}
|
||||
|
||||
// Register notification callback when virtual address is associated
|
||||
// with the physical address.
|
||||
// Create a Set Virtual Address Map event.
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
|
||||
TPL_NOTIFY,
|
||||
NotifySetVirtualAddressMap,
|
||||
NULL,
|
||||
&mSetVirtualAddressMapEvent
|
||||
);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
gBS->UninstallProtocolInterface (
|
||||
mMmCommunicateHandle,
|
||||
&gEfiMmCommunicationProtocolGuid,
|
||||
&mMmCommunication
|
||||
);
|
||||
|
||||
CleanAddedMemorySpace:
|
||||
gDS->RemoveMemorySpace (
|
||||
mNsCommBuffMemRegion.PhysicalBase,
|
||||
mNsCommBuffMemRegion.Length
|
||||
);
|
||||
|
||||
ReturnErrorStatus:
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
56
ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf
Normal file
56
ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf
Normal file
@ -0,0 +1,56 @@
|
||||
#/** @file
|
||||
#
|
||||
# DXE MM Communicate driver
|
||||
#
|
||||
# Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x0001001A
|
||||
BASE_NAME = ArmMmCommunication
|
||||
FILE_GUID = 09EE81D3-F15E-43F4-85B4-CB9873DA5D6B
|
||||
MODULE_TYPE = DXE_RUNTIME_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
ENTRY_POINT = MmCommunicationInitialize
|
||||
|
||||
#
|
||||
# The following is for reference only and not required by
|
||||
# build tools
|
||||
#
|
||||
# VALID_ARCHITECTURES = AARCH64
|
||||
#
|
||||
|
||||
[Sources.AARCH64]
|
||||
MmCommunication.c
|
||||
|
||||
[Packages]
|
||||
ArmPkg/ArmPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
ArmLib
|
||||
ArmSmcLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
DxeServicesTableLib
|
||||
HobLib
|
||||
UefiDriverEntryPoint
|
||||
|
||||
[Protocols]
|
||||
gEfiMmCommunicationProtocolGuid ## PRODUCES
|
||||
|
||||
[Pcd.common]
|
||||
gArmTokenSpaceGuid.PcdMmBufferBase
|
||||
gArmTokenSpaceGuid.PcdMmBufferSize
|
||||
|
||||
[Depex]
|
||||
gEfiCpuArchProtocolGuid
|
@ -20,7 +20,7 @@
|
||||
* delegated events and request the Secure partition manager to perform
|
||||
* privileged operations on its behalf.
|
||||
*/
|
||||
#define ARM_SVC_ID_SPM_VERSION_AARCH64 0xC4000060
|
||||
#define ARM_SVC_ID_SPM_VERSION_AARCH32 0x84000060
|
||||
#define ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64 0xC4000061
|
||||
#define ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64 0xC4000064
|
||||
#define ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64 0xC4000065
|
||||
@ -40,4 +40,11 @@
|
||||
((((c_perm) & SET_MEM_ATTR_CODE_PERM_MASK) << SET_MEM_ATTR_CODE_PERM_SHIFT) | \
|
||||
(( (d_perm) & SET_MEM_ATTR_DATA_PERM_MASK) << SET_MEM_ATTR_DATA_PERM_SHIFT))
|
||||
|
||||
/* MM SVC Return error codes */
|
||||
#define ARM_SVC_SPM_RET_SUCCESS 0
|
||||
#define ARM_SVC_SPM_RET_NOT_SUPPORTED -1
|
||||
#define ARM_SVC_SPM_RET_INVALID_PARAMS -2
|
||||
#define ARM_SVC_SPM_RET_DENIED -3
|
||||
#define ARM_SVC_SPM_RET_NO_MEMORY -5
|
||||
|
||||
#endif
|
||||
|
@ -733,4 +733,10 @@ ArmWriteCntvOff (
|
||||
UINT64 Val
|
||||
);
|
||||
|
||||
UINTN
|
||||
EFIAPI
|
||||
ArmGetPhysicalAddressBits (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // __ARM_LIB__
|
||||
|
@ -1,212 +0,0 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2013-2015, ARM Limited. All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are licensed and made available under the terms and conditions of the BSD License
|
||||
* which accompanies this distribution. The full text of the license may be found at
|
||||
* http://opensource.org/licenses/bsd-license.php
|
||||
*
|
||||
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
*
|
||||
**/
|
||||
|
||||
#ifndef __BDS_ENTRY_H__
|
||||
#define __BDS_ENTRY_H__
|
||||
|
||||
#define IS_DEVICE_PATH_NODE(node,type,subtype) \
|
||||
(((node)->Type == (type)) && ((node)->SubType == (subtype)))
|
||||
|
||||
/**
|
||||
This is defined by the UEFI specs, don't change it
|
||||
**/
|
||||
typedef struct {
|
||||
UINT16 LoadOptionIndex;
|
||||
EFI_LOAD_OPTION *LoadOption;
|
||||
UINTN LoadOptionSize;
|
||||
|
||||
UINT32 Attributes;
|
||||
UINT16 FilePathListLength;
|
||||
CHAR16 *Description;
|
||||
EFI_DEVICE_PATH_PROTOCOL *FilePathList;
|
||||
|
||||
VOID* OptionalData;
|
||||
UINTN OptionalDataSize;
|
||||
} BDS_LOAD_OPTION;
|
||||
|
||||
/**
|
||||
Connect a Device Path and return the handle of the driver that support this DevicePath
|
||||
|
||||
@param DevicePath Device Path of the File to connect
|
||||
@param Handle Handle of the driver that support this DevicePath
|
||||
@param RemainingDevicePath Remaining DevicePath nodes that do not match the driver DevicePath
|
||||
|
||||
@retval EFI_SUCCESS A driver that matches the Device Path has been found
|
||||
@retval EFI_NOT_FOUND No handles match the search.
|
||||
@retval EFI_INVALID_PARAMETER DevicePath or Handle is NULL
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
BdsConnectDevicePath (
|
||||
IN EFI_DEVICE_PATH_PROTOCOL* DevicePath,
|
||||
OUT EFI_HANDLE *Handle,
|
||||
OUT EFI_DEVICE_PATH_PROTOCOL **RemainingDevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Connect all DXE drivers
|
||||
|
||||
@retval EFI_SUCCESS All drivers have been connected
|
||||
@retval EFI_NOT_FOUND No handles match the search.
|
||||
@retval EFI_OUT_OF_RESOURCES There is not resource pool memory to store the matching results.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
BdsConnectAllDrivers (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Return the value of a global variable defined by its VariableName.
|
||||
The variable must be defined with the VendorGuid gEfiGlobalVariableGuid.
|
||||
|
||||
@param VariableName A Null-terminated string that is the name of the vendor's
|
||||
variable.
|
||||
@param DefaultValue Value returned by the function if the variable does not exist
|
||||
@param DataSize On input, the size in bytes of the return Data buffer.
|
||||
On output the size of data returned in Data.
|
||||
@param Value Value read from the UEFI Variable or copy of the default value
|
||||
if the UEFI Variable does not exist
|
||||
|
||||
@retval EFI_SUCCESS All drivers have been connected
|
||||
@retval EFI_NOT_FOUND No handles match the search.
|
||||
@retval EFI_OUT_OF_RESOURCES There is not resource pool memory to store the matching results.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetGlobalEnvironmentVariable (
|
||||
IN CONST CHAR16* VariableName,
|
||||
IN VOID* DefaultValue,
|
||||
IN OUT UINTN* Size,
|
||||
OUT VOID** Value
|
||||
);
|
||||
|
||||
/**
|
||||
Return the value of the variable defined by its VariableName and VendorGuid
|
||||
|
||||
@param VariableName A Null-terminated string that is the name of the vendor's
|
||||
variable.
|
||||
@param VendorGuid A unique identifier for the vendor.
|
||||
@param DefaultValue Value returned by the function if the variable does not exist
|
||||
@param DataSize On input, the size in bytes of the return Data buffer.
|
||||
On output the size of data returned in Data.
|
||||
@param Value Value read from the UEFI Variable or copy of the default value
|
||||
if the UEFI Variable does not exist
|
||||
|
||||
@retval EFI_SUCCESS All drivers have been connected
|
||||
@retval EFI_NOT_FOUND No handles match the search.
|
||||
@retval EFI_OUT_OF_RESOURCES There is not resource pool memory to store the matching results.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
GetEnvironmentVariable (
|
||||
IN CONST CHAR16* VariableName,
|
||||
IN EFI_GUID* VendorGuid,
|
||||
IN VOID* DefaultValue,
|
||||
IN OUT UINTN* Size,
|
||||
OUT VOID** Value
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
BootOptionFromLoadOptionIndex (
|
||||
IN UINT16 LoadOptionIndex,
|
||||
OUT BDS_LOAD_OPTION** BdsLoadOption
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
BootOptionFromLoadOptionVariable (
|
||||
IN CHAR16* BootVariableName,
|
||||
OUT BDS_LOAD_OPTION** BdsLoadOption
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
BootOptionToLoadOptionVariable (
|
||||
IN BDS_LOAD_OPTION* BdsLoadOption
|
||||
);
|
||||
|
||||
UINT16
|
||||
BootOptionAllocateBootIndex (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Start an EFI Application from a Device Path
|
||||
|
||||
@param ParentImageHandle Handle of the calling image
|
||||
@param DevicePath Location of the EFI Application
|
||||
|
||||
@retval EFI_SUCCESS All drivers have been connected
|
||||
@retval EFI_NOT_FOUND The Linux kernel Device Path has not been found
|
||||
@retval EFI_OUT_OF_RESOURCES There is not enough resource memory to store the matching results.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
BdsStartEfiApplication (
|
||||
IN EFI_HANDLE ParentImageHandle,
|
||||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
IN UINTN LoadOptionsSize,
|
||||
IN VOID* LoadOptions
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
BdsLoadImage (
|
||||
IN EFI_DEVICE_PATH *DevicePath,
|
||||
IN EFI_ALLOCATE_TYPE Type,
|
||||
IN OUT EFI_PHYSICAL_ADDRESS* Image,
|
||||
OUT UINTN *FileSize
|
||||
);
|
||||
|
||||
/**
|
||||
* Call BS.ExitBootServices with the appropriate Memory Map information
|
||||
*/
|
||||
EFI_STATUS
|
||||
ShutdownUefiBootServices (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Locate an EFI application in a the Firmware Volumes by its name
|
||||
|
||||
@param EfiAppGuid Guid of the EFI Application into the Firmware Volume
|
||||
@param DevicePath EFI Device Path of the EFI application
|
||||
|
||||
@return EFI_SUCCESS The function completed successfully.
|
||||
@return EFI_NOT_FOUND The protocol could not be located.
|
||||
@return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
LocateEfiApplicationInFvByName (
|
||||
IN CONST CHAR16* EfiAppName,
|
||||
OUT EFI_DEVICE_PATH **DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Locate an EFI application in a the Firmware Volumes by its GUID
|
||||
|
||||
@param EfiAppGuid Guid of the EFI Application into the Firmware Volume
|
||||
@param DevicePath EFI Device Path of the EFI application
|
||||
|
||||
@return EFI_SUCCESS The function completed successfully.
|
||||
@return EFI_NOT_FOUND The protocol could not be located.
|
||||
@return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
LocateEfiApplicationInFvByGuid (
|
||||
IN CONST EFI_GUID *EfiAppGuid,
|
||||
OUT EFI_DEVICE_PATH **DevicePath
|
||||
);
|
||||
|
||||
#endif
|
@ -35,6 +35,7 @@
|
||||
|
||||
#define OPTEE_MESSAGE_ATTRIBUTE_TYPE_MASK 0xff
|
||||
|
||||
#define OPTEE_SUCCESS 0x00000000
|
||||
#define OPTEE_ORIGIN_COMMUNICATION 0x00000002
|
||||
#define OPTEE_ERROR_COMMUNICATION 0xFFFF000E
|
||||
|
||||
|
42
ArmPkg/Include/Library/StandaloneMmMmuLib.h
Normal file
42
ArmPkg/Include/Library/StandaloneMmMmuLib.h
Normal file
@ -0,0 +1,42 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2018, ARM Ltd. All rights reserved.
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef __STANDALONEMM_MMU_LIB__
|
||||
#define __STANDALONEMM_MMU_LIB__
|
||||
|
||||
EFI_STATUS
|
||||
ArmSetMemoryRegionNoExec (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
ArmClearMemoryRegionNoExec (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
ArmSetMemoryRegionReadOnly (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
ArmClearMemoryRegionReadOnly (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
);
|
||||
|
||||
#endif /* __STANDALONEMM_MMU_LIB__ */
|
197
ArmPkg/Include/Protocol/ArmScmiClock2Protocol.h
Normal file
197
ArmPkg/Include/Protocol/ArmScmiClock2Protocol.h
Normal file
@ -0,0 +1,197 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2017-2018, Arm Limited. All rights reserved.
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
System Control and Management Interface V1.0
|
||||
http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/
|
||||
DEN0056A_System_Control_and_Management_Interface.pdf
|
||||
**/
|
||||
|
||||
#ifndef ARM_SCMI_CLOCK2_PROTOCOL_H_
|
||||
#define ARM_SCMI_CLOCK2_PROTOCOL_H_
|
||||
|
||||
#include <Protocol/ArmScmi.h>
|
||||
#include <Protocol/ArmScmiClockProtocol.h>
|
||||
|
||||
#define ARM_SCMI_CLOCK2_PROTOCOL_GUID { \
|
||||
0xb8d8caf2, 0x9e94, 0x462c, { 0xa8, 0x34, 0x6c, 0x99, 0xfc, 0x05, 0xef, 0xcf } \
|
||||
}
|
||||
|
||||
extern EFI_GUID gArmScmiClock2ProtocolGuid;
|
||||
|
||||
#define SCMI_CLOCK2_PROTOCOL_VERSION 1
|
||||
|
||||
typedef struct _SCMI_CLOCK2_PROTOCOL SCMI_CLOCK2_PROTOCOL;
|
||||
|
||||
// Protocol Interface functions.
|
||||
|
||||
/** Return version of the clock management protocol supported by SCP firmware.
|
||||
|
||||
@param[in] This A Pointer to SCMI_CLOCK2_PROTOCOL Instance.
|
||||
|
||||
@param[out] Version Version of the supported SCMI Clock management protocol.
|
||||
|
||||
@retval EFI_SUCCESS The version is returned.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *SCMI_CLOCK2_GET_VERSION) (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
OUT UINT32 *Version
|
||||
);
|
||||
|
||||
/** Return total number of clock devices supported by the clock management
|
||||
protocol.
|
||||
|
||||
@param[in] This A Pointer to SCMI_CLOCK2_PROTOCOL Instance.
|
||||
|
||||
@param[out] TotalClocks Total number of clocks supported.
|
||||
|
||||
@retval EFI_SUCCESS Total number of clocks supported is returned.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *SCMI_CLOCK2_GET_TOTAL_CLOCKS) (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
OUT UINT32 *TotalClocks
|
||||
);
|
||||
|
||||
/** Return attributes of a clock device.
|
||||
|
||||
@param[in] This A Pointer to SCMI_CLOCK2_PROTOCOL Instance.
|
||||
@param[in] ClockId Identifier for the clock device.
|
||||
|
||||
@param[out] Enabled If TRUE, the clock device is enabled.
|
||||
@param[out] ClockAsciiName A NULL terminated ASCII string with the clock
|
||||
name, of up to 16 bytes.
|
||||
|
||||
@retval EFI_SUCCESS Clock device attributes are returned.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *SCMI_CLOCK2_GET_CLOCK_ATTRIBUTES) (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
IN UINT32 ClockId,
|
||||
OUT BOOLEAN *Enabled,
|
||||
OUT CHAR8 *ClockAsciiName
|
||||
);
|
||||
|
||||
/** Return list of rates supported by a given clock device.
|
||||
|
||||
@param[in] This A pointer to SCMI_CLOCK2_PROTOCOL Instance.
|
||||
@param[in] ClockId Identifier for the clock device.
|
||||
|
||||
@param[out] Format SCMI_CLOCK_RATE_FORMAT_DISCRETE: Clock device
|
||||
supports range of clock rates which are non-linear.
|
||||
|
||||
SCMI_CLOCK_RATE_FORMAT_LINEAR: Clock device supports
|
||||
range of linear clock rates from Min to Max in steps.
|
||||
|
||||
@param[out] TotalRates Total number of rates.
|
||||
|
||||
@param[in,out] RateArraySize Size of the RateArray.
|
||||
|
||||
@param[out] RateArray List of clock rates.
|
||||
|
||||
@retval EFI_SUCCESS List of clock rates are returned.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval EFI_BUFFER_TOO_SMALL RateArraySize is too small for the result.
|
||||
It has been updated to the size needed.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *SCMI_CLOCK2_DESCRIBE_RATES) (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
IN UINT32 ClockId,
|
||||
OUT SCMI_CLOCK_RATE_FORMAT *Format,
|
||||
OUT UINT32 *TotalRates,
|
||||
IN OUT UINT32 *RateArraySize,
|
||||
OUT SCMI_CLOCK_RATE *RateArray
|
||||
);
|
||||
|
||||
/** Get clock rate.
|
||||
|
||||
@param[in] This A Pointer to SCMI_CLOCK2_PROTOCOL Instance.
|
||||
@param[in] ClockId Identifier for the clock device.
|
||||
|
||||
@param[out] Rate Clock rate.
|
||||
|
||||
@retval EFI_SUCCESS Clock rate is returned.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *SCMI_CLOCK2_RATE_GET) (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
IN UINT32 ClockId,
|
||||
OUT UINT64 *Rate
|
||||
);
|
||||
|
||||
/** Set clock rate.
|
||||
|
||||
@param[in] This A Pointer to SCMI_CLOCK2_PROTOCOL Instance.
|
||||
@param[in] ClockId Identifier for the clock device.
|
||||
@param[in] Rate Clock rate.
|
||||
|
||||
@retval EFI_SUCCESS Clock rate set success.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *SCMI_CLOCK2_RATE_SET) (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
IN UINT32 ClockId,
|
||||
IN UINT64 Rate
|
||||
);
|
||||
|
||||
/** Enable/Disable specified clock.
|
||||
Function is only available under gArmScmiClock2ProtocolGuid
|
||||
|
||||
@param[in] This A Pointer to SCMI_CLOCK2_PROTOCOL Instance.
|
||||
@param[in] ClockId Identifier for the clock device.
|
||||
@param[in] Enable TRUE to enable, FALSE to disable.
|
||||
|
||||
@retval EFI_SUCCESS Clock enable/disable successful.
|
||||
@retval EFI_DEVICE_ERROR SCP returns an SCMI error.
|
||||
@retval !(EFI_SUCCESS) Other errors.
|
||||
**/
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(EFIAPI *SCMI_CLOCK2_ENABLE) (
|
||||
IN SCMI_CLOCK2_PROTOCOL *This,
|
||||
IN UINT32 ClockId,
|
||||
IN BOOLEAN Enable
|
||||
);
|
||||
|
||||
typedef struct _SCMI_CLOCK2_PROTOCOL {
|
||||
SCMI_CLOCK2_GET_VERSION GetVersion;
|
||||
SCMI_CLOCK2_GET_TOTAL_CLOCKS GetTotalClocks;
|
||||
SCMI_CLOCK2_GET_CLOCK_ATTRIBUTES GetClockAttributes;
|
||||
SCMI_CLOCK2_DESCRIBE_RATES DescribeRates;
|
||||
SCMI_CLOCK2_RATE_GET RateGet;
|
||||
SCMI_CLOCK2_RATE_SET RateSet;
|
||||
|
||||
// Extension to original ClockProtocol, added here so SCMI_CLOCK2_PROTOCOL
|
||||
// can be cast to SCMI_CLOCK_PROTOCOL
|
||||
UINTN Version; // For future expandability
|
||||
SCMI_CLOCK2_ENABLE Enable;
|
||||
} SCMI_CLOCK2_PROTOCOL;
|
||||
|
||||
#endif /* ARM_SCMI_CLOCK2_PROTOCOL_H_ */
|
@ -196,4 +196,21 @@ ASM_FUNC(ArmWriteSctlr)
|
||||
3:msr sctlr_el3, x0
|
||||
4:ret
|
||||
|
||||
ASM_FUNC(ArmGetPhysicalAddressBits)
|
||||
mrs x0, id_aa64mmfr0_el1
|
||||
adr x1, .LPARanges
|
||||
and x0, x0, #0xf
|
||||
ldrb w0, [x1, x0]
|
||||
ret
|
||||
|
||||
//
|
||||
// Bits 0..3 of the AA64MFR0_EL1 system register encode the size of the
|
||||
// physical address space support on this CPU:
|
||||
// 0 == 32 bits, 1 == 36 bits, etc etc
|
||||
// 7 and up are reserved
|
||||
//
|
||||
.LPARanges:
|
||||
.byte 32, 36, 40, 42, 44, 48, 52, 0
|
||||
.byte 0, 0, 0, 0, 0, 0, 0, 0
|
||||
|
||||
ASM_FUNCTION_REMOVE_IF_UNREFERENCED
|
||||
|
@ -165,4 +165,12 @@ ASM_FUNC(ArmWriteCpuActlr)
|
||||
isb
|
||||
bx lr
|
||||
|
||||
ASM_FUNC (ArmGetPhysicalAddressBits)
|
||||
mrc p15, 0, r0, c0, c1, 4 // MMFR0
|
||||
and r0, r0, #0xf // VMSA [3:0]
|
||||
cmp r0, #5 // >= 5 implies LPAE support
|
||||
movlt r0, #32 // 32 bits if no LPAE
|
||||
movge r0, #40 // 40 bits if LPAE
|
||||
bx lr
|
||||
|
||||
ASM_FUNCTION_REMOVE_IF_UNREFERENCED
|
||||
|
@ -169,4 +169,12 @@
|
||||
isb
|
||||
bx lr
|
||||
|
||||
RVCT_ASM_EXPORT ArmGetPhysicalAddressBits
|
||||
mrc p15, 0, r0, c0, c1, 4 ; MMFR0
|
||||
and r0, r0, #0xf ; VMSA [3:0]
|
||||
cmp r0, #5 ; >= 5 implies LPAE support
|
||||
movlt r0, #32 ; 32 bits if no LPAE
|
||||
movge r0, #40 ; 40 bits if LPAE
|
||||
bx lr
|
||||
|
||||
END
|
||||
|
@ -604,8 +604,15 @@ ArmConfigureMmu (
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// Cover the entire GCD memory space
|
||||
MaxAddress = (1UL << PcdGet8 (PcdPrePiCpuMemorySize)) - 1;
|
||||
//
|
||||
// Limit the virtual address space to what we can actually use: UEFI
|
||||
// mandates a 1:1 mapping, so no point in making the virtual address
|
||||
// space larger than the physical address space. We also have to take
|
||||
// into account the architectural limitations that result from UEFI's
|
||||
// use of 4 KB pages.
|
||||
//
|
||||
MaxAddress = MIN (LShiftU64 (1ULL, ArmGetPhysicalAddressBits ()) - 1,
|
||||
MAX_ALLOC_ADDRESS);
|
||||
|
||||
// Lookup the Table Level to get the information
|
||||
LookupAddresstoRootTable (MaxAddress, &T0SZ, &RootTableEntryCount);
|
||||
|
@ -695,8 +695,12 @@ UpdateSectionEntries (
|
||||
} else {
|
||||
// still a section entry
|
||||
|
||||
if (CurrentDescriptor != 0) {
|
||||
// mask off appropriate fields
|
||||
Descriptor = CurrentDescriptor & ~EntryMask;
|
||||
} else {
|
||||
Descriptor = ((UINTN)FirstLevelIdx + i) << TT_DESCRIPTOR_SECTION_BASE_SHIFT;
|
||||
}
|
||||
|
||||
// mask in new attributes and/or permissions
|
||||
Descriptor |= EntryValue;
|
||||
|
@ -40,8 +40,5 @@
|
||||
CacheMaintenanceLib
|
||||
MemoryAllocationLib
|
||||
|
||||
[Pcd.AARCH64]
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
|
||||
[Pcd.ARM]
|
||||
gArmTokenSpaceGuid.PcdNormalMemoryNonshareableOverride
|
||||
|
@ -35,6 +35,3 @@
|
||||
ArmLib
|
||||
CacheMaintenanceLib
|
||||
MemoryAllocationLib
|
||||
|
||||
[Pcd.AARCH64]
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
|
30
ArmPkg/Library/ArmSmcPsciResetSystemLib/AArch64/Reset.S
Normal file
30
ArmPkg/Library/ArmSmcPsciResetSystemLib/AArch64/Reset.S
Normal file
@ -0,0 +1,30 @@
|
||||
/** @file
|
||||
ResetSystemLib implementation using PSCI calls
|
||||
|
||||
Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <AsmMacroIoLibV8.h>
|
||||
|
||||
ASM_FUNC(DisableMmuAndReenterPei)
|
||||
stp x29, x30, [sp, #-16]!
|
||||
mov x29, sp
|
||||
|
||||
bl ArmDisableMmu
|
||||
|
||||
// no memory accesses after MMU and caches have been disabled
|
||||
|
||||
MOV64 (x0, FixedPcdGet64 (PcdFvBaseAddress))
|
||||
blr x0
|
||||
|
||||
// never returns
|
||||
nop
|
35
ArmPkg/Library/ArmSmcPsciResetSystemLib/AArch64/Reset.asm
Normal file
35
ArmPkg/Library/ArmSmcPsciResetSystemLib/AArch64/Reset.asm
Normal file
@ -0,0 +1,35 @@
|
||||
;/** @file
|
||||
; ResetSystemLib implementation using PSCI calls
|
||||
;
|
||||
; Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>
|
||||
;
|
||||
; This program and the accompanying materials
|
||||
; are licensed and made available under the terms and conditions of the BSD License
|
||||
; which accompanies this distribution. The full text of the license may be found at
|
||||
; http://opensource.org/licenses/bsd-license.php
|
||||
;
|
||||
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
;
|
||||
;**/
|
||||
|
||||
AREA Reset, CODE, READONLY
|
||||
|
||||
EXPORT DisableMmuAndReenterPei
|
||||
IMPORT ArmDisableMmu
|
||||
|
||||
DisableMmuAndReenterPei
|
||||
stp x29, x30, [sp, #-16]!
|
||||
mov x29, sp
|
||||
|
||||
bl ArmDisableMmu
|
||||
|
||||
; no memory accesses after MMU and caches have been disabled
|
||||
|
||||
movl x0, FixedPcdGet64 (PcdFvBaseAddress)
|
||||
blr x0
|
||||
|
||||
; never returns
|
||||
nop
|
||||
|
||||
END
|
29
ArmPkg/Library/ArmSmcPsciResetSystemLib/Arm/Reset.S
Normal file
29
ArmPkg/Library/ArmSmcPsciResetSystemLib/Arm/Reset.S
Normal file
@ -0,0 +1,29 @@
|
||||
/** @file
|
||||
ResetSystemLib implementation using PSCI calls
|
||||
|
||||
Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <AsmMacroIoLib.h>
|
||||
|
||||
ASM_FUNC(DisableMmuAndReenterPei)
|
||||
push {lr}
|
||||
|
||||
bl ArmDisableMmu
|
||||
|
||||
// no memory accesses after MMU and caches have been disabled
|
||||
|
||||
MOV32 (r0, FixedPcdGet64 (PcdFvBaseAddress))
|
||||
blx r0
|
||||
|
||||
// never returns
|
||||
nop
|
34
ArmPkg/Library/ArmSmcPsciResetSystemLib/Arm/Reset.asm
Normal file
34
ArmPkg/Library/ArmSmcPsciResetSystemLib/Arm/Reset.asm
Normal file
@ -0,0 +1,34 @@
|
||||
;/** @file
|
||||
; ResetSystemLib implementation using PSCI calls
|
||||
;
|
||||
; Copyright (c) 2018, Linaro Ltd. All rights reserved.<BR>
|
||||
;
|
||||
; This program and the accompanying materials
|
||||
; are licensed and made available under the terms and conditions of the BSD License
|
||||
; which accompanies this distribution. The full text of the license may be found at
|
||||
; http://opensource.org/licenses/bsd-license.php
|
||||
;
|
||||
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
;
|
||||
;**/
|
||||
|
||||
INCLUDE AsmMacroExport.inc
|
||||
PRESERVE8
|
||||
|
||||
IMPORT ArmDisableMmu
|
||||
|
||||
RVCT_ASM_EXPORT DisableMmuAndReenterPei
|
||||
push {lr}
|
||||
|
||||
bl ArmDisableMmu
|
||||
|
||||
; no memory accesses after MMU and caches have been disabled
|
||||
|
||||
mov32 r0, FixedPcdGet64 (PcdFvBaseAddress)
|
||||
blx r0
|
||||
|
||||
; never returns
|
||||
nop
|
||||
|
||||
END
|
@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
ResetSystemLib implementation using PSCI calls
|
||||
|
||||
Copyright (c) 2017, Linaro Ltd. All rights reserved.<BR>
|
||||
Copyright (c) 2017 - 2018, Linaro Ltd. All rights reserved.<BR>
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
@ -81,6 +81,8 @@ ResetShutdown (
|
||||
ArmCallSmc (&ArmSmcArgs);
|
||||
}
|
||||
|
||||
VOID DisableMmuAndReenterPei (VOID);
|
||||
|
||||
/**
|
||||
This function causes the system to enter S3 and then wake up immediately.
|
||||
|
||||
@ -92,7 +94,12 @@ EnterS3WithImmediateWake (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
VOID (*Reset)(VOID);
|
||||
EFI_PHYSICAL_ADDRESS Alloc;
|
||||
EFI_MEMORY_DESCRIPTOR *MemMap;
|
||||
UINTN MemMapSize;
|
||||
UINTN MapKey, DescriptorSize;
|
||||
UINT32 DescriptorVersion;
|
||||
EFI_STATUS Status;
|
||||
|
||||
if (FeaturePcdGet (PcdArmReenterPeiForCapsuleWarmReboot) &&
|
||||
!EfiAtRuntime ()) {
|
||||
@ -101,11 +108,49 @@ EnterS3WithImmediateWake (
|
||||
// immediate wake (which is used by capsule update) by disabling the MMU
|
||||
// and interrupts, and jumping to the PEI entry point.
|
||||
//
|
||||
Reset = (VOID (*)(VOID))(UINTN)FixedPcdGet64 (PcdFvBaseAddress);
|
||||
|
||||
gBS->RaiseTPL (TPL_HIGH_LEVEL);
|
||||
ArmDisableMmu ();
|
||||
Reset ();
|
||||
//
|
||||
// Obtain the size of the memory map
|
||||
//
|
||||
MemMapSize = 0;
|
||||
MemMap = NULL;
|
||||
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize,
|
||||
&DescriptorVersion);
|
||||
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
|
||||
|
||||
//
|
||||
// Add some slack to the allocation to cater for changes in the memory
|
||||
// map if ExitBootServices () fails the first time around.
|
||||
//
|
||||
MemMapSize += SIZE_4KB;
|
||||
Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData,
|
||||
EFI_SIZE_TO_PAGES (MemMapSize), &Alloc);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
MemMap = (EFI_MEMORY_DESCRIPTOR *)(UINTN)Alloc;
|
||||
|
||||
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize,
|
||||
&DescriptorVersion);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = gBS->ExitBootServices (gImageHandle, MapKey);
|
||||
if (EFI_ERROR (Status)) {
|
||||
//
|
||||
// ExitBootServices () may fail the first time around if an event fired
|
||||
// right after the call to GetMemoryMap() which allocated or freed memory.
|
||||
// Since that first call to ExitBootServices () will disarm the timer,
|
||||
// this is guaranteed not to happen again, so one additional attempt
|
||||
// should suffice.
|
||||
//
|
||||
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize,
|
||||
&DescriptorVersion);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = gBS->ExitBootServices (gImageHandle, MapKey);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
}
|
||||
|
||||
DisableMmuAndReenterPei ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,14 @@
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = ResetSystemLib
|
||||
|
||||
[Sources.AARCH64]
|
||||
AArch64/Reset.S | GCC
|
||||
AArch64/Reset.asm | MSFT
|
||||
|
||||
[Sources.ARM]
|
||||
Arm/Reset.S | GCC
|
||||
Arm/Reset.asm | RVCT
|
||||
|
||||
[Sources]
|
||||
ArmSmcPsciResetSystemLib.c
|
||||
|
||||
|
@ -267,6 +267,8 @@ DefaultExceptionHandler (
|
||||
DEBUG ((EFI_D_ERROR, "\n"));
|
||||
ASSERT (FALSE);
|
||||
|
||||
CpuDeadLoop (); // may return if executing under a debugger
|
||||
|
||||
// Clear the error registers that we have already displayed incase some one wants to keep going
|
||||
SystemContext.SystemContextArm->DFSR = 0;
|
||||
SystemContext.SystemContextArm->IFSR = 0;
|
||||
|
@ -123,6 +123,17 @@ OpteeInit (
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsOpteeSmcReturnRpc (
|
||||
UINT32 Return
|
||||
)
|
||||
{
|
||||
return (Return != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION) &&
|
||||
((Return & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
|
||||
OPTEE_SMC_RETURN_RPC_PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
Does Standard SMC to OP-TEE in secure world.
|
||||
|
||||
@ -147,13 +158,22 @@ OpteeCallWithArg (
|
||||
while (TRUE) {
|
||||
ArmCallSmc (&ArmSmcArgs);
|
||||
|
||||
if (ArmSmcArgs.Arg0 == OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT) {
|
||||
if (IsOpteeSmcReturnRpc (ArmSmcArgs.Arg0)) {
|
||||
switch (ArmSmcArgs.Arg0) {
|
||||
case OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT:
|
||||
//
|
||||
// A foreign interrupt was raised while secure world was
|
||||
// executing, since they are handled in UEFI a dummy RPC is
|
||||
// performed to let UEFI take the interrupt through the normal
|
||||
// vector.
|
||||
//
|
||||
break;
|
||||
|
||||
default:
|
||||
// Do nothing in case RPC is not implemented.
|
||||
break;
|
||||
}
|
||||
|
||||
ArmSmcArgs.Arg0 = OPTEE_SMC_RETURN_FROM_RPC;
|
||||
} else {
|
||||
break;
|
||||
|
@ -25,6 +25,9 @@
|
||||
|
||||
#define OPTEE_SMC_SHARED_MEMORY_CACHED 1
|
||||
|
||||
#define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xffffffff
|
||||
#define OPTEE_SMC_RETURN_RPC_PREFIX_MASK 0xffff0000
|
||||
#define OPTEE_SMC_RETURN_RPC_PREFIX 0xffff0000
|
||||
#define OPTEE_SMC_RETURN_RPC_FOREIGN_INTERRUPT 0xffff0004
|
||||
|
||||
#define OPTEE_MESSAGE_COMMAND_OPEN_SESSION 0
|
||||
|
@ -0,0 +1,185 @@
|
||||
/** @file
|
||||
* File managing the MMU for ARMv8 architecture in S-EL0
|
||||
*
|
||||
* Copyright (c) 2017 - 2018, ARM Limited. All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are licensed and made available under the terms and conditions of the BSD License
|
||||
* which accompanies this distribution. The full text of the license may be found at
|
||||
* http://opensource.org/licenses/bsd-license.php
|
||||
*
|
||||
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
*
|
||||
**/
|
||||
|
||||
#include <Uefi.h>
|
||||
#include <IndustryStandard/ArmMmSvc.h>
|
||||
|
||||
#include <Library/ArmLib.h>
|
||||
#include <Library/ArmMmuLib.h>
|
||||
#include <Library/ArmSvcLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
GetMemoryPermissions (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
OUT UINT32 *MemoryAttributes
|
||||
)
|
||||
{
|
||||
ARM_SVC_ARGS GetMemoryPermissionsSvcArgs = {0};
|
||||
|
||||
GetMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64;
|
||||
GetMemoryPermissionsSvcArgs.Arg1 = BaseAddress;
|
||||
GetMemoryPermissionsSvcArgs.Arg2 = 0;
|
||||
GetMemoryPermissionsSvcArgs.Arg3 = 0;
|
||||
|
||||
ArmCallSvc (&GetMemoryPermissionsSvcArgs);
|
||||
if (GetMemoryPermissionsSvcArgs.Arg0 == ARM_SVC_SPM_RET_INVALID_PARAMS) {
|
||||
*MemoryAttributes = 0;
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*MemoryAttributes = GetMemoryPermissionsSvcArgs.Arg0;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
RequestMemoryPermissionChange (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length,
|
||||
IN UINTN Permissions
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ARM_SVC_ARGS ChangeMemoryPermissionsSvcArgs = {0};
|
||||
|
||||
ChangeMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64;
|
||||
ChangeMemoryPermissionsSvcArgs.Arg1 = BaseAddress;
|
||||
ChangeMemoryPermissionsSvcArgs.Arg2 = EFI_SIZE_TO_PAGES(Length);
|
||||
ChangeMemoryPermissionsSvcArgs.Arg3 = Permissions;
|
||||
|
||||
ArmCallSvc (&ChangeMemoryPermissionsSvcArgs);
|
||||
|
||||
Status = ChangeMemoryPermissionsSvcArgs.Arg0;
|
||||
|
||||
switch (Status) {
|
||||
case ARM_SVC_SPM_RET_SUCCESS:
|
||||
Status = EFI_SUCCESS;
|
||||
break;
|
||||
|
||||
case ARM_SVC_SPM_RET_NOT_SUPPORTED:
|
||||
Status = EFI_UNSUPPORTED;
|
||||
break;
|
||||
|
||||
case ARM_SVC_SPM_RET_INVALID_PARAMS:
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
break;
|
||||
|
||||
case ARM_SVC_SPM_RET_DENIED:
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
break;
|
||||
|
||||
case ARM_SVC_SPM_RET_NO_MEMORY:
|
||||
Status = EFI_BAD_BUFFER_SIZE;
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = EFI_ACCESS_DENIED;
|
||||
ASSERT (0);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
ArmSetMemoryRegionNoExec (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 MemoryAttributes;
|
||||
UINT32 CodePermission;
|
||||
|
||||
Status = GetMemoryPermissions (BaseAddress, &MemoryAttributes);
|
||||
if (Status != EFI_INVALID_PARAMETER) {
|
||||
CodePermission = SET_MEM_ATTR_CODE_PERM_XN << SET_MEM_ATTR_CODE_PERM_SHIFT;
|
||||
return RequestMemoryPermissionChange (
|
||||
BaseAddress,
|
||||
Length,
|
||||
MemoryAttributes | CodePermission
|
||||
);
|
||||
}
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
ArmClearMemoryRegionNoExec (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 MemoryAttributes;
|
||||
UINT32 CodePermission;
|
||||
|
||||
Status = GetMemoryPermissions (BaseAddress, &MemoryAttributes);
|
||||
if (Status != EFI_INVALID_PARAMETER) {
|
||||
CodePermission = SET_MEM_ATTR_CODE_PERM_XN << SET_MEM_ATTR_CODE_PERM_SHIFT;
|
||||
return RequestMemoryPermissionChange (
|
||||
BaseAddress,
|
||||
Length,
|
||||
MemoryAttributes & ~CodePermission
|
||||
);
|
||||
}
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
ArmSetMemoryRegionReadOnly (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 MemoryAttributes;
|
||||
UINT32 DataPermission;
|
||||
|
||||
Status = GetMemoryPermissions (BaseAddress, &MemoryAttributes);
|
||||
if (Status != EFI_INVALID_PARAMETER) {
|
||||
DataPermission = SET_MEM_ATTR_DATA_PERM_RO << SET_MEM_ATTR_DATA_PERM_SHIFT;
|
||||
return RequestMemoryPermissionChange (
|
||||
BaseAddress,
|
||||
Length,
|
||||
MemoryAttributes | DataPermission
|
||||
);
|
||||
}
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
ArmClearMemoryRegionReadOnly (
|
||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||
IN UINT64 Length
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 MemoryAttributes;
|
||||
UINT32 PermissionRequest;
|
||||
|
||||
Status = GetMemoryPermissions (BaseAddress, &MemoryAttributes);
|
||||
if (Status != EFI_INVALID_PARAMETER) {
|
||||
PermissionRequest = SET_MEM_ATTR_MAKE_PERM_REQUEST (SET_MEM_ATTR_DATA_PERM_RW,
|
||||
MemoryAttributes);
|
||||
return RequestMemoryPermissionChange (
|
||||
BaseAddress,
|
||||
Length,
|
||||
PermissionRequest
|
||||
);
|
||||
}
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
36
ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
Normal file
36
ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.inf
Normal file
@ -0,0 +1,36 @@
|
||||
#/** @file
|
||||
#
|
||||
# Copyright (c) 2017 - 2018, ARM Limited. All rights reserved.
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
#**/
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x0001001A
|
||||
BASE_NAME = ArmMmuStandaloneMmCoreLib
|
||||
FILE_GUID = da8f0232-fb14-42f0-922c-63104d2c70bd
|
||||
MODULE_TYPE = MM_CORE_STANDALONE
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = StandaloneMmMmuLib
|
||||
PI_SPECIFICATION_VERSION = 0x00010032
|
||||
|
||||
[Sources.AARCH64]
|
||||
AArch64/ArmMmuStandaloneMmLib.c
|
||||
|
||||
[Packages]
|
||||
ArmPkg/ArmPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
ArmLib
|
||||
CacheMaintenanceLib
|
||||
MemoryAllocationLib
|
||||
|
||||
|
@ -70,6 +70,7 @@
|
||||
## SP805 Watchdog
|
||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase|0x0|UINT32|0x00000023
|
||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz|32000|UINT32|0x00000021
|
||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogInterrupt|0|UINT32|0x0000002E
|
||||
|
||||
## PL011 UART
|
||||
gArmPlatformTokenSpaceGuid.PL011UartClkInHz|24000000|UINT32|0x0000001F
|
||||
|
@ -82,10 +82,14 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
{
|
||||
HARDWARE_DEVICE_PATH,
|
||||
HW_VENDOR_DP,
|
||||
{ (UINT8)sizeof(VENDOR_DEVICE_PATH), (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8) }
|
||||
{
|
||||
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End)),
|
||||
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8)
|
||||
}
|
||||
},
|
||||
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED
|
||||
},
|
||||
0, // Index
|
||||
{
|
||||
END_DEVICE_PATH_TYPE,
|
||||
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
||||
@ -99,10 +103,9 @@ NorFlashCreateInstance (
|
||||
IN UINTN NorFlashDeviceBase,
|
||||
IN UINTN NorFlashRegionBase,
|
||||
IN UINTN NorFlashSize,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT32 Index,
|
||||
IN UINT32 BlockSize,
|
||||
IN BOOLEAN SupportFvb,
|
||||
IN CONST GUID *NorFlashGuid,
|
||||
OUT NOR_FLASH_INSTANCE** NorFlashInstance
|
||||
)
|
||||
{
|
||||
@ -121,11 +124,12 @@ NorFlashCreateInstance (
|
||||
Instance->Size = NorFlashSize;
|
||||
|
||||
Instance->BlockIoProtocol.Media = &Instance->Media;
|
||||
Instance->Media.MediaId = MediaId;
|
||||
Instance->Media.MediaId = Index;
|
||||
Instance->Media.BlockSize = BlockSize;
|
||||
Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;
|
||||
|
||||
CopyGuid (&Instance->DevicePath.Vendor.Guid, NorFlashGuid);
|
||||
CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);
|
||||
Instance->DevicePath.Index = (UINT8)Index;
|
||||
|
||||
Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);;
|
||||
if (Instance->ShadowBuffer == NULL) {
|
||||
@ -1311,7 +1315,6 @@ NorFlashInitialise (
|
||||
Index,
|
||||
NorFlashDevices[Index].BlockSize,
|
||||
ContainVariableStorage,
|
||||
&NorFlashDevices[Index].Guid,
|
||||
&mNorFlashInstances[Index]
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
|
@ -122,10 +122,13 @@
|
||||
|
||||
typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;
|
||||
|
||||
#pragma pack (1)
|
||||
typedef struct {
|
||||
VENDOR_DEVICE_PATH Vendor;
|
||||
UINT8 Index;
|
||||
EFI_DEVICE_PATH_PROTOCOL End;
|
||||
} NOR_FLASH_DEVICE_PATH;
|
||||
#pragma pack ()
|
||||
|
||||
struct _NOR_FLASH_INSTANCE {
|
||||
UINT32 Signature;
|
||||
|
@ -1,6 +1,7 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
||||
* Copyright (c) 2018, Linaro Limited. All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are licensed and made available under the terms and conditions of the BSD License
|
||||
@ -19,16 +20,18 @@
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/IoLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiRuntimeServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
|
||||
#include <Protocol/HardwareInterrupt.h>
|
||||
#include <Protocol/WatchdogTimer.h>
|
||||
|
||||
#include "SP805Watchdog.h"
|
||||
|
||||
EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;
|
||||
STATIC EFI_EVENT mEfiExitBootServicesEvent;
|
||||
STATIC EFI_HARDWARE_INTERRUPT_PROTOCOL *mInterrupt;
|
||||
STATIC EFI_WATCHDOG_TIMER_NOTIFY mWatchdogNotify;
|
||||
STATIC UINT32 mTimerPeriod;
|
||||
|
||||
/**
|
||||
Make sure the SP805 registers are unlocked for writing.
|
||||
@ -67,6 +70,33 @@ SP805Lock (
|
||||
}
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
SP805InterruptHandler (
|
||||
IN HARDWARE_INTERRUPT_SOURCE Source,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
SP805Unlock ();
|
||||
MmioWrite32 (SP805_WDOG_INT_CLR_REG, 0); // write of any value clears the irq
|
||||
SP805Lock ();
|
||||
|
||||
mInterrupt->EndOfInterrupt (mInterrupt, Source);
|
||||
|
||||
//
|
||||
// The notify function should be called with the elapsed number of ticks
|
||||
// since the watchdog was armed, which should exceed the timer period.
|
||||
// We don't actually know the elapsed number of ticks, so let's return
|
||||
// the timer period plus 1.
|
||||
//
|
||||
if (mWatchdogNotify != NULL) {
|
||||
mWatchdogNotify (mTimerPeriod + 1);
|
||||
}
|
||||
|
||||
gRT->ResetSystem (EfiResetCold, EFI_TIMEOUT, 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
Stop the SP805 watchdog timer from counting down by disabling interrupts.
|
||||
**/
|
||||
@ -103,6 +133,7 @@ SP805Start (
|
||||
On exiting boot services we must make sure the SP805 Watchdog Timer
|
||||
is stopped.
|
||||
**/
|
||||
STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
ExitBootServicesEvent (
|
||||
@ -142,18 +173,26 @@ ExitBootServicesEvent (
|
||||
previously registered.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SP805RegisterHandler (
|
||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
|
||||
)
|
||||
{
|
||||
// ERROR: This function is not supported.
|
||||
// The hardware watchdog will reset the board
|
||||
if (mWatchdogNotify == NULL && NotifyFunction == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (mWatchdogNotify != NULL && NotifyFunction != NULL) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
mWatchdogNotify = NotifyFunction;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
This function adjusts the period of timer interrupts to the value specified
|
||||
@ -182,39 +221,39 @@ SP805RegisterHandler (
|
||||
@retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SP805SetTimerPeriod (
|
||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN UINT64 TimerPeriod // In 100ns units
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
EFI_STATUS Status;
|
||||
UINT64 Ticks64bit;
|
||||
|
||||
SP805Unlock ();
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
if (TimerPeriod == 0) {
|
||||
// This is a watchdog stop request
|
||||
SP805Stop ();
|
||||
goto EXIT;
|
||||
} else {
|
||||
// Calculate the Watchdog ticks required for a delay of (TimerTicks * 100) nanoseconds
|
||||
// The SP805 will count down to ZERO once, generate an interrupt and
|
||||
// then it will again reload the initial value and start again.
|
||||
// On the second time when it reaches ZERO, it will actually reset the board.
|
||||
// Therefore, we need to load half the required delay.
|
||||
// The SP805 will count down to zero and generate an interrupt.
|
||||
//
|
||||
// WatchdogTicks = ((TimerPeriod * 100 * SP805_CLOCK_FREQUENCY) / 1GHz) / 2 ;
|
||||
// WatchdogTicks = ((TimerPeriod * 100 * SP805_CLOCK_FREQUENCY) / 1GHz);
|
||||
//
|
||||
// i.e.:
|
||||
//
|
||||
// WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 20 MHz ;
|
||||
// WatchdogTicks = (TimerPeriod * SP805_CLOCK_FREQUENCY) / 10 MHz ;
|
||||
|
||||
Ticks64bit = DivU64x32(MultU64x32(TimerPeriod, (UINTN)PcdGet32(PcdSP805WatchdogClockFrequencyInHz)), 20000000);
|
||||
Ticks64bit = MultU64x32 (TimerPeriod, PcdGet32 (PcdSP805WatchdogClockFrequencyInHz));
|
||||
Ticks64bit = DivU64x32 (Ticks64bit, 10 * 1000 * 1000);
|
||||
|
||||
// The registers in the SP805 are only 32 bits
|
||||
if(Ticks64bit > (UINT64)0xFFFFFFFF) {
|
||||
if (Ticks64bit > MAX_UINT32) {
|
||||
// We could load the watchdog with the maximum supported value but
|
||||
// if a smaller value was requested, this could have the watchdog
|
||||
// triggering before it was intended.
|
||||
@ -230,9 +269,12 @@ SP805SetTimerPeriod (
|
||||
SP805Start ();
|
||||
}
|
||||
|
||||
mTimerPeriod = TimerPeriod;
|
||||
|
||||
EXIT:
|
||||
// Ensure the watchdog is locked before exiting.
|
||||
SP805Lock ();
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
@ -251,34 +293,20 @@ SP805SetTimerPeriod (
|
||||
@retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SP805GetTimerPeriod (
|
||||
IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
OUT UINT64 *TimerPeriod
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
UINT64 ReturnValue;
|
||||
|
||||
if (TimerPeriod == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// Check if the watchdog is stopped
|
||||
if ( (MmioRead32(SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_INTEN) == 0 ) {
|
||||
// It is stopped, so return zero.
|
||||
ReturnValue = 0;
|
||||
} else {
|
||||
// Convert the Watchdog ticks into TimerPeriod
|
||||
// Ensure 64bit arithmetic throughout because the Watchdog ticks may already
|
||||
// be at the maximum 32 bit value and we still need to multiply that by 600.
|
||||
ReturnValue = MultU64x32( MmioRead32(SP805_WDOG_LOAD_REG), 600 );
|
||||
}
|
||||
|
||||
*TimerPeriod = ReturnValue;
|
||||
|
||||
return Status;
|
||||
*TimerPeriod = mTimerPeriod;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -313,10 +341,10 @@ SP805GetTimerPeriod (
|
||||
Retrieves the period of the timer interrupt in 100 nS units.
|
||||
|
||||
**/
|
||||
EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {
|
||||
(EFI_WATCHDOG_TIMER_REGISTER_HANDLER) SP805RegisterHandler,
|
||||
(EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) SP805SetTimerPeriod,
|
||||
(EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) SP805GetTimerPeriod
|
||||
STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {
|
||||
SP805RegisterHandler,
|
||||
SP805SetTimerPeriod,
|
||||
SP805GetTimerPeriod
|
||||
};
|
||||
|
||||
/**
|
||||
@ -340,6 +368,11 @@ SP805Initialize (
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE Handle;
|
||||
|
||||
// Find the interrupt controller protocol. ASSERT if not found.
|
||||
Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL,
|
||||
(VOID **)&mInterrupt);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
// Unlock access to the SP805 registers
|
||||
SP805Unlock ();
|
||||
|
||||
@ -347,13 +380,31 @@ SP805Initialize (
|
||||
SP805Stop ();
|
||||
|
||||
// Set the watchdog to reset the board when triggered
|
||||
// This is a last resort in case the interrupt handler fails
|
||||
if ((MmioRead32 (SP805_WDOG_CONTROL_REG) & SP805_WDOG_CTRL_RESEN) == 0) {
|
||||
MmioOr32 (SP805_WDOG_CONTROL_REG, SP805_WDOG_CTRL_RESEN);
|
||||
}
|
||||
|
||||
// Clear any pending interrupts
|
||||
MmioWrite32 (SP805_WDOG_INT_CLR_REG, 0); // write of any value clears the irq
|
||||
|
||||
// Prohibit any rogue access to SP805 registers
|
||||
SP805Lock ();
|
||||
|
||||
if (PcdGet32 (PcdSP805WatchdogInterrupt) > 0) {
|
||||
Status = mInterrupt->RegisterInterruptSource (mInterrupt,
|
||||
PcdGet32 (PcdSP805WatchdogInterrupt),
|
||||
SP805InterruptHandler);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: failed to register watchdog interrupt - %r\n",
|
||||
__FUNCTION__, Status));
|
||||
return Status;
|
||||
}
|
||||
} else {
|
||||
DEBUG ((DEBUG_WARN, "%a: no interrupt specified, running in RESET mode only\n",
|
||||
__FUNCTION__));
|
||||
}
|
||||
|
||||
//
|
||||
// Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.
|
||||
// This will avoid conflicts with the universal watchdog
|
||||
@ -361,7 +412,8 @@ SP805Initialize (
|
||||
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
|
||||
|
||||
// Register for an ExitBootServicesEvent
|
||||
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
|
||||
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY,
|
||||
ExitBootServicesEvent, NULL, &mEfiExitBootServicesEvent);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto EXIT;
|
||||
@ -371,7 +423,7 @@ SP805Initialize (
|
||||
Handle = NULL;
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Handle,
|
||||
&gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,
|
||||
&gEfiWatchdogTimerArchProtocolGuid, &mWatchdogTimer,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
@ -380,9 +432,6 @@ SP805Initialize (
|
||||
}
|
||||
|
||||
EXIT:
|
||||
if(EFI_ERROR(Status)) {
|
||||
// The watchdog failed to initialize
|
||||
ASSERT(FALSE);
|
||||
}
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
return Status;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/** @file
|
||||
*
|
||||
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
|
||||
* Copyright (c) 2018, Linaro Limited. All rights reserved.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are licensed and made available under the terms and conditions of the BSD License
|
||||
@ -18,25 +19,21 @@
|
||||
FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
ENTRY_POINT = SP805Initialize
|
||||
|
||||
[Sources.common]
|
||||
SP805Watchdog.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
EmbeddedPkg/EmbeddedPkg.dec
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmPlatformPkg/ArmPlatformPkg.dec
|
||||
EmbeddedPkg/EmbeddedPkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
BaseMemoryLib
|
||||
DebugLib
|
||||
IoLib
|
||||
PcdLib
|
||||
UefiLib
|
||||
UefiBootServicesTableLib
|
||||
UefiDriverEntryPoint
|
||||
UefiRuntimeServicesTableLib
|
||||
@ -44,9 +41,11 @@
|
||||
[Pcd]
|
||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogBase
|
||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogClockFrequencyInHz
|
||||
gArmPlatformTokenSpaceGuid.PcdSP805WatchdogInterrupt
|
||||
|
||||
[Protocols]
|
||||
gEfiWatchdogTimerArchProtocolGuid
|
||||
gHardwareInterruptProtocolGuid ## ALWAYS_CONSUMES
|
||||
gEfiWatchdogTimerArchProtocolGuid ## ALWAYS_PRODUCES
|
||||
|
||||
[Depex]
|
||||
TRUE
|
||||
gHardwareInterruptProtocolGuid
|
||||
|
@ -20,7 +20,6 @@ typedef struct {
|
||||
UINTN RegionBaseAddress; // Start address of one single region
|
||||
UINTN Size;
|
||||
UINTN BlockSize;
|
||||
EFI_GUID Guid;
|
||||
} NOR_FLASH_DESCRIPTION;
|
||||
|
||||
EFI_STATUS
|
||||
|
@ -48,7 +48,7 @@ SerialPortInitialize (
|
||||
StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits);
|
||||
|
||||
return PL011UartInitializePort (
|
||||
(UINTN)FixedPcdGet64 (PcdSerialRegisterBase),
|
||||
(UINTN)PcdGet64 (PcdSerialRegisterBase),
|
||||
PL011UartClockGetFreq(),
|
||||
&BaudRate,
|
||||
&ReceiveFifoDepth,
|
||||
@ -75,7 +75,7 @@ SerialPortWrite (
|
||||
IN UINTN NumberOfBytes
|
||||
)
|
||||
{
|
||||
return PL011UartWrite ((UINTN)FixedPcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
|
||||
return PL011UartWrite ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +95,7 @@ SerialPortRead (
|
||||
IN UINTN NumberOfBytes
|
||||
)
|
||||
{
|
||||
return PL011UartRead ((UINTN)FixedPcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
|
||||
return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +111,7 @@ SerialPortPoll (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return PL011UartPoll ((UINTN)FixedPcdGet64 (PcdSerialRegisterBase));
|
||||
return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
|
||||
}
|
||||
/**
|
||||
Set new attributes to PL011.
|
||||
@ -156,7 +156,7 @@ SerialPortSetAttributes (
|
||||
)
|
||||
{
|
||||
return PL011UartInitializePort (
|
||||
(UINTN)FixedPcdGet64 (PcdSerialRegisterBase),
|
||||
(UINTN)PcdGet64 (PcdSerialRegisterBase),
|
||||
PL011UartClockGetFreq(),
|
||||
BaudRate,
|
||||
ReceiveFifoDepth,
|
||||
@ -198,7 +198,7 @@ SerialPortSetControl (
|
||||
IN UINT32 Control
|
||||
)
|
||||
{
|
||||
return PL011UartSetControl ((UINTN)FixedPcdGet64 (PcdSerialRegisterBase), Control);
|
||||
return PL011UartSetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -239,5 +239,5 @@ SerialPortGetControl (
|
||||
OUT UINT32 *Control
|
||||
)
|
||||
{
|
||||
return PL011UartGetControl ((UINTN)FixedPcdGet64 (PcdSerialRegisterBase), Control);
|
||||
return PL011UartGetControl ((UINTN)PcdGet64 (PcdSerialRegisterBase), Control);
|
||||
}
|
||||
|
@ -36,8 +36,10 @@
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
ArmPlatformPkg/ArmPlatformPkg.dec
|
||||
|
||||
[FixedPcd]
|
||||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
|
||||
|
||||
[FixedPcd]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits
|
||||
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
|
||||
|
@ -105,12 +105,12 @@ InitializeMemory (
|
||||
|
||||
// Ensure PcdSystemMemorySize has been set
|
||||
ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
|
||||
ASSERT (PcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ADDRESS);
|
||||
ASSERT (PcdGet64 (PcdSystemMemoryBase) < (UINT64)MAX_ALLOC_ADDRESS);
|
||||
|
||||
SystemMemoryBase = (UINTN)PcdGet64 (PcdSystemMemoryBase);
|
||||
SystemMemoryTop = SystemMemoryBase + PcdGet64 (PcdSystemMemorySize);
|
||||
if (SystemMemoryTop - 1 > MAX_ADDRESS) {
|
||||
SystemMemoryTop = (UINT64)MAX_ADDRESS + 1;
|
||||
if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {
|
||||
SystemMemoryTop = (UINT64)MAX_ALLOC_ADDRESS + 1;
|
||||
}
|
||||
FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress);
|
||||
FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize);
|
||||
|
@ -46,8 +46,5 @@
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
gArmTokenSpaceGuid.PcdFvSize
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize
|
||||
|
||||
[depex]
|
||||
TRUE
|
||||
|
@ -57,9 +57,6 @@
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
gArmTokenSpaceGuid.PcdFvSize
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize
|
||||
|
||||
[Depex]
|
||||
TRUE
|
||||
|
||||
|
@ -76,6 +76,9 @@ _PrepareArguments:
|
||||
// Ensure we're jumping to FV version of the code (not boot remapped alias)
|
||||
ldr x3, =ASM_PFX(CEntryPoint)
|
||||
|
||||
// Set the frame pointer to NULL so any backtraces terminate here
|
||||
mov x29, xzr
|
||||
|
||||
// Jump to PrePeiCore C code
|
||||
// x0 = mp_id
|
||||
// x1 = pei_core_address
|
||||
|
@ -109,6 +109,9 @@ _PrepareArguments:
|
||||
// Ensure we're jumping to FV version of the code (not boot remapped alias)
|
||||
ldr x4, =ASM_PFX(CEntryPoint)
|
||||
|
||||
// Set the frame pointer to NULL so any backtraces terminate here
|
||||
mov x29, xzr
|
||||
|
||||
// Jump to PrePiCore C code
|
||||
// x0 = MpId
|
||||
// x1 = UefiMemoryBase
|
||||
|
@ -97,7 +97,6 @@
|
||||
|
||||
gArmPlatformTokenSpaceGuid.PcdCoreCount
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
|
||||
|
@ -90,7 +90,6 @@
|
||||
|
||||
gArmPlatformTokenSpaceGuid.PcdCoreCount
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
|
||||
|
@ -115,7 +115,7 @@ PrePiMain (
|
||||
BuildStackHob (StacksBase, StacksSize);
|
||||
|
||||
//TODO: Call CpuPei as a library
|
||||
BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
|
||||
BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
|
||||
|
||||
if (ArmIsMpCore ()) {
|
||||
// Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
|
||||
|
@ -80,9 +80,7 @@
|
||||
DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
|
||||
UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
|
||||
IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf
|
||||
!if $(NETWORK_IP6_ENABLE) == TRUE
|
||||
TcpIoLib|MdeModulePkg/Library/DxeTcpIoLib/DxeTcpIoLib.inf
|
||||
!endif
|
||||
!if $(HTTP_BOOT_ENABLE) == TRUE
|
||||
HttpLib|MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.inf
|
||||
!endif
|
||||
@ -149,11 +147,9 @@
|
||||
#
|
||||
# CryptoPkg libraries needed by multiple firmware features
|
||||
#
|
||||
!if ($(SECURE_BOOT_ENABLE) == TRUE) || ($(NETWORK_IP6_ENABLE) == TRUE)
|
||||
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
|
||||
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
|
||||
BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
|
||||
!endif
|
||||
|
||||
#
|
||||
# Secure Boot dependencies
|
||||
@ -388,9 +384,6 @@
|
||||
#
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack|TRUE
|
||||
|
||||
[PcdsFixedAtBuild.ARM]
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|40
|
||||
|
||||
[Components.common]
|
||||
#
|
||||
# Ramdisk support
|
||||
|
@ -143,10 +143,6 @@
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
|
||||
|
||||
[PcdsFixedAtBuild.AARCH64]
|
||||
# KVM limits it IPA space to 40 bits (1 TB), so there is no need to
|
||||
# support anything bigger, even if the host hardware does
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|40
|
||||
|
||||
# Clearing BIT0 in this PCD prevents installing a 32-bit SMBIOS entry point,
|
||||
# if the entry point version is >= 3.0. AARCH64 OSes cannot assume the
|
||||
# presence of the 32-bit entry point anyway (because many AARCH64 systems
|
||||
@ -346,18 +342,14 @@
|
||||
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
|
||||
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
|
||||
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
|
||||
NetworkPkg/TcpDxe/TcpDxe.inf
|
||||
NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
NetworkPkg/IScsiDxe/IScsiDxe.inf
|
||||
!if $(NETWORK_IP6_ENABLE) == TRUE
|
||||
NetworkPkg/Ip6Dxe/Ip6Dxe.inf
|
||||
NetworkPkg/TcpDxe/TcpDxe.inf
|
||||
NetworkPkg/Udp6Dxe/Udp6Dxe.inf
|
||||
NetworkPkg/Dhcp6Dxe/Dhcp6Dxe.inf
|
||||
NetworkPkg/Mtftp6Dxe/Mtftp6Dxe.inf
|
||||
NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
NetworkPkg/IScsiDxe/IScsiDxe.inf
|
||||
!else
|
||||
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
|
||||
MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf
|
||||
!endif
|
||||
!if $(HTTP_BOOT_ENABLE) == TRUE
|
||||
NetworkPkg/DnsDxe/DnsDxe.inf
|
||||
|
@ -126,18 +126,14 @@ READ_LOCK_STATUS = TRUE
|
||||
INF MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
|
||||
INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
|
||||
INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
|
||||
INF NetworkPkg/TcpDxe/TcpDxe.inf
|
||||
INF NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
INF NetworkPkg/IScsiDxe/IScsiDxe.inf
|
||||
!if $(NETWORK_IP6_ENABLE) == TRUE
|
||||
INF NetworkPkg/Ip6Dxe/Ip6Dxe.inf
|
||||
INF NetworkPkg/TcpDxe/TcpDxe.inf
|
||||
INF NetworkPkg/Udp6Dxe/Udp6Dxe.inf
|
||||
INF NetworkPkg/Dhcp6Dxe/Dhcp6Dxe.inf
|
||||
INF NetworkPkg/Mtftp6Dxe/Mtftp6Dxe.inf
|
||||
INF NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
INF NetworkPkg/IScsiDxe/IScsiDxe.inf
|
||||
!else
|
||||
INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
|
||||
INF MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
INF MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf
|
||||
!endif
|
||||
!if $(HTTP_BOOT_ENABLE) == TRUE
|
||||
INF NetworkPkg/DnsDxe/DnsDxe.inf
|
||||
|
@ -68,11 +68,14 @@
|
||||
[LibraryClasses.common.UEFI_DRIVER]
|
||||
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
|
||||
|
||||
[BuildOptions.ARM.EDKII.SEC, BuildOptions.ARM.EDKII.BASE]
|
||||
# Avoid MOVT/MOVW instruction pairs in code that may end up in the PIE
|
||||
# executable we build for the relocatable PrePi. They are not runtime
|
||||
# relocatable in ELF.
|
||||
*_CLANG35_*_CC_FLAGS = -mno-movt
|
||||
[BuildOptions.common.EDKII.SEC, BuildOptions.common.EDKII.BASE]
|
||||
#
|
||||
# CLANG38 with LTO support enabled uses the GNU GOLD linker, which insists
|
||||
# on emitting GOT based symbol references when running in shared mode, unless
|
||||
# we override visibility to 'hidden' in all modules that make up the PrePi
|
||||
# build.
|
||||
#
|
||||
GCC:*_CLANG38_*_CC_FLAGS = -include $(WORKSPACE)/ArmVirtPkg/Include/Platform/Hidden.h
|
||||
|
||||
################################################################################
|
||||
#
|
||||
@ -130,6 +133,15 @@
|
||||
gEfiNetworkPkgTokenSpaceGuid.PcdAllowHttpConnections|TRUE
|
||||
!endif
|
||||
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
|
||||
|
||||
#
|
||||
# The maximum physical I/O addressability of the processor, set with
|
||||
# BuildCpuHob().
|
||||
#
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
|
||||
|
||||
[PcdsPatchableInModule.common]
|
||||
#
|
||||
# This will be overridden in the code
|
||||
@ -146,21 +158,6 @@
|
||||
gArmTokenSpaceGuid.PcdFdBaseAddress|0x0
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress|0x0
|
||||
|
||||
[PcdsFixedAtBuild.AARCH64]
|
||||
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
|
||||
|
||||
#
|
||||
# The maximum physical I/O addressability of the processor, set with
|
||||
# BuildCpuHob().
|
||||
#
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
|
||||
|
||||
# KVM limits it IPA space to 40 bits (1 TB), so there is no need to
|
||||
# support anything bigger, even if the host hardware does
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize|40
|
||||
|
||||
[PcdsDynamicDefault.common]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3
|
||||
|
||||
@ -335,18 +332,14 @@
|
||||
MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigDxe.inf
|
||||
MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
|
||||
MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
|
||||
NetworkPkg/TcpDxe/TcpDxe.inf
|
||||
NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
NetworkPkg/IScsiDxe/IScsiDxe.inf
|
||||
!if $(NETWORK_IP6_ENABLE) == TRUE
|
||||
NetworkPkg/Ip6Dxe/Ip6Dxe.inf
|
||||
NetworkPkg/TcpDxe/TcpDxe.inf
|
||||
NetworkPkg/Udp6Dxe/Udp6Dxe.inf
|
||||
NetworkPkg/Dhcp6Dxe/Dhcp6Dxe.inf
|
||||
NetworkPkg/Mtftp6Dxe/Mtftp6Dxe.inf
|
||||
NetworkPkg/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
NetworkPkg/IScsiDxe/IScsiDxe.inf
|
||||
!else
|
||||
MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
|
||||
MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf
|
||||
MdeModulePkg/Universal/Network/IScsiDxe/IScsiDxe.inf
|
||||
!endif
|
||||
!if $(HTTP_BOOT_ENABLE) == TRUE
|
||||
NetworkPkg/DnsDxe/DnsDxe.inf
|
||||
|
@ -57,11 +57,14 @@
|
||||
[LibraryClasses.common.UEFI_DRIVER]
|
||||
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
|
||||
|
||||
[BuildOptions.ARM.EDKII.SEC, BuildOptions.ARM.EDKII.BASE]
|
||||
# Avoid MOVT/MOVW instruction pairs in code that may end up in the PIE
|
||||
# executable we build for the relocatable PrePi. They are not runtime
|
||||
# relocatable in ELF.
|
||||
*_CLANG35_*_CC_FLAGS = -mno-movt
|
||||
[BuildOptions.common.EDKII.SEC, BuildOptions.common.EDKII.BASE]
|
||||
#
|
||||
# CLANG38 with LTO support enabled uses the GNU GOLD linker, which insists
|
||||
# on emitting GOT based symbol references when running in shared mode, unless
|
||||
# we override visibility to 'hidden' in all modules that make up the PrePi
|
||||
# build.
|
||||
#
|
||||
GCC:*_CLANG38_*_CC_FLAGS = -include $(WORKSPACE)/ArmVirtPkg/Include/Platform/Hidden.h
|
||||
|
||||
################################################################################
|
||||
#
|
||||
|
@ -78,6 +78,33 @@ SetNodeProperty (
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
STATIC
|
||||
BOOLEAN
|
||||
IsNodeEnabled (
|
||||
INT32 Node
|
||||
)
|
||||
{
|
||||
CONST CHAR8 *NodeStatus;
|
||||
INT32 Len;
|
||||
|
||||
//
|
||||
// A missing status property implies 'ok' so ignore any errors that
|
||||
// may occur here. If the status property is present, check whether
|
||||
// it is set to 'ok' or 'okay', anything else is treated as 'disabled'.
|
||||
//
|
||||
NodeStatus = fdt_getprop (mDeviceTreeBase, Node, "status", &Len);
|
||||
if (NodeStatus == NULL) {
|
||||
return TRUE;
|
||||
}
|
||||
if (Len >= 5 && AsciiStrCmp (NodeStatus, "okay") == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
if (Len >= 3 && AsciiStrCmp (NodeStatus, "ok") == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@ -101,6 +128,10 @@ FindNextCompatibleNode (
|
||||
break;
|
||||
}
|
||||
|
||||
if (!IsNodeEnabled (Next)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Type = fdt_getprop (mDeviceTreeBase, Next, "compatible", &Len);
|
||||
if (Type == NULL) {
|
||||
continue;
|
||||
@ -210,7 +241,6 @@ FindNextMemoryNodeReg (
|
||||
{
|
||||
INT32 Prev, Next;
|
||||
CONST CHAR8 *DeviceType;
|
||||
CONST CHAR8 *NodeStatus;
|
||||
INT32 Len;
|
||||
EFI_STATUS Status;
|
||||
|
||||
@ -223,10 +253,8 @@ FindNextMemoryNodeReg (
|
||||
break;
|
||||
}
|
||||
|
||||
NodeStatus = fdt_getprop (mDeviceTreeBase, Next, "status", &Len);
|
||||
if (NodeStatus != NULL && AsciiStrCmp (NodeStatus, "okay") != 0) {
|
||||
DEBUG ((DEBUG_WARN, "%a: ignoring memory node with status \"%a\"\n",
|
||||
__FUNCTION__, NodeStatus));
|
||||
if (!IsNodeEnabled (Next)) {
|
||||
DEBUG ((DEBUG_WARN, "%a: ignoring disabled memory node\n", __FUNCTION__));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
28
ArmVirtPkg/Include/Platform/Hidden.h
Normal file
28
ArmVirtPkg/Include/Platform/Hidden.h
Normal file
@ -0,0 +1,28 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2018, Linaro Limited. All rights reserved.
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef __PLATFORM_HIDDEN_H
|
||||
#define __PLATFORM_HIDDEN_H
|
||||
|
||||
//
|
||||
// Setting the GCC -fvisibility=hidden command line option is not quite the same
|
||||
// as setting the pragma below: the former only affects definitions, whereas the
|
||||
// pragma affects extern declarations as well. So if we want to ensure that no
|
||||
// GOT indirected symbol references are emitted, we need to use the pragma, or
|
||||
// GOT based cross object references could be emitted, e.g., in libraries, and
|
||||
// these cannot be relaxed to ordinary symbol references at link time.
|
||||
//
|
||||
#pragma GCC visibility push (hidden)
|
||||
|
||||
#endif
|
@ -75,18 +75,18 @@ MemoryPeim (
|
||||
SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) +
|
||||
PcdGet64 (PcdSystemMemorySize);
|
||||
|
||||
if (SystemMemoryTop - 1 > MAX_ADDRESS) {
|
||||
if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {
|
||||
BuildResourceDescriptorHob (
|
||||
EFI_RESOURCE_SYSTEM_MEMORY,
|
||||
ResourceAttributes,
|
||||
PcdGet64 (PcdSystemMemoryBase),
|
||||
(UINT64)MAX_ADDRESS - PcdGet64 (PcdSystemMemoryBase) + 1
|
||||
(UINT64)MAX_ALLOC_ADDRESS - PcdGet64 (PcdSystemMemoryBase) + 1
|
||||
);
|
||||
BuildResourceDescriptorHob (
|
||||
EFI_RESOURCE_SYSTEM_MEMORY,
|
||||
ResourceAttributes,
|
||||
(UINT64)MAX_ADDRESS + 1,
|
||||
SystemMemoryTop - MAX_ADDRESS - 1
|
||||
(UINT64)MAX_ALLOC_ADDRESS + 1,
|
||||
SystemMemoryTop - MAX_ALLOC_ADDRESS - 1
|
||||
);
|
||||
} else {
|
||||
BuildResourceDescriptorHob (
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <Library/PciHostBridgeLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/DevicePathLib.h>
|
||||
#include <Library/DxeServicesTableLib.h>
|
||||
#include <Library/MemoryAllocationLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
@ -82,6 +83,33 @@ typedef struct {
|
||||
#define DTB_PCI_HOST_RANGE_IO BIT24
|
||||
#define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
MapGcdMmioSpace (
|
||||
IN UINT64 Base,
|
||||
IN UINT64 Size
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo, Base, Size,
|
||||
EFI_MEMORY_UC);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR,
|
||||
"%a: failed to add GCD memory space for region [0x%Lx+0x%Lx)\n",
|
||||
__FUNCTION__, Base, Size));
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = gDS->SetMemorySpaceAttributes (Base, Size, EFI_MEMORY_UC);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR,
|
||||
"%a: failed to set memory space attributes for region [0x%Lx+0x%Lx)\n",
|
||||
__FUNCTION__, Base, Size));
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
ProcessPciHost (
|
||||
@ -266,7 +294,23 @@ ProcessPciHost (
|
||||
"Io[0x%Lx+0x%Lx)@0x%Lx Mem32[0x%Lx+0x%Lx)@0x0 Mem64[0x%Lx+0x%Lx)@0x0\n",
|
||||
__FUNCTION__, ConfigBase, ConfigSize, *BusMin, *BusMax, *IoBase, *IoSize,
|
||||
IoTranslation, *Mmio32Base, *Mmio32Size, *Mmio64Base, *Mmio64Size));
|
||||
return EFI_SUCCESS;
|
||||
|
||||
// Map the ECAM space in the GCD memory map
|
||||
Status = MapGcdMmioSpace (ConfigBase, ConfigSize);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Map the MMIO window that provides I/O access - the PCI host bridge code
|
||||
// is not aware of this translation and so it will only map the I/O view
|
||||
// in the GCD I/O map.
|
||||
//
|
||||
Status = MapGcdMmioSpace (*IoBase + IoTranslation, *IoSize);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
STATIC PCI_ROOT_BRIDGE mRootBridge;
|
||||
|
@ -42,6 +42,7 @@
|
||||
[LibraryClasses]
|
||||
DebugLib
|
||||
DevicePathLib
|
||||
DxeServicesTableLib
|
||||
MemoryAllocationLib
|
||||
PciPcdProducerLib
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/** @file
|
||||
|
||||
Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
|
||||
Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.<BR>
|
||||
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
@ -12,13 +12,16 @@
|
||||
|
||||
**/
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/NorFlashPlatformLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
|
||||
#include <Protocol/FdtClient.h>
|
||||
|
||||
#define QEMU_NOR_BLOCK_SIZE SIZE_256KB
|
||||
#define QEMU_NOR0_BASE 0x0
|
||||
#define QEMU_NOR0_SIZE SIZE_64MB
|
||||
#define QEMU_NOR1_BASE 0x04000000
|
||||
#define QEMU_NOR1_SIZE SIZE_64MB
|
||||
|
||||
#define MAX_FLASH_BANKS 4
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashPlatformInitialization (
|
||||
@ -28,21 +31,7 @@ NorFlashPlatformInitialization (
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {
|
||||
{
|
||||
QEMU_NOR0_BASE,
|
||||
QEMU_NOR0_BASE,
|
||||
QEMU_NOR0_SIZE,
|
||||
QEMU_NOR_BLOCK_SIZE,
|
||||
{0xF9B94AE2, 0x8BA6, 0x409B, {0x9D, 0x56, 0xB9, 0xB4, 0x17, 0xF5, 0x3C, 0xB3}}
|
||||
}, {
|
||||
QEMU_NOR1_BASE,
|
||||
QEMU_NOR1_BASE,
|
||||
QEMU_NOR1_SIZE,
|
||||
QEMU_NOR_BLOCK_SIZE,
|
||||
{0x8047DB4B, 0x7E9C, 0x4C0C, {0x8E, 0xBC, 0xDF, 0xBB, 0xAA, 0xCA, 0xCE, 0x8F}}
|
||||
}
|
||||
};
|
||||
NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS];
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashPlatformGetDevices (
|
||||
@ -50,7 +39,63 @@ NorFlashPlatformGetDevices (
|
||||
OUT UINT32 *Count
|
||||
)
|
||||
{
|
||||
FDT_CLIENT_PROTOCOL *FdtClient;
|
||||
INT32 Node;
|
||||
EFI_STATUS Status;
|
||||
EFI_STATUS FindNodeStatus;
|
||||
CONST UINT32 *Reg;
|
||||
UINT32 PropSize;
|
||||
UINT32 Num;
|
||||
UINT64 Base;
|
||||
UINT64 Size;
|
||||
|
||||
Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
|
||||
(VOID **)&FdtClient);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Num = 0;
|
||||
for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient,
|
||||
"cfi-flash", &Node);
|
||||
!EFI_ERROR (FindNodeStatus) && Num < MAX_FLASH_BANKS;
|
||||
FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient,
|
||||
"cfi-flash", Node, &Node)) {
|
||||
|
||||
Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",
|
||||
(CONST VOID **)&Reg, &PropSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n",
|
||||
__FUNCTION__, Status));
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0);
|
||||
|
||||
while (PropSize >= (4 * sizeof (UINT32)) && Num < MAX_FLASH_BANKS) {
|
||||
Base = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));
|
||||
Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));
|
||||
Reg += 4;
|
||||
|
||||
PropSize -= 4 * sizeof (UINT32);
|
||||
|
||||
//
|
||||
// Disregard any flash devices that overlap with the primary FV.
|
||||
// The firmware is not updatable from inside the guest anyway.
|
||||
//
|
||||
if ((PcdGet64 (PcdFvBaseAddress) + PcdGet32 (PcdFvSize) > Base) &&
|
||||
(Base + Size) > PcdGet64 (PcdFvBaseAddress)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base;
|
||||
mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base;
|
||||
mNorFlashDevices[Num].Size = (UINTN)Size;
|
||||
mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE;
|
||||
Num++;
|
||||
}
|
||||
}
|
||||
|
||||
*NorFlashDescriptions = mNorFlashDevices;
|
||||
*Count = ARRAY_SIZE (mNorFlashDevices);
|
||||
*Count = Num;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
@ -28,3 +28,20 @@
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
ArmPlatformPkg/ArmPlatformPkg.dec
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmVirtPkg/ArmVirtPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
UefiBootServicesTableLib
|
||||
|
||||
[Protocols]
|
||||
gFdtClientProtocolGuid ## CONSUMES
|
||||
|
||||
[Depex]
|
||||
gFdtClientProtocolGuid
|
||||
|
||||
[Pcd]
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
gArmTokenSpaceGuid.PcdFvSize
|
||||
|
@ -1,39 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
||||
# Copyright (c) 2016-2017, Linaro Limited. All rights reserved.
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
|
||||
#include <AsmMacroIoLibV8.h>
|
||||
|
||||
//EFI_PHYSICAL_ADDRESS
|
||||
//GetPhysAddrTop (
|
||||
// VOID
|
||||
// );
|
||||
ASM_FUNC(ArmGetPhysAddrTop)
|
||||
mrs x0, id_aa64mmfr0_el1
|
||||
adr x1, .LPARanges
|
||||
and x0, x0, #7
|
||||
ldrb w1, [x1, x0]
|
||||
mov x0, #1
|
||||
lsl x0, x0, x1
|
||||
ret
|
||||
|
||||
//
|
||||
// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
|
||||
// physical address space support on this CPU:
|
||||
// 0 == 32 bits, 1 == 36 bits, etc etc
|
||||
// 6 and 7 are reserved
|
||||
//
|
||||
.LPARanges:
|
||||
.byte 32, 36, 40, 42, 44, 48, -1, -1
|
||||
|
||||
ASM_FUNCTION_REMOVE_IF_UNREFERENCED
|
@ -1,24 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
||||
# Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
|
||||
#include <AsmMacroIoLib.h>
|
||||
|
||||
//EFI_PHYSICAL_ADDRESS
|
||||
//GetPhysAddrTop (
|
||||
// VOID
|
||||
// );
|
||||
ASM_FUNC(ArmGetPhysAddrTop)
|
||||
mov r0, #0x00000000
|
||||
mov r1, #0x10000
|
||||
bx lr
|
@ -21,10 +21,14 @@
|
||||
// Number of Virtual Memory Map Descriptors
|
||||
#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
|
||||
|
||||
EFI_PHYSICAL_ADDRESS
|
||||
ArmGetPhysAddrTop (
|
||||
VOID
|
||||
);
|
||||
//
|
||||
// mach-virt's core peripherals such as the UART, the GIC and the RTC are
|
||||
// all mapped in the 'miscellaneous device I/O' region, which we just map
|
||||
// in its entirety rather than device by device. Note that it does not
|
||||
// cover any of the NOR flash banks or PCI resource windows.
|
||||
//
|
||||
#define MACH_VIRT_PERIPH_BASE 0x08000000
|
||||
#define MACH_VIRT_PERIPH_SIZE SIZE_128MB
|
||||
|
||||
/**
|
||||
Return the Virtual Memory Map of your platform
|
||||
@ -45,7 +49,6 @@ ArmVirtGetMemoryMap (
|
||||
)
|
||||
{
|
||||
ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
|
||||
UINT64 TopOfMemory;
|
||||
|
||||
ASSERT (VirtualMemoryMap != NULL);
|
||||
|
||||
@ -72,29 +75,20 @@ ArmVirtGetMemoryMap (
|
||||
VirtualMemoryTable[0].VirtualBase,
|
||||
VirtualMemoryTable[0].Length));
|
||||
|
||||
// Peripheral space before DRAM
|
||||
VirtualMemoryTable[1].PhysicalBase = 0x0;
|
||||
VirtualMemoryTable[1].VirtualBase = 0x0;
|
||||
VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;
|
||||
// Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
|
||||
VirtualMemoryTable[1].PhysicalBase = MACH_VIRT_PERIPH_BASE;
|
||||
VirtualMemoryTable[1].VirtualBase = MACH_VIRT_PERIPH_BASE;
|
||||
VirtualMemoryTable[1].Length = MACH_VIRT_PERIPH_SIZE;
|
||||
VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
|
||||
|
||||
// Peripheral space after DRAM
|
||||
TopOfMemory = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),
|
||||
ArmGetPhysAddrTop ());
|
||||
VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;
|
||||
// Map the FV region as normal executable memory
|
||||
VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
|
||||
VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;
|
||||
VirtualMemoryTable[2].Length = TopOfMemory -
|
||||
VirtualMemoryTable[2].PhysicalBase;
|
||||
VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
|
||||
|
||||
// Remap the FD region as normal executable memory
|
||||
VirtualMemoryTable[3].PhysicalBase = PcdGet64 (PcdFdBaseAddress);
|
||||
VirtualMemoryTable[3].VirtualBase = VirtualMemoryTable[3].PhysicalBase;
|
||||
VirtualMemoryTable[3].Length = FixedPcdGet32 (PcdFdSize);
|
||||
VirtualMemoryTable[3].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
|
||||
VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFvSize);
|
||||
VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
|
||||
|
||||
// End of Table
|
||||
ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
|
||||
ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
|
||||
|
||||
*VirtualMemoryMap = VirtualMemoryTable;
|
||||
}
|
||||
|
@ -24,12 +24,6 @@
|
||||
[Sources]
|
||||
QemuVirtMemInfoLib.c
|
||||
|
||||
[Sources.ARM]
|
||||
Arm/PhysAddrTop.S
|
||||
|
||||
[Sources.AARCH64]
|
||||
AArch64/PhysAddrTop.S
|
||||
|
||||
[Packages]
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmVirtPkg/ArmVirtPkg.dec
|
||||
@ -45,10 +39,9 @@
|
||||
PcdLib
|
||||
|
||||
[Pcd]
|
||||
gArmTokenSpaceGuid.PcdFdBaseAddress
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
gArmTokenSpaceGuid.PcdSystemMemoryBase
|
||||
gArmTokenSpaceGuid.PcdSystemMemorySize
|
||||
|
||||
[FixedPcd]
|
||||
gArmTokenSpaceGuid.PcdFdSize
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
gArmTokenSpaceGuid.PcdFvSize
|
||||
|
@ -26,12 +26,6 @@
|
||||
QemuVirtMemInfoLib.c
|
||||
QemuVirtMemInfoPeiLibConstructor.c
|
||||
|
||||
[Sources.ARM]
|
||||
Arm/PhysAddrTop.S
|
||||
|
||||
[Sources.AARCH64]
|
||||
AArch64/PhysAddrTop.S
|
||||
|
||||
[Packages]
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmVirtPkg/ArmVirtPkg.dec
|
||||
@ -49,10 +43,11 @@
|
||||
|
||||
[Pcd]
|
||||
gArmTokenSpaceGuid.PcdFdBaseAddress
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
gArmTokenSpaceGuid.PcdSystemMemoryBase
|
||||
gArmTokenSpaceGuid.PcdSystemMemorySize
|
||||
|
||||
[FixedPcd]
|
||||
gArmTokenSpaceGuid.PcdFdSize
|
||||
gArmTokenSpaceGuid.PcdFvSize
|
||||
gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
|
@ -1,39 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
||||
# Copyright (c) 2016-2017, Linaro Limited. All rights reserved.
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
|
||||
#include <AsmMacroIoLibV8.h>
|
||||
|
||||
//EFI_PHYSICAL_ADDRESS
|
||||
//GetPhysAddrTop (
|
||||
// VOID
|
||||
// );
|
||||
ASM_FUNC(ArmGetPhysAddrTop)
|
||||
mrs x0, id_aa64mmfr0_el1
|
||||
adr x1, .LPARanges
|
||||
and x0, x0, #7
|
||||
ldrb w1, [x1, x0]
|
||||
mov x0, #1
|
||||
lsl x0, x0, x1
|
||||
ret
|
||||
|
||||
//
|
||||
// Bits 0..2 of the AA64MFR0_EL1 system register encode the size of the
|
||||
// physical address space support on this CPU:
|
||||
// 0 == 32 bits, 1 == 36 bits, etc etc
|
||||
// 6 and 7 are reserved
|
||||
//
|
||||
.LPARanges:
|
||||
.byte 32, 36, 40, 42, 44, 48, -1, -1
|
||||
|
||||
ASM_FUNCTION_REMOVE_IF_UNREFERENCED
|
@ -1,24 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
||||
# Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
#
|
||||
|
||||
#include <AsmMacroIoLib.h>
|
||||
|
||||
//EFI_PHYSICAL_ADDRESS
|
||||
//GetPhysAddrTop (
|
||||
// VOID
|
||||
// );
|
||||
ASM_FUNC(ArmGetPhysAddrTop)
|
||||
mov r0, #0x00000000
|
||||
mov r1, #0x10000
|
||||
bx lr
|
@ -14,15 +14,11 @@
|
||||
|
||||
#include <Base.h>
|
||||
#include <Library/ArmLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
|
||||
STATIC ARM_MEMORY_REGION_DESCRIPTOR mVirtualMemoryTable[2];
|
||||
|
||||
EFI_PHYSICAL_ADDRESS
|
||||
ArmGetPhysAddrTop (
|
||||
VOID
|
||||
);
|
||||
|
||||
/**
|
||||
Return the Virtual Memory Map of your platform
|
||||
|
||||
@ -42,8 +38,12 @@ ArmVirtGetMemoryMap (
|
||||
OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
|
||||
)
|
||||
{
|
||||
EFI_PHYSICAL_ADDRESS TopOfAddressSpace;
|
||||
|
||||
ASSERT (VirtualMemoryMap != NULL);
|
||||
|
||||
TopOfAddressSpace = LShiftU64 (1ULL, ArmGetPhysicalAddressBits ());
|
||||
|
||||
//
|
||||
// Map the entire physical memory space as cached. The only device
|
||||
// we care about is the GIC, which will be stage 2 mapped as a device
|
||||
@ -51,7 +51,7 @@ ArmVirtGetMemoryMap (
|
||||
//
|
||||
mVirtualMemoryTable[0].PhysicalBase = 0x0;
|
||||
mVirtualMemoryTable[0].VirtualBase = 0x0;
|
||||
mVirtualMemoryTable[0].Length = ArmGetPhysAddrTop ();
|
||||
mVirtualMemoryTable[0].Length = TopOfAddressSpace;
|
||||
mVirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
|
||||
|
||||
mVirtualMemoryTable[1].PhysicalBase = 0x0;
|
||||
|
@ -24,12 +24,6 @@
|
||||
[Sources]
|
||||
XenVirtMemInfoLib.c
|
||||
|
||||
[Sources.ARM]
|
||||
Arm/PhysAddrTop.S
|
||||
|
||||
[Sources.AARCH64]
|
||||
AArch64/PhysAddrTop.S
|
||||
|
||||
[Packages]
|
||||
ArmPkg/ArmPkg.dec
|
||||
ArmVirtPkg/ArmVirtPkg.dec
|
||||
@ -38,4 +32,5 @@
|
||||
|
||||
[LibraryClasses]
|
||||
ArmLib
|
||||
BaseLib
|
||||
DebugLib
|
||||
|
@ -121,6 +121,9 @@ _GetStackBase:
|
||||
mov x1, x21
|
||||
mov x2, x22
|
||||
|
||||
// Set the frame pointer to NULL so any backtraces terminate here
|
||||
mov x29, xzr
|
||||
|
||||
// Jump to PrePiCore C code
|
||||
// x0 = MpId
|
||||
// x1 = UefiMemoryBase
|
||||
|
@ -85,7 +85,6 @@
|
||||
|
||||
gArmPlatformTokenSpaceGuid.PcdCoreCount
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize
|
||||
gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize
|
||||
|
||||
gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
|
||||
@ -106,4 +105,4 @@
|
||||
gArmTokenSpaceGuid.PcdFvBaseAddress
|
||||
|
||||
[BuildOptions]
|
||||
GCC:*_*_*_DLINK_FLAGS = -pie -Wl,-T,$(MODULE_DIR)/Scripts/PrePi-PIE.lds
|
||||
GCC:*_*_*_DLINK_FLAGS = -shared -Wl,-Bsymbolic -Wl,-T,$(MODULE_DIR)/Scripts/PrePi-PIE.lds
|
||||
|
@ -80,7 +80,7 @@ PrePiMain (
|
||||
BuildStackHob (StacksBase, StacksSize);
|
||||
|
||||
//TODO: Call CpuPei as a library
|
||||
BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));
|
||||
BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
|
||||
|
||||
// Set the Boot Mode
|
||||
SetBootMode (BOOT_WITH_FULL_CONFIGURATION);
|
||||
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
|
||||
dir=$(dirname "$full_cmd")
|
||||
cmd=${full_cmd##*/}
|
||||
|
||||
if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
|
||||
then
|
||||
exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
|
||||
elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
|
||||
then
|
||||
if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
|
||||
then
|
||||
echo "BaseTools C Tool binary was not found ($cmd)"
|
||||
echo "You may need to run:"
|
||||
echo " make -C $EDK_TOOLS_PATH/Source/C"
|
||||
else
|
||||
exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
|
||||
fi
|
||||
elif [ -e "$dir/../../Source/C/bin/$cmd" ]
|
||||
then
|
||||
exec "$dir/../../Source/C/bin/$cmd" "$@"
|
||||
else
|
||||
echo "Unable to find the real '$cmd' to run"
|
||||
echo "This message was printed by"
|
||||
echo " $0"
|
||||
exit 127
|
||||
fi
|
||||
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
|
||||
dir=$(dirname "$full_cmd")
|
||||
cmd=${full_cmd##*/}
|
||||
|
||||
if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
|
||||
then
|
||||
exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
|
||||
elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
|
||||
then
|
||||
if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
|
||||
then
|
||||
echo "BaseTools C Tool binary was not found ($cmd)"
|
||||
echo "You may need to run:"
|
||||
echo " make -C $EDK_TOOLS_PATH/Source/C"
|
||||
else
|
||||
exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
|
||||
fi
|
||||
elif [ -e "$dir/../../Source/C/bin/$cmd" ]
|
||||
then
|
||||
exec "$dir/../../Source/C/bin/$cmd" "$@"
|
||||
else
|
||||
echo "Unable to find the real '$cmd' to run"
|
||||
echo "This message was printed by"
|
||||
echo " $0"
|
||||
exit 127
|
||||
fi
|
||||
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
|
||||
dir=$(dirname "$full_cmd")
|
||||
cmd=${full_cmd##*/}
|
||||
|
||||
if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
|
||||
then
|
||||
exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
|
||||
elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
|
||||
then
|
||||
if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
|
||||
then
|
||||
echo "BaseTools C Tool binary was not found ($cmd)"
|
||||
echo "You may need to run:"
|
||||
echo " make -C $EDK_TOOLS_PATH/Source/C"
|
||||
else
|
||||
exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
|
||||
fi
|
||||
elif [ -e "$dir/../../Source/C/bin/$cmd" ]
|
||||
then
|
||||
exec "$dir/../../Source/C/bin/$cmd" "$@"
|
||||
else
|
||||
echo "Unable to find the real '$cmd' to run"
|
||||
echo "This message was printed by"
|
||||
echo " $0"
|
||||
exit 127
|
||||
fi
|
||||
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
|
||||
dir=$(dirname "$full_cmd")
|
||||
cmd=${full_cmd##*/}
|
||||
|
||||
if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
|
||||
then
|
||||
exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
|
||||
elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
|
||||
then
|
||||
if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
|
||||
then
|
||||
echo "BaseTools C Tool binary was not found ($cmd)"
|
||||
echo "You may need to run:"
|
||||
echo " make -C $EDK_TOOLS_PATH/Source/C"
|
||||
else
|
||||
exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
|
||||
fi
|
||||
elif [ -e "$dir/../../Source/C/bin/$cmd" ]
|
||||
then
|
||||
exec "$dir/../../Source/C/bin/$cmd" "$@"
|
||||
else
|
||||
echo "Unable to find the real '$cmd' to run"
|
||||
echo "This message was printed by"
|
||||
echo " $0"
|
||||
exit 127
|
||||
fi
|
||||
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
|
||||
dir=$(dirname "$full_cmd")
|
||||
cmd=${full_cmd##*/}
|
||||
|
||||
if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
|
||||
then
|
||||
exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
|
||||
elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
|
||||
then
|
||||
if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
|
||||
then
|
||||
echo "BaseTools C Tool binary was not found ($cmd)"
|
||||
echo "You may need to run:"
|
||||
echo " make -C $EDK_TOOLS_PATH/Source/C"
|
||||
else
|
||||
exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
|
||||
fi
|
||||
elif [ -e "$dir/../../Source/C/bin/$cmd" ]
|
||||
then
|
||||
exec "$dir/../../Source/C/bin/$cmd" "$@"
|
||||
else
|
||||
echo "Unable to find the real '$cmd' to run"
|
||||
echo "This message was printed by"
|
||||
echo " $0"
|
||||
exit 127
|
||||
fi
|
||||
|
@ -62,6 +62,7 @@
|
||||
# $(BIN_DIR) Common directory for executable files
|
||||
# $(FV_DIR) Directory to store flash image files
|
||||
# $(INC) Search path of current module
|
||||
# $(NASM_INC) Search nasm file path of current module
|
||||
# $(INC_LIST) A file containing search pathes of current module
|
||||
# $(LIBS) Static library files of current module
|
||||
# $(<tool>_FLAGS) Tools flags of current module
|
||||
@ -225,7 +226,7 @@
|
||||
<Command>
|
||||
"$(PP)" $(PP_FLAGS) $(INC) ${src} > ${d_path}(+)${s_base}.i
|
||||
Trim --trim-long --source-code -o ${d_path}(+)${s_base}.iii ${d_path}(+)${s_base}.i
|
||||
"$(NASM)" -I${s_path}(+) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii
|
||||
"$(NASM)" -I${s_path}(+) $(NASM_INC) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii
|
||||
|
||||
[Device-Tree-Source-File]
|
||||
<InputFile>
|
||||
|
@ -4150,7 +4150,7 @@ DEFINE GCC_DLINK_FLAGS_COMMON = -nostdlib --pie
|
||||
DEFINE GCC_DLINK2_FLAGS_COMMON = -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
|
||||
DEFINE GCC_IA32_X64_DLINK_COMMON = DEF(GCC_DLINK_FLAGS_COMMON) --gc-sections
|
||||
DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Wl,--emit-relocs -nostdlib -Wl,--gc-sections -u $(IMAGE_ENTRY_POINT) -Wl,-e,$(IMAGE_ENTRY_POINT),-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
|
||||
DEFINE GCC_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
|
||||
DEFINE GCC_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20 -Wl,--pic-veneer
|
||||
DEFINE GCC_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -z common-page-size=0x20
|
||||
DEFINE GCC_ARM_AARCH64_ASLDLINK_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0 DEF(GCC_DLINK2_FLAGS_COMMON) -z common-page-size=0x20
|
||||
DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT)
|
||||
@ -4263,11 +4263,11 @@ DEFINE GCC49_ARM_ASM_FLAGS = DEF(GCC48_ARM_ASM_FLAGS)
|
||||
DEFINE GCC49_AARCH64_ASM_FLAGS = DEF(GCC48_AARCH64_ASM_FLAGS)
|
||||
DEFINE GCC49_ARM_CC_FLAGS = DEF(GCC48_ARM_CC_FLAGS)
|
||||
DEFINE GCC49_ARM_CC_XIPFLAGS = DEF(GCC48_ARM_CC_XIPFLAGS)
|
||||
DEFINE GCC49_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC44_ALL_CC_FLAGS) DEF(GCC_AARCH64_CC_FLAGS)
|
||||
DEFINE GCC49_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC44_ALL_CC_FLAGS) DEF(GCC_AARCH64_CC_FLAGS) -mcmodel=small
|
||||
DEFINE GCC49_AARCH64_CC_XIPFLAGS = DEF(GCC48_AARCH64_CC_XIPFLAGS)
|
||||
DEFINE GCC49_ARM_DLINK_FLAGS = DEF(GCC48_ARM_DLINK_FLAGS)
|
||||
DEFINE GCC49_ARM_DLINK2_FLAGS = DEF(GCC48_ARM_DLINK2_FLAGS)
|
||||
DEFINE GCC49_AARCH64_DLINK_FLAGS = DEF(GCC48_AARCH64_DLINK_FLAGS)
|
||||
DEFINE GCC49_AARCH64_DLINK_FLAGS = DEF(GCC48_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
|
||||
DEFINE GCC49_AARCH64_DLINK2_FLAGS = DEF(GCC48_AARCH64_DLINK2_FLAGS)
|
||||
DEFINE GCC49_ARM_ASLDLINK_FLAGS = DEF(GCC48_ARM_ASLDLINK_FLAGS)
|
||||
DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC48_AARCH64_ASLDLINK_FLAGS)
|
||||
@ -5034,15 +5034,16 @@ RELEASE_GCC49_ARM_CC_FLAGS = DEF(GCC49_ARM_CC_FLAGS) -Wno-unused-but-set-v
|
||||
*_GCC49_AARCH64_VFRPP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_VFRPP_FLAGS)
|
||||
*_GCC49_AARCH64_CC_XIPFLAGS = DEF(GCC49_AARCH64_CC_XIPFLAGS)
|
||||
|
||||
DEBUG_GCC49_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS) -O0 -mcmodel=small
|
||||
DEBUG_GCC49_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000
|
||||
DEBUG_GCC49_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS) -O0
|
||||
DEBUG_GCC49_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS)
|
||||
DEBUG_GCC49_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
|
||||
|
||||
RELEASE_GCC49_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -Wno-unused-const-variable -mcmodel=tiny
|
||||
RELEASE_GCC49_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable -Wno-unused-const-variable
|
||||
RELEASE_GCC49_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS)
|
||||
RELEASE_GCC49_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
|
||||
|
||||
NOOPT_GCC49_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS) -O0 -mcmodel=small
|
||||
NOOPT_GCC49_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000 -O0
|
||||
NOOPT_GCC49_AARCH64_CC_FLAGS = DEF(GCC49_AARCH64_CC_FLAGS) -O0
|
||||
NOOPT_GCC49_AARCH64_DLINK_FLAGS = DEF(GCC49_AARCH64_DLINK_FLAGS) -O0
|
||||
NOOPT_GCC49_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20 -O0
|
||||
|
||||
####################################################################################
|
||||
@ -5189,15 +5190,16 @@ RELEASE_GCC5_ARM_DLINK_FLAGS = DEF(GCC5_ARM_DLINK_FLAGS) -flto -Os -L$(WORKS
|
||||
*_GCC5_AARCH64_VFRPP_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_VFRPP_FLAGS)
|
||||
*_GCC5_AARCH64_CC_XIPFLAGS = DEF(GCC5_AARCH64_CC_XIPFLAGS)
|
||||
|
||||
DEBUG_GCC5_AARCH64_CC_FLAGS = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -Wno-unused-const-variable -mcmodel=small
|
||||
DEBUG_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000 -flto -Os -L$(WORKSPACE)/ArmPkg/Library/GccLto -llto-aarch64 -Wl,-plugin-opt=-pass-through=-llto-aarch64 -Wno-lto-type-mismatch -mcmodel=small
|
||||
DEBUG_GCC5_AARCH64_CC_FLAGS = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -Wno-unused-const-variable
|
||||
DEBUG_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -flto -Os -L$(WORKSPACE)/ArmPkg/Library/GccLto -llto-aarch64 -Wl,-plugin-opt=-pass-through=-llto-aarch64 -Wno-lto-type-mismatch
|
||||
DEBUG_GCC5_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
|
||||
|
||||
RELEASE_GCC5_AARCH64_CC_FLAGS = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -Wno-unused-const-variable -mcmodel=tiny
|
||||
RELEASE_GCC5_AARCH64_CC_FLAGS = DEF(GCC5_AARCH64_CC_FLAGS) -flto -Wno-unused-but-set-variable -Wno-unused-const-variable
|
||||
RELEASE_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -flto -Os -L$(WORKSPACE)/ArmPkg/Library/GccLto -llto-aarch64 -Wl,-plugin-opt=-pass-through=-llto-aarch64 -Wno-lto-type-mismatch
|
||||
RELEASE_GCC5_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20
|
||||
|
||||
NOOPT_GCC5_AARCH64_CC_FLAGS = DEF(GCC5_AARCH64_CC_FLAGS) -O0 -mcmodel=small
|
||||
NOOPT_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -z common-page-size=0x1000 -O0
|
||||
NOOPT_GCC5_AARCH64_CC_FLAGS = DEF(GCC5_AARCH64_CC_FLAGS) -O0
|
||||
NOOPT_GCC5_AARCH64_DLINK_FLAGS = DEF(GCC5_AARCH64_DLINK_FLAGS) -O0
|
||||
NOOPT_GCC5_AARCH64_DLINK_XIPFLAGS = -z common-page-size=0x20 -O0
|
||||
|
||||
####################################################################################
|
||||
@ -5247,7 +5249,7 @@ DEFINE CLANG35_AARCH64_CC_FLAGS = DEF(GCC_AARCH64_CC_FLAGS) DEF(CLANG35_AARCH64
|
||||
*_CLANG35_ARM_ASM_FLAGS = DEF(GCC_ASM_FLAGS) DEF(CLANG35_ARM_TARGET) $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) -Qunused-arguments
|
||||
*_CLANG35_ARM_DLINK_FLAGS = DEF(CLANG35_ARM_TARGET) DEF(GCC_ARM_DLINK_FLAGS)
|
||||
*_CLANG35_ARM_DLINK2_FLAGS = DEF(GCC_DLINK2_FLAGS_COMMON) -Wl,--defsym=PECOFF_HEADER_SIZE=0x220
|
||||
*_CLANG35_ARM_PLATFORM_FLAGS = -march=armv7-a
|
||||
*_CLANG35_ARM_PLATFORM_FLAGS = -march=armv7-a -mkernel -Qunused-arguments
|
||||
*_CLANG35_ARM_PP_FLAGS = DEF(GCC_PP_FLAGS) DEF(CLANG35_ARM_TARGET) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS)
|
||||
*_CLANG35_ARM_RC_FLAGS = DEF(GCC_ARM_RC_FLAGS)
|
||||
*_CLANG35_ARM_VFRPP_FLAGS = DEF(GCC_VFRPP_FLAGS) DEF(CLANG35_ARM_TARGET) $(ARCHCC_FLAGS) $(PLATFORM_FLAGS)
|
||||
|
@ -416,7 +416,7 @@ class PATH(object):
|
||||
|
||||
def header(self,struct):
|
||||
header={}
|
||||
head_re = re.compile(r'} %s;[\s\S\n]+h{1}"'%struct,re.M|re.S)
|
||||
head_re = re.compile('typedef.*} %s;[\n]+(.*?)(?:typedef|formset)'%struct,re.M|re.S)
|
||||
head_re2 = re.compile(r'#line[\s\d]+"(\S+h)"')
|
||||
for i in list(self.lstinf.keys()):
|
||||
with open(i,'r') as lst:
|
||||
|
@ -26,25 +26,20 @@
|
||||
[Bin.Win32]
|
||||
build.exe
|
||||
BPDG.exe
|
||||
BootSectImage.exe
|
||||
Common.PyUtility.pyd
|
||||
Ecc.exe
|
||||
EfiCompressor.pyd
|
||||
EfiLdrImage.exe
|
||||
EfiRom.exe
|
||||
Eot.EfiCompressor.pyd
|
||||
Eot.LzmaCompressor.pyd
|
||||
GenBootSector.exe
|
||||
GenCrc32.exe
|
||||
GenDepex.exe
|
||||
GenFds.exe
|
||||
GenFfs.exe
|
||||
GenFv.exe
|
||||
GenFw.exe
|
||||
GenPage.exe
|
||||
GenPatchPcdTable.exe
|
||||
GenSec.exe
|
||||
GenVtf.exe
|
||||
ImportTool.bat
|
||||
LzmaCompress.exe
|
||||
LzmaF86Compress.bat
|
||||
|
@ -1,21 +0,0 @@
|
||||
## @file
|
||||
# GNU/Linux makefile for 'BootSectImage' module build.
|
||||
#
|
||||
# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
MAKEROOT ?= ..
|
||||
|
||||
APPNAME = BootSectImage
|
||||
|
||||
LIBS = -lCommon
|
||||
|
||||
OBJECTS = bootsectimage.o
|
||||
|
||||
include $(MAKEROOT)/Makefiles/app.makefile
|
@ -1,22 +0,0 @@
|
||||
## @file
|
||||
# Windows makefile for 'BootSectImage' module build.
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
!INCLUDE ..\Makefiles\ms.common
|
||||
|
||||
APPNAME = BootSectImage
|
||||
|
||||
LIBS = $(LIB_PATH)\Common.lib
|
||||
|
||||
OBJECTS = BootSectImage.obj
|
||||
|
||||
!INCLUDE ..\Makefiles\ms.app
|
||||
|
@ -1,955 +0,0 @@
|
||||
/** @file
|
||||
|
||||
Abstract:
|
||||
Patch the BPB information in boot sector image file.
|
||||
Patch the MBR code in MBR image file.
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "fat.h"
|
||||
#include "mbr.h"
|
||||
#include "EfiUtilityMsgs.h"
|
||||
#include "ParseInf.h"
|
||||
|
||||
#define DEBUG_WARN 0x1
|
||||
#define DEBUG_ERROR 0x2
|
||||
|
||||
//
|
||||
// Utility Name
|
||||
//
|
||||
#define UTILITY_NAME "BootSectImage"
|
||||
|
||||
//
|
||||
// Utility version information
|
||||
//
|
||||
#define UTILITY_MAJOR_VERSION 1
|
||||
#define UTILITY_MINOR_VERSION 0
|
||||
|
||||
void
|
||||
Version (
|
||||
void
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Displays the standard utility information to SDTOUT
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
|
||||
}
|
||||
|
||||
void
|
||||
Usage (
|
||||
void
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
GC_TODO: Add function description
|
||||
|
||||
Arguments:
|
||||
|
||||
|
||||
Returns:
|
||||
|
||||
GC_TODO: add return values
|
||||
|
||||
--*/
|
||||
{
|
||||
Version();
|
||||
printf ("Copyright (c) 1999-2016 Intel Corporation. All rights reserved.\n");
|
||||
printf ("\n The BootSectImage tool prints information or patch destination file by source\n");
|
||||
printf (" file for BIOS Parameter Block (BPB) or Master Boot Record (MBR).\n");
|
||||
printf ("\nUsage: \n\
|
||||
BootSectImage\n\
|
||||
[-f, --force force patch even if the FAT type of SrcImage and DstImage mismatch]\n\
|
||||
[-m, --mbr process MBR instead of boot sector]\n\
|
||||
[-p, --parse parse SrcImageFile]\n\
|
||||
[-o, --output DstImage]\n\
|
||||
[-g, --patch patch DstImage using data from SrcImageFile]\n\
|
||||
[-v, --verbose]\n\
|
||||
[--version]\n\
|
||||
[-q, --quiet disable all messages except fatal errors]\n\
|
||||
[-d, --debug[#]\n\
|
||||
[-h, --help]\n\
|
||||
[SrcImageFile]\n");
|
||||
}
|
||||
|
||||
int WriteToFile (
|
||||
void *BootSector,
|
||||
char *FileName
|
||||
)
|
||||
/*++
|
||||
Routine Description:
|
||||
Write 512 bytes boot sector to file.
|
||||
|
||||
Arguments:
|
||||
BootSector - point to a buffer containing 512 bytes boot sector to write
|
||||
FileName - file to write to
|
||||
|
||||
Return:
|
||||
int - number of bytes wrote,
|
||||
512 indicates write successful
|
||||
0 indicates write failure
|
||||
--*/
|
||||
{
|
||||
FILE *FileHandle;
|
||||
int result;
|
||||
|
||||
FileHandle = fopen (LongFilePath (FileName), "r+b");
|
||||
if (FileHandle == NULL) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Open file: %s", FileName);
|
||||
return 0;
|
||||
}
|
||||
fseek (FileHandle, 0, SEEK_SET);
|
||||
|
||||
result = fwrite (BootSector, 1, 512, FileHandle);
|
||||
if (result != 512) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "Write file: %s", FileName);
|
||||
result = 0;
|
||||
}
|
||||
|
||||
fclose (FileHandle);
|
||||
return result;
|
||||
}
|
||||
|
||||
int ReadFromFile (
|
||||
void *BootSector,
|
||||
char *FileName
|
||||
)
|
||||
/*++
|
||||
Routine Description:
|
||||
Read first 512 bytes from file.
|
||||
|
||||
Arguments:
|
||||
BootSector - point to a buffer receiving the first 512 bytes data from file
|
||||
FileName - file to read from
|
||||
|
||||
Return:
|
||||
int - number of bytes read,
|
||||
512 indicates read successful
|
||||
0 indicates read failure
|
||||
--*/
|
||||
{
|
||||
FILE *FileHandle;
|
||||
int result;
|
||||
|
||||
FileHandle = fopen (LongFilePath (FileName), "rb");
|
||||
if (FileHandle == NULL) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E0001: Error opening file: %s", FileName);
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = fread (BootSector, 1, 512, FileHandle);
|
||||
if (result != 512) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E0004: Error reading file: %s", FileName);
|
||||
result = 0;
|
||||
}
|
||||
|
||||
fclose (FileHandle);
|
||||
return result;
|
||||
}
|
||||
|
||||
char *
|
||||
FatTypeToString (
|
||||
IN FAT_TYPE FatType
|
||||
)
|
||||
/*++
|
||||
Routine Description:
|
||||
Convert enum type of FatType to string
|
||||
--*/
|
||||
{
|
||||
switch (FatType) {
|
||||
case FatTypeFat12:
|
||||
return "FAT12";
|
||||
case FatTypeFat16:
|
||||
return "FAT16";
|
||||
case FatTypeFat32:
|
||||
return "FAT32";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "FAT Unknown";
|
||||
}
|
||||
|
||||
FAT_TYPE
|
||||
GetFatType (
|
||||
IN FAT_BPB_STRUCT *FatBpb
|
||||
)
|
||||
/*++
|
||||
Routine Description:
|
||||
Determine the FAT type according to BIOS Paramater Block (BPB) data
|
||||
|
||||
Arguments:
|
||||
FatBpb - BIOS Parameter Block (BPB) data, 512 Bytes
|
||||
|
||||
Return:
|
||||
FatTypeUnknown - Cannot determine the FAT type
|
||||
FatTypeFat12 - FAT12
|
||||
FatTypeFat16 - FAT16
|
||||
FatTypeFat32 - FAT32
|
||||
--*/
|
||||
{
|
||||
FAT_TYPE FatType;
|
||||
UINTN RootDirSectors;
|
||||
UINTN FATSz;
|
||||
UINTN TotSec;
|
||||
UINTN DataSec;
|
||||
UINTN CountOfClusters;
|
||||
CHAR8 FilSysType[9];
|
||||
|
||||
FatType = FatTypeUnknown;
|
||||
|
||||
//
|
||||
// Simple check
|
||||
//
|
||||
if (FatBpb->Fat12_16.Signature != FAT_BS_SIGNATURE) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - Signature Invalid - %04x, expected: %04x",
|
||||
FatBpb->Fat12_16.Signature, FAT_BS_SIGNATURE);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
|
||||
//
|
||||
// Check according to FAT spec
|
||||
//
|
||||
if ((FatBpb->Fat12_16.BS_jmpBoot[0] != FAT_BS_JMP1) &&
|
||||
(FatBpb->Fat12_16.BS_jmpBoot[0] != FAT_BS_JMP2)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BS_jmpBoot - %02x, expected: %02x or %02x",
|
||||
FatBpb->Fat12_16.BS_jmpBoot[0], FAT_BS_JMP1, FAT_BS_JMP2);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
|
||||
if ((FatBpb->Fat12_16.BPB_BytsPerSec != 512) &&
|
||||
(FatBpb->Fat12_16.BPB_BytsPerSec != 1024) &&
|
||||
(FatBpb->Fat12_16.BPB_BytsPerSec != 2048) &&
|
||||
(FatBpb->Fat12_16.BPB_BytsPerSec != 4096)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_BytsPerSec - %04x, expected: %04x, %04x, %04x, or %04x",
|
||||
FatBpb->Fat12_16.BPB_BytsPerSec, 512, 1024, 2048, 4096);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if (FatBpb->Fat12_16.BPB_BytsPerSec != 512) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT - BPB_BytsPerSec - %04x, expected: %04x",
|
||||
FatBpb->Fat12_16.BPB_BytsPerSec, 512);
|
||||
}
|
||||
if ((FatBpb->Fat12_16.BPB_SecPerClus != 1) &&
|
||||
(FatBpb->Fat12_16.BPB_SecPerClus != 2) &&
|
||||
(FatBpb->Fat12_16.BPB_SecPerClus != 4) &&
|
||||
(FatBpb->Fat12_16.BPB_SecPerClus != 8) &&
|
||||
(FatBpb->Fat12_16.BPB_SecPerClus != 16) &&
|
||||
(FatBpb->Fat12_16.BPB_SecPerClus != 32) &&
|
||||
(FatBpb->Fat12_16.BPB_SecPerClus != 64) &&
|
||||
(FatBpb->Fat12_16.BPB_SecPerClus != 128)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_SecPerClus - %02x, expected: %02x, %02x, %02x, %02x, %02x, %02x, %02x, or %02x",
|
||||
FatBpb->Fat12_16.BPB_BytsPerSec, 1, 2, 4, 8, 16, 32, 64, 128);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if (FatBpb->Fat12_16.BPB_BytsPerSec * FatBpb->Fat12_16.BPB_SecPerClus > 32 * 1024) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_BytsPerSec * BPB_SecPerClus - %08x, expected: <= %08x",
|
||||
FatBpb->Fat12_16.BPB_BytsPerSec * FatBpb->Fat12_16.BPB_SecPerClus, 32 * 1024);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if (FatBpb->Fat12_16.BPB_RsvdSecCnt == 0) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_RsvdSecCnt - %04x, expected: Non-Zero Value",
|
||||
FatBpb->Fat12_16.BPB_RsvdSecCnt);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if (FatBpb->Fat12_16.BPB_NumFATs != 2) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT - BPB_NumFATs - %02x, expected: %02x",
|
||||
FatBpb->Fat12_16.BPB_NumFATs, 2);
|
||||
}
|
||||
if ((FatBpb->Fat12_16.BPB_Media != 0xF0) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xF8) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xF9) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xFA) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xFB) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xFC) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xFD) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xFE) &&
|
||||
(FatBpb->Fat12_16.BPB_Media != 0xFF)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_Media - %02x, expected: %02x, %02x, %02x, %02x, %02x, %02x, %02x, %02x, or %02x",
|
||||
FatBpb->Fat12_16.BPB_Media, 0xF0, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
|
||||
//
|
||||
// Algo in FAT spec
|
||||
//
|
||||
RootDirSectors = ((FatBpb->Fat12_16.BPB_RootEntCnt * sizeof(FAT_DIRECTORY_ENTRY)) +
|
||||
(FatBpb->Fat12_16.BPB_BytsPerSec - 1)) /
|
||||
FatBpb->Fat12_16.BPB_BytsPerSec;
|
||||
|
||||
if (FatBpb->Fat12_16.BPB_FATSz16 != 0) {
|
||||
FATSz = FatBpb->Fat12_16.BPB_FATSz16;
|
||||
} else {
|
||||
FATSz = FatBpb->Fat32.BPB_FATSz32;
|
||||
}
|
||||
if (FATSz == 0) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_FATSz16, BPB_FATSz32 - 0, expected: Non-Zero Value");
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
|
||||
if (FatBpb->Fat12_16.BPB_TotSec16 != 0) {
|
||||
TotSec = FatBpb->Fat12_16.BPB_TotSec16;
|
||||
} else {
|
||||
TotSec = FatBpb->Fat12_16.BPB_TotSec32;
|
||||
}
|
||||
if (TotSec == 0) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT - BPB_TotSec16, BPB_TotSec32 - 0, expected: Non-Zero Value");
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
|
||||
DataSec = TotSec - (
|
||||
FatBpb->Fat12_16.BPB_RsvdSecCnt +
|
||||
FatBpb->Fat12_16.BPB_NumFATs * FATSz +
|
||||
RootDirSectors
|
||||
);
|
||||
|
||||
CountOfClusters = DataSec / FatBpb->Fat12_16.BPB_SecPerClus;
|
||||
|
||||
if (CountOfClusters < FAT_MAX_FAT12_CLUSTER) {
|
||||
FatType = FatTypeFat12;
|
||||
} else if (CountOfClusters < FAT_MAX_FAT16_CLUSTER) {
|
||||
FatType = FatTypeFat16;
|
||||
} else {
|
||||
FatType = FatTypeFat32;
|
||||
}
|
||||
//
|
||||
// Check according to FAT spec
|
||||
//
|
||||
if (((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) &&
|
||||
(FatBpb->Fat12_16.BPB_RsvdSecCnt != 1)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT12_16 - BPB_RsvdSecCnt - %04x, expected: %04x",
|
||||
FatBpb->Fat12_16.BPB_RsvdSecCnt, 1);
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat12_16.BPB_RsvdSecCnt != 32)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_RsvdSecCnt - %04x, expected: %04x",
|
||||
FatBpb->Fat12_16.BPB_RsvdSecCnt, 32);
|
||||
}
|
||||
if ((FatType == FatTypeFat16) &&
|
||||
(FatBpb->Fat12_16.BPB_RootEntCnt != 512)) {
|
||||
printf ("WARNING: FAT16: BPB_RootEntCnt - %04x, expected - %04x\n",
|
||||
FatBpb->Fat12_16.BPB_RootEntCnt, 512);
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat12_16.BPB_RootEntCnt != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_RootEntCnt - %04x, expected: %04x",
|
||||
FatBpb->Fat12_16.BPB_RootEntCnt, 0);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat12_16.BPB_TotSec16 != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_TotSec16 - %04x, expected: %04x",
|
||||
FatBpb->Fat12_16.BPB_TotSec16, 0);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat12_16.BPB_FATSz16 != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_FATSz16 - %04x, expected: %04x",
|
||||
FatBpb->Fat12_16.BPB_FATSz16, 0);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat12_16.BPB_TotSec32 == 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_TotSec32 - %04x, expected: Non-Zero",
|
||||
(unsigned) FatBpb->Fat12_16.BPB_TotSec32);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat32.BPB_FATSz32 == 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_FATSz32 - %08x, expected: Non-Zero",
|
||||
(unsigned) FatBpb->Fat32.BPB_FATSz32);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat32.BPB_FSVer != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_FSVer - %08x, expected: %04x",
|
||||
FatBpb->Fat32.BPB_FSVer, 0);
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat32.BPB_RootClus != 2)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_RootClus - %08x, expected: %04x",
|
||||
(unsigned) FatBpb->Fat32.BPB_RootClus, 2);
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat32.BPB_FSInfo != 1)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_FSInfo - %08x, expected: %04x",
|
||||
FatBpb->Fat32.BPB_FSInfo, 1);
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat32.BPB_BkBootSec != 6)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BPB_BkBootSec - %08x, expected: %04x",
|
||||
FatBpb->Fat32.BPB_BkBootSec, 6);
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
((*(UINT32 *)FatBpb->Fat32.BPB_Reserved != 0) ||
|
||||
(*((UINT32 *)FatBpb->Fat32.BPB_Reserved + 1) != 0) ||
|
||||
(*((UINT32 *)FatBpb->Fat32.BPB_Reserved + 2) != 0))) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BPB_Reserved - %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x, expected: 0",
|
||||
FatBpb->Fat32.BPB_Reserved[0],
|
||||
FatBpb->Fat32.BPB_Reserved[1],
|
||||
FatBpb->Fat32.BPB_Reserved[2],
|
||||
FatBpb->Fat32.BPB_Reserved[3],
|
||||
FatBpb->Fat32.BPB_Reserved[4],
|
||||
FatBpb->Fat32.BPB_Reserved[5],
|
||||
FatBpb->Fat32.BPB_Reserved[6],
|
||||
FatBpb->Fat32.BPB_Reserved[7],
|
||||
FatBpb->Fat32.BPB_Reserved[8],
|
||||
FatBpb->Fat32.BPB_Reserved[9],
|
||||
FatBpb->Fat32.BPB_Reserved[10],
|
||||
FatBpb->Fat32.BPB_Reserved[11]);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if (((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) &&
|
||||
(FatBpb->Fat12_16.BS_Reserved1 != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT12_16 - BS_Reserved1 - %02x, expected: 0\n",
|
||||
FatBpb->Fat12_16.BS_Reserved1);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat32.BS_Reserved1 != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BS_Reserved1 - %02x, expected: 0\n",
|
||||
FatBpb->Fat32.BS_Reserved1);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if (((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) &&
|
||||
(FatBpb->Fat12_16.BS_BootSig != FAT_BS_BOOTSIG)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT12_16 - BS_BootSig - %02x, expected: %02x\n",
|
||||
FatBpb->Fat12_16.BS_BootSig, FAT_BS_BOOTSIG);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
if ((FatType == FatTypeFat32) &&
|
||||
(FatBpb->Fat32.BS_BootSig != FAT_BS_BOOTSIG)) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3003: FAT32 - BS_BootSig - %02x, expected: %02x\n",
|
||||
FatBpb->Fat32.BS_BootSig, FAT_BS_BOOTSIG);
|
||||
return FatTypeUnknown;
|
||||
}
|
||||
|
||||
if ((FatType == FatTypeFat12) || (FatType == FatTypeFat16)) {
|
||||
memcpy (FilSysType, FatBpb->Fat12_16.BS_FilSysType, 8);
|
||||
FilSysType[8] = 0;
|
||||
if ((FatType == FatTypeFat12) &&
|
||||
(strcmp (FilSysType, FAT12_FILSYSTYPE) != 0) &&
|
||||
(strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT12 - BS_FilSysType - %s, expected: %s, or %s\n",
|
||||
FilSysType, FAT12_FILSYSTYPE, FAT_FILSYSTYPE);
|
||||
}
|
||||
if ((FatType == FatTypeFat16) &&
|
||||
(strcmp (FilSysType, FAT16_FILSYSTYPE) != 0) &&
|
||||
(strcmp (FilSysType, FAT_FILSYSTYPE) != 0)) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT16 - BS_FilSysType - %s, expected: %s, or %s\n",
|
||||
FilSysType, FAT16_FILSYSTYPE, FAT_FILSYSTYPE);
|
||||
}
|
||||
}
|
||||
if (FatType == FatTypeFat32) {
|
||||
memcpy (FilSysType, FatBpb->Fat32.BS_FilSysType, 8);
|
||||
FilSysType[8] = 0;
|
||||
if (strcmp (FilSysType, FAT32_FILSYSTYPE) != 0) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3003: FAT32 - BS_FilSysType - %s, expected: %s\n",
|
||||
FilSysType, FAT32_FILSYSTYPE);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// pass all check, get FAT type
|
||||
//
|
||||
return FatType;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParseBootSector (
|
||||
char *FileName
|
||||
)
|
||||
{
|
||||
FAT_BPB_STRUCT FatBpb;
|
||||
FAT_TYPE FatType;
|
||||
|
||||
if (ReadFromFile ((void *)&FatBpb, FileName) == 0) {
|
||||
return ;
|
||||
}
|
||||
|
||||
FatType = GetFatType (&FatBpb);
|
||||
if (FatType <= FatTypeUnknown || FatType >= FatTypeMax) {
|
||||
printf ("ERROR: E3002: Unknown FAT Type!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf ("\nBoot Sector %s:\n", FatTypeToString (FatType));
|
||||
printf ("\n");
|
||||
printf (" Offset Title Data\n");
|
||||
printf ("==================================================================\n");
|
||||
printf (" 0 JMP instruction %02x %02x %02x\n",
|
||||
FatBpb.Fat12_16.BS_jmpBoot[0],
|
||||
FatBpb.Fat12_16.BS_jmpBoot[1],
|
||||
FatBpb.Fat12_16.BS_jmpBoot[2]);
|
||||
printf (" 3 OEM %c%c%c%c%c%c%c%c\n",
|
||||
FatBpb.Fat12_16.BS_OEMName[0],
|
||||
FatBpb.Fat12_16.BS_OEMName[1],
|
||||
FatBpb.Fat12_16.BS_OEMName[2],
|
||||
FatBpb.Fat12_16.BS_OEMName[3],
|
||||
FatBpb.Fat12_16.BS_OEMName[4],
|
||||
FatBpb.Fat12_16.BS_OEMName[5],
|
||||
FatBpb.Fat12_16.BS_OEMName[6],
|
||||
FatBpb.Fat12_16.BS_OEMName[7]);
|
||||
printf ("\n");
|
||||
printf ("BIOS Parameter Block\n");
|
||||
printf (" B Bytes per sector %04x\n", FatBpb.Fat12_16.BPB_BytsPerSec);
|
||||
printf (" D Sectors per cluster %02x\n", FatBpb.Fat12_16.BPB_SecPerClus);
|
||||
printf (" E Reserved sectors %04x\n", FatBpb.Fat12_16.BPB_RsvdSecCnt);
|
||||
printf (" 10 Number of FATs %02x\n", FatBpb.Fat12_16.BPB_NumFATs);
|
||||
printf (" 11 Root entries %04x\n", FatBpb.Fat12_16.BPB_RootEntCnt);
|
||||
printf (" 13 Sectors (under 32MB) %04x\n", FatBpb.Fat12_16.BPB_TotSec16);
|
||||
printf (" 15 Media descriptor %02x\n", FatBpb.Fat12_16.BPB_Media);
|
||||
printf (" 16 Sectors per FAT (small vol.) %04x\n", FatBpb.Fat12_16.BPB_FATSz16);
|
||||
printf (" 18 Sectors per track %04x\n", FatBpb.Fat12_16.BPB_SecPerTrk);
|
||||
printf (" 1A Heads %04x\n", FatBpb.Fat12_16.BPB_NumHeads);
|
||||
printf (" 1C Hidden sectors %08x\n", (unsigned) FatBpb.Fat12_16.BPB_HiddSec);
|
||||
printf (" 20 Sectors (over 32MB) %08x\n", (unsigned) FatBpb.Fat12_16.BPB_TotSec32);
|
||||
printf ("\n");
|
||||
if (FatType != FatTypeFat32) {
|
||||
printf (" 24 BIOS drive %02x\n", FatBpb.Fat12_16.BS_DrvNum);
|
||||
printf (" 25 (Unused) %02x\n", FatBpb.Fat12_16.BS_Reserved1);
|
||||
printf (" 26 Ext. boot signature %02x\n", FatBpb.Fat12_16.BS_BootSig);
|
||||
printf (" 27 Volume serial number %08x\n", (unsigned) FatBpb.Fat12_16.BS_VolID);
|
||||
printf (" 2B Volume lable %c%c%c%c%c%c%c%c%c%c%c\n",
|
||||
FatBpb.Fat12_16.BS_VolLab[0],
|
||||
FatBpb.Fat12_16.BS_VolLab[1],
|
||||
FatBpb.Fat12_16.BS_VolLab[2],
|
||||
FatBpb.Fat12_16.BS_VolLab[3],
|
||||
FatBpb.Fat12_16.BS_VolLab[4],
|
||||
FatBpb.Fat12_16.BS_VolLab[5],
|
||||
FatBpb.Fat12_16.BS_VolLab[6],
|
||||
FatBpb.Fat12_16.BS_VolLab[7],
|
||||
FatBpb.Fat12_16.BS_VolLab[8],
|
||||
FatBpb.Fat12_16.BS_VolLab[9],
|
||||
FatBpb.Fat12_16.BS_VolLab[10]);
|
||||
printf (" 36 File system %c%c%c%c%c%c%c%c\n",
|
||||
FatBpb.Fat12_16.BS_FilSysType[0],
|
||||
FatBpb.Fat12_16.BS_FilSysType[1],
|
||||
FatBpb.Fat12_16.BS_FilSysType[2],
|
||||
FatBpb.Fat12_16.BS_FilSysType[3],
|
||||
FatBpb.Fat12_16.BS_FilSysType[4],
|
||||
FatBpb.Fat12_16.BS_FilSysType[5],
|
||||
FatBpb.Fat12_16.BS_FilSysType[6],
|
||||
FatBpb.Fat12_16.BS_FilSysType[7]);
|
||||
printf ("\n");
|
||||
} else {
|
||||
printf ("FAT32 Section\n");
|
||||
printf (" 24 Sectors per FAT (large vol.) %08x\n", (unsigned) FatBpb.Fat32.BPB_FATSz32);
|
||||
printf (" 28 Flags %04x\n", FatBpb.Fat32.BPB_ExtFlags);
|
||||
printf (" 2A Version %04x\n", FatBpb.Fat32.BPB_FSVer);
|
||||
printf (" 2C Root dir 1st cluster %08x\n", (unsigned) FatBpb.Fat32.BPB_RootClus);
|
||||
printf (" 30 FSInfo sector %04x\n", FatBpb.Fat32.BPB_FSInfo);
|
||||
printf (" 32 Backup boot sector %04x\n", FatBpb.Fat32.BPB_BkBootSec);
|
||||
printf (" 34 (Reserved) %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
|
||||
FatBpb.Fat32.BPB_Reserved[0],
|
||||
FatBpb.Fat32.BPB_Reserved[1],
|
||||
FatBpb.Fat32.BPB_Reserved[2],
|
||||
FatBpb.Fat32.BPB_Reserved[3],
|
||||
FatBpb.Fat32.BPB_Reserved[4],
|
||||
FatBpb.Fat32.BPB_Reserved[5],
|
||||
FatBpb.Fat32.BPB_Reserved[6],
|
||||
FatBpb.Fat32.BPB_Reserved[7],
|
||||
FatBpb.Fat32.BPB_Reserved[8],
|
||||
FatBpb.Fat32.BPB_Reserved[9],
|
||||
FatBpb.Fat32.BPB_Reserved[10],
|
||||
FatBpb.Fat32.BPB_Reserved[11]);
|
||||
printf ("\n");
|
||||
printf (" 40 BIOS drive %02x\n", FatBpb.Fat32.BS_DrvNum);
|
||||
printf (" 41 (Unused) %02x\n", FatBpb.Fat32.BS_Reserved1);
|
||||
printf (" 42 Ext. boot signature %02x\n", FatBpb.Fat32.BS_BootSig);
|
||||
printf (" 43 Volume serial number %08x\n", (unsigned) FatBpb.Fat32.BS_VolID);
|
||||
printf (" 47 Volume lable %c%c%c%c%c%c%c%c%c%c%c\n",
|
||||
FatBpb.Fat32.BS_VolLab[0],
|
||||
FatBpb.Fat32.BS_VolLab[1],
|
||||
FatBpb.Fat32.BS_VolLab[2],
|
||||
FatBpb.Fat32.BS_VolLab[3],
|
||||
FatBpb.Fat32.BS_VolLab[4],
|
||||
FatBpb.Fat32.BS_VolLab[5],
|
||||
FatBpb.Fat32.BS_VolLab[6],
|
||||
FatBpb.Fat32.BS_VolLab[7],
|
||||
FatBpb.Fat32.BS_VolLab[8],
|
||||
FatBpb.Fat32.BS_VolLab[9],
|
||||
FatBpb.Fat32.BS_VolLab[10]);
|
||||
printf (" 52 File system %c%c%c%c%c%c%c%c\n",
|
||||
FatBpb.Fat32.BS_FilSysType[0],
|
||||
FatBpb.Fat32.BS_FilSysType[1],
|
||||
FatBpb.Fat32.BS_FilSysType[2],
|
||||
FatBpb.Fat32.BS_FilSysType[3],
|
||||
FatBpb.Fat32.BS_FilSysType[4],
|
||||
FatBpb.Fat32.BS_FilSysType[5],
|
||||
FatBpb.Fat32.BS_FilSysType[6],
|
||||
FatBpb.Fat32.BS_FilSysType[7]);
|
||||
printf ("\n");
|
||||
}
|
||||
printf (" 1FE Signature %04x\n", FatBpb.Fat12_16.Signature);
|
||||
printf ("\n");
|
||||
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void
|
||||
PatchBootSector (
|
||||
char *DestFileName,
|
||||
char *SourceFileName,
|
||||
BOOLEAN ForcePatch
|
||||
)
|
||||
/*++
|
||||
Routine Description:
|
||||
Patch destination file according to the information from source file.
|
||||
Only patch BPB data but leave boot code un-touched.
|
||||
|
||||
Arguments:
|
||||
DestFileName - Destination file to patch
|
||||
SourceFileName - Source file where patch from
|
||||
--*/
|
||||
{
|
||||
FAT_BPB_STRUCT DestFatBpb;
|
||||
FAT_BPB_STRUCT SourceFatBpb;
|
||||
FAT_TYPE DestFatType;
|
||||
FAT_TYPE SourceFatType;
|
||||
CHAR8 VolLab[11];
|
||||
CHAR8 FilSysType[8];
|
||||
|
||||
if (ReadFromFile ((void *)&DestFatBpb, DestFileName) == 0) {
|
||||
return ;
|
||||
}
|
||||
if (ReadFromFile ((void *)&SourceFatBpb, SourceFileName) == 0) {
|
||||
return ;
|
||||
}
|
||||
|
||||
DestFatType = GetFatType (&DestFatBpb);
|
||||
SourceFatType = GetFatType (&SourceFatBpb);
|
||||
|
||||
if (DestFatType != SourceFatType) {
|
||||
//
|
||||
// FAT type mismatch
|
||||
//
|
||||
if (ForcePatch) {
|
||||
DebugMsg (NULL, 0, DEBUG_WARN, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s",
|
||||
FatTypeToString(SourceFatType), FatTypeToString(DestFatType));
|
||||
} else {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3004: FAT type mismatch: Source - %s, Dest - %s",
|
||||
FatTypeToString(SourceFatType), FatTypeToString(DestFatType));
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
if (SourceFatType <= FatTypeUnknown || SourceFatType >= FatTypeMax) {
|
||||
DebugMsg (NULL, 0, DEBUG_ERROR, NULL, "ERROR: E3002: Unknown FAT Type!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Copy BPB/boot data (excluding BS_jmpBoot, BS_OEMName, BootCode and Signature) from SourceFatBpb to DestFatBpb
|
||||
//
|
||||
printf ("Patching %s BPB: ", FatTypeToString (SourceFatType));
|
||||
if (SourceFatType != FatTypeFat32) {
|
||||
memcpy (
|
||||
&DestFatBpb.Fat12_16.BPB_BytsPerSec,
|
||||
&SourceFatBpb.Fat12_16.BPB_BytsPerSec,
|
||||
((UINTN)&DestFatBpb.Fat12_16.Reserved - (UINTN)&DestFatBpb.Fat12_16.BPB_BytsPerSec)
|
||||
);
|
||||
} else {
|
||||
memcpy (
|
||||
&DestFatBpb.Fat32.BPB_BytsPerSec,
|
||||
&SourceFatBpb.Fat32.BPB_BytsPerSec,
|
||||
((UINTN)&DestFatBpb.Fat32.Reserved - (UINTN)&DestFatBpb.Fat32.BPB_BytsPerSec)
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Set BS_VolLab and BS_FilSysType of DestFatBpb
|
||||
//
|
||||
// BS_VolLab BS_FilSysType
|
||||
// FAT12: EFI FAT12 FAT12
|
||||
// FAT16: EFI FAT16 FAT16
|
||||
// FAT32: EFI FAT32 FAT32
|
||||
//
|
||||
if (SourceFatType == FatTypeFat32) {
|
||||
memcpy (VolLab, "EFI FAT32 ", sizeof(VolLab));
|
||||
memcpy (FilSysType, FAT32_FILSYSTYPE, sizeof(FilSysType));
|
||||
} else if (SourceFatType == FatTypeFat16) {
|
||||
memcpy (VolLab, "EFI FAT16 ", sizeof(VolLab));
|
||||
memcpy (FilSysType, FAT16_FILSYSTYPE, sizeof(FilSysType));
|
||||
} else {
|
||||
memcpy (VolLab, "EFI FAT12 ", sizeof(VolLab));
|
||||
memcpy (FilSysType, FAT12_FILSYSTYPE, sizeof(FilSysType));
|
||||
}
|
||||
if (SourceFatType != FatTypeFat32) {
|
||||
memcpy (DestFatBpb.Fat12_16.BS_VolLab, VolLab, sizeof(VolLab));
|
||||
memcpy (DestFatBpb.Fat12_16.BS_FilSysType, FilSysType, sizeof(FilSysType));
|
||||
} else {
|
||||
memcpy (DestFatBpb.Fat32.BS_VolLab, VolLab, sizeof(VolLab));
|
||||
memcpy (DestFatBpb.Fat32.BS_FilSysType, FilSysType, sizeof(FilSysType));
|
||||
}
|
||||
|
||||
//
|
||||
// Set Signature of DestFatBpb to 55AA
|
||||
//
|
||||
DestFatBpb.Fat12_16.Signature = FAT_BS_SIGNATURE;
|
||||
|
||||
//
|
||||
// Write DestFatBpb
|
||||
//
|
||||
if (WriteToFile ((void *)&DestFatBpb, DestFileName)) {
|
||||
printf ("successful!\n");
|
||||
} else {
|
||||
printf ("failed!\n");
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void
|
||||
ParseMbr (
|
||||
char *FileName
|
||||
)
|
||||
{
|
||||
MASTER_BOOT_RECORD Mbr;
|
||||
|
||||
if (ReadFromFile ((void *)&Mbr, FileName) == 0) {
|
||||
return ;
|
||||
}
|
||||
|
||||
printf ("\nMaster Boot Record:\n");
|
||||
printf ("\n");
|
||||
printf (" Offset Title Value\n");
|
||||
printf ("==================================================================\n");
|
||||
printf (" 0 Master bootstrap loader code (not list)\n");
|
||||
printf (" 1B8 Windows disk signature %08x\n", (unsigned) Mbr.UniqueMbrSignature);
|
||||
printf ("\n");
|
||||
printf ("Partition Table Entry #1\n");
|
||||
printf (" 1BE 80 = active partition %02x\n", Mbr.PartitionRecord[0].BootIndicator);
|
||||
printf (" 1BF Start head %02x\n", Mbr.PartitionRecord[0].StartHead);
|
||||
printf (" 1C0 Start sector %02x\n", Mbr.PartitionRecord[0].StartSector);
|
||||
printf (" 1C1 Start cylinder %02x\n", Mbr.PartitionRecord[0].StartTrack);
|
||||
printf (" 1C2 Partition type indicator %02x\n", Mbr.PartitionRecord[0].OSType);
|
||||
printf (" 1C3 End head %02x\n", Mbr.PartitionRecord[0].EndHead);
|
||||
printf (" 1C4 End sector %02x\n", Mbr.PartitionRecord[0].EndSector);
|
||||
printf (" 1C5 End cylinder %02x\n", Mbr.PartitionRecord[0].EndTrack);
|
||||
printf (" 1C6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[0].StartingLBA);
|
||||
printf (" 1CA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[0].SizeInLBA);
|
||||
printf ("\n");
|
||||
printf ("Partition Table Entry #2\n");
|
||||
printf (" 1CE 80 = active partition %02x\n", Mbr.PartitionRecord[1].BootIndicator);
|
||||
printf (" 1CF Start head %02x\n", Mbr.PartitionRecord[1].StartHead);
|
||||
printf (" 1D0 Start sector %02x\n", Mbr.PartitionRecord[1].StartSector);
|
||||
printf (" 1D1 Start cylinder %02x\n", Mbr.PartitionRecord[1].StartTrack);
|
||||
printf (" 1D2 Partition type indicator %02x\n", Mbr.PartitionRecord[1].OSType);
|
||||
printf (" 1D3 End head %02x\n", Mbr.PartitionRecord[1].EndHead);
|
||||
printf (" 1D4 End sector %02x\n", Mbr.PartitionRecord[1].EndSector);
|
||||
printf (" 1D5 End cylinder %02x\n", Mbr.PartitionRecord[1].EndTrack);
|
||||
printf (" 1D6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[1].StartingLBA);
|
||||
printf (" 1DA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[1].SizeInLBA);
|
||||
printf ("\n");
|
||||
printf ("Partition Table Entry #3\n");
|
||||
printf (" 1DE 80 = active partition %02x\n", Mbr.PartitionRecord[2].BootIndicator);
|
||||
printf (" 1DF Start head %02x\n", Mbr.PartitionRecord[2].StartHead);
|
||||
printf (" 1E0 Start sector %02x\n", Mbr.PartitionRecord[2].StartSector);
|
||||
printf (" 1E1 Start cylinder %02x\n", Mbr.PartitionRecord[2].StartTrack);
|
||||
printf (" 1E2 Partition type indicator %02x\n", Mbr.PartitionRecord[2].OSType);
|
||||
printf (" 1E3 End head %02x\n", Mbr.PartitionRecord[2].EndHead);
|
||||
printf (" 1E4 End sector %02x\n", Mbr.PartitionRecord[2].EndSector);
|
||||
printf (" 1E5 End cylinder %02x\n", Mbr.PartitionRecord[2].EndTrack);
|
||||
printf (" 1E6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[2].StartingLBA);
|
||||
printf (" 1EA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[2].SizeInLBA);
|
||||
printf ("\n");
|
||||
printf ("Partition Table Entry #4\n");
|
||||
printf (" 1EE 80 = active partition %02x\n", Mbr.PartitionRecord[3].BootIndicator);
|
||||
printf (" 1EF Start head %02x\n", Mbr.PartitionRecord[3].StartHead);
|
||||
printf (" 1F0 Start sector %02x\n", Mbr.PartitionRecord[3].StartSector);
|
||||
printf (" 1F1 Start cylinder %02x\n", Mbr.PartitionRecord[3].StartTrack);
|
||||
printf (" 1F2 Partition type indicator %02x\n", Mbr.PartitionRecord[3].OSType);
|
||||
printf (" 1F3 End head %02x\n", Mbr.PartitionRecord[3].EndHead);
|
||||
printf (" 1F4 End sector %02x\n", Mbr.PartitionRecord[3].EndSector);
|
||||
printf (" 1F5 End cylinder %02x\n", Mbr.PartitionRecord[3].EndTrack);
|
||||
printf (" 1F6 Sectors preceding partition %08x\n", (unsigned) Mbr.PartitionRecord[3].StartingLBA);
|
||||
printf (" 1FA Sectors in partition %08x\n", (unsigned) Mbr.PartitionRecord[3].SizeInLBA);
|
||||
printf ("\n");
|
||||
printf (" 1FE Signature %04x\n", Mbr.Signature);
|
||||
printf ("\n");
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void
|
||||
PatchMbr (
|
||||
char *DestFileName,
|
||||
char *SourceFileName
|
||||
)
|
||||
{
|
||||
MASTER_BOOT_RECORD DestMbr;
|
||||
MASTER_BOOT_RECORD SourceMbr;
|
||||
|
||||
if (ReadFromFile ((void *)&DestMbr, DestFileName) == 0) {
|
||||
return ;
|
||||
}
|
||||
if (ReadFromFile ((void *)&SourceMbr, SourceFileName) == 0) {
|
||||
return ;
|
||||
}
|
||||
|
||||
if (SourceMbr.Signature != MBR_SIGNATURE) {
|
||||
printf ("ERROR: E3000: Invalid MBR!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf ("Patching MBR:\n");
|
||||
memcpy (
|
||||
&DestMbr.PartitionRecord[0],
|
||||
&SourceMbr.PartitionRecord[0],
|
||||
sizeof(DestMbr.PartitionRecord)
|
||||
);
|
||||
|
||||
DestMbr.Signature = MBR_SIGNATURE;
|
||||
|
||||
|
||||
if (WriteToFile ((void *)&DestMbr, DestFileName)) {
|
||||
printf ("\tsuccessful!\n");
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char *argv[]
|
||||
)
|
||||
{
|
||||
char *SrcImage;
|
||||
char *DstImage;
|
||||
BOOLEAN ForcePatch; // -f
|
||||
BOOLEAN ProcessMbr; // -m
|
||||
BOOLEAN DoParse; // -p SrcImage or -g SrcImage DstImage
|
||||
BOOLEAN Verbose; // -v
|
||||
UINT64 LogLevel;
|
||||
EFI_STATUS EfiStatus;
|
||||
|
||||
SrcImage = DstImage = NULL;
|
||||
ForcePatch = FALSE;
|
||||
ProcessMbr = FALSE;
|
||||
DoParse = TRUE;
|
||||
Verbose = FALSE;
|
||||
|
||||
SetUtilityName ("bootsectimage");
|
||||
|
||||
argc--; argv++;
|
||||
|
||||
if (argc == 0) {
|
||||
Usage ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (argc != 0) {
|
||||
if (strcmp (*argv, "-f") == 0 || strcmp (*argv, "--force") == 0) {
|
||||
ForcePatch = TRUE;
|
||||
} else if (strcmp (*argv, "-p") == 0 || strcmp (*argv, "--parse") == 0) {
|
||||
DoParse = TRUE;
|
||||
argc--; argv++;
|
||||
if (argc < 1) {
|
||||
Usage ();
|
||||
return -1;
|
||||
}
|
||||
SrcImage = *argv;
|
||||
} else if (strcmp (*argv, "-g") == 0 || strcmp (*argv, "--patch") == 0) {
|
||||
DoParse = FALSE;
|
||||
argc--; argv++;
|
||||
if (argc < 2) {
|
||||
Usage ();
|
||||
return -1;
|
||||
}
|
||||
SrcImage = *argv;
|
||||
argc--; argv++;
|
||||
DstImage = *argv;
|
||||
} else if (strcmp (*argv, "-m") == 0 || strcmp (*argv, "--mbr") == 0) {
|
||||
ProcessMbr = TRUE;
|
||||
} else if (strcmp (*argv, "-v") == 0 || strcmp (*argv, "--verbose") == 0) {
|
||||
Verbose = TRUE;
|
||||
} else if (strcmp (*argv, "--version") == 0) {
|
||||
Version();
|
||||
return 0;
|
||||
} else if ((stricmp (*argv, "-d") == 0) || (stricmp (*argv, "--debug") == 0)) {
|
||||
argc--; argv++;
|
||||
if (argc < 1) {
|
||||
Usage ();
|
||||
return -1;
|
||||
}
|
||||
EfiStatus = AsciiStringToUint64 (*argv, FALSE, &LogLevel);
|
||||
if (EFI_ERROR (EfiStatus)) {
|
||||
Error (NULL, 0, 1003, "Invalid option value", "%s = %s", "--debug", *argv);
|
||||
return 1;
|
||||
}
|
||||
if (LogLevel > 9) {
|
||||
Error (NULL, 0, 1003, "Invalid option value", "Debug Level range is 0-9, currnt input level is %d", (int) LogLevel);
|
||||
return 1;
|
||||
}
|
||||
SetPrintLevel (LogLevel);
|
||||
DebugMsg (NULL, 0, 9, "Debug Mode Set", "Debug Output Mode Level %s is set!", *argv);
|
||||
} else {
|
||||
Usage ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
if (ForcePatch && DoParse) {
|
||||
printf ("ERROR: E1002: Conflicting options: -f, -p. Cannot apply force(-f) to parse(-p)!\n");
|
||||
Usage ();
|
||||
return -1;
|
||||
}
|
||||
if (ForcePatch && !DoParse && ProcessMbr) {
|
||||
printf ("ERROR: E1002: Conflicting options: -f, -g -m. Cannot apply force(-f) to processing MBR (-g -m)!\n");
|
||||
Usage ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Verbose) {
|
||||
SetPrintLevel (VERBOSE_LOG_LEVEL);
|
||||
} else {
|
||||
SetPrintLevel (KEY_LOG_LEVEL);
|
||||
}
|
||||
|
||||
if (DoParse) {
|
||||
if (ProcessMbr) {
|
||||
ParseMbr (SrcImage);
|
||||
} else {
|
||||
ParseBootSector (SrcImage);
|
||||
}
|
||||
} else {
|
||||
if (ProcessMbr) {
|
||||
PatchMbr (DstImage, SrcImage);
|
||||
} else {
|
||||
PatchBootSector (DstImage, SrcImage, ForcePatch);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,152 +0,0 @@
|
||||
/** @file
|
||||
|
||||
Fat file system structure and definition.
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _FAT_BPB_H_
|
||||
#define _FAT_BPB_H_
|
||||
|
||||
#include "CommonLib.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct {
|
||||
//
|
||||
// Fat common field
|
||||
//
|
||||
UINT8 BS_jmpBoot[3];
|
||||
CHAR8 BS_OEMName[8];
|
||||
UINT16 BPB_BytsPerSec;
|
||||
UINT8 BPB_SecPerClus;
|
||||
UINT16 BPB_RsvdSecCnt;
|
||||
UINT8 BPB_NumFATs;
|
||||
UINT16 BPB_RootEntCnt;
|
||||
UINT16 BPB_TotSec16;
|
||||
UINT8 BPB_Media;
|
||||
UINT16 BPB_FATSz16;
|
||||
UINT16 BPB_SecPerTrk;
|
||||
UINT16 BPB_NumHeads;
|
||||
UINT32 BPB_HiddSec;
|
||||
UINT32 BPB_TotSec32;
|
||||
|
||||
//
|
||||
// Fat12/16 specific field
|
||||
//
|
||||
UINT8 BS_DrvNum;
|
||||
UINT8 BS_Reserved1;
|
||||
UINT8 BS_BootSig;
|
||||
UINT32 BS_VolID;
|
||||
CHAR8 BS_VolLab[11];
|
||||
CHAR8 BS_FilSysType[8];
|
||||
|
||||
//
|
||||
// Boot Code and Data
|
||||
//
|
||||
UINT8 Reserved[448];
|
||||
|
||||
//
|
||||
// Fat common signature - 0xAA55
|
||||
//
|
||||
UINT16 Signature;
|
||||
} FAT12_16_BPB_STRUCT;
|
||||
|
||||
typedef struct {
|
||||
//
|
||||
// Fat common field
|
||||
//
|
||||
UINT8 BS_jmpBoot[3];
|
||||
CHAR8 BS_OEMName[8];
|
||||
UINT16 BPB_BytsPerSec;
|
||||
UINT8 BPB_SecPerClus;
|
||||
UINT16 BPB_RsvdSecCnt;
|
||||
UINT8 BPB_NumFATs;
|
||||
UINT16 BPB_RootEntCnt;
|
||||
UINT16 BPB_TotSec16;
|
||||
UINT8 BPB_Media;
|
||||
UINT16 BPB_FATSz16;
|
||||
UINT16 BPB_SecPerTrk;
|
||||
UINT16 BPB_NumHeads;
|
||||
UINT32 BPB_HiddSec;
|
||||
UINT32 BPB_TotSec32;
|
||||
|
||||
//
|
||||
// Fat32 specific field
|
||||
//
|
||||
UINT32 BPB_FATSz32;
|
||||
UINT16 BPB_ExtFlags;
|
||||
UINT16 BPB_FSVer;
|
||||
UINT32 BPB_RootClus;
|
||||
UINT16 BPB_FSInfo;
|
||||
UINT16 BPB_BkBootSec;
|
||||
UINT8 BPB_Reserved[12];
|
||||
UINT8 BS_DrvNum;
|
||||
UINT8 BS_Reserved1;
|
||||
UINT8 BS_BootSig;
|
||||
UINT32 BS_VolID;
|
||||
CHAR8 BS_VolLab[11];
|
||||
CHAR8 BS_FilSysType[8];
|
||||
|
||||
//
|
||||
// Boot Code and Data
|
||||
//
|
||||
UINT8 Reserved[420];
|
||||
|
||||
//
|
||||
// Fat common signature - 0xAA55
|
||||
//
|
||||
UINT16 Signature;
|
||||
} FAT32_BPB_STRUCT;
|
||||
|
||||
typedef union {
|
||||
FAT12_16_BPB_STRUCT Fat12_16;
|
||||
FAT32_BPB_STRUCT Fat32;
|
||||
} FAT_BPB_STRUCT;
|
||||
|
||||
typedef enum {
|
||||
FatTypeUnknown,
|
||||
FatTypeFat12,
|
||||
FatTypeFat16,
|
||||
FatTypeFat32,
|
||||
FatTypeMax
|
||||
} FAT_TYPE;
|
||||
|
||||
typedef struct {
|
||||
CHAR8 DIR_Name[11];
|
||||
UINT8 DIR_Attr;
|
||||
UINT8 DIR_NTRes;
|
||||
UINT8 DIR_CrtTimeTenth;
|
||||
UINT16 DIR_CrtTime;
|
||||
UINT16 DIR_CrtDate;
|
||||
UINT16 DIR_LstAccDate;
|
||||
UINT16 DIR_FstClusHI;
|
||||
UINT16 DIR_WrtTime;
|
||||
UINT16 DIR_WrtDate;
|
||||
UINT16 DIR_FstClusLO;
|
||||
UINT32 DIR_FileSize;
|
||||
} FAT_DIRECTORY_ENTRY;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define FAT_MAX_FAT12_CLUSTER 0xFF5
|
||||
#define FAT_MAX_FAT16_CLUSTER 0xFFF5
|
||||
|
||||
#define FAT_BS_SIGNATURE 0xAA55
|
||||
#define FAT_BS_BOOTSIG 0x29
|
||||
#define FAT_BS_JMP1 0xEB
|
||||
#define FAT_BS_JMP2 0xE9
|
||||
#define FAT_FILSYSTYPE "FAT "
|
||||
#define FAT12_FILSYSTYPE "FAT12 "
|
||||
#define FAT16_FILSYSTYPE "FAT16 "
|
||||
#define FAT32_FILSYSTYPE "FAT32 "
|
||||
|
||||
#endif
|
@ -1,58 +0,0 @@
|
||||
/** @file
|
||||
|
||||
MBR Partition Entry and Table structure defintions.
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _MBR_H_
|
||||
#define _MBR_H_
|
||||
|
||||
#include "CommonLib.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
#define MAX_MBR_PARTITIONS 4
|
||||
|
||||
//
|
||||
// MBR Partition Entry
|
||||
//
|
||||
typedef struct {
|
||||
UINT8 BootIndicator;
|
||||
UINT8 StartHead;
|
||||
UINT8 StartSector;
|
||||
UINT8 StartTrack;
|
||||
UINT8 OSType;
|
||||
UINT8 EndHead;
|
||||
UINT8 EndSector;
|
||||
UINT8 EndTrack;
|
||||
UINT32 StartingLBA;
|
||||
UINT32 SizeInLBA;
|
||||
} MBR_PARTITION_RECORD;
|
||||
|
||||
//
|
||||
// MBR Partition table
|
||||
//
|
||||
typedef struct {
|
||||
UINT8 BootCode[440];
|
||||
UINT32 UniqueMbrSignature;
|
||||
UINT16 Unknown;
|
||||
MBR_PARTITION_RECORD PartitionRecord[MAX_MBR_PARTITIONS];
|
||||
UINT16 Signature;
|
||||
} MASTER_BOOT_RECORD;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define MBR_SIGNATURE 0xAA55
|
||||
#define EXTENDED_DOS_PARTITION 0x05
|
||||
#define EXTENDED_WINDOWS_PARTITION 0x0F
|
||||
|
||||
#endif
|
@ -882,72 +882,6 @@ InternalSafeStringNoStrOverlap (
|
||||
return !InternalSafeStringIsOverlap (Str1, Size1 * sizeof(CHAR16), Str2, Size2 * sizeof(CHAR16));
|
||||
}
|
||||
|
||||
RETURN_STATUS
|
||||
StrDecimalToUintnS (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
UINTN *Data
|
||||
)
|
||||
{
|
||||
ASSERT (((UINTN) String & BIT0) == 0);
|
||||
|
||||
//
|
||||
// 1. Neither String nor Data shall be a null pointer.
|
||||
//
|
||||
SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);
|
||||
SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);
|
||||
|
||||
//
|
||||
// 2. The length of String shall not be greater than RSIZE_MAX.
|
||||
//
|
||||
if (RSIZE_MAX != 0) {
|
||||
SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (EndPointer != NULL) {
|
||||
*EndPointer = (CHAR16 *) String;
|
||||
}
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
//
|
||||
while ((*String == L' ') || (*String == L'\t')) {
|
||||
String++;
|
||||
}
|
||||
|
||||
//
|
||||
// Ignore leading Zeros after the spaces
|
||||
//
|
||||
while (*String == L'0') {
|
||||
String++;
|
||||
}
|
||||
|
||||
*Data = 0;
|
||||
|
||||
while (InternalIsDecimalDigitCharacter (*String)) {
|
||||
//
|
||||
// If the number represented by String overflows according to the range
|
||||
// defined by UINTN, then MAX_UINTN is stored in *Data and
|
||||
// RETURN_UNSUPPORTED is returned.
|
||||
//
|
||||
if (*Data > ((MAX_UINTN - (*String - L'0')) / 10)) {
|
||||
*Data = MAX_UINTN;
|
||||
if (EndPointer != NULL) {
|
||||
*EndPointer = (CHAR16 *) String;
|
||||
}
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
*Data = *Data * 10 + (*String - L'0');
|
||||
String++;
|
||||
}
|
||||
|
||||
if (EndPointer != NULL) {
|
||||
*EndPointer = (CHAR16 *) String;
|
||||
}
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Convert a Null-terminated Unicode decimal string to a value of type UINT64.
|
||||
|
||||
@ -1064,9 +998,9 @@ StrDecimalToUint64S (
|
||||
|
||||
/**
|
||||
Convert a Null-terminated Unicode hexadecimal string to a value of type
|
||||
UINTN.
|
||||
UINT64.
|
||||
|
||||
This function outputs a value of type UINTN by interpreting the contents of
|
||||
This function outputs a value of type UINT64 by interpreting the contents of
|
||||
the Unicode string specified by String as a hexadecimal number. The format of
|
||||
the input Unicode string String is:
|
||||
|
||||
@ -1091,8 +1025,8 @@ StrDecimalToUint64S (
|
||||
|
||||
If String has no valid hexadecimal digits in the above format, then 0 is
|
||||
stored at the location pointed to by Data.
|
||||
If the number represented by String exceeds the range defined by UINTN, then
|
||||
MAX_UINTN is stored at the location pointed to by Data.
|
||||
If the number represented by String exceeds the range defined by UINT64, then
|
||||
MAX_UINT64 is stored at the location pointed to by Data.
|
||||
|
||||
If EndPointer is not NULL, a pointer to the character that stopped the scan
|
||||
is stored at the location pointed to by EndPointer. If String has no valid
|
||||
@ -1112,86 +1046,10 @@ StrDecimalToUint64S (
|
||||
characters, not including the
|
||||
Null-terminator.
|
||||
@retval RETURN_UNSUPPORTED If the number represented by String exceeds
|
||||
the range defined by UINTN.
|
||||
the range defined by UINT64.
|
||||
|
||||
**/
|
||||
RETURN_STATUS
|
||||
StrHexToUintnS (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
UINTN *Data
|
||||
)
|
||||
{
|
||||
ASSERT (((UINTN) String & BIT0) == 0);
|
||||
|
||||
//
|
||||
// 1. Neither String nor Data shall be a null pointer.
|
||||
//
|
||||
SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER);
|
||||
SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER);
|
||||
|
||||
//
|
||||
// 2. The length of String shall not be greater than RSIZE_MAX.
|
||||
//
|
||||
if (RSIZE_MAX != 0) {
|
||||
SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if (EndPointer != NULL) {
|
||||
*EndPointer = (CHAR16 *) String;
|
||||
}
|
||||
|
||||
//
|
||||
// Ignore the pad spaces (space or tab)
|
||||
//
|
||||
while ((*String == L' ') || (*String == L'\t')) {
|
||||
String++;
|
||||
}
|
||||
|
||||
//
|
||||
// Ignore leading Zeros after the spaces
|
||||
//
|
||||
while (*String == L'0') {
|
||||
String++;
|
||||
}
|
||||
|
||||
if (InternalCharToUpper (*String) == L'X') {
|
||||
if (*(String - 1) != L'0') {
|
||||
*Data = 0;
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
//
|
||||
// Skip the 'X'
|
||||
//
|
||||
String++;
|
||||
}
|
||||
|
||||
*Data = 0;
|
||||
|
||||
while (InternalIsHexaDecimalDigitCharacter (*String)) {
|
||||
//
|
||||
// If the number represented by String overflows according to the range
|
||||
// defined by UINTN, then MAX_UINTN is stored in *Data and
|
||||
// RETURN_UNSUPPORTED is returned.
|
||||
//
|
||||
if (*Data > ((MAX_UINTN - InternalHexCharToUintn (*String)) >> 4)) {
|
||||
*Data = MAX_UINTN;
|
||||
if (EndPointer != NULL) {
|
||||
*EndPointer = (CHAR16 *) String;
|
||||
}
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
*Data = (*Data << 4) + InternalHexCharToUintn (*String);
|
||||
String++;
|
||||
}
|
||||
|
||||
if (EndPointer != NULL) {
|
||||
*EndPointer = (CHAR16 *) String;
|
||||
}
|
||||
return RETURN_SUCCESS;
|
||||
}
|
||||
RETURN_STATUS
|
||||
StrHexToUint64S (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
@ -1291,28 +1149,6 @@ StrHexToUint64 (
|
||||
return Result;
|
||||
}
|
||||
|
||||
UINTN
|
||||
StrDecimalToUintn (
|
||||
CONST CHAR16 *String
|
||||
)
|
||||
{
|
||||
UINTN Result;
|
||||
|
||||
StrDecimalToUintnS (String, (CHAR16 **) NULL, &Result);
|
||||
return Result;
|
||||
}
|
||||
|
||||
UINTN
|
||||
StrHexToUintn (
|
||||
CONST CHAR16 *String
|
||||
)
|
||||
{
|
||||
UINTN Result;
|
||||
|
||||
StrHexToUintnS (String, (CHAR16 **) NULL, &Result);
|
||||
return Result;
|
||||
}
|
||||
|
||||
UINTN
|
||||
StrSize (
|
||||
CONST CHAR16 *String
|
||||
@ -1400,7 +1236,6 @@ InternalAllocateCopyPool (
|
||||
VOID *Memory;
|
||||
|
||||
ASSERT (Buffer != NULL);
|
||||
ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
|
||||
|
||||
Memory = malloc (AllocationSize);
|
||||
if (Memory != NULL) {
|
||||
@ -1785,7 +1620,7 @@ StrToIpv4Address (
|
||||
{
|
||||
RETURN_STATUS Status;
|
||||
UINTN AddressIndex;
|
||||
UINTN Uintn;
|
||||
UINT64 Uint64;
|
||||
EFI_IPv4_ADDRESS LocalAddress;
|
||||
UINT8 LocalPrefixLength;
|
||||
CHAR16 *Pointer;
|
||||
@ -1812,7 +1647,7 @@ StrToIpv4Address (
|
||||
//
|
||||
// Get D or P.
|
||||
//
|
||||
Status = StrDecimalToUintnS ((CONST CHAR16 *) Pointer, &Pointer, &Uintn);
|
||||
Status = StrDecimalToUint64S ((CONST CHAR16 *) Pointer, &Pointer, &Uint64);
|
||||
if (RETURN_ERROR (Status)) {
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
@ -1820,18 +1655,18 @@ StrToIpv4Address (
|
||||
//
|
||||
// It's P.
|
||||
//
|
||||
if (Uintn > 32) {
|
||||
if (Uint64 > 32) {
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
LocalPrefixLength = (UINT8) Uintn;
|
||||
LocalPrefixLength = (UINT8) Uint64;
|
||||
} else {
|
||||
//
|
||||
// It's D.
|
||||
//
|
||||
if (Uintn > MAX_UINT8) {
|
||||
if (Uint64 > MAX_UINT8) {
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
LocalAddress.Addr[AddressIndex] = (UINT8) Uintn;
|
||||
LocalAddress.Addr[AddressIndex] = (UINT8) Uint64;
|
||||
AddressIndex++;
|
||||
}
|
||||
|
||||
@ -1888,7 +1723,7 @@ StrToIpv6Address (
|
||||
{
|
||||
RETURN_STATUS Status;
|
||||
UINTN AddressIndex;
|
||||
UINTN Uintn;
|
||||
UINT64 Uint64;
|
||||
EFI_IPv6_ADDRESS LocalAddress;
|
||||
UINT8 LocalPrefixLength;
|
||||
CONST CHAR16 *Pointer;
|
||||
@ -1969,7 +1804,7 @@ StrToIpv6Address (
|
||||
//
|
||||
// Get X.
|
||||
//
|
||||
Status = StrHexToUintnS (Pointer, &End, &Uintn);
|
||||
Status = StrHexToUint64S (Pointer, &End, &Uint64);
|
||||
if (RETURN_ERROR (Status) || End - Pointer > 4) {
|
||||
//
|
||||
// Number of hexadecimal digit characters is no more than 4.
|
||||
@ -1978,24 +1813,24 @@ StrToIpv6Address (
|
||||
}
|
||||
Pointer = End;
|
||||
//
|
||||
// Uintn won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4.
|
||||
// Uint64 won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4.
|
||||
//
|
||||
ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr));
|
||||
LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8);
|
||||
LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn;
|
||||
LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uint64 >> 8);
|
||||
LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uint64;
|
||||
AddressIndex += 2;
|
||||
} else {
|
||||
//
|
||||
// Get P, then exit the loop.
|
||||
//
|
||||
Status = StrDecimalToUintnS (Pointer, &End, &Uintn);
|
||||
if (RETURN_ERROR (Status) || End == Pointer || Uintn > 128) {
|
||||
Status = StrDecimalToUint64S (Pointer, &End, &Uint64);
|
||||
if (RETURN_ERROR (Status) || End == Pointer || Uint64 > 128) {
|
||||
//
|
||||
// Prefix length should not exceed 128.
|
||||
//
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
LocalPrefixLength = (UINT8) Uintn;
|
||||
LocalPrefixLength = (UINT8) Uint64;
|
||||
Pointer = End;
|
||||
break;
|
||||
}
|
||||
@ -2252,9 +2087,9 @@ Strtoi (
|
||||
)
|
||||
{
|
||||
if (IsHexStr (Str)) {
|
||||
return StrHexToUintn (Str);
|
||||
return (UINTN)StrHexToUint64 (Str);
|
||||
} else {
|
||||
return StrDecimalToUintn (Str);
|
||||
return (UINTN)StrDecimalToUint64 (Str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
#define MAX_LONG_FILE_PATH 500
|
||||
|
||||
#define MAX_UINTN MAX_ADDRESS
|
||||
#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL)
|
||||
#define MAX_UINT32 ((UINT32)0xFFFFFFFF)
|
||||
#define MAX_UINT16 ((UINT16)0xFFFF)
|
||||
#define MAX_UINT8 ((UINT8)0xFF)
|
||||
#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
|
||||
@ -250,16 +250,6 @@ StrSize (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
UINTN
|
||||
StrHexToUintn (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
UINTN
|
||||
StrDecimalToUintn (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
UINT64
|
||||
StrHexToUint64 (
|
||||
CONST CHAR16 *String
|
||||
@ -277,13 +267,6 @@ StrHexToUint64S (
|
||||
UINT64 *Data
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrHexToUintnS (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
UINTN *Data
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrDecimalToUint64S (
|
||||
CONST CHAR16 *String,
|
||||
@ -291,13 +274,6 @@ StrDecimalToUint64S (
|
||||
UINT64 *Data
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrDecimalToUintnS (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
UINTN *Data
|
||||
);
|
||||
|
||||
VOID *
|
||||
ReallocatePool (
|
||||
UINTN OldSize,
|
||||
|
@ -520,7 +520,7 @@ EisaIdFromText (
|
||||
return (((Text[0] - 'A' + 1) & 0x1f) << 10)
|
||||
+ (((Text[1] - 'A' + 1) & 0x1f) << 5)
|
||||
+ (((Text[2] - 'A' + 1) & 0x1f) << 0)
|
||||
+ (UINT32) (StrHexToUintn (&Text[3]) << 16)
|
||||
+ (UINT32) (StrHexToUint64 (&Text[3]) << 16)
|
||||
;
|
||||
}
|
||||
|
||||
@ -1506,7 +1506,7 @@ DevPathFromTextNVMe (
|
||||
|
||||
Index = sizeof (Nvme->NamespaceUuid) / sizeof (UINT8);
|
||||
while (Index-- != 0) {
|
||||
Uuid[Index] = (UINT8) StrHexToUintn (SplitStr (&NamespaceUuidStr, L'-'));
|
||||
Uuid[Index] = (UINT8) StrHexToUint64 (SplitStr (&NamespaceUuidStr, L'-'));
|
||||
}
|
||||
|
||||
return (EFI_DEVICE_PATH_PROTOCOL *) Nvme;
|
||||
|
@ -62,7 +62,7 @@ IsDevicePathValid (
|
||||
ASSERT (DevicePath != NULL);
|
||||
|
||||
if (MaxSize == 0) {
|
||||
MaxSize = MAX_UINTN;
|
||||
MaxSize = MAX_UINT32;
|
||||
}
|
||||
|
||||
//
|
||||
@ -78,7 +78,7 @@ IsDevicePathValid (
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (NodeLength > MAX_UINTN - Size) {
|
||||
if (NodeLength > MAX_UINT32 - Size) {
|
||||
return FALSE;
|
||||
}
|
||||
Size += NodeLength;
|
||||
|
@ -1,319 +0,0 @@
|
||||
/** @file
|
||||
Creates and EFILDR image.
|
||||
This tool combines several PE Image files together using following format denoted as EBNF:
|
||||
FILE := EFILDR_HEADER
|
||||
EFILDR_IMAGE +
|
||||
<PeImageFileContent> +
|
||||
The order of EFILDR_IMAGE is same as the order of placing PeImageFileContent.
|
||||
|
||||
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ParseInf.h"
|
||||
#include "CommonLib.h"
|
||||
#include "EfiUtilityMsgs.h"
|
||||
|
||||
#define MAX_PE_IMAGES 63
|
||||
#define FILE_TYPE_FIXED_LOADER 0
|
||||
#define FILE_TYPE_RELOCATABLE_PE_IMAGE 1
|
||||
|
||||
typedef struct {
|
||||
UINT32 CheckSum;
|
||||
UINT32 Offset;
|
||||
UINT32 Length;
|
||||
UINT8 FileName[52];
|
||||
} EFILDR_IMAGE;
|
||||
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
UINT32 HeaderCheckSum;
|
||||
UINT32 FileLength;
|
||||
UINT32 NumberOfImages;
|
||||
} EFILDR_HEADER;
|
||||
|
||||
//
|
||||
// Utility Name
|
||||
//
|
||||
#define UTILITY_NAME "EfiLdrImage"
|
||||
|
||||
//
|
||||
// Utility version information
|
||||
//
|
||||
#define UTILITY_MAJOR_VERSION 1
|
||||
#define UTILITY_MINOR_VERSION 0
|
||||
|
||||
void
|
||||
Version (
|
||||
void
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Displays the standard utility information to SDTOUT
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
|
||||
}
|
||||
|
||||
VOID
|
||||
Usage (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
printf ("Usage: EfiLdrImage -o OutImage LoaderImage PeImage1 PeImage2 ... PeImageN\n");
|
||||
printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
|
||||
printf ("Copyright (c) 1999-2017 Intel Corporation. All rights reserved.\n");
|
||||
printf ("\n The EfiLdrImage tool is used to combine PE files into EFILDR image with Efi loader header.\n");
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
CountVerboseLevel (
|
||||
IN CONST CHAR8* VerboseLevelString,
|
||||
IN CONST UINT64 Length,
|
||||
OUT UINT64 *ReturnValue
|
||||
)
|
||||
{
|
||||
UINT64 i = 0;
|
||||
for (;i < Length; ++i) {
|
||||
if (VerboseLevelString[i] != 'v' && VerboseLevelString[i] != 'V') {
|
||||
return EFI_ABORTED;
|
||||
}
|
||||
++(*ReturnValue);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
UINT64
|
||||
FCopyFile (
|
||||
FILE *in,
|
||||
FILE *out
|
||||
)
|
||||
/*++
|
||||
Routine Description:
|
||||
Write all the content of input file to output file.
|
||||
|
||||
Arguments:
|
||||
in - input file pointer
|
||||
out - output file pointer
|
||||
|
||||
Return:
|
||||
UINT64 : file size of input file
|
||||
--*/
|
||||
{
|
||||
UINT32 filesize, offset, length;
|
||||
CHAR8 Buffer[8*1024];
|
||||
|
||||
fseek (in, 0, SEEK_END);
|
||||
filesize = ftell(in);
|
||||
|
||||
fseek (in, 0, SEEK_SET);
|
||||
|
||||
offset = 0;
|
||||
while (offset < filesize) {
|
||||
length = sizeof(Buffer);
|
||||
if (filesize-offset < length) {
|
||||
length = filesize-offset;
|
||||
}
|
||||
|
||||
fread (Buffer, length, 1, in);
|
||||
fwrite (Buffer, length, 1, out);
|
||||
offset += length;
|
||||
}
|
||||
|
||||
return filesize;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char *argv[]
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
|
||||
Arguments:
|
||||
|
||||
|
||||
Returns:
|
||||
|
||||
|
||||
--*/
|
||||
{
|
||||
UINT64 i;
|
||||
UINT64 filesize;
|
||||
FILE *fpIn, *fpOut;
|
||||
EFILDR_HEADER EfiLdrHeader;
|
||||
EFILDR_IMAGE EfiLdrImage[MAX_PE_IMAGES];
|
||||
CHAR8* OutputFileName = NULL;
|
||||
CHAR8* InputFileNames[MAX_PE_IMAGES + 1];
|
||||
UINT8 InputFileCount = 0;
|
||||
UINT64 DebugLevel = 0;
|
||||
UINT64 VerboseLevel = 0;
|
||||
EFI_STATUS Status = EFI_SUCCESS;
|
||||
|
||||
SetUtilityName (UTILITY_NAME);
|
||||
|
||||
if (argc == 1) {
|
||||
printf ("Usage: EfiLdrImage -o OutImage LoaderImage PeImage1 PeImage2 ... PeImageN\n");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
argc --;
|
||||
argv ++;
|
||||
|
||||
if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {
|
||||
Usage();
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (stricmp (argv[0], "--version") == 0) {
|
||||
Version();
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
|
||||
if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--output") == 0)) {
|
||||
OutputFileName = argv[1];
|
||||
if (OutputFileName == NULL) {
|
||||
Error (NULL, 0, 1003, "Invalid option value", "Output file can't be null");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {
|
||||
argc --;
|
||||
argv ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((strlen(argv[0]) >= 2 && argv[0][0] == '-' && (argv[0][1] == 'v' || argv[0][1] == 'V')) || (stricmp (argv[0], "--verbose") == 0)) {
|
||||
VerboseLevel = 1;
|
||||
if (strlen(argv[0]) > 2) {
|
||||
Status = CountVerboseLevel (&argv[0][2], strlen(argv[0]) - 2, &VerboseLevel);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 1003, "Invalid option value", "%s", argv[0]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
argc --;
|
||||
argv ++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {
|
||||
Status = AsciiStringToUint64 (argv[1], FALSE, &DebugLevel);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
continue;
|
||||
}
|
||||
//
|
||||
// Don't recognize the parameter, should be regarded as the input file name.
|
||||
//
|
||||
InputFileNames[InputFileCount] = argv[0];
|
||||
InputFileCount++;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (InputFileCount == 0) {
|
||||
Error (NULL, 0, 1001, "Missing option", "No input file");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
//
|
||||
// Open output file for write
|
||||
//
|
||||
if (OutputFileName == NULL) {
|
||||
Error (NULL, 0, 1001, "Missing option", "No output file");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
fpOut = fopen (LongFilePath (OutputFileName), "w+b");
|
||||
if (!fpOut) {
|
||||
Error (NULL, 0, 0001, "Could not open output file", OutputFileName);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
memset (&EfiLdrHeader, 0, sizeof (EfiLdrHeader));
|
||||
memset (&EfiLdrImage, 0, sizeof (EFILDR_IMAGE) * (InputFileCount));
|
||||
|
||||
memcpy (&EfiLdrHeader.Signature, "EFIL", 4);
|
||||
EfiLdrHeader.FileLength = sizeof(EFILDR_HEADER) + sizeof(EFILDR_IMAGE)*(InputFileCount);
|
||||
|
||||
//
|
||||
// Skip the file header first
|
||||
//
|
||||
fseek (fpOut, EfiLdrHeader.FileLength, SEEK_SET);
|
||||
|
||||
//
|
||||
// copy all the input files to the output file
|
||||
//
|
||||
for(i=0;i<InputFileCount;i++) {
|
||||
//
|
||||
// Copy the content of PeImage file to output file
|
||||
//
|
||||
fpIn = fopen (LongFilePath (InputFileNames[i]), "rb");
|
||||
if (!fpIn) {
|
||||
Error (NULL, 0, 0001, "Could not open input file", InputFileNames[i]);
|
||||
fclose (fpOut);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
filesize = FCopyFile (fpIn, fpOut);
|
||||
fclose(fpIn);
|
||||
|
||||
//
|
||||
// And in the same time update the EfiLdrHeader and EfiLdrImage array
|
||||
//
|
||||
EfiLdrImage[i].Offset = EfiLdrHeader.FileLength;
|
||||
EfiLdrImage[i].Length = (UINT32) filesize;
|
||||
strncpy ((CHAR8*) EfiLdrImage[i].FileName, InputFileNames[i], sizeof (EfiLdrImage[i].FileName) - 1);
|
||||
EfiLdrHeader.FileLength += (UINT32) filesize;
|
||||
EfiLdrHeader.NumberOfImages++;
|
||||
}
|
||||
|
||||
//
|
||||
// Write the image header to the output file finally
|
||||
//
|
||||
fseek (fpOut, 0, SEEK_SET);
|
||||
fwrite (&EfiLdrHeader, sizeof(EFILDR_HEADER) , 1, fpOut);
|
||||
fwrite (&EfiLdrImage , sizeof(EFILDR_IMAGE)*(InputFileCount), 1, fpOut);
|
||||
|
||||
fclose (fpOut);
|
||||
printf ("Created %s\n", OutputFileName);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
## @file
|
||||
# GNU/Linux makefile for 'EfiLdrImage' module build.
|
||||
#
|
||||
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
MAKEROOT ?= ..
|
||||
|
||||
APPNAME = EfiLdrImage
|
||||
|
||||
LIBS = -lCommon
|
||||
|
||||
OBJECTS = EfiLdrImage.o
|
||||
|
||||
include $(MAKEROOT)/Makefiles/app.makefile
|
@ -1,22 +0,0 @@
|
||||
## @file
|
||||
# Windows makefile for 'EfiLdrImage' module build.
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
!INCLUDE ..\Makefiles\ms.common
|
||||
|
||||
APPNAME = EfiLdrImage
|
||||
|
||||
LIBS = $(LIB_PATH)\Common.lib
|
||||
|
||||
OBJECTS = EfiLdrImage.obj
|
||||
|
||||
!INCLUDE ..\Makefiles\ms.app
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user