Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ lookup table in the .hwids section of the kernel image.
If a match is found it loads the corresponding device tree from the
.dtbauto section before jumping tothe bundled kernel.

## Command-line parameters

- `debug`: Enable debug logging
- `stubble.dtb_override=true/false`: Enable or disable device-tree compat based dtb lookup. The default is `true`.

## Dependencies

```
Expand Down
2 changes: 2 additions & 0 deletions include/pe.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "efi.h"

extern bool dtb_override;

/* This is the actual PE format of the section header */
typedef struct PeSectionHeader {
uint8_t Name[8];
Expand Down
15 changes: 14 additions & 1 deletion pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
# define TARGET_MACHINE_TYPE_COMPATIBILITY 0
#endif

bool dtb_override = true;

typedef struct DosFileHeader {
uint8_t Magic[2];
uint16_t LastSize;
Expand Down Expand Up @@ -203,7 +205,18 @@ static bool pe_use_this_dtb(

EFI_STATUS err;

/* Do nothing if a firmware dtb exists */
if (dtb_override == true) {
err = devicetree_match(dtb, dtb_size);
if (err == EFI_SUCCESS) {
log_debug("found device-tree based on compatible: %s",
devicetree_get_compatible(dtb));
return true;
}
if (err != EFI_UNSUPPORTED)
return false;
}

/* Do nothing if a firmware dtb exists */
const void *fw_dtb = find_configuration_table(MAKE_GUID_PTR(EFI_DTB_TABLE));
if (fw_dtb)
return false;
Expand Down
32 changes: 24 additions & 8 deletions stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@

DECLARE_SBAT(SBAT_STUB_SECTION_TEXT);

static void parse_cmdline(char16_t *p) {
static bool parse_string(char16_t *p, const char16_t *opt) {
const size_t opt_len = strlen16(opt);
if (strncmp16(p, opt, opt_len) == 0 &&
(p[opt_len] == ' ' ||
p[opt_len] == '\0'))
return true;
return false;
}

static void parse_cmdline(char16_t *p) {
assert(p);

while (*p != '\0') {
const char16_t *debug = L"debug";
size_t debug_len = strlen16(debug);
if (strncmp16(p, debug, debug_len) == 0 &&
(p[debug_len] == ' ' ||
p[debug_len] == '\0'))
if (parse_string(p, L"debug")) {
log_isdebug = true;

} else if (strncmp16(p, L"stubble.dtb_override=",
strlen16(L"stubble.dtb_override=")) == 0) {
p += strlen16(L"stubble.dtb_override=");
if (parse_string(p, L"true")) {
dtb_override = true;
} else if (parse_string(p, L"false")) {
dtb_override = false;
}
}
p = strchr16(p, ' ');
if (p == NULL)
return;
Expand Down Expand Up @@ -155,6 +166,11 @@ static EFI_STATUS run(EFI_HANDLE image) {
* as potential command line to use. */
(void) process_arguments(image, loaded_image, &cmdline);
parse_cmdline(cmdline);
if (log_isdebug == true) {
log_debug("Stubble configuration:");
log_debug("debug: enabled");
log_debug("dtb_override: %s", dtb_override ? "enabled" : "disabled");
}

/* Find the sections we want to operate on */
err = find_sections(loaded_image, sections);
Expand Down