cmd: pxe_utils: sysboot: add label override support
authorAmjad Ouled-Ameur <aouledameur@baylibre.com>
Sat, 13 Nov 2021 13:09:20 +0000 (14:09 +0100)
committerRamon Fried <ramon@neureality.ai>
Sat, 15 Jan 2022 16:42:48 +0000 (18:42 +0200)
This will allow consumers to choose a pxe label at runtime instead of
having to prompt the user. One good use-case for this, is choosing
whether or not to apply a dtbo depending on the hardware configuration.
e.g: for TI's AM335x EVM, it would be convenient to apply a particular
dtbo only when the J9 jumper is on PRUSS mode. To achieve this, the
pxe menu should have 2 labels, one with the dtbo and the other without,
then the "pxe_label_override" env variable should point to the label with
the dtbo at runtime only when the jumper is on PRUSS mode.

This change can be used for different use-cases and bring more
flexibilty to consumers who use sysboot/pxe_utils.

if "pxe_label_override" is set but does not exist in the pxe menu,
the code should fallback to the default label if given, and no failure
is returned but rather a warning message.

Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Artem Lapkin <email2tema@gmail.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
boot/pxe_utils.c
doc/README.pxe

index a32acca..fcfee5e 100644 (file)
@@ -1355,9 +1355,11 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
        struct pxe_label *label;
        struct list_head *pos;
        struct menu *m;
+       char *label_override;
        int err;
        int i = 1;
        char *default_num = NULL;
+       char *override_num = NULL;
 
        /*
         * Create a menu and add items for all the labels.
@@ -1367,6 +1369,8 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
        if (!m)
                return NULL;
 
+       label_override = env_get("pxe_label_override");
+
        list_for_each(pos, &cfg->labels) {
                label = list_entry(pos, struct pxe_label, list);
 
@@ -1378,6 +1382,17 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
                if (cfg->default_label &&
                    (strcmp(label->name, cfg->default_label) == 0))
                        default_num = label->num;
+               if (label_override && !strcmp(label->name, label_override))
+                       override_num = label->num;
+       }
+
+
+       if (label_override) {
+               if (override_num)
+                       default_num = override_num;
+               else
+                       printf("Missing override pxe label: %s\n",
+                             label_override);
        }
 
        /*
index b67151c..a1f0423 100644 (file)
@@ -92,6 +92,12 @@ pxe boot
      fdtoverlay_addr_r - location in RAM at which 'pxe boot' will temporarily store
      fdt overlay(s) before applying them to the fdt blob stored at 'fdt_addr_r'.
 
+     pxe_label_override - override label to be used, if exists, instead of the
+     default label. This will allow consumers to choose a pxe label at
+     runtime instead of having to prompt the user. If "pxe_label_override" is set
+     but does not exist in the pxe menu, pxe would fallback to the default label if
+     given, and no failure is returned but rather a warning message.
+
 pxe file format
 ===============
 The pxe file format is nearly a subset of the PXELINUX file format; see