From 1f2982bf03657d33334548b2b4ed7f135326e342 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Thu, 3 Dec 2020 17:34:12 +0300 Subject: [PATCH] OcBootManagementLib: Allow launching any app via GUID --- Application/BootKicker/BootKicker.c | 2 +- .../Acidanthera/Library/OcBootManagementLib.h | 10 +++-- .../OcBootManagementLib/OcBootManagementLib.c | 41 +++++++++++-------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Application/BootKicker/BootKicker.c b/Application/BootKicker/BootKicker.c index 687dc9c9..bff937c8 100644 --- a/Application/BootKicker/BootKicker.c +++ b/Application/BootKicker/BootKicker.c @@ -61,7 +61,7 @@ UefiMain ( return Status; } - Status = OcRunAppleBootPicker (); + Status = OcRunFirmwareApplication (&gAppleBootPickerFileGuid, TRUE); Pixel.Raw = 0x0; if (Status == EFI_NOT_FOUND) { diff --git a/Include/Acidanthera/Library/OcBootManagementLib.h b/Include/Acidanthera/Library/OcBootManagementLib.h index 5e2684bb..1af7f633 100755 --- a/Include/Acidanthera/Library/OcBootManagementLib.h +++ b/Include/Acidanthera/Library/OcBootManagementLib.h @@ -1210,13 +1210,17 @@ OcDeleteVariables ( ); /** - Launch Apple BootPicker. + Launch firmware application. + + @param[in] ApplicationGuid Application GUID identifier in the firmware. + @param[in] SetReason Pass enter reason (specific to Apple BootPicker). @retval error code, should not return. **/ EFI_STATUS -OcRunAppleBootPicker ( - VOID +OcRunFirmwareApplication ( + IN EFI_GUID *ApplicationGuid, + IN BOOLEAN SetReason ); /** diff --git a/Library/OcBootManagementLib/OcBootManagementLib.c b/Library/OcBootManagementLib/OcBootManagementLib.c index c026de15..02e0042c 100644 --- a/Library/OcBootManagementLib/OcBootManagementLib.c +++ b/Library/OcBootManagementLib/OcBootManagementLib.c @@ -61,7 +61,7 @@ RunShowMenu ( if (!BootContext->PickerContext->ApplePickerUnsupported && BootContext->PickerContext->PickerMode == OcPickerModeApple) { - Status = OcRunAppleBootPicker (); + Status = OcRunFirmwareApplication (&gAppleBootPickerFileGuid, TRUE); // // This should not return on success. // @@ -540,7 +540,7 @@ OcRunBootPicker ( } if (Context->PickerCommand == OcPickerShowPicker && Context->PickerMode == OcPickerModeApple) { - Status = OcRunAppleBootPicker (); + Status = OcRunFirmwareApplication (&gAppleBootPickerFileGuid, TRUE); DEBUG ((DEBUG_INFO, "OCB: Apple BootPicker failed - %r, fallback to builtin\n", Status)); Context->ApplePickerUnsupported = TRUE; } @@ -707,8 +707,9 @@ OcRunBootPicker ( } EFI_STATUS -OcRunAppleBootPicker ( - VOID +OcRunFirmwareApplication ( + IN EFI_GUID *ApplicationGuid, + IN BOOLEAN SetReason ) { EFI_STATUS Status; @@ -716,11 +717,11 @@ OcRunAppleBootPicker ( EFI_DEVICE_PATH_PROTOCOL *Dp; APPLE_PICKER_ENTRY_REASON PickerEntryReason; - DEBUG ((DEBUG_INFO, "OCB: OcRunAppleBootPicker attempting to find...\n")); + DEBUG ((DEBUG_INFO, "OCB: run fw app attempting to find %g...\n", ApplicationGuid)); - Dp = CreateFvFileDevicePath (&gAppleBootPickerFileGuid); + Dp = CreateFvFileDevicePath (ApplicationGuid); if (Dp != NULL) { - DEBUG ((DEBUG_INFO, "OCB: OcRunAppleBootPicker attempting to load...\n")); + DEBUG ((DEBUG_INFO, "OCB: run fw app attempting to load %g...\n", ApplicationGuid)); NewHandle = NULL; Status = gBS->LoadImage ( FALSE, @@ -738,16 +739,24 @@ OcRunAppleBootPicker ( } if (!EFI_ERROR (Status)) { - PickerEntryReason = ApplePickerEntryReasonUnknown; - Status = gRT->SetVariable ( - APPLE_PICKER_ENTRY_REASON_VARIABLE_NAME, - &gAppleVendorVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - sizeof (PickerEntryReason), - &PickerEntryReason - ); + if (SetReason) { + PickerEntryReason = ApplePickerEntryReasonUnknown; + Status = gRT->SetVariable ( + APPLE_PICKER_ENTRY_REASON_VARIABLE_NAME, + &gAppleVendorVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (PickerEntryReason), + &PickerEntryReason + ); + } - DEBUG ((DEBUG_INFO, "OCB: OcRunAppleBootPicker attempting to start with var %r...\n", Status)); + DEBUG (( + DEBUG_INFO, + "OCB: run fw app attempting to start %g (%d) %r...\n", + ApplicationGuid, + SetReason, + Status + )); Status = gBS->StartImage ( NewHandle, NULL,