summaryrefslogtreecommitdiff
path: root/lib/efi_loader
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2025-05-11 08:36:37 -0600
committerTom Rini <trini@konsulko.com>2025-05-11 08:36:37 -0600
commitfa51a4d57d910df4f3beffa5d3e1d61a1d5d824b (patch)
tree02a816537f5f381c7a43ca342f9f02872d04592e /lib/efi_loader
parentfeb55165233623648cb0a74953735b00ec6e322e (diff)
parent8fdb8740b39b01d182137d437f2d1d16b526a4b5 (diff)
Merge tag 'efi-2025-07-rc3' of https://source.denx.de/u-boot/custodians/u-boot-efi
Pull-request efi-2025-07-rc3 CI: * https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/26146 Documentation: * Improve the pytest documentation * u-boot-test-reset: mention power cycling * describe u-boot-test-release * correct link to QEMU * describe that RISC-V supports semihosting UEFI: * link libggc via PLATFORM_LIBGCC to EFI binaries * allow suppressing ANSI output in dtbdump.efi * test/py/test_efi_fit: test fdt and initrd # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEEK7wKXt3/btL6/yA+hO4vgnE3U0sFAmggj+IACgkQhO4vgnE3 # U0sjTBAAkWySSBNFoj12AyjO2h4kJecxiJJxyoMYTcsr3xdgV0WTPQFaWcSBqTsL # NgKq5KFNe+ywUdDIqU1VLOTcQf298hofRrcp5Gfhv+syZaRCorCSoSJI6ZveZ5Bi # 9N2pPvhEVrlFBF2XannJ5ilYtLAbiqIvVFmdLmFwRPbODv/gfEkSudSy0Za7t1tM # c7RoRegpXziY4Y1XPfr3MpXgKpUQkOPnvXKUwtHhL055X/1Ggg87dzPg1fiU+DiQ # AGAgvGD/KF/ym4aWQ3jWyji8Kxc5BLsurv083it7JAmL82wqNbU9j5cx3mS/f2Le # uL7YWv1GANbq+MoBC5O3nkB+yUtHSLylFC3KKFiehmKhc/JO+Uj3cJY/Q/25+lxs # aahG3C/5xgBTgM6YEqJfSqKYQVFsC2V/a7gWAFlX7OidYXm6oDBu4TeAHmAtBgcj # pz0AVCYMWyhKE+zb+4U2mlKEQ8bJpFdC2Q+pTMciGAM3YyztotJ1yoM4IndDrh4q # ScrIpXHSqWLlZfev+NnJDw1UKLWEJIMeXh0uzfpaT5M0cLEDeHTOSX9Fp3ZPj9Af # +T3nNWSXWlOW0wc6C5igj4p0UiGSbHMMPOa54f/D0gdl/UkPZ1YPBYVBa/eX1yBy # NlaJziLCmLqyWpYIVhaigKDtGWfgjoHGaABfyuSIj/HxmIHhD5w= # =NbGi # -----END PGP SIGNATURE----- # gpg: Signature made Sun 11 May 2025 05:54:10 AM CST # gpg: using RSA key 2BBC0A5EDDFF6ED2FAFF203E84EE2F827137534B # gpg: Can't check signature: No public key
Diffstat (limited to 'lib/efi_loader')
-rw-r--r--lib/efi_loader/dtbdump.c86
1 files changed, 74 insertions, 12 deletions
diff --git a/lib/efi_loader/dtbdump.c b/lib/efi_loader/dtbdump.c
index a3d59a2fd3b..1e72404ecc1 100644
--- a/lib/efi_loader/dtbdump.c
+++ b/lib/efi_loader/dtbdump.c
@@ -29,6 +29,18 @@ static struct efi_system_table *systable;
static const efi_guid_t efi_dt_fixup_protocol_guid = EFI_DT_FIXUP_PROTOCOL_GUID;
static const efi_guid_t efi_file_info_guid = EFI_FILE_INFO_GUID;
static const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID;
+static bool nocolor;
+
+/**
+ * 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
@@ -88,15 +100,34 @@ static void printx(unsigned char val)
}
/**
+ * 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);
+}
+
+/**
+ * efi_drain_input() - drain console input
+ */
+static void efi_drain_input(void)
+{
+ cin->reset(cin, true);
}
/**
@@ -116,8 +147,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)
@@ -158,8 +187,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);
@@ -262,6 +289,9 @@ static u16 *skip_whitespace(u16 *pos)
*/
static bool starts_with(u16 *string, u16 *keyword)
{
+ if (!string || !keyword)
+ return false;
+
for (; *keyword; ++string, ++keyword) {
if (*string != *keyword)
return false;
@@ -737,6 +767,7 @@ static efi_status_t do_dump(void)
error(u"Missing end node\r\n");
return EFI_LOAD_ERROR;
}
+ print(u"\r\n");
return EFI_SUCCESS;
default:
error(u"Invalid device tree token\r\n");
@@ -749,6 +780,30 @@ static efi_status_t do_dump(void)
}
/**
+ * get_load_options() - get load options
+ *
+ * Return: load options or NULL
+ */
+static 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
@@ -758,24 +813,31 @@ static efi_status_t do_dump(void)
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();
+
+ if (starts_with(load_options, u"nocolor"))
+ nocolor = true;
- cout->set_attribute(cout, EFI_LIGHTBLUE | EFI_BACKGROUND_BLACK);
- cout->clear_screen(cout);
- cout->set_attribute(cout, EFI_WHITE | EFI_BACKGROUND_BLACK);
+ color(EFI_LIGHTBLUE);
+ cls();
+ color(EFI_WHITE);
print(u"DTB 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)
@@ -793,7 +855,7 @@ 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;
}