OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
BootEntryManagement.c File Reference
#include "BootManagementInternal.h"
#include <Protocol/DevicePath.h>
#include <Protocol/SimpleFileSystem.h>
#include <IndustryStandard/AppleCsrConfig.h>
#include <Guid/AppleVariable.h>
#include <Guid/FileInfo.h>
#include <Guid/GlobalVariable.h>
#include <Guid/Gpt.h>
#include <Guid/OcVariable.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcConsoleLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/OcFileLib.h>
#include <Library/OcStringLib.h>
#include <Library/OcVariableLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>

Go to the source code of this file.

Functions

STATIC EFI_DEVICE_PATH_PROTOCOL * ExpandShortFormBootPath (IN OC_BOOT_CONTEXT *BootContext, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN LazyScan, OUT OC_BOOT_FILESYSTEM **FileSystem, OUT BOOLEAN *IsRoot)
 
STATIC INTERNAL_ENTRY_VISIBILITY ReadEntryVisibility (IN OC_PICKER_CONTEXT *Context, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 
STATIC VOID RegisterBootOption (IN OUT OC_BOOT_CONTEXT *BootContext, IN OUT OC_BOOT_FILESYSTEM *FileSystem, IN OC_BOOT_ENTRY *BootEntry)
 
STATIC EFI_STATUS AddBootEntryOnFileSystem (IN OUT OC_BOOT_CONTEXT *BootContext, IN OUT OC_BOOT_FILESYSTEM *FileSystem, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN RecoveryPart, IN BOOLEAN Deduplicate)
 
STATIC VOID FreeBootEntry (IN OC_BOOT_ENTRY *BootEntry)
 
EFI_STATUS InternalAddBootEntryFromCustomEntry (IN OUT OC_BOOT_CONTEXT *BootContext, IN OUT OC_BOOT_FILESYSTEM *FileSystem, IN OC_PICKER_ENTRY *CustomEntry, IN BOOLEAN IsBootEntryProtocol)
 
STATIC EFI_STATUS AddBootEntryFromBless (IN OUT OC_BOOT_CONTEXT *BootContext, IN OUT OC_BOOT_FILESYSTEM *FileSystem, IN CONST CHAR16 **PredefinedPaths, IN UINTN NumPredefinedPaths, IN BOOLEAN LazyScan, IN BOOLEAN Deduplicate)
 
STATIC EFI_STATUS AddBootEntryFromSelfRecovery (IN OUT OC_BOOT_CONTEXT *BootContext, IN OUT OC_BOOT_FILESYSTEM *FileSystem)
 
STATIC EFI_STATUS AddBootEntryFromBootOption (IN OUT OC_BOOT_CONTEXT *BootContext, IN UINT16 BootOption, IN BOOLEAN LazyScan, IN OUT OC_BOOT_FILESYSTEM *CustomFileSystem, OUT UINT32 *CustomIndex, OPTIONAL IN EFI_HANDLE *EntryProtocolHandles, IN UINTN EntryProtocolHandleCount, OUT EFI_GUID *EntryProtocolPartuuid, OPTIONAL OUT CHAR16 **EntryProtocolId OPTIONAL)
 
STATIC EFI_STATUS AddFileSystemEntry (IN OUT OC_BOOT_CONTEXT *BootContext, IN EFI_HANDLE FileSystemHandle, OUT OC_BOOT_FILESYSTEM **FileSystemEntry OPTIONAL)
 
STATIC OC_BOOT_FILESYSTEMCreateFileSystemForCustom (IN OUT CONST OC_BOOT_CONTEXT *BootContext)
 
STATIC EFI_STATUS AddFileSystemEntryForCustom (IN OUT OC_BOOT_CONTEXT *BootContext, IN OUT OC_BOOT_FILESYSTEM *FileSystem, IN UINT32 PrecreatedCustomIndex)
 
STATIC VOID FreeFileSystemEntry (IN OUT OC_BOOT_CONTEXT *BootContext, IN OC_BOOT_FILESYSTEM *FileSystemEntry)
 
OC_BOOT_FILESYSTEMInternalFileSystemForHandle (IN OC_BOOT_CONTEXT *BootContext, IN EFI_HANDLE FileSystemHandle, IN BOOLEAN LazyScan, OUT BOOLEAN *AlreadySeen OPTIONAL)
 
STATIC OC_BOOT_CONTEXTBuildFileSystemList (IN OC_PICKER_CONTEXT *Context, IN BOOLEAN Empty)
 
VOID OcFreeBootContext (IN OUT OC_BOOT_CONTEXT *Context)
 
EFI_STATUS OcSetDefaultBootRecovery (IN OUT OC_BOOT_CONTEXT *BootContext)
 
OC_BOOT_CONTEXTOcScanForBootEntries (IN OC_PICKER_CONTEXT *Context)
 
OC_BOOT_CONTEXTOcScanForDefaultBootEntry (IN OC_PICKER_CONTEXT *Context, IN BOOLEAN UseBootNextOnly)
 
OC_BOOT_ENTRY ** OcEnumerateEntries (IN OC_BOOT_CONTEXT *BootContext)
 
EFI_STATUS OcLoadBootEntry (IN OC_PICKER_CONTEXT *Context, IN OC_BOOT_ENTRY *BootEntry, IN EFI_HANDLE ParentHandle)
 

Detailed Description

Copyright (C) 2019-2022, vit9696, mikebeaton. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause

Definition in file BootEntryManagement.c.

Function Documentation

◆ AddBootEntryFromBless()

STATIC EFI_STATUS AddBootEntryFromBless ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN OUT OC_BOOT_FILESYSTEM * FileSystem,
IN CONST CHAR16 ** PredefinedPaths,
IN UINTN NumPredefinedPaths,
IN BOOLEAN LazyScan,
IN BOOLEAN Deduplicate )

Create bootable entries from bless policy. This function may create more than one entry, and for APFS it will likely produce a sequence of 'OS, RECOVERY' entry pairs.

Parameters
[in,out]BootContextContext of filesystems.
[in,out]FileSystemFilesystem to scan for bless.
[in]PredefinedPathsThe predefined boot file locations to scan.
[in]NumPredefinedPathsThe number of elements in PredefinedPaths.
[in]LazyScanLazy filesystem scanning.
[in]DeduplicateEnsure that duplicated entries are not added.
Return values
EFI_STATUSfor last created option.

Definition at line 911 of file BootEntryManagement.c.

◆ AddBootEntryFromBootOption()

STATIC EFI_STATUS AddBootEntryFromBootOption ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN UINT16 BootOption,
IN BOOLEAN LazyScan,
IN OUT OC_BOOT_FILESYSTEM * CustomFileSystem,
OUT UINT32 * CustomIndex,
OPTIONAL IN EFI_HANDLE * EntryProtocolHandles,
IN UINTN EntryProtocolHandleCount,
OUT EFI_GUID * EntryProtocolPartuuid,
OPTIONAL OUT CHAR16 **EntryProtocolId OPTIONAL )

Create bootable entries from boot options.

Parameters
[in,out]BootContextContext of filesystems.
[in]BootOptionBoot option number.
[in]LazyScanLazy filesystem scanning.
[in,out]CustomFileSystemFile system on which to add user defined custom option. If non-NULL still searching for first (normally only) OC custom entry, either user defined or entry protocol.
[out]CustomIndexIndex of custom user defined entry, if matched.
[in]EntryProtocolHandlesInstalled Boot Entry Protocol handles.
[in]EntryProtocolHandleCountInstalled Boot Entry Protocol handle count.
[out]EntryProtocolPartuuidUnique partition UUID of parition with entry protocol custom entry, if matched.
[out]EntryProtocolIdId of entry protocol custom entry, if matched.
Return values
EFI_SUCCESSif at least one option was added.

Definition at line 1223 of file BootEntryManagement.c.

◆ AddBootEntryFromSelfRecovery()

STATIC EFI_STATUS AddBootEntryFromSelfRecovery ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN OUT OC_BOOT_FILESYSTEM * FileSystem )

Create bootable entries from recovery files (com.apple.recovery.boot) on the volume.

Parameters
[in,out]BootContextContext of filesystems.
[in,out]FileSystemFilesystem to scan for recovery.
Return values
EFI_SUCCESSon success.

Definition at line 1160 of file BootEntryManagement.c.

◆ AddBootEntryOnFileSystem()

STATIC EFI_STATUS AddBootEntryOnFileSystem ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN OUT OC_BOOT_FILESYSTEM * FileSystem,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN BOOLEAN RecoveryPart,
IN BOOLEAN Deduplicate )

Create single bootable entry from device path.

Parameters
[in,out]BootContextContext of filesystems.
[in,out]FileSystemFilesystem for creation.
[in]DevicePathDevice path of the entry.
[in]RecoveryPartDevice path is on recovery partition.
[in]DeduplicateEnsure that duplicated entries are not added.
Return values
EFI_SUCCESSon success.

Definition at line 398 of file BootEntryManagement.c.

◆ AddFileSystemEntry()

STATIC EFI_STATUS AddFileSystemEntry ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN EFI_HANDLE FileSystemHandle,
OUT OC_BOOT_FILESYSTEM **FileSystemEntry OPTIONAL )

Allocate a new filesystem entry in boot entries in case it can be used according to current ScanPolicy.

Parameters
[in,out]BootContextContext of filesystems.
[in]FileSystemHandleFilesystem handle.
[in]FileSystemEntryResulting filesystem, optional.
Return values
EFI_SUCCESSon success.

Definition at line 1726 of file BootEntryManagement.c.

◆ AddFileSystemEntryForCustom()

STATIC EFI_STATUS AddFileSystemEntryForCustom ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN OUT OC_BOOT_FILESYSTEM * FileSystem,
IN UINT32 PrecreatedCustomIndex )

Definition at line 1835 of file BootEntryManagement.c.

◆ BuildFileSystemList()

STATIC OC_BOOT_CONTEXT * BuildFileSystemList ( IN OC_PICKER_CONTEXT * Context,
IN BOOLEAN Empty )

Definition at line 1944 of file BootEntryManagement.c.

◆ CreateFileSystemForCustom()

STATIC OC_BOOT_FILESYSTEM * CreateFileSystemForCustom ( IN OUT CONST OC_BOOT_CONTEXT * BootContext)

Definition at line 1804 of file BootEntryManagement.c.

◆ ExpandShortFormBootPath()

STATIC EFI_DEVICE_PATH_PROTOCOL * ExpandShortFormBootPath ( IN OC_BOOT_CONTEXT * BootContext,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN BOOLEAN LazyScan,
OUT OC_BOOT_FILESYSTEM ** FileSystem,
OUT BOOLEAN * IsRoot )

Definition at line 51 of file BootEntryManagement.c.

◆ FreeBootEntry()

STATIC VOID FreeBootEntry ( IN OC_BOOT_ENTRY * BootEntry)

Release boot entry contents allocated from pool.

Parameters
[in,out]BootEntryLocated boot entry.

Definition at line 594 of file BootEntryManagement.c.

◆ FreeFileSystemEntry()

STATIC VOID FreeFileSystemEntry ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN OC_BOOT_FILESYSTEM * FileSystemEntry )

Definition at line 1872 of file BootEntryManagement.c.

◆ InternalAddBootEntryFromCustomEntry()

EFI_STATUS InternalAddBootEntryFromCustomEntry ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN OUT OC_BOOT_FILESYSTEM * FileSystem,
IN OC_PICKER_ENTRY * CustomEntry,
IN BOOLEAN IsBootEntryProtocol )

Create bootable entry from custom entry.

Parameters
[in,out]BootContextContext of filesystems.
[in,out]FileSystemFilesystem to add custom entry.
[in]CustomEntryCustom entry.
Return values
EFI_SUCCESSon success.

Definition at line 642 of file BootEntryManagement.c.

◆ InternalFileSystemForHandle()

OC_BOOT_FILESYSTEM * InternalFileSystemForHandle ( IN OC_BOOT_CONTEXT * BootContext,
IN EFI_HANDLE FileSystemHandle,
IN BOOLEAN LazyScan,
OUT BOOLEAN *AlreadySeen OPTIONAL )

Finds filesystem for discovered filesystem handle. This solves the problem of checking scan policy multiple times as well as the problem of finding the filesystem to add entries too.

Parameters
[in]BootContextContext of filesystems.
[in]FileSystemHandlePartition handle.
[in]LazyScanLazy filesystem scanning.
[out]AlreadySeenSet to TRUE if file system was already present in context.
Return values
discoveredfilesystem (legit). @retcal NULL when booting is not allowed from this filesystem.

Definition at line 1894 of file BootEntryManagement.c.

◆ OcEnumerateEntries()

OC_BOOT_ENTRY ** OcEnumerateEntries ( IN OC_BOOT_CONTEXT * BootContext)

Perform boot entry enumeration.

Parameters
[in]BootContextBoot context.
Return values
enumeratedboot entry list allocated from pool.

Definition at line 2506 of file BootEntryManagement.c.

◆ OcFreeBootContext()

VOID OcFreeBootContext ( IN OUT OC_BOOT_CONTEXT * Context)

Free boot context.

Parameters
[in,out]ContextBoot context to free.

Definition at line 2000 of file BootEntryManagement.c.

◆ OcLoadBootEntry()

EFI_STATUS OcLoadBootEntry ( IN OC_PICKER_CONTEXT * Context,
IN OC_BOOT_ENTRY * BootEntry,
IN EFI_HANDLE ParentHandle )

Load & start boot entry loader image with given options.

Parameters
[in]ContextPicker context.
[in]BootEntryLocated boot entry.
[in]ParentHandleParent image handle.
Return values
EFI_SUCCESSThe image was found, started, and ended succesfully.

Definition at line 2549 of file BootEntryManagement.c.

◆ OcScanForBootEntries()

OC_BOOT_CONTEXT * OcScanForBootEntries ( IN OC_PICKER_CONTEXT * Context)

Scan system for boot entries.

Parameters
[in]ContextPicker context.
Return values
bootcontext allocated from pool.

< Index if Tools or Entries item is pre-created

< ID if boot entry protocol item is pre-created

< PARTUUID for pre-created boot entry protocol item

Definition at line 2102 of file BootEntryManagement.c.

◆ OcScanForDefaultBootEntry()

OC_BOOT_CONTEXT * OcScanForDefaultBootEntry ( IN OC_PICKER_CONTEXT * Context,
IN BOOLEAN UseBootNextOnly )

Scan system for first entry to boot. This is likely to return an incomplete list and can even give NULL, when only tools and system entries are present.

Parameters
[in]ContextPicker context.
[in]UseBootNextOnlyUse only BootNext.
Return values
bootcontext allocated from pool.

Definition at line 2293 of file BootEntryManagement.c.

◆ OcSetDefaultBootRecovery()

EFI_STATUS OcSetDefaultBootRecovery ( IN OUT OC_BOOT_CONTEXT * BootContext)

Definition at line 2017 of file BootEntryManagement.c.

◆ ReadEntryVisibility()

STATIC INTERNAL_ENTRY_VISIBILITY ReadEntryVisibility ( IN OC_PICKER_CONTEXT * Context,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath )

Check boot entry visibility by device path.

Parameters
[in]ContextPicker context.
[in]DevicePathDevice path of the entry.
Returns
Entry visibility

Definition at line 202 of file BootEntryManagement.c.

◆ RegisterBootOption()

STATIC VOID RegisterBootOption ( IN OUT OC_BOOT_CONTEXT * BootContext,
IN OUT OC_BOOT_FILESYSTEM * FileSystem,
IN OC_BOOT_ENTRY * BootEntry )

Register bootable entry on the filesystem.

Parameters
[in,out]BootContextContext of filesystems.
[in,out]FileSystemFilesystem for creation.
[in]BootEntryEntry to register.

Definition at line 310 of file BootEntryManagement.c.