Set up a timer event and the WaitForKey event.
In the notify function of the timer event check for console input
and signal the WaitForKey event accordingly.

Signed-off-by: Heinrich Schuchardt <xypron.g...@gmx.de>
---
v2
        dynamically register events to monitor the serial console
        input
---
 cmd/bootefi.c                 |  1 +
 include/efi_loader.h          |  6 +++++-
 lib/efi_loader/efi_boottime.c |  2 +-
 lib/efi_loader/efi_console.c  | 40 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 966d001d41..cf717564c4 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -112,6 +112,7 @@ static void efi_init_obj_list(void)
        efi_obj_list_initalized = 1;
        list_add_tail(&loaded_image_info_obj.link, &efi_obj_list);
        list_add_tail(&bootefi_device_obj.link, &efi_obj_list);
+       efi_console_register();
 #ifdef CONFIG_PARTITIONS
        efi_disk_register();
 #endif
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 342e960d14..2abb6b87e1 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -26,7 +26,7 @@ extern struct efi_runtime_services efi_runtime_services;
 extern struct efi_system_table systab;
 
 extern const struct efi_simple_text_output_protocol efi_con_out;
-extern const struct efi_simple_input_interface efi_con_in;
+extern struct efi_simple_input_interface efi_con_in;
 extern const struct efi_console_control_protocol efi_console_control;
 extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
 
@@ -90,6 +90,8 @@ struct efi_event {
 /* This list contains all UEFI objects we know of */
 extern struct list_head efi_obj_list;
 
+/* Called by bootefi to make console interface available */
+int efi_console_register(void);
 /* Called by bootefi to make all disk storage accessible as EFI objects */
 int efi_disk_register(void);
 /* Called by bootefi to make GOP (graphical) interface available */
@@ -125,6 +127,8 @@ efi_status_t efi_create_event(enum efi_event_type type, 
UINTN notify_tpl,
 /* Call this to set a timer */
 efi_status_t efi_set_timer(struct efi_event *event, int type,
                           uint64_t trigger_time);
+/* Call this to signal an event */
+void efi_signal_event(struct efi_event *event);
 
 /* Generic EFI memory allocator, call this to get memory */
 void *efi_alloc(uint64_t len, int memory_type);
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index 7f10b6090a..137a4036c6 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -82,7 +82,7 @@ efi_status_t efi_exit_func(efi_status_t ret)
        return ret;
 }
 
-static void efi_signal_event(struct efi_event *event)
+void efi_signal_event(struct efi_event *event)
 {
        if (event->signaled)
                return;
diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index 8ef7326fef..dbe98ac08b 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -421,8 +421,46 @@ static efi_status_t EFIAPI efi_cin_read_key_stroke(
        return EFI_EXIT(EFI_SUCCESS);
 }
 
-const struct efi_simple_input_interface efi_con_in = {
+struct efi_simple_input_interface efi_con_in = {
        .reset = efi_cin_reset,
        .read_key_stroke = efi_cin_read_key_stroke,
        .wait_for_key = NULL,
 };
+
+static struct efi_event *console_timer_event;
+
+static void efi_key_notify(struct efi_event *event, void *context)
+{
+}
+
+static void efi_console_timer_notify(struct efi_event *event, void *context)
+{
+       EFI_ENTRY("%p, %p", event, context);
+       if (tstc())
+               efi_signal_event(efi_con_in.wait_for_key);
+       EFI_EXIT(EFI_SUCCESS);
+}
+
+/* This gets called from do_bootefi_exec(). */
+int efi_console_register(void)
+{
+       efi_status_t r;
+       r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK,
+                            efi_key_notify, NULL, &efi_con_in.wait_for_key);
+       if (r != EFI_SUCCESS) {
+               printf("ERROR: Failed to register WaitForKey event\n");
+               return r;
+       }
+       r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK,
+                            efi_console_timer_notify, NULL,
+                            &console_timer_event);
+       if (r != EFI_SUCCESS) {
+               printf("ERROR: Failed to register console event\n");
+               return r;
+       }
+       /* 5000 ns cycle is sufficient for 2 MBaud */
+       r = efi_set_timer(console_timer_event, EFI_TIMER_PERIODIC, 50);
+       if (r != EFI_SUCCESS)
+               printf("ERROR: Failed to set console timer\n");
+       return r;
+}
-- 
2.13.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to