All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramon Fried <rfried.dev@gmail.com>
To: Simon Glass <sjg@chromium.org>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	Patrice Chotard <patrice.chotard@foss.st.com>,
	 Artem Lapkin <email2tema@gmail.com>,
	Tom Rini <trini@konsulko.com>,
	 Joe Hershberger <joe.hershberger@ni.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	 Peter Hoyes <Peter.Hoyes@arm.com>
Subject: Re: [PATCH v3 03/18] pxe: Use a context pointer
Date: Tue, 9 Nov 2021 10:08:25 +0200	[thread overview]
Message-ID: <CAGi-RUK3AwK-oVyyd8i38bkQuSFMKL6y=marOey11nFQM4M1qQ@mail.gmail.com> (raw)
In-Reply-To: <20211014184811.482560-4-sjg@chromium.org>

On Thu, Oct 14, 2021 at 9:49 PM Simon Glass <sjg@chromium.org> wrote:
>
> At present the PXE functions pass around a pointer to command-table entry
> which is very strange. It is only needed in a few places and it is odd to
> pass around a data structure from another module in this way.
>
> For bootmethod we will need to provide some context information when
> reading files.
>
> Create a PXE context struct to hold the command-table-entry pointer and
> pass that around instead. We can then add more things to the context as
> needed.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> (no changes since v1)
>
>  cmd/pxe.c       | 28 +++++++++--------
>  cmd/pxe_utils.c | 80 ++++++++++++++++++++++++++-----------------------
>  cmd/pxe_utils.h | 43 +++++++++++++++++++-------
>  cmd/sysboot.c   |  8 +++--
>  4 files changed, 97 insertions(+), 62 deletions(-)
>
> diff --git a/cmd/pxe.c b/cmd/pxe.c
> index 46ac08fa3a0..17ce54fc049 100644
> --- a/cmd/pxe.c
> +++ b/cmd/pxe.c
> @@ -43,7 +43,7 @@ static int do_get_tftp(struct cmd_tbl *cmdtp, const char *file_path,
>   *
>   * Returns 1 on success or < 0 on error.
>   */
> -static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
> +static int pxe_uuid_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
>  {
>         char *uuid_str;
>
> @@ -52,7 +52,7 @@ static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
>         if (!uuid_str)
>                 return -ENOENT;
>
> -       return get_pxelinux_path(cmdtp, uuid_str, pxefile_addr_r);
> +       return get_pxelinux_path(ctx, uuid_str, pxefile_addr_r);
>  }
>
>  /*
> @@ -61,7 +61,7 @@ static int pxe_uuid_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
>   *
>   * Returns 1 on success or < 0 on error.
>   */
> -static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
> +static int pxe_mac_path(struct pxe_context *ctx, unsigned long pxefile_addr_r)
>  {
>         char mac_str[21];
>         int err;
> @@ -71,7 +71,7 @@ static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
>         if (err < 0)
>                 return err;
>
> -       return get_pxelinux_path(cmdtp, mac_str, pxefile_addr_r);
> +       return get_pxelinux_path(ctx, mac_str, pxefile_addr_r);
>  }
>
>  /*
> @@ -81,7 +81,7 @@ static int pxe_mac_path(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
>   *
>   * Returns 1 on success or < 0 on error.
>   */
> -static int pxe_ipaddr_paths(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
> +static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_r)
>  {
>         char ip_addr[9];
>         int mask_pos, err;
> @@ -89,7 +89,7 @@ static int pxe_ipaddr_paths(struct cmd_tbl *cmdtp, unsigned long pxefile_addr_r)
>         sprintf(ip_addr, "%08X", ntohl(net_ip.s_addr));
>
>         for (mask_pos = 7; mask_pos >= 0;  mask_pos--) {
> -               err = get_pxelinux_path(cmdtp, ip_addr, pxefile_addr_r);
> +               err = get_pxelinux_path(ctx, ip_addr, pxefile_addr_r);
>
>                 if (err > 0)
>                         return err;
> @@ -118,8 +118,10 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>  {
>         char *pxefile_addr_str;
>         unsigned long pxefile_addr_r;
> +       struct pxe_context ctx;
>         int err, i = 0;
>
> +       pxe_setup_ctx(&ctx, cmdtp);
>         do_getfile = do_get_tftp;
>
>         if (argc != 1)
> @@ -139,16 +141,16 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>          * Keep trying paths until we successfully get a file we're looking
>          * for.
>          */
> -       if (pxe_uuid_path(cmdtp, pxefile_addr_r) > 0 ||
> -           pxe_mac_path(cmdtp, pxefile_addr_r) > 0 ||
> -           pxe_ipaddr_paths(cmdtp, pxefile_addr_r) > 0) {
> +       if (pxe_uuid_path(&ctx, pxefile_addr_r) > 0 ||
> +           pxe_mac_path(&ctx, pxefile_addr_r) > 0 ||
> +           pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) {
>                 printf("Config file found\n");
>
>                 return 0;
>         }
>
>         while (pxe_default_paths[i]) {
> -               if (get_pxelinux_path(cmdtp, pxe_default_paths[i],
> +               if (get_pxelinux_path(&ctx, pxe_default_paths[i],
>                                       pxefile_addr_r) > 0) {
>                         printf("Config file found\n");
>                         return 0;
> @@ -172,7 +174,9 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>         unsigned long pxefile_addr_r;
>         struct pxe_menu *cfg;
>         char *pxefile_addr_str;
> +       struct pxe_context ctx;
>
> +       pxe_setup_ctx(&ctx, cmdtp);
>         do_getfile = do_get_tftp;
>
>         if (argc == 1) {
> @@ -191,14 +195,14 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>                 return 1;
>         }
>
> -       cfg = parse_pxefile(cmdtp, pxefile_addr_r);
> +       cfg = parse_pxefile(&ctx, pxefile_addr_r);
>
>         if (!cfg) {
>                 printf("Error parsing config file\n");
>                 return 1;
>         }
>
> -       handle_pxe_menu(cmdtp, cfg);
> +       handle_pxe_menu(&ctx, cfg);
>
>         destroy_pxe_menu(cfg);
>
> diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
> index d7f4017efeb..280be55d9b3 100644
> --- a/cmd/pxe_utils.c
> +++ b/cmd/pxe_utils.c
> @@ -105,7 +105,7 @@ int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
>   *
>   * Returns 1 for success, or < 0 on error.
>   */
> -static int get_relfile(struct cmd_tbl *cmdtp, const char *file_path,
> +static int get_relfile(struct pxe_context *ctx, const char *file_path,
>                        unsigned long file_addr)
>  {
>         size_t path_len;
> @@ -133,10 +133,10 @@ static int get_relfile(struct cmd_tbl *cmdtp, const char *file_path,
>
>         sprintf(addr_buf, "%lx", file_addr);
>
> -       return do_getfile(cmdtp, relfile, addr_buf);
> +       return do_getfile(ctx->cmdtp, relfile, addr_buf);
>  }
>
> -int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
> +int get_pxe_file(struct pxe_context *ctx, const char *file_path,
>                  unsigned long file_addr)
>  {
>         unsigned long config_file_size;
> @@ -144,7 +144,7 @@ int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
>         int err;
>         char *buf;
>
> -       err = get_relfile(cmdtp, file_path, file_addr);
> +       err = get_relfile(ctx, file_path, file_addr);
>
>         if (err < 0)
>                 return err;
> @@ -170,7 +170,7 @@ int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
>
>  #define PXELINUX_DIR "pxelinux.cfg/"
>
> -int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
> +int get_pxelinux_path(struct pxe_context *ctx, const char *file,
>                       unsigned long pxefile_addr_r)
>  {
>         size_t base_len = strlen(PXELINUX_DIR);
> @@ -184,7 +184,7 @@ int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
>
>         sprintf(path, PXELINUX_DIR "%s", file);
>
> -       return get_pxe_file(cmdtp, path, pxefile_addr_r);
> +       return get_pxe_file(ctx, path, pxefile_addr_r);
>  }
>
>  /*
> @@ -194,7 +194,7 @@ int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
>   *
>   * Returns 1 on success or < 0 on error.
>   */
> -static int get_relfile_envaddr(struct cmd_tbl *cmdtp, const char *file_path,
> +static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
>                                const char *envaddr_name)
>  {
>         unsigned long file_addr;
> @@ -208,7 +208,7 @@ static int get_relfile_envaddr(struct cmd_tbl *cmdtp, const char *file_path,
>         if (strict_strtoul(envaddr, 16, &file_addr) < 0)
>                 return -EINVAL;
>
> -       return get_relfile(cmdtp, file_path, file_addr);
> +       return get_relfile(ctx, file_path, file_addr);
>  }
>
>  /*
> @@ -317,7 +317,8 @@ static int label_localboot(struct pxe_label *label)
>   * Loads fdt overlays specified in 'fdtoverlays'.
>   */
>  #ifdef CONFIG_OF_LIBFDT_OVERLAY
> -static void label_boot_fdtoverlay(struct cmd_tbl *cmdtp, struct pxe_label *label)
> +static void label_boot_fdtoverlay(struct pxe_context *ctx,
> +                                 struct pxe_label *label)
>  {
>         char *fdtoverlay = label->fdtoverlays;
>         struct fdt_header *working_fdt;
> @@ -367,7 +368,7 @@ static void label_boot_fdtoverlay(struct cmd_tbl *cmdtp, struct pxe_label *label
>                         goto skip_overlay;
>
>                 /* Load overlay file */
> -               err = get_relfile_envaddr(cmdtp, overlayfile,
> +               err = get_relfile_envaddr(ctx, overlayfile,
>                                           "fdtoverlay_addr_r");
>                 if (err < 0) {
>                         printf("Failed loading overlay %s\n", overlayfile);
> @@ -414,7 +415,7 @@ skip_overlay:
>   * If the label specifies an 'append' line, its contents will overwrite that
>   * of the 'bootargs' environment variable.
>   */
> -static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
> +static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
>  {
>         char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
>         char initrd_str[28];
> @@ -443,7 +444,7 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
>         }
>
>         if (label->initrd) {
> -               if (get_relfile_envaddr(cmdtp, label->initrd, "ramdisk_addr_r") < 0) {
> +               if (get_relfile_envaddr(ctx, label->initrd, "ramdisk_addr_r") < 0) {
>                         printf("Skipping %s for failure retrieving initrd\n",
>                                label->name);
>                         return 1;
> @@ -456,7 +457,7 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
>                 bootm_argc = 3;
>         }
>
> -       if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
> +       if (get_relfile_envaddr(ctx, label->kernel, "kernel_addr_r") < 0) {
>                 printf("Skipping %s for failure retrieving kernel\n",
>                        label->name);
>                 return 1;
> @@ -596,7 +597,7 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
>                 }
>
>                 if (fdtfile) {
> -                       int err = get_relfile_envaddr(cmdtp, fdtfile,
> +                       int err = get_relfile_envaddr(ctx, fdtfile,
>                                                       "fdt_addr_r");
>
>                         free(fdtfilefree);
> @@ -612,7 +613,7 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
>
>  #ifdef CONFIG_OF_LIBFDT_OVERLAY
>                         if (label->fdtoverlays)
> -                               label_boot_fdtoverlay(cmdtp, label);
> +                               label_boot_fdtoverlay(ctx, label);
>  #endif
>                 } else {
>                         bootm_argv[3] = NULL;
> @@ -632,16 +633,16 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
>         buf = map_sysmem(kernel_addr, 0);
>         /* Try bootm for legacy and FIT format image */
>         if (genimg_get_format(buf) != IMAGE_FORMAT_INVALID)
> -               do_bootm(cmdtp, 0, bootm_argc, bootm_argv);
> +               do_bootm(ctx->cmdtp, 0, bootm_argc, bootm_argv);
>         /* Try booting an AArch64 Linux kernel image */
>         else if (IS_ENABLED(CONFIG_CMD_BOOTI))
> -               do_booti(cmdtp, 0, bootm_argc, bootm_argv);
> +               do_booti(ctx->cmdtp, 0, bootm_argc, bootm_argv);
>         /* Try booting a Image */
>         else if (IS_ENABLED(CONFIG_CMD_BOOTZ))
> -               do_bootz(cmdtp, 0, bootm_argc, bootm_argv);
> +               do_bootz(ctx->cmdtp, 0, bootm_argc, bootm_argv);
>         /* Try booting an x86_64 Linux kernel image */
>         else if (IS_ENABLED(CONFIG_CMD_ZBOOT))
> -               do_zboot_parent(cmdtp, 0, bootm_argc, bootm_argv, NULL);
> +               do_zboot_parent(ctx->cmdtp, 0, bootm_argc, bootm_argv, NULL);
>
>         unmap_sysmem(buf);
>
> @@ -917,7 +918,7 @@ static int parse_integer(char **c, int *dst)
>         return 1;
>  }
>
> -static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
> +static int parse_pxefile_top(struct pxe_context *ctx, char *p, ulong base,
>                              struct pxe_menu *cfg, int nest_level);
>
>  /*
> @@ -928,7 +929,7 @@ static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
>   * include, nest_level has already been incremented and doesn't need to be
>   * incremented here.
>   */
> -static int handle_include(struct cmd_tbl *cmdtp, char **c, unsigned long base,
> +static int handle_include(struct pxe_context *ctx, char **c, unsigned long base,
>                           struct pxe_menu *cfg, int nest_level)
>  {
>         char *include_path;
> @@ -944,7 +945,7 @@ static int handle_include(struct cmd_tbl *cmdtp, char **c, unsigned long base,
>                 return err;
>         }
>
> -       err = get_pxe_file(cmdtp, include_path, base);
> +       err = get_pxe_file(ctx, include_path, base);
>
>         if (err < 0) {
>                 printf("Couldn't retrieve %s\n", include_path);
> @@ -952,7 +953,7 @@ static int handle_include(struct cmd_tbl *cmdtp, char **c, unsigned long base,
>         }
>
>         buf = map_sysmem(base, 0);
> -       ret = parse_pxefile_top(cmdtp, buf, base, cfg, nest_level);
> +       ret = parse_pxefile_top(ctx, buf, base, cfg, nest_level);
>         unmap_sysmem(buf);
>
>         return ret;
> @@ -968,7 +969,7 @@ static int handle_include(struct cmd_tbl *cmdtp, char **c, unsigned long base,
>   * nest_level should be 1 when parsing the top level pxe file, 2 when parsing
>   * a file it includes, 3 when parsing a file included by that file, and so on.
>   */
> -static int parse_menu(struct cmd_tbl *cmdtp, char **c, struct pxe_menu *cfg,
> +static int parse_menu(struct pxe_context *ctx, char **c, struct pxe_menu *cfg,
>                       unsigned long base, int nest_level)
>  {
>         struct token t;
> @@ -984,7 +985,7 @@ static int parse_menu(struct cmd_tbl *cmdtp, char **c, struct pxe_menu *cfg,
>                 break;
>
>         case T_INCLUDE:
> -               err = handle_include(cmdtp, c, base, cfg, nest_level + 1);
> +               err = handle_include(ctx, c, base, cfg, nest_level + 1);
>                 break;
>
>         case T_BACKGROUND:
> @@ -1186,7 +1187,7 @@ static int parse_label(char **c, struct pxe_menu *cfg)
>   *
>   * Returns 1 on success, < 0 on error.
>   */
> -static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
> +static int parse_pxefile_top(struct pxe_context *ctx, char *p, unsigned long base,
>                              struct pxe_menu *cfg, int nest_level)
>  {
>         struct token t;
> @@ -1209,7 +1210,7 @@ static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
>                 switch (t.type) {
>                 case T_MENU:
>                         cfg->prompt = 1;
> -                       err = parse_menu(cmdtp, &p, cfg,
> +                       err = parse_menu(ctx, &p, cfg,
>                                          base + ALIGN(strlen(b) + 1, 4),
>                                          nest_level);
>                         break;
> @@ -1236,7 +1237,7 @@ static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
>                         break;
>
>                 case T_INCLUDE:
> -                       err = handle_include(cmdtp, &p,
> +                       err = handle_include(ctx, &p,
>                                              base + ALIGN(strlen(b), 4), cfg,
>                                              nest_level + 1);
>                         break;
> @@ -1263,7 +1264,6 @@ static int parse_pxefile_top(struct cmd_tbl *cmdtp, char *p, unsigned long base,
>  }
>
>  /*
> - * Free the memory used by a pxe_menu and its labels.
>   */
>  void destroy_pxe_menu(struct pxe_menu *cfg)
>  {
> @@ -1285,7 +1285,7 @@ void destroy_pxe_menu(struct pxe_menu *cfg)
>         free(cfg);
>  }
>
> -struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, unsigned long menucfg)
> +struct pxe_menu *parse_pxefile(struct pxe_context *ctx, unsigned long menucfg)
>  {
>         struct pxe_menu *cfg;
>         char *buf;
> @@ -1301,7 +1301,7 @@ struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, unsigned long menucfg)
>         INIT_LIST_HEAD(&cfg->labels);
>
>         buf = map_sysmem(menucfg, 0);
> -       r = parse_pxefile_top(cmdtp, buf, menucfg, cfg, 1);
> +       r = parse_pxefile_top(ctx, buf, menucfg, cfg, 1);
>         unmap_sysmem(buf);
>
>         if (r < 0) {
> @@ -1369,7 +1369,8 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg)
>  /*
>   * Try to boot any labels we have yet to attempt to boot.
>   */
> -static void boot_unattempted_labels(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
> +static void boot_unattempted_labels(struct pxe_context *ctx,
> +                                   struct pxe_menu *cfg)
>  {
>         struct list_head *pos;
>         struct pxe_label *label;
> @@ -1378,11 +1379,11 @@ static void boot_unattempted_labels(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
>                 label = list_entry(pos, struct pxe_label, list);
>
>                 if (!label->attempted)
> -                       label_boot(cmdtp, label);
> +                       label_boot(ctx, label);
>         }
>  }
>
> -void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
> +void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg)
>  {
>         void *choice;
>         struct menu *m;
> @@ -1391,7 +1392,7 @@ void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
>         if (IS_ENABLED(CONFIG_CMD_BMP)) {
>                 /* display BMP if available */
>                 if (cfg->bmp) {
> -                       if (get_relfile(cmdtp, cfg->bmp, image_load_addr)) {
> +                       if (get_relfile(ctx, cfg->bmp, image_load_addr)) {
>                                 if (CONFIG_IS_ENABLED(CMD_CLS))
>                                         run_command("cls", 0);
>                                 bmp_display(image_load_addr,
> @@ -1423,12 +1424,17 @@ void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg)
>          */
>
>         if (err == 1) {
> -               err = label_boot(cmdtp, choice);
> +               err = label_boot(ctx, choice);
>                 if (!err)
>                         return;
>         } else if (err != -ENOENT) {
>                 return;
>         }
>
> -       boot_unattempted_labels(cmdtp, cfg);
> +       boot_unattempted_labels(ctx, cfg);
> +}
> +
> +void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp)
> +{
> +       ctx->cmdtp = cmdtp;
>  }
> diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h
> index 441beefa2bc..cd0d3371765 100644
> --- a/cmd/pxe_utils.h
> +++ b/cmd/pxe_utils.h
> @@ -79,6 +79,23 @@ extern bool is_pxe;
>
>  extern int (*do_getfile)(struct cmd_tbl *cmdtp, const char *file_path,
>                          char *file_addr);
> +
> +/**
> + * struct pxe_context - context information for PXE parsing
> + *
> + * @cmdtp: Pointer to command table to use when calling other commands
> + */
> +struct pxe_context {
> +       struct cmd_tbl *cmdtp;
> +};
> +
> +/**
> + * destroy_pxe_menu() - Destroy an allocated pxe structure
> + *
> + * Free the memory used by a pxe_menu and its labels
> + *
> + * @cfg: Config to destroy, previous returned from parse_pxefile()
> + */
>  void destroy_pxe_menu(struct pxe_menu *cfg);
>
>  /**
> @@ -88,12 +105,12 @@ void destroy_pxe_menu(struct pxe_menu *cfg);
>   * 'bootfile' was specified in the environment, the path to bootfile will be
>   * prepended to 'file_path' and the resulting path will be used.
>   *
> - * @cmdtp: Pointer to command-table entry for the initiating command
> + * @ctx: PXE context
>   * @file_path: Path to file
>   * @file_addr: Address to place file
>   * Returns 1 on success, or < 0 for error
>   */
> -int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
> +int get_pxe_file(struct pxe_context *ctx, const char *file_path,
>                  ulong file_addr);
>
>  /**
> @@ -103,12 +120,12 @@ int get_pxe_file(struct cmd_tbl *cmdtp, const char *file_path,
>   * to do the hard work, the location of the 'pxelinux.cfg' folder is generated
>   * from the bootfile path, as described in get_pxe_file().
>   *
> - * @cmdtp: Pointer to command-table entry for the initiating command
> + * @ctx: PXE context
>   * @file: Relative path to file
>   * @pxefile_addr_r: Address to load file
>   * Returns 1 on success or < 0 on error.
>   */
> -int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
> +int get_pxelinux_path(struct pxe_context *ctx, const char *file,
>                       ulong pxefile_addr_r);
>
>  /**
> @@ -123,25 +140,23 @@ int get_pxelinux_path(struct cmd_tbl *cmdtp, const char *file,
>   * If this function returns, there weren't any labels that successfully
>   * booted, or the user interrupted the menu selection via ctrl+c.
>   *
> - * @cmdtp: Pointer to command-table entry for the initiating command
> + * @ctx: PXE context
>   * @cfg: PXE menu
>   */
> -void handle_pxe_menu(struct cmd_tbl *cmdtp, struct pxe_menu *cfg);
> +void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg);
>
>  /**
>   * parse_pxefile() - Parsing a pxe file
>   *
>   * This is only used for the top-level file.
>   *
> - * @cmdtp: Pointer to command-table entry for the initiating command
> - * @menucfg: Address of PXE file
> - *
> + * @ctx: PXE context (provided by the caller)
>   * Returns NULL if there is an error, otherwise, returns a pointer to a
>   * pxe_menu struct populated with the results of parsing the pxe file (and any
>   * files it includes). The resulting pxe_menu struct can be free()'d by using
>   * the destroy_pxe_menu() function.
>   */
> -struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, ulong menucfg);
> +struct pxe_menu *parse_pxefile(struct pxe_context *ctx, ulong menucfg);
>
>  /**
>   * format_mac_pxe() - Convert a MAC address to PXE format
> @@ -159,4 +174,12 @@ struct pxe_menu *parse_pxefile(struct cmd_tbl *cmdtp, ulong menucfg);
>   */
>  int format_mac_pxe(char *outbuf, size_t outbuf_len);
>
> +/**
> + * pxe_setup_ctx() - Setup a new PXE context
> + *
> + * @ctx: Context to set up
> + * @cmdtp: Command table entry which started this action
> + */
> +void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp);
> +
>  #endif /* __PXE_UTILS_H */
> diff --git a/cmd/sysboot.c b/cmd/sysboot.c
> index af6a2f1b7f1..9ba713c8aae 100644
> --- a/cmd/sysboot.c
> +++ b/cmd/sysboot.c
> @@ -59,6 +59,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
>                       char *const argv[])
>  {
>         unsigned long pxefile_addr_r;
> +       struct pxe_context ctx;
>         struct pxe_menu *cfg;
>         char *pxefile_addr_str;
>         char *filename;
> @@ -90,6 +91,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
>                 env_set("bootfile", filename);
>         }
>
> +       pxe_setup_ctx(&ctx, cmdtp);
>         if (strstr(argv[3], "ext2")) {
>                 do_getfile = do_get_ext2;
>         } else if (strstr(argv[3], "fat")) {
> @@ -108,12 +110,12 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
>                 return 1;
>         }
>
> -       if (get_pxe_file(cmdtp, filename, pxefile_addr_r) < 0) {
> +       if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) {
>                 printf("Error reading config file\n");
>                 return 1;
>         }
>
> -       cfg = parse_pxefile(cmdtp, pxefile_addr_r);
> +       cfg = parse_pxefile(&ctx, pxefile_addr_r);
>
>         if (!cfg) {
>                 printf("Error parsing config file\n");
> @@ -123,7 +125,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc,
>         if (prompt)
>                 cfg->prompt = 1;
>
> -       handle_pxe_menu(cmdtp, cfg);
> +       handle_pxe_menu(&ctx, cfg);
>
>         destroy_pxe_menu(cfg);
>
> --
> 2.33.0.1079.g6e70778dc9-goog
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>

  parent reply	other threads:[~2021-11-09  8:08 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14 18:47 [PATCH v3 00/18] pxe: Refactoring to tidy up and prepare for bootflow Simon Glass
2021-10-14 18:47 ` [PATCH v3 01/18] Create a new boot/ directory Simon Glass
2021-10-16  5:31   ` Art Nikpal
2021-10-18  8:41   ` art
2021-11-12 15:38   ` Tom Rini
2021-10-14 18:47 ` [PATCH v3 02/18] pxe: Move API comments to the header files Simon Glass
2021-10-18  8:42   ` art
2021-11-09  8:07   ` Ramon Fried
2021-11-09  8:52   ` Heinrich Schuchardt
2021-11-12 15:38   ` Tom Rini
2021-10-14 18:47 ` [PATCH v3 03/18] pxe: Use a context pointer Simon Glass
2021-10-18  8:45   ` art
2021-11-09  8:08   ` Ramon Fried [this message]
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:47 ` [PATCH v3 04/18] pxe: Move do_getfile() into the context Simon Glass
2021-10-18  8:46   ` art
2021-11-09  8:11   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:47 ` [PATCH v3 05/18] pxe: Add a userdata field to " Simon Glass
2021-10-18  8:46   ` art
2021-11-09  8:10   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:47 ` [PATCH v3 06/18] pxe: Tidy up the is_pxe global Simon Glass
2021-10-18  8:47   ` art
2021-11-09  8:10   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 07/18] pxe: Move pxe_utils files Simon Glass
2021-10-18  8:47   ` art
2021-11-09  8:10   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2022-02-09 11:40   ` Adam Ford
2022-02-09 12:32     ` Tom Rini
2022-02-09 17:16       ` Simon Glass
2022-02-10 13:56         ` Adam Ford
2022-02-10 13:57           ` Adam Ford
2022-02-10 14:32             ` Simon Glass
2022-02-10 14:41               ` Adam Ford
2022-02-10 14:57           ` Tom Rini
2022-02-11 15:50             ` Adam Ford
2022-02-11 16:12               ` Tom Rini
2022-02-11 16:39                 ` Adam Ford
2022-02-11 16:44                   ` Tom Rini
2022-02-11 17:10                     ` Adam Ford
2022-02-11 17:13                       ` Tom Rini
2022-02-12  1:09                         ` Adam Ford
2022-02-12  1:43                           ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 08/18] pxe: Tidy up some comments in pxe_utils Simon Glass
2021-10-18  8:48   ` art
2021-11-09  8:10   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 09/18] pxe: Tidy up code style a little " Simon Glass
2021-10-18  8:48   ` art
2021-11-09  8:10   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 10/18] pxe: Move common parsing coding into pxe_util Simon Glass
2021-10-18  8:49   ` art
2021-11-09  8:09   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 11/18] pxe: Clean up the use of bootfile Simon Glass
2021-10-18  8:51   ` art
2021-11-09  8:09   ` Ramon Fried
2021-11-12 15:39   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 12/18] pxe: Drop get_bootfile_path() Simon Glass
2021-10-18  8:51   ` art
2021-11-09  8:09   ` Ramon Fried
2021-11-12 15:40   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 13/18] lib: Add tests for simple_itoa() Simon Glass
2021-10-18  8:30   ` art
2021-11-12 15:40   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 14/18] lib: Add a function to convert a string to a hex value Simon Glass
2021-10-18  8:52   ` art
2021-11-12 15:40   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 15/18] pxe: Return the file size from the getfile() function Simon Glass
2021-10-18  8:53   ` art
2021-11-09  8:09   ` Ramon Fried
2021-11-12 15:40   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 16/18] pxe: Refactor sysboot to have one helper Simon Glass
2021-10-18  8:54   ` art
2021-11-09  8:09   ` Ramon Fried
2021-11-12 15:40   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 17/18] doc: Move distro boot doc to rST Simon Glass
2021-10-18  8:55   ` art
2021-11-09  8:08   ` Ramon Fried
2021-11-12 15:40   ` Tom Rini
2021-10-14 18:48 ` [PATCH v3 18/18] pxe: Allow calling the pxe_get logic directly Simon Glass
2021-10-18  8:56   ` art
2021-11-09  8:07   ` Ramon Fried
2021-11-12 15:40   ` Tom Rini
2021-10-15 10:27 ` [PATCH v3 00/18] pxe: Refactoring to tidy up and prepare for bootflow Art Nikpal
2021-10-26  1:28 ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGi-RUK3AwK-oVyyd8i38bkQuSFMKL6y=marOey11nFQM4M1qQ@mail.gmail.com' \
    --to=rfried.dev@gmail.com \
    --cc=Peter.Hoyes@arm.com \
    --cc=email2tema@gmail.com \
    --cc=joe.hershberger@ni.com \
    --cc=patrice.chotard@foss.st.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.