EmbeddedPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the EmbeddedPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Andrew Fish <afish@apple.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:53:56 -08:00
committed by mergify[bot]
parent 731c67e1d7
commit e7108d0e96
106 changed files with 9242 additions and 7648 deletions

View File

@ -28,12 +28,15 @@ ValidateAndroidMediaDevicePath (
NextNode = DevicePath; NextNode = DevicePath;
while (NextNode != NULL) { while (NextNode != NULL) {
Node = NextNode; Node = NextNode;
if (Node->Type == MEDIA_DEVICE_PATH && if ((Node->Type == MEDIA_DEVICE_PATH) &&
Node->SubType == MEDIA_HARDDRIVE_DP) { (Node->SubType == MEDIA_HARDDRIVE_DP))
{
return EFI_SUCCESS; return EFI_SUCCESS;
} }
NextNode = NextDevicePathNode (Node); NextNode = NextDevicePathNode (Node);
} }
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -56,8 +59,11 @@ AndroidBootAppEntryPoint (
BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath); BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);
ASSERT (BootPathStr != NULL); ASSERT (BootPathStr != NULL);
Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&EfiDevicePathFromTextProtocol); &gEfiDevicePathFromTextProtocolGuid,
NULL,
(VOID **)&EfiDevicePathFromTextProtocol
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
DevicePath = (EFI_DEVICE_PATH *)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr); DevicePath = (EFI_DEVICE_PATH *)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr);
ASSERT (DevicePath != NULL); ASSERT (DevicePath != NULL);
@ -67,8 +73,11 @@ AndroidBootAppEntryPoint (
return Status; return Status;
} }
Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, Status = gBS->LocateDevicePath (
&DevicePath, &Handle); &gEfiDevicePathProtocolGuid,
&DevicePath,
&Handle
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -92,6 +101,7 @@ AndroidBootAppEntryPoint (
if (Buffer == NULL) { if (Buffer == NULL) {
return EFI_BUFFER_TOO_SMALL; return EFI_BUFFER_TOO_SMALL;
} }
/* Load header of boot.img */ /* Load header of boot.img */
Status = BlockIo->ReadBlocks ( Status = BlockIo->ReadBlocks (
BlockIo, BlockIo,
@ -105,6 +115,7 @@ AndroidBootAppEntryPoint (
DEBUG ((DEBUG_ERROR, "Failed to get AndroidBootImg Size: %r\n", Status)); DEBUG ((DEBUG_ERROR, "Failed to get AndroidBootImg Size: %r\n", Status));
return Status; return Status;
} }
BootImgSize = ALIGN_VALUE (BootImgSize, BlockSize); BootImgSize = ALIGN_VALUE (BootImgSize, BlockSize);
FreePages (Buffer, EFI_SIZE_TO_PAGES (sizeof (ANDROID_BOOTIMG_HEADER))); FreePages (Buffer, EFI_SIZE_TO_PAGES (sizeof (ANDROID_BOOTIMG_HEADER)));

View File

@ -32,8 +32,12 @@ ParseAndroidBootImg (
Header = (ANDROID_BOOTIMG_HEADER *)BootImg; Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, if (AsciiStrnCmp (
ANDROID_BOOT_MAGIC_LENGTH) != 0) { (CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -53,8 +57,12 @@ ParseAndroidBootImg (
+ ALIGN_VALUE (Header->KernelSize, Header->PageSize)); + ALIGN_VALUE (Header->KernelSize, Header->PageSize));
} }
AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs, AsciiStrnCpyS (
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE,
Header->KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -122,8 +122,12 @@ HandleDownload (
SEND_LITERAL ("FAILNot enough memory"); SEND_LITERAL ("FAILNot enough memory");
} else { } else {
ZeroMem (Response, sizeof Response); ZeroMem (Response, sizeof Response);
AsciiSPrint (Response, sizeof Response, "DATA%x", AsciiSPrint (
(UINT32)mNumDataBytes); Response,
sizeof Response,
"DATA%x",
(UINT32)mNumDataBytes
);
mTransport->Send (sizeof Response - 1, Response, &mFatalSendErrorEvent); mTransport->Send (sizeof Response - 1, Response, &mFatalSendErrorEvent);
mState = ExpectDataState; mState = ExpectDataState;
@ -214,6 +218,7 @@ HandleBoot (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Failed to boot downloaded image: %r\n", Status)); DEBUG ((DEBUG_ERROR, "Failed to boot downloaded image: %r\n", Status));
} }
// We shouldn't get here // We shouldn't get here
} }
@ -282,6 +287,7 @@ AcceptCmd (
// Here we just reboot normally. // Here we just reboot normally.
SEND_LITERAL ("INFOreboot-bootloader not supported, rebooting normally."); SEND_LITERAL ("INFOreboot-bootloader not supported, rebooting normally.");
} }
SEND_LITERAL ("OKAY"); SEND_LITERAL ("OKAY");
gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
@ -331,7 +337,7 @@ AcceptData (
// Show download progress. Don't do it for every packet as outputting text // Show download progress. Don't do it for every packet as outputting text
// might be time consuming - do it on the last packet and on every 32nd packet // might be time consuming - do it on the last packet and on every 32nd packet
if ((Count++ % 32) == 0 || Size == RemainingBytes) { if (((Count++ % 32) == 0) || (Size == RemainingBytes)) {
// (Note no newline in format string - it will overwrite the line each time) // (Note no newline in format string - it will overwrite the line each time)
UnicodeSPrint ( UnicodeSPrint (
OutputString, OutputString,
@ -380,6 +386,7 @@ DataReady (
} else { } else {
ASSERT (FALSE); ASSERT (FALSE);
} }
FreePool (Data); FreePool (Data);
} }
} while (!EFI_ERROR (Status)); } while (!EFI_ERROR (Status));
@ -448,8 +455,10 @@ FastbootAppEntryPoint (
Status = gBS->LocateProtocol (&gEfiSimpleTextOutProtocolGuid, NULL, (VOID **)&mTextOut); Status = gBS->LocateProtocol (&gEfiSimpleTextOutProtocolGuid, NULL, (VOID **)&mTextOut);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
"Fastboot: Couldn't open Text Output Protocol: %r\n", Status DEBUG_ERROR,
"Fastboot: Couldn't open Text Output Protocol: %r\n",
Status
)); ));
return Status; return Status;
} }
@ -491,7 +500,6 @@ FastbootAppEntryPoint (
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// Start listening for data // Start listening for data
Status = mTransport->Start ( Status = mTransport->Start (
ReceiveEvent ReceiveEvent
@ -502,8 +510,10 @@ FastbootAppEntryPoint (
} }
// Talk to the user // Talk to the user
mTextOut->OutputString (mTextOut, mTextOut->OutputString (
L"Android Fastboot mode - version " ANDROID_FASTBOOT_VERSION ". Press RETURN or SPACE key to quit.\r\n"); mTextOut,
L"Android Fastboot mode - version " ANDROID_FASTBOOT_VERSION ". Press RETURN or SPACE key to quit.\r\n"
);
// Quit when the user presses any key, or mFinishedEvent is signalled // Quit when the user presses any key, or mFinishedEvent is signalled
WaitEventArray[0] = mFinishedEvent; WaitEventArray[0] = mFinishedEvent;
@ -513,7 +523,8 @@ FastbootAppEntryPoint (
Status = TextIn->ReadKeyStroke (gST->ConIn, &Key); Status = TextIn->ReadKeyStroke (gST->ConIn, &Key);
if (Key.ScanCode == SCAN_NULL) { if (Key.ScanCode == SCAN_NULL) {
if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) || if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) ||
(Key.UnicodeChar == L' ')) { (Key.UnicodeChar == L' '))
{
break; break;
} }
} }
@ -523,6 +534,7 @@ FastbootAppEntryPoint (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Warning: Fastboot Transport Stop: %r\n", Status)); DEBUG ((DEBUG_ERROR, "Warning: Fastboot Transport Stop: %r\n", Status));
} }
mPlatform->UnInit (); mPlatform->UnInit ();
return EFI_SUCCESS; return EFI_SUCCESS;

View File

@ -44,7 +44,6 @@ STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =
} // End } // End
}; };
/** /**
Start an EFI Application from a Device Path Start an EFI Application from a Device Path
@ -70,8 +69,14 @@ StartEfiApplication (
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
// Load the image from the device path with Boot Services function // Load the image from the device path with Boot Services function
Status = gBS->LoadImage (TRUE, ParentImageHandle, DevicePath, NULL, 0, Status = gBS->LoadImage (
&ImageHandle); TRUE,
ParentImageHandle,
DevicePath,
NULL,
0,
&ImageHandle
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
// //
// With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created
@ -82,13 +87,17 @@ StartEfiApplication (
if (Status == EFI_SECURITY_VIOLATION) { if (Status == EFI_SECURITY_VIOLATION) {
gBS->UnloadImage (ImageHandle); gBS->UnloadImage (ImageHandle);
} }
return Status; return Status;
} }
// Passed LoadOptions to the EFI Application // Passed LoadOptions to the EFI Application
if (LoadOptionsSize != 0) { if (LoadOptionsSize != 0) {
Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, Status = gBS->HandleProtocol (
(VOID **) &LoadedImage); ImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **)&LoadedImage
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -148,19 +157,26 @@ BootAndroidBootImg (
} }
if (RamdiskSize != 0) { if (RamdiskSize != 0) {
NewLoadOptions = CatSPrint (LoadOptions, L" initrd=0x%x,0x%x", NewLoadOptions = CatSPrint (
(UINTN)Ramdisk, RamdiskSize); LoadOptions,
L" initrd=0x%x,0x%x",
(UINTN)Ramdisk,
RamdiskSize
);
FreePool (LoadOptions); FreePool (LoadOptions);
if (NewLoadOptions == NULL) { if (NewLoadOptions == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
LoadOptions = NewLoadOptions; LoadOptions = NewLoadOptions;
} }
Status = StartEfiApplication (gImageHandle, Status = StartEfiApplication (
gImageHandle,
(EFI_DEVICE_PATH_PROTOCOL *)&KernelDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&KernelDevicePath,
StrSize (LoadOptions), StrSize (LoadOptions),
LoadOptions); LoadOptions
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Couldn't Boot Linux: %d\n", Status)); DEBUG ((DEBUG_ERROR, "Couldn't Boot Linux: %d\n", Status));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;

View File

@ -224,7 +224,6 @@ DataReceived (
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
/* /*
Event notify function to be called when we accept an incoming TCP connection. Event notify function to be called when we accept an incoming TCP connection.
*/ */
@ -247,6 +246,7 @@ ConnectionAccepted (
DEBUG ((DEBUG_ERROR, "TCP Fastboot: Connection Error: %r\n", Status)); DEBUG ((DEBUG_ERROR, "TCP Fastboot: Connection Error: %r\n", Status));
return; return;
} }
DEBUG ((DEBUG_ERROR, "TCP Fastboot: Connection Received.\n")); DEBUG ((DEBUG_ERROR, "TCP Fastboot: Connection Received.\n"));
// //
@ -308,10 +308,16 @@ TcpFastbootTransportStart (
255, // IPv4 Time to Live 255, // IPv4 Time to Live
{ // AccessPoint: { // AccessPoint:
TRUE, // Use default address TRUE, // Use default address
{ {0, 0, 0, 0} }, // IP Address (ignored - use default) {
{ {0, 0, 0, 0} }, // Subnet mask (ignored - use default) { 0, 0, 0, 0 }
}, // IP Address (ignored - use default)
{
{ 0, 0, 0, 0 }
}, // Subnet mask (ignored - use default)
FixedPcdGet32 (PcdAndroidFastbootTcpPort), // Station port FixedPcdGet32 (PcdAndroidFastbootTcpPort), // Station port
{ {0, 0, 0, 0} }, // Remote address: accept any {
{ 0, 0, 0, 0 }
}, // Remote address: accept any
0, // Remote Port: accept any 0, // Remote Port: accept any
FALSE // ActiveFlag: be a "server" FALSE // ActiveFlag: be a "server"
}, },
@ -414,13 +420,17 @@ TcpFastbootTransportStart (
if (Status == EFI_NO_MAPPING) { if (Status == EFI_NO_MAPPING) {
// Wait until the IP configuration process (probably DHCP) has finished // Wait until the IP configuration process (probably DHCP) has finished
do { do {
Status = mTcpListener->GetModeData (mTcpListener, Status = mTcpListener->GetModeData (
NULL, NULL, mTcpListener,
NULL,
NULL,
&Ip4ModeData, &Ip4ModeData,
NULL, NULL NULL,
NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} while (!Ip4ModeData.IsConfigured); } while (!Ip4ModeData.IsConfigured);
Status = mTcpListener->Configure (mTcpListener, &TcpConfigData); Status = mTcpListener->Configure (mTcpListener, &TcpConfigData);
} else if (EFI_ERROR (Status)) { } else if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "TCP Configure: %r\n", Status)); DEBUG ((DEBUG_ERROR, "TCP Configure: %r\n", Status));
@ -494,7 +504,6 @@ TcpFastbootTransportStop (
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
gBS->CloseEvent (mAcceptToken.CompletionToken.Event); gBS->CloseEvent (mAcceptToken.CompletionToken.Event);
// Stop listening for connections. // Stop listening for connections.
@ -514,6 +523,7 @@ TcpFastbootTransportStop (
if (Entry->Buffer) { if (Entry->Buffer) {
FreePool (Entry->Buffer); FreePool (Entry->Buffer);
} }
FreePool (Entry); FreePool (Entry);
Entry = NextEntry; Entry = NextEntry;
@ -591,7 +601,6 @@ TcpFastbootTransportSend (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
TcpFastbootTransportReceive ( TcpFastbootTransportReceive (
OUT UINTN *BufferSize, OUT UINTN *BufferSize,
@ -635,7 +644,6 @@ TcpFastbootTransportEntryPoint (
{ {
EFI_STATUS Status; EFI_STATUS Status;
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEfiSimpleTextOutProtocolGuid, &gEfiSimpleTextOutProtocolGuid,
NULL, NULL,

View File

@ -40,7 +40,6 @@ typedef struct _FASTBOOT_USB_PACKET_LIST {
UINTN BufferSize; UINTN BufferSize;
} FASTBOOT_USB_PACKET_LIST; } FASTBOOT_USB_PACKET_LIST;
/* /*
No string descriptors - all string descriptor members are set to 0 No string descriptors - all string descriptor members are set to 0
*/ */

View File

@ -69,27 +69,34 @@ InstallHiiPages (
EFI_HANDLE DriverHandle; EFI_HANDLE DriverHandle;
DriverHandle = NULL; DriverHandle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (&DriverHandle, Status = gBS->InstallMultipleProtocolInterfaces (
&DriverHandle,
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
&mConsolePrefDxeVendorDevicePath, &mConsolePrefDxeVendorDevicePath,
NULL); NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
HiiHandle = HiiAddPackages (&gConsolePrefFormSetGuid, HiiHandle = HiiAddPackages (
&gConsolePrefFormSetGuid,
DriverHandle, DriverHandle,
ConsolePrefDxeStrings, ConsolePrefDxeStrings,
ConsolePrefHiiBin, ConsolePrefHiiBin,
NULL); NULL
);
if (HiiHandle == NULL) { if (HiiHandle == NULL) {
gBS->UninstallMultipleProtocolInterfaces (DriverHandle, gBS->UninstallMultipleProtocolInterfaces (
DriverHandle,
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
&mConsolePrefDxeVendorDevicePath, &mConsolePrefDxeVendorDevicePath,
NULL); NULL
);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -106,8 +113,12 @@ RemoveDtStdoutPath (
Status = EfiGetSystemConfigurationTable (&gFdtTableGuid, &Dtb); Status = EfiGetSystemConfigurationTable (&gFdtTableGuid, &Dtb);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "%a: could not retrieve DT blob - %r\n", __FUNCTION__, DEBUG ((
Status)); DEBUG_INFO,
"%a: could not retrieve DT blob - %r\n",
__FUNCTION__,
Status
));
return; return;
} }
@ -118,8 +129,12 @@ RemoveDtStdoutPath (
Error = fdt_delprop (Dtb, Node, "stdout-path"); Error = fdt_delprop (Dtb, Node, "stdout-path");
if (Error) { if (Error) {
DEBUG ((DEBUG_INFO, "%a: Failed to delete 'stdout-path' property: %a\n", DEBUG ((
__FUNCTION__, fdt_strerror (Error))); DEBUG_INFO,
"%a: Failed to delete 'stdout-path' property: %a\n",
__FUNCTION__,
fdt_strerror (Error)
));
} }
} }
@ -137,8 +152,11 @@ RemoveSpcrTable (
EFI_ACPI_TABLE_VERSION TableVersion; EFI_ACPI_TABLE_VERSION TableVersion;
UINTN TableKey; UINTN TableKey;
Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&AcpiTable); &gEfiAcpiTableProtocolGuid,
NULL,
(VOID **)&AcpiTable
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return; return;
} }
@ -153,8 +171,12 @@ RemoveSpcrTable (
TableHeader = NULL; TableHeader = NULL;
do { do {
Status = Sdt->GetAcpiTable (TableIndex++, &TableHeader, &TableVersion, Status = Sdt->GetAcpiTable (
&TableKey); TableIndex++,
&TableHeader,
&TableVersion,
&TableKey
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
@ -165,9 +187,14 @@ RemoveSpcrTable (
Status = AcpiTable->UninstallAcpiTable (AcpiTable, TableKey); Status = AcpiTable->UninstallAcpiTable (AcpiTable, TableKey);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: failed to uninstall SPCR table - %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_WARN,
"%a: failed to uninstall SPCR table - %r\n",
__FUNCTION__,
Status
));
} }
break; break;
} while (TRUE); } while (TRUE);
} }
@ -186,18 +213,29 @@ OnReadyToBoot (
VOID *Gop; VOID *Gop;
BufferSize = sizeof (ConsolePref); BufferSize = sizeof (ConsolePref);
Status = gRT->GetVariable (CONSOLE_PREF_VARIABLE_NAME, Status = gRT->GetVariable (
&gConsolePrefFormSetGuid, NULL, &BufferSize, &ConsolePref); CONSOLE_PREF_VARIABLE_NAME,
&gConsolePrefFormSetGuid,
NULL,
&BufferSize,
&ConsolePref
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
"%a: variable '%s' could not be read - bailing!\n", __FUNCTION__, DEBUG_ERROR,
CONSOLE_PREF_VARIABLE_NAME)); "%a: variable '%s' could not be read - bailing!\n",
__FUNCTION__,
CONSOLE_PREF_VARIABLE_NAME
));
return; return;
} }
if (ConsolePref.Console == CONSOLE_PREF_SERIAL) { if (ConsolePref.Console == CONSOLE_PREF_SERIAL) {
DEBUG ((DEBUG_INFO, DEBUG ((
"%a: serial console preferred - doing nothing\n", __FUNCTION__)); DEBUG_INFO,
"%a: serial console preferred - doing nothing\n",
__FUNCTION__
));
return; return;
} }
@ -206,9 +244,12 @@ OnReadyToBoot (
// //
Status = gBS->LocateProtocol (&gEfiGraphicsOutputProtocolGuid, NULL, &Gop); Status = gBS->LocateProtocol (&gEfiGraphicsOutputProtocolGuid, NULL, &Gop);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, DEBUG ((
"%a: no GOP instances found - doing nothing (%r)\n", __FUNCTION__, DEBUG_INFO,
Status)); "%a: no GOP instances found - doing nothing (%r)\n",
__FUNCTION__,
Status
));
return; return;
} }
@ -244,20 +285,32 @@ ConsolePrefDxeEntryPoint (
// Get the current console preference from the ConsolePref variable. // Get the current console preference from the ConsolePref variable.
// //
BufferSize = sizeof (ConsolePref); BufferSize = sizeof (ConsolePref);
Status = gRT->GetVariable (CONSOLE_PREF_VARIABLE_NAME, Status = gRT->GetVariable (
&gConsolePrefFormSetGuid, NULL, &BufferSize, &ConsolePref); CONSOLE_PREF_VARIABLE_NAME,
&gConsolePrefFormSetGuid,
NULL,
&BufferSize,
&ConsolePref
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, DEBUG ((
DEBUG_INFO,
"%a: no console preference found, defaulting to graphical\n", "%a: no console preference found, defaulting to graphical\n",
__FUNCTION__)); __FUNCTION__
));
ConsolePref.Console = CONSOLE_PREF_GRAPHICAL; ConsolePref.Console = CONSOLE_PREF_GRAPHICAL;
} }
if (!EFI_ERROR (Status) && if (!EFI_ERROR (Status) &&
ConsolePref.Console != CONSOLE_PREF_GRAPHICAL && (ConsolePref.Console != CONSOLE_PREF_GRAPHICAL) &&
ConsolePref.Console != CONSOLE_PREF_SERIAL) { (ConsolePref.Console != CONSOLE_PREF_SERIAL))
DEBUG ((DEBUG_WARN, "%a: invalid value for %s, defaulting to graphical\n", {
__FUNCTION__, CONSOLE_PREF_VARIABLE_NAME)); DEBUG ((
DEBUG_WARN,
"%a: invalid value for %s, defaulting to graphical\n",
__FUNCTION__,
CONSOLE_PREF_VARIABLE_NAME
));
ConsolePref.Console = CONSOLE_PREF_GRAPHICAL; ConsolePref.Console = CONSOLE_PREF_GRAPHICAL;
Status = EFI_INVALID_PARAMETER; // trigger setvar below Status = EFI_INVALID_PARAMETER; // trigger setvar below
} }
@ -267,21 +320,33 @@ ConsolePrefDxeEntryPoint (
// //
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
ZeroMem (&ConsolePref.Reserved, sizeof (ConsolePref.Reserved)); ZeroMem (&ConsolePref.Reserved, sizeof (ConsolePref.Reserved));
Status = gRT->SetVariable (CONSOLE_PREF_VARIABLE_NAME, Status = gRT->SetVariable (
CONSOLE_PREF_VARIABLE_NAME,
&gConsolePrefFormSetGuid, &gConsolePrefFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (ConsolePref), &ConsolePref); sizeof (ConsolePref),
&ConsolePref
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: gRT->SetVariable () failed - %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_ERROR,
"%a: gRT->SetVariable () failed - %r\n",
__FUNCTION__,
Status
));
return Status; return Status;
} }
} }
Status = gBS->CreateEventEx (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, Status = gBS->CreateEventEx (
OnReadyToBoot, NULL, &gEfiEventReadyToBootGuid, EVT_NOTIFY_SIGNAL,
&mReadyToBootEvent); TPL_CALLBACK,
OnReadyToBoot,
NULL,
&gEfiEventReadyToBootGuid,
&mReadyToBootEvent
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return InstallHiiPages (); return InstallHiiPages ();

View File

@ -59,27 +59,34 @@ InstallHiiPages (
EFI_HANDLE DriverHandle; EFI_HANDLE DriverHandle;
DriverHandle = NULL; DriverHandle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (&DriverHandle, Status = gBS->InstallMultipleProtocolInterfaces (
&DriverHandle,
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
&mDtPlatformDxeVendorDevicePath, &mDtPlatformDxeVendorDevicePath,
NULL); NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
HiiHandle = HiiAddPackages (&gDtPlatformFormSetGuid, HiiHandle = HiiAddPackages (
&gDtPlatformFormSetGuid,
DriverHandle, DriverHandle,
DtPlatformDxeStrings, DtPlatformDxeStrings,
DtPlatformHiiBin, DtPlatformHiiBin,
NULL); NULL
);
if (HiiHandle == NULL) { if (HiiHandle == NULL) {
gBS->UninstallMultipleProtocolInterfaces (DriverHandle, gBS->UninstallMultipleProtocolInterfaces (
DriverHandle,
&gEfiDevicePathProtocolGuid, &gEfiDevicePathProtocolGuid,
&mDtPlatformDxeVendorDevicePath, &mDtPlatformDxeVendorDevicePath,
NULL); NULL
);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -112,31 +119,48 @@ DtPlatformDxeEntryPoint (
Dtb = NULL; Dtb = NULL;
Status = DtPlatformLoadDtb (&Dtb, &DtbSize); Status = DtPlatformLoadDtb (&Dtb, &DtbSize);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"%a: no DTB blob could be loaded, defaulting to ACPI (Status == %r)\n", "%a: no DTB blob could be loaded, defaulting to ACPI (Status == %r)\n",
__FUNCTION__, Status)); __FUNCTION__,
Status
));
DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI; DtAcpiPref.Pref = DT_ACPI_SELECT_ACPI;
} else { } else {
// //
// Get the current DT/ACPI preference from the DtAcpiPref variable. // Get the current DT/ACPI preference from the DtAcpiPref variable.
// //
BufferSize = sizeof (DtAcpiPref); BufferSize = sizeof (DtAcpiPref);
Status = gRT->GetVariable(DT_ACPI_VARIABLE_NAME, &gDtPlatformFormSetGuid, Status = gRT->GetVariable (
NULL, &BufferSize, &DtAcpiPref); DT_ACPI_VARIABLE_NAME,
&gDtPlatformFormSetGuid,
NULL,
&BufferSize,
&DtAcpiPref
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "%a: no DT/ACPI preference found, defaulting to %a\n", DEBUG ((
__FUNCTION__, PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI")); DEBUG_WARN,
"%a: no DT/ACPI preference found, defaulting to %a\n",
__FUNCTION__,
PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"
));
DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT
: DT_ACPI_SELECT_ACPI; : DT_ACPI_SELECT_ACPI;
} }
} }
if (!EFI_ERROR (Status) && if (!EFI_ERROR (Status) &&
DtAcpiPref.Pref != DT_ACPI_SELECT_ACPI && (DtAcpiPref.Pref != DT_ACPI_SELECT_ACPI) &&
DtAcpiPref.Pref != DT_ACPI_SELECT_DT) { (DtAcpiPref.Pref != DT_ACPI_SELECT_DT))
DEBUG ((DEBUG_WARN, "%a: invalid value for %s, defaulting to %a\n", {
__FUNCTION__, DT_ACPI_VARIABLE_NAME, DEBUG ((
PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI")); DEBUG_WARN,
"%a: invalid value for %s, defaulting to %a\n",
__FUNCTION__,
DT_ACPI_VARIABLE_NAME,
PcdGetBool (PcdDefaultDtPref) ? "DT" : "ACPI"
));
DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT DtAcpiPref.Pref = PcdGetBool (PcdDefaultDtPref) ? DT_ACPI_SELECT_DT
: DT_ACPI_SELECT_ACPI; : DT_ACPI_SELECT_ACPI;
Status = EFI_INVALID_PARAMETER; // trigger setvar below Status = EFI_INVALID_PARAMETER; // trigger setvar below
@ -146,9 +170,13 @@ DtPlatformDxeEntryPoint (
// Write the newly selected default value back to the variable store. // Write the newly selected default value back to the variable store.
// //
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
Status = gRT->SetVariable(DT_ACPI_VARIABLE_NAME, &gDtPlatformFormSetGuid, Status = gRT->SetVariable (
DT_ACPI_VARIABLE_NAME,
&gDtPlatformFormSetGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
sizeof (DtAcpiPref), &DtAcpiPref); sizeof (DtAcpiPref),
&DtAcpiPref
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeDtb; goto FreeDtb;
} }
@ -159,12 +187,18 @@ DtPlatformDxeEntryPoint (
// ACPI was selected: install the gEdkiiPlatformHasAcpiGuid GUID as a // ACPI was selected: install the gEdkiiPlatformHasAcpiGuid GUID as a
// NULL protocol to unlock dispatch of ACPI related drivers. // NULL protocol to unlock dispatch of ACPI related drivers.
// //
Status = gBS->InstallMultipleProtocolInterfaces (&ImageHandle, Status = gBS->InstallMultipleProtocolInterfaces (
&gEdkiiPlatformHasAcpiGuid, NULL, NULL); &ImageHandle,
&gEdkiiPlatformHasAcpiGuid,
NULL,
NULL
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n", "%a: failed to install gEdkiiPlatformHasAcpiGuid as a protocol\n",
__FUNCTION__)); __FUNCTION__
));
goto FreeDtb; goto FreeDtb;
} }
} else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) { } else if (DtAcpiPref.Pref == DT_ACPI_SELECT_DT) {
@ -174,8 +208,11 @@ DtPlatformDxeEntryPoint (
// //
Status = gBS->InstallConfigurationTable (&gFdtTableGuid, Dtb); Status = gBS->InstallConfigurationTable (&gFdtTableGuid, Dtb);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to install FDT configuration table\n", DEBUG ((
__FUNCTION__)); DEBUG_ERROR,
"%a: failed to install FDT configuration table\n",
__FUNCTION__
));
goto FreeDtb; goto FreeDtb;
} }
} else { } else {

View File

@ -46,6 +46,7 @@ GetNodeProperty (
if (PropSize != NULL) { if (PropSize != NULL) {
*PropSize = Len; *PropSize = Len;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -90,12 +91,15 @@ IsNodeEnabled (
if (NodeStatus == NULL) { if (NodeStatus == NULL) {
return TRUE; return TRUE;
} }
if (Len >= 5 && AsciiStrCmp (NodeStatus, "okay") == 0) {
if ((Len >= 5) && (AsciiStrCmp (NodeStatus, "okay") == 0)) {
return TRUE; return TRUE;
} }
if (Len >= 3 && AsciiStrCmp (NodeStatus, "ok") == 0) {
if ((Len >= 3) && (AsciiStrCmp (NodeStatus, "ok") == 0)) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
@ -136,13 +140,15 @@ FindNextCompatibleNode (
// compatible strings so check each one // compatible strings so check each one
// //
for (Compatible = Type; Compatible < Type + Len && *Compatible; for (Compatible = Type; Compatible < Type + Len && *Compatible;
Compatible += 1 + AsciiStrLen (Compatible)) { Compatible += 1 + AsciiStrLen (Compatible))
{
if (AsciiStrCmp (CompatibleString, Compatible) == 0) { if (AsciiStrCmp (CompatibleString, Compatible) == 0) {
*Node = Next; *Node = Next;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
} }
} }
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -201,16 +207,25 @@ FindCompatibleNodeReg (
// 8 byte quantities for base and size, respectively. // 8 byte quantities for base and size, respectively.
// TODO use #cells root properties instead // TODO use #cells root properties instead
// //
Status = FindCompatibleNodeProperty (This, CompatibleString, "reg", Reg, Status = FindCompatibleNodeProperty (
RegSize); This,
CompatibleString,
"reg",
Reg,
RegSize
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
if ((*RegSize % 16) != 0) { if ((*RegSize % 16) != 0) {
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: '%a' compatible node has invalid 'reg' property (size == 0x%x)\n", "%a: '%a' compatible node has invalid 'reg' property (size == 0x%x)\n",
__FUNCTION__, CompatibleString, *RegSize)); __FUNCTION__,
CompatibleString,
*RegSize
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -253,7 +268,7 @@ FindNextMemoryNodeReg (
} }
DeviceType = fdt_getprop (mDeviceTreeBase, Next, "device_type", &Len); DeviceType = fdt_getprop (mDeviceTreeBase, Next, "device_type", &Len);
if (DeviceType != NULL && AsciiStrCmp (DeviceType, "memory") == 0) { if ((DeviceType != NULL) && (AsciiStrCmp (DeviceType, "memory") == 0)) {
// //
// Get the 'reg' property of this memory node. For now, we will assume // Get the 'reg' property of this memory node. For now, we will assume
// 8 byte quantities for base and size, respectively. // 8 byte quantities for base and size, respectively.
@ -261,15 +276,21 @@ FindNextMemoryNodeReg (
// //
Status = GetNodeProperty (This, Next, "reg", Reg, RegSize); Status = GetNodeProperty (This, Next, "reg", Reg, RegSize);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"%a: ignoring memory node with no 'reg' property\n", "%a: ignoring memory node with no 'reg' property\n",
__FUNCTION__)); __FUNCTION__
));
continue; continue;
} }
if ((*RegSize % 16) != 0) { if ((*RegSize % 16) != 0) {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"%a: ignoring memory node with invalid 'reg' property (size == 0x%x)\n", "%a: ignoring memory node with invalid 'reg' property (size == 0x%x)\n",
__FUNCTION__, *RegSize)); __FUNCTION__,
*RegSize
));
continue; continue;
} }
@ -279,6 +300,7 @@ FindNextMemoryNodeReg (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
} }
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -294,8 +316,15 @@ FindMemoryNodeReg (
OUT UINT32 *RegSize OUT UINT32 *RegSize
) )
{ {
return FindNextMemoryNodeReg (This, 0, Node, Reg, AddressCells, SizeCells, return FindNextMemoryNodeReg (
RegSize); This,
0,
Node,
Reg,
AddressCells,
SizeCells,
RegSize
);
} }
STATIC STATIC
@ -385,14 +414,19 @@ InitializeFdtClientDxe (
VOID *Registration; VOID *Registration;
Hob = GetFirstGuidHob (&gFdtHobGuid); Hob = GetFirstGuidHob (&gFdtHobGuid);
if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) { if ((Hob == NULL) || (GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64))) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob); DeviceTreeBase = (VOID *)(UINTN)*(UINT64 *)GET_GUID_HOB_DATA (Hob);
if (fdt_check_header (DeviceTreeBase) != 0) { if (fdt_check_header (DeviceTreeBase) != 0) {
DEBUG ((DEBUG_ERROR, "%a: No DTB found @ 0x%p\n", __FUNCTION__, DEBUG ((
DeviceTreeBase)); DEBUG_ERROR,
"%a: No DTB found @ 0x%p\n",
__FUNCTION__,
DeviceTreeBase
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }

View File

@ -138,8 +138,13 @@ NonCoherentIoMmuMap (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
return DmaMap (DmaOperation, HostAddress, NumberOfBytes, return DmaMap (
DeviceAddress, Mapping); DmaOperation,
HostAddress,
NumberOfBytes,
DeviceAddress,
Mapping
);
} }
/** /**
@ -236,7 +241,6 @@ STATIC EDKII_IOMMU_PROTOCOL mNonCoherentIoMmuOps = {
NonCoherentIoMmuFreeBuffer, NonCoherentIoMmuFreeBuffer,
}; };
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
NonCoherentIoMmuDxeEntryPoint ( NonCoherentIoMmuDxeEntryPoint (
@ -244,7 +248,10 @@ NonCoherentIoMmuDxeEntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
return gBS->InstallMultipleProtocolInterfaces (&ImageHandle, return gBS->InstallMultipleProtocolInterfaces (
&gEdkiiIoMmuProtocolGuid, &mNonCoherentIoMmuOps, &ImageHandle,
NULL); &gEdkiiIoMmuProtocolGuid,
&mNonCoherentIoMmuOps,
NULL
);
} }

View File

@ -27,7 +27,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gVirtualKeyboardCompo
"en" "en"
}; };
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mVirtualKeyboardDriverNameTable[] = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mVirtualKeyboardDriverNameTable[] = {
{ {
"eng;en", "eng;en",

View File

@ -10,13 +10,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _VIRTUAL_KEYBOARD_COMPONENT_NAME_H_ #ifndef _VIRTUAL_KEYBOARD_COMPONENT_NAME_H_
#define _VIRTUAL_KEYBOARD_COMPONENT_NAME_H_ #define _VIRTUAL_KEYBOARD_COMPONENT_NAME_H_
extern EFI_COMPONENT_NAME_PROTOCOL gVirtualKeyboardComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gVirtualKeyboardComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gVirtualKeyboardComponentName2; extern EFI_COMPONENT_NAME2_PROTOCOL gVirtualKeyboardComponentName2;
// //
// EFI Component Name Functions // EFI Component Name Functions
// //
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -64,7 +64,6 @@ VirtualKeyboardComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -143,5 +142,4 @@ VirtualKeyboardComponentNameGetControllerName (
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
#endif #endif

View File

@ -59,6 +59,7 @@ VirtualKeyboardDriverBindingSupported (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
gBS->CloseProtocol ( gBS->CloseProtocol (
Controller, Controller,
&gPlatformVirtualKeyboardProtocolGuid, &gPlatformVirtualKeyboardProtocolGuid,
@ -162,6 +163,7 @@ VirtualKeyboardDriverBindingStart (
(VirtualKeyboardPrivate->SimpleTextIn).WaitForKey = NULL; (VirtualKeyboardPrivate->SimpleTextIn).WaitForKey = NULL;
goto Done; goto Done;
} }
Status = gBS->CreateEvent ( Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT, EVT_NOTIFY_WAIT,
TPL_NOTIFY, TPL_NOTIFY,
@ -222,6 +224,7 @@ VirtualKeyboardDriverBindingStart (
DEBUG ((DEBUG_ERROR, "[KBD]Reset Failed. Status - %r\n", Status)); DEBUG ((DEBUG_ERROR, "[KBD]Reset Failed. Status - %r\n", Status));
goto Done; goto Done;
} }
// //
// Install protocol interfaces for the keyboard device. // Install protocol interfaces for the keyboard device.
// //
@ -256,6 +259,7 @@ Done:
if (VirtualKeyboardPrivate->TimerEvent != NULL) { if (VirtualKeyboardPrivate->TimerEvent != NULL) {
gBS->CloseEvent (VirtualKeyboardPrivate->TimerEvent); gBS->CloseEvent (VirtualKeyboardPrivate->TimerEvent);
} }
FreePool (VirtualKeyboardPrivate); FreePool (VirtualKeyboardPrivate);
} }
} }
@ -297,7 +301,6 @@ VirtualKeyboardDriverBindingStop (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Enqueue the key. Enqueue the key.
@ -412,6 +415,7 @@ VirtualKeyboardFreeNotifyList (
if (ListHead == NULL) { if (ListHead == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
while (!IsListEmpty (ListHead)) { while (!IsListEmpty (ListHead)) {
NotifyNode = CR ( NotifyNode = CR (
ListHead->ForwardLink, ListHead->ForwardLink,
@ -450,7 +454,8 @@ IsKeyRegistered (
ASSERT (RegsiteredData != NULL && InputData != NULL); ASSERT (RegsiteredData != NULL && InputData != NULL);
if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) || if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
(RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) { (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar))
{
return FALSE; return FALSE;
} }
@ -459,16 +464,18 @@ IsKeyRegistered (
// these state could be ignored. // these state could be ignored.
// //
if ((RegsiteredData->KeyState.KeyShiftState != 0) && if ((RegsiteredData->KeyState.KeyShiftState != 0) &&
(RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState)) { (RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState))
{
return FALSE; return FALSE;
} }
if ((RegsiteredData->KeyState.KeyToggleState != 0) && if ((RegsiteredData->KeyState.KeyToggleState != 0) &&
(RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState)) { (RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState))
{
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
/** /**
@ -528,12 +535,12 @@ VirtualKeyboardWaitForKeyEx (
VirtualKeyboardPrivate = TEXT_INPUT_EX_VIRTUAL_KEYBOARD_DEV_FROM_THIS (Context); VirtualKeyboardPrivate = TEXT_INPUT_EX_VIRTUAL_KEYBOARD_DEV_FROM_THIS (Context);
VirtualKeyboardWaitForKey (Event, &VirtualKeyboardPrivate->SimpleTextIn); VirtualKeyboardWaitForKey (Event, &VirtualKeyboardPrivate->SimpleTextIn);
} }
// //
// EFI Simple Text In Protocol Functions // EFI Simple Text In Protocol Functions
// //
/** /**
Reset the Keyboard and do BAT test for it, if (ExtendedVerification == TRUE) Reset the Keyboard and do BAT test for it, if (ExtendedVerification == TRUE)
then do some extra keyboard validations. then do some extra keyboard validations.
@ -565,7 +572,8 @@ VirtualKeyboardReset (
OldTpl = gBS->RaiseTPL (TPL_NOTIFY); OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
if (VirtualKeyboardPrivate->PlatformVirtual && if (VirtualKeyboardPrivate->PlatformVirtual &&
VirtualKeyboardPrivate->PlatformVirtual->Reset) { VirtualKeyboardPrivate->PlatformVirtual->Reset)
{
Status = VirtualKeyboardPrivate->PlatformVirtual->Reset (); Status = VirtualKeyboardPrivate->PlatformVirtual->Reset ();
} else { } else {
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
@ -616,7 +624,6 @@ VirtualKeyboardResetEx (
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
@ -643,6 +650,7 @@ KeyboardReadKeyStrokeWorker (
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_TPL OldTpl; EFI_TPL OldTpl;
if (KeyData == NULL) { if (KeyData == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -715,11 +723,13 @@ VirtualKeyboardReadKeyStroke (
// Convert the Ctrl+[a-z] to Ctrl+[1-26] // Convert the Ctrl+[a-z] to Ctrl+[1-26]
// //
if ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) { if ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) {
if (KeyData.Key.UnicodeChar >= L'a' && if ((KeyData.Key.UnicodeChar >= L'a') &&
KeyData.Key.UnicodeChar <= L'z') { (KeyData.Key.UnicodeChar <= L'z'))
{
KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'a' + 1); KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'a' + 1);
} else if (KeyData.Key.UnicodeChar >= L'A' && } else if ((KeyData.Key.UnicodeChar >= L'A') &&
KeyData.Key.UnicodeChar <= L'Z') { (KeyData.Key.UnicodeChar <= L'Z'))
{
KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'A' + 1); KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar - L'A' + 1);
} }
} }
@ -760,7 +770,6 @@ VirtualKeyboardReadKeyStrokeEx (
VirtualKeyboardPrivate = TEXT_INPUT_EX_VIRTUAL_KEYBOARD_DEV_FROM_THIS (This); VirtualKeyboardPrivate = TEXT_INPUT_EX_VIRTUAL_KEYBOARD_DEV_FROM_THIS (This);
return KeyboardReadKeyStrokeWorker (VirtualKeyboardPrivate, KeyData); return KeyboardReadKeyStrokeWorker (VirtualKeyboardPrivate, KeyData);
} }
/** /**
@ -829,9 +838,10 @@ VirtualKeyboardRegisterKeyNotify (
LIST_ENTRY *Link; LIST_ENTRY *Link;
VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify; VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
if (KeyData == NULL || if ((KeyData == NULL) ||
NotifyHandle == NULL || (NotifyHandle == NULL) ||
KeyNotificationFunction == NULL) { (KeyNotificationFunction == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -848,7 +858,8 @@ VirtualKeyboardRegisterKeyNotify (
// //
for (Link = VirtualKeyboardPrivate->NotifyList.ForwardLink; for (Link = VirtualKeyboardPrivate->NotifyList.ForwardLink;
Link != &VirtualKeyboardPrivate->NotifyList; Link != &VirtualKeyboardPrivate->NotifyList;
Link = Link->ForwardLink) { Link = Link->ForwardLink)
{
CurrentNotify = CR ( CurrentNotify = CR (
Link, Link,
VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY, VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY,
@ -888,7 +899,6 @@ Exit:
// //
gBS->RestoreTPL (OldTpl); gBS->RestoreTPL (OldTpl);
return Status; return Status;
} }
/** /**
@ -924,7 +934,8 @@ VirtualKeyboardUnregisterKeyNotify (
} }
if (((VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY *)NotificationHandle)->Signature != if (((VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY *)NotificationHandle)->Signature !=
VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE) { VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE)
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -937,7 +948,8 @@ VirtualKeyboardUnregisterKeyNotify (
for (Link = VirtualKeyboardPrivate->NotifyList.ForwardLink; for (Link = VirtualKeyboardPrivate->NotifyList.ForwardLink;
Link != &VirtualKeyboardPrivate->NotifyList; Link != &VirtualKeyboardPrivate->NotifyList;
Link = Link->ForwardLink) { Link = Link->ForwardLink)
{
CurrentNotify = CR ( CurrentNotify = CR (
Link, Link,
VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY, VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY,
@ -1001,11 +1013,14 @@ VirtualKeyboardTimerHandler (
OldTpl = gBS->RaiseTPL (TPL_NOTIFY); OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
if (VirtualKeyboardPrivate->PlatformVirtual && if (VirtualKeyboardPrivate->PlatformVirtual &&
VirtualKeyboardPrivate->PlatformVirtual->Query) { VirtualKeyboardPrivate->PlatformVirtual->Query)
{
if (VirtualKeyboardPrivate->PlatformVirtual->Query (&VirtualKey) == if (VirtualKeyboardPrivate->PlatformVirtual->Query (&VirtualKey) ==
FALSE) { FALSE)
{
goto Exit; goto Exit;
} }
// Found key // Found key
KeyData.Key.ScanCode = VirtualKey.Key.ScanCode; KeyData.Key.ScanCode = VirtualKey.Key.ScanCode;
KeyData.Key.UnicodeChar = VirtualKey.Key.UnicodeChar; KeyData.Key.UnicodeChar = VirtualKey.Key.UnicodeChar;
@ -1023,7 +1038,8 @@ VirtualKeyboardTimerHandler (
// //
for (Link = VirtualKeyboardPrivate->NotifyList.ForwardLink; for (Link = VirtualKeyboardPrivate->NotifyList.ForwardLink;
Link != &VirtualKeyboardPrivate->NotifyList; Link != &VirtualKeyboardPrivate->NotifyList;
Link = Link->ForwardLink) { Link = Link->ForwardLink)
{
CurrentNotify = CR ( CurrentNotify = CR (
Link, Link,
VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY, VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY,
@ -1091,10 +1107,13 @@ KeyNotifyProcessHandler (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
for (Link = GetFirstNode (NotifyList); for (Link = GetFirstNode (NotifyList);
!IsNull (NotifyList, Link); !IsNull (NotifyList, Link);
Link = GetNextNode (NotifyList, Link)) { Link = GetNextNode (NotifyList, Link))
CurrentNotify = CR (Link, {
CurrentNotify = CR (
Link,
VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY, VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY,
NotifyEntry, NotifyEntry,
VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE VIRTUAL_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE

View File

@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef _VIRTUAL_KEYBOARD_H_ #ifndef _VIRTUAL_KEYBOARD_H_
#define _VIRTUAL_KEYBOARD_H_ #define _VIRTUAL_KEYBOARD_H_
#include <Guid/StatusCodeDataTypeId.h> #include <Guid/StatusCodeDataTypeId.h>
#include <Protocol/DevicePath.h> #include <Protocol/DevicePath.h>
#include <Protocol/PlatformVirtualKeyboard.h> #include <Protocol/PlatformVirtualKeyboard.h>
@ -35,7 +34,6 @@ extern EFI_DRIVER_BINDING_PROTOCOL gVirtualKeyboardDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gVirtualKeyboardComponentName; extern EFI_COMPONENT_NAME_PROTOCOL gVirtualKeyboardComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gVirtualKeyboardComponentName2; extern EFI_COMPONENT_NAME2_PROTOCOL gVirtualKeyboardComponentName2;
// //
// VIRTUAL Keyboard Defines // VIRTUAL Keyboard Defines
// //
@ -222,7 +220,6 @@ VirtualKeyboardComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. that is being managed by a driver.
@ -301,10 +298,10 @@ VirtualKeyboardComponentNameGetControllerName (
OUT CHAR16 **ControllerName OUT CHAR16 **ControllerName
); );
// //
// Simple Text Input Protocol functions // Simple Text Input Protocol functions
// //
/** /**
Reset the Keyboard and do BAT test for it, if (ExtendedVerification == TRUE) then do some extra keyboard validations. Reset the Keyboard and do BAT test for it, if (ExtendedVerification == TRUE) then do some extra keyboard validations.
@ -406,6 +403,7 @@ VirtualKeyboardUnregisterKeyNotify (
// //
// Private worker functions // Private worker functions
// //
/** /**
Free keyboard notify list. Free keyboard notify list.

View File

@ -48,7 +48,6 @@ GetNextHighMonotonicCount (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MonotonicCounterDriverInitialize ( MonotonicCounterDriverInitialize (
@ -69,7 +68,8 @@ MonotonicCounterDriverInitialize (
// Install the Monotonic Counter Architectural Protocol onto a new handle // Install the Monotonic Counter Architectural Protocol onto a new handle
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Handle, &Handle,
&gEfiMonotonicCounterArchProtocolGuid, NULL, &gEfiMonotonicCounterArchProtocolGuid,
NULL,
NULL NULL
); );
return Status; return Status;

View File

@ -91,7 +91,6 @@ MaxEfiException (
return sizeof (gExceptionType) / sizeof (EFI_EXCEPTION_TYPE_ENTRY); return sizeof (gExceptionType) / sizeof (EFI_EXCEPTION_TYPE_ENTRY);
} }
/** /**
Return the number of entries in the gRegisters[] Return the number of entries in the gRegisters[]
@ -105,7 +104,6 @@ MaxRegisterCount (
return sizeof (gRegisterOffsets) / sizeof (UINTN); return sizeof (gRegisterOffsets) / sizeof (UINTN);
} }
/** /**
Check to see if the ISA is supported. Check to see if the ISA is supported.
ISA = Instruction Set Architecture ISA = Instruction Set Architecture
@ -125,7 +123,6 @@ CheckIsa (
} }
} }
/** /**
This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
It is, by default, set to find the register pointer of the ARM member It is, by default, set to find the register pointer of the ARM member
@ -140,12 +137,12 @@ FindPointerToRegister (
) )
{ {
UINT8 *TempPtr; UINT8 *TempPtr;
ASSERT (gRegisterOffsets[RegNumber] < 0xF00); ASSERT (gRegisterOffsets[RegNumber] < 0xF00);
TempPtr = ((UINT8 *)SystemContext.SystemContextArm) + gRegisterOffsets[RegNumber]; TempPtr = ((UINT8 *)SystemContext.SystemContextArm) + gRegisterOffsets[RegNumber];
return (UINT32 *)TempPtr; return (UINT32 *)TempPtr;
} }
/** /**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -175,20 +172,22 @@ BasicReadRegister (
if ((Char >= 'A') && (Char <= 'F')) { if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a'; Char = Char - 'A' + 'a';
} }
*OutBufPtr++ = Char; *OutBufPtr++ = Char;
Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)]; Char = mHexToStr[(UINT8)((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];
if ((Char >= 'A') && (Char <= 'F')) { if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a'; Char = Char - 'A' + 'a';
} }
*OutBufPtr++ = Char; *OutBufPtr++ = Char;
RegSize = RegSize + 8; RegSize = RegSize + 8;
} }
return OutBufPtr; return OutBufPtr;
} }
/** /**
Reads the n-th register's value into an output buffer and sends it as a packet Reads the n-th register's value into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -218,7 +217,6 @@ ReadNthRegister (
SendPacket (OutBuffer); SendPacket (OutBuffer);
} }
/** /**
Reads the general registers into an output buffer and sends it as a packet Reads the general registers into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -246,7 +244,6 @@ ReadGeneralRegisters (
FreePool (OutBuffer); FreePool (OutBuffer);
} }
/** /**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -255,7 +252,8 @@ ReadGeneralRegisters (
@retval the pointer to the next character of the input buffer that can be used @retval the pointer to the next character of the input buffer that can be used
**/ **/
CHAR8 CHAR8
*BasicWriteRegister ( *
BasicWriteRegister (
IN EFI_SYSTEM_CONTEXT SystemContext, IN EFI_SYSTEM_CONTEXT SystemContext,
IN UINTN RegNumber, IN UINTN RegNumber,
IN CHAR8 *InBufPtr IN CHAR8 *InBufPtr
@ -290,11 +288,11 @@ CHAR8
NewValue += (TempValue << RegSize); NewValue += (TempValue << RegSize);
RegSize = RegSize + 8; RegSize = RegSize + 8;
} }
*(FindPointerToRegister (SystemContext, RegNumber)) = NewValue; *(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;
return InBufPtr; return InBufPtr;
} }
/** P n...=r... /** P n...=r...
Writes the new value of n-th register received into the input buffer to the n-th register Writes the new value of n-th register received into the input buffer to the n-th register
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -317,6 +315,7 @@ WriteNthRegister (
while (*InBufPtr != '=') { while (*InBufPtr != '=') {
*RegNumBufPtr++ = *InBufPtr++; *RegNumBufPtr++ = *InBufPtr++;
} }
*RegNumBufPtr = '\0'; *RegNumBufPtr = '\0';
RegNumber = AsciiStrHexToUintn (RegNumBuffer); RegNumber = AsciiStrHexToUintn (RegNumBuffer);
@ -325,18 +324,17 @@ WriteNthRegister (
SendError (GDB_EINVALIDREGNUM); SendError (GDB_EINVALIDREGNUM);
return; return;
} }
InBufPtr++; // skips the '=' character InBufPtr++; // skips the '=' character
BasicWriteRegister (SystemContext, RegNumber, InBufPtr); BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
SendSuccess (); SendSuccess ();
} }
/** G XX... /** G XX...
Writes the new values received into the input buffer to the general registers Writes the new values received into the input buffer to the general registers
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@param InBuffer Pointer to the input buffer received from gdb server @param InBuffer Pointer to the input buffer received from gdb server
**/ **/
VOID VOID
EFIAPI EFIAPI
WriteGeneralRegisters ( WriteGeneralRegisters (
@ -403,6 +401,7 @@ AddSingleStep (
// Currently don't support nesting // Currently don't support nesting
return; return;
} }
mSingleStepActive = TRUE; mSingleStepActive = TRUE;
mSingleStepPC = SystemContext.SystemContextArm->PC; mSingleStepPC = SystemContext.SystemContextArm->PC;
@ -419,7 +418,6 @@ AddSingleStep (
// DEBUG((DEBUG_ERROR, "AddSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, mSingleStepData, *(UINT32 *)mSingleStepPC)); // DEBUG((DEBUG_ERROR, "AddSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, mSingleStepData, *(UINT32 *)mSingleStepPC));
} }
/** /**
Remove Single Step in the SystemContext Remove Single Step in the SystemContext
@ -440,12 +438,11 @@ RemoveSingleStep (
// DEBUG((DEBUG_ERROR, "RemoveSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, *(UINT32 *)mSingleStepPC, mSingleStepData)); // DEBUG((DEBUG_ERROR, "RemoveSingleStep at 0x%08x (was: 0x%08x is:0x%08x)\n", SystemContext.SystemContextArm->PC, *(UINT32 *)mSingleStepPC, mSingleStepData));
*(UINT32 *)mSingleStepPC = mSingleStepData; *(UINT32 *)mSingleStepPC = mSingleStepData;
} }
InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize); InvalidateInstructionCacheRange ((VOID *)mSingleStepPC, mSingleStepDataSize);
mSingleStepActive = FALSE; mSingleStepActive = FALSE;
} }
/** /**
Continue. addr is Address to resume. If addr is omitted, resume at current Continue. addr is Address to resume. If addr is omitted, resume at current
Address. Address.
@ -464,7 +461,6 @@ ContinueAtAddress (
} }
} }
/** s [addr ] /** s [addr ]
Single step. addr is the Address at which to resume. If addr is omitted, resume Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address. at same Address.

View File

@ -14,7 +14,6 @@
#include <GdbStubInternal.h> #include <GdbStubInternal.h>
#include <Protocol/DebugPort.h> #include <Protocol/DebugPort.h>
UINTN gMaxProcessorIndex = 0; UINTN gMaxProcessorIndex = 0;
// //
@ -40,7 +39,6 @@ CHAR8 gXferLibraryBuffer[2000];
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexToStr[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
VOID VOID
EFIAPI EFIAPI
GdbSymbolEventHandler ( GdbSymbolEventHandler (
@ -50,7 +48,6 @@ GdbSymbolEventHandler (
{ {
} }
/** /**
The user Entry Point for Application. The user code starts with this function The user Entry Point for Application. The user code starts with this function
as the real entry point for the image goes into a library that calls this as the real entry point for the image goes into a library that calls this
@ -113,6 +110,7 @@ GdbStubEntry (
} }
} }
} while (HandleCount > 0); } while (HandleCount > 0);
FreePool (Handles); FreePool (Handles);
if (!IsaSupported) { if (!IsaSupported) {
@ -135,6 +133,7 @@ GdbStubEntry (
Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor, GdbExceptionHandler, gExceptionType[Index].Exception); Status = DebugSupport->RegisterExceptionCallback (DebugSupport, Processor, GdbExceptionHandler, gExceptionType[Index].Exception);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
// //
// Current edk2 DebugPort is not interrupt context safe so we can not use it // Current edk2 DebugPort is not interrupt context safe so we can not use it
// //
@ -165,7 +164,6 @@ GdbStubEntry (
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
if (PcdGetBool (PcdGdbSerial)) { if (PcdGetBool (PcdGdbSerial)) {
GdbInitializeSerialConsole (); GdbInitializeSerialConsole ();
} }
@ -180,7 +178,6 @@ GdbStubEntry (
@param *address the start address of the transferring/writing the memory @param *address the start address of the transferring/writing the memory
@param *new_data the new data to be written to memory @param *new_data the new data to be written to memory
**/ **/
VOID VOID
TransferFromInBufToMem ( TransferFromInBufToMem (
IN UINTN Length, IN UINTN Length,
@ -200,13 +197,13 @@ TransferFromInBufToMem (
SendError (GDB_EBADMEMDATA); SendError (GDB_EBADMEMDATA);
return; return;
} }
*Address++ = (UINT8)((c1 << 4) + c2); *Address++ = (UINT8)((c1 << 4) + c2);
} }
SendSuccess (); SendSuccess ();
} }
/** /**
Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer Transfer Length bytes of memory starting at Address to an output buffer, OutBuffer. This function will finally send the buffer
as a packet. as a packet.
@ -214,7 +211,6 @@ TransferFromInBufToMem (
@param Length the number of the bytes to be transferred/read @param Length the number of the bytes to be transferred/read
@param *address pointer to the start address of the transferring/reading the memory @param *address pointer to the start address of the transferring/reading the memory
**/ **/
VOID VOID
TransferFromMemToOutBufAndSend ( TransferFromMemToOutBufAndSend (
IN UINTN Length, IN UINTN Length,
@ -233,17 +229,18 @@ TransferFromMemToOutBufAndSend (
OutBufPtr = OutBuffer; OutBufPtr = OutBuffer;
while (Length > 0) { while (Length > 0) {
Char = mHexToStr[*Address >> 4]; Char = mHexToStr[*Address >> 4];
if ((Char >= 'A') && (Char <= 'F')) { if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a'; Char = Char - 'A' + 'a';
} }
*OutBufPtr++ = Char; *OutBufPtr++ = Char;
Char = mHexToStr[*Address & 0x0f]; Char = mHexToStr[*Address & 0x0f];
if ((Char >= 'A') && (Char <= 'F')) { if ((Char >= 'A') && (Char <= 'F')) {
Char = Char - 'A' + 'a'; Char = Char - 'A' + 'a';
} }
*OutBufPtr++ = Char; *OutBufPtr++ = Char;
Address++; Address++;
@ -254,8 +251,6 @@ TransferFromMemToOutBufAndSend (
SendPacket (OutBuffer); SendPacket (OutBuffer);
} }
/** /**
Send a GDB Remote Serial Protocol Packet Send a GDB Remote Serial Protocol Packet
@ -286,7 +281,6 @@ SendPacket (
Count = 0; Count = 0;
do { do {
Ptr = PacketData; Ptr = PacketData;
if (Timeout-- == 0) { if (Timeout-- == 0) {
@ -348,7 +342,7 @@ ReceivePacket (
TestChar = GdbGetChar (); TestChar = GdbGetChar ();
while (TestChar != '$') { while (TestChar != '$') {
TestChar = GdbGetChar (); TestChar = GdbGetChar ();
}; }
retry: retry:
for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) { for (Index = 0, CheckSum = 0; Index < (PacketDataSize - 1); Index++) {
@ -356,6 +350,7 @@ ReceivePacket (
if (Char == '$') { if (Char == '$') {
goto retry; goto retry;
} }
if (Char == '#') { if (Char == '#') {
break; break;
} }
@ -363,6 +358,7 @@ ReceivePacket (
PacketData[Index] = Char; PacketData[Index] = Char;
CheckSum = CheckSum + Char; CheckSum = CheckSum + Char;
} }
PacketData[Index] = '\0'; PacketData[Index] = '\0';
if (Index == PacketDataSize) { if (Index == PacketDataSize) {
@ -389,7 +385,6 @@ ReceivePacket (
// return 0; // return 0;
} }
/** /**
Empties the given buffer Empties the given buffer
@param Buf pointer to the first element in buffer to be emptied @param Buf pointer to the first element in buffer to be emptied
@ -402,7 +397,6 @@ EmptyBuffer (
*Buf = '\0'; *Buf = '\0';
} }
/** /**
Converts an 8-bit Hex Char into a INTN. Converts an 8-bit Hex Char into a INTN.
@ -421,7 +415,8 @@ HexCharToInt (
return Char - 'a' + 10; return Char - 'a' + 10;
} else if ((Char >= '0') && (Char <= '9')) { } else if ((Char >= '0') && (Char <= '9')) {
return Char - '0'; return Char - '0';
} else { // if not a hex value, return a negative value } else {
// if not a hex value, return a negative value
return -1; return -1;
} }
} }
@ -451,8 +446,6 @@ SendError (
SendPacket (gError); // send buffer SendPacket (gError); // send buffer
} }
/** /**
Send 'OK' when the function is done executing successfully. Send 'OK' when the function is done executing successfully.
**/ **/
@ -465,7 +458,6 @@ SendSuccess (
SendPacket ("OK"); // send buffer SendPacket ("OK"); // send buffer
} }
/** /**
Send empty packet to specify that particular command/functionality is not supported. Send empty packet to specify that particular command/functionality is not supported.
**/ **/
@ -478,7 +470,6 @@ SendNotSupported (
SendPacket (""); SendPacket ("");
} }
/** /**
Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
@ -519,10 +510,9 @@ GdbSendTSignal (
while (*WatchStrPtr != '\0') { while (*WatchStrPtr != '\0') {
*TSignalPtr++ = *WatchStrPtr++; *TSignalPtr++ = *WatchStrPtr++;
} }
gSymbolTableUpdate = FALSE; gSymbolTableUpdate = FALSE;
} else { } else {
// //
// possible n:r pairs // possible n:r pairs
// //
@ -535,7 +525,6 @@ GdbSendTSignal (
// INFO: rwatch is not supported due to the way IA32 debug registers work // INFO: rwatch is not supported due to the way IA32 debug registers work
if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) { if ((BreakType == DataWrite) || (BreakType == DataRead) || (BreakType == DataReadWrite)) {
// Construct n:r pair // Construct n:r pair
DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected); DataAddress = GetBreakpointDataAddress (SystemContext, BreakpointDetected);
@ -572,7 +561,6 @@ GdbSendTSignal (
SendPacket (TSignalBuffer); SendPacket (TSignalBuffer);
} }
/** /**
Translates the EFI mapping to GDB mapping Translates the EFI mapping to GDB mapping
@ -591,16 +579,15 @@ ConvertEFItoGDBtype (
return gExceptionType[Index].SignalNo; return gExceptionType[Index].SignalNo;
} }
} }
return GDB_SIGTRAP; // this is a GDB trap return GDB_SIGTRAP; // this is a GDB trap
} }
/** "m addr,length" /** "m addr,length"
Find the Length of the area to read and the start address. Finally, pass them to Find the Length of the area to read and the start address. Finally, pass them to
another function, TransferFromMemToOutBufAndSend, that will read from that memory space and another function, TransferFromMemToOutBufAndSend, that will read from that memory space and
send it as a packet. send it as a packet.
**/ **/
VOID VOID
EFIAPI EFIAPI
ReadFromMemory ( ReadFromMemory (
@ -618,6 +605,7 @@ ReadFromMemory (
while (*InBufPtr != ',') { while (*InBufPtr != ',') {
*AddrBufPtr++ = *InBufPtr++; *AddrBufPtr++ = *InBufPtr++;
} }
*AddrBufPtr = '\0'; *AddrBufPtr = '\0';
InBufPtr++; // this skips ',' in the buffer InBufPtr++; // this skips ',' in the buffer
@ -642,7 +630,6 @@ ReadFromMemory (
TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address); TransferFromMemToOutBufAndSend (Length, (unsigned char *)Address);
} }
/** "M addr,length :XX..." /** "M addr,length :XX..."
Find the Length of the area in bytes to write and the start address. Finally, pass them to Find the Length of the area in bytes to write and the start address. Finally, pass them to
another function, TransferFromInBufToMem, that will write to that memory space the info in another function, TransferFromInBufToMem, that will write to that memory space the info in
@ -670,6 +657,7 @@ WriteToMemory (
while (*InBufPtr != ',') { while (*InBufPtr != ',') {
*AddrBufPtr++ = *InBufPtr++; *AddrBufPtr++ = *InBufPtr++;
} }
*AddrBufPtr = '\0'; *AddrBufPtr = '\0';
InBufPtr++; // this skips ',' in the buffer InBufPtr++; // this skips ',' in the buffer
@ -677,6 +665,7 @@ WriteToMemory (
while (*InBufPtr != ':') { while (*InBufPtr != ':') {
*LengthBufPtr++ = *InBufPtr++; *LengthBufPtr++ = *InBufPtr++;
} }
*LengthBufPtr = '\0'; *LengthBufPtr = '\0';
InBufPtr++; // this skips ':' in the buffer InBufPtr++; // this skips ':' in the buffer
@ -708,6 +697,7 @@ WriteToMemory (
SendError (GDB_EBADMEMDATASIZE); SendError (GDB_EBADMEMDATASIZE);
return; return;
} }
TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr); TransferFromInBufToMem (Length, (unsigned char *)Address, InBufPtr);
} }
@ -749,12 +739,14 @@ ParseBreakpointPacket (
} }
// Skip ',' in the buffer. // Skip ',' in the buffer.
while (*PacketDataPtr++ != ','); while (*PacketDataPtr++ != ',') {
}
// Parse Address information // Parse Address information
while (*PacketDataPtr != ',') { while (*PacketDataPtr != ',') {
*AddressBufferPtr++ = *PacketDataPtr++; *AddressBufferPtr++ = *PacketDataPtr++;
} }
*AddressBufferPtr = '\0'; *AddressBufferPtr = '\0';
// Check if Address is not too long. // Check if Address is not too long.
@ -804,6 +796,7 @@ gXferObjectReadResponse (
Char ^= 0x20; Char ^= 0x20;
} }
*OutBufPtr++ = Char; *OutBufPtr++ = Char;
Count++; Count++;
} }
@ -814,7 +807,6 @@ gXferObjectReadResponse (
return Count; return Count;
} }
/** /**
Note: This should be a library function. In the Apple case you have to add Note: This should be a library function. In the Apple case you have to add
the size of the PE/COFF header into the starting address to make things work the size of the PE/COFF header into the starting address to make things work
@ -888,15 +880,14 @@ PeCoffLoaderGetDebuggerInfo (
Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress + Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
TEImageAdjust); TEImageAdjust);
} }
SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize; SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize;
// __APPLE__ check this math... // __APPLE__ check this math...
*DebugBase = ((CHAR8 *)Pe32Data) - TEImageAdjust; *DebugBase = ((CHAR8 *)Pe32Data) - TEImageAdjust;
} else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) { } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
*DebugBase = Pe32Data; *DebugBase = Pe32Data;
// //
// NOTE: We use Machine field to identify PE32/PE32+, instead of Magic. // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.
// It is due to backward-compatibility, for some system might // It is due to backward-compatibility, for some system might
@ -949,7 +940,7 @@ PeCoffLoaderGetDebuggerInfo (
return NULL; return NULL;
} }
if (DebugEntry == NULL || DirectoryEntry == NULL) { if ((DebugEntry == NULL) || (DirectoryEntry == NULL)) {
return NULL; return NULL;
} }
@ -976,7 +967,6 @@ PeCoffLoaderGetDebuggerInfo (
return NULL; return NULL;
} }
/** /**
Process "qXfer:object:read:annex:offset,length" request. Process "qXfer:object:read:annex:offset,length" request.
@ -1045,7 +1035,8 @@ QxferLibrary (
for ( ; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) { for ( ; gEfiDebugImageTableEntry < gDebugImageTableHeader->TableSize; gEfiDebugImageTableEntry++, gDebugTable++) {
if (gDebugTable->NormalImage != NULL) { if (gDebugTable->NormalImage != NULL) {
if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) && if ((gDebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
(gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL)) { (gDebugTable->NormalImage->LoadedImageProtocolInstance != NULL))
{
Pdb = PeCoffLoaderGetDebuggerInfo ( Pdb = PeCoffLoaderGetDebuggerInfo (
gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase, gDebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase,
&LoadAddress &LoadAddress
@ -1080,13 +1071,11 @@ QxferLibrary (
} }
} }
gXferObjectReadResponse ('l', "</library-list>\n"); gXferObjectReadResponse ('l', "</library-list>\n");
gPacketqXferLibraryOffset = 0; gPacketqXferLibraryOffset = 0;
return; return;
} }
/** /**
Exception Handler for GDB. It will be called for all exceptions Exception Handler for GDB. It will be called for all exceptions
registered via the gExceptionType[] array. registered via the gExceptionType[] array.
@ -1104,7 +1093,6 @@ GdbExceptionHandler (
UINT8 GdbExceptionType; UINT8 GdbExceptionType;
CHAR8 *Ptr; CHAR8 *Ptr;
if (ValidateException (ExceptionType, SystemContext) == FALSE) { if (ValidateException (ExceptionType, SystemContext) == FALSE) {
return; return;
} }
@ -1163,17 +1151,21 @@ GdbExceptionHandler (
} else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) { } else if (AsciiStrnCmp (gInBuffer, "qXfer:libraries:read::", 22) == 0) {
// qXfer:libraries:read::offset,length // qXfer:libraries:read::offset,length
// gInBuffer[22] is offset string, ++Ptr is length string // gInBuffer[22] is offset string, ++Ptr is length string
for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++); for (Ptr = &gInBuffer[22]; *Ptr != ','; Ptr++) {
}
// Not sure if multi-radix support is required. Currently only support decimal // Not sure if multi-radix support is required. Currently only support decimal
QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr)); QxferLibrary (AsciiStrHexToUintn (&gInBuffer[22]), AsciiStrHexToUintn (++Ptr));
} if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) { }
if (AsciiStrnCmp (gInBuffer, "qOffsets", 10) == 0) {
AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000"); AsciiSPrint (gOutBuffer, MAX_BUF_SIZE, "Text=1000;Data=f000;Bss=f000");
SendPacket (gOutBuffer); SendPacket (gOutBuffer);
} else { } else {
// Send empty packet // Send empty packet
SendNotSupported (); SendNotSupported ();
} }
break; break;
case 's': case 's':
@ -1196,7 +1188,6 @@ GdbExceptionHandler (
} }
} }
/** /**
Periodic callback for GDB. This function is used to catch a ctrl-c or other Periodic callback for GDB. This function is used to catch a ctrl-c or other
break in type command from GDB. break in type command from GDB.

View File

@ -49,7 +49,6 @@ extern CONST CHAR8 mHexToStr[];
// the mask used to clear all the cache // the mask used to clear all the cache
#define TF_BIT 0x00000100 #define TF_BIT 0x00000100
// //
// GDB Signal definitions - generic names for interrupts // GDB Signal definitions - generic names for interrupts
// //
@ -59,7 +58,6 @@ extern CONST CHAR8 mHexToStr[];
#define GDB_SIGFPE 8 // Floating point exception #define GDB_SIGFPE 8 // Floating point exception
#define GDB_SIGSEGV 11 // Segment violation, page fault #define GDB_SIGSEGV 11 // Segment violation, page fault
// //
// GDB File I/O Error values, zero means no error // GDB File I/O Error values, zero means no error
// Includes all general GDB Unix like error values // Includes all general GDB Unix like error values
@ -76,7 +74,6 @@ extern CONST CHAR8 mHexToStr[];
#define GDB_EINVALIDREGNUM 61 // given register number is not valid: either <0 or >=Number of Registers #define GDB_EINVALIDREGNUM 61 // given register number is not valid: either <0 or >=Number of Registers
#define GDB_EUNKNOWN 255 // unknown #define GDB_EUNKNOWN 255 // unknown
// //
// These devices are open by GDB so we can just read and write to them // These devices are open by GDB so we can just read and write to them
// //
@ -122,16 +119,13 @@ typedef struct {
INTN OutFileDescriptor; INTN OutFileDescriptor;
} GDB_SERIAL_DEV; } GDB_SERIAL_DEV;
#define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE) #define GDB_SERIAL_DEV_FROM_THIS(a) CR (a, GDB_SERIAL_DEV, SerialIo, GDB_SERIAL_DEV_SIGNATURE)
typedef struct { typedef struct {
EFI_EXCEPTION_TYPE Exception; EFI_EXCEPTION_TYPE Exception;
UINT8 SignalNo; UINT8 SignalNo;
} EFI_EXCEPTION_TYPE_ENTRY; } EFI_EXCEPTION_TYPE_ENTRY;
#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
// //
@ -215,7 +209,6 @@ extern BOOLEAN gCtrlCBreakFlag;
// //
extern BOOLEAN gProcessingFPacket; extern BOOLEAN gProcessingFPacket;
// The offsets of registers SystemContext. // The offsets of registers SystemContext.
// The fields in the array are in the gdb ordering. // The fields in the array are in the gdb ordering.
// //
@ -231,7 +224,6 @@ MaxEfiException (
VOID VOID
); );
/** /**
Return the number of entries in the gRegisters[] Return the number of entries in the gRegisters[]
@ -242,7 +234,6 @@ MaxRegisterCount (
VOID VOID
); );
/** /**
Check to see if the ISA is supported. Check to see if the ISA is supported.
ISA = Instruction Set Architecture ISA = Instruction Set Architecture
@ -255,7 +246,6 @@ CheckIsa (
IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa
); );
/** /**
Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints Send the T signal with the given exception type (in gdb order) and possibly with n:r pairs related to the watchpoints
@ -269,7 +259,6 @@ GdbSendTSignal (
IN UINT8 GdbExceptionType IN UINT8 GdbExceptionType
); );
/** /**
Translates the EFI mapping to GDB mapping Translates the EFI mapping to GDB mapping
@ -281,7 +270,6 @@ ConvertEFItoGDBtype (
IN EFI_EXCEPTION_TYPE EFIExceptionType IN EFI_EXCEPTION_TYPE EFIExceptionType
); );
/** /**
Empties the given buffer Empties the given buffer
@param *Buf pointer to the first element in buffer to be emptied @param *Buf pointer to the first element in buffer to be emptied
@ -291,7 +279,6 @@ EmptyBuffer (
IN CHAR8 *Buf IN CHAR8 *Buf
); );
/** /**
Converts an 8-bit Hex Char into a INTN. Converts an 8-bit Hex Char into a INTN.
@ -304,7 +291,6 @@ HexCharToInt (
IN CHAR8 Char IN CHAR8 Char
); );
/** 'E NN' /** 'E NN'
Send an error with the given error number after converting to hex. Send an error with the given error number after converting to hex.
The error number is put into the buffer in hex. '255' is the biggest errno we can send. The error number is put into the buffer in hex. '255' is the biggest errno we can send.
@ -318,7 +304,6 @@ SendError (
IN UINT8 ErrorNum IN UINT8 ErrorNum
); );
/** /**
Send 'OK' when the function is done executing successfully. Send 'OK' when the function is done executing successfully.
**/ **/
@ -328,7 +313,6 @@ SendSuccess (
VOID VOID
); );
/** /**
Send empty packet to specify that particular command/functionality is not supported. Send empty packet to specify that particular command/functionality is not supported.
**/ **/
@ -349,7 +333,6 @@ ReadNthRegister (
IN CHAR8 *InBuffer IN CHAR8 *InBuffer
); );
/** g /** g
Reads the general registers into an output buffer and sends it as a packet Reads the general registers into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -360,7 +343,6 @@ ReadGeneralRegisters (
IN EFI_SYSTEM_CONTEXT SystemContext IN EFI_SYSTEM_CONTEXT SystemContext
); );
/** P n...=r... /** P n...=r...
Writes the new value of n-th register received into the input buffer to the n-th register Writes the new value of n-th register received into the input buffer to the n-th register
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -373,7 +355,6 @@ WriteNthRegister (
IN CHAR8 *InBuffer IN CHAR8 *InBuffer
); );
/** G XX... /** G XX...
Writes the new values received into the input buffer to the general registers Writes the new values received into the input buffer to the general registers
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -387,7 +368,6 @@ WriteGeneralRegisters (
IN CHAR8 *InBuffer IN CHAR8 *InBuffer
); );
/** m addr,length /** m addr,length
Find the Length of the area to read and the start address. Finally, pass them to Find the Length of the area to read and the start address. Finally, pass them to
another function, TransferFromMemToOutBufAndSend, that will read from that memory space and another function, TransferFromMemToOutBufAndSend, that will read from that memory space and
@ -401,7 +381,6 @@ ReadFromMemory (
IN CHAR8 *PacketData IN CHAR8 *PacketData
); );
/** M addr,length :XX... /** M addr,length :XX...
Find the Length of the area in bytes to write and the start address. Finally, pass them to Find the Length of the area in bytes to write and the start address. Finally, pass them to
another function, TransferFromInBufToMem, that will write to that memory space the info in another function, TransferFromInBufToMem, that will write to that memory space the info in
@ -415,7 +394,6 @@ WriteToMemory (
IN CHAR8 *PacketData IN CHAR8 *PacketData
); );
/** c [addr ] /** c [addr ]
Continue. addr is Address to resume. If addr is omitted, resume at current Continue. addr is Address to resume. If addr is omitted, resume at current
Address. Address.
@ -431,7 +409,6 @@ ContinueAtAddress (
IN CHAR8 *PacketData IN CHAR8 *PacketData
); );
/** s [addr ] /** s [addr ]
Single step. addr is the Address at which to resume. If addr is omitted, resume Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address. at same Address.
@ -466,7 +443,6 @@ RemoveSingleStep (
IN EFI_SYSTEM_CONTEXT SystemContext IN EFI_SYSTEM_CONTEXT SystemContext
); );
/** /**
Z1, [addr], [length] Z1, [addr], [length]
Z2, [addr], [length] Z2, [addr], [length]
@ -486,7 +462,6 @@ InsertBreakPoint(
IN CHAR8 *PacketData IN CHAR8 *PacketData
); );
/** /**
z1, [addr], [length] z1, [addr], [length]
z2, [addr], [length] z2, [addr], [length]
@ -506,7 +481,6 @@ RemoveBreakPoint(
IN CHAR8 *PacketData IN CHAR8 *PacketData
); );
/** /**
Exception Handler for GDB. It will be called for all exceptions Exception Handler for GDB. It will be called for all exceptions
registered via the gExceptionType[] array. registered via the gExceptionType[] array.
@ -522,7 +496,6 @@ GdbExceptionHandler (
IN OUT EFI_SYSTEM_CONTEXT SystemContext IN OUT EFI_SYSTEM_CONTEXT SystemContext
); );
/** /**
Periodic callback for GDB. This function is used to catch a ctrl-c or other Periodic callback for GDB. This function is used to catch a ctrl-c or other
break in type command from GDB. break in type command from GDB.
@ -536,7 +509,6 @@ GdbPeriodicCallBack (
IN OUT EFI_SYSTEM_CONTEXT SystemContext IN OUT EFI_SYSTEM_CONTEXT SystemContext
); );
/** /**
Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB. Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
@ -549,7 +521,6 @@ GdbInitializeSerialConsole (
VOID VOID
); );
/** /**
Send a GDB Remote Serial Protocol Packet Send a GDB Remote Serial Protocol Packet
@ -569,7 +540,6 @@ SendPacket (
IN CHAR8 *PacketData IN CHAR8 *PacketData
); );
/** /**
Receive a GDB Remote Serial Protocol Packet Receive a GDB Remote Serial Protocol Packet
@ -592,7 +562,6 @@ ReceivePacket (
IN UINTN PacketDataSize IN UINTN PacketDataSize
); );
/** /**
Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates
the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero. the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.
@ -612,7 +581,6 @@ GdbRead (
IN UINTN Count IN UINTN Count
); );
/** /**
Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates
nothing was written. On error -1 is returned. nothing was written. On error -1 is returned.

View File

@ -30,7 +30,6 @@ EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
{ EXCEPT_IA32_MACHINE_CHECK, GDB_SIGEMT } { EXCEPT_IA32_MACHINE_CHECK, GDB_SIGEMT }
}; };
// The offsets of registers SystemContext. // The offsets of registers SystemContext.
// The fields in the array are in the gdb ordering. // The fields in the array are in the gdb ordering.
// //
@ -54,7 +53,6 @@ UINTN gRegisterOffsets[] = {
OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Gs) OFFSET_OF (EFI_SYSTEM_CONTEXT_IA32, Gs)
}; };
// Debug only.. // Debug only..
VOID VOID
PrintReg ( PrintReg (
@ -87,7 +85,6 @@ PrintDRreg (
Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7); Print ((CHAR16 *)L"DR7: %x\n", SystemContext.SystemContextIa32->Dr7);
} }
/** /**
Return the number of entries in the gExceptionType[] Return the number of entries in the gExceptionType[]
@ -101,7 +98,6 @@ MaxEfiException (
return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY); return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);
} }
/** /**
Return the number of entries in the gRegisters[] Return the number of entries in the gRegisters[]
@ -115,7 +111,6 @@ MaxRegisterCount (
return sizeof (gRegisterOffsets)/sizeof (UINTN); return sizeof (gRegisterOffsets)/sizeof (UINTN);
} }
/** /**
Check to see if the ISA is supported. Check to see if the ISA is supported.
ISA = Instruction Set Architecture ISA = Instruction Set Architecture
@ -131,7 +126,6 @@ CheckIsa (
return (BOOLEAN)(Isa == IsaIa32); return (BOOLEAN)(Isa == IsaIa32);
} }
/** /**
This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
It is, by default, set to find the register pointer of the IA32 member It is, by default, set to find the register pointer of the IA32 member
@ -147,11 +141,11 @@ FindPointerToRegister (
) )
{ {
UINT8 *TempPtr; UINT8 *TempPtr;
TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber]; TempPtr = ((UINT8 *)SystemContext.SystemContextIa32) + gRegisterOffsets[RegNumber];
return (UINTN *)TempPtr; return (UINTN *)TempPtr;
} }
/** /**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@ -175,10 +169,10 @@ BasicReadRegister (
*OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)]; *OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];
RegSize = RegSize + 8; RegSize = RegSize + 8;
} }
return OutBufPtr; return OutBufPtr;
} }
/** p n /** p n
Reads the n-th register's value into an output buffer and sends it as a packet Reads the n-th register's value into an output buffer and sends it as a packet
@ -210,7 +204,6 @@ ReadNthRegister (
SendPacket (OutBuffer); SendPacket (OutBuffer);
} }
/** g /** g
Reads the general registers into an output buffer and sends it as a packet Reads the general registers into an output buffer and sends it as a packet
@ -227,7 +220,8 @@ ReadGeneralRegisters (
CHAR8 *OutBufPtr; // pointer to the output buffer CHAR8 *OutBufPtr; // pointer to the output buffer
OutBufPtr = OutBuffer; OutBufPtr = OutBuffer;
for (i = 0 ; i < MaxRegisterCount() ; i++) { // there are only 16 registers to read for (i = 0; i < MaxRegisterCount (); i++) {
// there are only 16 registers to read
OutBufPtr = BasicReadRegister (SystemContext, i, OutBufPtr); OutBufPtr = BasicReadRegister (SystemContext, i, OutBufPtr);
} }
@ -235,7 +229,6 @@ ReadGeneralRegisters (
SendPacket (OutBuffer); SendPacket (OutBuffer);
} }
/** /**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@ -276,11 +269,11 @@ BasicWriteRegister (
NewValue += (TempValue << RegSize); NewValue += (TempValue << RegSize);
RegSize = RegSize + 8; RegSize = RegSize + 8;
} }
*(FindPointerToRegister (SystemContext, RegNumber)) = NewValue; *(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;
return InBufPtr; return InBufPtr;
} }
/** P n...=r... /** P n...=r...
Writes the new value of n-th register received into the input buffer to the n-th register Writes the new value of n-th register received into the input buffer to the n-th register
@ -305,6 +298,7 @@ WriteNthRegister (
while (*InBufPtr != '=') { while (*InBufPtr != '=') {
*RegNumBufPtr++ = *InBufPtr++; *RegNumBufPtr++ = *InBufPtr++;
} }
*RegNumBufPtr = '\0'; *RegNumBufPtr = '\0';
RegNumber = AsciiStrHexToUintn (RegNumBuffer); RegNumber = AsciiStrHexToUintn (RegNumBuffer);
@ -313,12 +307,12 @@ WriteNthRegister (
SendError (GDB_EINVALIDREGNUM); SendError (GDB_EINVALIDREGNUM);
return; return;
} }
InBufPtr++; // skips the '=' character InBufPtr++; // skips the '=' character
BasicWriteRegister (SystemContext, RegNumber, InBufPtr); BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
SendSuccess (); SendSuccess ();
} }
/** G XX... /** G XX...
Writes the new values received into the input buffer to the general registers Writes the new values received into the input buffer to the general registers
@ -337,7 +331,8 @@ WriteGeneralRegisters (
// check to see if the buffer is the right size which is // check to see if the buffer is the right size which is
// 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129 // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 129
if (AsciiStrLen(InBuffer) != 129) { // 16 regs, 8 hex chars each, and the end '\0' (escape seq) if (AsciiStrLen (InBuffer) != 129) {
// 16 regs, 8 hex chars each, and the end '\0' (escape seq)
// Bad message. Message is not the right length // Bad message. Message is not the right length
SendError (GDB_EBADBUFSIZE); SendError (GDB_EBADBUFSIZE);
return; return;
@ -347,14 +342,14 @@ WriteGeneralRegisters (
// Read the new values for the registers from the input buffer to an array, NewValueArray. // Read the new values for the registers from the input buffer to an array, NewValueArray.
// The values in the array are in the gdb ordering // The values in the array are in the gdb ordering
for (i=0; i < MaxRegisterCount(); i++) { // there are only 16 registers to write for (i = 0; i < MaxRegisterCount (); i++) {
// there are only 16 registers to write
InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr); InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr);
} }
SendSuccess (); SendSuccess ();
} }
/** /**
Insert Single Step in the SystemContext Insert Single Step in the SystemContext
@ -368,7 +363,6 @@ AddSingleStep (
SystemContext.SystemContextIa32->Eflags |= TF_BIT; // Setting the TF bit. SystemContext.SystemContextIa32->Eflags |= TF_BIT; // Setting the TF bit.
} }
/** /**
Remove Single Step in the SystemContext Remove Single Step in the SystemContext
@ -382,8 +376,6 @@ RemoveSingleStep (
SystemContext.SystemContextIa32->Eflags &= ~TF_BIT; // clearing the TF bit. SystemContext.SystemContextIa32->Eflags &= ~TF_BIT; // clearing the TF bit.
} }
/** c [addr ] /** c [addr ]
Continue. addr is Address to resume. If addr is omitted, resume at current Continue. addr is Address to resume. If addr is omitted, resume at current
Address. Address.
@ -402,7 +394,6 @@ ContinueAtAddress (
} }
} }
/** s [addr ] /** s [addr ]
Single step. addr is the Address at which to resume. If addr is omitted, resume Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address. at same Address.
@ -423,7 +414,6 @@ SingleStep (
AddSingleStep (SystemContext); AddSingleStep (SystemContext);
} }
/** /**
Returns breakpoint data address from DR0-DR3 based on the input breakpoint number Returns breakpoint data address from DR0-DR3 based on the input breakpoint number
@ -456,7 +446,6 @@ GetBreakpointDataAddress (
return Address; return Address;
} }
/** /**
Returns currently detected breakpoint value based on the register DR6 B0-B3 field. Returns currently detected breakpoint value based on the register DR6 B0-B3 field.
If no breakpoint is detected then it returns 0. If no breakpoint is detected then it returns 0.
@ -492,7 +481,6 @@ GetBreakpointDetected (
return BreakpointNumber; return BreakpointNumber;
} }
/** /**
Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite) Returns Breakpoint type (InstructionExecution, DataWrite, DataRead or DataReadWrite)
based on the Breakpoint number based on the Breakpoint number
@ -528,7 +516,6 @@ GetBreakpointType (
return Type; return Type;
} }
/** /**
Parses Length and returns the length which DR7 LENn field accepts. Parses Length and returns the length which DR7 LENn field accepts.
For example: If we receive 1-Byte length then we should return 0. For example: If we receive 1-Byte length then we should return 0.
@ -544,18 +531,21 @@ ConvertLengthData (
IN UINTN Length IN UINTN Length
) )
{ {
if (Length == 1) { //1-Byte length if (Length == 1) {
// 1-Byte length
return 0; return 0;
} else if (Length == 2) { //2-Byte length } else if (Length == 2) {
// 2-Byte length
return 1; return 1;
} else if (Length == 4) { //4-Byte length } else if (Length == 4) {
// 4-Byte length
return 3; return 3;
} else { //Undefined or 8-byte length } else {
// Undefined or 8-byte length
return 2; return 2;
} }
} }
/** /**
Finds the next free debug register. If all the registers are occupied then Finds the next free debug register. If all the registers are occupied then
EFI_OUT_OF_RESOURCES is returned. EFI_OUT_OF_RESOURCES is returned.
@ -591,7 +581,6 @@ FindNextFreeDebugRegister (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Enables the debug register. Writes Address value to appropriate DR0-3 register. Enables the debug register. Writes Address value to appropriate DR0-3 register.
Sets LENn, Gn, RWn bits in DR7 register. Sets LENn, Gn, RWn bits in DR7 register.
@ -628,7 +617,8 @@ EnableDebugRegister (
// Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
// software breakpoint. We should send empty packet in both these cases. // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) || if ((Type == (BREAK_TYPE)DataRead) ||
(Type == (BREAK_TYPE)SoftwareBreakpoint)) { (Type == (BREAK_TYPE)SoftwareBreakpoint))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -665,7 +655,6 @@ EnableDebugRegister (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Returns register number 0 - 3 for the matching debug register. Returns register number 0 - 3 for the matching debug register.
This function compares incoming Address, Type, Length and This function compares incoming Address, Type, Length and
@ -696,7 +685,8 @@ FindMatchingDebugRegister (
// Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
// software breakpoint. We should send empty packet in both these cases. // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) || if ((Type == (BREAK_TYPE)DataRead) ||
(Type == (BREAK_TYPE)SoftwareBreakpoint)) { (Type == (BREAK_TYPE)SoftwareBreakpoint))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -708,22 +698,26 @@ FindMatchingDebugRegister (
if ((Dr7.Bits.G0 == 1) && if ((Dr7.Bits.G0 == 1) &&
(Dr7.Bits.LEN0 == Length) && (Dr7.Bits.LEN0 == Length) &&
(Dr7.Bits.RW0 == Type) && (Dr7.Bits.RW0 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr0)) { (Address == SystemContext.SystemContextIa32->Dr0))
{
*Register = 0; *Register = 0;
} else if ((Dr7.Bits.G1 == 1) && } else if ((Dr7.Bits.G1 == 1) &&
(Dr7.Bits.LEN1 == Length) && (Dr7.Bits.LEN1 == Length) &&
(Dr7.Bits.RW1 == Type) && (Dr7.Bits.RW1 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr1)) { (Address == SystemContext.SystemContextIa32->Dr1))
{
*Register = 1; *Register = 1;
} else if ((Dr7.Bits.G2 == 1) && } else if ((Dr7.Bits.G2 == 1) &&
(Dr7.Bits.LEN2 == Length) && (Dr7.Bits.LEN2 == Length) &&
(Dr7.Bits.RW2 == Type) && (Dr7.Bits.RW2 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr2)) { (Address == SystemContext.SystemContextIa32->Dr2))
{
*Register = 2; *Register = 2;
} else if ((Dr7.Bits.G3 == 1) && } else if ((Dr7.Bits.G3 == 1) &&
(Dr7.Bits.LEN3 == Length) && (Dr7.Bits.LEN3 == Length) &&
(Dr7.Bits.RW3 == Type) && (Dr7.Bits.RW3 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr3)) { (Address == SystemContext.SystemContextIa32->Dr3))
{
*Register = 3; *Register = 3;
} else { } else {
Print ((CHAR16 *)L"No match found..\n"); Print ((CHAR16 *)L"No match found..\n");
@ -733,7 +727,6 @@ FindMatchingDebugRegister (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Disables the particular debug register. Disables the particular debug register.
@ -785,7 +778,6 @@ DisableDebugRegister (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Z1, [addr], [length] Z1, [addr], [length]
Z2, [addr], [length] Z2, [addr], [length]
@ -820,7 +812,6 @@ InsertBreakPoint (
} }
switch (Type) { switch (Type) {
case 0: // Software breakpoint case 0: // Software breakpoint
BreakType = SoftwareBreakpoint; BreakType = SoftwareBreakpoint;
break; break;
@ -858,7 +849,6 @@ InsertBreakPoint (
// Write Address, length data at particular DR register // Write Address, length data at particular DR register
Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType); Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) { if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported\n"); Print ((CHAR16 *)L"Not supported\n");
SendNotSupported (); SendNotSupported ();
@ -873,7 +863,6 @@ InsertBreakPoint (
SendSuccess (); SendSuccess ();
} }
/** /**
z1, [addr], [length] z1, [addr], [length]
z2, [addr], [length] z2, [addr], [length]
@ -908,7 +897,6 @@ RemoveBreakPoint (
} }
switch (Type) { switch (Type) {
case 0: // Software breakpoint case 0: // Software breakpoint
BreakType = SoftwareBreakpoint; BreakType = SoftwareBreakpoint;
break; break;
@ -937,7 +925,6 @@ RemoveBreakPoint (
// Find matching debug register // Find matching debug register
Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register); Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) { if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported.\n"); Print ((CHAR16 *)L"Not supported.\n");
SendNotSupported (); SendNotSupported ();
@ -960,7 +947,6 @@ RemoveBreakPoint (
SendSuccess (); SendSuccess ();
} }
VOID VOID
InitializeProcessor ( InitializeProcessor (
VOID VOID
@ -984,4 +970,3 @@ ValidateException (
{ {
return TRUE; return TRUE;
} }

View File

@ -35,7 +35,6 @@ BOOLEAN gProcessingFPacket = FALSE;
@param ErrNo Error information from the F reply packet or other source @param ErrNo Error information from the F reply packet or other source
**/ **/
VOID VOID
GdbCtrlCBreakMessage ( GdbCtrlCBreakMessage (
IN UINTN ErrNo IN UINTN ErrNo
@ -49,7 +48,6 @@ GdbCtrlCBreakMessage (
gCtrlCBreakFlag = TRUE; gCtrlCBreakFlag = TRUE;
} }
/** /**
Parse the F reply packet and extract the return value and an ErrNo if it exists. Parse the F reply packet and extract the return value and an ErrNo if it exists.
@ -76,7 +74,9 @@ GdbParseFReplyPacket (
RetCode = AsciiStrHexToUintn (&Packet[1]); RetCode = AsciiStrHexToUintn (&Packet[1]);
// Find 1st comma // Find 1st comma
for (;*Packet != '\0' && *Packet != ','; Packet++); for ( ; *Packet != '\0' && *Packet != ','; Packet++) {
}
if (*Packet == '\0') { if (*Packet == '\0') {
*ErrNo = 0; *ErrNo = 0;
return RetCode; return RetCode;
@ -85,7 +85,9 @@ GdbParseFReplyPacket (
*ErrNo = AsciiStrHexToUintn (++Packet); *ErrNo = AsciiStrHexToUintn (++Packet);
// Find 2nd comma // Find 2nd comma
for (;*Packet != '\0' && *Packet != ','; Packet++); for ( ; *Packet != '\0' && *Packet != ','; Packet++) {
}
if (*Packet == '\0') { if (*Packet == '\0') {
return RetCode; return RetCode;
} }
@ -97,7 +99,6 @@ GdbParseFReplyPacket (
return RetCode; return RetCode;
} }
/** /**
Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates Read data from a FileDescriptor. On success number of bytes read is returned. Zero indicates
the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero. the end of a file. On error -1 is returned. If count is zero, GdbRead returns zero.
@ -180,7 +181,6 @@ GdbRead (
return RetCode; return RetCode;
} }
/** /**
Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates Write data to a FileDescriptor. On success number of bytes written is returned. Zero indicates
nothing was written. On error -1 is returned. nothing was written. On error -1 is returned.
@ -260,7 +260,6 @@ GdbWrite (
return RetCode; return RetCode;
} }
/** /**
Reset the serial device. Reset the serial device.
@ -279,7 +278,6 @@ GdbSerialReset (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
data buts, and stop bits on a serial device. data buts, and stop bits on a serial device.
@ -321,7 +319,6 @@ GdbSerialSetAttributes (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
Set the control bits on a serial device Set the control bits on a serial device
@ -343,7 +340,6 @@ GdbSerialSetControl (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
Retrieves the status of the control bits on a serial device Retrieves the status of the control bits on a serial device
@ -364,7 +360,6 @@ GdbSerialGetControl (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
Writes data to a serial device. Writes data to a serial device.
@ -416,7 +411,6 @@ GdbSerialWrite (
@retval EFI_TIMEOUT The data write was stopped due to a timeout. @retval EFI_TIMEOUT The data write was stopped due to a timeout.
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
GdbSerialRead ( GdbSerialRead (
@ -442,7 +436,6 @@ GdbSerialRead (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
// //
// Template used to initialize the GDB Serial IO protocols // Template used to initialize the GDB Serial IO protocols
// //
@ -495,7 +488,6 @@ GDB_SERIAL_DEV gdbSerialDevTemplate = {
GDB_STDOUT GDB_STDOUT
}; };
/** /**
Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB. Make two serial consoles: 1) StdIn and StdOut via GDB. 2) StdErr via GDB.
@ -529,8 +521,10 @@ GdbInitializeSerialConsole (
// Make a new handle with Serial IO protocol and its device path on it. // Make a new handle with Serial IO protocol and its device path on it.
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&StdOutSerialDev->Handle, &StdOutSerialDev->Handle,
&gEfiSerialIoProtocolGuid, &StdOutSerialDev->SerialIo, &gEfiSerialIoProtocolGuid,
&gEfiDevicePathProtocolGuid, &StdOutSerialDev->DevicePath, &StdOutSerialDev->SerialIo,
&gEfiDevicePathProtocolGuid,
&StdOutSerialDev->DevicePath,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -538,10 +532,11 @@ GdbInitializeSerialConsole (
// Make a new handle with Serial IO protocol and its device path on it. // Make a new handle with Serial IO protocol and its device path on it.
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&StdErrSerialDev->Handle, &StdErrSerialDev->Handle,
&gEfiSerialIoProtocolGuid, &StdErrSerialDev->SerialIo, &gEfiSerialIoProtocolGuid,
&gEfiDevicePathProtocolGuid, &StdErrSerialDev->DevicePath, &StdErrSerialDev->SerialIo,
&gEfiDevicePathProtocolGuid,
&StdErrSerialDev->DevicePath,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }

View File

@ -29,7 +29,6 @@ EFI_EXCEPTION_TYPE_ENTRY gExceptionType[] = {
{ EXCEPT_X64_MACHINE_CHECK, GDB_SIGEMT } { EXCEPT_X64_MACHINE_CHECK, GDB_SIGEMT }
}; };
// The offsets of registers SystemContextX64. // The offsets of registers SystemContextX64.
// The fields in the array are in the gdb ordering. // The fields in the array are in the gdb ordering.
// HAVE TO DOUBLE-CHECK THE ORDER of the 24 regs // HAVE TO DOUBLE-CHECK THE ORDER of the 24 regs
@ -61,7 +60,6 @@ UINTN gRegisterOffsets[] = {
OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R15) OFFSET_OF (EFI_SYSTEM_CONTEXT_X64, R15)
}; };
/** /**
Return the number of entries in the gExceptionType[] Return the number of entries in the gExceptionType[]
@ -75,7 +73,6 @@ MaxEfiException (
return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY); return sizeof (gExceptionType)/sizeof (EFI_EXCEPTION_TYPE_ENTRY);
} }
/** /**
Return the number of entries in the gRegisters[] Return the number of entries in the gRegisters[]
@ -89,7 +86,6 @@ MaxRegisterCount (
return sizeof (gRegisterOffsets)/sizeof (UINTN); return sizeof (gRegisterOffsets)/sizeof (UINTN);
} }
/** /**
Check to see if the ISA is supported. Check to see if the ISA is supported.
ISA = Instruction Set Architecture ISA = Instruction Set Architecture
@ -104,7 +100,6 @@ CheckIsa (
return (BOOLEAN)(Isa == IsaX64); return (BOOLEAN)(Isa == IsaX64);
} }
/** /**
This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering This takes in the register number and the System Context, and returns a pointer to the RegNumber-th register in gdb ordering
It is, by default, set to find the register pointer of the X64 member It is, by default, set to find the register pointer of the X64 member
@ -119,11 +114,11 @@ FindPointerToRegister(
) )
{ {
UINT8 *TempPtr; UINT8 *TempPtr;
TempPtr = ((UINT8 *)SystemContext.SystemContextX64) + gRegisterOffsets[RegNumber]; TempPtr = ((UINT8 *)SystemContext.SystemContextX64) + gRegisterOffsets[RegNumber];
return (UINTN *)TempPtr; return (UINTN *)TempPtr;
} }
/** /**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -146,10 +141,10 @@ BasicReadRegister (
*OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)]; *OutBufPtr++ = mHexToStr[((*FindPointerToRegister (SystemContext, RegNumber) >> RegSize) & 0xf)];
RegSize = RegSize + 8; RegSize = RegSize + 8;
} }
return OutBufPtr; return OutBufPtr;
} }
/** p n /** p n
Reads the n-th register's value into an output buffer and sends it as a packet Reads the n-th register's value into an output buffer and sends it as a packet
@param SystemContext Register content at time of the exception @param SystemContext Register content at time of the exception
@ -179,7 +174,6 @@ ReadNthRegister (
SendPacket (OutBuffer); SendPacket (OutBuffer);
} }
/** g /** g
Reads the general registers into an output buffer and sends it as a packet Reads the general registers into an output buffer and sends it as a packet
@ -196,7 +190,8 @@ ReadGeneralRegisters (
CHAR8 *OutBufPtr; // pointer to the output buffer CHAR8 *OutBufPtr; // pointer to the output buffer
OutBufPtr = OutBuffer; OutBufPtr = OutBuffer;
for(i = 0 ; i < MaxRegisterCount() ; i++) { // there are only 24 registers to read for (i = 0; i < MaxRegisterCount (); i++) {
// there are only 24 registers to read
OutBufPtr = BasicReadRegister (SystemContext, i, OutBufPtr); OutBufPtr = BasicReadRegister (SystemContext, i, OutBufPtr);
} }
@ -204,7 +199,6 @@ ReadGeneralRegisters (
SendPacket (OutBuffer); SendPacket (OutBuffer);
} }
/** /**
Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr Adds the RegNumber-th register's value to the output buffer, starting at the given OutBufPtr
@ -245,11 +239,11 @@ BasicWriteRegister (
NewValue += (TempValue << RegSize); NewValue += (TempValue << RegSize);
RegSize = RegSize + 8; RegSize = RegSize + 8;
} }
*(FindPointerToRegister (SystemContext, RegNumber)) = NewValue; *(FindPointerToRegister (SystemContext, RegNumber)) = NewValue;
return InBufPtr; return InBufPtr;
} }
/** P n...=r... /** P n...=r...
Writes the new value of n-th register received into the input buffer to the n-th register Writes the new value of n-th register received into the input buffer to the n-th register
@ -274,6 +268,7 @@ WriteNthRegister (
while (*InBufPtr != '=') { while (*InBufPtr != '=') {
*RegNumBufPtr++ = *InBufPtr++; *RegNumBufPtr++ = *InBufPtr++;
} }
*RegNumBufPtr = '\0'; *RegNumBufPtr = '\0';
RegNumber = AsciiStrHexToUintn (RegNumBuffer); RegNumber = AsciiStrHexToUintn (RegNumBuffer);
@ -282,12 +277,12 @@ WriteNthRegister (
SendError (GDB_EINVALIDREGNUM); SendError (GDB_EINVALIDREGNUM);
return; return;
} }
InBufPtr++; // skips the '=' character InBufPtr++; // skips the '=' character
BasicWriteRegister (SystemContext, RegNumber, InBufPtr); BasicWriteRegister (SystemContext, RegNumber, InBufPtr);
SendSuccess (); SendSuccess ();
} }
/** G XX... /** G XX...
Writes the new values received into the input buffer to the general registers Writes the new values received into the input buffer to the general registers
@ -306,7 +301,8 @@ WriteGeneralRegisters (
// check to see if the buffer is the right size which is // check to see if the buffer is the right size which is
// 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 385 // 1 (for 'G') + 16 (for 16 registers) * 8 ( for 8 hex chars each) = 385
if (AsciiStrLen(InBuffer) != 385) { // 24 regs, 16 hex chars each, and the end '\0' (escape seq) if (AsciiStrLen (InBuffer) != 385) {
// 24 regs, 16 hex chars each, and the end '\0' (escape seq)
// Bad message. Message is not the right length // Bad message. Message is not the right length
SendError (GDB_EBADBUFSIZE); SendError (GDB_EBADBUFSIZE);
return; return;
@ -316,14 +312,14 @@ WriteGeneralRegisters (
// Read the new values for the registers from the input buffer to an array, NewValueArray. // Read the new values for the registers from the input buffer to an array, NewValueArray.
// The values in the array are in the gdb ordering // The values in the array are in the gdb ordering
for(i=0; i < MaxRegisterCount(); i++) { // there are only 16 registers to write for (i = 0; i < MaxRegisterCount (); i++) {
// there are only 16 registers to write
InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr); InBufPtr = BasicWriteRegister (SystemContext, i, InBufPtr);
} }
SendSuccess (); SendSuccess ();
} }
/** /**
Insert Single Step in the SystemContext Insert Single Step in the SystemContext
@ -337,8 +333,6 @@ AddSingleStep (
SystemContext.SystemContextX64->Rflags |= TF_BIT; // Setting the TF bit. SystemContext.SystemContextX64->Rflags |= TF_BIT; // Setting the TF bit.
} }
/** /**
Remove Single Step in the SystemContext Remove Single Step in the SystemContext
@ -352,8 +346,6 @@ RemoveSingleStep (
SystemContext.SystemContextX64->Rflags &= ~TF_BIT; // clearing the TF bit. SystemContext.SystemContextX64->Rflags &= ~TF_BIT; // clearing the TF bit.
} }
/** c [addr ] /** c [addr ]
Continue. addr is Address to resume. If addr is omitted, resume at current Continue. addr is Address to resume. If addr is omitted, resume at current
Address. Address.
@ -372,7 +364,6 @@ ContinueAtAddress (
} }
} }
/** s [addr ] /** s [addr ]
Single step. addr is the Address at which to resume. If addr is omitted, resume Single step. addr is the Address at which to resume. If addr is omitted, resume
at same Address. at same Address.
@ -393,7 +384,6 @@ SingleStep (
AddSingleStep (SystemContext); AddSingleStep (SystemContext);
} }
/** /**
Returns breakpoint data address from DR0-DR3 based on the input breakpoint Returns breakpoint data address from DR0-DR3 based on the input breakpoint
number number
@ -499,7 +489,6 @@ GetBreakpointType (
return Type; return Type;
} }
/** /**
Parses Length and returns the length which DR7 LENn field accepts. Parses Length and returns the length which DR7 LENn field accepts.
For example: If we receive 1-Byte length then we should return 0. For example: If we receive 1-Byte length then we should return 0.
@ -515,18 +504,21 @@ ConvertLengthData (
IN UINTN Length IN UINTN Length
) )
{ {
if (Length == 1) { //1-Byte length if (Length == 1) {
// 1-Byte length
return 0; return 0;
} else if (Length == 2) { //2-Byte length } else if (Length == 2) {
// 2-Byte length
return 1; return 1;
} else if (Length == 4) { //4-Byte length } else if (Length == 4) {
// 4-Byte length
return 3; return 3;
} else { //Undefined or 8-byte length } else {
// Undefined or 8-byte length
return 2; return 2;
} }
} }
/** /**
Finds the next free debug register. If all the registers are occupied then Finds the next free debug register. If all the registers are occupied then
EFI_OUT_OF_RESOURCES is returned. EFI_OUT_OF_RESOURCES is returned.
@ -562,7 +554,6 @@ FindNextFreeDebugRegister (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Enables the debug register. Writes Address value to appropriate DR0-3 register. Enables the debug register. Writes Address value to appropriate DR0-3 register.
Sets LENn, Gn, RWn bits in DR7 register. Sets LENn, Gn, RWn bits in DR7 register.
@ -599,7 +590,8 @@ EnableDebugRegister (
// Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
// software breakpoint. We should send empty packet in both these cases. // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) || if ((Type == (BREAK_TYPE)DataRead) ||
(Type == (BREAK_TYPE)SoftwareBreakpoint)) { (Type == (BREAK_TYPE)SoftwareBreakpoint))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -636,7 +628,6 @@ EnableDebugRegister (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Returns register number 0 - 3 for the matching debug register. Returns register number 0 - 3 for the matching debug register.
This function compares incoming Address, Type, Length and This function compares incoming Address, Type, Length and
@ -667,7 +658,8 @@ FindMatchingDebugRegister (
// Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle // Hardware doesn't support ReadWatch (z3 packet) type. GDB can handle
// software breakpoint. We should send empty packet in both these cases. // software breakpoint. We should send empty packet in both these cases.
if ((Type == (BREAK_TYPE)DataRead) || if ((Type == (BREAK_TYPE)DataRead) ||
(Type == (BREAK_TYPE)SoftwareBreakpoint)) { (Type == (BREAK_TYPE)SoftwareBreakpoint))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -679,22 +671,26 @@ FindMatchingDebugRegister (
if ((Dr7.Bits.G0 == 1) && if ((Dr7.Bits.G0 == 1) &&
(Dr7.Bits.LEN0 == Length) && (Dr7.Bits.LEN0 == Length) &&
(Dr7.Bits.RW0 == Type) && (Dr7.Bits.RW0 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr0)) { (Address == SystemContext.SystemContextIa32->Dr0))
{
*Register = 0; *Register = 0;
} else if ((Dr7.Bits.G1 == 1) && } else if ((Dr7.Bits.G1 == 1) &&
(Dr7.Bits.LEN1 == Length) && (Dr7.Bits.LEN1 == Length) &&
(Dr7.Bits.RW1 == Type) && (Dr7.Bits.RW1 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr1)) { (Address == SystemContext.SystemContextIa32->Dr1))
{
*Register = 1; *Register = 1;
} else if ((Dr7.Bits.G2 == 1) && } else if ((Dr7.Bits.G2 == 1) &&
(Dr7.Bits.LEN2 == Length) && (Dr7.Bits.LEN2 == Length) &&
(Dr7.Bits.RW2 == Type) && (Dr7.Bits.RW2 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr2)) { (Address == SystemContext.SystemContextIa32->Dr2))
{
*Register = 2; *Register = 2;
} else if ((Dr7.Bits.G3 == 1) && } else if ((Dr7.Bits.G3 == 1) &&
(Dr7.Bits.LEN3 == Length) && (Dr7.Bits.LEN3 == Length) &&
(Dr7.Bits.RW3 == Type) && (Dr7.Bits.RW3 == Type) &&
(Address == SystemContext.SystemContextIa32->Dr3)) { (Address == SystemContext.SystemContextIa32->Dr3))
{
*Register = 3; *Register = 3;
} else { } else {
Print ((CHAR16 *)L"No match found..\n"); Print ((CHAR16 *)L"No match found..\n");
@ -704,7 +700,6 @@ FindMatchingDebugRegister (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Disables the particular debug register. Disables the particular debug register.
@ -790,7 +785,6 @@ InsertBreakPoint (
} }
switch (Type) { switch (Type) {
case 0: // Software breakpoint case 0: // Software breakpoint
BreakType = SoftwareBreakpoint; BreakType = SoftwareBreakpoint;
break; break;
@ -828,7 +822,6 @@ InsertBreakPoint (
// Write Address, length data at particular DR register // Write Address, length data at particular DR register
Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType); Status = EnableDebugRegister (SystemContext, Register, Address, Length, (UINTN)BreakType);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) { if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported\n"); Print ((CHAR16 *)L"Not supported\n");
SendNotSupported (); SendNotSupported ();
@ -843,7 +836,6 @@ InsertBreakPoint (
SendSuccess (); SendSuccess ();
} }
/** /**
z1, [addr], [length] z1, [addr], [length]
z2, [addr], [length] z2, [addr], [length]
@ -878,7 +870,6 @@ RemoveBreakPoint (
} }
switch (Type) { switch (Type) {
case 0: // Software breakpoint case 0: // Software breakpoint
BreakType = SoftwareBreakpoint; BreakType = SoftwareBreakpoint;
break; break;
@ -907,7 +898,6 @@ RemoveBreakPoint (
// Find matching debug register // Find matching debug register
Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register); Status = FindMatchingDebugRegister (SystemContext, Address, Length, (UINTN)BreakType, &Register);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) { if (Status == EFI_UNSUPPORTED) {
Print ((CHAR16 *)L"Not supported.\n"); Print ((CHAR16 *)L"Not supported.\n");
SendNotSupported (); SendNotSupported ();
@ -930,7 +920,6 @@ RemoveBreakPoint (
SendSuccess (); SendSuccess ();
} }
VOID VOID
InitializeProcessor ( InitializeProcessor (
VOID VOID
@ -954,4 +943,3 @@ ValidateException (
{ {
return TRUE; return TRUE;
} }

View File

@ -11,7 +11,6 @@
#include <Library/ExtractGuidedSectionLib.h> #include <Library/ExtractGuidedSectionLib.h>
// //
// The GUID for this protocol mathes the Decompression scheme being used // The GUID for this protocol mathes the Decompression scheme being used
// So for example LZMA would be gLzmaCustomDecompressGuid // So for example LZMA would be gLzmaCustomDecompressGuid
@ -27,4 +26,3 @@ typedef struct {
} EXTRACT_SECTION_HOB; } EXTRACT_SECTION_HOB;
#endif #endif

View File

@ -18,7 +18,6 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __EDKII_NV_VAR_STORE_FORMATTED_H__ #ifndef __EDKII_NV_VAR_STORE_FORMATTED_H__
#define __EDKII_NV_VAR_STORE_FORMATTED_H__ #define __EDKII_NV_VAR_STORE_FORMATTED_H__

View File

@ -14,7 +14,6 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __EDKII_PLATFORM_HAS_DEVICE_TREE_H__ #ifndef __EDKII_PLATFORM_HAS_DEVICE_TREE_H__
#define __EDKII_PLATFORM_HAS_DEVICE_TREE_H__ #define __EDKII_PLATFORM_HAS_DEVICE_TREE_H__

View File

@ -45,6 +45,7 @@ typedef struct {
/* Check Val (unsigned) is a power of 2 (has only one bit set) */ /* Check Val (unsigned) is a power of 2 (has only one bit set) */
#define IS_POWER_OF_2(Val) ((Val) != 0 && (((Val) & ((Val) - 1)) == 0)) #define IS_POWER_OF_2(Val) ((Val) != 0 && (((Val) & ((Val) - 1)) == 0))
/* Android boot image page size is not specified, but it should be power of 2 /* Android boot image page size is not specified, but it should be power of 2
* and larger than boot header */ * and larger than boot header */
#define IS_VALID_ANDROID_PAGE_SIZE(Val) \ #define IS_VALID_ANDROID_PAGE_SIZE(Val) \

View File

@ -12,8 +12,6 @@
#ifndef __GDB_TIMER_LIB__ #ifndef __GDB_TIMER_LIB__
#define __GDB_TIMER_LIB__ #define __GDB_TIMER_LIB__
/** /**
Setup all the hardware needed for the debug agents timer. Setup all the hardware needed for the debug agents timer.
@ -26,7 +24,6 @@ DebugAgentTimerIntialize (
VOID VOID
); );
/** /**
Set the period for the debug agent timer. Zero means disable the timer. Set the period for the debug agent timer. Zero means disable the timer.
@ -39,7 +36,6 @@ DebugAgentTimerSetPeriod (
IN UINT32 TimerPeriodMilliseconds IN UINT32 TimerPeriodMilliseconds
); );
/** /**
Perform End Of Interrupt for the debug agent timer. This is called in the Perform End Of Interrupt for the debug agent timer. This is called in the
interrupt handler after the interrupt has been processed. interrupt handler after the interrupt has been processed.
@ -52,5 +48,3 @@ DebugAgentTimerEndOfInterrupt (
); );
#endif #endif

View File

@ -51,9 +51,6 @@ typedef enum {
MapOperationMaximum MapOperationMaximum
} DMA_MAP_OPERATION; } DMA_MAP_OPERATION;
/** /**
Provides the DMA controller-specific addresses needed to access system memory. Provides the DMA controller-specific addresses needed to access system memory.
@ -84,9 +81,6 @@ DmaMap (
OUT VOID **Mapping OUT VOID **Mapping
); );
/** /**
Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer Completes the DmaMapBusMasterRead, DmaMapBusMasterWrite, or DmaMapBusMasterCommonBuffer
operation and releases any corresponding resources. operation and releases any corresponding resources.
@ -103,7 +97,6 @@ DmaUnmap (
IN VOID *Mapping IN VOID *Mapping
); );
/** /**
Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer. Allocates pages that are suitable for an DmaMap() of type MapOperationBusMasterCommonBuffer.
mapping. mapping.
@ -129,7 +122,6 @@ DmaAllocateBuffer (
OUT VOID **HostAddress OUT VOID **HostAddress
); );
/** /**
Frees memory that was allocated with DmaAllocateBuffer(). Frees memory that was allocated with DmaAllocateBuffer().
@ -148,7 +140,6 @@ DmaFreeBuffer (
IN VOID *HostAddress IN VOID *HostAddress
); );
/** /**
Allocates pages that are suitable for an DmaMap() of type Allocates pages that are suitable for an DmaMap() of type
MapOperationBusMasterCommonBuffer mapping, at the requested alignment. MapOperationBusMasterCommonBuffer mapping, at the requested alignment.
@ -177,5 +168,4 @@ DmaAllocateAlignedBuffer (
OUT VOID **HostAddress OUT VOID **HostAddress
); );
#endif #endif

View File

@ -55,7 +55,6 @@ typedef enum {
EfiOpenMaxValue EfiOpenMaxValue
} EFI_OPEN_FILE_TYPE; } EFI_OPEN_FILE_TYPE;
/// Public information about the open file /// Public information about the open file
typedef struct { typedef struct {
UINTN Version; // Common information UINTN Version; // Common information
@ -97,10 +96,8 @@ typedef struct {
EFI_IP_ADDRESS ServerIp; // Information valid for t: EFI_IP_ADDRESS ServerIp; // Information valid for t:
BOOLEAN IsDirty; BOOLEAN IsDirty;
BOOLEAN IsBufferValid; BOOLEAN IsBufferValid;
} EFI_OPEN_FILE; } EFI_OPEN_FILE;
/// Type of Seek to perform /// Type of Seek to perform
typedef enum { typedef enum {
EfiSeekStart, EfiSeekStart,
@ -109,7 +106,6 @@ typedef enum {
EfiSeekMax EfiSeekMax
} EFI_SEEK_TYPE; } EFI_SEEK_TYPE;
/** /**
Open a device named by PathName. The PathName includes a device name and Open a device named by PathName. The PathName includes a device name and
path separated by a :. See file header for more details on the PathName path separated by a :. See file header for more details on the PathName
@ -158,7 +154,6 @@ EfiDeviceOpenByType (
IN UINTN Index IN UINTN Index
); );
/** /**
Close a file handle opened by EfiOpen() and free all resources allocated by Close a file handle opened by EfiOpen() and free all resources allocated by
EfiOpen(). EfiOpen().
@ -174,7 +169,6 @@ EfiClose (
IN EFI_OPEN_FILE *Stream IN EFI_OPEN_FILE *Stream
); );
/** /**
Return the size of the file represented by Stream. Also return the current Return the size of the file represented by Stream. Also return the current
Seek position. Opening a file will enable a valid file size to be returned. Seek position. Opening a file will enable a valid file size to be returned.
@ -191,7 +185,6 @@ EfiTell (
OUT UINT64 *CurrentPosition OPTIONAL OUT UINT64 *CurrentPosition OPTIONAL
); );
/** /**
Seek to the Offset location in the file. LoadFile and FV device types do Seek to the Offset location in the file. LoadFile and FV device types do
not support EfiSeek(). It is not possible to grow the file size using not support EfiSeek(). It is not possible to grow the file size using
@ -220,7 +213,6 @@ EfiSeek (
IN EFI_SEEK_TYPE SeekType IN EFI_SEEK_TYPE SeekType
); );
/** /**
Read BufferSize bytes from the current location in the file. For load file Read BufferSize bytes from the current location in the file. For load file
and FV case you must read the entire file. and FV case you must read the entire file.
@ -244,7 +236,6 @@ EfiRead (
OUT UINTN *BufferSize OUT UINTN *BufferSize
); );
/** /**
Read the entire file into a buffer. This routine allocates the buffer and Read the entire file into a buffer. This routine allocates the buffer and
returns it to the user full of the read data. returns it to the user full of the read data.
@ -271,7 +262,6 @@ EfiReadAllocatePool (
OUT UINTN *BufferSize OUT UINTN *BufferSize
); );
/** /**
Write data back to the file. Write data back to the file.
@ -294,7 +284,6 @@ EfiWrite (
OUT UINTN *BufferSize OUT UINTN *BufferSize
); );
/** /**
Return the number of devices of the current type active in the system Return the number of devices of the current type active in the system
@ -308,7 +297,6 @@ EfiGetDeviceCounts (
IN EFI_OPEN_FILE_TYPE Type IN EFI_OPEN_FILE_TYPE Type
); );
/** /**
Set the Current Working Directory (CWD). If a call is made to EfiOpen () and Set the Current Working Directory (CWD). If a call is made to EfiOpen () and
the path does not contain a device name, The CWD is prepended to the path. the path does not contain a device name, The CWD is prepended to the path.

View File

@ -6,11 +6,9 @@
**/ **/
#ifndef __EFI_RESET_SYSTEM_LIB_H___ #ifndef __EFI_RESET_SYSTEM_LIB_H___
#define __EFI_RESET_SYSTEM_LIB_H___ #define __EFI_RESET_SYSTEM_LIB_H___
/** /**
Resets the entire platform. Resets the entire platform.
@ -31,8 +29,6 @@ LibResetSystem (
IN CHAR16 *ResetData OPTIONAL IN CHAR16 *ResetData OPTIONAL
); );
/** /**
Initialize any infrastructure required for LibResetSystem () to function. Initialize any infrastructure required for LibResetSystem () to function.

View File

@ -10,8 +10,6 @@
#ifndef __GDB_SERIAL_LIB_H__ #ifndef __GDB_SERIAL_LIB_H__
#define __GDB_SERIAL_LIB_H__ #define __GDB_SERIAL_LIB_H__
/** /**
Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
data buts, and stop bits on a serial device. This call is optional as the serial data buts, and stop bits on a serial device. This call is optional as the serial
@ -40,7 +38,6 @@ GdbSerialInit (
IN UINT8 StopBits IN UINT8 StopBits
); );
/** /**
Check to see if a character is available from GDB. Do not read the character as that is Check to see if a character is available from GDB. Do not read the character as that is
done via GdbGetChar(). done via GdbGetChar().
@ -67,7 +64,6 @@ GdbGetChar (
VOID VOID
); );
/** /**
Send a character to GDB. This function must be able to run in interrupt context. Send a character to GDB. This function must be able to run in interrupt context.
@ -82,7 +78,6 @@ GdbPutChar (
IN CHAR8 Char IN CHAR8 Char
); );
/** /**
Send an ASCII string to GDB. This function must be able to run in interrupt context. Send an ASCII string to GDB. This function must be able to run in interrupt context.
@ -96,6 +91,4 @@ GdbPutString (
IN CHAR8 *String IN CHAR8 *String
); );
#endif #endif

View File

@ -6,15 +6,18 @@
**/ **/
#ifndef __RUNTIME_SERVICES_LIB_H__ #ifndef __RUNTIME_SERVICES_LIB_H__
#define __RUNTIME_SERVICES_LIB_H__ #define __RUNTIME_SERVICES_LIB_H__
VOID VOID
LibMtcInitialize (VOID); LibMtcInitialize (
VOID
);
VOID VOID
LibMtcVirtualAddressChangeEvent (VOID); LibMtcVirtualAddressChangeEvent (
VOID
);
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
@ -27,13 +30,15 @@ LibMtcGetNextMonotonicCount (
OUT UINT64 *Count OUT UINT64 *Count
); );
VOID
LibVariableInitialize (
VOID
);
VOID VOID
LibVariableInitialize (VOID); LibVariableVirtualAddressChangeEvent (
VOID VOID
LibVariableVirtualAddressChangeEvent (VOID); );
EFI_STATUS EFI_STATUS
LibGetVariable ( LibGetVariable (
@ -68,13 +73,15 @@ LibQueryVariableInfo (
OUT UINT64 *MaximumVariableSize OUT UINT64 *MaximumVariableSize
); );
VOID
LibResetInitializeReset (
VOID
);
VOID VOID
LibResetInitializeReset (VOID); LibResetVirtualAddressChangeEvent (
VOID VOID
LibResetVirtualAddressChangeEvent (VOID); );
VOID VOID
LibResetSystem ( LibResetSystem (
@ -84,12 +91,15 @@ LibResetSystem (
IN CHAR16 *ResetData OPTIONAL IN CHAR16 *ResetData OPTIONAL
); );
VOID
LibCapsuleInitialize (
VOID
);
VOID VOID
LibCapsuleInitialize (VOID); LibCapsuleVirtualAddressChangeEvent (
VOID VOID
LibCapsuleVirtualAddressChangeEvent (VOID); );
EFI_STATUS EFI_STATUS
LibUpdateCapsule ( LibUpdateCapsule (
@ -106,13 +116,15 @@ QueryCapsuleCapabilities (
OUT EFI_RESET_TYPE *ResetType OUT EFI_RESET_TYPE *ResetType
); );
VOID
LibRtcInitialize (
VOID
);
VOID VOID
LibRtcInitialize (VOID); LibRtcVirtualAddressChangeEvent (
VOID VOID
LibRtcVirtualAddressChangeEvent (VOID); );
EFI_STATUS EFI_STATUS
LibGetTime ( LibGetTime (
@ -138,12 +150,15 @@ LibSetWakeupTime (
OUT EFI_TIME *Time OUT EFI_TIME *Time
); );
VOID
LibReportStatusCodeInitialize (
VOID
);
VOID VOID
LibReportStatusCodeInitialize (VOID); LibReportStatusCodeVirtualAddressChangeEvent (
VOID VOID
LibReportStatusCodeVirtualAddressChangeEvent (VOID); );
EFI_STATUS EFI_STATUS
LibReportStatusCode ( LibReportStatusCode (
@ -154,6 +169,4 @@ LibReportStatusCode (
IN EFI_STATUS_CODE_DATA *Data OPTIONAL IN EFI_STATUS_CODE_DATA *Data OPTIONAL
); );
#endif #endif

View File

@ -87,4 +87,5 @@ EFIAPI
NorFlashPrintInfo ( NorFlashPrintInfo (
IN NOR_FLASH_INFO *Info IN NOR_FLASH_INFO *Info
); );
#endif #endif

View File

@ -31,7 +31,6 @@ FfsFindNextVolume (
IN OUT EFI_PEI_FV_HANDLE *VolumeHandle IN OUT EFI_PEI_FV_HANDLE *VolumeHandle
); );
/** /**
This service enables discovery of additional firmware files. This service enables discovery of additional firmware files.
@ -53,7 +52,6 @@ FfsFindNextFile (
IN OUT EFI_PEI_FILE_HANDLE *FileHandle IN OUT EFI_PEI_FILE_HANDLE *FileHandle
); );
/** /**
This service enables discovery sections of a given type within a valid FFS file. This service enables discovery sections of a given type within a valid FFS file.
@ -74,7 +72,6 @@ FfsFindSectionData (
OUT VOID **SectionData OUT VOID **SectionData
); );
/** /**
Find a file in the volume by name Find a file in the volume by name
@ -101,7 +98,6 @@ FfsFindFileByName (
OUT EFI_PEI_FILE_HANDLE *FileHandle OUT EFI_PEI_FILE_HANDLE *FileHandle
); );
/** /**
Get information about the file by name. Get information about the file by name.
@ -125,7 +121,6 @@ FfsGetFileInfo (
OUT EFI_FV_FILE_INFO *FileInfo OUT EFI_FV_FILE_INFO *FileInfo
); );
/** /**
Get Information about the volume by name Get Information about the volume by name
@ -149,8 +144,6 @@ FfsGetVolumeInfo (
OUT EFI_FV_INFO *VolumeInfo OUT EFI_FV_INFO *VolumeInfo
); );
/** /**
Get Fv image from the FV type file, then add FV & FV2 Hob. Get Fv image from the FV type file, then add FV & FV2 Hob.
@ -166,7 +159,6 @@ FfsProcessFvFile (
IN EFI_PEI_FILE_HANDLE FvFileHandle IN EFI_PEI_FILE_HANDLE FvFileHandle
); );
/** /**
Search through every FV until you find a file of type FileType Search through every FV until you find a file of type FileType
@ -186,7 +178,6 @@ FfsAnyFvFindFirstFile (
OUT EFI_PEI_FILE_HANDLE *FileHandle OUT EFI_PEI_FILE_HANDLE *FileHandle
); );
/** /**
Get Fv image from the FV type file, then add FV & FV2 Hob. Get Fv image from the FV type file, then add FV & FV2 Hob.
@ -203,7 +194,6 @@ FfsProcessFvFile (
IN EFI_PEI_FILE_HANDLE FvFileHandle IN EFI_PEI_FILE_HANDLE FvFileHandle
); );
/** /**
This service enables PEIMs to ascertain the present value of the boot mode. This service enables PEIMs to ascertain the present value of the boot mode.
@ -217,7 +207,6 @@ GetBootMode (
VOID VOID
); );
/** /**
This service enables PEIMs to update the boot mode variable. This service enables PEIMs to update the boot mode variable.
@ -247,7 +236,6 @@ GetHobList (
VOID VOID
); );
/** /**
Updates the pointer to the HOB list. Updates the pointer to the HOB list.
@ -284,7 +272,6 @@ CreateHob (
IN UINT16 HobLenght IN UINT16 HobLenght
); );
/** /**
Returns the next instance of a HOB type from the starting HOB. Returns the next instance of a HOB type from the starting HOB.
@ -371,7 +358,6 @@ GetFirstGuidHob (
IN CONST EFI_GUID *Guid IN CONST EFI_GUID *Guid
); );
/** /**
Builds a HOB for a loaded PE32 module. Builds a HOB for a loaded PE32 module.
@ -511,7 +497,6 @@ BuildFvHobs (
IN EFI_RESOURCE_ATTRIBUTE_TYPE *ResourceAttribute OPTIONAL IN EFI_RESOURCE_ATTRIBUTE_TYPE *ResourceAttribute OPTIONAL
); );
/** /**
Builds a EFI_HOB_TYPE_FV2 HOB. Builds a EFI_HOB_TYPE_FV2 HOB.
@ -605,7 +590,6 @@ UpdateStackHob (
IN UINT64 Length IN UINT64 Length
); );
/** /**
Builds a HOB for the BSP store. Builds a HOB for the BSP store.
@ -648,7 +632,6 @@ BuildMemoryAllocationHob (
IN EFI_MEMORY_TYPE MemoryType IN EFI_MEMORY_TYPE MemoryType
); );
VOID VOID
EFIAPI EFIAPI
BuildExtractSectionHob ( BuildExtractSectionHob (
@ -663,7 +646,6 @@ BuildPeCoffLoaderHob (
VOID VOID
); );
/** /**
Allocates one or more 4KB pages of type EfiBootServicesData. Allocates one or more 4KB pages of type EfiBootServicesData.
@ -701,7 +683,6 @@ AllocatePool (
IN UINTN AllocationSize IN UINTN AllocationSize
); );
/** /**
Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment. Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
@ -725,7 +706,6 @@ AllocateAlignedPages (
IN UINTN Alignment IN UINTN Alignment
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LoadPeCoffImage ( LoadPeCoffImage (

View File

@ -12,7 +12,6 @@
#ifndef __REAL_TIME_CLOCK_LIB__ #ifndef __REAL_TIME_CLOCK_LIB__
#define __REAL_TIME_CLOCK_LIB__ #define __REAL_TIME_CLOCK_LIB__
/** /**
Returns the current time and date information, and the time-keeping capabilities Returns the current time and date information, and the time-keeping capabilities
of the hardware platform. of the hardware platform.
@ -33,7 +32,6 @@ LibGetTime (
OUT EFI_TIME_CAPABILITIES *Capabilities OUT EFI_TIME_CAPABILITIES *Capabilities
); );
/** /**
Sets the current local time and date information. Sets the current local time and date information.
@ -50,7 +48,6 @@ LibSetTime (
IN EFI_TIME *Time IN EFI_TIME *Time
); );
/** /**
Returns the current wakeup alarm clock setting. Returns the current wakeup alarm clock setting.
@ -71,7 +68,6 @@ LibGetWakeupTime (
OUT EFI_TIME *Time OUT EFI_TIME *Time
); );
/** /**
Sets the system wakeup alarm clock time. Sets the system wakeup alarm clock time.
@ -92,8 +88,6 @@ LibSetWakeupTime (
OUT EFI_TIME *Time OUT EFI_TIME *Time
); );
/** /**
This is the declaration of an EFI image entry point. This can be the entry point to an application This is the declaration of an EFI image entry point. This can be the entry point to an application
written to this specification, an EFI boot service driver, or an EFI runtime driver. written to this specification, an EFI boot service driver, or an EFI runtime driver.
@ -111,7 +105,6 @@ LibRtcInitialize (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
); );
/** /**
Fixup internal data so that EFI can be call in virtual mode. Fixup internal data so that EFI can be call in virtual mode.
Call the passed in Child Notify event and convert any pointers in Call the passed in Child Notify event and convert any pointers in
@ -127,6 +120,4 @@ LibRtcVirtualNotifyEvent (
IN VOID *Context IN VOID *Context
); );
#endif #endif

View File

@ -88,7 +88,6 @@ EFI_STATUS
IN EMBEDDED_GPIO_MODE Mode IN EMBEDDED_GPIO_MODE Mode
); );
/** /**
Gets the mode (function) of a GPIO pin Gets the mode (function) of a GPIO pin
@ -110,7 +109,6 @@ EFI_STATUS
OUT EMBEDDED_GPIO_MODE *Mode OUT EMBEDDED_GPIO_MODE *Mode
); );
/** /**
Sets the pull-up / pull-down resistor of a GPIO pin Sets the pull-up / pull-down resistor of a GPIO pin
@ -132,7 +130,6 @@ EFI_STATUS
IN EMBEDDED_GPIO_PULL Direction IN EMBEDDED_GPIO_PULL Direction
); );
struct _EMBEDDED_GPIO_PPI { struct _EMBEDDED_GPIO_PPI {
EMBEDDED_GPIO_GET Get; EMBEDDED_GPIO_GET Get;
EMBEDDED_GPIO_SET Set; EMBEDDED_GPIO_SET Set;

View File

@ -23,7 +23,6 @@
#ifndef __EMBEDDED_DEVICE_PROTOCOL_H__ #ifndef __EMBEDDED_DEVICE_PROTOCOL_H__
#define __EMBEDDED_DEVICE_PROTOCOL_H__ #define __EMBEDDED_DEVICE_PROTOCOL_H__
// //
// Protocol GUID // Protocol GUID
// //
@ -32,8 +31,6 @@
#define EMBEDDED_DEVICE_PROTOCOL_GUID \ #define EMBEDDED_DEVICE_PROTOCOL_GUID \
{ 0xbf4b9d10, 0x13ec, 0x43dd, { 0x88, 0x80, 0xe9, 0xb, 0x71, 0x8f, 0x27, 0xde } } { 0xbf4b9d10, 0x13ec, 0x43dd, { 0x88, 0x80, 0xe9, 0xb, 0x71, 0x8f, 0x27, 0xde } }
typedef struct { typedef struct {
UINT16 VendorId; UINT16 VendorId;
UINT16 DeviceId; UINT16 DeviceId;
@ -48,5 +45,3 @@ typedef struct {
extern EFI_GUID gEmbeddedDeviceGuid; extern EFI_GUID gEmbeddedDeviceGuid;
#endif #endif

View File

@ -30,6 +30,7 @@ EFI_STATUS
IN UINTN Length, IN UINTN Length,
OUT VOID *Buffer OUT VOID *Buffer
) )
/*++ /*++
Routine Description: Routine Description:
@ -58,6 +59,7 @@ EFI_STATUS
IN UINTN Length, IN UINTN Length,
IN VOID *Buffer IN VOID *Buffer
) )
/*++ /*++
Routine Description: Routine Description:

View File

@ -51,6 +51,7 @@ EFI_STATUS
IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_PIN Gpio,
OUT UINTN *Value OUT UINTN *Value
); );
/*++ /*++
Routine Description: Routine Description:
@ -69,7 +70,6 @@ Returns:
--*/ --*/
typedef typedef
EFI_STATUS EFI_STATUS
(EFIAPI *EMBEDDED_GPIO_SET)( (EFIAPI *EMBEDDED_GPIO_SET)(
@ -77,6 +77,7 @@ EFI_STATUS
IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_PIN Gpio,
IN EMBEDDED_GPIO_MODE Mode IN EMBEDDED_GPIO_MODE Mode
); );
/*++ /*++
Routine Description: Routine Description:
@ -95,7 +96,6 @@ Returns:
--*/ --*/
typedef typedef
EFI_STATUS EFI_STATUS
(EFIAPI *EMBEDDED_GPIO_GET_MODE)( (EFIAPI *EMBEDDED_GPIO_GET_MODE)(
@ -103,6 +103,7 @@ EFI_STATUS
IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_PIN Gpio,
OUT EMBEDDED_GPIO_MODE *Mode OUT EMBEDDED_GPIO_MODE *Mode
); );
/*++ /*++
Routine Description: Routine Description:
@ -121,7 +122,6 @@ Returns:
--*/ --*/
typedef typedef
EFI_STATUS EFI_STATUS
(EFIAPI *EMBEDDED_GPIO_SET_PULL)( (EFIAPI *EMBEDDED_GPIO_SET_PULL)(
@ -129,6 +129,7 @@ EFI_STATUS
IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_PIN Gpio,
IN EMBEDDED_GPIO_PULL Direction IN EMBEDDED_GPIO_PULL Direction
); );
/*++ /*++
Routine Description: Routine Description:
@ -147,8 +148,6 @@ Returns:
--*/ --*/
struct _EMBEDDED_GPIO { struct _EMBEDDED_GPIO {
EMBEDDED_GPIO_GET Get; EMBEDDED_GPIO_GET Get;
EMBEDDED_GPIO_SET Set; EMBEDDED_GPIO_SET Set;

View File

@ -20,7 +20,6 @@
#include <Protocol/DebugSupport.h> #include <Protocol/DebugSupport.h>
// //
// Protocol GUID // Protocol GUID
// //
@ -29,13 +28,10 @@
#define EFI_HARDWARE_INTERRUPT_PROTOCOL_GGUID \ #define EFI_HARDWARE_INTERRUPT_PROTOCOL_GGUID \
{ 0x2890B3EA, 0x053D, 0x1643, { 0xAD, 0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } } { 0x2890B3EA, 0x053D, 0x1643, { 0xAD, 0x0C, 0xD6, 0x48, 0x08, 0xDA, 0x3F, 0xF1 } }
typedef struct _EFI_HARDWARE_INTERRUPT_PROTOCOL EFI_HARDWARE_INTERRUPT_PROTOCOL; typedef struct _EFI_HARDWARE_INTERRUPT_PROTOCOL EFI_HARDWARE_INTERRUPT_PROTOCOL;
typedef UINTN HARDWARE_INTERRUPT_SOURCE; typedef UINTN HARDWARE_INTERRUPT_SOURCE;
/** /**
C Interrupt Handler calledin the interrupt context when Source interrupt is active. C Interrupt Handler calledin the interrupt context when Source interrupt is active.
@ -53,7 +49,6 @@ VOID
IN EFI_SYSTEM_CONTEXT SystemContext IN EFI_SYSTEM_CONTEXT SystemContext
); );
/** /**
Register Handler for the specified interrupt source. Register Handler for the specified interrupt source.
@ -73,7 +68,6 @@ EFI_STATUS
IN HARDWARE_INTERRUPT_HANDLER Handler IN HARDWARE_INTERRUPT_HANDLER Handler
); );
/** /**
Enable interrupt source Source. Enable interrupt source Source.
@ -91,8 +85,6 @@ EFI_STATUS
IN HARDWARE_INTERRUPT_SOURCE Source IN HARDWARE_INTERRUPT_SOURCE Source
); );
/** /**
Disable interrupt source Source. Disable interrupt source Source.
@ -110,7 +102,6 @@ EFI_STATUS
IN HARDWARE_INTERRUPT_SOURCE Source IN HARDWARE_INTERRUPT_SOURCE Source
); );
/** /**
Return current state of interrupt source Source. Return current state of interrupt source Source.
@ -148,7 +139,6 @@ EFI_STATUS
IN HARDWARE_INTERRUPT_SOURCE Source IN HARDWARE_INTERRUPT_SOURCE Source
); );
struct _EFI_HARDWARE_INTERRUPT_PROTOCOL { struct _EFI_HARDWARE_INTERRUPT_PROTOCOL {
HARDWARE_INTERRUPT_REGISTER RegisterInterruptSource; HARDWARE_INTERRUPT_REGISTER RegisterInterruptSource;
HARDWARE_INTERRUPT_ENABLE EnableInterruptSource; HARDWARE_INTERRUPT_ENABLE EnableInterruptSource;
@ -160,5 +150,3 @@ struct _EFI_HARDWARE_INTERRUPT_PROTOCOL {
extern EFI_GUID gHardwareInterruptProtocolGuid; extern EFI_GUID gHardwareInterruptProtocolGuid;
#endif #endif

View File

@ -46,7 +46,6 @@ EFI_STATUS
IN HARDWARE_INTERRUPT_HANDLER Handler IN HARDWARE_INTERRUPT_HANDLER Handler
); );
/** /**
Enable interrupt source Source. Enable interrupt source Source.
@ -64,7 +63,6 @@ EFI_STATUS
IN HARDWARE_INTERRUPT_SOURCE Source IN HARDWARE_INTERRUPT_SOURCE Source
); );
/** /**
Disable interrupt source Source. Disable interrupt source Source.
@ -82,7 +80,6 @@ EFI_STATUS
IN HARDWARE_INTERRUPT_SOURCE Source IN HARDWARE_INTERRUPT_SOURCE Source
); );
/** /**
Return current state of interrupt source Source. Return current state of interrupt source Source.
@ -139,7 +136,6 @@ EFI_STATUS
OUT EFI_HARDWARE_INTERRUPT2_TRIGGER_TYPE *TriggerType OUT EFI_HARDWARE_INTERRUPT2_TRIGGER_TYPE *TriggerType
); );
/** /**
Configure the trigger type for an interrupt source Configure the trigger type for an interrupt source

View File

@ -152,7 +152,6 @@ typedef BOOLEAN (EFIAPI *MMC_ISMULTIBLOCK) (
); );
struct _EFI_MMC_HOST_PROTOCOL { struct _EFI_MMC_HOST_PROTOCOL {
UINT32 Revision; UINT32 Revision;
MMC_ISCARDPRESENT IsCardPresent; MMC_ISCARDPRESENT IsCardPresent;
MMC_ISREADONLY IsReadOnly; MMC_ISREADONLY IsReadOnly;
@ -168,7 +167,6 @@ struct _EFI_MMC_HOST_PROTOCOL {
MMC_SETIOS SetIos; MMC_SETIOS SetIos;
MMC_ISMULTIBLOCK IsMultiBlock; MMC_ISMULTIBLOCK IsMultiBlock;
}; };
#define MMC_HOST_PROTOCOL_REVISION 0x00010002 // 1.2 #define MMC_HOST_PROTOCOL_REVISION 0x00010002 // 1.2
@ -181,4 +179,3 @@ struct _EFI_MMC_HOST_PROTOCOL {
extern EFI_GUID gEmbeddedMmcHostProtocolGuid; extern EFI_GUID gEmbeddedMmcHostProtocolGuid;
#endif #endif

View File

@ -16,11 +16,8 @@
#define PE_COFF_LOADER_PROTOCOL_GUID \ #define PE_COFF_LOADER_PROTOCOL_GUID \
{ 0xB323179B, 0x97FB, 0x477E, { 0xB0, 0xFE, 0xD8, 0x85, 0x91, 0xFA, 0x11, 0xAB } } { 0xB323179B, 0x97FB, 0x477E, { 0xB0, 0xFE, 0xD8, 0x85, 0x91, 0xFA, 0x11, 0xAB } }
typedef struct _PE_COFF_LOADER_PROTOCOL PE_COFF_LOADER_PROTOCOL; typedef struct _PE_COFF_LOADER_PROTOCOL PE_COFF_LOADER_PROTOCOL;
/** /**
Retrieves information about a PE/COFF image. Retrieves information about a PE/COFF image.
@ -50,7 +47,6 @@ RETURN_STATUS
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
); );
/** /**
Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage(). Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
@ -87,7 +83,6 @@ RETURN_STATUS
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
); );
/** /**
Loads a PE/COFF image into memory. Loads a PE/COFF image into memory.
@ -125,8 +120,6 @@ RETURN_STATUS
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
); );
/** /**
Reads contents of a PE/COFF image from a buffer in system memory. Reads contents of a PE/COFF image from a buffer in system memory.
@ -159,8 +152,6 @@ RETURN_STATUS
OUT VOID *Buffer OUT VOID *Buffer
); );
/** /**
Reapply fixups on a fixed up PE32/PE32+ image to allow virtual calling at EFI Reapply fixups on a fixed up PE32/PE32+ image to allow virtual calling at EFI
runtime. runtime.
@ -193,8 +184,6 @@ VOID
IN VOID *RelocationData IN VOID *RelocationData
); );
/** /**
Unloads a loaded PE/COFF image from memory and releases its taken resource. Unloads a loaded PE/COFF image from memory and releases its taken resource.
Releases any environment specific resources that were allocated when the image Releases any environment specific resources that were allocated when the image
@ -217,7 +206,6 @@ RETURN_STATUS
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
); );
struct _PE_COFF_LOADER_PROTOCOL { struct _PE_COFF_LOADER_PROTOCOL {
PE_COFF_LOADER_GET_IMAGE_INFO GetImageInfo; PE_COFF_LOADER_GET_IMAGE_INFO GetImageInfo;
PE_COFF_LOADER_LOAD_IMAGE LoadImage; PE_COFF_LOADER_LOAD_IMAGE LoadImage;
@ -227,9 +215,6 @@ struct _PE_COFF_LOADER_PROTOCOL {
PE_COFF_LOADER_UNLOAD_IMAGE UnloadImage; PE_COFF_LOADER_UNLOAD_IMAGE UnloadImage;
}; };
extern EFI_GUID gPeCoffLoaderProtocolGuid; extern EFI_GUID gPeCoffLoaderProtocolGuid;
#endif #endif

View File

@ -1,5 +1,6 @@
#ifndef _FDT_H #ifndef _FDT_H
#define _FDT_H #define _FDT_H
/* /*
* libfdt - Flat Device Tree manipulation * libfdt - Flat Device Tree manipulation
* Copyright (C) 2006 David Gibson, IBM Corporation. * Copyright (C) 2006 David Gibson, IBM Corporation.

File diff suppressed because it is too large Load Diff

View File

@ -23,68 +23,142 @@ typedef UINT64 uint64_t;
typedef UINTN uintptr_t; typedef UINTN uintptr_t;
typedef UINTN size_t; typedef UINTN size_t;
static inline uint16_t fdt16_to_cpu(fdt16_t x) static inline uint16_t
fdt16_to_cpu (
fdt16_t x
)
{ {
return SwapBytes16 (x); return SwapBytes16 (x);
} }
#define cpu_to_fdt16(x) fdt16_to_cpu(x) #define cpu_to_fdt16(x) fdt16_to_cpu(x)
static inline uint32_t fdt32_to_cpu(fdt32_t x) static inline uint32_t
fdt32_to_cpu (
fdt32_t x
)
{ {
return SwapBytes32 (x); return SwapBytes32 (x);
} }
#define cpu_to_fdt32(x) fdt32_to_cpu(x) #define cpu_to_fdt32(x) fdt32_to_cpu(x)
static inline uint64_t fdt64_to_cpu(fdt64_t x) static inline uint64_t
fdt64_to_cpu (
fdt64_t x
)
{ {
return SwapBytes64 (x); return SwapBytes64 (x);
} }
#define cpu_to_fdt64(x) fdt64_to_cpu(x) #define cpu_to_fdt64(x) fdt64_to_cpu(x)
static inline void* memcpy(void* dest, const void* src, size_t len) { static inline void *
memcpy (
void *dest,
const void *src,
size_t len
)
{
return CopyMem (dest, src, len); return CopyMem (dest, src, len);
} }
static inline void *memmove(void *dest, const void *src, size_t n) { static inline void *
memmove (
void *dest,
const void *src,
size_t n
)
{
return CopyMem (dest, src, n); return CopyMem (dest, src, n);
} }
static inline void *memset(void *s, int c, size_t n) { static inline void *
memset (
void *s,
int c,
size_t n
)
{
return SetMem (s, n, c); return SetMem (s, n, c);
} }
static inline int memcmp(const void* dest, const void* src, int len) { static inline int
memcmp (
const void *dest,
const void *src,
int len
)
{
return CompareMem (dest, src, len); return CompareMem (dest, src, len);
} }
static inline void *memchr(const void *s, int c, size_t n) { static inline void *
memchr (
const void *s,
int c,
size_t n
)
{
return ScanMem8 (s, n, c); return ScanMem8 (s, n, c);
} }
static inline size_t strlen (const char* str) { static inline size_t
strlen (
const char *str
)
{
return AsciiStrLen (str); return AsciiStrLen (str);
} }
static inline char *strchr(const char *s, int c) { static inline char *
strchr (
const char *s,
int c
)
{
char pattern[2]; char pattern[2];
pattern[0] = c; pattern[0] = c;
pattern[1] = 0; pattern[1] = 0;
return AsciiStrStr (s, pattern); return AsciiStrStr (s, pattern);
} }
static inline size_t strnlen (const char* str, size_t strsz ) { static inline size_t
strnlen (
const char *str,
size_t strsz
)
{
return AsciiStrnLenS (str, strsz); return AsciiStrnLenS (str, strsz);
} }
static inline size_t strcmp (const char* str1, const char* str2) { static inline size_t
strcmp (
const char *str1,
const char *str2
)
{
return AsciiStrCmp (str1, str2); return AsciiStrCmp (str1, str2);
} }
static inline size_t strncmp (const char* str1, const char* str2, size_t strsz ) { static inline size_t
strncmp (
const char *str1,
const char *str2,
size_t strsz
)
{
return AsciiStrnCmp (str1, str2, strsz); return AsciiStrnCmp (str1, str2, strsz);
} }
static inline size_t strncpy (char* dest, const char* source, size_t dest_max) { static inline size_t
strncpy (
char *dest,
const char *source,
size_t dest_max
)
{
return AsciiStrCpyS (dest, dest_max, source); return AsciiStrCpyS (dest, dest_max, source);
} }

View File

@ -108,11 +108,14 @@ LocateAndInstallAcpiFromFvConditional (
AcpiTableSize = ((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Length; AcpiTableSize = ((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Length;
ASSERT (SectionSize >= AcpiTableSize); ASSERT (SectionSize >= AcpiTableSize);
DEBUG ((DEBUG_ERROR, "- Found '%c%c%c%c' ACPI Table\n", DEBUG ((
DEBUG_ERROR,
"- Found '%c%c%c%c' ACPI Table\n",
(((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature & 0xFF), (((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature & 0xFF),
((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 8) & 0xFF), ((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 8) & 0xFF),
((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 16) & 0xFF), ((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 16) & 0xFF),
((((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature >> 24) & 0xFF))); ((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 24) & 0xFF)
));
// Is the ACPI table valid? // Is the ACPI table valid?
if (CheckAcpiTableFunction) { if (CheckAcpiTableFunction) {

View File

@ -116,10 +116,11 @@ AndroidBootImgLoadFile2 (
{ {
// Verify if the valid parameters // Verify if the valid parameters
if (This == NULL || if ((This == NULL) ||
BufferSize == NULL || (BufferSize == NULL) ||
FilePath == NULL || (FilePath == NULL) ||
!IsDevicePathValid (FilePath, 0)) { !IsDevicePathValid (FilePath, 0))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -132,7 +133,8 @@ AndroidBootImgLoadFile2 (
if (mRamdiskSize == 0) { if (mRamdiskSize == 0) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (Buffer == NULL || *BufferSize < mRamdiskSize) {
if ((Buffer == NULL) || (*BufferSize < mRamdiskSize)) {
*BufferSize = mRamdiskSize; *BufferSize = mRamdiskSize;
return EFI_BUFFER_TOO_SMALL; return EFI_BUFFER_TOO_SMALL;
} }
@ -161,8 +163,12 @@ AndroidBootImgGetImgSize (
Header = (ANDROID_BOOTIMG_HEADER *)BootImg; Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, if (AsciiStrnCmp (
ANDROID_BOOT_MAGIC_LENGTH) != 0) { (CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -188,8 +194,12 @@ AndroidBootImgGetKernelInfo (
Header = (ANDROID_BOOTIMG_HEADER *)BootImg; Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, if (AsciiStrnCmp (
ANDROID_BOOT_MAGIC_LENGTH) != 0) { (CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -215,8 +225,12 @@ AndroidBootImgGetRamdiskInfo (
Header = (ANDROID_BOOTIMG_HEADER *)BootImg; Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, if (AsciiStrnCmp (
ANDROID_BOOT_MAGIC_LENGTH) != 0) { (CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -229,6 +243,7 @@ AndroidBootImgGetRamdiskInfo (
+ Header->PageSize + Header->PageSize
+ ALIGN_VALUE (Header->KernelSize, Header->PageSize)); + ALIGN_VALUE (Header->KernelSize, Header->PageSize));
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -243,8 +258,12 @@ AndroidBootImgGetSecondBootLoaderInfo (
Header = (ANDROID_BOOTIMG_HEADER *)BootImg; Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
if (AsciiStrnCmp ((CONST CHAR8 *)Header->BootMagic, ANDROID_BOOT_MAGIC, if (AsciiStrnCmp (
ANDROID_BOOT_MAGIC_LENGTH) != 0) { (CONST CHAR8 *)Header->BootMagic,
ANDROID_BOOT_MAGIC,
ANDROID_BOOT_MAGIC_LENGTH
) != 0)
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -258,6 +277,7 @@ AndroidBootImgGetSecondBootLoaderInfo (
+ ALIGN_VALUE (Header->KernelSize, Header->PageSize) + ALIGN_VALUE (Header->KernelSize, Header->PageSize)
+ ALIGN_VALUE (Header->RamdiskSize, Header->PageSize)); + ALIGN_VALUE (Header->RamdiskSize, Header->PageSize));
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -270,8 +290,12 @@ AndroidBootImgGetKernelArgs (
ANDROID_BOOTIMG_HEADER *Header; ANDROID_BOOTIMG_HEADER *Header;
Header = (ANDROID_BOOTIMG_HEADER *)BootImg; Header = (ANDROID_BOOTIMG_HEADER *)BootImg;
AsciiStrnCpyS (KernelArgs, ANDROID_BOOTIMG_KERNEL_ARGS_SIZE, Header->KernelArgs, AsciiStrnCpyS (
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE,
Header->KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -309,13 +333,20 @@ AndroidBootImgUpdateArgs (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
AsciiStrToUnicodeStrS (ImageKernelArgs, KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE >> 1); AsciiStrToUnicodeStrS (
ImageKernelArgs,
KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE >> 1
);
// Append platform kernel arguments // Append platform kernel arguments
if (mAndroidBootImg->AppendArgs) { if (mAndroidBootImg->AppendArgs) {
Status = mAndroidBootImg->AppendArgs (KernelArgs, Status = mAndroidBootImg->AppendArgs (
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE); KernelArgs,
ANDROID_BOOTIMG_KERNEL_ARGS_SIZE
);
} }
return Status; return Status;
} }
@ -359,10 +390,12 @@ AndroidBootImgUninstallLoadFile2 (
); );
mRamDiskLoadFileHandle = NULL; mRamDiskLoadFileHandle = NULL;
} }
return Status; return Status;
} }
BOOLEAN AndroidBootImgAcpiSupported ( BOOLEAN
AndroidBootImgAcpiSupported (
VOID VOID
) )
{ {
@ -391,12 +424,17 @@ AndroidBootImgLocateFdt (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
Err = fdt_check_header (*FdtBase); Err = fdt_check_header (*FdtBase);
if (Err != 0) { if (Err != 0) {
DEBUG ((DEBUG_ERROR, "ERROR: Device Tree header not valid (Err:%d)\n", DEBUG ((
Err)); DEBUG_ERROR,
"ERROR: Device Tree header not valid (Err:%d)\n",
Err
));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -415,6 +453,7 @@ AndroidBootImgGetChosenNode (
return 0; return 0;
} }
} }
return ChosenNode; return ChosenNode;
} }
@ -430,19 +469,32 @@ AndroidBootImgSetProperty64 (
struct fdt_property *Property; struct fdt_property *Property;
int Len; int Len;
Property = fdt_get_property_w((VOID *)UpdatedFdtBase, ChosenNode, Property = fdt_get_property_w (
PropertyName, &Len); (VOID *)UpdatedFdtBase,
if (NULL == Property && Len == -FDT_ERR_NOTFOUND) { ChosenNode,
PropertyName,
&Len
);
if ((NULL == Property) && (Len == -FDT_ERR_NOTFOUND)) {
Val = cpu_to_fdt64 (Val); Val = cpu_to_fdt64 (Val);
Err = fdt_appendprop ((VOID *)UpdatedFdtBase, ChosenNode, Err = fdt_appendprop (
PropertyName, &Val, sizeof (UINT64)); (VOID *)UpdatedFdtBase,
ChosenNode,
PropertyName,
&Val,
sizeof (UINT64)
);
if (Err) { if (Err) {
DEBUG ((DEBUG_ERROR, "fdt_appendprop() fail: %a\n", fdt_strerror (Err))); DEBUG ((DEBUG_ERROR, "fdt_appendprop() fail: %a\n", fdt_strerror (Err)));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
} else if (Property != NULL) { } else if (Property != NULL) {
Err = fdt_setprop_u64((VOID *)UpdatedFdtBase, ChosenNode, Err = fdt_setprop_u64 (
PropertyName, Val); (VOID *)UpdatedFdtBase,
ChosenNode,
PropertyName,
Val
);
if (Err) { if (Err) {
DEBUG ((DEBUG_ERROR, "fdt_setprop_u64() fail: %a\n", fdt_strerror (Err))); DEBUG ((DEBUG_ERROR, "fdt_setprop_u64() fail: %a\n", fdt_strerror (Err)));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -451,6 +503,7 @@ AndroidBootImgSetProperty64 (
DEBUG ((DEBUG_ERROR, "Failed to set fdt Property %a\n", PropertyName)); DEBUG ((DEBUG_ERROR, "Failed to set fdt Property %a\n", PropertyName));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -468,11 +521,18 @@ AndroidBootImgUpdateFdt (
NewFdtSize = (UINTN)fdt_totalsize (FdtBase) NewFdtSize = (UINTN)fdt_totalsize (FdtBase)
+ FDT_ADDITIONAL_ENTRIES_SIZE; + FDT_ADDITIONAL_ENTRIES_SIZE;
Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, Status = gBS->AllocatePages (
EFI_SIZE_TO_PAGES (NewFdtSize), &UpdatedFdtBase); AllocateAnyPages,
EfiBootServicesData,
EFI_SIZE_TO_PAGES (NewFdtSize),
&UpdatedFdtBase
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Warning: Failed to reallocate FDT, err %d.\n", DEBUG ((
Status)); DEBUG_WARN,
"Warning: Failed to reallocate FDT, err %d.\n",
Status
));
return Status; return Status;
} }
@ -495,16 +555,22 @@ AndroidBootImgUpdateFdt (
goto Fdt_Exit; goto Fdt_Exit;
} }
Status = AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, Status = AndroidBootImgSetProperty64 (
UpdatedFdtBase,
ChosenNode,
"linux,initrd-start", "linux,initrd-start",
(UINTN)RamdiskData); (UINTN)RamdiskData
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Fdt_Exit; goto Fdt_Exit;
} }
Status = AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, Status = AndroidBootImgSetProperty64 (
UpdatedFdtBase,
ChosenNode,
"linux,initrd-end", "linux,initrd-end",
(UINTN)RamdiskData + RamdiskSize); (UINTN)RamdiskData + RamdiskSize
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Fdt_Exit; goto Fdt_Exit;
} }
@ -518,6 +584,7 @@ AndroidBootImgUpdateFdt (
} else { } else {
NewFdtBase = UpdatedFdtBase; NewFdtBase = UpdatedFdtBase;
} }
Status = gBS->InstallConfigurationTable ( Status = gBS->InstallConfigurationTable (
&gFdtTableGuid, &gFdtTableGuid,
(VOID *)(UINTN)NewFdtBase (VOID *)(UINTN)NewFdtBase
@ -552,8 +619,11 @@ AndroidBootImgBoot (
NewKernelArg = NULL; NewKernelArg = NULL;
ImageHandle = NULL; ImageHandle = NULL;
Status = gBS->LocateProtocol (&gAndroidBootImgProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **) &mAndroidBootImg); &gAndroidBootImgProtocolGuid,
NULL,
(VOID **)&mAndroidBootImg
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Exit; goto Exit;
} }
@ -611,19 +681,28 @@ AndroidBootImgBoot (
KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Kernel KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Kernel
+ KernelSize; + KernelSize;
Status = gBS->LoadImage (TRUE, gImageHandle, Status = gBS->LoadImage (
TRUE,
gImageHandle,
(EFI_DEVICE_PATH *)&KernelDevicePath, (EFI_DEVICE_PATH *)&KernelDevicePath,
(VOID*)(UINTN)Kernel, KernelSize, &ImageHandle); (VOID *)(UINTN)Kernel,
KernelSize,
&ImageHandle
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Exit; goto Exit;
} }
// Set kernel arguments // Set kernel arguments
Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, Status = gBS->HandleProtocol (
(VOID **) &ImageInfo); ImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **)&ImageInfo
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Exit; goto Exit;
} }
ImageInfo->LoadOptions = NewKernelArg; ImageInfo->LoadOptions = NewKernelArg;
ImageInfo->LoadOptionsSize = StrLen (NewKernelArg) * sizeof (CHAR16); ImageInfo->LoadOptionsSize = StrLen (NewKernelArg) * sizeof (CHAR16);
@ -640,12 +719,14 @@ Exit:
gBS->UnloadImage (ImageHandle); gBS->UnloadImage (ImageHandle);
ImageHandle = NULL; ImageHandle = NULL;
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (NewKernelArg != NULL) { if (NewKernelArg != NULL) {
FreePool (NewKernelArg); FreePool (NewKernelArg);
NewKernelArg = NULL; NewKernelArg = NULL;
} }
} }
AndroidBootImgUninstallLoadFile2 (); AndroidBootImgUninstallLoadFile2 ();
return Status; return Status;
} }

View File

@ -12,7 +12,6 @@
#include <Library/DmaLib.h> #include <Library/DmaLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
STATIC STATIC
PHYSICAL_ADDRESS PHYSICAL_ADDRESS
HostToDeviceAddress ( HostToDeviceAddress (
@ -52,18 +51,19 @@ DmaMap (
OUT VOID **Mapping OUT VOID **Mapping
) )
{ {
if (HostAddress == NULL || if ((HostAddress == NULL) ||
NumberOfBytes == NULL || (NumberOfBytes == NULL) ||
DeviceAddress == NULL || (DeviceAddress == NULL) ||
Mapping == NULL ) { (Mapping == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
*DeviceAddress = HostToDeviceAddress (HostAddress); *DeviceAddress = HostToDeviceAddress (HostAddress);
*Mapping = NULL; *Mapping = NULL;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer() Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or DmaMapBusMasterCommonBuffer()
operation and releases any corresponding resources. operation and releases any corresponding resources.
@ -111,7 +111,6 @@ DmaAllocateBuffer (
return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress); return DmaAllocateAlignedBuffer (MemoryType, Pages, 0, HostAddress);
} }
/** /**
Allocates pages that are suitable for an DmaMap() of type Allocates pages that are suitable for an DmaMap() of type
MapOperationBusMasterCommonBuffer mapping, at the requested alignment. MapOperationBusMasterCommonBuffer mapping, at the requested alignment.
@ -144,8 +143,9 @@ DmaAllocateAlignedBuffer (
Alignment = EFI_PAGE_SIZE; Alignment = EFI_PAGE_SIZE;
} }
if (HostAddress == NULL || if ((HostAddress == NULL) ||
(Alignment & (Alignment - 1)) != 0) { ((Alignment & (Alignment - 1)) != 0))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -163,10 +163,10 @@ DmaAllocateAlignedBuffer (
if (*HostAddress == NULL) { if (*HostAddress == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Frees memory that was allocated with DmaAllocateBuffer(). Frees memory that was allocated with DmaAllocateBuffer().
@ -192,4 +192,3 @@ DmaFreeBuffer (
FreePages (HostAddress, Pages); FreePages (HostAddress, Pages);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -11,7 +11,6 @@
**/ **/
/** /**
Setup all the hardware needed for the debug agents timer. Setup all the hardware needed for the debug agents timer.
@ -26,7 +25,6 @@ DebugAgentTimerIntialize (
{ {
} }
/** /**
Set the period for the debug agent timer. Zero means disable the timer. Set the period for the debug agent timer. Zero means disable the timer.
@ -41,7 +39,6 @@ DebugAgentTimerSetPeriod (
{ {
} }
/** /**
Perform End Of Interrupt for the debug agent timer. This is called in the Perform End Of Interrupt for the debug agent timer. This is called in the
interrupt handler after the interrupt has been processed. interrupt handler after the interrupt has been processed.
@ -54,4 +51,3 @@ DebugAgentTimerEndOfInterrupt (
) )
{ {
} }

View File

@ -36,8 +36,13 @@ DtPlatformLoadDtb (
VOID *CopyDtb; VOID *CopyDtb;
UINTN OrigDtbSize; UINTN OrigDtbSize;
Status = GetSectionFromAnyFv (&gDtPlatformDefaultDtbFileGuid, Status = GetSectionFromAnyFv (
EFI_SECTION_RAW, 0, &OrigDtb, &OrigDtbSize); &gDtPlatformDefaultDtbFileGuid,
EFI_SECTION_RAW,
0,
&OrigDtb,
&OrigDtbSize
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }

View File

@ -55,18 +55,25 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
int fdt_check_header(const void *fdt) int
fdt_check_header (
const void *fdt
)
{ {
if (fdt_magic (fdt) == FDT_MAGIC) { if (fdt_magic (fdt) == FDT_MAGIC) {
/* Complete tree */ /* Complete tree */
if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) if (fdt_version (fdt) < FDT_FIRST_SUPPORTED_VERSION) {
return -FDT_ERR_BADVERSION; return -FDT_ERR_BADVERSION;
if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION) }
if (fdt_last_comp_version (fdt) > FDT_LAST_SUPPORTED_VERSION) {
return -FDT_ERR_BADVERSION; return -FDT_ERR_BADVERSION;
}
} else if (fdt_magic (fdt) == FDT_SW_MAGIC) { } else if (fdt_magic (fdt) == FDT_SW_MAGIC) {
/* Unfinished sequential-write blob */ /* Unfinished sequential-write blob */
if (fdt_size_dt_struct(fdt) == 0) if (fdt_size_dt_struct (fdt) == 0) {
return -FDT_ERR_BADSTATE; return -FDT_ERR_BADSTATE;
}
} else { } else {
return -FDT_ERR_BADMAGIC; return -FDT_ERR_BADMAGIC;
} }
@ -74,24 +81,39 @@ int fdt_check_header(const void *fdt)
return 0; return 0;
} }
const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) const void *
fdt_offset_ptr (
const void *fdt,
int offset,
unsigned int len
)
{ {
unsigned absoffset = offset + fdt_off_dt_struct (fdt); unsigned absoffset = offset + fdt_off_dt_struct (fdt);
if ( (absoffset < offset) if ( (absoffset < offset)
|| ((absoffset + len) < absoffset) || ((absoffset + len) < absoffset)
|| (absoffset + len) > fdt_totalsize(fdt)) || ((absoffset + len) > fdt_totalsize (fdt)))
{
return NULL; return NULL;
}
if (fdt_version(fdt) >= 0x11) if (fdt_version (fdt) >= 0x11) {
if ( ((offset + len) < offset) if ( ((offset + len) < offset)
|| ((offset + len) > fdt_size_dt_struct (fdt))) || ((offset + len) > fdt_size_dt_struct (fdt)))
{
return NULL; return NULL;
}
}
return _fdt_offset_ptr (fdt, offset); return _fdt_offset_ptr (fdt, offset);
} }
uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) uint32_t
fdt_next_tag (
const void *fdt,
int startoffset,
int *nextoffset
)
{ {
const fdt32_t *tagp, *lenp; const fdt32_t *tagp, *lenp;
uint32_t tag; uint32_t tag;
@ -100,8 +122,10 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
*nextoffset = -FDT_ERR_TRUNCATED; *nextoffset = -FDT_ERR_TRUNCATED;
tagp = fdt_offset_ptr (fdt, offset, FDT_TAGSIZE); tagp = fdt_offset_ptr (fdt, offset, FDT_TAGSIZE);
if (!tagp) if (!tagp) {
return FDT_END; /* premature end */ return FDT_END; /* premature end */
}
tag = fdt32_to_cpu (*tagp); tag = fdt32_to_cpu (*tagp);
offset += FDT_TAGSIZE; offset += FDT_TAGSIZE;
@ -112,14 +136,19 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
do { do {
p = fdt_offset_ptr (fdt, offset++, 1); p = fdt_offset_ptr (fdt, offset++, 1);
} while (p && (*p != '\0')); } while (p && (*p != '\0'));
if (!p)
if (!p) {
return FDT_END; /* premature end */ return FDT_END; /* premature end */
}
break; break;
case FDT_PROP: case FDT_PROP:
lenp = fdt_offset_ptr (fdt, offset, sizeof (*lenp)); lenp = fdt_offset_ptr (fdt, offset, sizeof (*lenp));
if (!lenp) if (!lenp) {
return FDT_END; /* premature end */ return FDT_END; /* premature end */
}
/* skip-name offset, length and value */ /* skip-name offset, length and value */
offset += sizeof (struct fdt_property) - FDT_TAGSIZE offset += sizeof (struct fdt_property) - FDT_TAGSIZE
+ fdt32_to_cpu (*lenp); + fdt32_to_cpu (*lenp);
@ -134,39 +163,59 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
return FDT_END; return FDT_END;
} }
if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset)) if (!fdt_offset_ptr (fdt, startoffset, offset - startoffset)) {
return FDT_END; /* premature end */ return FDT_END; /* premature end */
}
*nextoffset = FDT_TAGALIGN (offset); *nextoffset = FDT_TAGALIGN (offset);
return tag; return tag;
} }
int _fdt_check_node_offset(const void *fdt, int offset) int
_fdt_check_node_offset (
const void *fdt,
int offset
)
{ {
if ( (offset < 0) || (offset % FDT_TAGSIZE) if ( (offset < 0) || (offset % FDT_TAGSIZE)
|| (fdt_next_tag (fdt, offset, &offset) != FDT_BEGIN_NODE)) || (fdt_next_tag (fdt, offset, &offset) != FDT_BEGIN_NODE))
{
return -FDT_ERR_BADOFFSET; return -FDT_ERR_BADOFFSET;
}
return offset; return offset;
} }
int _fdt_check_prop_offset(const void *fdt, int offset) int
_fdt_check_prop_offset (
const void *fdt,
int offset
)
{ {
if ( (offset < 0) || (offset % FDT_TAGSIZE) if ( (offset < 0) || (offset % FDT_TAGSIZE)
|| (fdt_next_tag (fdt, offset, &offset) != FDT_PROP)) || (fdt_next_tag (fdt, offset, &offset) != FDT_PROP))
{
return -FDT_ERR_BADOFFSET; return -FDT_ERR_BADOFFSET;
}
return offset; return offset;
} }
int fdt_next_node(const void *fdt, int offset, int *depth) int
fdt_next_node (
const void *fdt,
int offset,
int *depth
)
{ {
int nextoffset = 0; int nextoffset = 0;
uint32_t tag; uint32_t tag;
if (offset >= 0) if (offset >= 0) {
if ((nextoffset = _fdt_check_node_offset(fdt, offset)) < 0) if ((nextoffset = _fdt_check_node_offset (fdt, offset)) < 0) {
return nextoffset; return nextoffset;
}
}
do { do {
offset = nextoffset; offset = nextoffset;
@ -178,39 +227,54 @@ int fdt_next_node(const void *fdt, int offset, int *depth)
break; break;
case FDT_BEGIN_NODE: case FDT_BEGIN_NODE:
if (depth) if (depth) {
(*depth)++; (*depth)++;
}
break; break;
case FDT_END_NODE: case FDT_END_NODE:
if (depth && ((--(*depth)) < 0)) if (depth && ((--(*depth)) < 0)) {
return nextoffset; return nextoffset;
}
break; break;
case FDT_END: case FDT_END:
if ( (nextoffset >= 0) if ( (nextoffset >= 0)
|| ((nextoffset == -FDT_ERR_TRUNCATED) && !depth)) || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth))
{
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
else } else {
return nextoffset; return nextoffset;
} }
}
} while (tag != FDT_BEGIN_NODE); } while (tag != FDT_BEGIN_NODE);
return offset; return offset;
} }
int fdt_first_subnode(const void *fdt, int offset) int
fdt_first_subnode (
const void *fdt,
int offset
)
{ {
int depth = 0; int depth = 0;
offset = fdt_next_node (fdt, offset, &depth); offset = fdt_next_node (fdt, offset, &depth);
if (offset < 0 || depth != 1) if ((offset < 0) || (depth != 1)) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
}
return offset; return offset;
} }
int fdt_next_subnode(const void *fdt, int offset) int
fdt_next_subnode (
const void *fdt,
int offset
)
{ {
int depth = 1; int depth = 1;
@ -220,31 +284,46 @@ int fdt_next_subnode(const void *fdt, int offset)
*/ */
do { do {
offset = fdt_next_node (fdt, offset, &depth); offset = fdt_next_node (fdt, offset, &depth);
if (offset < 0 || depth < 1) if ((offset < 0) || (depth < 1)) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
}
} while (depth > 1); } while (depth > 1);
return offset; return offset;
} }
const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) const char *
_fdt_find_string (
const char *strtab,
int tabsize,
const char *s
)
{ {
int len = strlen (s) + 1; int len = strlen (s) + 1;
const char *last = strtab + tabsize - len; const char *last = strtab + tabsize - len;
const char *p; const char *p;
for (p = strtab; p <= last; p++) for (p = strtab; p <= last; p++) {
if (memcmp(p, s, len) == 0) if (memcmp (p, s, len) == 0) {
return p; return p;
}
}
return NULL; return NULL;
} }
int fdt_move(const void *fdt, void *buf, int bufsize) int
fdt_move (
const void *fdt,
void *buf,
int bufsize
)
{ {
FDT_CHECK_HEADER (fdt); FDT_CHECK_HEADER (fdt);
if (fdt_totalsize(fdt) > bufsize) if (fdt_totalsize (fdt) > bufsize) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
memmove (buf, fdt, fdt_totalsize (fdt)); memmove (buf, fdt, fdt_totalsize (fdt));
return 0; return 0;

View File

@ -55,42 +55,56 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
int fdt_address_cells(const void *fdt, int nodeoffset) int
fdt_address_cells (
const void *fdt,
int nodeoffset
)
{ {
const fdt32_t *ac; const fdt32_t *ac;
int val; int val;
int len; int len;
ac = fdt_getprop (fdt, nodeoffset, "#address-cells", &len); ac = fdt_getprop (fdt, nodeoffset, "#address-cells", &len);
if (!ac) if (!ac) {
return 2; return 2;
}
if (len != sizeof(*ac)) if (len != sizeof (*ac)) {
return -FDT_ERR_BADNCELLS; return -FDT_ERR_BADNCELLS;
}
val = fdt32_to_cpu (*ac); val = fdt32_to_cpu (*ac);
if ((val <= 0) || (val > FDT_MAX_NCELLS)) if ((val <= 0) || (val > FDT_MAX_NCELLS)) {
return -FDT_ERR_BADNCELLS; return -FDT_ERR_BADNCELLS;
}
return val; return val;
} }
int fdt_size_cells(const void *fdt, int nodeoffset) int
fdt_size_cells (
const void *fdt,
int nodeoffset
)
{ {
const fdt32_t *sc; const fdt32_t *sc;
int val; int val;
int len; int len;
sc = fdt_getprop (fdt, nodeoffset, "#size-cells", &len); sc = fdt_getprop (fdt, nodeoffset, "#size-cells", &len);
if (!sc) if (!sc) {
return 2; return 2;
}
if (len != sizeof(*sc)) if (len != sizeof (*sc)) {
return -FDT_ERR_BADNCELLS; return -FDT_ERR_BADNCELLS;
}
val = fdt32_to_cpu (*sc); val = fdt32_to_cpu (*sc);
if ((val < 0) || (val > FDT_MAX_NCELLS)) if ((val < 0) || (val > FDT_MAX_NCELLS)) {
return -FDT_ERR_BADNCELLS; return -FDT_ERR_BADNCELLS;
}
return val; return val;
} }

View File

@ -55,29 +55,38 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
int fdt_create_empty_tree(void *buf, int bufsize) int
fdt_create_empty_tree (
void *buf,
int bufsize
)
{ {
int err; int err;
err = fdt_create (buf, bufsize); err = fdt_create (buf, bufsize);
if (err) if (err) {
return err; return err;
}
err = fdt_finish_reservemap (buf); err = fdt_finish_reservemap (buf);
if (err) if (err) {
return err; return err;
}
err = fdt_begin_node (buf, ""); err = fdt_begin_node (buf, "");
if (err) if (err) {
return err; return err;
}
err = fdt_end_node (buf); err = fdt_end_node (buf);
if (err) if (err) {
return err; return err;
}
err = fdt_finish (buf); err = fdt_finish (buf);
if (err) if (err) {
return err; return err;
}
return fdt_open_into (buf, buf, bufsize); return fdt_open_into (buf, buf, bufsize);
} }

View File

@ -70,17 +70,23 @@
* 0, if the phandle was not found * 0, if the phandle was not found
* -1, if the phandle was malformed * -1, if the phandle was malformed
*/ */
static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) static uint32_t
overlay_get_target_phandle (
const void *fdto,
int fragment
)
{ {
const fdt32_t *val; const fdt32_t *val;
int len; int len;
val = fdt_getprop (fdto, fragment, "target", &len); val = fdt_getprop (fdto, fragment, "target", &len);
if (!val) if (!val) {
return 0; return 0;
}
if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1)) if ((len != sizeof (*val)) || (fdt32_to_cpu (*val) == (uint32_t)-1)) {
return (uint32_t)-1; return (uint32_t)-1;
}
return fdt32_to_cpu (*val); return fdt32_to_cpu (*val);
} }
@ -100,8 +106,13 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment)
* the targetted node offset in the base device tree * the targetted node offset in the base device tree
* Negative error code on error * Negative error code on error
*/ */
static int overlay_get_target(const void *fdt, const void *fdto, static int
int fragment, char const **pathp) overlay_get_target (
const void *fdt,
const void *fdto,
int fragment,
char const **pathp
)
{ {
uint32_t phandle; uint32_t phandle;
const char *path = NULL; const char *path = NULL;
@ -109,19 +120,22 @@ static int overlay_get_target(const void *fdt, const void *fdto,
/* Try first to do a phandle based lookup */ /* Try first to do a phandle based lookup */
phandle = overlay_get_target_phandle (fdto, fragment); phandle = overlay_get_target_phandle (fdto, fragment);
if (phandle == (uint32_t)-1) if (phandle == (uint32_t)-1) {
return -FDT_ERR_BADPHANDLE; return -FDT_ERR_BADPHANDLE;
}
/* no phandle, try path */ /* no phandle, try path */
if (!phandle) { if (!phandle) {
/* And then a path based lookup */ /* And then a path based lookup */
path = fdt_getprop (fdto, fragment, "target-path", &path_len); path = fdt_getprop (fdto, fragment, "target-path", &path_len);
if (path) if (path) {
ret = fdt_path_offset (fdt, path); ret = fdt_path_offset (fdt, path);
else } else {
ret = path_len; ret = path_len;
} else }
} else {
ret = fdt_node_offset_by_phandle (fdt, phandle); ret = fdt_node_offset_by_phandle (fdt, phandle);
}
/* /*
* If we haven't found either a target or a * If we haven't found either a target or a
@ -130,16 +144,19 @@ static int overlay_get_target(const void *fdt, const void *fdto,
* otherwise), consider it a improperly written * otherwise), consider it a improperly written
* overlay * overlay
*/ */
if (ret < 0 && path_len == -FDT_ERR_NOTFOUND) if ((ret < 0) && (path_len == -FDT_ERR_NOTFOUND)) {
ret = -FDT_ERR_BADOVERLAY; ret = -FDT_ERR_BADOVERLAY;
}
/* return on error */ /* return on error */
if (ret < 0) if (ret < 0) {
return ret; return ret;
}
/* return pointer to path (if available) */ /* return pointer to path (if available) */
if (pathp) if (pathp) {
*pathp = path ? path : NULL; *pathp = path ? path : NULL;
}
return ret; return ret;
} }
@ -158,27 +175,36 @@ static int overlay_get_target(const void *fdt, const void *fdto,
* 0 on success. * 0 on success.
* Negative error code on error * Negative error code on error
*/ */
static int overlay_phandle_add_offset(void *fdt, int node, static int
const char *name, uint32_t delta) overlay_phandle_add_offset (
void *fdt,
int node,
const char *name,
uint32_t delta
)
{ {
const fdt32_t *val; const fdt32_t *val;
uint32_t adj_val; uint32_t adj_val;
int len; int len;
val = fdt_getprop (fdt, node, name, &len); val = fdt_getprop (fdt, node, name, &len);
if (!val) if (!val) {
return len; return len;
}
if (len != sizeof(*val)) if (len != sizeof (*val)) {
return -FDT_ERR_BADPHANDLE; return -FDT_ERR_BADPHANDLE;
}
adj_val = fdt32_to_cpu (*val); adj_val = fdt32_to_cpu (*val);
if ((adj_val + delta) < adj_val) if ((adj_val + delta) < adj_val) {
return -FDT_ERR_NOPHANDLES; return -FDT_ERR_NOPHANDLES;
}
adj_val += delta; adj_val += delta;
if (adj_val == (uint32_t)-1) if (adj_val == (uint32_t)-1) {
return -FDT_ERR_NOPHANDLES; return -FDT_ERR_NOPHANDLES;
}
return fdt_setprop_inplace_u32 (fdt, node, name, adj_val); return fdt_setprop_inplace_u32 (fdt, node, name, adj_val);
} }
@ -198,25 +224,32 @@ static int overlay_phandle_add_offset(void *fdt, int node,
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_adjust_node_phandles(void *fdto, int node, static int
uint32_t delta) overlay_adjust_node_phandles (
void *fdto,
int node,
uint32_t delta
)
{ {
int child; int child;
int ret; int ret;
ret = overlay_phandle_add_offset (fdto, node, "phandle", delta); ret = overlay_phandle_add_offset (fdto, node, "phandle", delta);
if (ret && ret != -FDT_ERR_NOTFOUND) if (ret && (ret != -FDT_ERR_NOTFOUND)) {
return ret; return ret;
}
ret = overlay_phandle_add_offset (fdto, node, "linux,phandle", delta); ret = overlay_phandle_add_offset (fdto, node, "linux,phandle", delta);
if (ret && ret != -FDT_ERR_NOTFOUND) if (ret && (ret != -FDT_ERR_NOTFOUND)) {
return ret; return ret;
}
fdt_for_each_subnode (child, fdto, node) { fdt_for_each_subnode (child, fdto, node) {
ret = overlay_adjust_node_phandles (fdto, child, delta); ret = overlay_adjust_node_phandles (fdto, child, delta);
if (ret) if (ret) {
return ret; return ret;
} }
}
return 0; return 0;
} }
@ -235,7 +268,11 @@ static int overlay_adjust_node_phandles(void *fdto, int node,
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_adjust_local_phandles(void *fdto, uint32_t delta) static int
overlay_adjust_local_phandles (
void *fdto,
uint32_t delta
)
{ {
/* /*
* Start adjusting the phandles from the overlay root * Start adjusting the phandles from the overlay root
@ -262,10 +299,13 @@ static int overlay_adjust_local_phandles(void *fdto, uint32_t delta)
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_update_local_node_references(void *fdto, static int
overlay_update_local_node_references (
void *fdto,
int tree_node, int tree_node,
int fixup_node, int fixup_node,
uint32_t delta) uint32_t delta
)
{ {
int fixup_prop; int fixup_prop;
int fixup_child; int fixup_child;
@ -279,18 +319,25 @@ static int overlay_update_local_node_references(void *fdto,
int tree_len; int tree_len;
int i; int i;
fixup_val = fdt_getprop_by_offset(fdto, fixup_prop, fixup_val = fdt_getprop_by_offset (
&name, &fixup_len); fdto,
if (!fixup_val) fixup_prop,
&name,
&fixup_len
);
if (!fixup_val) {
return fixup_len; return fixup_len;
}
if (fixup_len % sizeof(uint32_t)) if (fixup_len % sizeof (uint32_t)) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
tree_val = fdt_getprop (fdto, tree_node, name, &tree_len); tree_val = fdt_getprop (fdto, tree_node, name, &tree_len);
if (!tree_val) { if (!tree_val) {
if (tree_len == -FDT_ERR_NOTFOUND) if (tree_len == -FDT_ERR_NOTFOUND) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
return tree_len; return tree_len;
} }
@ -311,40 +358,56 @@ static int overlay_update_local_node_references(void *fdto,
adj_val = cpu_to_fdt32 (fdt32_to_cpu (adj_val) + delta); adj_val = cpu_to_fdt32 (fdt32_to_cpu (adj_val) + delta);
ret = fdt_setprop_inplace_namelen_partial(fdto, ret = fdt_setprop_inplace_namelen_partial (
fdto,
tree_node, tree_node,
name, name,
strlen (name), strlen (name),
poffset, poffset,
&adj_val, &adj_val,
sizeof(adj_val)); sizeof (adj_val)
if (ret == -FDT_ERR_NOSPACE) );
if (ret == -FDT_ERR_NOSPACE) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
if (ret) if (ret) {
return ret; return ret;
} }
} }
}
fdt_for_each_subnode (fixup_child, fdto, fixup_node) { fdt_for_each_subnode (fixup_child, fdto, fixup_node) {
const char *fixup_child_name = fdt_get_name(fdto, fixup_child, const char *fixup_child_name = fdt_get_name (
NULL); fdto,
fixup_child,
NULL
);
int tree_child; int tree_child;
tree_child = fdt_subnode_offset(fdto, tree_node, tree_child = fdt_subnode_offset (
fixup_child_name); fdto,
if (tree_child == -FDT_ERR_NOTFOUND) tree_node,
fixup_child_name
);
if (tree_child == -FDT_ERR_NOTFOUND) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
if (tree_child < 0) }
return tree_child;
ret = overlay_update_local_node_references(fdto, if (tree_child < 0) {
return tree_child;
}
ret = overlay_update_local_node_references (
fdto,
tree_child, tree_child,
fixup_child, fixup_child,
delta); delta
if (ret) );
if (ret) {
return ret; return ret;
} }
}
return 0; return 0;
} }
@ -366,15 +429,20 @@ static int overlay_update_local_node_references(void *fdto,
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_update_local_references(void *fdto, uint32_t delta) static int
overlay_update_local_references (
void *fdto,
uint32_t delta
)
{ {
int fixups; int fixups;
fixups = fdt_path_offset (fdto, "/__local_fixups__"); fixups = fdt_path_offset (fdto, "/__local_fixups__");
if (fixups < 0) { if (fixups < 0) {
/* There's no local phandles to adjust, bail out */ /* There's no local phandles to adjust, bail out */
if (fixups == -FDT_ERR_NOTFOUND) if (fixups == -FDT_ERR_NOTFOUND) {
return 0; return 0;
}
return fixups; return fixups;
} }
@ -382,8 +450,12 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)
/* /*
* Update our local references from the root of the tree * Update our local references from the root of the tree
*/ */
return overlay_update_local_node_references(fdto, 0, fixups, return overlay_update_local_node_references (
delta); fdto,
0,
fixups,
delta
);
} }
/** /**
@ -409,11 +481,18 @@ static int overlay_update_local_references(void *fdto, uint32_t delta)
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_fixup_one_phandle(void *fdt, void *fdto, static int
overlay_fixup_one_phandle (
void *fdt,
void *fdto,
int symbols_off, int symbols_off,
const char *path, uint32_t path_len, const char *path,
const char *name, uint32_t name_len, uint32_t path_len,
int poffset, const char *label) const char *name,
uint32_t name_len,
int poffset,
const char *label
)
{ {
const char *symbol_path; const char *symbol_path;
uint32_t phandle; uint32_t phandle;
@ -421,36 +500,57 @@ static int overlay_fixup_one_phandle(void *fdt, void *fdto,
int symbol_off, fixup_off; int symbol_off, fixup_off;
int prop_len; int prop_len;
if (symbols_off < 0) if (symbols_off < 0) {
return symbols_off; return symbols_off;
}
symbol_path = fdt_getprop(fdt, symbols_off, label, symbol_path = fdt_getprop (
&prop_len); fdt,
if (!symbol_path) symbols_off,
label,
&prop_len
);
if (!symbol_path) {
return prop_len; return prop_len;
}
symbol_off = fdt_path_offset (fdt, symbol_path); symbol_off = fdt_path_offset (fdt, symbol_path);
if (symbol_off < 0) if (symbol_off < 0) {
return symbol_off; return symbol_off;
}
phandle = fdt_get_phandle (fdt, symbol_off); phandle = fdt_get_phandle (fdt, symbol_off);
if (!phandle) if (!phandle) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
}
fixup_off = fdt_path_offset_namelen (fdto, path, path_len); fixup_off = fdt_path_offset_namelen (fdto, path, path_len);
if (fixup_off == -FDT_ERR_NOTFOUND) if (fixup_off == -FDT_ERR_NOTFOUND) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
if (fixup_off < 0) }
if (fixup_off < 0) {
return fixup_off; return fixup_off;
}
phandle_prop = cpu_to_fdt32 (phandle); phandle_prop = cpu_to_fdt32 (phandle);
return fdt_setprop_inplace_namelen_partial(fdto, fixup_off, return fdt_setprop_inplace_namelen_partial (
name, name_len, poffset, fdto,
fixup_off,
name,
name_len,
poffset,
&phandle_prop, &phandle_prop,
sizeof(phandle_prop)); sizeof (phandle_prop)
}; );
}
unsigned long strtoul(const char *nptr, char **endptr, int base); unsigned long
strtoul (
const char *nptr,
char **endptr,
int base
);
/** /**
* overlay_fixup_phandle - Set an overlay phandle to the base one * overlay_fixup_phandle - Set an overlay phandle to the base one
@ -471,18 +571,28 @@ unsigned long strtoul(const char *nptr, char **endptr, int base);
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off, static int
int property) overlay_fixup_phandle (
void *fdt,
void *fdto,
int symbols_off,
int property
)
{ {
const char *value; const char *value;
const char *label; const char *label;
int len; int len;
value = fdt_getprop_by_offset(fdto, property, value = fdt_getprop_by_offset (
&label, &len); fdto,
property,
&label,
&len
);
if (!value) { if (!value) {
if (len == -FDT_ERR_NOTFOUND) if (len == -FDT_ERR_NOTFOUND) {
return -FDT_ERR_INTERNAL; return -FDT_ERR_INTERNAL;
}
return len; return len;
} }
@ -496,8 +606,10 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
int poffset, ret; int poffset, ret;
fixup_end = memchr (value, '\0', len); fixup_end = memchr (value, '\0', len);
if (!fixup_end) if (!fixup_end) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
fixup_len = fixup_end - fixup_str; fixup_len = fixup_end - fixup_str;
len -= fixup_len + 1; len -= fixup_len + 1;
@ -505,32 +617,46 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
path = fixup_str; path = fixup_str;
sep = memchr (fixup_str, ':', fixup_len); sep = memchr (fixup_str, ':', fixup_len);
if (!sep || *sep != ':') if (!sep || (*sep != ':')) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
path_len = sep - path; path_len = sep - path;
if (path_len == (fixup_len - 1)) if (path_len == (fixup_len - 1)) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
fixup_len -= path_len + 1; fixup_len -= path_len + 1;
name = sep + 1; name = sep + 1;
sep = memchr (name, ':', fixup_len); sep = memchr (name, ':', fixup_len);
if (!sep || *sep != ':') if (!sep || (*sep != ':')) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
name_len = sep - name; name_len = sep - name;
if (!name_len) if (!name_len) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
poffset = strtoul (sep + 1, &endptr, 10); poffset = strtoul (sep + 1, &endptr, 10);
if ((*endptr != '\0') || (endptr <= (sep + 1))) if ((*endptr != '\0') || (endptr <= (sep + 1))) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off, ret = overlay_fixup_one_phandle (
path, path_len, name, name_len, fdt,
poffset, label); fdto,
if (ret) symbols_off,
path,
path_len,
name,
name_len,
poffset,
label
);
if (ret) {
return ret; return ret;
}
} while (len > 0); } while (len > 0);
return 0; return 0;
@ -553,30 +679,39 @@ static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off,
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_fixup_phandles(void *fdt, void *fdto) static int
overlay_fixup_phandles (
void *fdt,
void *fdto
)
{ {
int fixups_off, symbols_off; int fixups_off, symbols_off;
int property; int property;
/* We can have overlays without any fixups */ /* We can have overlays without any fixups */
fixups_off = fdt_path_offset (fdto, "/__fixups__"); fixups_off = fdt_path_offset (fdto, "/__fixups__");
if (fixups_off == -FDT_ERR_NOTFOUND) if (fixups_off == -FDT_ERR_NOTFOUND) {
return 0; /* nothing to do */ return 0; /* nothing to do */
if (fixups_off < 0) }
if (fixups_off < 0) {
return fixups_off; return fixups_off;
}
/* And base DTs without symbols */ /* And base DTs without symbols */
symbols_off = fdt_path_offset (fdt, "/__symbols__"); symbols_off = fdt_path_offset (fdt, "/__symbols__");
if ((symbols_off < 0 && (symbols_off != -FDT_ERR_NOTFOUND))) if (((symbols_off < 0) && (symbols_off != -FDT_ERR_NOTFOUND))) {
return symbols_off; return symbols_off;
}
fdt_for_each_property_offset (property, fdto, fixups_off) { fdt_for_each_property_offset (property, fdto, fixups_off) {
int ret; int ret;
ret = overlay_fixup_phandle (fdt, fdto, symbols_off, property); ret = overlay_fixup_phandle (fdt, fdto, symbols_off, property);
if (ret) if (ret) {
return ret; return ret;
} }
}
return 0; return 0;
} }
@ -600,8 +735,13 @@ static int overlay_fixup_phandles(void *fdt, void *fdto)
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_apply_node(void *fdt, int target, static int
void *fdto, int node) overlay_apply_node (
void *fdt,
int target,
void *fdto,
int node
)
{ {
int property; int property;
int subnode; int subnode;
@ -612,17 +752,25 @@ static int overlay_apply_node(void *fdt, int target,
int prop_len; int prop_len;
int ret; int ret;
prop = fdt_getprop_by_offset(fdto, property, &name, prop = fdt_getprop_by_offset (
&prop_len); fdto,
if (prop_len == -FDT_ERR_NOTFOUND) property,
&name,
&prop_len
);
if (prop_len == -FDT_ERR_NOTFOUND) {
return -FDT_ERR_INTERNAL; return -FDT_ERR_INTERNAL;
if (prop_len < 0) }
if (prop_len < 0) {
return prop_len; return prop_len;
}
ret = fdt_setprop (fdt, target, name, prop, prop_len); ret = fdt_setprop (fdt, target, name, prop, prop_len);
if (ret) if (ret) {
return ret; return ret;
} }
}
fdt_for_each_subnode (subnode, fdto, node) { fdt_for_each_subnode (subnode, fdto, node) {
const char *name = fdt_get_name (fdto, subnode, NULL); const char *name = fdt_get_name (fdto, subnode, NULL);
@ -632,17 +780,20 @@ static int overlay_apply_node(void *fdt, int target,
nnode = fdt_add_subnode (fdt, target, name); nnode = fdt_add_subnode (fdt, target, name);
if (nnode == -FDT_ERR_EXISTS) { if (nnode == -FDT_ERR_EXISTS) {
nnode = fdt_subnode_offset (fdt, target, name); nnode = fdt_subnode_offset (fdt, target, name);
if (nnode == -FDT_ERR_NOTFOUND) if (nnode == -FDT_ERR_NOTFOUND) {
return -FDT_ERR_INTERNAL; return -FDT_ERR_INTERNAL;
} }
}
if (nnode < 0) if (nnode < 0) {
return nnode; return nnode;
}
ret = overlay_apply_node (fdt, nnode, fdto, subnode); ret = overlay_apply_node (fdt, nnode, fdto, subnode);
if (ret) if (ret) {
return ret; return ret;
} }
}
return 0; return 0;
} }
@ -662,7 +813,11 @@ static int overlay_apply_node(void *fdt, int target,
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_merge(void *fdt, void *fdto) static int
overlay_merge (
void *fdt,
void *fdto
)
{ {
int fragment; int fragment;
@ -676,25 +831,33 @@ static int overlay_merge(void *fdt, void *fdto)
* they don't, it's not supposed to be merged * they don't, it's not supposed to be merged
*/ */
overlay = fdt_subnode_offset (fdto, fragment, "__overlay__"); overlay = fdt_subnode_offset (fdto, fragment, "__overlay__");
if (overlay == -FDT_ERR_NOTFOUND) if (overlay == -FDT_ERR_NOTFOUND) {
continue; continue;
}
if (overlay < 0) if (overlay < 0) {
return overlay; return overlay;
}
target = overlay_get_target (fdt, fdto, fragment, NULL); target = overlay_get_target (fdt, fdto, fragment, NULL);
if (target < 0) if (target < 0) {
return target; return target;
}
ret = overlay_apply_node (fdt, target, fdto, overlay); ret = overlay_apply_node (fdt, target, fdto, overlay);
if (ret) if (ret) {
return ret; return ret;
} }
}
return 0; return 0;
} }
static int get_path_len(const void *fdt, int nodeoffset) static int
get_path_len (
const void *fdt,
int nodeoffset
)
{ {
int len = 0, namelen; int len = 0, namelen;
const char *name; const char *name;
@ -703,22 +866,28 @@ static int get_path_len(const void *fdt, int nodeoffset)
for ( ; ;) { for ( ; ;) {
name = fdt_get_name (fdt, nodeoffset, &namelen); name = fdt_get_name (fdt, nodeoffset, &namelen);
if (!name) if (!name) {
return namelen; return namelen;
}
/* root? we're done */ /* root? we're done */
if (namelen == 0) if (namelen == 0) {
break; break;
}
nodeoffset = fdt_parent_offset (fdt, nodeoffset); nodeoffset = fdt_parent_offset (fdt, nodeoffset);
if (nodeoffset < 0) if (nodeoffset < 0) {
return nodeoffset; return nodeoffset;
}
len += namelen + 1; len += namelen + 1;
} }
/* in case of root pretend it's "/" */ /* in case of root pretend it's "/" */
if (len == 0) if (len == 0) {
len++; len++;
}
return len; return len;
} }
@ -738,7 +907,11 @@ static int get_path_len(const void *fdt, int nodeoffset)
* 0 on success * 0 on success
* Negative error code on failure * Negative error code on failure
*/ */
static int overlay_symbol_update(void *fdt, void *fdto) static int
overlay_symbol_update (
void *fdt,
void *fdto
)
{ {
int root_sym, ov_sym, prop, path_len, fragment, target; int root_sym, ov_sym, prop, path_len, fragment, target;
int len, frag_name_len, ret, rel_path_len; int len, frag_name_len, ret, rel_path_len;
@ -754,106 +927,136 @@ static int overlay_symbol_update(void *fdt, void *fdto)
ov_sym = fdt_subnode_offset (fdto, 0, "__symbols__"); ov_sym = fdt_subnode_offset (fdto, 0, "__symbols__");
/* if no overlay symbols exist no problem */ /* if no overlay symbols exist no problem */
if (ov_sym < 0) if (ov_sym < 0) {
return 0; return 0;
}
root_sym = fdt_subnode_offset (fdt, 0, "__symbols__"); root_sym = fdt_subnode_offset (fdt, 0, "__symbols__");
/* it no root symbols exist we should create them */ /* it no root symbols exist we should create them */
if (root_sym == -FDT_ERR_NOTFOUND) if (root_sym == -FDT_ERR_NOTFOUND) {
root_sym = fdt_add_subnode (fdt, 0, "__symbols__"); root_sym = fdt_add_subnode (fdt, 0, "__symbols__");
}
/* any error is fatal now */ /* any error is fatal now */
if (root_sym < 0) if (root_sym < 0) {
return root_sym; return root_sym;
}
/* iterate over each overlay symbol */ /* iterate over each overlay symbol */
fdt_for_each_property_offset (prop, fdto, ov_sym) { fdt_for_each_property_offset (prop, fdto, ov_sym) {
path = fdt_getprop_by_offset (fdto, prop, &name, &path_len); path = fdt_getprop_by_offset (fdto, prop, &name, &path_len);
if (!path) if (!path) {
return path_len; return path_len;
}
/* verify it's a string property (terminated by a single \0) */ /* verify it's a string property (terminated by a single \0) */
if (path_len < 1 || memchr(path, '\0', path_len) != &path[path_len - 1]) if ((path_len < 1) || (memchr (path, '\0', path_len) != &path[path_len - 1])) {
return -FDT_ERR_BADVALUE; return -FDT_ERR_BADVALUE;
}
/* keep end marker to avoid strlen() */ /* keep end marker to avoid strlen() */
e = path + path_len; e = path + path_len;
/* format: /<fragment-name>/__overlay__/<relative-subnode-path> */ /* format: /<fragment-name>/__overlay__/<relative-subnode-path> */
if (*path != '/') if (*path != '/') {
return -FDT_ERR_BADVALUE; return -FDT_ERR_BADVALUE;
}
/* get fragment name first */ /* get fragment name first */
s = strchr (path + 1, '/'); s = strchr (path + 1, '/');
if (!s) if (!s) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
frag_name = path + 1; frag_name = path + 1;
frag_name_len = s - path - 1; frag_name_len = s - path - 1;
/* verify format; safe since "s" lies in \0 terminated prop */ /* verify format; safe since "s" lies in \0 terminated prop */
len = sizeof ("/__overlay__/") - 1; len = sizeof ("/__overlay__/") - 1;
if ((e - s) < len || memcmp(s, "/__overlay__/", len)) if (((e - s) < len) || memcmp (s, "/__overlay__/", len)) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
rel_path = s + len; rel_path = s + len;
rel_path_len = e - rel_path; rel_path_len = e - rel_path;
/* find the fragment index in which the symbol lies */ /* find the fragment index in which the symbol lies */
ret = fdt_subnode_offset_namelen(fdto, 0, frag_name, ret = fdt_subnode_offset_namelen (
frag_name_len); fdto,
0,
frag_name,
frag_name_len
);
/* not found? */ /* not found? */
if (ret < 0) if (ret < 0) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
fragment = ret; fragment = ret;
/* an __overlay__ subnode must exist */ /* an __overlay__ subnode must exist */
ret = fdt_subnode_offset (fdto, fragment, "__overlay__"); ret = fdt_subnode_offset (fdto, fragment, "__overlay__");
if (ret < 0) if (ret < 0) {
return -FDT_ERR_BADOVERLAY; return -FDT_ERR_BADOVERLAY;
}
/* get the target of the fragment */ /* get the target of the fragment */
ret = overlay_get_target (fdt, fdto, fragment, &target_path); ret = overlay_get_target (fdt, fdto, fragment, &target_path);
if (ret < 0) if (ret < 0) {
return ret; return ret;
}
target = ret; target = ret;
/* if we have a target path use */ /* if we have a target path use */
if (!target_path) { if (!target_path) {
ret = get_path_len (fdt, target); ret = get_path_len (fdt, target);
if (ret < 0) if (ret < 0) {
return ret; return ret;
}
len = ret; len = ret;
} else { } else {
len = strlen (target_path); len = strlen (target_path);
} }
ret = fdt_setprop_placeholder(fdt, root_sym, name, ret = fdt_setprop_placeholder (
len + (len > 1) + rel_path_len + 1, &p); fdt,
if (ret < 0) root_sym,
name,
len + (len > 1) + rel_path_len + 1,
&p
);
if (ret < 0) {
return ret; return ret;
}
if (!target_path) { if (!target_path) {
/* again in case setprop_placeholder changed it */ /* again in case setprop_placeholder changed it */
ret = overlay_get_target (fdt, fdto, fragment, &target_path); ret = overlay_get_target (fdt, fdto, fragment, &target_path);
if (ret < 0) if (ret < 0) {
return ret; return ret;
}
target = ret; target = ret;
} }
buf = p; buf = p;
if (len > 1) { /* target is not root */ if (len > 1) {
/* target is not root */
if (!target_path) { if (!target_path) {
ret = fdt_get_path (fdt, target, buf, len + 1); ret = fdt_get_path (fdt, target, buf, len + 1);
if (ret < 0) if (ret < 0) {
return ret; return ret;
} else }
} else {
memcpy (buf, target_path, len + 1); memcpy (buf, target_path, len + 1);
}
} else } else {
len--; len--;
}
buf[len] = '/'; buf[len] = '/';
memcpy (buf + len + 1, rel_path, rel_path_len); memcpy (buf + len + 1, rel_path, rel_path_len);
@ -863,7 +1066,11 @@ static int overlay_symbol_update(void *fdt, void *fdto)
return 0; return 0;
} }
int fdt_overlay_apply(void *fdt, void *fdto) int
fdt_overlay_apply (
void *fdt,
void *fdto
)
{ {
uint32_t delta = fdt_get_max_phandle (fdt); uint32_t delta = fdt_get_max_phandle (fdt);
int ret; int ret;
@ -872,24 +1079,29 @@ int fdt_overlay_apply(void *fdt, void *fdto)
FDT_CHECK_HEADER (fdto); FDT_CHECK_HEADER (fdto);
ret = overlay_adjust_local_phandles (fdto, delta); ret = overlay_adjust_local_phandles (fdto, delta);
if (ret) if (ret) {
goto err; goto err;
}
ret = overlay_update_local_references (fdto, delta); ret = overlay_update_local_references (fdto, delta);
if (ret) if (ret) {
goto err; goto err;
}
ret = overlay_fixup_phandles (fdt, fdto); ret = overlay_fixup_phandles (fdt, fdto);
if (ret) if (ret) {
goto err; goto err;
}
ret = overlay_merge (fdt, fdto); ret = overlay_merge (fdt, fdto);
if (ret) if (ret) {
goto err; goto err;
}
ret = overlay_symbol_update (fdt, fdto); ret = overlay_symbol_update (fdt, fdto);
if (ret) if (ret) {
goto err; goto err;
}
/* /*
* The overlay has been damaged, erase its magic. * The overlay has been damaged, erase its magic.
@ -899,6 +1111,7 @@ int fdt_overlay_apply(void *fdt, void *fdto)
return 0; return 0;
err: err:
/* /*
* The overlay might have been damaged, erase its magic. * The overlay might have been damaged, erase its magic.
*/ */

View File

@ -55,66 +55,97 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
static int _fdt_nodename_eq(const void *fdt, int offset, static int
const char *s, int len) _fdt_nodename_eq (
const void *fdt,
int offset,
const char *s,
int len
)
{ {
const char *p = fdt_offset_ptr (fdt, offset + FDT_TAGSIZE, len+1); const char *p = fdt_offset_ptr (fdt, offset + FDT_TAGSIZE, len+1);
if (!p) if (!p) {
/* short match */ /* short match */
return 0; return 0;
if (memcmp(p, s, len) != 0)
return 0;
if (p[len] == '\0')
return 1;
else if (!memchr(s, '@', len) && (p[len] == '@'))
return 1;
else
return 0;
} }
const char *fdt_string(const void *fdt, int stroffset) if (memcmp (p, s, len) != 0) {
return 0;
}
if (p[len] == '\0') {
return 1;
} else if (!memchr (s, '@', len) && (p[len] == '@')) {
return 1;
} else {
return 0;
}
}
const char *
fdt_string (
const void *fdt,
int stroffset
)
{ {
return (const char *)fdt + fdt_off_dt_strings (fdt) + stroffset; return (const char *)fdt + fdt_off_dt_strings (fdt) + stroffset;
} }
static int _fdt_string_eq(const void *fdt, int stroffset, static int
const char *s, int len) _fdt_string_eq (
const void *fdt,
int stroffset,
const char *s,
int len
)
{ {
const char *p = fdt_string (fdt, stroffset); const char *p = fdt_string (fdt, stroffset);
return (strlen (p) == len) && (memcmp (p, s, len) == 0); return (strlen (p) == len) && (memcmp (p, s, len) == 0);
} }
uint32_t fdt_get_max_phandle(const void *fdt) uint32_t
fdt_get_max_phandle (
const void *fdt
)
{ {
uint32_t max_phandle = 0; uint32_t max_phandle = 0;
int offset; int offset;
for (offset = fdt_next_node (fdt, -1, NULL); ; for (offset = fdt_next_node (fdt, -1, NULL); ;
offset = fdt_next_node(fdt, offset, NULL)) { offset = fdt_next_node (fdt, offset, NULL))
{
uint32_t phandle; uint32_t phandle;
if (offset == -FDT_ERR_NOTFOUND) if (offset == -FDT_ERR_NOTFOUND) {
return max_phandle; return max_phandle;
}
if (offset < 0) if (offset < 0) {
return (uint32_t)-1; return (uint32_t)-1;
}
phandle = fdt_get_phandle (fdt, offset); phandle = fdt_get_phandle (fdt, offset);
if (phandle == (uint32_t)-1) if (phandle == (uint32_t)-1) {
continue; continue;
}
if (phandle > max_phandle) if (phandle > max_phandle) {
max_phandle = phandle; max_phandle = phandle;
} }
}
return 0; return 0;
} }
int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size) int
fdt_get_mem_rsv (
const void *fdt,
int n,
uint64_t *address,
uint64_t *size
)
{ {
FDT_CHECK_HEADER (fdt); FDT_CHECK_HEADER (fdt);
*address = fdt64_to_cpu (_fdt_mem_rsv (fdt, n)->address); *address = fdt64_to_cpu (_fdt_mem_rsv (fdt, n)->address);
@ -122,16 +153,25 @@ int fdt_get_mem_rsv(const void *fdt, int n, uint64_t *address, uint64_t *size)
return 0; return 0;
} }
int fdt_num_mem_rsv(const void *fdt) int
fdt_num_mem_rsv (
const void *fdt
)
{ {
int i = 0; int i = 0;
while (fdt64_to_cpu(_fdt_mem_rsv(fdt, i)->size) != 0) while (fdt64_to_cpu (_fdt_mem_rsv (fdt, i)->size) != 0) {
i++; i++;
}
return i; return i;
} }
static int _nextprop(const void *fdt, int offset) static int
_nextprop (
const void *fdt,
int offset
)
{ {
uint32_t tag; uint32_t tag;
int nextoffset; int nextoffset;
@ -141,22 +181,29 @@ static int _nextprop(const void *fdt, int offset)
switch (tag) { switch (tag) {
case FDT_END: case FDT_END:
if (nextoffset >= 0) if (nextoffset >= 0) {
return -FDT_ERR_BADSTRUCTURE; return -FDT_ERR_BADSTRUCTURE;
else } else {
return nextoffset; return nextoffset;
}
case FDT_PROP: case FDT_PROP:
return offset; return offset;
} }
offset = nextoffset; offset = nextoffset;
} while (tag == FDT_NOP); } while (tag == FDT_NOP);
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
} }
int fdt_subnode_offset_namelen(const void *fdt, int offset, int
const char *name, int namelen) fdt_subnode_offset_namelen (
const void *fdt,
int offset,
const char *name,
int namelen
)
{ {
int depth; int depth;
@ -165,22 +212,37 @@ int fdt_subnode_offset_namelen(const void *fdt, int offset,
for (depth = 0; for (depth = 0;
(offset >= 0) && (depth >= 0); (offset >= 0) && (depth >= 0);
offset = fdt_next_node (fdt, offset, &depth)) offset = fdt_next_node (fdt, offset, &depth))
{
if ( (depth == 1) if ( (depth == 1)
&& _fdt_nodename_eq (fdt, offset, name, namelen)) && _fdt_nodename_eq (fdt, offset, name, namelen))
{
return offset; return offset;
}
}
if (depth < 0) if (depth < 0) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
}
return offset; /* error */ return offset; /* error */
} }
int fdt_subnode_offset(const void *fdt, int parentoffset, int
const char *name) fdt_subnode_offset (
const void *fdt,
int parentoffset,
const char *name
)
{ {
return fdt_subnode_offset_namelen (fdt, parentoffset, name, strlen (name)); return fdt_subnode_offset_namelen (fdt, parentoffset, name, strlen (name));
} }
int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen) int
fdt_path_offset_namelen (
const void *fdt,
const char *path,
int namelen
)
{ {
const char *end = path + namelen; const char *end = path + namelen;
const char *p = path; const char *p = path;
@ -192,12 +254,15 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
if (*path != '/') { if (*path != '/') {
const char *q = memchr (path, '/', end - p); const char *q = memchr (path, '/', end - p);
if (!q) if (!q) {
q = end; q = end;
}
p = fdt_get_alias_namelen (fdt, p, q - p); p = fdt_get_alias_namelen (fdt, p, q - p);
if (!p) if (!p) {
return -FDT_ERR_BADPATH; return -FDT_ERR_BADPATH;
}
offset = fdt_path_offset (fdt, p); offset = fdt_path_offset (fdt, p);
p = q; p = q;
@ -208,16 +273,20 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
while (*p == '/') { while (*p == '/') {
p++; p++;
if (p == end) if (p == end) {
return offset; return offset;
} }
}
q = memchr (p, '/', end - p); q = memchr (p, '/', end - p);
if (! q) if (!q) {
q = end; q = end;
}
offset = fdt_subnode_offset_namelen (fdt, offset, p, q-p); offset = fdt_subnode_offset_namelen (fdt, offset, p, q-p);
if (offset < 0) if (offset < 0) {
return offset; return offset;
}
p = q; p = q;
} }
@ -225,134 +294,212 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
return offset; return offset;
} }
int fdt_path_offset(const void *fdt, const char *path) int
fdt_path_offset (
const void *fdt,
const char *path
)
{ {
return fdt_path_offset_namelen (fdt, path, strlen (path)); return fdt_path_offset_namelen (fdt, path, strlen (path));
} }
const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) const char *
fdt_get_name (
const void *fdt,
int nodeoffset,
int *len
)
{ {
const struct fdt_node_header *nh = _fdt_offset_ptr (fdt, nodeoffset); const struct fdt_node_header *nh = _fdt_offset_ptr (fdt, nodeoffset);
int err; int err;
if ( ((err = fdt_check_header (fdt)) != 0) if ( ((err = fdt_check_header (fdt)) != 0)
|| ((err = _fdt_check_node_offset (fdt, nodeoffset)) < 0)) || ((err = _fdt_check_node_offset (fdt, nodeoffset)) < 0))
{
goto fail; goto fail;
}
if (len) if (len) {
*len = strlen (nh->name); *len = strlen (nh->name);
}
return nh->name; return nh->name;
fail: fail:
if (len) if (len) {
*len = err; *len = err;
}
return NULL; return NULL;
} }
int fdt_first_property_offset(const void *fdt, int nodeoffset) int
fdt_first_property_offset (
const void *fdt,
int nodeoffset
)
{ {
int offset; int offset;
if ((offset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) if ((offset = _fdt_check_node_offset (fdt, nodeoffset)) < 0) {
return offset; return offset;
}
return _nextprop (fdt, offset); return _nextprop (fdt, offset);
} }
int fdt_next_property_offset(const void *fdt, int offset) int
fdt_next_property_offset (
const void *fdt,
int offset
)
{ {
if ((offset = _fdt_check_prop_offset(fdt, offset)) < 0) if ((offset = _fdt_check_prop_offset (fdt, offset)) < 0) {
return offset; return offset;
}
return _nextprop (fdt, offset); return _nextprop (fdt, offset);
} }
const struct fdt_property *fdt_get_property_by_offset(const void *fdt, const struct fdt_property *
fdt_get_property_by_offset (
const void *fdt,
int offset, int offset,
int *lenp) int *lenp
)
{ {
int err; int err;
const struct fdt_property *prop; const struct fdt_property *prop;
if ((err = _fdt_check_prop_offset (fdt, offset)) < 0) { if ((err = _fdt_check_prop_offset (fdt, offset)) < 0) {
if (lenp) if (lenp) {
*lenp = err; *lenp = err;
}
return NULL; return NULL;
} }
prop = _fdt_offset_ptr (fdt, offset); prop = _fdt_offset_ptr (fdt, offset);
if (lenp) if (lenp) {
*lenp = fdt32_to_cpu (prop->len); *lenp = fdt32_to_cpu (prop->len);
}
return prop; return prop;
} }
const struct fdt_property *fdt_get_property_namelen(const void *fdt, const struct fdt_property *
fdt_get_property_namelen (
const void *fdt,
int offset, int offset,
const char *name, const char *name,
int namelen, int *lenp) int namelen,
int *lenp
)
{ {
for (offset = fdt_first_property_offset (fdt, offset); for (offset = fdt_first_property_offset (fdt, offset);
(offset >= 0); (offset >= 0);
(offset = fdt_next_property_offset(fdt, offset))) { (offset = fdt_next_property_offset (fdt, offset)))
{
const struct fdt_property *prop; const struct fdt_property *prop;
if (!(prop = fdt_get_property_by_offset (fdt, offset, lenp))) { if (!(prop = fdt_get_property_by_offset (fdt, offset, lenp))) {
offset = -FDT_ERR_INTERNAL; offset = -FDT_ERR_INTERNAL;
break; break;
} }
if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff),
name, namelen)) if (_fdt_string_eq (
fdt,
fdt32_to_cpu (prop->nameoff),
name,
namelen
))
{
return prop; return prop;
} }
}
if (lenp) if (lenp) {
*lenp = offset; *lenp = offset;
}
return NULL; return NULL;
} }
const struct fdt_property *fdt_get_property(const void *fdt, const struct fdt_property *
fdt_get_property (
const void *fdt,
int nodeoffset, int nodeoffset,
const char *name, int *lenp) const char *name,
int *lenp
)
{ {
return fdt_get_property_namelen(fdt, nodeoffset, name, return fdt_get_property_namelen (
strlen(name), lenp); fdt,
nodeoffset,
name,
strlen (name),
lenp
);
} }
const void *fdt_getprop_namelen(const void *fdt, int nodeoffset, const void *
const char *name, int namelen, int *lenp) fdt_getprop_namelen (
const void *fdt,
int nodeoffset,
const char *name,
int namelen,
int *lenp
)
{ {
const struct fdt_property *prop; const struct fdt_property *prop;
prop = fdt_get_property_namelen (fdt, nodeoffset, name, namelen, lenp); prop = fdt_get_property_namelen (fdt, nodeoffset, name, namelen, lenp);
if (!prop) if (!prop) {
return NULL; return NULL;
}
return prop->data; return prop->data;
} }
const void *fdt_getprop_by_offset(const void *fdt, int offset, const void *
const char **namep, int *lenp) fdt_getprop_by_offset (
const void *fdt,
int offset,
const char **namep,
int *lenp
)
{ {
const struct fdt_property *prop; const struct fdt_property *prop;
prop = fdt_get_property_by_offset (fdt, offset, lenp); prop = fdt_get_property_by_offset (fdt, offset, lenp);
if (!prop) if (!prop) {
return NULL; return NULL;
if (namep) }
if (namep) {
*namep = fdt_string (fdt, fdt32_to_cpu (prop->nameoff)); *namep = fdt_string (fdt, fdt32_to_cpu (prop->nameoff));
}
return prop->data; return prop->data;
} }
const void *fdt_getprop(const void *fdt, int nodeoffset, const void *
const char *name, int *lenp) fdt_getprop (
const void *fdt,
int nodeoffset,
const char *name,
int *lenp
)
{ {
return fdt_getprop_namelen (fdt, nodeoffset, name, strlen (name), lenp); return fdt_getprop_namelen (fdt, nodeoffset, name, strlen (name), lenp);
} }
uint32_t fdt_get_phandle(const void *fdt, int nodeoffset) uint32_t
fdt_get_phandle (
const void *fdt,
int nodeoffset
)
{ {
const fdt32_t *php; const fdt32_t *php;
int len; int len;
@ -362,31 +509,47 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
php = fdt_getprop (fdt, nodeoffset, "phandle", &len); php = fdt_getprop (fdt, nodeoffset, "phandle", &len);
if (!php || (len != sizeof (*php))) { if (!php || (len != sizeof (*php))) {
php = fdt_getprop (fdt, nodeoffset, "linux,phandle", &len); php = fdt_getprop (fdt, nodeoffset, "linux,phandle", &len);
if (!php || (len != sizeof(*php))) if (!php || (len != sizeof (*php))) {
return 0; return 0;
} }
}
return fdt32_to_cpu (*php); return fdt32_to_cpu (*php);
} }
const char *fdt_get_alias_namelen(const void *fdt, const char *
const char *name, int namelen) fdt_get_alias_namelen (
const void *fdt,
const char *name,
int namelen
)
{ {
int aliasoffset; int aliasoffset;
aliasoffset = fdt_path_offset (fdt, "/aliases"); aliasoffset = fdt_path_offset (fdt, "/aliases");
if (aliasoffset < 0) if (aliasoffset < 0) {
return NULL; return NULL;
}
return fdt_getprop_namelen (fdt, aliasoffset, name, namelen, NULL); return fdt_getprop_namelen (fdt, aliasoffset, name, namelen, NULL);
} }
const char *fdt_get_alias(const void *fdt, const char *name) const char *
fdt_get_alias (
const void *fdt,
const char *name
)
{ {
return fdt_get_alias_namelen (fdt, name, strlen (name)); return fdt_get_alias_namelen (fdt, name, strlen (name));
} }
int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) int
fdt_get_path (
const void *fdt,
int nodeoffset,
char *buf,
int buflen
)
{ {
int pdepth = 0, p = 0; int pdepth = 0, p = 0;
int offset, depth, namelen; int offset, depth, namelen;
@ -394,23 +557,28 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
FDT_CHECK_HEADER (fdt); FDT_CHECK_HEADER (fdt);
if (buflen < 2) if (buflen < 2) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
for (offset = 0, depth = 0; for (offset = 0, depth = 0;
(offset >= 0) && (offset <= nodeoffset); (offset >= 0) && (offset <= nodeoffset);
offset = fdt_next_node(fdt, offset, &depth)) { offset = fdt_next_node (fdt, offset, &depth))
{
while (pdepth > depth) { while (pdepth > depth) {
do { do {
p--; p--;
} while (buf[p-1] != '/'); } while (buf[p-1] != '/');
pdepth--; pdepth--;
} }
if (pdepth >= depth) { if (pdepth >= depth) {
name = fdt_get_name (fdt, offset, &namelen); name = fdt_get_name (fdt, offset, &namelen);
if (!name) if (!name) {
return namelen; return namelen;
}
if ((p + namelen + 1) <= buflen) { if ((p + namelen + 1) <= buflen) {
memcpy (buf + p, name, namelen); memcpy (buf + p, name, namelen);
p += namelen; p += namelen;
@ -420,84 +588,121 @@ int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
} }
if (offset == nodeoffset) { if (offset == nodeoffset) {
if (pdepth < (depth + 1)) if (pdepth < (depth + 1)) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
if (p > 1) /* special case so that root path is "/", not "" */ if (p > 1) {
/* special case so that root path is "/", not "" */
p--; p--;
}
buf[p] = '\0'; buf[p] = '\0';
return 0; return 0;
} }
} }
if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) {
return -FDT_ERR_BADOFFSET; return -FDT_ERR_BADOFFSET;
else if (offset == -FDT_ERR_BADOFFSET) } else if (offset == -FDT_ERR_BADOFFSET) {
return -FDT_ERR_BADSTRUCTURE; return -FDT_ERR_BADSTRUCTURE;
}
return offset; /* error from fdt_next_node() */ return offset; /* error from fdt_next_node() */
} }
int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, int
int supernodedepth, int *nodedepth) fdt_supernode_atdepth_offset (
const void *fdt,
int nodeoffset,
int supernodedepth,
int *nodedepth
)
{ {
int offset, depth; int offset, depth;
int supernodeoffset = -FDT_ERR_INTERNAL; int supernodeoffset = -FDT_ERR_INTERNAL;
FDT_CHECK_HEADER (fdt); FDT_CHECK_HEADER (fdt);
if (supernodedepth < 0) if (supernodedepth < 0) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
}
for (offset = 0, depth = 0; for (offset = 0, depth = 0;
(offset >= 0) && (offset <= nodeoffset); (offset >= 0) && (offset <= nodeoffset);
offset = fdt_next_node(fdt, offset, &depth)) { offset = fdt_next_node (fdt, offset, &depth))
if (depth == supernodedepth) {
if (depth == supernodedepth) {
supernodeoffset = offset; supernodeoffset = offset;
}
if (offset == nodeoffset) { if (offset == nodeoffset) {
if (nodedepth) if (nodedepth) {
*nodedepth = depth; *nodedepth = depth;
}
if (supernodedepth > depth) if (supernodedepth > depth) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
else } else {
return supernodeoffset; return supernodeoffset;
} }
} }
}
if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) {
return -FDT_ERR_BADOFFSET; return -FDT_ERR_BADOFFSET;
else if (offset == -FDT_ERR_BADOFFSET) } else if (offset == -FDT_ERR_BADOFFSET) {
return -FDT_ERR_BADSTRUCTURE; return -FDT_ERR_BADSTRUCTURE;
}
return offset; /* error from fdt_next_node() */ return offset; /* error from fdt_next_node() */
} }
int fdt_node_depth(const void *fdt, int nodeoffset) int
fdt_node_depth (
const void *fdt,
int nodeoffset
)
{ {
int nodedepth; int nodedepth;
int err; int err;
err = fdt_supernode_atdepth_offset (fdt, nodeoffset, 0, &nodedepth); err = fdt_supernode_atdepth_offset (fdt, nodeoffset, 0, &nodedepth);
if (err) if (err) {
return (err < 0) ? err : -FDT_ERR_INTERNAL; return (err < 0) ? err : -FDT_ERR_INTERNAL;
}
return nodedepth; return nodedepth;
} }
int fdt_parent_offset(const void *fdt, int nodeoffset) int
fdt_parent_offset (
const void *fdt,
int nodeoffset
)
{ {
int nodedepth = fdt_node_depth (fdt, nodeoffset); int nodedepth = fdt_node_depth (fdt, nodeoffset);
if (nodedepth < 0) if (nodedepth < 0) {
return nodedepth; return nodedepth;
return fdt_supernode_atdepth_offset(fdt, nodeoffset,
nodedepth - 1, NULL);
} }
int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, return fdt_supernode_atdepth_offset (
fdt,
nodeoffset,
nodedepth - 1,
NULL
);
}
int
fdt_node_offset_by_prop_value (
const void *fdt,
int startoffset,
const char *propname, const char *propname,
const void *propval, int proplen) const void *propval,
int proplen
)
{ {
int offset; int offset;
const void *val; const void *val;
@ -512,22 +717,30 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset,
* approach; performance can come later. */ * approach; performance can come later. */
for (offset = fdt_next_node (fdt, startoffset, NULL); for (offset = fdt_next_node (fdt, startoffset, NULL);
offset >= 0; offset >= 0;
offset = fdt_next_node(fdt, offset, NULL)) { offset = fdt_next_node (fdt, offset, NULL))
{
val = fdt_getprop (fdt, offset, propname, &len); val = fdt_getprop (fdt, offset, propname, &len);
if ( val && (len == proplen) if ( val && (len == proplen)
&& (memcmp (val, propval, len) == 0)) && (memcmp (val, propval, len) == 0))
{
return offset; return offset;
} }
}
return offset; /* error from fdt_next_node() */ return offset; /* error from fdt_next_node() */
} }
int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle) int
fdt_node_offset_by_phandle (
const void *fdt,
uint32_t phandle
)
{ {
int offset; int offset;
if ((phandle == 0) || (phandle == -1)) if ((phandle == 0) || (phandle == -1)) {
return -FDT_ERR_BADPHANDLE; return -FDT_ERR_BADPHANDLE;
}
FDT_CHECK_HEADER (fdt); FDT_CHECK_HEADER (fdt);
@ -539,39 +752,57 @@ int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle)
* performance can come later. */ * performance can come later. */
for (offset = fdt_next_node (fdt, -1, NULL); for (offset = fdt_next_node (fdt, -1, NULL);
offset >= 0; offset >= 0;
offset = fdt_next_node(fdt, offset, NULL)) { offset = fdt_next_node (fdt, offset, NULL))
if (fdt_get_phandle(fdt, offset) == phandle) {
if (fdt_get_phandle (fdt, offset) == phandle) {
return offset; return offset;
} }
}
return offset; /* error from fdt_next_node() */ return offset; /* error from fdt_next_node() */
} }
int fdt_stringlist_contains(const char *strlist, int listlen, const char *str) int
fdt_stringlist_contains (
const char *strlist,
int listlen,
const char *str
)
{ {
int len = strlen (str); int len = strlen (str);
const char *p; const char *p;
while (listlen >= len) { while (listlen >= len) {
if (memcmp(str, strlist, len+1) == 0) if (memcmp (str, strlist, len+1) == 0) {
return 1; return 1;
}
p = memchr (strlist, '\0', listlen); p = memchr (strlist, '\0', listlen);
if (!p) if (!p) {
return 0; /* malformed strlist.. */ return 0; /* malformed strlist.. */
}
listlen -= (p-strlist) + 1; listlen -= (p-strlist) + 1;
strlist = p + 1; strlist = p + 1;
} }
return 0; return 0;
} }
int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property) int
fdt_stringlist_count (
const void *fdt,
int nodeoffset,
const char *property
)
{ {
const char *list, *end; const char *list, *end;
int length, count = 0; int length, count = 0;
list = fdt_getprop (fdt, nodeoffset, property, &length); list = fdt_getprop (fdt, nodeoffset, property, &length);
if (!list) if (!list) {
return length; return length;
}
end = list + length; end = list + length;
@ -579,8 +810,9 @@ int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)
length = strnlen (list, end - list) + 1; length = strnlen (list, end - list) + 1;
/* Abort if the last string isn't properly NUL-terminated. */ /* Abort if the last string isn't properly NUL-terminated. */
if (list + length > end) if (list + length > end) {
return -FDT_ERR_BADVALUE; return -FDT_ERR_BADVALUE;
}
list += length; list += length;
count++; count++;
@ -589,15 +821,21 @@ int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)
return count; return count;
} }
int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, int
const char *string) fdt_stringlist_search (
const void *fdt,
int nodeoffset,
const char *property,
const char *string
)
{ {
int length, len, idx = 0; int length, len, idx = 0;
const char *list, *end; const char *list, *end;
list = fdt_getprop (fdt, nodeoffset, property, &length); list = fdt_getprop (fdt, nodeoffset, property, &length);
if (!list) if (!list) {
return length; return length;
}
len = strlen (string) + 1; len = strlen (string) + 1;
end = list + length; end = list + length;
@ -606,11 +844,13 @@ int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
length = strnlen (list, end - list) + 1; length = strnlen (list, end - list) + 1;
/* Abort if the last string isn't properly NUL-terminated. */ /* Abort if the last string isn't properly NUL-terminated. */
if (list + length > end) if (list + length > end) {
return -FDT_ERR_BADVALUE; return -FDT_ERR_BADVALUE;
}
if (length == len && memcmp(list, string, length) == 0) if ((length == len) && (memcmp (list, string, length) == 0)) {
return idx; return idx;
}
list += length; list += length;
idx++; idx++;
@ -619,17 +859,23 @@ int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
} }
const char *fdt_stringlist_get(const void *fdt, int nodeoffset, const char *
const char *property, int idx, fdt_stringlist_get (
int *lenp) const void *fdt,
int nodeoffset,
const char *property,
int idx,
int *lenp
)
{ {
const char *list, *end; const char *list, *end;
int length; int length;
list = fdt_getprop (fdt, nodeoffset, property, &length); list = fdt_getprop (fdt, nodeoffset, property, &length);
if (!list) { if (!list) {
if (lenp) if (lenp) {
*lenp = length; *lenp = length;
}
return NULL; return NULL;
} }
@ -641,15 +887,17 @@ const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
/* Abort if the last string isn't properly NUL-terminated. */ /* Abort if the last string isn't properly NUL-terminated. */
if (list + length > end) { if (list + length > end) {
if (lenp) if (lenp) {
*lenp = -FDT_ERR_BADVALUE; *lenp = -FDT_ERR_BADVALUE;
}
return NULL; return NULL;
} }
if (idx == 0) { if (idx == 0) {
if (lenp) if (lenp) {
*lenp = length - 1; *lenp = length - 1;
}
return list; return list;
} }
@ -658,27 +906,37 @@ const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
idx--; idx--;
} }
if (lenp) if (lenp) {
*lenp = -FDT_ERR_NOTFOUND; *lenp = -FDT_ERR_NOTFOUND;
}
return NULL; return NULL;
} }
int fdt_node_check_compatible(const void *fdt, int nodeoffset, int
const char *compatible) fdt_node_check_compatible (
const void *fdt,
int nodeoffset,
const char *compatible
)
{ {
const void *prop; const void *prop;
int len; int len;
prop = fdt_getprop (fdt, nodeoffset, "compatible", &len); prop = fdt_getprop (fdt, nodeoffset, "compatible", &len);
if (!prop) if (!prop) {
return len; return len;
}
return !fdt_stringlist_contains (prop, len, compatible); return !fdt_stringlist_contains (prop, len, compatible);
} }
int fdt_node_offset_by_compatible(const void *fdt, int startoffset, int
const char *compatible) fdt_node_offset_by_compatible (
const void *fdt,
int startoffset,
const char *compatible
)
{ {
int offset, err; int offset, err;
@ -691,13 +949,15 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
* implement approach; performance can come later. */ * implement approach; performance can come later. */
for (offset = fdt_next_node (fdt, startoffset, NULL); for (offset = fdt_next_node (fdt, startoffset, NULL);
offset >= 0; offset >= 0;
offset = fdt_next_node(fdt, offset, NULL)) { offset = fdt_next_node (fdt, offset, NULL))
{
err = fdt_node_check_compatible (fdt, offset, compatible); err = fdt_node_check_compatible (fdt, offset, compatible);
if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) {
return err; return err;
else if (err == 0) } else if (err == 0) {
return offset; return offset;
} }
}
return offset; /* error from fdt_next_node() */ return offset; /* error from fdt_next_node() */
} }

View File

@ -55,8 +55,12 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
static int _fdt_blocks_misordered(const void *fdt, static int
int mem_rsv_size, int struct_size) _fdt_blocks_misordered (
const void *fdt,
int mem_rsv_size,
int struct_size
)
{ {
return (fdt_off_mem_rsvmap (fdt) < FDT_ALIGN (sizeof (struct fdt_header), 8)) return (fdt_off_mem_rsvmap (fdt) < FDT_ALIGN (sizeof (struct fdt_header), 8))
|| (fdt_off_dt_struct (fdt) < || (fdt_off_dt_struct (fdt) <
@ -67,17 +71,29 @@ static int _fdt_blocks_misordered(const void *fdt,
(fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt))); (fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt)));
} }
static int _fdt_rw_check_header(void *fdt) static int
_fdt_rw_check_header (
void *fdt
)
{ {
FDT_CHECK_HEADER (fdt); FDT_CHECK_HEADER (fdt);
if (fdt_version(fdt) < 17) if (fdt_version (fdt) < 17) {
return -FDT_ERR_BADVERSION; return -FDT_ERR_BADVERSION;
if (_fdt_blocks_misordered(fdt, sizeof(struct fdt_reserve_entry), }
fdt_size_dt_struct(fdt)))
if (_fdt_blocks_misordered (
fdt,
sizeof (struct fdt_reserve_entry),
fdt_size_dt_struct (fdt)
))
{
return -FDT_ERR_BADLAYOUT; return -FDT_ERR_BADLAYOUT;
if (fdt_version(fdt) > 17) }
if (fdt_version (fdt) > 17) {
fdt_set_version (fdt, 17); fdt_set_version (fdt, 17);
}
return 0; return 0;
} }
@ -89,67 +105,105 @@ static int _fdt_rw_check_header(void *fdt)
return __err; \ return __err; \
} }
static inline int _fdt_data_size(void *fdt) static inline int
_fdt_data_size (
void *fdt
)
{ {
return fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt); return fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt);
} }
static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen) static int
_fdt_splice (
void *fdt,
void *splicepoint,
int oldlen,
int newlen
)
{ {
char *p = splicepoint; char *p = splicepoint;
char *end = (char *)fdt + _fdt_data_size (fdt); char *end = (char *)fdt + _fdt_data_size (fdt);
if (((p + oldlen) < p) || ((p + oldlen) > end)) if (((p + oldlen) < p) || ((p + oldlen) > end)) {
return -FDT_ERR_BADOFFSET; return -FDT_ERR_BADOFFSET;
if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt)) }
if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt)) {
return -FDT_ERR_BADOFFSET; return -FDT_ERR_BADOFFSET;
if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt))) }
if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize (fdt))) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
memmove (p + newlen, p + oldlen, end - p - oldlen); memmove (p + newlen, p + oldlen, end - p - oldlen);
return 0; return 0;
} }
static int _fdt_splice_mem_rsv(void *fdt, struct fdt_reserve_entry *p, static int
int oldn, int newn) _fdt_splice_mem_rsv (
void *fdt,
struct fdt_reserve_entry *p,
int oldn,
int newn
)
{ {
int delta = (newn - oldn) * sizeof (*p); int delta = (newn - oldn) * sizeof (*p);
int err; int err;
err = _fdt_splice (fdt, p, oldn * sizeof (*p), newn * sizeof (*p)); err = _fdt_splice (fdt, p, oldn * sizeof (*p), newn * sizeof (*p));
if (err) if (err) {
return err; return err;
}
fdt_set_off_dt_struct (fdt, fdt_off_dt_struct (fdt) + delta); fdt_set_off_dt_struct (fdt, fdt_off_dt_struct (fdt) + delta);
fdt_set_off_dt_strings (fdt, fdt_off_dt_strings (fdt) + delta); fdt_set_off_dt_strings (fdt, fdt_off_dt_strings (fdt) + delta);
return 0; return 0;
} }
static int _fdt_splice_struct(void *fdt, void *p, static int
int oldlen, int newlen) _fdt_splice_struct (
void *fdt,
void *p,
int oldlen,
int newlen
)
{ {
int delta = newlen - oldlen; int delta = newlen - oldlen;
int err; int err;
if ((err = _fdt_splice(fdt, p, oldlen, newlen))) if ((err = _fdt_splice (fdt, p, oldlen, newlen))) {
return err; return err;
}
fdt_set_size_dt_struct (fdt, fdt_size_dt_struct (fdt) + delta); fdt_set_size_dt_struct (fdt, fdt_size_dt_struct (fdt) + delta);
fdt_set_off_dt_strings (fdt, fdt_off_dt_strings (fdt) + delta); fdt_set_off_dt_strings (fdt, fdt_off_dt_strings (fdt) + delta);
return 0; return 0;
} }
static int _fdt_splice_string(void *fdt, int newlen) static int
_fdt_splice_string (
void *fdt,
int newlen
)
{ {
void *p = (char *)fdt void *p = (char *)fdt
+ fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt); + fdt_off_dt_strings (fdt) + fdt_size_dt_strings (fdt);
int err; int err;
if ((err = _fdt_splice(fdt, p, 0, newlen))) if ((err = _fdt_splice (fdt, p, 0, newlen))) {
return err; return err;
}
fdt_set_size_dt_strings (fdt, fdt_size_dt_strings (fdt) + newlen); fdt_set_size_dt_strings (fdt, fdt_size_dt_strings (fdt) + newlen);
return 0; return 0;
} }
static int _fdt_find_add_string(void *fdt, const char *s) static int
_fdt_find_add_string (
void *fdt,
const char *s
)
{ {
char *strtab = (char *)fdt + fdt_off_dt_strings (fdt); char *strtab = (char *)fdt + fdt_off_dt_strings (fdt);
const char *p; const char *p;
@ -158,20 +212,27 @@ static int _fdt_find_add_string(void *fdt, const char *s)
int err; int err;
p = _fdt_find_string (strtab, fdt_size_dt_strings (fdt), s); p = _fdt_find_string (strtab, fdt_size_dt_strings (fdt), s);
if (p) if (p) {
/* found it */ /* found it */
return (p - strtab); return (p - strtab);
}
new = strtab + fdt_size_dt_strings (fdt); new = strtab + fdt_size_dt_strings (fdt);
err = _fdt_splice_string (fdt, len); err = _fdt_splice_string (fdt, len);
if (err) if (err) {
return err; return err;
}
memcpy (new, s, len); memcpy (new, s, len);
return (new - strtab); return (new - strtab);
} }
int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size) int
fdt_add_mem_rsv (
void *fdt,
uint64_t address,
uint64_t size
)
{ {
struct fdt_reserve_entry *re; struct fdt_reserve_entry *re;
int err; int err;
@ -180,65 +241,93 @@ int fdt_add_mem_rsv(void *fdt, uint64_t address, uint64_t size)
re = _fdt_mem_rsv_w (fdt, fdt_num_mem_rsv (fdt)); re = _fdt_mem_rsv_w (fdt, fdt_num_mem_rsv (fdt));
err = _fdt_splice_mem_rsv (fdt, re, 0, 1); err = _fdt_splice_mem_rsv (fdt, re, 0, 1);
if (err) if (err) {
return err; return err;
}
re->address = cpu_to_fdt64 (address); re->address = cpu_to_fdt64 (address);
re->size = cpu_to_fdt64 (size); re->size = cpu_to_fdt64 (size);
return 0; return 0;
} }
int fdt_del_mem_rsv(void *fdt, int n) int
fdt_del_mem_rsv (
void *fdt,
int n
)
{ {
struct fdt_reserve_entry *re = _fdt_mem_rsv_w (fdt, n); struct fdt_reserve_entry *re = _fdt_mem_rsv_w (fdt, n);
FDT_RW_CHECK_HEADER (fdt); FDT_RW_CHECK_HEADER (fdt);
if (n >= fdt_num_mem_rsv(fdt)) if (n >= fdt_num_mem_rsv (fdt)) {
return -FDT_ERR_NOTFOUND; return -FDT_ERR_NOTFOUND;
}
return _fdt_splice_mem_rsv (fdt, re, 1, 0); return _fdt_splice_mem_rsv (fdt, re, 1, 0);
} }
static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, static int
int len, struct fdt_property **prop) _fdt_resize_property (
void *fdt,
int nodeoffset,
const char *name,
int len,
struct fdt_property **prop
)
{ {
int oldlen; int oldlen;
int err; int err;
*prop = fdt_get_property_w (fdt, nodeoffset, name, &oldlen); *prop = fdt_get_property_w (fdt, nodeoffset, name, &oldlen);
if (!*prop) if (!*prop) {
return oldlen; return oldlen;
}
if ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), if ((err = _fdt_splice_struct (
FDT_TAGALIGN(len)))) fdt,
(*prop)->data,
FDT_TAGALIGN (oldlen),
FDT_TAGALIGN (len)
)))
{
return err; return err;
}
(*prop)->len = cpu_to_fdt32 (len); (*prop)->len = cpu_to_fdt32 (len);
return 0; return 0;
} }
static int _fdt_add_property(void *fdt, int nodeoffset, const char *name, static int
int len, struct fdt_property **prop) _fdt_add_property (
void *fdt,
int nodeoffset,
const char *name,
int len,
struct fdt_property **prop
)
{ {
int proplen; int proplen;
int nextoffset; int nextoffset;
int namestroff; int namestroff;
int err; int err;
if ((nextoffset = _fdt_check_node_offset(fdt, nodeoffset)) < 0) if ((nextoffset = _fdt_check_node_offset (fdt, nodeoffset)) < 0) {
return nextoffset; return nextoffset;
}
namestroff = _fdt_find_add_string (fdt, name); namestroff = _fdt_find_add_string (fdt, name);
if (namestroff < 0) if (namestroff < 0) {
return namestroff; return namestroff;
}
*prop = _fdt_offset_ptr_w (fdt, nextoffset); *prop = _fdt_offset_ptr_w (fdt, nextoffset);
proplen = sizeof (**prop) + FDT_TAGALIGN (len); proplen = sizeof (**prop) + FDT_TAGALIGN (len);
err = _fdt_splice_struct (fdt, *prop, 0, proplen); err = _fdt_splice_struct (fdt, *prop, 0, proplen);
if (err) if (err) {
return err; return err;
}
(*prop)->tag = cpu_to_fdt32 (FDT_PROP); (*prop)->tag = cpu_to_fdt32 (FDT_PROP);
(*prop)->nameoff = cpu_to_fdt32 (namestroff); (*prop)->nameoff = cpu_to_fdt32 (namestroff);
@ -246,7 +335,12 @@ static int _fdt_add_property(void *fdt, int nodeoffset, const char *name,
return 0; return 0;
} }
int fdt_set_name(void *fdt, int nodeoffset, const char *name) int
fdt_set_name (
void *fdt,
int nodeoffset,
const char *name
)
{ {
char *namep; char *namep;
int oldlen, newlen; int oldlen, newlen;
@ -255,22 +349,34 @@ int fdt_set_name(void *fdt, int nodeoffset, const char *name)
FDT_RW_CHECK_HEADER (fdt); FDT_RW_CHECK_HEADER (fdt);
namep = (char *)(uintptr_t)fdt_get_name (fdt, nodeoffset, &oldlen); namep = (char *)(uintptr_t)fdt_get_name (fdt, nodeoffset, &oldlen);
if (!namep) if (!namep) {
return oldlen; return oldlen;
}
newlen = strlen (name); newlen = strlen (name);
err = _fdt_splice_struct(fdt, namep, FDT_TAGALIGN(oldlen+1), err = _fdt_splice_struct (
FDT_TAGALIGN(newlen+1)); fdt,
if (err) namep,
FDT_TAGALIGN (oldlen+1),
FDT_TAGALIGN (newlen+1)
);
if (err) {
return err; return err;
}
memcpy (namep, name, newlen+1); memcpy (namep, name, newlen+1);
return 0; return 0;
} }
int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name, int
int len, void **prop_data) fdt_setprop_placeholder (
void *fdt,
int nodeoffset,
const char *name,
int len,
void **prop_data
)
{ {
struct fdt_property *prop; struct fdt_property *prop;
int err; int err;
@ -278,32 +384,50 @@ int fdt_setprop_placeholder(void *fdt, int nodeoffset, const char *name,
FDT_RW_CHECK_HEADER (fdt); FDT_RW_CHECK_HEADER (fdt);
err = _fdt_resize_property (fdt, nodeoffset, name, len, &prop); err = _fdt_resize_property (fdt, nodeoffset, name, len, &prop);
if (err == -FDT_ERR_NOTFOUND) if (err == -FDT_ERR_NOTFOUND) {
err = _fdt_add_property (fdt, nodeoffset, name, len, &prop); err = _fdt_add_property (fdt, nodeoffset, name, len, &prop);
if (err) }
if (err) {
return err; return err;
}
*prop_data = prop->data; *prop_data = prop->data;
return 0; return 0;
} }
int fdt_setprop(void *fdt, int nodeoffset, const char *name, int
const void *val, int len) fdt_setprop (
void *fdt,
int nodeoffset,
const char *name,
const void *val,
int len
)
{ {
void *prop_data; void *prop_data;
int err; int err;
err = fdt_setprop_placeholder (fdt, nodeoffset, name, len, &prop_data); err = fdt_setprop_placeholder (fdt, nodeoffset, name, len, &prop_data);
if (err) if (err) {
return err; return err;
}
if (len) if (len) {
memcpy (prop_data, val, len); memcpy (prop_data, val, len);
}
return 0; return 0;
} }
int fdt_appendprop(void *fdt, int nodeoffset, const char *name, int
const void *val, int len) fdt_appendprop (
void *fdt,
int nodeoffset,
const char *name,
const void *val,
int len
)
{ {
struct fdt_property *prop; struct fdt_property *prop;
int err, oldlen, newlen; int err, oldlen, newlen;
@ -313,23 +437,36 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
prop = fdt_get_property_w (fdt, nodeoffset, name, &oldlen); prop = fdt_get_property_w (fdt, nodeoffset, name, &oldlen);
if (prop) { if (prop) {
newlen = len + oldlen; newlen = len + oldlen;
err = _fdt_splice_struct(fdt, prop->data, err = _fdt_splice_struct (
fdt,
prop->data,
FDT_TAGALIGN (oldlen), FDT_TAGALIGN (oldlen),
FDT_TAGALIGN(newlen)); FDT_TAGALIGN (newlen)
if (err) );
if (err) {
return err; return err;
}
prop->len = cpu_to_fdt32 (newlen); prop->len = cpu_to_fdt32 (newlen);
memcpy (prop->data + oldlen, val, len); memcpy (prop->data + oldlen, val, len);
} else { } else {
err = _fdt_add_property (fdt, nodeoffset, name, len, &prop); err = _fdt_add_property (fdt, nodeoffset, name, len, &prop);
if (err) if (err) {
return err; return err;
}
memcpy (prop->data, val, len); memcpy (prop->data, val, len);
} }
return 0; return 0;
} }
int fdt_delprop(void *fdt, int nodeoffset, const char *name) int
fdt_delprop (
void *fdt,
int nodeoffset,
const char *name
)
{ {
struct fdt_property *prop; struct fdt_property *prop;
int len, proplen; int len, proplen;
@ -337,15 +474,21 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name)
FDT_RW_CHECK_HEADER (fdt); FDT_RW_CHECK_HEADER (fdt);
prop = fdt_get_property_w (fdt, nodeoffset, name, &len); prop = fdt_get_property_w (fdt, nodeoffset, name, &len);
if (!prop) if (!prop) {
return len; return len;
}
proplen = sizeof (*prop) + FDT_TAGALIGN (len); proplen = sizeof (*prop) + FDT_TAGALIGN (len);
return _fdt_splice_struct (fdt, prop, proplen, 0); return _fdt_splice_struct (fdt, prop, proplen, 0);
} }
int fdt_add_subnode_namelen(void *fdt, int parentoffset, int
const char *name, int namelen) fdt_add_subnode_namelen (
void *fdt,
int parentoffset,
const char *name,
int namelen
)
{ {
struct fdt_node_header *nh; struct fdt_node_header *nh;
int offset, nextoffset; int offset, nextoffset;
@ -357,10 +500,11 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
FDT_RW_CHECK_HEADER (fdt); FDT_RW_CHECK_HEADER (fdt);
offset = fdt_subnode_offset_namelen (fdt, parentoffset, name, namelen); offset = fdt_subnode_offset_namelen (fdt, parentoffset, name, namelen);
if (offset >= 0) if (offset >= 0) {
return -FDT_ERR_EXISTS; return -FDT_ERR_EXISTS;
else if (offset != -FDT_ERR_NOTFOUND) } else if (offset != -FDT_ERR_NOTFOUND) {
return offset; return offset;
}
/* Try to place the new node after the parent's properties */ /* Try to place the new node after the parent's properties */
fdt_next_tag (fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */ fdt_next_tag (fdt, parentoffset, &nextoffset); /* skip the BEGIN_NODE */
@ -373,8 +517,9 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
nodelen = sizeof (*nh) + FDT_TAGALIGN (namelen+1) + FDT_TAGSIZE; nodelen = sizeof (*nh) + FDT_TAGALIGN (namelen+1) + FDT_TAGSIZE;
err = _fdt_splice_struct (fdt, nh, 0, nodelen); err = _fdt_splice_struct (fdt, nh, 0, nodelen);
if (err) if (err) {
return err; return err;
}
nh->tag = cpu_to_fdt32 (FDT_BEGIN_NODE); nh->tag = cpu_to_fdt32 (FDT_BEGIN_NODE);
memset (nh->name, 0, FDT_TAGALIGN (namelen+1)); memset (nh->name, 0, FDT_TAGALIGN (namelen+1));
@ -385,27 +530,46 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,
return offset; return offset;
} }
int fdt_add_subnode(void *fdt, int parentoffset, const char *name) int
fdt_add_subnode (
void *fdt,
int parentoffset,
const char *name
)
{ {
return fdt_add_subnode_namelen (fdt, parentoffset, name, strlen (name)); return fdt_add_subnode_namelen (fdt, parentoffset, name, strlen (name));
} }
int fdt_del_node(void *fdt, int nodeoffset) int
fdt_del_node (
void *fdt,
int nodeoffset
)
{ {
int endoffset; int endoffset;
FDT_RW_CHECK_HEADER (fdt); FDT_RW_CHECK_HEADER (fdt);
endoffset = _fdt_node_end_offset (fdt, nodeoffset); endoffset = _fdt_node_end_offset (fdt, nodeoffset);
if (endoffset < 0) if (endoffset < 0) {
return endoffset; return endoffset;
return _fdt_splice_struct(fdt, _fdt_offset_ptr_w(fdt, nodeoffset),
endoffset - nodeoffset, 0);
} }
static void _fdt_packblocks(const char *old, char *new, return _fdt_splice_struct (
int mem_rsv_size, int struct_size) fdt,
_fdt_offset_ptr_w (fdt, nodeoffset),
endoffset - nodeoffset,
0
);
}
static void
_fdt_packblocks (
const char *old,
char *new,
int mem_rsv_size,
int struct_size
)
{ {
int mem_rsv_off, struct_off, strings_off; int mem_rsv_off, struct_off, strings_off;
@ -420,13 +584,21 @@ static void _fdt_packblocks(const char *old, char *new,
fdt_set_off_dt_struct (new, struct_off); fdt_set_off_dt_struct (new, struct_off);
fdt_set_size_dt_struct (new, struct_size); fdt_set_size_dt_struct (new, struct_size);
memmove(new + strings_off, old + fdt_off_dt_strings(old), memmove (
fdt_size_dt_strings(old)); new + strings_off,
old + fdt_off_dt_strings (old),
fdt_size_dt_strings (old)
);
fdt_set_off_dt_strings (new, strings_off); fdt_set_off_dt_strings (new, strings_off);
fdt_set_size_dt_strings (new, fdt_size_dt_strings (old)); fdt_set_size_dt_strings (new, fdt_size_dt_strings (old));
} }
int fdt_open_into(const void *fdt, void *buf, int bufsize) int
fdt_open_into (
const void *fdt,
void *buf,
int bufsize
)
{ {
int err; int err;
int mem_rsv_size, struct_size; int mem_rsv_size, struct_size;
@ -444,17 +616,21 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
struct_size = fdt_size_dt_struct (fdt); struct_size = fdt_size_dt_struct (fdt);
} else { } else {
struct_size = 0; struct_size = 0;
while (fdt_next_tag(fdt, struct_size, &struct_size) != FDT_END) while (fdt_next_tag (fdt, struct_size, &struct_size) != FDT_END) {
; }
if (struct_size < 0)
if (struct_size < 0) {
return struct_size; return struct_size;
} }
}
if (!_fdt_blocks_misordered (fdt, mem_rsv_size, struct_size)) { if (!_fdt_blocks_misordered (fdt, mem_rsv_size, struct_size)) {
/* no further work necessary */ /* no further work necessary */
err = fdt_move (fdt, buf, bufsize); err = fdt_move (fdt, buf, bufsize);
if (err) if (err) {
return err; return err;
}
fdt_set_version (buf, 17); fdt_set_version (buf, 17);
fdt_set_size_dt_struct (buf, struct_size); fdt_set_size_dt_struct (buf, struct_size);
fdt_set_totalsize (buf, bufsize); fdt_set_totalsize (buf, bufsize);
@ -465,8 +641,9 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
newsize = FDT_ALIGN (sizeof (struct fdt_header), 8) + mem_rsv_size newsize = FDT_ALIGN (sizeof (struct fdt_header), 8) + mem_rsv_size
+ struct_size + fdt_size_dt_strings (fdt); + struct_size + fdt_size_dt_strings (fdt);
if (bufsize < newsize) if (bufsize < newsize) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
/* First attempt to build converted tree at beginning of buffer */ /* First attempt to build converted tree at beginning of buffer */
tmp = buf; tmp = buf;
@ -474,9 +651,10 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) { if (((tmp + newsize) > fdtstart) && (tmp < fdtend)) {
/* Try right after the old tree instead */ /* Try right after the old tree instead */
tmp = (char *)(uintptr_t)fdtend; tmp = (char *)(uintptr_t)fdtend;
if ((tmp + newsize) > ((char *)buf + bufsize)) if ((tmp + newsize) > ((char *)buf + bufsize)) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
} }
}
_fdt_packblocks (fdt, tmp, mem_rsv_size, struct_size); _fdt_packblocks (fdt, tmp, mem_rsv_size, struct_size);
memmove (buf, tmp, newsize); memmove (buf, tmp, newsize);
@ -490,7 +668,10 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
return 0; return 0;
} }
int fdt_pack(void *fdt) int
fdt_pack (
void *fdt
)
{ {
int mem_rsv_size; int mem_rsv_size;

View File

@ -85,18 +85,22 @@ static struct fdt_errtabent fdt_errtable[] = {
}; };
#define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0])) #define FDT_ERRTABSIZE (sizeof(fdt_errtable) / sizeof(fdt_errtable[0]))
const char *fdt_strerror(int errval) const char *
fdt_strerror (
int errval
)
{ {
if (errval > 0) if (errval > 0) {
return "<valid offset/length>"; return "<valid offset/length>";
else if (errval == 0) } else if (errval == 0) {
return "<no error>"; return "<no error>";
else if (errval > -FDT_ERRTABSIZE) { } else if (errval > -FDT_ERRTABSIZE) {
const char *s = fdt_errtable[-errval].str; const char *s = fdt_errtable[-errval].str;
if (s) if (s) {
return s; return s;
} }
}
return "<unknown error>"; return "<unknown error>";
} }

View File

@ -9,7 +9,12 @@
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
unsigned long strtoul(const char *nptr, char **endptr, int base) unsigned long
strtoul (
const char *nptr,
char **endptr,
int base
)
{ {
RETURN_STATUS Status; RETURN_STATUS Status;
UINTN ReturnValue; UINTN ReturnValue;

View File

@ -55,10 +55,15 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
static int _fdt_sw_check_header(void *fdt) static int
_fdt_sw_check_header (
void *fdt
)
{ {
if (fdt_magic(fdt) != FDT_SW_MAGIC) if (fdt_magic (fdt) != FDT_SW_MAGIC) {
return -FDT_ERR_BADMAGIC; return -FDT_ERR_BADMAGIC;
}
/* FIXME: should check more details about the header state */ /* FIXME: should check more details about the header state */
return 0; return 0;
} }
@ -70,7 +75,11 @@ static int _fdt_sw_check_header(void *fdt)
return err; \ return err; \
} }
static void *_fdt_grab_space(void *fdt, size_t len) static void *
_fdt_grab_space (
void *fdt,
size_t len
)
{ {
int offset = fdt_size_dt_struct (fdt); int offset = fdt_size_dt_struct (fdt);
int spaceleft; int spaceleft;
@ -78,19 +87,25 @@ static void *_fdt_grab_space(void *fdt, size_t len)
spaceleft = fdt_totalsize (fdt) - fdt_off_dt_struct (fdt) spaceleft = fdt_totalsize (fdt) - fdt_off_dt_struct (fdt)
- fdt_size_dt_strings (fdt); - fdt_size_dt_strings (fdt);
if ((offset + len < offset) || (offset + len > spaceleft)) if ((offset + len < offset) || (offset + len > spaceleft)) {
return NULL; return NULL;
}
fdt_set_size_dt_struct (fdt, offset + len); fdt_set_size_dt_struct (fdt, offset + len);
return _fdt_offset_ptr_w (fdt, offset); return _fdt_offset_ptr_w (fdt, offset);
} }
int fdt_create(void *buf, int bufsize) int
fdt_create (
void *buf,
int bufsize
)
{ {
void *fdt = buf; void *fdt = buf;
if (bufsize < sizeof(struct fdt_header)) if (bufsize < sizeof (struct fdt_header)) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
memset (buf, 0, bufsize); memset (buf, 0, bufsize);
@ -99,15 +114,25 @@ int fdt_create(void *buf, int bufsize)
fdt_set_last_comp_version (fdt, FDT_FIRST_SUPPORTED_VERSION); fdt_set_last_comp_version (fdt, FDT_FIRST_SUPPORTED_VERSION);
fdt_set_totalsize (fdt, bufsize); fdt_set_totalsize (fdt, bufsize);
fdt_set_off_mem_rsvmap(fdt, FDT_ALIGN(sizeof(struct fdt_header), fdt_set_off_mem_rsvmap (
sizeof(struct fdt_reserve_entry))); fdt,
FDT_ALIGN (
sizeof (struct fdt_header),
sizeof (struct fdt_reserve_entry)
)
);
fdt_set_off_dt_struct (fdt, fdt_off_mem_rsvmap (fdt)); fdt_set_off_dt_struct (fdt, fdt_off_mem_rsvmap (fdt));
fdt_set_off_dt_strings (fdt, bufsize); fdt_set_off_dt_strings (fdt, bufsize);
return 0; return 0;
} }
int fdt_resize(void *fdt, void *buf, int bufsize) int
fdt_resize (
void *fdt,
void *buf,
int bufsize
)
{ {
size_t headsize, tailsize; size_t headsize, tailsize;
char *oldtail, *newtail; char *oldtail, *newtail;
@ -117,8 +142,9 @@ int fdt_resize(void *fdt, void *buf, int bufsize)
headsize = fdt_off_dt_struct (fdt); headsize = fdt_off_dt_struct (fdt);
tailsize = fdt_size_dt_strings (fdt); tailsize = fdt_size_dt_strings (fdt);
if ((headsize + tailsize) > bufsize) if ((headsize + tailsize) > bufsize) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
oldtail = (char *)fdt + fdt_totalsize (fdt) - tailsize; oldtail = (char *)fdt + fdt_totalsize (fdt) - tailsize;
newtail = (char *)buf + bufsize - tailsize; newtail = (char *)buf + bufsize - tailsize;
@ -139,19 +165,26 @@ int fdt_resize(void *fdt, void *buf, int bufsize)
return 0; return 0;
} }
int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) int
fdt_add_reservemap_entry (
void *fdt,
uint64_t addr,
uint64_t size
)
{ {
struct fdt_reserve_entry *re; struct fdt_reserve_entry *re;
int offset; int offset;
FDT_SW_CHECK_HEADER (fdt); FDT_SW_CHECK_HEADER (fdt);
if (fdt_size_dt_struct(fdt)) if (fdt_size_dt_struct (fdt)) {
return -FDT_ERR_BADSTATE; return -FDT_ERR_BADSTATE;
}
offset = fdt_off_dt_struct (fdt); offset = fdt_off_dt_struct (fdt);
if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) if ((offset + sizeof (*re)) > fdt_totalsize (fdt)) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
re = (struct fdt_reserve_entry *)((char *)fdt + offset); re = (struct fdt_reserve_entry *)((char *)fdt + offset);
re->address = cpu_to_fdt64 (addr); re->address = cpu_to_fdt64 (addr);
@ -162,12 +195,19 @@ int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size)
return 0; return 0;
} }
int fdt_finish_reservemap(void *fdt) int
fdt_finish_reservemap (
void *fdt
)
{ {
return fdt_add_reservemap_entry (fdt, 0, 0); return fdt_add_reservemap_entry (fdt, 0, 0);
} }
int fdt_begin_node(void *fdt, const char *name) int
fdt_begin_node (
void *fdt,
const char *name
)
{ {
struct fdt_node_header *nh; struct fdt_node_header *nh;
int namelen = strlen (name) + 1; int namelen = strlen (name) + 1;
@ -175,29 +215,38 @@ int fdt_begin_node(void *fdt, const char *name)
FDT_SW_CHECK_HEADER (fdt); FDT_SW_CHECK_HEADER (fdt);
nh = _fdt_grab_space (fdt, sizeof (*nh) + FDT_TAGALIGN (namelen)); nh = _fdt_grab_space (fdt, sizeof (*nh) + FDT_TAGALIGN (namelen));
if (! nh) if (!nh) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
nh->tag = cpu_to_fdt32 (FDT_BEGIN_NODE); nh->tag = cpu_to_fdt32 (FDT_BEGIN_NODE);
memcpy (nh->name, name, namelen); memcpy (nh->name, name, namelen);
return 0; return 0;
} }
int fdt_end_node(void *fdt) int
fdt_end_node (
void *fdt
)
{ {
fdt32_t *en; fdt32_t *en;
FDT_SW_CHECK_HEADER (fdt); FDT_SW_CHECK_HEADER (fdt);
en = _fdt_grab_space (fdt, FDT_TAGSIZE); en = _fdt_grab_space (fdt, FDT_TAGSIZE);
if (! en) if (!en) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
*en = cpu_to_fdt32 (FDT_END_NODE); *en = cpu_to_fdt32 (FDT_END_NODE);
return 0; return 0;
} }
static int _fdt_find_add_string(void *fdt, const char *s) static int
_fdt_find_add_string (
void *fdt,
const char *s
)
{ {
char *strtab = (char *)fdt + fdt_totalsize (fdt); char *strtab = (char *)fdt + fdt_totalsize (fdt);
const char *p; const char *p;
@ -206,21 +255,29 @@ static int _fdt_find_add_string(void *fdt, const char *s)
int struct_top, offset; int struct_top, offset;
p = _fdt_find_string (strtab - strtabsize, strtabsize, s); p = _fdt_find_string (strtab - strtabsize, strtabsize, s);
if (p) if (p) {
return p - strtab; return p - strtab;
}
/* Add it */ /* Add it */
offset = -strtabsize - len; offset = -strtabsize - len;
struct_top = fdt_off_dt_struct (fdt) + fdt_size_dt_struct (fdt); struct_top = fdt_off_dt_struct (fdt) + fdt_size_dt_struct (fdt);
if (fdt_totalsize(fdt) + offset < struct_top) if (fdt_totalsize (fdt) + offset < struct_top) {
return 0; /* no more room :( */ return 0; /* no more room :( */
}
memcpy (strtab + offset, s, len); memcpy (strtab + offset, s, len);
fdt_set_size_dt_strings (fdt, strtabsize + len); fdt_set_size_dt_strings (fdt, strtabsize + len);
return offset; return offset;
} }
int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp) int
fdt_property_placeholder (
void *fdt,
const char *name,
int len,
void **valp
)
{ {
struct fdt_property *prop; struct fdt_property *prop;
int nameoff; int nameoff;
@ -228,12 +285,14 @@ int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp)
FDT_SW_CHECK_HEADER (fdt); FDT_SW_CHECK_HEADER (fdt);
nameoff = _fdt_find_add_string (fdt, name); nameoff = _fdt_find_add_string (fdt, name);
if (nameoff == 0) if (nameoff == 0) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
prop = _fdt_grab_space (fdt, sizeof (*prop) + FDT_TAGALIGN (len)); prop = _fdt_grab_space (fdt, sizeof (*prop) + FDT_TAGALIGN (len));
if (! prop) if (!prop) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
prop->tag = cpu_to_fdt32 (FDT_PROP); prop->tag = cpu_to_fdt32 (FDT_PROP);
prop->nameoff = cpu_to_fdt32 (nameoff); prop->nameoff = cpu_to_fdt32 (nameoff);
@ -242,19 +301,30 @@ int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp)
return 0; return 0;
} }
int fdt_property(void *fdt, const char *name, const void *val, int len) int
fdt_property (
void *fdt,
const char *name,
const void *val,
int len
)
{ {
void *ptr; void *ptr;
int ret; int ret;
ret = fdt_property_placeholder (fdt, name, len, &ptr); ret = fdt_property_placeholder (fdt, name, len, &ptr);
if (ret) if (ret) {
return ret; return ret;
}
memcpy (ptr, val, len); memcpy (ptr, val, len);
return 0; return 0;
} }
int fdt_finish(void *fdt) int
fdt_finish (
void *fdt
)
{ {
char *p = (char *)fdt; char *p = (char *)fdt;
fdt32_t *end; fdt32_t *end;
@ -266,8 +336,10 @@ int fdt_finish(void *fdt)
/* Add terminator */ /* Add terminator */
end = _fdt_grab_space (fdt, sizeof (*end)); end = _fdt_grab_space (fdt, sizeof (*end));
if (! end) if (!end) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
*end = cpu_to_fdt32 (FDT_END); *end = cpu_to_fdt32 (FDT_END);
/* Relocate the string table */ /* Relocate the string table */
@ -288,10 +360,13 @@ int fdt_finish(void *fdt)
nameoff += fdt_size_dt_strings (fdt); nameoff += fdt_size_dt_strings (fdt);
prop->nameoff = cpu_to_fdt32 (nameoff); prop->nameoff = cpu_to_fdt32 (nameoff);
} }
offset = nextoffset; offset = nextoffset;
} }
if (nextoffset < 0)
if (nextoffset < 0) {
return nextoffset; return nextoffset;
}
/* Finally, adjust the header */ /* Finally, adjust the header */
fdt_set_totalsize (fdt, newstroffset + fdt_size_dt_strings (fdt)); fdt_set_totalsize (fdt, newstroffset + fdt_size_dt_strings (fdt));

View File

@ -55,85 +55,135 @@
#include "libfdt_internal.h" #include "libfdt_internal.h"
int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, int
const char *name, int namelen, fdt_setprop_inplace_namelen_partial (
uint32_t idx, const void *val, void *fdt,
int len) int nodeoffset,
const char *name,
int namelen,
uint32_t idx,
const void *val,
int len
)
{ {
void *propval; void *propval;
int proplen; int proplen;
propval = fdt_getprop_namelen_w(fdt, nodeoffset, name, namelen, propval = fdt_getprop_namelen_w (
&proplen); fdt,
if (!propval) nodeoffset,
name,
namelen,
&proplen
);
if (!propval) {
return proplen; return proplen;
}
if (proplen < (len + idx)) if (proplen < (len + idx)) {
return -FDT_ERR_NOSPACE; return -FDT_ERR_NOSPACE;
}
memcpy ((char *)propval + idx, val, len); memcpy ((char *)propval + idx, val, len);
return 0; return 0;
} }
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name, int
const void *val, int len) fdt_setprop_inplace (
void *fdt,
int nodeoffset,
const char *name,
const void *val,
int len
)
{ {
const void *propval; const void *propval;
int proplen; int proplen;
propval = fdt_getprop (fdt, nodeoffset, name, &proplen); propval = fdt_getprop (fdt, nodeoffset, name, &proplen);
if (!propval) if (!propval) {
return proplen; return proplen;
if (proplen != len)
return -FDT_ERR_NOSPACE;
return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
strlen(name), 0,
val, len);
} }
static void _fdt_nop_region(void *start, int len) if (proplen != len) {
return -FDT_ERR_NOSPACE;
}
return fdt_setprop_inplace_namelen_partial (
fdt,
nodeoffset,
name,
strlen (name),
0,
val,
len
);
}
static void
_fdt_nop_region (
void *start,
int len
)
{ {
fdt32_t *p; fdt32_t *p;
for (p = start; (char *)p < ((char *)start + len); p++) for (p = start; (char *)p < ((char *)start + len); p++) {
*p = cpu_to_fdt32 (FDT_NOP); *p = cpu_to_fdt32 (FDT_NOP);
} }
}
int fdt_nop_property(void *fdt, int nodeoffset, const char *name) int
fdt_nop_property (
void *fdt,
int nodeoffset,
const char *name
)
{ {
struct fdt_property *prop; struct fdt_property *prop;
int len; int len;
prop = fdt_get_property_w (fdt, nodeoffset, name, &len); prop = fdt_get_property_w (fdt, nodeoffset, name, &len);
if (!prop) if (!prop) {
return len; return len;
}
_fdt_nop_region (prop, len + sizeof (*prop)); _fdt_nop_region (prop, len + sizeof (*prop));
return 0; return 0;
} }
int _fdt_node_end_offset(void *fdt, int offset) int
_fdt_node_end_offset (
void *fdt,
int offset
)
{ {
int depth = 0; int depth = 0;
while ((offset >= 0) && (depth >= 0)) while ((offset >= 0) && (depth >= 0)) {
offset = fdt_next_node (fdt, offset, &depth); offset = fdt_next_node (fdt, offset, &depth);
}
return offset; return offset;
} }
int fdt_nop_node(void *fdt, int nodeoffset) int
fdt_nop_node (
void *fdt,
int nodeoffset
)
{ {
int endoffset; int endoffset;
endoffset = _fdt_node_end_offset (fdt, nodeoffset); endoffset = _fdt_node_end_offset (fdt, nodeoffset);
if (endoffset < 0) if (endoffset < 0) {
return endoffset; return endoffset;
}
_fdt_nop_region(fdt_offset_ptr_w(fdt, nodeoffset, 0), _fdt_nop_region (
endoffset - nodeoffset); fdt_offset_ptr_w (fdt, nodeoffset, 0),
endoffset - nodeoffset
);
return 0; return 0;
} }

View File

@ -1,5 +1,6 @@
#ifndef _LIBFDT_INTERNAL_H #ifndef _LIBFDT_INTERNAL_H
#define _LIBFDT_INTERNAL_H #define _LIBFDT_INTERNAL_H
/* /*
* libfdt - Flat Device Tree manipulation * libfdt - Flat Device Tree manipulation
* Copyright (C) 2006 David Gibson, IBM Corporation. * Copyright (C) 2006 David Gibson, IBM Corporation.
@ -62,22 +63,54 @@
return __err; \ return __err; \
} }
int _fdt_check_node_offset(const void *fdt, int offset); int
int _fdt_check_prop_offset(const void *fdt, int offset); _fdt_check_node_offset (
const char *_fdt_find_string(const char *strtab, int tabsize, const char *s); const void *fdt,
int _fdt_node_end_offset(void *fdt, int nodeoffset); int offset
);
static inline const void *_fdt_offset_ptr(const void *fdt, int offset) int
_fdt_check_prop_offset (
const void *fdt,
int offset
);
const char *
_fdt_find_string (
const char *strtab,
int tabsize,
const char *s
);
int
_fdt_node_end_offset (
void *fdt,
int nodeoffset
);
static inline const void *
_fdt_offset_ptr (
const void *fdt,
int offset
)
{ {
return (const char *)fdt + fdt_off_dt_struct (fdt) + offset; return (const char *)fdt + fdt_off_dt_struct (fdt) + offset;
} }
static inline void *_fdt_offset_ptr_w(void *fdt, int offset) static inline void *
_fdt_offset_ptr_w (
void *fdt,
int offset
)
{ {
return (void *)(uintptr_t)_fdt_offset_ptr (fdt, offset); return (void *)(uintptr_t)_fdt_offset_ptr (fdt, offset);
} }
static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int n) static inline const struct fdt_reserve_entry *
_fdt_mem_rsv (
const void *fdt,
int n
)
{ {
const struct fdt_reserve_entry *rsv_table = const struct fdt_reserve_entry *rsv_table =
(const struct fdt_reserve_entry *) (const struct fdt_reserve_entry *)
@ -85,7 +118,12 @@ static inline const struct fdt_reserve_entry *_fdt_mem_rsv(const void *fdt, int
return rsv_table + n; return rsv_table + n;
} }
static inline struct fdt_reserve_entry *_fdt_mem_rsv_w(void *fdt, int n)
static inline struct fdt_reserve_entry *
_fdt_mem_rsv_w (
void *fdt,
int n
)
{ {
return (void *)(uintptr_t)_fdt_mem_rsv (fdt, n); return (void *)(uintptr_t)_fdt_mem_rsv (fdt, n);
} }

View File

@ -16,7 +16,6 @@
#include <Protocol/DebugPort.h> #include <Protocol/DebugPort.h>
EFI_DEBUGPORT_PROTOCOL *gDebugPort = NULL; EFI_DEBUGPORT_PROTOCOL *gDebugPort = NULL;
UINTN gTimeOut = 0; UINTN gTimeOut = 0;
@ -47,8 +46,6 @@ GdbSerialLibDebugPortConstructor (
return Status; return Status;
} }
/** /**
Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
data buts, and stop bits on a serial device. This call is optional as the serial data buts, and stop bits on a serial device. This call is optional as the serial
@ -83,7 +80,6 @@ GdbSerialInit (
return Status; return Status;
} }
/** /**
Check to see if a character is available from GDB. Do not read the character as that is Check to see if a character is available from GDB. Do not read the character as that is
done via GdbGetChar(). done via GdbGetChar().
@ -105,7 +101,6 @@ GdbIsCharAvailable (
return (Status == EFI_SUCCESS ? TRUE : FALSE); return (Status == EFI_SUCCESS ? TRUE : FALSE);
} }
/** /**
Get a character from GDB. This function must be able to run in interrupt context. Get a character from GDB. This function must be able to run in interrupt context.
@ -130,7 +125,6 @@ GdbGetChar (
return Char; return Char;
} }
/** /**
Send a character to GDB. This function must be able to run in interrupt context. Send a character to GDB. This function must be able to run in interrupt context.
@ -138,7 +132,6 @@ GdbGetChar (
@param Char Send a character to GDB @param Char Send a character to GDB
**/ **/
VOID VOID
EFIAPI EFIAPI
GdbPutChar ( GdbPutChar (
@ -163,7 +156,6 @@ GdbPutChar (
@param String Send a string to GDB @param String Send a string to GDB
**/ **/
VOID VOID
GdbPutString ( GdbPutString (
IN CHAR8 *String IN CHAR8 *String
@ -175,7 +167,3 @@ GdbPutString (
String++; String++;
} }
} }

View File

@ -13,7 +13,6 @@
#include <Library/IoLib.h> #include <Library/IoLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
// --------------------------------------------- // ---------------------------------------------
// UART Register Offsets // UART Register Offsets
// --------------------------------------------- // ---------------------------------------------
@ -40,12 +39,9 @@
#define ENABLE_FIFO 0x01U #define ENABLE_FIFO 0x01U
#define CLEAR_FIFOS 0x06U #define CLEAR_FIFOS 0x06U
// IO Port Base for the UART // IO Port Base for the UART
UINTN gPort; UINTN gPort;
/** /**
The constructor function initializes the UART. The constructor function initializes the UART.
@ -77,8 +73,6 @@ GdbSerialLibConstructor (
return GdbSerialInit (BaudRate, Parity, DataBits, StopBits); return GdbSerialInit (BaudRate, Parity, DataBits, StopBits);
} }
/** /**
Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
data buts, and stop bits on a serial device. This call is optional as the serial data buts, and stop bits on a serial device. This call is optional as the serial
@ -138,7 +132,6 @@ GdbSerialInit (
IoWrite8 (gPort + BAUD_HIGH_OFFSET, (UINT8)(Divisor >> 8)); IoWrite8 (gPort + BAUD_HIGH_OFFSET, (UINT8)(Divisor >> 8));
IoWrite8 (gPort + BAUD_LOW_OFFSET, (UINT8)(Divisor & 0xff)); IoWrite8 (gPort + BAUD_LOW_OFFSET, (UINT8)(Divisor & 0xff));
// //
// Switch back to bank 0 // Switch back to bank 0
// //
@ -149,12 +142,10 @@ GdbSerialInit (
// We probably need the FIFO enabled to not drop input // We probably need the FIFO enabled to not drop input
IoWrite8 (gPort + FCR_SHADOW_OFFSET, ENABLE_FIFO); IoWrite8 (gPort + FCR_SHADOW_OFFSET, ENABLE_FIFO);
// Configure the UART hardware here // Configure the UART hardware here
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
/** /**
Check to see if a character is available from GDB. Do not read the character as that is Check to see if a character is available from GDB. Do not read the character as that is
done via GdbGetChar(). done via GdbGetChar().
@ -176,7 +167,6 @@ GdbIsCharAvailable (
return ((Data & LSR_RXDA) == LSR_RXDA); return ((Data & LSR_RXDA) == LSR_RXDA);
} }
/** /**
Get a character from GDB. This function must be able to run in interrupt context. Get a character from GDB. This function must be able to run in interrupt context.
@ -204,7 +194,6 @@ GdbGetChar (
return Char; return Char;
} }
/** /**
Send a character to GDB. This function must be able to run in interrupt context. Send a character to GDB. This function must be able to run in interrupt context.
@ -212,7 +201,6 @@ GdbGetChar (
@param Char Send a character to GDB @param Char Send a character to GDB
**/ **/
VOID VOID
EFIAPI EFIAPI
GdbPutChar ( GdbPutChar (
@ -239,7 +227,6 @@ GdbPutChar (
@param String Send a string to GDB @param String Send a string to GDB
**/ **/
VOID VOID
GdbPutString ( GdbPutString (
IN CHAR8 *String IN CHAR8 *String

View File

@ -29,7 +29,6 @@ typedef struct {
BOOLEAN DoubleBuffer; BOOLEAN DoubleBuffer;
} MAP_INFO_INSTANCE; } MAP_INFO_INSTANCE;
typedef struct { typedef struct {
LIST_ENTRY Link; LIST_ENTRY Link;
VOID *HostAddress; VOID *HostAddress;
@ -95,6 +94,7 @@ InternalAllocateAlignedPages (
if (Pages == 0) { if (Pages == 0) {
return NULL; return NULL;
} }
if (Alignment > EFI_PAGE_SIZE) { if (Alignment > EFI_PAGE_SIZE) {
// //
// Calculate the total number of pages since alignment is larger than page // Calculate the total number of pages since alignment is larger than page
@ -109,11 +109,16 @@ InternalAllocateAlignedPages (
ASSERT (RealPages > Pages); ASSERT (RealPages > Pages);
Memory = mDmaHostAddressLimit; Memory = mDmaHostAddressLimit;
Status = gBS->AllocatePages (AllocateMaxAddress, MemoryType, RealPages, Status = gBS->AllocatePages (
&Memory); AllocateMaxAddress,
MemoryType,
RealPages,
&Memory
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
AlignedMemory = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask; AlignedMemory = ((UINTN)Memory + AlignmentMask) & ~AlignmentMask;
UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory); UnalignedPages = EFI_SIZE_TO_PAGES (AlignedMemory - (UINTN)Memory);
if (UnalignedPages > 0) { if (UnalignedPages > 0) {
@ -123,6 +128,7 @@ InternalAllocateAlignedPages (
Status = gBS->FreePages (Memory, UnalignedPages); Status = gBS->FreePages (Memory, UnalignedPages);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
} }
Memory = AlignedMemory + EFI_PAGES_TO_SIZE (Pages); Memory = AlignedMemory + EFI_PAGES_TO_SIZE (Pages);
UnalignedPages = RealPages - Pages - UnalignedPages; UnalignedPages = RealPages - Pages - UnalignedPages;
if (UnalignedPages > 0) { if (UnalignedPages > 0) {
@ -137,13 +143,19 @@ InternalAllocateAlignedPages (
// Do not over-allocate pages in this case. // Do not over-allocate pages in this case.
// //
Memory = mDmaHostAddressLimit; Memory = mDmaHostAddressLimit;
Status = gBS->AllocatePages (AllocateMaxAddress, MemoryType, Pages, Status = gBS->AllocatePages (
&Memory); AllocateMaxAddress,
MemoryType,
Pages,
&Memory
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return NULL; return NULL;
} }
AlignedMemory = (UINTN)Memory; AlignedMemory = (UINTN)Memory;
} }
return (VOID *)AlignedMemory; return (VOID *)AlignedMemory;
} }
@ -190,10 +202,11 @@ DmaMap (
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
UINTN AllocSize; UINTN AllocSize;
if (HostAddress == NULL || if ((HostAddress == NULL) ||
NumberOfBytes == NULL || (NumberOfBytes == NULL) ||
DeviceAddress == NULL || (DeviceAddress == NULL) ||
Mapping == NULL ) { (Mapping == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -210,15 +223,16 @@ DmaMap (
} }
if (((UINTN)HostAddress + *NumberOfBytes) > mDmaHostAddressLimit) { if (((UINTN)HostAddress + *NumberOfBytes) > mDmaHostAddressLimit) {
if (Operation == MapOperationBusMasterCommonBuffer) { if (Operation == MapOperationBusMasterCommonBuffer) {
goto CommonBufferError; goto CommonBufferError;
} }
AllocSize = ALIGN_VALUE (*NumberOfBytes, mCpu->DmaBufferAlignment); AllocSize = ALIGN_VALUE (*NumberOfBytes, mCpu->DmaBufferAlignment);
Map->BufferAddress = InternalAllocateAlignedPages (EfiBootServicesData, Map->BufferAddress = InternalAllocateAlignedPages (
EfiBootServicesData,
EFI_SIZE_TO_PAGES (AllocSize), EFI_SIZE_TO_PAGES (AllocSize),
mCpu->DmaBufferAlignment); mCpu->DmaBufferAlignment
);
if (Map->BufferAddress == NULL) { if (Map->BufferAddress == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto FreeMapInfo; goto FreeMapInfo;
@ -227,14 +241,19 @@ DmaMap (
if (Operation == MapOperationBusMasterRead) { if (Operation == MapOperationBusMasterRead) {
CopyMem (Map->BufferAddress, (VOID *)(UINTN)HostAddress, *NumberOfBytes); CopyMem (Map->BufferAddress, (VOID *)(UINTN)HostAddress, *NumberOfBytes);
} }
mCpu->FlushDataCache (mCpu, (UINTN)Map->BufferAddress, AllocSize,
EfiCpuFlushTypeWriteBack); mCpu->FlushDataCache (
mCpu,
(UINTN)Map->BufferAddress,
AllocSize,
EfiCpuFlushTypeWriteBack
);
*DeviceAddress = HostToDeviceAddress (Map->BufferAddress); *DeviceAddress = HostToDeviceAddress (Map->BufferAddress);
} else if (Operation != MapOperationBusMasterRead && } else if ((Operation != MapOperationBusMasterRead) &&
((((UINTN)HostAddress & (mCpu->DmaBufferAlignment - 1)) != 0) || ((((UINTN)HostAddress & (mCpu->DmaBufferAlignment - 1)) != 0) ||
((*NumberOfBytes & (mCpu->DmaBufferAlignment - 1)) != 0))) { ((*NumberOfBytes & (mCpu->DmaBufferAlignment - 1)) != 0)))
{
// Get the cacheability of the region // Get the cacheability of the region
Status = gDS->GetMemorySpaceDescriptor ((UINTN)HostAddress, &GcdDescriptor); Status = gDS->GetMemorySpaceDescriptor ((UINTN)HostAddress, &GcdDescriptor);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -275,8 +294,12 @@ DmaMap (
// prevents them from being written back unexpectedly, potentially // prevents them from being written back unexpectedly, potentially
// overwriting the data we receive from the device. // overwriting the data we receive from the device.
// //
mCpu->FlushDataCache (mCpu, (UINTN)Buffer, *NumberOfBytes, mCpu->FlushDataCache (
EfiCpuFlushTypeWriteBack); mCpu,
(UINTN)Buffer,
*NumberOfBytes,
EfiCpuFlushTypeWriteBack
);
} else { } else {
Map->DoubleBuffer = FALSE; Map->DoubleBuffer = FALSE;
} }
@ -295,15 +318,21 @@ DmaMap (
Status = gDS->GetMemorySpaceDescriptor ((UINTN)HostAddress, &GcdDescriptor); Status = gDS->GetMemorySpaceDescriptor ((UINTN)HostAddress, &GcdDescriptor);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
ASSERT (Operation != MapOperationBusMasterCommonBuffer || ASSERT (
(GcdDescriptor.Attributes & (EFI_MEMORY_WB | EFI_MEMORY_WT)) == 0); Operation != MapOperationBusMasterCommonBuffer ||
(GcdDescriptor.Attributes & (EFI_MEMORY_WB | EFI_MEMORY_WT)) == 0
);
DEBUG_CODE_END (); DEBUG_CODE_END ();
// Flush the Data Cache (should not have any effect if the memory region is // Flush the Data Cache (should not have any effect if the memory region is
// uncached) // uncached)
mCpu->FlushDataCache (mCpu, (UINTN)HostAddress, *NumberOfBytes, mCpu->FlushDataCache (
EfiCpuFlushTypeWriteBackInvalidate); mCpu,
(UINTN)HostAddress,
*NumberOfBytes,
EfiCpuFlushTypeWriteBackInvalidate
);
} }
Map->HostAddress = (UINTN)HostAddress; Map->HostAddress = (UINTN)HostAddress;
@ -315,10 +344,13 @@ DmaMap (
return EFI_SUCCESS; return EFI_SUCCESS;
CommonBufferError: CommonBufferError:
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"%a: Operation type 'MapOperationBusMasterCommonBuffer' is only " "%a: Operation type 'MapOperationBusMasterCommonBuffer' is only "
"supported\non memory regions that were allocated using " "supported\non memory regions that were allocated using "
"DmaAllocateBuffer ()\n", __FUNCTION__)); "DmaAllocateBuffer ()\n",
__FUNCTION__
));
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
FreeMapInfo: FreeMapInfo:
FreePool (Map); FreePool (Map);
@ -326,7 +358,6 @@ FreeMapInfo:
return Status; return Status;
} }
/** /**
Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or Completes the DmaMapBusMasterRead(), DmaMapBusMasterWrite(), or
DmaMapBusMasterCommonBuffer() operation and releases any corresponding DmaMapBusMasterCommonBuffer() operation and releases any corresponding
@ -363,14 +394,21 @@ DmaUnmap (
if (((UINTN)Map->HostAddress + Map->NumberOfBytes) > mDmaHostAddressLimit) { if (((UINTN)Map->HostAddress + Map->NumberOfBytes) > mDmaHostAddressLimit) {
AllocSize = ALIGN_VALUE (Map->NumberOfBytes, mCpu->DmaBufferAlignment); AllocSize = ALIGN_VALUE (Map->NumberOfBytes, mCpu->DmaBufferAlignment);
if (Map->Operation == MapOperationBusMasterWrite) { if (Map->Operation == MapOperationBusMasterWrite) {
mCpu->FlushDataCache (mCpu, (UINTN)Map->BufferAddress, AllocSize, mCpu->FlushDataCache (
EfiCpuFlushTypeInvalidate); mCpu,
CopyMem ((VOID *)(UINTN)Map->HostAddress, Map->BufferAddress, (UINTN)Map->BufferAddress,
Map->NumberOfBytes); AllocSize,
EfiCpuFlushTypeInvalidate
);
CopyMem (
(VOID *)(UINTN)Map->HostAddress,
Map->BufferAddress,
Map->NumberOfBytes
);
} }
FreePages (Map->BufferAddress, EFI_SIZE_TO_PAGES (AllocSize)); FreePages (Map->BufferAddress, EFI_SIZE_TO_PAGES (AllocSize));
} else if (Map->DoubleBuffer) { } else if (Map->DoubleBuffer) {
ASSERT (Map->Operation == MapOperationBusMasterWrite); ASSERT (Map->Operation == MapOperationBusMasterWrite);
if (Map->Operation != MapOperationBusMasterWrite) { if (Map->Operation != MapOperationBusMasterWrite) {
@ -378,8 +416,12 @@ DmaUnmap (
} else { } else {
Buffer = ALIGN_POINTER (Map->BufferAddress, mCpu->DmaBufferAlignment); Buffer = ALIGN_POINTER (Map->BufferAddress, mCpu->DmaBufferAlignment);
mCpu->FlushDataCache (mCpu, (UINTN)Buffer, Map->NumberOfBytes, mCpu->FlushDataCache (
EfiCpuFlushTypeInvalidate); mCpu,
(UINTN)Buffer,
Map->NumberOfBytes,
EfiCpuFlushTypeInvalidate
);
CopyMem ((VOID *)(UINTN)Map->HostAddress, Buffer, Map->NumberOfBytes); CopyMem ((VOID *)(UINTN)Map->HostAddress, Buffer, Map->NumberOfBytes);
@ -390,8 +432,12 @@ DmaUnmap (
// //
// Make sure we read buffer from uncached memory and not the cache // Make sure we read buffer from uncached memory and not the cache
// //
mCpu->FlushDataCache (mCpu, Map->HostAddress, Map->NumberOfBytes, mCpu->FlushDataCache (
EfiCpuFlushTypeInvalidate); mCpu,
Map->HostAddress,
Map->NumberOfBytes,
EfiCpuFlushTypeInvalidate
);
} }
} }
@ -462,13 +508,15 @@ DmaAllocateAlignedBuffer (
Alignment = EFI_PAGE_SIZE; Alignment = EFI_PAGE_SIZE;
} }
if (HostAddress == NULL || if ((HostAddress == NULL) ||
(Alignment & (Alignment - 1)) != 0) { ((Alignment & (Alignment - 1)) != 0))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (MemoryType == EfiBootServicesData || if ((MemoryType == EfiBootServicesData) ||
MemoryType == EfiRuntimeServicesData) { (MemoryType == EfiRuntimeServicesData))
{
Allocation = InternalAllocateAlignedPages (MemoryType, Pages, Alignment); Allocation = InternalAllocateAlignedPages (MemoryType, Pages, Alignment);
} else { } else {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -506,17 +554,21 @@ DmaAllocateAlignedBuffer (
InsertHeadList (&UncachedAllocationList, &Alloc->Link); InsertHeadList (&UncachedAllocationList, &Alloc->Link);
// Remap the region with the new attributes // Remap the region with the new attributes
Status = gDS->SetMemorySpaceAttributes ((PHYSICAL_ADDRESS)(UINTN)Allocation, Status = gDS->SetMemorySpaceAttributes (
(PHYSICAL_ADDRESS)(UINTN)Allocation,
EFI_PAGES_TO_SIZE (Pages), EFI_PAGES_TO_SIZE (Pages),
MemType); MemType
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeAlloc; goto FreeAlloc;
} }
Status = mCpu->FlushDataCache (mCpu, Status = mCpu->FlushDataCache (
mCpu,
(PHYSICAL_ADDRESS)(UINTN)Allocation, (PHYSICAL_ADDRESS)(UINTN)Allocation,
EFI_PAGES_TO_SIZE (Pages), EFI_PAGES_TO_SIZE (Pages),
EfiCpuFlushTypeInvalidate); EfiCpuFlushTypeInvalidate
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeAlloc; goto FreeAlloc;
} }
@ -534,7 +586,6 @@ FreeBuffer:
return Status; return Status;
} }
/** /**
Frees memory that was allocated with DmaAllocateBuffer(). Frees memory that was allocated with DmaAllocateBuffer().
@ -566,10 +617,10 @@ DmaFreeBuffer (
for (Link = GetFirstNode (&UncachedAllocationList), Found = FALSE; for (Link = GetFirstNode (&UncachedAllocationList), Found = FALSE;
!IsNull (&UncachedAllocationList, Link); !IsNull (&UncachedAllocationList, Link);
Link = GetNextNode (&UncachedAllocationList, Link)) { Link = GetNextNode (&UncachedAllocationList, Link))
{
Alloc = BASE_CR (Link, UNCACHED_ALLOCATION, Link); Alloc = BASE_CR (Link, UNCACHED_ALLOCATION, Link);
if (Alloc->HostAddress == HostAddress && Alloc->NumPages == Pages) { if ((Alloc->HostAddress == HostAddress) && (Alloc->NumPages == Pages)) {
Found = TRUE; Found = TRUE;
break; break;
} }
@ -582,9 +633,11 @@ DmaFreeBuffer (
RemoveEntryList (&Alloc->Link); RemoveEntryList (&Alloc->Link);
Status = gDS->SetMemorySpaceAttributes ((PHYSICAL_ADDRESS)(UINTN)HostAddress, Status = gDS->SetMemorySpaceAttributes (
(PHYSICAL_ADDRESS)(UINTN)HostAddress,
EFI_PAGES_TO_SIZE (Pages), EFI_PAGES_TO_SIZE (Pages),
Alloc->Attributes); Alloc->Attributes
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto FreeAlloc; goto FreeAlloc;
} }
@ -600,7 +653,6 @@ FreeAlloc:
return Status; return Status;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
NonCoherentDmaLibConstructor ( NonCoherentDmaLibConstructor (

View File

@ -183,6 +183,7 @@ NorFlashGetInfo (
} else { } else {
*FlashInfo = AllocateCopyPool (sizeof (NOR_FLASH_INFO), TmpInfo); *FlashInfo = AllocateCopyPool (sizeof (NOR_FLASH_INFO), TmpInfo);
} }
if (FlashInfo == NULL) { if (FlashInfo == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -211,10 +212,12 @@ NorFlashPrintInfo (
EraseSize = Info->SectorSize; EraseSize = Info->SectorSize;
} }
DEBUG ((DEBUG_ERROR, DEBUG ((
DEBUG_ERROR,
"Detected %s SPI NOR flash with page size %d B, erase size %d KB, total %d MB\n", "Detected %s SPI NOR flash with page size %d B, erase size %d KB, total %d MB\n",
Info->Name, Info->Name,
Info->PageSize, Info->PageSize,
EraseSize / 1024, EraseSize / 1024,
(Info->SectorSize * Info->SectorCount) / 1024 / 1024)); (Info->SectorSize * Info->SectorCount) / 1024 / 1024
));
} }

View File

@ -46,6 +46,7 @@ ExtractGuidedSectionRegisterHandlers (
{ {
PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData; PRE_PI_EXTRACT_GUIDED_SECTION_DATA *SavedData;
UINT32 Index; UINT32 Index;
// //
// Check input parameter. // Check input parameter.
// //

View File

@ -44,8 +44,6 @@ GetHobList (
return PrePeiGetHobList (); return PrePeiGetHobList ();
} }
/** /**
Updates the pointer to the HOB list. Updates the pointer to the HOB list.
@ -177,7 +175,6 @@ BuildFvHobs (
IN EFI_RESOURCE_ATTRIBUTE_TYPE *ResourceAttribute IN EFI_RESOURCE_ATTRIBUTE_TYPE *ResourceAttribute
) )
{ {
EFI_RESOURCE_ATTRIBUTE_TYPE Resource; EFI_RESOURCE_ATTRIBUTE_TYPE Resource;
BuildFvHob (PhysicalStart, NumberOfBytes); BuildFvHob (PhysicalStart, NumberOfBytes);
@ -229,13 +226,13 @@ GetNextHob (
if (Hob.Header->HobType == Type) { if (Hob.Header->HobType == Type) {
return Hob.Raw; return Hob.Raw;
} }
Hob.Raw = GET_NEXT_HOB (Hob); Hob.Raw = GET_NEXT_HOB (Hob);
} }
return NULL; return NULL;
} }
/** /**
Returns the first instance of a HOB type among the whole HOB list. Returns the first instance of a HOB type among the whole HOB list.
@ -259,7 +256,6 @@ GetFirstHob (
return GetNextHob (Type, HobList); return GetNextHob (Type, HobList);
} }
/** /**
This function searches the first instance of a HOB from the starting HOB pointer. This function searches the first instance of a HOB from the starting HOB pointer.
Such HOB should satisfy two conditions: Such HOB should satisfy two conditions:
@ -284,7 +280,8 @@ EFIAPI
GetNextGuidHob ( GetNextGuidHob (
IN CONST EFI_GUID *Guid, IN CONST EFI_GUID *Guid,
IN CONST VOID *HobStart IN CONST VOID *HobStart
){ )
{
EFI_PEI_HOB_POINTERS GuidHob; EFI_PEI_HOB_POINTERS GuidHob;
GuidHob.Raw = (UINT8 *)HobStart; GuidHob.Raw = (UINT8 *)HobStart;
@ -292,12 +289,13 @@ GetNextGuidHob (
if (CompareGuid (Guid, &GuidHob.Guid->Name)) { if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
break; break;
} }
GuidHob.Raw = GET_NEXT_HOB (GuidHob); GuidHob.Raw = GET_NEXT_HOB (GuidHob);
} }
return GuidHob.Raw; return GuidHob.Raw;
} }
/** /**
This function searches the first instance of a HOB among the whole HOB list. This function searches the first instance of a HOB among the whole HOB list.
Such HOB should satisfy two conditions: Such HOB should satisfy two conditions:
@ -324,7 +322,6 @@ GetFirstGuidHob (
return GetNextGuidHob (Guid, HobList); return GetNextGuidHob (Guid, HobList);
} }
/** /**
Get the Boot Mode from the HOB list. Get the Boot Mode from the HOB list.
@ -348,7 +345,6 @@ GetBootMode (
return Hob.HandoffInformationTable->BootMode; return Hob.HandoffInformationTable->BootMode;
} }
/** /**
Get the Boot Mode from the HOB list. Get the Boot Mode from the HOB list.
@ -399,8 +395,10 @@ BuildModuleHob (
{ {
EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob; EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) && ASSERT (
((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0)); ((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&
((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0)
);
Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE)); Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
@ -455,7 +453,6 @@ BuildGuidHob (
return Hob + 1; return Hob + 1;
} }
/** /**
Copies a data buffer to a newly-built HOB. Copies a data buffer to a newly-built HOB.
@ -493,7 +490,6 @@ BuildGuidDataHob (
return CopyMem (HobData, Data, DataLength); return CopyMem (HobData, Data, DataLength);
} }
/** /**
Builds a Firmware Volume HOB. Builds a Firmware Volume HOB.
@ -521,7 +517,6 @@ BuildFvHob (
Hob->Length = Length; Hob->Length = Length;
} }
/** /**
Builds a EFI_HOB_TYPE_FV2 HOB. Builds a EFI_HOB_TYPE_FV2 HOB.
@ -622,7 +617,6 @@ BuildCvHob (
ASSERT (FALSE); ASSERT (FALSE);
} }
/** /**
Builds a HOB for the CPU. Builds a HOB for the CPU.
@ -655,7 +649,6 @@ BuildCpuHob (
ZeroMem (Hob->Reserved, sizeof (Hob->Reserved)); ZeroMem (Hob->Reserved, sizeof (Hob->Reserved));
} }
/** /**
Builds a HOB for the Stack. Builds a HOB for the Stack.
@ -677,8 +670,10 @@ BuildStackHob (
{ {
EFI_HOB_MEMORY_ALLOCATION_STACK *Hob; EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;
ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) && ASSERT (
((Length & (EFI_PAGE_SIZE - 1)) == 0)); ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
((Length & (EFI_PAGE_SIZE - 1)) == 0)
);
Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK)); Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
@ -693,7 +688,6 @@ BuildStackHob (
ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved)); ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
} }
/** /**
Update the Stack Hob if the stack has been moved Update the Stack Hob if the stack has been moved
@ -728,12 +722,11 @@ UpdateStackHob (
Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length; Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;
break; break;
} }
Hob.Raw = GET_NEXT_HOB (Hob); Hob.Raw = GET_NEXT_HOB (Hob);
} }
} }
/** /**
Builds a HOB for the memory allocation. Builds a HOB for the memory allocation.
@ -757,8 +750,10 @@ BuildMemoryAllocationHob (
{ {
EFI_HOB_MEMORY_ALLOCATION *Hob; EFI_HOB_MEMORY_ALLOCATION *Hob;
ASSERT (((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) && ASSERT (
((Length & (EFI_PAGE_SIZE - 1)) == 0)); ((BaseAddress & (EFI_PAGE_SIZE - 1)) == 0) &&
((Length & (EFI_PAGE_SIZE - 1)) == 0)
);
Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION)); Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof (EFI_HOB_MEMORY_ALLOCATION));
@ -772,8 +767,6 @@ BuildMemoryAllocationHob (
ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved)); ZeroMem (Hob->AllocDescriptor.Reserved, sizeof (Hob->AllocDescriptor.Reserved));
} }
VOID VOID
EFIAPI EFIAPI
BuildExtractSectionHob ( BuildExtractSectionHob (
@ -798,8 +791,6 @@ PE_COFF_LOADER_PROTOCOL gPeCoffProtocol = {
PeCoffLoaderUnloadImage PeCoffLoaderUnloadImage
}; };
VOID VOID
EFIAPI EFIAPI
BuildPeCoffLoaderHob ( BuildPeCoffLoaderHob (
@ -843,6 +834,5 @@ BuildMemoryTypeInformationHob (
Info[9].Type = EfiMaxMemoryType; Info[9].Type = EfiMaxMemoryType;
Info[9].NumberOfPages = 0; Info[9].NumberOfPages = 0;
BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info)); BuildGuidDataHob (&gEfiMemoryTypeInformationGuid, &Info, sizeof (Info));
} }

View File

@ -12,11 +12,9 @@
#include <PrePi.h> #include <PrePi.h>
#include <Library/ExtractGuidedSectionLib.h> #include <Library/ExtractGuidedSectionLib.h>
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \ #define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
(ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)) (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))
/** /**
Returns the highest bit set of the State field Returns the highest bit set of the State field
@ -52,7 +50,6 @@ GetFileState(
return HighestBit; return HighestBit;
} }
/** /**
Calculates the checksum of the header of a file. Calculates the checksum of the header of a file.
The header is a zero byte checksum, so zero means header is good The header is a zero byte checksum, so zero means header is good
@ -98,7 +95,6 @@ CalculateHeaderChecksum (
return Sum; return Sum;
} }
/** /**
Given a FileHandle return the VolumeHandle Given a FileHandle return the VolumeHandle
@ -129,7 +125,8 @@ FileHandleToVolume (
if (Hob.Raw != NULL) { if (Hob.Raw != NULL) {
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(Hob.FirmwareVolume->BaseAddress); FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)(Hob.FirmwareVolume->BaseAddress);
if (((UINT64)(UINTN)FileHandle > (UINT64)(UINTN)FwVolHeader) && \ if (((UINT64)(UINTN)FileHandle > (UINT64)(UINTN)FwVolHeader) && \
((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) { ((UINT64)(UINTN)FileHandle <= ((UINT64)(UINTN)FwVolHeader + FwVolHeader->FvLength - 1)))
{
*VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader; *VolumeHandle = (EFI_PEI_FV_HANDLE)FwVolHeader;
return TRUE; return TRUE;
} }
@ -141,8 +138,6 @@ FileHandleToVolume (
return FALSE; return FALSE;
} }
/** /**
Given the input file pointer, search for the next matching file in the Given the input file pointer, search for the next matching file in the
FFS volume as defined by SearchType. The search starts from FileHeader inside FFS volume as defined by SearchType. The search starts from FileHeader inside
@ -216,7 +211,6 @@ FindFileEx (
FileState = GetFileState (ErasePolarity, FfsFileHeader); FileState = GetFileState (ErasePolarity, FfsFileHeader);
switch (FileState) { switch (FileState) {
case EFI_FILE_HEADER_INVALID: case EFI_FILE_HEADER_INVALID:
FileOffset += sizeof (EFI_FFS_FILE_HEADER); FileOffset += sizeof (EFI_FFS_FILE_HEADER);
FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER)); FfsFileHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));
@ -239,7 +233,8 @@ FindFileEx (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
} else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) && } else if (((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) &&
(FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD)) { (FfsFileHeader->Type != EFI_FV_FILETYPE_FFS_PAD))
{
*FileHeader = FfsFileHeader; *FileHeader = FfsFileHeader;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -261,12 +256,10 @@ FindFileEx (
} }
} }
*FileHeader = NULL; *FileHeader = NULL;
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
Go through the file to search SectionType section, Go through the file to search SectionType section,
when meeting an encapsuled section. when meeting an encapsuled section.
@ -300,7 +293,6 @@ FfsProcessSection (
CHAR8 *CompressedData; CHAR8 *CompressedData;
UINTN CompressedDataLength; UINTN CompressedDataLength;
*OutputBuffer = NULL; *OutputBuffer = NULL;
ParsedLength = 0; ParsedLength = 0;
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
@ -318,7 +310,6 @@ FfsProcessSection (
return EFI_SUCCESS; return EFI_SUCCESS;
} else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) { } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) {
if (Section->Type == EFI_SECTION_COMPRESSION) { if (Section->Type == EFI_SECTION_COMPRESSION) {
if (IS_SECTION2 (Section)) { if (IS_SECTION2 (Section)) {
CompressionSection2 = (EFI_COMPRESSION_SECTION2 *)Section; CompressionSection2 = (EFI_COMPRESSION_SECTION2 *)Section;
@ -364,6 +355,7 @@ FfsProcessSection (
DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status)); DEBUG ((DEBUG_ERROR, "Decompress GetInfo Failed - %r\n", Status));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// //
// Allocate scratch buffer // Allocate scratch buffer
// //
@ -371,6 +363,7 @@ FfsProcessSection (
if (ScratchBuffer == NULL) { if (ScratchBuffer == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
// //
// Allocate destination buffer, extra one page for adjustment // Allocate destination buffer, extra one page for adjustment
// //
@ -378,22 +371,24 @@ FfsProcessSection (
if (DstBuffer == NULL) { if (DstBuffer == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
// //
// DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header
// to make section data at page alignment. // to make section data at page alignment.
// //
if (IS_SECTION2 (Section)) if (IS_SECTION2 (Section)) {
DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER2); DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER2);
else } else {
DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER); DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER);
}
// //
// Call decompress function // Call decompress function
// //
if (Section->Type == EFI_SECTION_COMPRESSION) { if (Section->Type == EFI_SECTION_COMPRESSION) {
if (IS_SECTION2 (Section)) { if (IS_SECTION2 (Section)) {
CompressedData = (CHAR8 *)((EFI_COMPRESSION_SECTION2 *)Section + 1); CompressedData = (CHAR8 *)((EFI_COMPRESSION_SECTION2 *)Section + 1);
} } else {
else {
CompressedData = (CHAR8 *)((EFI_COMPRESSION_SECTION *)Section + 1); CompressedData = (CHAR8 *)((EFI_COMPRESSION_SECTION *)Section + 1);
} }
@ -432,6 +427,7 @@ FfsProcessSection (
} else { } else {
SectionLength = SECTION_SIZE (Section); SectionLength = SECTION_SIZE (Section);
} }
// //
// SectionLength is adjusted it is 4 byte aligned. // SectionLength is adjusted it is 4 byte aligned.
// Go to the next section // Go to the next section
@ -445,8 +441,6 @@ FfsProcessSection (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
This service enables discovery sections of a given type within a valid FFS file. This service enables discovery sections of a given type within a valid FFS file.
@ -490,11 +484,6 @@ FfsFindSectionData (
); );
} }
/** /**
This service enables discovery of additional firmware files. This service enables discovery of additional firmware files.
@ -519,7 +508,6 @@ FfsFindNextFile (
return FindFileEx (VolumeHandle, NULL, SearchType, FileHandle); return FindFileEx (VolumeHandle, NULL, SearchType, FileHandle);
} }
/** /**
This service enables discovery of additional firmware volumes. This service enables discovery of additional firmware volumes.
@ -540,7 +528,6 @@ FfsFindNextVolume (
{ {
EFI_PEI_HOB_POINTERS Hob; EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = GetHobList (); Hob.Raw = GetHobList ();
if (Hob.Raw == NULL) { if (Hob.Raw == NULL) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
@ -559,10 +546,8 @@ FfsFindNextVolume (
} while (Hob.Raw != NULL); } while (Hob.Raw != NULL);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
Find a file in the volume by name Find a file in the volume by name
@ -590,19 +575,19 @@ FfsFindFileByName (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) { if ((VolumeHandle == NULL) || (FileName == NULL) || (FileHandle == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Status = FindFileEx (VolumeHandle, FileName, 0, FileHandle); Status = FindFileEx (VolumeHandle, FileName, 0, FileHandle);
if (Status == EFI_NOT_FOUND) { if (Status == EFI_NOT_FOUND) {
*FileHandle = NULL; *FileHandle = NULL;
} }
return Status; return Status;
} }
/** /**
Get information about the file by name. Get information about the file by name.
@ -671,7 +656,6 @@ FfsGetFileInfo (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Get Information about the volume by name Get Information about the volume by name
@ -714,6 +698,7 @@ FfsGetVolumeInfo (
if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) { if (FwVolHeader.Signature != EFI_FVH_SIGNATURE) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
VolumeInfo->FvAttributes = FwVolHeader.Attributes; VolumeInfo->FvAttributes = FwVolHeader.Attributes;
VolumeInfo->FvStart = (VOID *)VolumeHandle; VolumeInfo->FvStart = (VOID *)VolumeHandle;
VolumeInfo->FvSize = FwVolHeader.FvLength; VolumeInfo->FvSize = FwVolHeader.FvLength;
@ -723,11 +708,10 @@ FfsGetVolumeInfo (
FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset); FwVolExHeaderInfo = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)(((UINT8 *)VolumeHandle) + FwVolHeader.ExtHeaderOffset);
CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof (EFI_GUID)); CopyMem (&VolumeInfo->FvName, &FwVolExHeaderInfo->FvName, sizeof (EFI_GUID));
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Search through every FV until you find a file of type FileType Search through every FV until you find a file of type FileType
@ -756,17 +740,14 @@ FfsAnyFvFindFirstFile (
Instance = 0; Instance = 0;
*FileHandle = NULL; *FileHandle = NULL;
while (1) while (1) {
{
Status = FfsFindNextVolume (Instance++, VolumeHandle); Status = FfsFindNextVolume (Instance++, VolumeHandle);
if (EFI_ERROR (Status)) if (EFI_ERROR (Status)) {
{
break; break;
} }
Status = FfsFindNextFile (FileType, *VolumeHandle, FileHandle); Status = FfsFindNextFile (FileType, *VolumeHandle, FileHandle);
if (!EFI_ERROR (Status)) if (!EFI_ERROR (Status)) {
{
break; break;
} }
} }
@ -774,8 +755,6 @@ FfsAnyFvFindFirstFile (
return Status; return Status;
} }
/** /**
Get Fv image from the FV type file, then add FV & FV2 Hob. Get Fv image from the FV type file, then add FV & FV2 Hob.
@ -801,7 +780,6 @@ FfsProcessFvFile (
FvBuffer = NULL; FvBuffer = NULL;
// //
// Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
// been extracted. // been extracted.
@ -814,6 +792,7 @@ FfsProcessFvFile (
// //
return EFI_SUCCESS; return EFI_SUCCESS;
} }
HobFv2.Raw = GET_NEXT_HOB (HobFv2); HobFv2.Raw = GET_NEXT_HOB (HobFv2);
} }
@ -848,6 +827,7 @@ FfsProcessFvFile (
if (FvBuffer == NULL) { if (FvBuffer == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN)FvImageInfo.FvSize); CopyMem (FvBuffer, FvImageInfo.FvStart, (UINTN)FvImageInfo.FvSize);
// //
// Update FvImageInfo after reload FvImage to new aligned memory // Update FvImageInfo after reload FvImage to new aligned memory
@ -855,7 +835,6 @@ FfsProcessFvFile (
FfsGetVolumeInfo ((EFI_PEI_FV_HANDLE)FvBuffer, &FvImageInfo); FfsGetVolumeInfo ((EFI_PEI_FV_HANDLE)FvBuffer, &FvImageInfo);
} }
// //
// Inform HOB consumer phase, i.e. DXE core, the existence of this FV // Inform HOB consumer phase, i.e. DXE core, the existence of this FV
// //

View File

@ -26,7 +26,6 @@
#include <Guid/MemoryAllocationHob.h> #include <Guid/MemoryAllocationHob.h>
#define GET_HOB_TYPE(Hob) ((Hob).Header->HobType) #define GET_HOB_TYPE(Hob) ((Hob).Header->HobType)
#define GET_HOB_LENGTH(Hob) ((Hob).Header->HobLength) #define GET_HOB_LENGTH(Hob) ((Hob).Header->HobLength)
#define GET_NEXT_HOB(Hob) ((Hob).Raw + GET_HOB_LENGTH (Hob)) #define GET_NEXT_HOB(Hob) ((Hob).Raw + GET_HOB_LENGTH (Hob))

View File

@ -44,6 +44,7 @@ AllocateCodePages (
Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode; Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode;
return Alloc; return Alloc;
} }
Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (Hob)); Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (Hob));
} }
@ -53,7 +54,6 @@ AllocateCodePages (
return NULL; return NULL;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LoadPeCoffImage ( LoadPeCoffImage (
@ -75,14 +75,12 @@ LoadPeCoffImage (
Status = PeCoffLoaderGetImageInfo (&ImageContext); Status = PeCoffLoaderGetImageInfo (&ImageContext);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
// Allocate Memory for the image // Allocate Memory for the image
// //
Buffer = AllocateCodePages (EFI_SIZE_TO_PAGES ((UINT32)ImageContext.ImageSize)); Buffer = AllocateCodePages (EFI_SIZE_TO_PAGES ((UINT32)ImageContext.ImageSize));
ASSERT (Buffer != 0); ASSERT (Buffer != 0);
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer; ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
// //
@ -97,7 +95,6 @@ LoadPeCoffImage (
Status = PeCoffLoaderRelocateImage (&ImageContext); Status = PeCoffLoaderRelocateImage (&ImageContext);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
*ImageAddress = ImageContext.ImageAddress; *ImageAddress = ImageContext.ImageAddress;
*ImageSize = ImageContext.ImageSize; *ImageSize = ImageContext.ImageSize;
*EntryPoint = ImageContext.EntryPoint; *EntryPoint = ImageContext.EntryPoint;
@ -111,8 +108,6 @@ LoadPeCoffImage (
return Status; return Status;
} }
typedef typedef
VOID VOID
(EFIAPI *DXE_CORE_ENTRY_POINT)( (EFIAPI *DXE_CORE_ENTRY_POINT)(
@ -141,7 +136,6 @@ LoadDxeCoreFromFfsFile (
return Status; return Status;
} }
Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint); Status = LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);
// For NT32 Debug Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint); // For NT32 Debug Status = SecWinNtPeiLoadFile (PeCoffImage, &ImageAddress, &ImageSize, &EntryPoint);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -162,7 +156,6 @@ LoadDxeCoreFromFfsFile (
((DXE_CORE_ENTRY_POINT)(UINTN)EntryPoint)(Hob); ((DXE_CORE_ENTRY_POINT)(UINTN)EntryPoint)(Hob);
} else { } else {
// //
// Allocate 128KB for the Stack // Allocate 128KB for the Stack
// //
@ -187,7 +180,6 @@ LoadDxeCoreFromFfsFile (
NULL, NULL,
TopOfStack TopOfStack
); );
} }
// Should never get here as DXE Core does not return // Should never get here as DXE Core does not return
@ -197,8 +189,6 @@ LoadDxeCoreFromFfsFile (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LoadDxeCoreFromFv ( LoadDxeCoreFromFv (
@ -229,7 +219,6 @@ LoadDxeCoreFromFv (
return Status; return Status;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
DecompressFirstFv ( DecompressFirstFv (

View File

@ -14,8 +14,6 @@
#include <Library/PrePiLib.h> #include <Library/PrePiLib.h>
#include <Library/DebugLib.h> #include <Library/DebugLib.h>
/** /**
Allocates one or more 4KB pages of type EfiBootServicesData. Allocates one or more 4KB pages of type EfiBootServicesData.
@ -73,7 +71,6 @@ AllocatePages (
} }
} }
/** /**
Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment. Allocates one or more 4KB pages of type EfiBootServicesData at a specified alignment.
@ -108,6 +105,7 @@ AllocateAlignedPages (
if (Pages == 0) { if (Pages == 0) {
return NULL; return NULL;
} }
// //
// Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow.
// //
@ -121,10 +119,10 @@ AllocateAlignedPages (
} else { } else {
AlignmentMask = Alignment - 1; AlignmentMask = Alignment - 1;
} }
return (VOID *)(UINTN)(((UINTN)Memory + AlignmentMask) & ~AlignmentMask); return (VOID *)(UINTN)(((UINTN)Memory + AlignmentMask) & ~AlignmentMask);
} }
/** /**
Frees one or more 4KB pages that were previously allocated with one of the page allocation Frees one or more 4KB pages that were previously allocated with one of the page allocation
functions in the Memory Allocation Library. functions in the Memory Allocation Library.
@ -175,7 +173,6 @@ AllocatePool (
Hob = GetHobList (); Hob = GetHobList ();
// //
// Verify that there is sufficient memory to satisfy the allocation // Verify that there is sufficient memory to satisfy the allocation
// //
@ -183,10 +180,11 @@ AllocatePool (
// Please call AllocatePages for big allocations // Please call AllocatePages for big allocations
return 0; return 0;
} else { } else {
Hob = (EFI_HOB_MEMORY_POOL *)CreateHob (
Hob = (EFI_HOB_MEMORY_POOL *)CreateHob (EFI_HOB_TYPE_MEMORY_POOL, EFI_HOB_TYPE_MEMORY_POOL,
(UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) +
AllocationSize)); AllocationSize)
);
return (VOID *)(Hob + 1); return (VOID *)(Hob + 1);
} }
} }

View File

@ -15,7 +15,6 @@
#include <Library/IoLib.h> #include <Library/IoLib.h>
#include <Library/RealTimeClockLib.h> #include <Library/RealTimeClockLib.h>
/** /**
Returns the current time and date information, and the time-keeping capabilities Returns the current time and date information, and the time-keeping capabilities
of the hardware platform. of the hardware platform.
@ -42,7 +41,6 @@ LibGetTime (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
/** /**
Sets the current local time and date information. Sets the current local time and date information.
@ -65,7 +63,6 @@ LibSetTime (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
/** /**
Returns the current wakeup alarm clock setting. Returns the current wakeup alarm clock setting.
@ -90,7 +87,6 @@ LibGetWakeupTime (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
Sets the system wakeup alarm clock time. Sets the system wakeup alarm clock time.
@ -115,8 +111,6 @@ LibSetWakeupTime (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
This is the declaration of an EFI image entry point. This can be the entry point to an application This is the declaration of an EFI image entry point. This can be the entry point to an application
written to this specification, an EFI boot service driver, or an EFI runtime driver. written to this specification, an EFI boot service driver, or an EFI runtime driver.
@ -140,7 +134,6 @@ LibRtcInitialize (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Fixup internal data so that EFI can be call in virtual mode. Fixup internal data so that EFI can be call in virtual mode.
Call the passed in Child Notify event and convert any pointers in Call the passed in Child Notify event and convert any pointers in
@ -164,6 +157,3 @@ LibRtcVirtualNotifyEvent (
// //
return; return;
} }

View File

@ -10,14 +10,12 @@
**/ **/
#include <PiDxe.h> #include <PiDxe.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/IoLib.h> #include <Library/IoLib.h>
#include <Library/EfiResetSystemLib.h> #include <Library/EfiResetSystemLib.h>
/** /**
Resets the entire platform. Resets the entire platform.
@ -41,7 +39,6 @@ LibResetSystem (
UINTN Address; UINTN Address;
UINT8 Data; UINT8 Data;
switch (ResetType) { switch (ResetType) {
case EfiResetCold: case EfiResetCold:
// system power cycle // system power cycle
@ -74,8 +71,6 @@ LibResetSystem (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
/** /**
Initialize any infrastructure required for LibResetSystem () to function. Initialize any infrastructure required for LibResetSystem () to function.
@ -94,4 +89,3 @@ LibInitializeResetSystem (
{ {
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -72,7 +72,6 @@ EpochToEfiTime (
Time->Minute = (UINT8)mm; Time->Minute = (UINT8)mm;
Time->Second = (UINT8)ss; Time->Second = (UINT8)ss;
Time->Nanosecond = 0; Time->Nanosecond = 0;
} }
/** /**
@ -200,10 +199,11 @@ IsDayValid (
{ {
STATIC CONST INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; STATIC CONST INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (Time->Day < 1 || if ((Time->Day < 1) ||
Time->Day > DayOfMonth[Time->Month - 1] || (Time->Day > DayOfMonth[Time->Month - 1]) ||
(Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28)) ((Time->Month == 2) && (!IsLeapYear (Time) && (Time->Day > 28)))
) { )
{
return FALSE; return FALSE;
} }
@ -281,7 +281,8 @@ IsTimeValid (
(Time->Second > 59) || (Time->Second > 59) ||
(Time->Nanosecond > 999999999) || (Time->Nanosecond > 999999999) ||
(!IsValidTimeZone (Time->TimeZone)) || (!IsValidTimeZone (Time->TimeZone)) ||
(!IsValidDaylight(Time->Daylight))) { (!IsValidDaylight (Time->Daylight)))
{
return FALSE; return FALSE;
} }

View File

@ -101,6 +101,7 @@ LibGetTime (
&EpochSeconds &EpochSeconds
); );
} }
Counter = GetPerformanceCounter (); Counter = GetPerformanceCounter ();
EpochSeconds += DivU64x64Remainder (Counter, Freq, &Remainder); EpochSeconds += DivU64x64Remainder (Counter, Freq, &Remainder);
@ -147,7 +148,8 @@ LibGetTime (
// Check TimeZone bounds: -1440 to 1440 or 2047 // Check TimeZone bounds: -1440 to 1440 or 2047
if ( ((Time->TimeZone < -1440) || (Time->TimeZone > 1440)) if ( ((Time->TimeZone < -1440) || (Time->TimeZone > 1440))
&& (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE)) { && (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE))
{
Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE; Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
} }
@ -254,13 +256,15 @@ LibSetTime (
// Adjust for the correct time zone, i.e. convert to UTC time zone // Adjust for the correct time zone, i.e. convert to UTC time zone
if ( (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) if ( (Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE)
&& (EpochSeconds > Time->TimeZone * SEC_PER_MIN)) { && (EpochSeconds > Time->TimeZone * SEC_PER_MIN))
{
EpochSeconds -= Time->TimeZone * SEC_PER_MIN; EpochSeconds -= Time->TimeZone * SEC_PER_MIN;
} }
// Adjust for the correct period // Adjust for the correct period
if ( ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT) if ( ((Time->Daylight & EFI_TIME_IN_DAYLIGHT) == EFI_TIME_IN_DAYLIGHT)
&& (EpochSeconds > SEC_PER_HOUR)) { && (EpochSeconds > SEC_PER_HOUR))
{
// Convert to un-adjusted time, i.e. fall back one hour // Convert to un-adjusted time, i.e. fall back one hour
EpochSeconds -= SEC_PER_HOUR; EpochSeconds -= SEC_PER_HOUR;
} }

View File

@ -54,7 +54,6 @@ EFI_METRONOME_ARCH_PROTOCOL gMetronome = {
FixedPcdGet32 (PcdMetronomeTickPeriod) FixedPcdGet32 (PcdMetronomeTickPeriod)
}; };
/** /**
The WaitForTick() function waits for the number of ticks specified by The WaitForTick() function waits for the number of ticks specified by
TickNumber from a known time source in the platform. If TickNumber of TickNumber from a known time source in the platform. If TickNumber of
@ -93,11 +92,8 @@ WaitForTick (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_HANDLE gMetronomeHandle = NULL; EFI_HANDLE gMetronomeHandle = NULL;
/** /**
Initialize the state information for the CPU Architectural Protocol Initialize the state information for the CPU Architectural Protocol
@ -124,11 +120,11 @@ MetronomeInitialize (
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&gMetronomeHandle, &gMetronomeHandle,
&gEfiMetronomeArchProtocolGuid, &gMetronome, &gEfiMetronomeArchProtocolGuid,
&gMetronome,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;
} }

View File

@ -67,8 +67,6 @@ GetTime (
return LibGetTime (Time, Capabilities); return LibGetTime (Time, Capabilities);
} }
/** /**
Sets the current local time and date information. Sets the current local time and date information.
@ -88,14 +86,14 @@ SetTime (
EFI_STATUS Status; EFI_STATUS Status;
BOOLEAN TimeSettingsChanged; BOOLEAN TimeSettingsChanged;
if (Time == NULL || !IsTimeValid (Time)) { if ((Time == NULL) || !IsTimeValid (Time)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
TimeSettingsChanged = FALSE; TimeSettingsChanged = FALSE;
if (mTimeSettings.TimeZone != Time->TimeZone || if ((mTimeSettings.TimeZone != Time->TimeZone) ||
mTimeSettings.Daylight != Time->Daylight) { (mTimeSettings.Daylight != Time->Daylight))
{
mTimeSettings.TimeZone = Time->TimeZone; mTimeSettings.TimeZone = Time->TimeZone;
mTimeSettings.Daylight = Time->Daylight; mTimeSettings.Daylight = Time->Daylight;
TimeSettingsChanged = TRUE; TimeSettingsChanged = TRUE;
@ -114,15 +112,16 @@ SetTime (
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS |
EFI_VARIABLE_RUNTIME_ACCESS, EFI_VARIABLE_RUNTIME_ACCESS,
sizeof (mTimeSettings), sizeof (mTimeSettings),
(VOID *)&mTimeSettings); (VOID *)&mTimeSettings
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Returns the current wakeup alarm clock setting. Returns the current wakeup alarm clock setting.
@ -143,7 +142,7 @@ GetWakeupTime (
OUT EFI_TIME *Time OUT EFI_TIME *Time
) )
{ {
if (Time == NULL || Enabled == NULL || Pending == NULL) { if ((Time == NULL) || (Enabled == NULL) || (Pending == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -157,7 +156,6 @@ GetWakeupTime (
return LibGetWakeupTime (Enabled, Pending, Time); return LibGetWakeupTime (Enabled, Pending, Time);
} }
/** /**
Sets the system wakeup alarm clock time. Sets the system wakeup alarm clock time.
@ -181,8 +179,6 @@ SetWakeupTime (
return LibSetWakeupTime (Enabled, Time); return LibSetWakeupTime (Enabled, Time);
} }
/** /**
This is the declaration of an EFI image entry point. This can be the entry point to an application This is the declaration of an EFI image entry point. This can be the entry point to an application
written to this specification, an EFI boot service driver, or an EFI runtime driver. written to this specification, an EFI boot service driver, or an EFI runtime driver.
@ -209,13 +205,22 @@ InitializeRealTimeClock (
} }
Size = sizeof (mTimeSettings); Size = sizeof (mTimeSettings);
Status = EfiGetVariable ((CHAR16 *)mTimeSettingsVariableName, Status = EfiGetVariable (
&gEfiCallerIdGuid, NULL, &Size, (VOID *)&mTimeSettings); (CHAR16 *)mTimeSettingsVariableName,
&gEfiCallerIdGuid,
NULL,
&Size,
(VOID *)&mTimeSettings
);
if (EFI_ERROR (Status) || if (EFI_ERROR (Status) ||
!IsValidTimeZone (mTimeSettings.TimeZone) || !IsValidTimeZone (mTimeSettings.TimeZone) ||
!IsValidDaylight (mTimeSettings.Daylight)) { !IsValidDaylight (mTimeSettings.Daylight))
DEBUG ((DEBUG_WARN, "%a: using default timezone/daylight settings\n", {
__FUNCTION__)); DEBUG ((
DEBUG_WARN,
"%a: using default timezone/daylight settings\n",
__FUNCTION__
));
mTimeSettings.TimeZone = EFI_UNSPECIFIED_TIMEZONE; mTimeSettings.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
mTimeSettings.Daylight = 0; mTimeSettings.Daylight = 0;
@ -235,4 +240,3 @@ InitializeRealTimeClock (
return Status; return Status;
} }

View File

@ -13,7 +13,6 @@
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/EfiResetSystemLib.h> #include <Library/EfiResetSystemLib.h>
/** /**
Resets the entire platform. Resets the entire platform.
@ -38,8 +37,6 @@ ResetSystemViaLib (
return; return;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
InitializeReset ( InitializeReset (
@ -65,4 +62,3 @@ InitializeReset (
return Status; return Status;
} }

View File

@ -65,11 +65,9 @@
#include <Protocol/SimpleTextOut.h> #include <Protocol/SimpleTextOut.h>
#include <Protocol/DevicePath.h> #include <Protocol/DevicePath.h>
#define MODE0_COLUMN_COUNT 80 #define MODE0_COLUMN_COUNT 80
#define MODE0_ROW_COUNT 25 #define MODE0_ROW_COUNT 25
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TextInReset ( TextInReset (
@ -77,7 +75,6 @@ TextInReset(
IN BOOLEAN ExtendedVerification IN BOOLEAN ExtendedVerification
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
ReadKeyStroke ( ReadKeyStroke (
@ -85,7 +82,6 @@ ReadKeyStroke(
OUT EFI_INPUT_KEY *Key OUT EFI_INPUT_KEY *Key
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TextOutReset ( TextOutReset (
@ -107,7 +103,6 @@ OutputString (
IN CHAR16 *String IN CHAR16 *String
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TestString ( TestString (
@ -115,7 +110,6 @@ TestString (
IN CHAR16 *String IN CHAR16 *String
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
QueryMode ( QueryMode (
@ -125,7 +119,6 @@ QueryMode (
OUT UINTN *Rows OUT UINTN *Rows
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SetMode ( SetMode (
@ -133,7 +126,6 @@ SetMode(
IN UINTN ModeNumber IN UINTN ModeNumber
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SetAttribute ( SetAttribute (
@ -141,14 +133,12 @@ SetAttribute(
IN UINTN Attribute IN UINTN Attribute
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
ClearScreen ( ClearScreen (
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SetCursorPosition ( SetCursorPosition (
@ -157,7 +147,6 @@ SetCursorPosition (
IN UINTN Row IN UINTN Row
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EnableCursor ( EnableCursor (
@ -165,7 +154,6 @@ EnableCursor (
IN BOOLEAN Enable IN BOOLEAN Enable
); );
EFI_SIMPLE_TEXT_INPUT_PROTOCOL mSimpleTextIn = { EFI_SIMPLE_TEXT_INPUT_PROTOCOL mSimpleTextIn = {
TextInReset, TextInReset,
ReadKeyStroke, ReadKeyStroke,
@ -204,23 +192,23 @@ typedef struct {
SIMPLE_TEXT_OUT_DEVICE_PATH mDevicePath = { SIMPLE_TEXT_OUT_DEVICE_PATH mDevicePath = {
{ {
{ HARDWARE_DEVICE_PATH, HW_VENDOR_DP, { sizeof (VENDOR_DEVICE_PATH), 0} }, { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, { sizeof (VENDOR_DEVICE_PATH), 0 }
},
EFI_CALLER_ID_GUID EFI_CALLER_ID_GUID
}, },
{ {
{ MESSAGING_DEVICE_PATH, MSG_UART_DP, { sizeof (UART_DEVICE_PATH), 0} }, { MESSAGING_DEVICE_PATH, MSG_UART_DP, { sizeof (UART_DEVICE_PATH), 0 }
},
0, // Reserved 0, // Reserved
FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate FixedPcdGet64 (PcdUartDefaultBaudRate), // BaudRate
FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits FixedPcdGet8 (PcdUartDefaultDataBits), // DataBits
FixedPcdGet8 (PcdUartDefaultParity), // Parity (N) FixedPcdGet8 (PcdUartDefaultParity), // Parity (N)
FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits FixedPcdGet8 (PcdUartDefaultStopBits) // StopBits
}, },
{ END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0} } { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
}
}; };
BOOLEAN BOOLEAN
TextOutIsValidAscii ( TextOutIsValidAscii (
IN CHAR16 Ascii IN CHAR16 Ascii
@ -236,7 +224,6 @@ TextOutIsValidAscii (
return FALSE; return FALSE;
} }
BOOLEAN BOOLEAN
TextOutIsValidEfiCntlChar ( TextOutIsValidEfiCntlChar (
IN CHAR16 Char IN CHAR16 Char
@ -245,18 +232,18 @@ TextOutIsValidEfiCntlChar (
// //
// only support four control characters. // only support four control characters.
// //
if (Char == CHAR_NULL || if ((Char == CHAR_NULL) ||
Char == CHAR_BACKSPACE || (Char == CHAR_BACKSPACE) ||
Char == CHAR_LINEFEED || (Char == CHAR_LINEFEED) ||
Char == CHAR_CARRIAGE_RETURN || (Char == CHAR_CARRIAGE_RETURN) ||
Char == CHAR_TAB ) { (Char == CHAR_TAB))
{
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
VOID VOID
EFIAPI EFIAPI
WaitForKeyEvent ( WaitForKeyEvent (
@ -269,7 +256,6 @@ WaitForKeyEvent (
} }
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TextInReset ( TextInReset (
@ -280,7 +266,6 @@ TextInReset (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
ReadKeyStroke ( ReadKeyStroke (
@ -416,7 +401,8 @@ ReadKeyStroke (
if ((Char == CHAR_BACKSPACE) || if ((Char == CHAR_BACKSPACE) ||
(Char == CHAR_TAB) || (Char == CHAR_TAB) ||
(Char == CHAR_LINEFEED) || (Char == CHAR_LINEFEED) ||
(Char == CHAR_CARRIAGE_RETURN)) { (Char == CHAR_CARRIAGE_RETURN))
{
// Only let through EFI required control characters // Only let through EFI required control characters
Key->UnicodeChar = (CHAR16)Char; Key->UnicodeChar = (CHAR16)Char;
} }
@ -429,7 +415,6 @@ ReadKeyStroke (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TextOutReset ( TextOutReset (
@ -472,7 +457,6 @@ SafeUnicodeStrToAsciiStr (
ASSERT ((UINTN)((CHAR16 *)Destination - Source) > StrLen (Source)); ASSERT ((UINTN)((CHAR16 *)Destination - Source) > StrLen (Source));
ASSERT ((UINTN)((CHAR8 *)Source - Destination) > StrLen (Source)); ASSERT ((UINTN)((CHAR8 *)Source - Destination) > StrLen (Source));
ReturnValue = Destination; ReturnValue = Destination;
while (*Source != '\0') { while (*Source != '\0') {
// //
@ -543,18 +527,19 @@ OutputString (
} }
for ( ; *String != CHAR_NULL; String++) { for ( ; *String != CHAR_NULL; String++) {
switch (*String) { switch (*String) {
case CHAR_BACKSPACE: case CHAR_BACKSPACE:
if (Mode->CursorColumn > 0) { if (Mode->CursorColumn > 0) {
Mode->CursorColumn--; Mode->CursorColumn--;
} }
break; break;
case CHAR_LINEFEED: case CHAR_LINEFEED:
if (Mode->CursorRow < (INT32)(MaxRow - 1)) { if (Mode->CursorRow < (INT32)(MaxRow - 1)) {
Mode->CursorRow++; Mode->CursorRow++;
} }
break; break;
case CHAR_CARRIAGE_RETURN: case CHAR_CARRIAGE_RETURN:
@ -568,11 +553,13 @@ OutputString (
if (Mode->CursorRow < (INT32)(MaxRow - 1)) { if (Mode->CursorRow < (INT32)(MaxRow - 1)) {
Mode->CursorRow++; Mode->CursorRow++;
} }
// CHAR_CARIAGE_RETURN // CHAR_CARIAGE_RETURN
Mode->CursorColumn = 0; Mode->CursorColumn = 0;
} else { } else {
Mode->CursorColumn++; Mode->CursorColumn++;
} }
break; break;
} }
} }
@ -582,7 +569,6 @@ OutputString (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
TestString ( TestString (
@ -602,7 +588,6 @@ TestString (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
QueryMode ( QueryMode (
@ -625,7 +610,6 @@ QueryMode (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SetMode ( SetMode (
@ -642,7 +626,6 @@ SetMode (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SetAttribute ( SetAttribute (
@ -654,7 +637,6 @@ SetAttribute(
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
ClearScreen ( ClearScreen (
@ -667,7 +649,6 @@ ClearScreen (
return Status; return Status;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SetCursorPosition ( SetCursorPosition (
@ -703,7 +684,6 @@ SetCursorPosition (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
EnableCursor ( EnableCursor (
@ -718,7 +698,6 @@ EnableCursor (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
SimpleTextInOutEntryPoint ( SimpleTextInOutEntryPoint (
@ -739,9 +718,12 @@ SimpleTextInOutEntryPoint (
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&mInstallHandle, &mInstallHandle,
&gEfiSimpleTextInProtocolGuid, &mSimpleTextIn, &gEfiSimpleTextInProtocolGuid,
&gEfiSimpleTextOutProtocolGuid, &mSimpleTextOut, &mSimpleTextIn,
&gEfiDevicePathProtocolGuid, &mDevicePath, &gEfiSimpleTextOutProtocolGuid,
&mSimpleTextOut,
&gEfiDevicePathProtocolGuid,
&mDevicePath,
NULL NULL
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {

View File

@ -36,6 +36,7 @@ DiagnosticLog (
) )
{ {
UINTN len = StrLen (Str); UINTN len = StrLen (Str);
if (len < mLogRemainChar) { if (len < mLogRemainChar) {
StrCpyS (mLogBuffer, mLogRemainChar, Str); StrCpyS (mLogBuffer, mLogRemainChar, Str);
mLogRemainChar -= len; mLogRemainChar -= len;
@ -78,9 +79,11 @@ CompareBuffer (
DEBUG ((DEBUG_ERROR, "(0x%lX) != (0x%lX)\n", *BufferA64, *BufferB64)); DEBUG ((DEBUG_ERROR, "(0x%lX) != (0x%lX)\n", *BufferA64, *BufferB64));
return FALSE; return FALSE;
} }
BufferA64++; BufferA64++;
BufferB64++; BufferB64++;
} }
return TRUE; return TRUE;
} }
@ -183,7 +186,8 @@ MmcDriverDiagnosticsRunDiagnostics (
(ErrorType == NULL) || (ErrorType == NULL) ||
(Buffer == NULL) || (Buffer == NULL) ||
(ControllerHandle == NULL) || (ControllerHandle == NULL) ||
(BufferSize == NULL)) { (BufferSize == NULL))
{
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -208,12 +212,14 @@ MmcDriverDiagnosticsRunDiagnostics (
if (MmcHostInstance->MmcHandle == ControllerHandle) { if (MmcHostInstance->MmcHandle == ControllerHandle) {
break; break;
} }
CurrentLink = CurrentLink->ForwardLink; CurrentLink = CurrentLink->ForwardLink;
} }
// If we didn't find the controller, return EFI_UNSUPPORTED // If we didn't find the controller, return EFI_UNSUPPORTED
if ( (MmcHostInstance == NULL) if ( (MmcHostInstance == NULL)
|| (MmcHostInstance->MmcHandle != ControllerHandle)) { || (MmcHostInstance->MmcHandle != ControllerHandle))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }

View File

@ -76,7 +76,8 @@ RemoveMmcHost (
RemoveEntryList (&(MmcHostInstance->Link)); RemoveEntryList (&(MmcHostInstance->Link));
} }
MMC_HOST_INSTANCE* CreateMmcHostInstance ( MMC_HOST_INSTANCE *
CreateMmcHostInstance (
IN EFI_MMC_HOST_PROTOCOL *MmcHost IN EFI_MMC_HOST_PROTOCOL *MmcHost
) )
{ {
@ -124,8 +125,10 @@ MMC_HOST_INSTANCE* CreateMmcHostInstance (
// Publish BlockIO protocol interface // Publish BlockIO protocol interface
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&MmcHostInstance->MmcHandle, &MmcHostInstance->MmcHandle,
&gEfiBlockIoProtocolGuid,&MmcHostInstance->BlockIo, &gEfiBlockIoProtocolGuid,
&gEfiDevicePathProtocolGuid,MmcHostInstance->DevicePath, &MmcHostInstance->BlockIo,
&gEfiDevicePathProtocolGuid,
MmcHostInstance->DevicePath,
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -146,7 +149,8 @@ FREE_INSTANCE:
return NULL; return NULL;
} }
EFI_STATUS DestroyMmcHostInstance ( EFI_STATUS
DestroyMmcHostInstance (
IN MMC_HOST_INSTANCE *MmcHostInstance IN MMC_HOST_INSTANCE *MmcHostInstance
) )
{ {
@ -155,8 +159,10 @@ EFI_STATUS DestroyMmcHostInstance (
// Uninstall Protocol Interfaces // Uninstall Protocol Interfaces
Status = gBS->UninstallMultipleProtocolInterfaces ( Status = gBS->UninstallMultipleProtocolInterfaces (
MmcHostInstance->MmcHandle, MmcHostInstance->MmcHandle,
&gEfiBlockIoProtocolGuid,&(MmcHostInstance->BlockIo), &gEfiBlockIoProtocolGuid,
&gEfiDevicePathProtocolGuid,MmcHostInstance->DevicePath, &(MmcHostInstance->BlockIo),
&gEfiDevicePathProtocolGuid,
MmcHostInstance->DevicePath,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -165,9 +171,11 @@ EFI_STATUS DestroyMmcHostInstance (
if (MmcHostInstance->BlockIo.Media) { if (MmcHostInstance->BlockIo.Media) {
FreePool (MmcHostInstance->BlockIo.Media); FreePool (MmcHostInstance->BlockIo.Media);
} }
if (MmcHostInstance->CardInfo.ECSDData) { if (MmcHostInstance->CardInfo.ECSDData) {
FreePages (MmcHostInstance->CardInfo.ECSDData, EFI_SIZE_TO_PAGES (sizeof (ECSD))); FreePages (MmcHostInstance->CardInfo.ECSDData, EFI_SIZE_TO_PAGES (sizeof (ECSD)));
} }
FreePool (MmcHostInstance); FreePool (MmcHostInstance);
return Status; return Status;
@ -203,9 +211,10 @@ MmcDriverBindingSupported (
// check its validation // check its validation
// //
Node.DevPath = RemainingDevicePath; Node.DevPath = RemainingDevicePath;
if (Node.DevPath->Type != HARDWARE_DEVICE_PATH || if ((Node.DevPath->Type != HARDWARE_DEVICE_PATH) ||
Node.DevPath->SubType != HW_VENDOR_DP || (Node.DevPath->SubType != HW_VENDOR_DP) ||
DevicePathNodeLength(Node.DevPath) != sizeof(VENDOR_DEVICE_PATH)) { (DevicePathNodeLength (Node.DevPath) != sizeof (VENDOR_DEVICE_PATH)))
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
} }
@ -225,6 +234,7 @@ MmcDriverBindingSupported (
if (Status == EFI_ALREADY_STARTED) { if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -285,6 +295,7 @@ MmcDriverBindingStart (
if (Status == EFI_ALREADY_STARTED) { if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
return Status; return Status;
} }
@ -385,7 +396,6 @@ CheckCardsCallback (
} }
} }
EFI_DRIVER_BINDING_PROTOCOL gMmcDriverBinding = { EFI_DRIVER_BINDING_PROTOCOL gMmcDriverBinding = {
MmcDriverBindingSupported, MmcDriverBindingSupported,
MmcDriverBindingStart, MmcDriverBindingStart,
@ -428,7 +438,8 @@ MmcDxeInitialize (
// Install driver diagnostics // Install driver diagnostics
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&ImageHandle, &ImageHandle,
&gEfiDriverDiagnostics2ProtocolGuid,&gMmcDriverDiagnostics2, &gEfiDriverDiagnostics2ProtocolGuid,
&gMmcDriverDiagnostics2,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -439,13 +450,15 @@ MmcDxeInitialize (
TPL_CALLBACK, TPL_CALLBACK,
CheckCardsCallback, CheckCardsCallback,
NULL, NULL,
&gCheckCardsEvent); &gCheckCardsEvent
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gBS->SetTimer ( Status = gBS->SetTimer (
gCheckCardsEvent, gCheckCardsEvent,
TimerPeriodic, TimerPeriodic,
(UINT64)(10*1000*200)); // 200 ms (UINT64)(10*1000*200)
); // 200 ms
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
return Status; return Status;

View File

@ -344,7 +344,6 @@ typedef struct _MMC_HOST_INSTANCE {
#define MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS(a) CR (a, MMC_HOST_INSTANCE, BlockIo, MMC_HOST_INSTANCE_SIGNATURE) #define MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS(a) CR (a, MMC_HOST_INSTANCE, BlockIo, MMC_HOST_INSTANCE_SIGNATURE)
#define MMC_HOST_INSTANCE_FROM_LINK(a) CR (a, MMC_HOST_INSTANCE, Link, MMC_HOST_INSTANCE_SIGNATURE) #define MMC_HOST_INSTANCE_FROM_LINK(a) CR (a, MMC_HOST_INSTANCE, Link, MMC_HOST_INSTANCE_SIGNATURE)
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
MmcGetDriverName ( MmcGetDriverName (

View File

@ -38,6 +38,7 @@ MmcGetCardStatus (
if (MmcHost == NULL) { if (MmcHost == NULL) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (MmcHostInstance->State != MmcHwInitializationState) { if (MmcHostInstance->State != MmcHwInitializationState) {
// Get the Status of the card. // Get the Status of the card.
CmdArg = MmcHostInstance->CardInfo.RCA << 16; CmdArg = MmcHostInstance->CardInfo.RCA << 16;
@ -108,12 +109,14 @@ MmcStopTransmission (
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT32 Response[4]; UINT32 Response[4];
// Command 12 - Stop transmission (ends read or write) // Command 12 - Stop transmission (ends read or write)
// Normally only needed for streaming transfers or after error. // Normally only needed for streaming transfers or after error.
Status = MmcHost->SendCommand (MmcHost, MMC_CMD12, 0); Status = MmcHost->SendCommand (MmcHost, MMC_CMD12, 0);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b, Response); MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b, Response);
} }
return Status; return Status;
} }
@ -154,7 +157,8 @@ MmcTransferBlock (
} else { } else {
// Set command argument based on the card access mode (Byte mode or Block mode) // Set command argument based on the card access mode (Byte mode or Block mode)
if ((MmcHostInstance->CardInfo.OCRData.AccessMode & MMC_OCR_ACCESS_MASK) == if ((MmcHostInstance->CardInfo.OCRData.AccessMode & MMC_OCR_ACCESS_MASK) ==
MMC_OCR_ACCESS_SECTOR) { MMC_OCR_ACCESS_SECTOR)
{
CmdArg = Lba; CmdArg = Lba;
} else { } else {
CmdArg = MultU64x32 (Lba, This->Media->BlockSize); CmdArg = MultU64x32 (Lba, This->Media->BlockSize);
@ -175,6 +179,7 @@ MmcTransferBlock (
MmcStopTransmission (MmcHost); MmcStopTransmission (MmcHost);
return Status; return Status;
} }
Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState); Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a() : Error MmcProgrammingState\n", __func__)); DEBUG ((DEBUG_ERROR, "%a() : Error MmcProgrammingState\n", __func__));
@ -196,7 +201,8 @@ MmcTransferBlock (
Response[0] = 0; Response[0] = 0;
while ( !(Response[0] & MMC_R0_READY_FOR_DATA) while ( !(Response[0] & MMC_R0_READY_FOR_DATA)
&& (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN) && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
&& Timeout--) { && Timeout--)
{
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response); MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
@ -211,6 +217,7 @@ MmcTransferBlock (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_BLKIO, "%a(): Error and Status:%r\n", __func__, Status)); DEBUG ((DEBUG_BLKIO, "%a(): Error and Status:%r\n", __func__, Status));
} }
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b, Response); MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b, Response);
} }
@ -219,6 +226,7 @@ MmcTransferBlock (
DEBUG ((DEBUG_ERROR, "MmcIoBlocks() : Error MmcTransferState\n")); DEBUG ((DEBUG_ERROR, "MmcIoBlocks() : Error MmcTransferState\n"));
return Status; return Status;
} }
return Status; return Status;
} }
@ -297,7 +305,6 @@ MmcIoBlocks (
RemainingBlock = BlockCount; RemainingBlock = BlockCount;
BytesRemainingToBeTransfered = BufferSize; BytesRemainingToBeTransfered = BufferSize;
while (BytesRemainingToBeTransfered > 0) { while (BytesRemainingToBeTransfered > 0) {
if (RemainingBlock <= MaxBlock) { if (RemainingBlock <= MaxBlock) {
BlockCount = RemainingBlock; BlockCount = RemainingBlock;
} else { } else {
@ -310,7 +317,8 @@ MmcIoBlocks (
Timeout = 20; Timeout = 20;
while ( (!(Response[0] & MMC_R0_READY_FOR_DATA)) while ( (!(Response[0] & MMC_R0_READY_FOR_DATA))
&& (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN) && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
&& Timeout--) { && Timeout--)
{
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg); Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response); MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
@ -344,6 +352,7 @@ MmcIoBlocks (
if (BytesRemainingToBeTransfered < ConsumeSize) { if (BytesRemainingToBeTransfered < ConsumeSize) {
ConsumeSize = BytesRemainingToBeTransfered; ConsumeSize = BytesRemainingToBeTransfered;
} }
Status = MmcTransferBlock (This, Cmd, Transfer, MediaId, Lba, ConsumeSize, Buffer); Status = MmcTransferBlock (This, Cmd, Transfer, MediaId, Lba, ConsumeSize, Buffer);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a(): Failed to transfer block and Status:%r\n", __func__, Status)); DEBUG ((DEBUG_ERROR, "%a(): Failed to transfer block and Status:%r\n", __func__, Status));

View File

@ -9,10 +9,14 @@
#include "Mmc.h" #include "Mmc.h"
#if !defined (MDEPKG_NDEBUG) #if !defined (MDEPKG_NDEBUG)
CONST CHAR8* mStrUnit[] = { "100kbit/s", "1Mbit/s", "10Mbit/s", "100MBit/s", CONST CHAR8 *mStrUnit[] = {
"Unknown", "Unknown", "Unknown", "Unknown" }; "100kbit/s", "1Mbit/s", "10Mbit/s", "100MBit/s",
CONST CHAR8* mStrValue[] = { "1.0", "1.2", "1.3", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0", "Unknown", "Unknown", "Unknown", "Unknown"
"Unknown", "Unknown", "Unknown", "Unknown" }; };
CONST CHAR8 *mStrValue[] = {
"1.0", "1.2", "1.3", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0",
"Unknown", "Unknown", "Unknown", "Unknown"
};
#endif #endif
VOID VOID
@ -28,7 +32,6 @@ PrintCID (
DEBUG ((DEBUG_ERROR, "\t- OEM ID: %c%c\n", (Cid[3] >> 8) & 0xFF, (Cid[3] >> 16) & 0xFF)); DEBUG ((DEBUG_ERROR, "\t- OEM ID: %c%c\n", (Cid[3] >> 8) & 0xFF, (Cid[3] >> 16) & 0xFF));
} }
VOID VOID
PrintCSD ( PrintCSD (
IN UINT32 *Csd IN UINT32 *Csd
@ -95,10 +98,12 @@ PrintOCR (
if (MinV > Volts) { if (MinV > Volts) {
MinV = Volts; MinV = Volts;
} }
if (MaxV < Volts) { if (MaxV < Volts) {
MaxV = Volts + 1; MaxV = Volts + 1;
} }
} }
Volts++; Volts++;
} }

View File

@ -84,15 +84,18 @@ EmmcGetDeviceState (
DEBUG ((DEBUG_ERROR, "EmmcGetDeviceState(): Failed to get card status, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "EmmcGetDeviceState(): Failed to get card status, Status=%r.\n", Status));
return Status; return Status;
} }
Status = Host->ReceiveResponse (Host, MMC_RESPONSE_TYPE_R1, &Data); Status = Host->ReceiveResponse (Host, MMC_RESPONSE_TYPE_R1, &Data);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "EmmcGetDeviceState(): Failed to get response of CMD13, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "EmmcGetDeviceState(): Failed to get response of CMD13, Status=%r.\n", Status));
return Status; return Status;
} }
if (Data & EMMC_SWITCH_ERROR) { if (Data & EMMC_SWITCH_ERROR) {
DEBUG ((DEBUG_ERROR, "EmmcGetDeviceState(): Failed to switch expected mode, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "EmmcGetDeviceState(): Failed to switch expected mode, Status=%r.\n", Status));
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
*State = DEVICE_STATE (Data); *State = DEVICE_STATE (Data);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -119,6 +122,7 @@ EmmcSetEXTCSD (
DEBUG ((DEBUG_ERROR, "EmmcSetEXTCSD(): Failed to send CMD6, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "EmmcSetEXTCSD(): Failed to send CMD6, Status=%r.\n", Status));
return Status; return Status;
} }
// Make sure device exiting prog mode // Make sure device exiting prog mode
do { do {
Status = EmmcGetDeviceState (MmcHostInstance, &State); Status = EmmcGetDeviceState (MmcHostInstance, &State);
@ -127,6 +131,7 @@ EmmcSetEXTCSD (
return Status; return Status;
} }
} while (State == EMMC_PRG_STATE); } while (State == EMMC_PRG_STATE);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -209,6 +214,7 @@ EmmcIdentificationMode (
if (MmcHostInstance->CardInfo.ECSDData == NULL) { if (MmcHostInstance->CardInfo.ECSDData == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = Host->SendCommand (Host, MMC_CMD8, 0); Status = Host->SendCommand (Host, MMC_CMD8, 0);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "EmmcIdentificationMode(): ECSD fetch error, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "EmmcIdentificationMode(): ECSD fetch error, Status=%r.\n", Status));
@ -262,12 +268,14 @@ InitializeEmmcDevice (
Host = MmcHostInstance->MmcHost; Host = MmcHostInstance->MmcHost;
ECSDData = MmcHostInstance->CardInfo.ECSDData; ECSDData = MmcHostInstance->CardInfo.ECSDData;
if (ECSDData->DEVICE_TYPE == EMMCBACKWARD) if (ECSDData->DEVICE_TYPE == EMMCBACKWARD) {
return EFI_SUCCESS; return EFI_SUCCESS;
}
if (!MMC_HOST_HAS_SETIOS (Host)) { if (!MMC_HOST_HAS_SETIOS (Host)) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
Status = EmmcSetEXTCSD (MmcHostInstance, EXTCSD_HS_TIMING, EMMC_TIMING_HS); Status = EmmcSetEXTCSD (MmcHostInstance, EXTCSD_HS_TIMING, EMMC_TIMING_HS);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "InitializeEmmcDevice(): Failed to switch high speed mode, Status:%r.\n", Status)); DEBUG ((DEBUG_ERROR, "InitializeEmmcDevice(): Failed to switch high speed mode, Status:%r.\n", Status));
@ -287,6 +295,7 @@ InitializeEmmcDevice (
default: default:
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Status = Host->SetIos (Host, BusClockFreq, 8, TimingMode[Idx]); Status = Host->SetIos (Host, BusClockFreq, 8, TimingMode[Idx]);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
switch (TimingMode[Idx]) { switch (TimingMode[Idx]) {
@ -301,13 +310,16 @@ InitializeEmmcDevice (
default: default:
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
Status = EmmcSetEXTCSD (MmcHostInstance, EXTCSD_BUS_WIDTH, BusMode); Status = EmmcSetEXTCSD (MmcHostInstance, EXTCSD_BUS_WIDTH, BusMode);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "InitializeEmmcDevice(): Failed to set EXTCSD bus width, Status:%r\n", Status)); DEBUG ((DEBUG_ERROR, "InitializeEmmcDevice(): Failed to set EXTCSD bus width, Status:%r\n", Status));
} }
return Status; return Status;
} }
} }
return Status; return Status;
} }
@ -363,6 +375,7 @@ InitializeSdMmcDevice (
DEBUG ((DEBUG_ERROR, "InitializeSdMmcDevice(): Failed to receive CSD, Status=%r\n", Status)); DEBUG ((DEBUG_ERROR, "InitializeSdMmcDevice(): Failed to receive CSD, Status=%r\n", Status));
return Status; return Status;
} }
PrintCSD (Response); PrintCSD (Response);
if (MMC_CSD_GET_CCC (Response) & SD_CCC_SWITCH) { if (MMC_CSD_GET_CCC (Response) & SD_CCC_SWITCH) {
CccSwitch = TRUE; CccSwitch = TRUE;
@ -404,11 +417,13 @@ InitializeSdMmcDevice (
DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status));
return Status; return Status;
} }
Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response); Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status));
return Status; return Status;
} }
if ((Response[0] & MMC_STATUS_APP_CMD) == 0) { if ((Response[0] & MMC_STATUS_APP_CMD) == 0) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -424,6 +439,7 @@ InitializeSdMmcDevice (
DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status = %r\n", __func__, Status)); DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status = %r\n", __func__, Status));
return Status; return Status;
} }
CopyMem (&Scr, Buffer, 8); CopyMem (&Scr, Buffer, 8);
if (Scr.SD_SPEC == 2) { if (Scr.SD_SPEC == 2) {
if (Scr.SD_SPEC3 == 1) { if (Scr.SD_SPEC3 == 1) {
@ -451,6 +467,7 @@ InitializeSdMmcDevice (
} }
} }
} }
if (CccSwitch) { if (CccSwitch) {
/* SD Switch, Mode:0, Group:0, Value:0 */ /* SD Switch, Mode:0, Group:0, Value:0 */
CmdArg = CreateSwitchCmdArgument (0, 0, 0); CmdArg = CreateSwitchCmdArgument (0, 0, 0);
@ -491,6 +508,7 @@ InitializeSdMmcDevice (
} }
} }
} }
if (Scr.SD_BUS_WIDTHS & SD_BUS_WIDTH_4BIT) { if (Scr.SD_BUS_WIDTHS & SD_BUS_WIDTH_4BIT) {
CmdArg = MmcHostInstance->CardInfo.RCA << 16; CmdArg = MmcHostInstance->CardInfo.RCA << 16;
Status = MmcHost->SendCommand (MmcHost, MMC_CMD55, CmdArg); Status = MmcHost->SendCommand (MmcHost, MMC_CMD55, CmdArg);
@ -498,6 +516,7 @@ InitializeSdMmcDevice (
DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status)); DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status));
return Status; return Status;
} }
/* Width: 4 */ /* Width: 4 */
Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, 2); Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, 2);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -505,6 +524,7 @@ InitializeSdMmcDevice (
return Status; return Status;
} }
} }
if (MMC_HOST_HAS_SETIOS (MmcHost)) { if (MMC_HOST_HAS_SETIOS (MmcHost)) {
Status = MmcHost->SetIos (MmcHost, Speed, BUSWIDTH_4, EMMCBACKWARD); Status = MmcHost->SetIos (MmcHost, Speed, BUSWIDTH_4, EMMCBACKWARD);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -512,6 +532,7 @@ InitializeSdMmcDevice (
return Status; return Status;
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -553,6 +574,7 @@ MmcIdentificationMode (
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD0): Error, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD0): Error, Status=%r.\n", Status));
return Status; return Status;
} }
Status = MmcNotifyState (MmcHostInstance, MmcIdleState); Status = MmcNotifyState (MmcHostInstance, MmcIdleState);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Error MmcIdleState, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Error MmcIdleState, Status=%r.\n", Status));
@ -564,30 +586,36 @@ MmcIdentificationMode (
Timeout = MAX_RETRY_COUNT; Timeout = MAX_RETRY_COUNT;
do { do {
Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, EMMC_CMD1_CAPACITY_GREATER_THAN_2GB); Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, EMMC_CMD1_CAPACITY_GREATER_THAN_2GB);
if (EFI_ERROR (Status)) if (EFI_ERROR (Status)) {
break; break;
}
Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, (UINT32 *)&OcrResponse); Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, (UINT32 *)&OcrResponse);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status));
return Status; return Status;
} }
Timeout--; Timeout--;
} while (!OcrResponse.Ocr.PowerUp && (Timeout > 0)); } while (!OcrResponse.Ocr.PowerUp && (Timeout > 0));
if (Status == EFI_SUCCESS) { if (Status == EFI_SUCCESS) {
if (!OcrResponse.Ocr.PowerUp) { if (!OcrResponse.Ocr.PowerUp) {
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD1): Card initialisation failure, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD1): Card initialisation failure, Status=%r.\n", Status));
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
OcrResponse.Ocr.PowerUp = 0; OcrResponse.Ocr.PowerUp = 0;
if (OcrResponse.Raw == EMMC_CMD1_CAPACITY_GREATER_THAN_2GB) { if (OcrResponse.Raw == EMMC_CMD1_CAPACITY_GREATER_THAN_2GB) {
MmcHostInstance->CardInfo.OCRData.AccessMode = BIT1; MmcHostInstance->CardInfo.OCRData.AccessMode = BIT1;
} } else {
else {
MmcHostInstance->CardInfo.OCRData.AccessMode = 0x0; MmcHostInstance->CardInfo.OCRData.AccessMode = 0x0;
} }
// Check whether MMC or eMMC // Check whether MMC or eMMC
if (OcrResponse.Raw == EMMC_CMD1_CAPACITY_GREATER_THAN_2GB || if ((OcrResponse.Raw == EMMC_CMD1_CAPACITY_GREATER_THAN_2GB) ||
OcrResponse.Raw == EMMC_CMD1_CAPACITY_LESS_THAN_2GB) { (OcrResponse.Raw == EMMC_CMD1_CAPACITY_LESS_THAN_2GB))
{
return EmmcIdentificationMode (MmcHostInstance, OcrResponse); return EmmcIdentificationMode (MmcHostInstance, OcrResponse);
} }
} }
@ -610,6 +638,7 @@ MmcIdentificationMode (
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive response to CMD8, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive response to CMD8, Status=%r.\n", Status));
return Status; return Status;
} }
PrintResponseR1 (Response[0]); PrintResponseR1 (Response[0]);
// Check if it is valid response // Check if it is valid response
if (Response[0] != CmdArg) { if (Response[0] != CmdArg) {
@ -638,6 +667,7 @@ MmcIdentificationMode (
if (IsHCS) { if (IsHCS) {
CmdArg |= BIT30; CmdArg |= BIT30;
} }
Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, CmdArg); Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, CmdArg);
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response); Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response);
@ -645,6 +675,7 @@ MmcIdentificationMode (
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status));
return Status; return Status;
} }
((UINT32 *)&(MmcHostInstance->CardInfo.OCRData))[0] = Response[0]; ((UINT32 *)&(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
} }
} else { } else {
@ -658,6 +689,7 @@ MmcIdentificationMode (
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status));
return Status; return Status;
} }
((UINT32 *)&(MmcHostInstance->CardInfo.OCRData))[0] = Response[0]; ((UINT32 *)&(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
} }
} }
@ -671,6 +703,7 @@ MmcIdentificationMode (
MmcHostInstance->CardInfo.CardType = SD_CARD_2_HIGH; MmcHostInstance->CardInfo.CardType = SD_CARD_2_HIGH;
DEBUG ((DEBUG_ERROR, "High capacity card.\n")); DEBUG ((DEBUG_ERROR, "High capacity card.\n"));
} }
break; // The MMC/SD card is ready. Continue the Identification Mode break; // The MMC/SD card is ready. Continue the Identification Mode
} }
} else { } else {
@ -697,6 +730,7 @@ MmcIdentificationMode (
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD2): Error\n")); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode(MMC_CMD2): Error\n"));
return Status; return Status;
} }
Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CID, Response); Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CID, Response);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive CID, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive CID, Status=%r.\n", Status));
@ -728,6 +762,7 @@ MmcIdentificationMode (
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive RCA, Status=%r.\n", Status)); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Failed to receive RCA, Status=%r.\n", Status));
return Status; return Status;
} }
PrintRCA (Response[0]); PrintRCA (Response[0]);
// For MMC card, RCA is assigned by CMD3 while CMD3 dumps the RCA for SD card // For MMC card, RCA is assigned by CMD3 while CMD3 dumps the RCA for SD card
@ -736,6 +771,7 @@ MmcIdentificationMode (
} else { } else {
MmcHostInstance->CardInfo.RCA = CmdArg; MmcHostInstance->CardInfo.RCA = CmdArg;
} }
Status = MmcNotifyState (MmcHostInstance, MmcStandByState); Status = MmcNotifyState (MmcHostInstance, MmcStandByState);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Error MmcStandByState\n")); DEBUG ((DEBUG_ERROR, "MmcIdentificationMode() : Error MmcStandByState\n"));
@ -774,6 +810,7 @@ InitializeMmcDevice (
} else { } else {
Status = InitializeEmmcDevice (MmcHostInstance); Status = InitializeEmmcDevice (MmcHostInstance);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
@ -781,8 +818,12 @@ InitializeMmcDevice (
// Set Block Length // Set Block Length
Status = MmcHost->SendCommand (MmcHost, MMC_CMD16, MmcHostInstance->BlockIo.Media->BlockSize); Status = MmcHost->SendCommand (MmcHost, MMC_CMD16, MmcHostInstance->BlockIo.Media->BlockSize);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "InitializeMmcDevice(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n", DEBUG ((
MmcHostInstance->BlockIo.Media->BlockSize, Status)); DEBUG_ERROR,
"InitializeMmcDevice(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n",
MmcHostInstance->BlockIo.Media->BlockSize,
Status
));
return Status; return Status;
} }