Skip to content

Commit

Permalink
OpenLinuxBoot: Non-'+' user options should also override LINUX_BOOT_A…
Browse files Browse the repository at this point in the history
…DD_RO
  • Loading branch information
mikebeaton committed Sep 14, 2021
1 parent e316aac commit 91859ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ OpenCore Changelog
==================
#### v0.7.4
- Fixed Linux kernel sort order
- Added Linux boot optional log detail
- Added Linux detection optional log detail
- Fixed CPU core count detection for more legacy CPUs
- Added ability to fully override autodetect Linux boot options

#### v0.7.3
- Improved SSDT-PNLF compatibility with CFL+ graphics
Expand Down
57 changes: 36 additions & 21 deletions Platform/OpenLinuxBoot/Autodetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "LinuxBootInternal.h"

#include <Uefi.h>
#include <Guid/Gpt.h>
#include <Library/BaseLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
Expand Down Expand Up @@ -329,17 +330,10 @@ AutodetectBootOptions (
CHAR8 *AsciiStrValue;
CHAR8 *GrubVarName;
CHAR8 **NewOption;
BOOLEAN Found;
BOOLEAN FoundOptions;
BOOLEAN PlusOpts;

if ((gLinuxBootFlags & LINUX_BOOT_ADD_RO) != 0) {
DEBUG (((gLinuxBootFlags & LINUX_BOOT_LOG_VERBOSE) == 0 ? DEBUG_VERBOSE : DEBUG_INFO,
"LNX: Adding \"ro\"\n"));
Status = AddOption (Options, "ro", FALSE);
}

Found = FALSE;
InsertIndex = Options->Count;
FoundOptions = FALSE;

//
// Look for user-specified options for this partuuid.
Expand Down Expand Up @@ -383,7 +377,7 @@ AutodetectBootOptions (
return EFI_SUCCESS;
}

Found = TRUE;
FoundOptions = TRUE;
}
}
}
Expand All @@ -396,7 +390,7 @@ AutodetectBootOptions (
//
// Don't use autoopts if partition specific partuuidopts already found.
//
if (!Found && StrCmp (Option->Unicode.Name, L"autoopts") == 0) {
if (!FoundOptions && StrCmp (Option->Unicode.Name, L"autoopts") == 0) {
if (Option->Unicode.Value == NULL) {
DEBUG ((DEBUG_WARN, "LNX: Missing value for %s\n", Option->Unicode.Name));
continue;
Expand All @@ -421,14 +415,19 @@ AutodetectBootOptions (
return Status;
}

Found = TRUE;
FoundOptions = TRUE;
}
}

//
// Use options from GRUB default location.
//
if (mEtcDefaultGrubOptions != NULL) {
//
// Insert these after "ro" but before any user specified opts.
//
InsertIndex = 0;

//
// If both are present both should be added, standard grub scripts add them
// in this order.
Expand All @@ -452,16 +451,13 @@ AutodetectBootOptions (
DEBUG (((gLinuxBootFlags & LINUX_BOOT_LOG_VERBOSE) == 0 ? DEBUG_VERBOSE : DEBUG_INFO,
"LNX: Using %a=\"%a\"\n", GrubVarName, AsciiStrValue));

//
// Insert these after "ro" but any user specified opts.
//
if (AsciiStrValue[0] != '\0') {
Status = InsertOption (InsertIndex, Options, AsciiStrValue, FALSE);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Must not bump this if empty option.
// Must not increment insert index if empty option.
//
InsertIndex++;
}
Expand All @@ -470,32 +466,51 @@ AutodetectBootOptions (
// Empty string value is good enough for found: we are operating
// from GRUB cfg files rather than pure guesswork.
//
Found = TRUE;
FoundOptions = TRUE;
}
}
}

//
// It might be valid to have no options except "ro", but at least empty
// string "GRUB_CMDLINE_LINUX" needs to be present in that case or we stop.
// (not missing) user specified options, or GRUB_CMDLINE_LINUX_... needs
// to be present in that case or we stop.
//
if (!Found) {
if (!FoundOptions) {
DEBUG ((DEBUG_WARN, "LNX: No grub default or user defined options - aborting\n"));
return EFI_INVALID_PARAMETER;
}

//
// Insert root=PARTUUID=... option if we get to here.
// Insert "root=PARTUUID=..." option, followed by "ro" if requested, only if we get to here.
//
if (CompareGuid (&gPartuuid, &gEfiPartTypeUnusedGuid)) {
Status = EFI_UNSUPPORTED;
DEBUG ((DEBUG_WARN, "LNX: Cannot autodetect root on MBR partition - %r\n", Status));
return Status;
}
DEBUG (((gLinuxBootFlags & LINUX_BOOT_LOG_VERBOSE) == 0 ? DEBUG_VERBOSE : DEBUG_INFO,
"LNX: Creating \"root=PARTUUID=%g\"\n", gPartuuid));

NewOption = OcFlexArrayInsertItem (Options, 0);
InsertIndex = 0;

NewOption = OcFlexArrayInsertItem (Options, InsertIndex);
if (NewOption == NULL) {
return EFI_OUT_OF_RESOURCES;
}
++InsertIndex;

Status = CreateRootPartuuid (NewOption);
if (EFI_ERROR (Status)) {
return Status;
}

if ((gLinuxBootFlags & LINUX_BOOT_ADD_RO) != 0) {
DEBUG (((gLinuxBootFlags & LINUX_BOOT_LOG_VERBOSE) == 0 ? DEBUG_VERBOSE : DEBUG_INFO,
"LNX: Adding \"ro\"\n"));
Status = InsertOption (InsertIndex, Options, "ro", FALSE);
}

return Status;
}

Expand Down

0 comments on commit 91859ce

Please sign in to comment.