]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
expo: Update bootflow_menu_poll() to return a sequence ID
authorSimon Glass <sjg@chromium.org>
Fri, 2 May 2025 14:46:55 +0000 (08:46 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 30 May 2025 08:49:33 +0000 (09:49 +0100)
Rather than returning a bootflow, return the index of the bootflow. This
will allow callers to do their own translation to bootflows or some
other data structure.

Also return a special code when the user tries to move the pointer, so
that the caller can cancel the boot-menu timeout, if this is in use.

Signed-off-by: Simon Glass <sjg@chromium.org>
boot/bootflow_menu.c
cmd/bootflow.c
include/bootflow.h

index fb90e51e9209e4e0b2268ebc74286de17f2ad4eb..6bca17142adf2b46dca45b778e1c68db2bccd92f 100644 (file)
@@ -301,34 +301,28 @@ int bootflow_menu_start(struct bootstd_priv *std, bool text_mode,
        return 0;
 }
 
-int bootflow_menu_poll(struct expo *exp, struct bootflow **bflowp)
+int bootflow_menu_poll(struct expo *exp, int *seqp)
 {
        struct bootflow *sel_bflow;
        struct expo_action act;
-       int ret;
+       struct scene *scn;
+       int item, ret;
 
        sel_bflow = NULL;
-       *bflowp = NULL;
+
+       scn = expo_lookup_scene_id(exp, exp->scene_id);
+
+       item = scene_menu_get_cur_item(scn, OBJ_MENU);
+       *seqp = item > 0 ? item - ITEM : -1;
 
        ret = expo_poll(exp, &act);
        if (ret)
                return log_msg_ret("bmp", ret);
 
        switch (act.type) {
-       case EXPOACT_SELECT: {
-               struct bootflow *bflow;
-               int i;
-
-               for (ret = bootflow_first_glob(&bflow), i = 0; !ret && i < 36;
-                    ret = bootflow_next_glob(&bflow), i++) {
-                       if (i == act.select.id - ITEM) {
-                               *bflowp = bflow;
-                               // printf("found %p\n", bflow);
-                               return 0;
-                       }
-               }
+       case EXPOACT_SELECT:
+               *seqp = act.select.id - ITEM;
                break;
-       }
        case EXPOACT_POINT_ITEM: {
                struct scene *scn = expo_lookup_scene_id(exp, MAIN);
 
@@ -337,13 +331,13 @@ int bootflow_menu_poll(struct expo *exp, struct bootflow **bflowp)
                ret = scene_menu_select_item(scn, OBJ_MENU, act.select.id);
                if (ret)
                        return log_msg_ret("bmp", ret);
-               break;
+               return -ERESTART;
        }
        case EXPOACT_QUIT:
                return -EPIPE;
        default:
-               break;
+               return -EAGAIN;
        }
 
-       return -EAGAIN;
+       return 0;
 }
index 55643a6876f0c7a273fc4e57f3cec577bad2ae74..551dffbb8b89534c75d0bd67600ed6d720cb6ab2 100644 (file)
@@ -109,18 +109,21 @@ __maybe_unused static int bootflow_handle_menu(struct bootstd_priv *std,
 {
        struct expo *exp;
        struct bootflow *bflow;
-       int ret;
+       int ret, seq;
 
        ret = bootflow_menu_start(std, text_mode, &exp);
        if (ret)
                return log_msg_ret("bhs", ret);
 
+       ret = -ERESTART;
        do {
-               ret = expo_render(exp);
-               if (ret)
-                       return log_msg_ret("bhr", ret);
-               ret = bootflow_menu_poll(exp, &bflow);
-       } while (ret == -EAGAIN);
+               if (ret == -ERESTART) {
+                       ret = expo_render(exp);
+                       if (ret)
+                               return log_msg_ret("bhr", ret);
+               }
+               ret = bootflow_menu_poll(exp, &seq);
+       } while (ret == -EAGAIN || ret == -ERESTART);
 
        if (ret == -EPIPE) {
                printf("Nothing chosen\n");
@@ -128,6 +131,7 @@ __maybe_unused static int bootflow_handle_menu(struct bootstd_priv *std,
        } else if (ret) {
                printf("Menu failed (err=%d)\n", ret);
        } else {
+               bflow = alist_getw(&std->bootflows, seq, struct bootflow);
                printf("Selected: %s\n", bflow->os_name ? bflow->os_name :
                       bflow->name);
                std->cur_bootflow = bflow;
index 615fb97f4a4ff7b447fc1c9fb02c0454678192ec..75d88d47884f095986d593cca7b3da738fc9328d 100644 (file)
@@ -670,10 +670,10 @@ int bootflow_menu_start(struct bootstd_priv *std, bool text_mode,
  * bootflow_menu_poll() - Poll a menu for user action
  *
  * @exp: Expo to poll
- * @bflowp: Returns chosen bootflow (set to NULL if nothing is chosen)
- * Return 0 if a bootflow was chosen, -EAGAIN if nothing is chosen yet, -EPIPE
- *     if the user quit
+ * @seqp: Returns the bootflow chosen or currently pointed to (numbered from 0)
+ * Return: 0 if a bootflow was chosen, -EAGAIN if nothing is chosen yet, -EPIPE
+ *     if the user quit, -ERESTART if the expo needs refreshing
  */
-int bootflow_menu_poll(struct expo *exp, struct bootflow **bflowp);
+int bootflow_menu_poll(struct expo *exp, int *seqp);
 
 #endif