提交 8be51674 编写于 作者: V vit9696

OcBootManagementLib: Implement RealPath and TextMode for custom entries

closes acidanthera/bugtracker#1081
上级 91306327
......@@ -57,7 +57,7 @@ LoadOpenCore (
Buffer = NULL;
BufferSize = 0;
LoaderPath = OcCopyDevicePathFullName (LoaderDevicePath);
LoaderPath = OcCopyDevicePathFullName (LoaderDevicePath, NULL);
*ImagePath = NULL;
......
......@@ -6,6 +6,8 @@ OpenCore Changelog
- Dropped HII services from OpenDuet improving size and performance
- Fixed patching of injected kexts in mkext
- Added support for launching from relative paths
- Added direct path passing for tools via `RealPath`
- Allowed launching tools and entries in text mode via `TextMode`
#### v0.6.3
- Added support for xml comments in plist files
......
......@@ -3812,8 +3812,31 @@ rm vault.pub
Example: \texttt{OpenShell.efi}.
\end{itemize}
\end{enumerate}
\item
\texttt{RealPath}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{plist\ boolean}\\
\textbf{Description}: Pass full path to the tool when launching.
Passing tool directory may be unsafe for tool accidentally trying to access
files without checking their integrity and thus should generally be disabled.
Reason to enable this property may include cases where tools cannot work
without external files.
\emph{Note}: This property is only valid for \texttt{Tools}. For \texttt{Entries}
this property cannot be specified and is always \texttt{true}.
\item
\texttt{TextMode}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{plist\ boolean}\\
\textbf{Description}: Run the entry in text mode instead of graphics mode.
This setting may be benefitial to some older tools that require text output.
By default all the tools are launched in graphics mode. Read more about text
modes in \hyperref[uefioutputprops]{Output Properties} section below.
\end{enumerate}
\section{NVRAM}\label{nvram}
......
\documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Wed Nov 4 05:07:23 2020
%DIF ADD ../Configuration.tex Fri Nov 6 23:16:40 2020
%DIF ADD ../Configuration.tex Sat Nov 7 04:03:21 2020
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
......@@ -3874,8 +3874,36 @@ rm vault.pub
Example: \texttt{OpenShell.efi}.
\end{itemize}
\end{enumerate}
\DIFaddbegin \item
\texttt{\DIFadd{RealPath}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\
\textbf{\DIFadd{Description}}\DIFadd{: Pass full path to the tool when launching.
}
\DIFadd{Passing tool directory may be unsafe for tool accidentally trying to access
files without checking their integrity and thus should generally be disabled.
Reason to enable this property may include cases where tools cannot work
without external files.
}
\emph{\DIFadd{Note}}\DIFadd{: This property is only valid for }\texttt{\DIFadd{Tools}}\DIFadd{. For }\texttt{\DIFadd{Entries}}
\DIFadd{this property cannot be specified and is always }\texttt{\DIFadd{true}}\DIFadd{.
}
\item
\texttt{\DIFadd{TextMode}}\\
\textbf{\DIFadd{Type}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\
\textbf{\DIFadd{Failsafe}}\DIFadd{: }\texttt{\DIFadd{plist\ boolean}}\\
\textbf{\DIFadd{Description}}\DIFadd{: Run the entry in text mode instead of graphics mode.
}
\DIFadd{This setting may be benefitial to some older tools that require text output.
By default all the tools are launched in graphics mode. Read more about text
modes in }\hyperref[uefioutputprops]{Output Properties} \DIFadd{section below.
}
\DIFaddend \end{enumerate}
\section{NVRAM}\label{nvram}
......
......@@ -768,6 +768,8 @@
<string>CustomOS</string>
<key>Path</key>
<string>PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/NVMe(0x1,11-22-33-44-55-66-77-88)/HD(1,GPT,00000000-0000-0000-0000-000000000000,0x800,0x64000)/\EFI\BOOT\BOOTX64.EFI</string>
<key>TextMode</key>
<false/>
</dict>
</array>
<key>Security</key>
......@@ -818,6 +820,10 @@
<string>UEFI Shell</string>
<key>Path</key>
<string>OpenShell.efi</string>
<key>RealPath</key>
<false/>
<key>TextMode</key>
<false/>
</dict>
<dict>
<key>Arguments</key>
......@@ -832,6 +838,10 @@
<string>memcheck</string>
<key>Path</key>
<string>memcheck/memcheck.efi</string>
<key>RealPath</key>
<false/>
<key>TextMode</key>
<false/>
</dict>
<dict>
<key>Arguments</key>
......@@ -846,6 +856,10 @@
<string>Shutdown</string>
<key>Path</key>
<string>ResetSystem.efi</string>
<key>RealPath</key>
<false/>
<key>TextMode</key>
<false/>
</dict>
</array>
</dict>
......
......@@ -768,6 +768,8 @@
<string>CustomOS</string>
<key>Path</key>
<string>PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/NVMe(0x1,11-22-33-44-55-66-77-88)/HD(1,GPT,00000000-0000-0000-0000-000000000000,0x800,0x64000)/\EFI\BOOT\BOOTX64.EFI</string>
<key>TextMode</key>
<false/>
</dict>
</array>
<key>Security</key>
......@@ -818,6 +820,10 @@
<string>UEFI Shell</string>
<key>Path</key>
<string>OpenShell.efi</string>
<key>RealPath</key>
<false/>
<key>TextMode</key>
<false/>
</dict>
<dict>
<key>Arguments</key>
......@@ -832,6 +838,10 @@
<string>memcheck</string>
<key>Path</key>
<string>memcheck/memcheck.efi</string>
<key>RealPath</key>
<false/>
<key>TextMode</key>
<false/>
</dict>
<dict>
<key>Arguments</key>
......@@ -846,6 +856,10 @@
<string>Shutdown</string>
<key>Path</key>
<string>ResetSystem.efi</string>
<key>RealPath</key>
<false/>
<key>TextMode</key>
<false/>
</dict>
</array>
</dict>
......
......@@ -199,6 +199,14 @@ typedef struct OC_BOOT_ENTRY_ {
//
BOOLEAN SetDefault;
//
// Should launch this entry in text mode.
//
BOOLEAN LaunchInText;
//
// Should expose real device path when dealing with custom entries.
//
BOOLEAN ExposeDevicePath;
//
// Load option data (usually "boot args") size.
//
UINT32 LoadOptionsSize;
......@@ -403,7 +411,8 @@ EFI_STATUS
IN OC_BOOT_ENTRY *ChosenEntry,
IN EFI_HANDLE ImageHandle,
OUT UINTN *ExitDataSize,
OUT CHAR16 **ExitData OPTIONAL
OUT CHAR16 **ExitData OPTIONAL,
IN BOOLEAN LaunchInText
);
/**
......@@ -417,9 +426,9 @@ EFI_STATUS
IN OC_BOOT_ENTRY *ChosenEntry,
OUT VOID **Data,
OUT UINT32 *DataSize,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath OPTIONAL,
OUT EFI_HANDLE *ParentDeviceHandle OPTIONAL,
OUT EFI_DEVICE_PATH_PROTOCOL **ParentFilePath OPTIONAL
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT EFI_HANDLE *StorageHandle,
OUT EFI_DEVICE_PATH_PROTOCOL **StoragePath
);
/**
......@@ -462,6 +471,14 @@ typedef struct {
// Whether this entry is a tool.
//
BOOLEAN Tool;
//
// Whether it should be started in text mode.
//
BOOLEAN TextMode;
//
// Whether we should pass the actual device path (if possible).
//
BOOLEAN RealPath;
} OC_PICKER_ENTRY;
/**
......
......@@ -358,6 +358,8 @@ typedef enum {
_(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
_(BOOLEAN , Auxiliary , , FALSE , () ) \
_(BOOLEAN , Enabled , , FALSE , () ) \
_(BOOLEAN , RealPath , , FALSE , () ) \
_(BOOLEAN , TextMode , , FALSE , () ) \
_(OC_STRING , Name , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) \
_(OC_STRING , Path , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) )
OC_DECLARE (OC_MISC_TOOLS_ENTRY)
......
......@@ -189,14 +189,16 @@ OcFileDevicePathFullName (
/**
Retrieves full file path from device path allocating it on pool.
@param[in] DevicePath Device path to extract file path from.
@param[in] DevicePath Device path to extract file path from.
@param[out] FileDevicePath Pointer to file path part of the device path, optional.
@returns Path allocated from pool.
@retval NULL when missing.
**/
CHAR16 *
OcCopyDevicePathFullName (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT EFI_DEVICE_PATH_PROTOCOL **FileDevicePath OPTIONAL
);
/**
......
......@@ -65,13 +65,25 @@ typedef struct {
///
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
///
/// Storage root owned by context.
/// Real storage handle for loading.
///
EFI_FILE_PROTOCOL *StorageRoot;
EFI_HANDLE StorageHandle;
///
/// Real file path for file storage, can be missing.
///
EFI_DEVICE_PATH_PROTOCOL *StoragePath;
///
/// Path to the root of file storage on StoragePage.
///
CONST CHAR16 *StorageRoot;
///
/// Storage file instance owned by context.
///
EFI_FILE_PROTOCOL *Storage;
///
/// Device handle with storage (dummy) device path for loading.
///
EFI_HANDLE StorageHandle;
EFI_HANDLE DummyStorageHandle;
///
/// Dummy file path for file storage.
///
......@@ -93,10 +105,12 @@ typedef struct {
/**
Create storage context from UEFI file system at specified path.
@param[out] Context Resulting storage context.
@param[in] FileSystem Storage file system.
@param[in] Path Storage file system path (e.g. L"\\").
@param[in] StorageKey Storage signature verification key, optional.
@param[out] Context Resulting storage context.
@param[in] FileSystem Storage file system.
@param[in] StorageHandle Storage handle, optional.
@param[in] StoragePath Actual storage device path, optional.
@param[in] StorageRoot Storage file system root (e.g. L"\\").
@param[in] StorageKey Storage signature verification key, optional.
@retval EFI_SUCCESS on success.
**/
......@@ -104,8 +118,10 @@ EFI_STATUS
OcStorageInitFromFs (
OUT OC_STORAGE_CONTEXT *Context,
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *Path,
IN OC_RSA_PUBLIC_KEY *StorageKey OPTIONAL
IN EFI_HANDLE StorageHandle OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *StoragePath OPTIONAL,
IN CONST CHAR16 *StorageRoot,
IN OC_RSA_PUBLIC_KEY *StorageKey OPTIONAL
);
/**
......@@ -152,4 +168,26 @@ OcStorageReadFileUnicode (
OUT UINT32 *FileSize OPTIONAL
);
/**
Get information about the storage file when possible.
@param[in] Context Storage context.
@param[in] FilePath The full path to the file on the device.
@param[out] DevicePath Full storage file device path.
@param[out] StorageHandle Storage handle.
@param[out] StoragePath Path on the storage.
@param[in] RealPath Provide real paths instead of dummy.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
OcStorageGetInfo (
IN OC_STORAGE_CONTEXT *Context,
IN CONST CHAR16 *FilePath,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT EFI_HANDLE *StorageHandle,
OUT EFI_DEVICE_PATH_PROTOCOL **StoragePath,
IN BOOLEAN RealPath
);
#endif // OC_STORAGE_LIB_H
......@@ -282,17 +282,17 @@ OcMiscEarlyInit (
@param[in] Config OpenCore configuration.
@param[in] RootPath Root load path.
@param[in] LoadPath OpenCore loading path.
@param[out] LoadHandle OpenCore loading handle.
@param[in] LoadHandle OpenCore loading handle.
@retval EFI_SUCCESS on success, informational.
**/
EFI_STATUS
VOID
OcMiscMiddleInit (
IN OC_STORAGE_CONTEXT *Storage,
IN OC_GLOBAL_CONFIG *Config,
IN CONST CHAR16 *RootPath OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *LoadPath OPTIONAL,
OUT EFI_HANDLE *LoadHandle
IN EFI_HANDLE LoadHandle OPTIONAL
);
/**
......
......@@ -29,6 +29,7 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/OcConsoleLib.h>
#include <Library/OcFileLib.h>
#include <Library/OcStringLib.h>
#include <Library/UefiBootServicesTableLib.h>
......@@ -595,6 +596,9 @@ AddBootEntryFromCustomEntry (
}
}
BootEntry->LaunchInText = CustomEntry->TextMode;
BootEntry->ExposeDevicePath = CustomEntry->RealPath;
BootEntry->LoadOptionsSize = (UINT32) AsciiStrLen (CustomEntry->Arguments);
if (BootEntry->LoadOptionsSize > 0) {
BootEntry->LoadOptions = AllocateCopyPool (
......@@ -1924,7 +1928,7 @@ OcLoadBootEntry (
&DmgLoadContext
);
if (!EFI_ERROR (Status)) {
Status = Context->StartImage (BootEntry, EntryHandle, NULL, NULL);
Status = Context->StartImage (BootEntry, EntryHandle, NULL, NULL, BootEntry->LaunchInText);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "OCB: StartImage failed - %r\n", Status));
//
......
......@@ -1082,8 +1082,8 @@ InternalLoadBootEntry (
EFI_STATUS Status;
EFI_STATUS OptionalStatus;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_HANDLE ParentDeviceHandle;
EFI_DEVICE_PATH_PROTOCOL *ParentFilePath;
EFI_HANDLE StorageHandle;
EFI_DEVICE_PATH_PROTOCOL *StoragePath;
CHAR16 *UnicodeDevicePath;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
VOID *EntryData;
......@@ -1104,10 +1104,10 @@ InternalLoadBootEntry (
ZeroMem (DmgLoadContext, sizeof (*DmgLoadContext));
EntryData = NULL;
EntryDataSize = 0;
ParentDeviceHandle = NULL;
ParentFilePath = NULL;
EntryData = NULL;
EntryDataSize = 0;
StorageHandle = NULL;
StoragePath = NULL;
if (BootEntry->IsFolder) {
if (Context->DmgLoading == OcDmgLoadingDisabled) {
......@@ -1128,8 +1128,8 @@ InternalLoadBootEntry (
&EntryData,
&EntryDataSize,
&DevicePath,
&ParentDeviceHandle,
&ParentFilePath
&StorageHandle,
&StoragePath
);
if (EFI_ERROR (Status)) {
......@@ -1215,12 +1215,12 @@ InternalLoadBootEntry (
// fields to our custom device path, so we fix it up here.
// REF: https://github.com/acidanthera/bugtracker/issues/712
//
if (LoadedImage->DeviceHandle == NULL && ParentDeviceHandle != NULL) {
if (LoadedImage->DeviceHandle == NULL && StorageHandle != NULL) {
if (LoadedImage->FilePath != NULL) {
FreePool (LoadedImage->FilePath);
}
LoadedImage->DeviceHandle = ParentDeviceHandle;
LoadedImage->FilePath = DuplicateDevicePath (ParentFilePath);
LoadedImage->DeviceHandle = StorageHandle;
LoadedImage->FilePath = StoragePath;
}
}
}
......
......@@ -296,7 +296,7 @@ OcGetBootDevicePathType (
*IsFolder = FALSE;
}
Path = OcCopyDevicePathFullName (DevicePath);
Path = OcCopyDevicePathFullName (DevicePath, NULL);
if (Path == NULL) {
return OC_BOOT_UNKNOWN;
}
......
......@@ -413,6 +413,22 @@ mMiscConfigurationSecuritySchema[] = {
OC_SCHEMA_STRING_IN ("Vault", OC_GLOBAL_CONFIG, Misc.Security.Vault),
};
STATIC
OC_SCHEMA
mMiscEntriesSchemaEntry[] = {
OC_SCHEMA_STRING_IN ("Arguments", OC_MISC_TOOLS_ENTRY, Arguments),
OC_SCHEMA_BOOLEAN_IN ("Auxiliary", OC_MISC_TOOLS_ENTRY, Auxiliary),
OC_SCHEMA_STRING_IN ("Comment", OC_MISC_TOOLS_ENTRY, Comment),
OC_SCHEMA_BOOLEAN_IN ("Enabled", OC_MISC_TOOLS_ENTRY, Enabled),
OC_SCHEMA_STRING_IN ("Name", OC_MISC_TOOLS_ENTRY, Name),
OC_SCHEMA_STRING_IN ("Path", OC_MISC_TOOLS_ENTRY, Path),
OC_SCHEMA_BOOLEAN_IN ("TextMode", OC_MISC_TOOLS_ENTRY, TextMode),
};
STATIC
OC_SCHEMA
mMiscEntriesSchema = OC_SCHEMA_DICT (NULL, mMiscEntriesSchemaEntry);
STATIC
OC_SCHEMA
mMiscToolsSchemaEntry[] = {
......@@ -422,6 +438,8 @@ mMiscToolsSchemaEntry[] = {
OC_SCHEMA_BOOLEAN_IN ("Enabled", OC_MISC_TOOLS_ENTRY, Enabled),
OC_SCHEMA_STRING_IN ("Name", OC_MISC_TOOLS_ENTRY, Name),
OC_SCHEMA_STRING_IN ("Path", OC_MISC_TOOLS_ENTRY, Path),
OC_SCHEMA_BOOLEAN_IN ("RealPath", OC_MISC_TOOLS_ENTRY, RealPath),
OC_SCHEMA_BOOLEAN_IN ("TextMode", OC_MISC_TOOLS_ENTRY, TextMode),
};
STATIC
......@@ -434,7 +452,7 @@ mMiscConfigurationSchema[] = {
OC_SCHEMA_ARRAY_IN ("BlessOverride", OC_GLOBAL_CONFIG, Misc.BlessOverride, &mMiscBlessOverrideSchema),
OC_SCHEMA_DICT ("Boot", mMiscConfigurationBootSchema),
OC_SCHEMA_DICT ("Debug", mMiscConfigurationDebugSchema),
OC_SCHEMA_ARRAY_IN ("Entries", OC_GLOBAL_CONFIG, Misc.Entries, &mMiscToolsSchema),
OC_SCHEMA_ARRAY_IN ("Entries", OC_GLOBAL_CONFIG, Misc.Entries, &mMiscEntriesSchema),
OC_SCHEMA_DICT ("Security", mMiscConfigurationSecuritySchema),
OC_SCHEMA_ARRAY_IN ("Tools", OC_GLOBAL_CONFIG, Misc.Tools, &mMiscToolsSchema),
};
......
......@@ -1119,7 +1119,8 @@ OcFileDevicePathFullName (
CHAR16 *
OcCopyDevicePathFullName (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
OUT EFI_DEVICE_PATH_PROTOCOL **FileDevicePath OPTIONAL
)
{
CHAR16 *Path;
......@@ -1128,9 +1129,17 @@ OcCopyDevicePathFullName (
Path = NULL;
if (FileDevicePath != NULL) {
*FileDevicePath = NULL;
}
for (CurrNode = DevicePath; !IsDevicePathEnd (CurrNode); CurrNode = NextDevicePathNode (CurrNode)) {
if ((DevicePathType (CurrNode) == MEDIA_DEVICE_PATH)
&& (DevicePathSubType (CurrNode) == MEDIA_FILEPATH_DP)) {
if (FileDevicePath != NULL) {
*FileDevicePath = CurrNode;
}
//
// Perform copying of all the underlying nodes due to potential unaligned access.
//
......
......@@ -21,6 +21,7 @@
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/OcStringLib.h>
#include <Library/OcStorageLib.h>
#include <Library/UefiBootServicesTableLib.h>
......@@ -215,8 +216,10 @@ EFI_STATUS
OcStorageInitFromFs (
OUT OC_STORAGE_CONTEXT *Context,
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *Path,
IN OC_RSA_PUBLIC_KEY *StorageKey OPTIONAL
IN EFI_HANDLE StorageHandle OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *StoragePath OPTIONAL,
IN CONST CHAR16 *StorageRoot,
IN OC_RSA_PUBLIC_KEY *StorageKey OPTIONAL
)
{
EFI_STATUS Status;
......@@ -228,7 +231,7 @@ OcStorageInitFromFs (
ASSERT (Context != NULL);
ASSERT (FileSystem != NULL);
ASSERT (Path != NULL);
ASSERT (StorageRoot != NULL);
ZeroMem (Context, sizeof (*Context));
......@@ -242,8 +245,8 @@ OcStorageInitFromFs (
Status = SafeFileOpen (
RootVolume,
&Context->StorageRoot,
(CHAR16 *) Path,
&Context->Storage,
(CHAR16 *) StorageRoot,
EFI_FILE_MODE_READ,
0
);
......@@ -251,7 +254,7 @@ OcStorageInitFromFs (
RootVolume->Close (RootVolume);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCST: Directory %s cannot be opened - %r\n", Path, Status));
DEBUG ((DEBUG_INFO, "OCST: Directory %s cannot be opened - %r\n", StorageRoot, Status));
return Status;
}
......@@ -287,11 +290,14 @@ OcStorageInitFromFs (
}
gBS->InstallProtocolInterface (
&Context->StorageHandle,
&Context->DummyStorageHandle,
&gEfiDevicePathProtocolGuid,
EFI_NATIVE_INTERFACE,
&mDummyBootDevicePath
);
Context->StorageHandle = StorageHandle;
Context->StoragePath = StoragePath;
Context->StorageRoot = StorageRoot;
Context->DummyDevicePath = &mDummyBootDeviceFilePath.Vendor.Header;
Context->DummyFilePath = &mDummyBootDeviceFilePath.VendorFile.Header;
......@@ -311,9 +317,9 @@ OcStorageFree (
IN OUT OC_STORAGE_CONTEXT *Context
)
{
if (Context->StorageRoot != NULL) {
Context->StorageRoot->Close (Context->StorageRoot);
Context->StorageRoot = NULL;
if (Context->Storage != NULL) {
Context->Storage->Close (Context->Storage);
Context->Storage = NULL;
}
if (Context->HasVault) {
......@@ -345,12 +351,12 @@ OcStorageExistsFileUnicode (
return TRUE;
}
if (Context->StorageRoot == NULL) {
if (Context->Storage == NULL) {
return FALSE;
}
Status = SafeFileOpen (
Context->StorageRoot,
Context->Storage,
&File,
(CHAR16 *) FilePath,
EFI_FILE_MODE_READ,
......@@ -393,7 +399,7 @@ OcStorageReadFileUnicode (
return NULL;
}
if (Context->StorageRoot == NULL) {
if (Context->Storage == NULL) {
//
// TODO: expand support for other contexts.
//
......@@ -401,7 +407,7 @@ OcStorageReadFileUnicode (
}
Status = SafeFileOpen (
Context->StorageRoot,
Context->Storage,
&File,
(CHAR16 *) FilePath,
EFI_FILE_MODE_READ,
......@@ -449,3 +455,80 @@ OcStorageReadFileUnicode (
return FileBuffer;
}
EFI_STATUS
OcStorageGetInfo (
IN OC_STORAGE_CONTEXT *Context,
IN CONST CHAR16 *FilePath,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath OPTIONAL,
OUT EFI_HANDLE *StorageHandle OPTIONAL,
OUT EFI_DEVICE_PATH_PROTOCOL **StoragePath OPTIONAL,
IN BOOLEAN RealPath
)
{
CHAR16 *FullPath;
UINTN RootLength;
UINTN FileSize;
if (RealPath
&& Context->StorageHandle != NULL
&& Context->StorageRoot != NULL
&& Context->StoragePath != NULL) {
//
// Set the storage handle right away.
//
*StorageHandle = Context->StorageHandle;
//
// Prepare file path.
//
RootLength = StrLen (Context->StorageRoot);
FileSize = StrSize (FilePath);
FullPath = AllocatePool (RootLength * sizeof (CHAR16) + sizeof (CHAR16) + FileSize);
if (FullPath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
CopyMem (&FullPath[0], Context->StorageRoot, RootLength * sizeof (CHAR16));
FullPath[RootLength] = '\\';
CopyMem (&FullPath[RootLength + 1], FilePath, FileSize);
//
// Set joint device path.
//
*DevicePath = AppendFileNameDevicePath (Context->StoragePath, FullPath);
if (*DevicePath == NULL) {
FreePool (FullPath);
return EFI_OUT_OF_RESOURCES;
}
//
// Set onstorage path.
//
*StoragePath = FileDevicePath (NULL, FullPath);
if (*StoragePath == NULL) {
FreePool (*DevicePath);
FreePool (FullPath);
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
*StorageHandle = Context->DummyStorageHandle;
*DevicePath = DuplicateDevicePath (Context->DummyDevicePath);
if (*DevicePath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*StoragePath = DuplicateDevicePath (Context->DummyFilePath);
if (*StoragePath == NULL) {
FreePool (*DevicePath);
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
......@@ -62,11 +62,15 @@ mOpenCorePrivilege;
STATIC
EFI_HANDLE
mLoadHandle;
mStorageHandle;
STATIC
EFI_DEVICE_PATH_PROTOCOL *
mStoragePath;
STATIC
CHAR16 *
mRootPath;
mStorageRoot;
STATIC
EFI_STATUS
......@@ -75,13 +79,16 @@ OcStartImage (
IN OC_BOOT_ENTRY *Chosen,
IN EFI_HANDLE ImageHandle,
OUT UINTN *ExitDataSize,
OUT CHAR16 **ExitData OPTIONAL
OUT CHAR16 **ExitData OPTIONAL,
IN BOOLEAN LaunchInText
)
{
EFI_STATUS Status;
EFI_CONSOLE_CONTROL_SCREEN_MODE OldMode;
OldMode = OcConsoleControlSetMode (EfiConsoleControlScreenGraphics);
OldMode = OcConsoleControlSetMode (
LaunchInText ? EfiConsoleControlScreenText : EfiConsoleControlScreenGraphics
);
Status = gBS->StartImage (
ImageHandle,
......@@ -124,7 +131,7 @@ OcMain (
DEBUG ((DEBUG_INFO, "OC: OcLoadNvramSupport...\n"));
OcLoadNvramSupport (Storage, &mOpenCoreConfiguration);
DEBUG ((DEBUG_INFO, "OC: OcMiscMiddleInit...\n"));
OcMiscMiddleInit (Storage, &mOpenCoreConfiguration, mRootPath, LoadPath, &mLoadHandle);
OcMiscMiddleInit (Storage, &mOpenCoreConfiguration, mStorageRoot, LoadPath, mStorageHandle);
DEBUG ((DEBUG_INFO, "OC: OcLoadUefiSupport...\n"));
OcLoadUefiSupport (Storage, &mOpenCoreConfiguration, &mOpenCoreCpuInfo);
DEBUG ((DEBUG_INFO, "OC: OcLoadAcpiSupport...\n"));
......@@ -157,7 +164,7 @@ OcMain (
Privilege,
OcStartImage,
mOpenCoreConfiguration.Uefi.Quirks.RequestBootVarRouting,
mLoadHandle
mStorageHandle
);
}
......@@ -170,7 +177,9 @@ OcBootstrapRerun (
IN EFI_DEVICE_PATH_PROTOCOL *LoadPath OPTIONAL
)
{
EFI_STATUS Status;
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *RemainingPath;
UINTN StoragePathSize;
DEBUG ((DEBUG_INFO, "OC: ReRun executed!\n"));
......@@ -183,36 +192,59 @@ OcBootstrapRerun (
// Calculate root path (never freed).
//
if (LoadPath != NULL) {
ASSERT (mRootPath == NULL);
mRootPath = OcCopyDevicePathFullName (LoadPath);
ASSERT (mStorageRoot == NULL);
mStorageRoot = OcCopyDevicePathFullName (LoadPath, &RemainingPath);
//
// Skipping this or later failing to call UnicodeGetParentDirectory means
// we got valid path to the root of the partition. This happens when
// OpenCore.efi was loaded from e.g. firmware and then bootstrapped
// on a different partition.
//
if (mRootPath != NULL) {
if (UnicodeGetParentDirectory (mRootPath)) {
if (mStorageRoot != NULL) {
if (UnicodeGetParentDirectory (mStorageRoot)) {
//
// This means we got valid path to ourselves.
//
DEBUG ((DEBUG_INFO, "OC: Got launch root path %s\n", mRootPath));
DEBUG ((DEBUG_INFO, "OC: Got launch root path %s\n", mStorageRoot));
} else {
FreePool (mRootPath);
mRootPath = NULL;
FreePool (mStorageRoot);
mStorageRoot = NULL;
}
}
}
if (mRootPath == NULL) {
mRootPath = OPEN_CORE_ROOT_PATH;
DEBUG ((DEBUG_INFO, "OC: Got default root path %s\n", mRootPath));
if (mStorageRoot == NULL) {
mStorageRoot = OPEN_CORE_ROOT_PATH;
RemainingPath = NULL;
DEBUG ((DEBUG_INFO, "OC: Got default root path %s\n", mStorageRoot));
}
//
// Calculate storage path.
//
if (RemainingPath != NULL) {
StoragePathSize = (UINTN) RemainingPath - (UINTN) LoadPath;
mStoragePath = AllocatePool (StoragePathSize + END_DEVICE_PATH_LENGTH);
if (mStoragePath != NULL) {
CopyMem (mStoragePath, LoadPath, StoragePathSize);
SetDevicePathEndNode ((UINT8 *) mStoragePath + StoragePathSize);
}
} else {
mStoragePath = NULL;
}
gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&LoadPath,
&mStorageHandle
);
Status = OcStorageInitFromFs (
&mOpenCoreStorage,
FileSystem,
mRootPath,
mStorageHandle,
mStoragePath,
mStorageRoot,
mOpenCoreVaultKey
);
......@@ -242,7 +274,7 @@ OcGetLoadHandle (
IN OC_BOOTSTRAP_PROTOCOL *This
)
{
return mLoadHandle;
return mStorageHandle;
}
STATIC
......
......@@ -170,9 +170,9 @@ OcToolLoadEntry (
IN OC_BOOT_ENTRY *ChosenEntry,
OUT VOID **Data,
OUT UINT32 *DataSize,
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath OPTIONAL,
OUT EFI_HANDLE *ParentDeviceHandle OPTIONAL,
OUT EFI_DEVICE_PATH_PROTOCOL **ParentFilePath OPTIONAL
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
OUT EFI_HANDLE *StorageHandle,
OUT EFI_DEVICE_PATH_PROTOCOL **StoragePath
)
{
EFI_STATUS Status;
......@@ -211,16 +211,18 @@ OcToolLoadEntry (
return EFI_NOT_FOUND;
}
if (DevicePath != NULL) {
*DevicePath = Storage->DummyDevicePath;
}
if (ParentDeviceHandle != NULL) {
*ParentDeviceHandle = Storage->StorageHandle;
}
if (ParentFilePath != NULL) {
*ParentFilePath = Storage->DummyFilePath;
Status = OcStorageGetInfo (
Storage,
ToolPath,
DevicePath,
StorageHandle,
StoragePath,
ChosenEntry->ExposeDevicePath
);
if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OC: Returning tool %s\n", ToolPath));
DebugPrintDevicePath (DEBUG_INFO, "OC: Tool path", *DevicePath);
DebugPrintDevicePath (DEBUG_INFO, "OC: Storage path", *StoragePath);
}
return EFI_SUCCESS;
......@@ -583,49 +585,36 @@ OcMiscEarlyInit (
return EFI_SUCCESS;
}
EFI_STATUS
VOID
OcMiscMiddleInit (
IN OC_STORAGE_CONTEXT *Storage,
IN OC_GLOBAL_CONFIG *Config,
IN CONST CHAR16 *RootPath OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *LoadPath OPTIONAL,
OUT EFI_HANDLE *LoadHandle
IN EFI_HANDLE LoadHandle OPTIONAL
)
{
EFI_STATUS Status;
CONST CHAR8 *BootProtect;
UINT32 BootProtectFlag;
CHAR16 *BootstrapPath;
UINTN BootstrapSize;
EFI_HANDLE OcHandle;
if ((Config->Misc.Security.ExposeSensitiveData & OCS_EXPOSE_BOOT_PATH) != 0) {
OcStoreLoadPath (LoadPath);
}
OcHandle = NULL;
if (LoadPath != NULL) {
Status = gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&LoadPath,
&OcHandle
);
} else {
Status = EFI_UNSUPPORTED;
}
BootProtect = OC_BLOB_GET (&Config->Misc.Security.BootProtect);
DEBUG ((DEBUG_INFO, "OC: LoadHandle %p with BootProtect in %a mode - %r\n", OcHandle, BootProtect, Status));
DEBUG ((DEBUG_INFO, "OC: LoadHandle %p with BootProtect in %a mode\n", LoadHandle, BootProtect));
BootProtectFlag = Config->Uefi.Quirks.RequestBootVarRouting ? OC_BOOT_PROTECT_VARIABLE_NAMESPACE : 0;
if (OcHandle != NULL && AsciiStrCmp (BootProtect, "Bootstrap") == 0) {
if (LoadHandle != NULL && AsciiStrCmp (BootProtect, "Bootstrap") == 0) {
ASSERT (RootPath != NULL);
BootstrapSize = StrSize (RootPath) + StrSize (OPEN_CORE_BOOTSTRAP_PATH);
BootstrapPath = AllocatePool (BootstrapSize);
if (BootstrapPath != NULL) {
UnicodeSPrint (BootstrapPath, BootstrapSize, L"%s\\%s", RootPath, OPEN_CORE_BOOTSTRAP_PATH);
OcRegisterBootOption (L"OpenCore", OcHandle, BootstrapPath);
OcRegisterBootOption (L"OpenCore", LoadHandle, BootstrapPath);
BootProtectFlag = OC_BOOT_PROTECT_VARIABLE_BOOTSTRAP;
FreePool (BootstrapPath);
}
......@@ -642,15 +631,11 @@ OcMiscMiddleInit (
&BootProtectFlag
);
*LoadHandle = OcHandle;
DEBUG_CODE_BEGIN ();
if (OcHandle != NULL && Config->Misc.Debug.SysReport) {
ProduceDebugReport (OcHandle);
if (LoadHandle != NULL && Config->Misc.Debug.SysReport) {
ProduceDebugReport (LoadHandle);
}
DEBUG_CODE_END ();
return Status;
}
EFI_STATUS
......@@ -872,6 +857,8 @@ OcMiscBoot (
Context->CustomEntries[EntryIndex].Arguments = OC_BLOB_GET (&Config->Misc.Entries.Values[Index]->Arguments);
Context->CustomEntries[EntryIndex].Auxiliary = Config->Misc.Entries.Values[Index]->Auxiliary;
Context->CustomEntries[EntryIndex].Tool = FALSE;
Context->CustomEntries[EntryIndex].TextMode = Config->Misc.Entries.Values[Index]->TextMode;
Context->CustomEntries[EntryIndex].RealPath = TRUE; ///< Always true for entries
++EntryIndex;
}
}
......@@ -888,6 +875,8 @@ OcMiscBoot (
Context->CustomEntries[EntryIndex].Arguments = OC_BLOB_GET (&Config->Misc.Tools.Values[Index]->Arguments);
Context->CustomEntries[EntryIndex].Auxiliary = Config->Misc.Tools.Values[Index]->Auxiliary;
Context->CustomEntries[EntryIndex].Tool = TRUE;
Context->CustomEntries[EntryIndex].TextMode = Config->Misc.Tools.Values[Index]->TextMode;
Context->CustomEntries[EntryIndex].RealPath = Config->Misc.Tools.Values[Index]->RealPath;
++EntryIndex;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册