summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-03-27 09:22:19 -0400
committerTom Rini <[email protected]>2022-03-27 09:22:19 -0400
commitc259b197f6f8a4b1d33700e0b9202781fb8ce737 (patch)
tree7e577aaf7d3f19b6eeffd977f47fdd4f8984ed12 /lib
parent28c2ebef372b4c9bb18bed8373e0d9e65a09b42b (diff)
parentccc41fcfaf33356f7789c8bd50551a9e37507f2d (diff)
Merge tag 'efi-2022-04-rc5-2' of https://source.denx.de/u-boot/custodians/u-boot-efi
Pull request for efi-2022-04-rc5-2 Documentation: * man-page for the wdt command UEFI: * Unit test for boot manager
Diffstat (limited to 'lib')
-rw-r--r--lib/efi_loader/efi_device_path.c2
-rw-r--r--lib/efi_loader/initrddump.c91
2 files changed, 79 insertions, 14 deletions
diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c
index 0a8802903d7..0542aaae16c 100644
--- a/lib/efi_loader/efi_device_path.c
+++ b/lib/efi_loader/efi_device_path.c
@@ -137,7 +137,7 @@ int efi_dp_match(const struct efi_device_path *a,
*
* See UEFI spec (section 3.1.2, about short-form device-paths)
*
- * @dp: original devie-path
+ * @dp: original device-path
* @Return: shortened device-path or NULL
*/
struct efi_device_path *efi_dp_shorten(struct efi_device_path *dp)
diff --git a/lib/efi_loader/initrddump.c b/lib/efi_loader/initrddump.c
index 7de43bcfff4..98721069816 100644
--- a/lib/efi_loader/initrddump.c
+++ b/lib/efi_loader/initrddump.c
@@ -4,6 +4,9 @@
*
* initrddump.efi saves the initial RAM disk provided via the
* EFI_LOAD_FILE2_PROTOCOL.
+ *
+ * Specifying 'nocolor' as load option data suppresses colored output and
+ * clearing of the screen.
*/
#include <common.h>
@@ -25,6 +28,7 @@ static const efi_guid_t guid_simple_file_system_protocol =
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
static const efi_guid_t load_file2_guid = EFI_LOAD_FILE2_PROTOCOL_GUID;
static efi_handle_t handle;
+static bool nocolor;
/*
* Device path defined by Linux to identify the handle providing the
@@ -47,6 +51,17 @@ static const struct efi_initrd_dp initrd_dp = {
};
/**
+ * color() - set foreground color
+ *
+ * @color: foreground color
+ */
+static void color(u8 color)
+{
+ if (!nocolor)
+ cout->set_attribute(cout, color | EFI_BACKGROUND_BLACK);
+}
+
+/**
* print() - print string
*
* @string: text
@@ -57,15 +72,26 @@ static void print(u16 *string)
}
/**
+ * cls() - clear screen
+ */
+static void cls(void)
+{
+ if (nocolor)
+ print(u"\r\n");
+ else
+ cout->clear_screen(cout);
+}
+
+/**
* error() - print error string
*
* @string: error text
*/
static void error(u16 *string)
{
- cout->set_attribute(cout, EFI_LIGHTRED | EFI_BACKGROUND_BLACK);
+ color(EFI_LIGHTRED);
print(string);
- cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK);
+ color(EFI_LIGHTBLUE);
}
/*
@@ -95,6 +121,14 @@ static void printx(u64 val, u32 prec)
}
/**
+ * efi_drain_input() - drain console input
+ */
+static void efi_drain_input(void)
+{
+ cin->reset(cin, true);
+}
+
+/**
* efi_input_yn() - get answer to yes/no question
*
* Return:
@@ -111,8 +145,6 @@ static efi_status_t efi_input_yn(void)
efi_uintn_t index;
efi_status_t ret;
- /* Drain the console input */
- ret = cin->reset(cin, true);
for (;;) {
ret = bs->wait_for_event(1, &cin->wait_for_key, &index);
if (ret != EFI_SUCCESS)
@@ -153,8 +185,6 @@ static efi_status_t efi_input(u16 *buffer, efi_uintn_t buffer_size)
u16 outbuf[2] = u" ";
efi_status_t ret;
- /* Drain the console input */
- ret = cin->reset(cin, true);
*buffer = 0;
for (;;) {
ret = bs->wait_for_event(1, &cin->wait_for_key, &index);
@@ -215,10 +245,13 @@ static u16 *skip_whitespace(u16 *pos)
*
* @string: string to search for keyword
* @keyword: keyword to be searched
- * Return: true fi @string starts with the keyword
+ * Return: true if @string starts with the keyword
*/
static bool starts_with(u16 *string, u16 *keyword)
{
+ if (!string || !keyword)
+ return false;
+
for (; *keyword; ++string, ++keyword) {
if (*string != *keyword)
return false;
@@ -364,6 +397,7 @@ static efi_status_t do_save(u16 *filename)
ret = root->open(root, &file, filename, EFI_FILE_MODE_READ, 0);
if (ret == EFI_SUCCESS) {
file->close(file);
+ efi_drain_input();
print(u"Overwrite existing file (y/n)? ");
ret = efi_input_yn();
print(u"\r\n");
@@ -401,6 +435,30 @@ out:
}
/**
+ * get_load_options() - get load options
+ *
+ * Return: load options or NULL
+ */
+u16 *get_load_options(void)
+{
+ efi_status_t ret;
+ struct efi_loaded_image *loaded_image;
+
+ ret = bs->open_protocol(handle, &loaded_image_guid,
+ (void **)&loaded_image, NULL, NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (ret != EFI_SUCCESS) {
+ error(u"Loaded image protocol not found\r\n");
+ return NULL;
+ }
+
+ if (!loaded_image->load_options_size || !loaded_image->load_options)
+ return NULL;
+
+ return loaded_image->load_options;
+}
+
+/**
* efi_main() - entry point of the EFI application.
*
* @handle: handle of the loaded image
@@ -410,24 +468,30 @@ out:
efi_status_t EFIAPI efi_main(efi_handle_t image_handle,
struct efi_system_table *systab)
{
+ u16 *load_options;
+
handle = image_handle;
systable = systab;
cerr = systable->std_err;
cout = systable->con_out;
cin = systable->con_in;
bs = systable->boottime;
+ load_options = get_load_options();
- cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK);
- cout->clear_screen(cout);
- cout->set_attribute(cout, EFI_WHITE | EFI_BACKGROUND_BLACK);
+ if (starts_with(load_options, u"nocolor"))
+ nocolor = true;
+
+ color(EFI_WHITE);
+ cls();
print(u"INITRD Dump\r\n===========\r\n\r\n");
- cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK);
+ color(EFI_LIGHTBLUE);
for (;;) {
u16 command[BUFFER_SIZE];
u16 *pos;
efi_uintn_t ret;
+ efi_drain_input();
print(u"=> ");
ret = efi_input(command, sizeof(command));
if (ret == EFI_ABORTED)
@@ -443,7 +507,8 @@ efi_status_t EFIAPI efi_main(efi_handle_t image_handle,
do_help();
}
- cout->set_attribute(cout, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK);
- cout->clear_screen(cout);
+ color(EFI_LIGHTGRAY);
+ cls();
+
return EFI_SUCCESS;
}