This was supposed to be in reply to Patrick's comment on patch 1/4 of my previous set, but I missed a letter at the end of the message ID. Oops.

---
Cal

On 06/14/2017 06:47 PM, California Sullivan wrote:
Allows you to modify the command line when called from EFI shell
instead of the entire command line getting replaced.

Signed-off-by: California Sullivan <[email protected]>
---
I liked this idea so I gave it a shot. Let me know what you think.
Commit message is a WIP. Its getting late but I'd like some feedback.

  ...ub-allow-smarter-command-line-modificatio.patch | 132 +++++++++++++++++++++
  .../systemd-boot/systemd-boot_%.bbappend           |   1 +
  2 files changed, 133 insertions(+)
  create mode 100644 
common/recipes-bsp/systemd-boot/systemd-boot/0001-boot-efi-stub-allow-smarter-command-line-modificatio.patch

diff --git 
a/common/recipes-bsp/systemd-boot/systemd-boot/0001-boot-efi-stub-allow-smarter-command-line-modificatio.patch
 
b/common/recipes-bsp/systemd-boot/systemd-boot/0001-boot-efi-stub-allow-smarter-command-line-modificatio.patch
new file mode 100644
index 0000000..9cc92c9
--- /dev/null
+++ 
b/common/recipes-bsp/systemd-boot/systemd-boot/0001-boot-efi-stub-allow-smarter-command-line-modificatio.patch
@@ -0,0 +1,132 @@
+From 47a4ce351911625f227b8b29d9c307d5c32fd32f Mon Sep 17 00:00:00 2001
+From: California Sullivan <[email protected]>
+Date: Wed, 14 Jun 2017 17:33:30 -0700
+Subject: [PATCH] boot: efi: stub: allow smarter command line modifications
+
+Currently, the command line is replaced with anything that ends up in
+LoadOptions. LoadOptions gets populated by the firmware, and EFI shell
+command line information when running a binary. This includes the name
+of the binary itself, so it will usually break booting from the EFI
+shell.
+
+Instead, have LoadOptions modify the command line in the following way:
+
+bootx64 root=/dev/sda -> prepend the command line (default)
+bootx64 ^console=/dev/tty0 -> prepend the command line (explicit)
+bootx64 $console=/dev/tty0 -> append the command line
+bootx64 !console=/dev/tty0 root=/dev/sda -> replace the command line
+
+The '^', '$' and '!' characters act as sentinel values, telling the EFI
+stub how to handle LoadOptions values, as well as indicating where
+command line modifications in LoadOptions should begin.
+
+Note that with the default case, bootx64 will end up in the kernel
+command line, as we use the sentinel values to decide where to begin the
+command line modifications.
+
+Signed-off-by: California Sullivan <[email protected]>
+---
+ src/boot/efi/stub.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++---
+ 1 file changed, 78 insertions(+), 4 deletions(-)
+
+diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c
+index 74e95fd..a4b34a2 100644
+--- a/src/boot/efi/stub.c
++++ b/src/boot/efi/stub.c
+@@ -93,15 +93,89 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE 
*sys_table) {
+         /* if we are not in secure boot mode, accept a custom command line 
and replace the built-in one */
+         if (!secure && loaded_image->LoadOptionsSize > 0 && *(CHAR16 
*)loaded_image->LoadOptions != 0) {
+                 CHAR16 *options;
++                CHAR8 mode;
+                 CHAR8 *line;
++                UINTN options_len;
++                UINTN total_len;
+                 UINTN i;
++                UINTN j;
++                UINTN k;
+
+                 options = (CHAR16 *)loaded_image->LoadOptions;
+-                cmdline_len = (loaded_image->LoadOptionsSize / 
sizeof(CHAR16)) * sizeof(CHAR8);
+-                line = AllocatePool(cmdline_len);
+-                for (i = 0; i < cmdline_len; i++)
+-                        line[i] = options[i];
++                options_len = (loaded_image->LoadOptionsSize / 
sizeof(CHAR16)) * sizeof(CHAR8);
++
++                mode = '?';
++                /* walk through options to find sentinel values indicating 
alternative modes
++                * also use this index to begin the command line changes
++                * this lets us avoid adding the binary name to the command 
line */
++                for(i = 0; i < options_len; i++) {
++                        if (options[i] == '$' ||
++                            options[i] == '!' ||
++                            options[i] == '^') {
++                                mode = options[i];
++                                break;
++                        }
++                }
++
++                switch(mode) {
++
++                /* append to the cmdline */
++                case '$':
++                        total_len = cmdline_len + options_len - i + 1;
++                        i++;
++                        line = AllocatePool(total_len);
++                        for (j = 0; j < cmdline_len; j++)
++                                line[j] = cmdline[j];
++
++                        line[j++] = ' ';
++
++                        for (k = 0; i + k < options_len && j + k < total_len; 
k++)
++                                line[j + k] = options[i + k];
++
++                        break;
++
++                /* replace the cmdline */
++                case '!':
++                        total_len = options_len - i;
++                        i++;
++                        line = AllocatePool(total_len);
++                        for (j = 0; i + j < options_len; j++)
++                                line[j] = options[i + j];
++                        break;
++
++                /* prepend to cmdline */
++                case '^':
++                        total_len = cmdline_len + options_len - i;
++                        i++;
++                        line = AllocatePool(total_len);
++
++                        /* Ignore null character at last index */
++                        for (j = 0; i + j < options_len - 1; j++)
++                                line[j] = options[i + j];
++
++                        line[j++] = ' ';
++
++                        for (k = 0; k < cmdline_len && j + k < total_len; k++)
++                                line[j + k] = cmdline[k];
++                        break;
++
++                /* prepend anyway, but don't get rid of binary name since we 
couldn't find a sentinel */
++                default:
++                        total_len = cmdline_len + options_len;
++                        line = AllocatePool(total_len);
++                        /* Ignore null character at last index */
++                        for (i = 0; i < options_len - 1; i++)
++                                line[i] = options[i];
++
++                        line[i++] = ' ';
++
++                        for (j = 0; j < cmdline_len && i + j < total_len; j++)
++                                line[i + j] = cmdline[j];
++                        break;
++                }
++
+                 cmdline = line;
++                cmdline_len = total_len;
+
+ #ifdef SD_BOOT_LOG_TPM
+                 /* Try to log any options to the TPM, escpecially manually 
edited options */
+--
+2.5.5
+
diff --git a/common/recipes-bsp/systemd-boot/systemd-boot_%.bbappend 
b/common/recipes-bsp/systemd-boot/systemd-boot_%.bbappend
index 98eaf45..05bc490 100644
--- a/common/recipes-bsp/systemd-boot/systemd-boot_%.bbappend
+++ b/common/recipes-bsp/systemd-boot/systemd-boot_%.bbappend
@@ -21,6 +21,7 @@ SRC_URI_append_intel-x86-common = " \
              
file://0004-sd-boot-Support-global-kernel-command-line-fragment-in-EFI-stub.patch
 \
              file://0001-efi-boot.c-workaround-for-Joule-BIOS-hang.patch \
              file://0001-sd-boot-stub-check-LoadOptions-contains-data.patch \
+            
file://0001-boot-efi-stub-allow-smarter-command-line-modificatio.patch \
              "
PACKAGE_ARCH_intel-x86-common = "${INTEL_COMMON_PACKAGE_ARCH}"

--
_______________________________________________
meta-intel mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/meta-intel

Reply via email to