diff --git a/Include/Library/OcBootManagementLib.h b/Include/Library/OcBootManagementLib.h index bce3fb2a..53ade500 100755 --- a/Include/Library/OcBootManagementLib.h +++ b/Include/Library/OcBootManagementLib.h @@ -402,6 +402,24 @@ OcScanForBootEntries ( IN BOOLEAN Describe ); +/** + Obtain default entry from the list. + + @param[in,out] BootEntries Described list of entries, may get updated. + @param[in] NumBootEntries Positive number of boot entries. + @param[in] CustomBootGuid Use custom GUID for Boot#### lookup. + @param[in] LoadHandle Handle to skip (potential OpenCore handle). + + @retval boot entry or NULL. +**/ +OC_BOOT_ENTRY * +OcGetDefaultBootEntry ( + IN OUT OC_BOOT_ENTRY *BootEntries, + IN UINTN NumBootEntries, + IN BOOLEAN CustomBootGuid, + IN EFI_HANDLE LoadHandle OPTIONAL + ); + /** Show simple boot entry selection menu and return chosen entry. diff --git a/Include/Protocol/OcInterface.h b/Include/Protocol/OcInterface.h new file mode 100644 index 00000000..583d9a51 --- /dev/null +++ b/Include/Protocol/OcInterface.h @@ -0,0 +1,71 @@ +/** @file + Copyright (C) 2019, vit9696. All rights reserved. + + All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#ifndef OC_INTERFACE_PROTOCOL_H +#define OC_INTERFACE_PROTOCOL_H + +#include +#include + +/** + Current supported interface protocol revision. + It is changed every time the contract changes. + + WARNING: This protocol currently undergoes design process. +**/ +#define OC_INTERFACE_REVISION 0x1 + +/** + The GUID of the OC_INTERFACE_PROTOCOL. +**/ +#define OC_INTERFACE_PROTOCOL_GUID \ + { 0x53027CDF, 0x3A89, 0x4255, \ + { 0xAE, 0x29, 0xD6, 0x66, 0x6E, 0xFE, 0x99, 0xEF } } + +/** + The forward declaration for the protocol for the OC_INTERFACE_PROTOCOL_H. +**/ +typedef struct OC_INTERFACE_PROTOCOL_ OC_INTERFACE_PROTOCOL; + +/** + Add an entry to the log buffer + + @param[in] This This protocol. + @param[in] Storage File system access storage. + @param[in] Picker User interface configuration. + + @retval does not return unless a fatal error happened. +**/ +typedef +EFI_STATUS +(EFIAPI *OC_INTERFACE_RUN) ( + IN OC_INTERFACE_PROTOCOL *This, + IN OC_STORAGE_CONTEXT *Storage, + IN OC_PICKER_CONTEXT *Picker + ); + +/** + The structure exposed by the OC_INTERFACE_PROTOCOL. +**/ +struct OC_INTERFACE_PROTOCOL_ { + UINT32 Revision; ///< The revision of the installed protocol. + OC_INTERFACE_RUN ShowInteface; ///< A pointer to the ShowInterface function. +}; + +/** + A global variable storing the GUID of the OC_INTERFACE_PROTOCOL. +**/ +extern EFI_GUID gOcInterfaceProtocolGuid; + +#endif // OC_INTERFACE_PROTOCOL_H diff --git a/Include/Protocol/OcLog.h b/Include/Protocol/OcLog.h index 0246eae3..f2a3cf52 100755 --- a/Include/Protocol/OcLog.h +++ b/Include/Protocol/OcLog.h @@ -38,10 +38,9 @@ typedef UINT32 OC_LOG_OPTIONS; /** The GUID of the OC_LOG_PROTOCOL. **/ -#define OC_LOG_PROTOCOL_GUID \ - { \ - 0xDBB6008F, 0x89E4, 0x4272, { 0x98, 0x81, 0xCE, 0x3A, 0xFD, 0x97, 0x24, 0xD0 } \ - } +#define OC_LOG_PROTOCOL_GUID \ + { 0xDBB6008F, 0x89E4, 0x4272, \ + { 0x98, 0x81, 0xCE, 0x3A, 0xFD, 0x97, 0x24, 0xD0 } } /** The forward declaration for the protocol for the OC_LOG_PROTOCOL. diff --git a/Library/OcBootManagementLib/BootManagementInternal.h b/Library/OcBootManagementLib/BootManagementInternal.h index 28ccdd1d..8e5285cb 100644 --- a/Library/OcBootManagementLib/BootManagementInternal.h +++ b/Library/OcBootManagementLib/BootManagementInternal.h @@ -49,14 +49,6 @@ InternalUnloadDmg ( IN INTERNAL_DMG_LOAD_CONTEXT *DmgLoadContext ); -OC_BOOT_ENTRY * -InternalGetDefaultBootEntry ( - IN OUT OC_BOOT_ENTRY *BootEntries, - IN UINTN NumBootEntries, - IN BOOLEAN CustomBootGuid, - IN EFI_HANDLE LoadHandle OPTIONAL - ); - CHAR16 * InternalGetAppleDiskLabel ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem, diff --git a/Library/OcBootManagementLib/DefaultEntryChoice.c b/Library/OcBootManagementLib/DefaultEntryChoice.c index 29bc48fc..da9f2886 100644 --- a/Library/OcBootManagementLib/DefaultEntryChoice.c +++ b/Library/OcBootManagementLib/DefaultEntryChoice.c @@ -350,7 +350,7 @@ InternalIsAppleLegacyLoadApp ( } OC_BOOT_ENTRY * -InternalGetDefaultBootEntry ( +OcGetDefaultBootEntry ( IN OUT OC_BOOT_ENTRY *BootEntries, IN UINTN NumBootEntries, IN BOOLEAN CustomBootGuid, diff --git a/Library/OcBootManagementLib/OcBootManagementLib.c b/Library/OcBootManagementLib/OcBootManagementLib.c index 12b2845b..3e372ee5 100644 --- a/Library/OcBootManagementLib/OcBootManagementLib.c +++ b/Library/OcBootManagementLib/OcBootManagementLib.c @@ -870,7 +870,7 @@ OcRunSimpleBootPicker ( DEBUG ((DEBUG_INFO, "Performing OcShowSimpleBootMenu...\n")); DefaultEntry = 0; - Entry = InternalGetDefaultBootEntry (Entries, EntryCount, Context->CustomBootGuid, Context->ExcludeHandle); + Entry = OcGetDefaultBootEntry (Entries, EntryCount, Context->CustomBootGuid, Context->ExcludeHandle); if (Entry != NULL) { DefaultEntry = (UINT32)(Entry - Entries); } diff --git a/Library/OcBootManagementLib/PolicyManagement.c b/Library/OcBootManagementLib/PolicyManagement.c index c50a0413..aad4fe52 100644 --- a/Library/OcBootManagementLib/PolicyManagement.c +++ b/Library/OcBootManagementLib/PolicyManagement.c @@ -158,7 +158,7 @@ InternalCheckScanPolicy ( // DevicePolicy = OcGetDevicePolicyType (Handle, External); if ((Policy & OC_SCAN_DEVICE_LOCK) != 0 && (Policy & DevicePolicy) == 0) { - DEBUG ((DEBUG_INFO, "OCB: invalid device policy (%u/%u) for %p\n", DevicePolicy, Policy, Handle)); + DEBUG ((DEBUG_INFO, "OCB: Invalid device policy (%x/%x) for %p\n", DevicePolicy, Policy, Handle)); return EFI_SECURITY_VIOLATION; } @@ -166,7 +166,7 @@ InternalCheckScanPolicy ( FileSystemPolicy = OcGetFileSystemPolicyType (Handle); if ((Policy & FileSystemPolicy) == 0) { - DEBUG ((DEBUG_INFO, "OCB: invalid file system policy (%u/%u) for %p\n", FileSystemPolicy, Policy, Handle)); + DEBUG ((DEBUG_INFO, "OCB: Invalid file system policy (%x/%x) for %p\n", FileSystemPolicy, Policy, Handle)); return EFI_SECURITY_VIOLATION; } } diff --git a/OcSupportPkg.dec b/OcSupportPkg.dec index ba33ee03..2235aadc 100644 --- a/OcSupportPkg.dec +++ b/OcSupportPkg.dec @@ -35,8 +35,11 @@ gOcCustomSmbiosTableGuid = { 0xEB9D2D35, 0x2D88, 0x11D3, { 0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }} [Protocols] - gOcLogProtocolGuid = { 0xDBB6008F, 0x89E4, 0x4272, { 0x98, 0x81, 0xCE, 0x3A, 0xFD, 0x97, 0x24, 0xD0 }} + ## Include/Protocol/OcInterface.h + gOcInterfaceProtocolGuid = { 0x53027CDF, 0x3A89, 0x4255, { 0xAE, 0x29, 0xD6, 0x66, 0x6E, 0xFE, 0x99, 0xEF }} + ## Include/Protocol/OcLog.h + gOcLogProtocolGuid = { 0xDBB6008F, 0x89E4, 0x4272, { 0x98, 0x81, 0xCE, 0x3A, 0xFD, 0x97, 0x24, 0xD0 }} ## Include/Protocol/LegacyRegion.h gEfiLegacyRegionProtocolGuid = { 0x0fc9013a, 0x0568, 0x4ba9, { 0x9b, 0x7e, 0xc9, 0xc3, 0x90, 0xa6, 0x60, 0x9b }} diff --git a/OcSupportPkg.dsc b/OcSupportPkg.dsc index a4d5a191..b5488d4b 100644 --- a/OcSupportPkg.dsc +++ b/OcSupportPkg.dsc @@ -123,6 +123,7 @@ OcSupportPkg/Tests/BlessTest/BlessTestApp.inf OcSupportPkg/Tests/DataHubTest/DataHubTest.inf OcSupportPkg/Tests/DataHubTest/DataHubTestApp.inf + OcSupportPkg/Tests/ExternalUi/ExternalUi.inf OcSupportPkg/Tests/KernelTest/KernelTest.inf OcSupportPkg/Tests/KernelTest/KernelTestApp.inf OcSupportPkg/Tests/PropertyTest/PropertyTest.inf diff --git a/Tests/ExternalUi/ExternalUi.c b/Tests/ExternalUi/ExternalUi.c new file mode 100644 index 00000000..b4523654 --- /dev/null +++ b/Tests/ExternalUi/ExternalUi.c @@ -0,0 +1,94 @@ +/** @file + Test external interface support. + + Copyright (c) 2019, vit9696. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include +#include + +#include + +STATIC +EFI_STATUS +EFIAPI +ExternalGuiRun ( + IN OC_INTERFACE_PROTOCOL *This, + IN OC_STORAGE_CONTEXT *Storage, + IN OC_PICKER_CONTEXT *Picker + ) +{ + // + // Storage could be used to access custom graphical theme. + // One must NOT access disk bypassing Storage as other + // data may not be protected by vaulting. + // Always use OcStorageReadFileUnicode. + // + (VOID) Storage; + + // + // For simplicity this example just calls reference boot picker, + // however, a more advanced user interface should reimplement + // OcRunSimpleBootPicker logic. + // + return OcRunSimpleBootPicker (Picker); +} + +STATIC +OC_INTERFACE_PROTOCOL +mOcInterfaceProtocol = { + OC_INTERFACE_REVISION, + ExternalGuiRun +}; + +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + VOID *PrevInterface; + EFI_HANDLE NewHandle; + + // + // Check for previous GUI protocols. + // + Status = gBS->LocateProtocol ( + &gOcInterfaceProtocolGuid, + NULL, + &PrevInterface + ); + + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "OCE: Another GUI is already present\n")); + return EFI_ALREADY_STARTED; + } + + // + // Install new GUI protocol + // + NewHandle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces ( + &NewHandle, + &gOcInterfaceProtocolGuid, + &mOcInterfaceProtocol, + NULL + ); + + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "OCE: Registered custom GUI protocol\n")); + } else { + DEBUG ((DEBUG_ERROR, "OCE: Failed to install GUI protocol - %r\n", Status)); + } + + return Status; +} diff --git a/Tests/ExternalUi/ExternalUi.inf b/Tests/ExternalUi/ExternalUi.inf new file mode 100644 index 00000000..a6f77749 --- /dev/null +++ b/Tests/ExternalUi/ExternalUi.inf @@ -0,0 +1,53 @@ +## @file +# External OpenCore GUI application. +# +# Copyright (c) 2019, vit9696. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = ExternalUi + FILE_GUID = 34773042-6AED-4617-BCDB-AD3DF0592EE9 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + INF_VERSION = 0x00010005 + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00010000 + ENTRY_POINT = UefiMain + +# +# This flag specifies whether HII resource section is generated into PE image. +# + UEFI_HII_RESOURCE_SECTION = TRUE + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources] + ExternalUi.c + +[Packages] + OcSupportPkg/OcSupportPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + EfiPkg/EfiPkg.dec + +[Protocols] + gOcInterfaceProtocolGuid ## SOMETIMES_PRODUCES + +[LibraryClasses] + OcBootManagementLib + UefiBootServicesTableLib + UefiDriverEntryPoint diff --git a/Tests/KernelTest/KernelTest.inf b/Tests/KernelTest/KernelTest.inf index c29899ea..04dfd86c 100644 --- a/Tests/KernelTest/KernelTest.inf +++ b/Tests/KernelTest/KernelTest.inf @@ -66,4 +66,3 @@ OcSmbiosLib OcDataHubLib OcVirtualFsLib -