From b0c2eddd7fa66200aef91a905ca8a1a4e3f3007b Mon Sep 17 00:00:00 2001 From: MikeBeaton Date: Tue, 30 Mar 2021 15:38:20 +0100 Subject: [PATCH] OpenShell: Patch devices shell command to work with misaligned device names found in some Apple firmware --- ...-shell-command-support-misaligned-de.patch | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Patches/0005-ShellPkg-Devices-shell-command-support-misaligned-de.patch diff --git a/Patches/0005-ShellPkg-Devices-shell-command-support-misaligned-de.patch b/Patches/0005-ShellPkg-Devices-shell-command-support-misaligned-de.patch new file mode 100644 index 00000000..37a4d2b6 --- /dev/null +++ b/Patches/0005-ShellPkg-Devices-shell-command-support-misaligned-de.patch @@ -0,0 +1,63 @@ +From 5f81e6e5dfab91bd185994eb3edbeb227c826f9b Mon Sep 17 00:00:00 2001 +From: ocbuild +Date: Tue, 30 Mar 2021 18:27:11 +0100 +Subject: [PATCH] ShellPkg: Devices shell command support misaligned device + names found in some Apple firmware + +--- + ShellPkg/Application/Shell/ShellProtocol.c | 24 ++++++++++++++++++++++ + 1 file changed, 24 insertions(+) + +diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c +index 4e639fe..b313af6 100644 +--- a/ShellPkg/Application/Shell/ShellProtocol.c ++++ b/ShellPkg/Application/Shell/ShellProtocol.c +@@ -573,6 +573,22 @@ EfiShellGetDevicePathFromFilePath( + return (DevicePathForReturn); + } + ++STATIC ++CHAR16 *Realign ( ++ CHAR16 *Source ++ ) ++{ ++ UINTN Len; ++ CHAR16 *Dest; ++ ++ for (Len = 0; !(((UINT8 *) Source)[Len * 2] == '\0' && ((UINT8 *) Source)[Len * 2 + 1] == '\0'); Len++) { ++ } ++ Len = (Len + 1) * sizeof (CHAR16); ++ Dest = AllocateCopyPool (Len, Source); ++ ++ return Dest; ++} ++ + /** + Gets the name of the device specified by the device handle. + +@@ -630,6 +646,7 @@ EfiShellGetDeviceName( + EFI_HANDLE *ParentControllerBuffer; + UINTN ParentDriverCount; + EFI_HANDLE *ParentDriverBuffer; ++ BOOLEAN NeedsRealign; + + if (BestDeviceName == NULL || + DeviceHandle == NULL +@@ -748,7 +765,14 @@ EfiShellGetDeviceName( + // + if (DeviceNameToReturn != NULL){ + ASSERT(BestDeviceName != NULL); ++ NeedsRealign = ((UINTN) DeviceNameToReturn & BIT0) != 0; ++ if (NeedsRealign) { ++ DeviceNameToReturn = Realign (DeviceNameToReturn); ++ } + StrnCatGrow(BestDeviceName, NULL, DeviceNameToReturn, 0); ++ if (NeedsRealign) { ++ FreePool (DeviceNameToReturn); ++ } + return (EFI_SUCCESS); + } + } +-- +2.27.0 +