aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-10-01 19:14:38 -0600
committerSimon Glass <sjg@chromium.org>2023-11-14 20:04:00 -0700
commit3fa53b9531c1db5e3be42014f2004786e9511f35 (patch)
tree54612c886104b00a78898970b17689645f789600 /cmd
parentbaea7ec6a63e38bd4a5815c6cafded972a91c148 (diff)
downloadu-boot-3fa53b9531c1db5e3be42014f2004786e9511f35.zip
u-boot-3fa53b9531c1db5e3be42014f2004786e9511f35.tar.gz
u-boot-3fa53b9531c1db5e3be42014f2004786e9511f35.tar.bz2
bootstd: Add a return code to bootflow menu
Return an error when the user does not select an OS, so we know whether to boot or not. Move calling of bootflow_menu_run() into a separate function so we can call it from other places. Expand the test to cover these cases. Add some documentation also, while we are here. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/bootflow.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/cmd/bootflow.c b/cmd/bootflow.c
index ad39ebe..3aeb40d 100644
--- a/cmd/bootflow.c
+++ b/cmd/bootflow.c
@@ -89,6 +89,44 @@ static void show_footer(int count, int num_valid)
num_valid);
}
+/**
+ * bootflow_handle_menu() - Handle running the menu and updating cur bootflow
+ *
+ * This shows the menu, allows the user to select something and then prints
+ * what happened
+ *
+ * @std: bootstd information
+ * @text_mode: true to run the menu in text mode
+ * @bflowp: Returns selected bootflow, on success
+ * Return: 0 on success (a bootflow was selected), -EAGAIN if nothing was
+ * chosen, other -ve value on other error
+ */
+__maybe_unused static int bootflow_handle_menu(struct bootstd_priv *std,
+ bool text_mode,
+ struct bootflow **bflowp)
+{
+ struct bootflow *bflow;
+ int ret;
+
+ ret = bootflow_menu_run(std, text_mode, &bflow);
+ if (ret) {
+ if (ret == -EAGAIN) {
+ printf("Nothing chosen\n");
+ std->cur_bootflow = NULL;
+ } else {
+ printf("Menu failed (err=%d)\n", ret);
+ }
+
+ return ret;
+ }
+
+ printf("Selected: %s\n", bflow->os_name ? bflow->os_name : bflow->name);
+ std->cur_bootflow = bflow;
+ *bflowp = bflow;
+
+ return 0;
+}
+
static int do_bootflow_scan(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
@@ -455,18 +493,9 @@ static int do_bootflow_menu(struct cmd_tbl *cmdtp, int flag, int argc,
if (ret)
return CMD_RET_FAILURE;
- ret = bootflow_menu_run(std, text_mode, &bflow);
- if (ret) {
- if (ret == -EAGAIN)
- printf("Nothing chosen\n");
- else {
- printf("Menu failed (err=%d)\n", ret);
- return CMD_RET_FAILURE;
- }
- }
-
- printf("Selected: %s\n", bflow->os_name ? bflow->os_name : bflow->name);
- std->cur_bootflow = bflow;
+ ret = bootflow_handle_menu(std, text_mode, &bflow);
+ if (ret)
+ return CMD_RET_FAILURE;
return 0;
}