[PATCH 2/3] Add hot-key to alter bootargs during boot

3 views
Skip to first unread message

Andreas J. Reichel

unread,
Oct 25, 2018, 9:51:15 AM10/25/18
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

Give the user a chance to override kernel arguments.
EBG waits for 3 seconds and checks if user pressed the <a> key.
This can help in unbricking a system.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>
---
main.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/main.c b/main.c
index 0d5f14b..f0fcaff 100644
--- a/main.c
+++ b/main.c
@@ -21,6 +21,7 @@
#include <bootguard.h>
#include <configuration.h>
#include "version.h"
+#include "envdata.h"
#include "color.h"

extern const unsigned long init_array_start[];
@@ -108,6 +109,8 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
BG_STATUS bg_status;
BG_LOADER_PARAMS bg_loader_params;
CHAR16 *tmp;
+ EFI_INPUT_KEY key;
+ CHAR16 input_buffer[ENV_STRING_LENGTH];

ZeroMem(&bg_loader_params, sizeof(bg_loader_params));

@@ -198,11 +201,31 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
status);
}

+ /* Give user a chance to change the boot parameters on the fly */
+ Color(system_table, 15, 0);
+ Print(L"Press <a> to change kernel arguments\n");
+ Color(system_table, 7, 0);
+
+ /* Wait for key for 3 seconds */
+ WaitForSingleEvent(system_table->ConIn->WaitForKey, 30000000);
+
+ input_buffer[0] = L'\0';
+ if (uefi_call_wrapper(system_table->ConIn->ReadKeyStroke,
+ 2, system_table->ConIn, &key) == EFI_SUCCESS) {
+ if (key.UnicodeChar == L'a') {
+ Input(L"\nInput kernel args (empty str to cancel): ",
+ input_buffer, ENV_STRING_LENGTH - 1);
+ }
+ }
+ if (StrLen(input_buffer) > 0) {
+ StrCpy(bg_loader_params.payload_options, input_buffer);
+ }
+
loaded_image->LoadOptions = bg_loader_params.payload_options;
loaded_image->LoadOptionsSize =
(StrLen(bg_loader_params.payload_options) + 1) * sizeof(CHAR16);

- Print(L"Starting %s with watchdog set to %d seconds\n",
+ Print(L"\nStarting %s with watchdog set to %d seconds\n",
bg_loader_params.payload_path, bg_loader_params.timeout);

return uefi_call_wrapper(BS->StartImage, 3, payload_handle, 0, 0);
--
2.19.1

Jan Kiszka

unread,
Oct 25, 2018, 10:01:19 AM10/25/18
to [ext] Andreas J. Reichel, efibootg...@googlegroups.com
On 25.10.18 14:44, [ext] Andreas J. Reichel wrote:
> From: Andreas Reichel <andreas.r...@siemens.com>
>
> Give the user a chance to override kernel arguments.
> EBG waits for 3 seconds and checks if user pressed the <a> key.
> This can help in unbricking a system.

No, we don't want to do that unconditionally. This is primarily a debugging
tool, and there should be a switch - just like in all other bootloaders - to
enable that if desired.

Jan
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
Reply all
Reply to author
Forward
0 new messages