From 262cfb5b15420a1aea465745a821e684b3dfa153 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:00 -0600 Subject: pxe: Move pxe_utils files Move the header file into the main include/ directory so we can use it from the bootmethod code. Move the C file into boot/ since it relates to booting. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin Reviewed-by: Ramon Fried --- include/pxe_utils.h | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 include/pxe_utils.h (limited to 'include') diff --git a/include/pxe_utils.h b/include/pxe_utils.h new file mode 100644 index 00000000000..6681442ea55 --- /dev/null +++ b/include/pxe_utils.h @@ -0,0 +1,205 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __PXE_UTILS_H +#define __PXE_UTILS_H + +#include + +/* + * A note on the pxe file parser. + * + * We're parsing files that use syslinux grammar, which has a few quirks. + * String literals must be recognized based on context - there is no + * quoting or escaping support. There's also nothing to explicitly indicate + * when a label section completes. We deal with that by ending a label + * section whenever we see a line that doesn't include. + * + * As with the syslinux family, this same file format could be reused in the + * future for non pxe purposes. The only action it takes during parsing that + * would throw this off is handling of include files. It assumes we're using + * pxe, and does a tftp download of a file listed as an include file in the + * middle of the parsing operation. That could be handled by refactoring it to + * take a 'include file getter' function. + */ + +/* + * Describes a single label given in a pxe file. + * + * Create these with the 'label_create' function given below. + * + * name - the name of the menu as given on the 'menu label' line. + * kernel - the path to the kernel file to use for this label. + * append - kernel command line to use when booting this label + * initrd - path to the initrd to use for this label. + * attempted - 0 if we haven't tried to boot this label, 1 if we have. + * localboot - 1 if this label specified 'localboot', 0 otherwise. + * list - lets these form a list, which a pxe_menu struct will hold. + */ +struct pxe_label { + char num[4]; + char *name; + char *menu; + char *kernel; + char *config; + char *append; + char *initrd; + char *fdt; + char *fdtdir; + char *fdtoverlays; + int ipappend; + int attempted; + int localboot; + int localboot_val; + struct list_head list; +}; + +/* + * Describes a pxe menu as given via pxe files. + * + * title - the name of the menu as given by a 'menu title' line. + * default_label - the name of the default label, if any. + * bmp - the bmp file name which is displayed in background + * timeout - time in tenths of a second to wait for a user key-press before + * booting the default label. + * prompt - if 0, don't prompt for a choice unless the timeout period is + * interrupted. If 1, always prompt for a choice regardless of + * timeout. + * labels - a list of labels defined for the menu. + */ +struct pxe_menu { + char *title; + char *default_label; + char *bmp; + int timeout; + int prompt; + struct list_head labels; +}; + +struct pxe_context; +typedef int (*pxe_getfile_func)(struct pxe_context *ctx, 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 + * @getfile: Function called by PXE to read a file + * @userdata: Data the caller requires for @getfile + * @allow_abs_path: true to allow absolute paths + */ +struct pxe_context { + struct cmd_tbl *cmdtp; + /** + * getfile() - read a file + * + * @ctx: PXE context + * @file_path: Path to the file + * @file_addr: String containing the hex address to put the file in + * memory + * Return 0 if OK, -ve on error + */ + pxe_getfile_func getfile; + + void *userdata; + bool allow_abs_path; +}; + +/** + * 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); + +/** + * get_pxe_file() - Read a file + * + * Retrieve the file at 'file_path' to the locate given by 'file_addr'. If + * 'bootfile' was specified in the environment, the path to bootfile will be + * prepended to 'file_path' and the resulting path will be used. + * + * @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 pxe_context *ctx, const char *file_path, + ulong file_addr); + +/** + * get_pxelinux_path() - Read a file from the same place as pxelinux.cfg + * + * Retrieves a file in the 'pxelinux.cfg' folder. Since this uses get_pxe_file() + * to do the hard work, the location of the 'pxelinux.cfg' folder is generated + * from the bootfile path, as described in get_pxe_file(). + * + * @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 pxe_context *ctx, const char *file, + ulong pxefile_addr_r); + +/** + * handle_pxe_menu() - Boot the system as prescribed by a pxe_menu. + * + * Use the menu system to either get the user's choice or the default, based + * on config or user input. If there is no default or user's choice, + * attempted to boot labels in the order they were given in pxe files. + * If the default or user's choice fails to boot, attempt to boot other + * labels in the order they were given in pxe files. + * + * If this function returns, there weren't any labels that successfully + * booted, or the user interrupted the menu selection via ctrl+c. + * + * @ctx: PXE context + * @cfg: PXE menu + */ +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. + * + * @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 pxe_context *ctx, ulong menucfg); + +/** + * format_mac_pxe() - Convert a MAC address to PXE format + * + * Convert an ethaddr from the environment to the format used by pxelinux + * filenames based on mac addresses. Convert's ':' to '-', and adds "01-" to + * the beginning of the ethernet address to indicate a hardware type of + * Ethernet. Also converts uppercase hex characters into lowercase, to match + * pxelinux's behavior. + * + * @outbuf: Buffer to hold the output (must hold 22 bytes) + * @outbuf_len: Length of buffer + * Returns 1 for success, -ENOENT if 'ethaddr' is undefined in the + * environment, or some other value < 0 on error. + */ +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 + * @getfile: Function to call to read a file + * @userdata: Data the caller requires for @getfile - stored in ctx->userdata + * @allow_abs_path: true to allow absolute paths + */ +void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, + pxe_getfile_func getfile, void *userdata, + bool allow_abs_path); + +#endif /* __PXE_UTILS_H */ -- cgit v1.3.1 From 9e62e7ca543ea94a46f30053262f67202e2435f4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:03 -0600 Subject: pxe: Move common parsing coding into pxe_util Both the syslinux and pxe commands use essentially the same code to parse and run extlinux.conf files. Move this into a common function. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin Reviewed-by: Ramon Fried --- boot/pxe_utils.c | 20 ++++++++++++++++++++ cmd/pxe.c | 15 ++++----------- cmd/sysboot.c | 18 ++++-------------- include/pxe_utils.h | 9 +++++++++ 4 files changed, 37 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 6ecd15ceada..f40ad2b161e 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -1505,3 +1505,23 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, ctx->userdata = userdata; ctx->allow_abs_path = allow_abs_path; } + +int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt) +{ + struct pxe_menu *cfg; + + cfg = parse_pxefile(ctx, pxefile_addr_r); + if (!cfg) { + printf("Error parsing config file\n"); + return 1; + } + + if (prompt) + cfg->prompt = 1; + + handle_pxe_menu(ctx, cfg); + + destroy_pxe_menu(cfg); + + return 0; +} diff --git a/cmd/pxe.c b/cmd/pxe.c index 17fe364bed9..4fa51d2e053 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -171,9 +171,9 @@ static int 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; + int ret; pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false); @@ -193,16 +193,9 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return 1; } - cfg = parse_pxefile(&ctx, pxefile_addr_r); - - if (!cfg) { - printf("Error parsing config file\n"); - return 1; - } - - handle_pxe_menu(&ctx, cfg); - - destroy_pxe_menu(cfg); + ret = pxe_process(&ctx, pxefile_addr_r, false); + if (ret) + return CMD_RET_FAILURE; copy_filename(net_boot_file_name, "", sizeof(net_boot_file_name)); diff --git a/cmd/sysboot.c b/cmd/sysboot.c index b81255e155a..7ee14df79e5 100644 --- a/cmd/sysboot.c +++ b/cmd/sysboot.c @@ -60,10 +60,10 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, { unsigned long pxefile_addr_r; struct pxe_context ctx; - struct pxe_menu *cfg; char *pxefile_addr_str; char *filename; int prompt = 0; + int ret; if (argc > 1 && strstr(argv[1], "-p")) { prompt = 1; @@ -113,19 +113,9 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, return 1; } - cfg = parse_pxefile(&ctx, pxefile_addr_r); - - if (!cfg) { - printf("Error parsing config file\n"); - return 1; - } - - if (prompt) - cfg->prompt = 1; - - handle_pxe_menu(&ctx, cfg); - - destroy_pxe_menu(cfg); + ret = pxe_process(&ctx, pxefile_addr_r, prompt); + if (ret) + return CMD_RET_FAILURE; return 0; } diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 6681442ea55..0cae0dabec3 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -202,4 +202,13 @@ void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, pxe_getfile_func getfile, void *userdata, bool allow_abs_path); +/** + * pxe_process() - Process a PXE file through to boot + * + * @ctx: PXE context created with pxe_setup_ctx() + * @pxefile_addr_r: Address to load file + * @prompt: Force a prompt for the user + */ +int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt); + #endif /* __PXE_UTILS_H */ -- cgit v1.3.1 From 12df842ee324a7e188a643bfee6fe08f28127b26 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:04 -0600 Subject: pxe: Clean up the use of bootfile The 'bootfile' environment variable is read in the bowels of pxe_util to provide a directory to which all loaded files are relative. This is not obvious from the API to PXE and it is strange to make the caller set an environment variable rather than pass this as a parameter. The code is also convoluted, which this feature implemented by get_bootfile_path(). Update the API to improve this. Unfortunately this means that pxe_setup_ctx() can fail, so add error checking. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin Reviewed-by: Ramon Fried --- boot/pxe_utils.c | 60 +++++++++++++++++++++++++++++++++-------------------- cmd/pxe.c | 18 ++++++++++++---- cmd/sysboot.c | 15 ++++++++++---- include/pxe_utils.h | 19 ++++++++++++++--- 4 files changed, 79 insertions(+), 33 deletions(-) (limited to 'include') diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index f40ad2b161e..5d47d30a9ee 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -67,10 +67,10 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len) /** * get_bootfile_path() - Figure out the path of a file to read * - * Returns the directory the file specified in the 'bootfile' env variable is - * in. If bootfile isn't defined in the environment, return NULL, which should - * be interpreted as "don't prepend anything to paths". + * Copies the boot directory into the supplied buffer. If there is no boot + * directory, set it to "" * + * @ctx: PXE context * @file_path: File path to read (relative to the PXE file) * @bootfile_path: Place to put the bootfile path * @bootfile_path_size: Size of @bootfile_path in bytes @@ -79,34 +79,25 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len) * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the * resulting path */ -static int get_bootfile_path(const char *file_path, char *bootfile_path, - size_t bootfile_path_size, bool allow_abs_path) +static int get_bootfile_path(struct pxe_context *ctx, const char *file_path, + char *bootfile_path, size_t bootfile_path_size, + bool allow_abs_path) { - char *bootfile, *last_slash; size_t path_len = 0; /* Only syslinux allows absolute paths */ if (file_path[0] == '/' && allow_abs_path) goto ret; - bootfile = from_env("bootfile"); - if (!bootfile) - goto ret; - - last_slash = strrchr(bootfile, '/'); - if (!last_slash) - goto ret; - - path_len = (last_slash - bootfile) + 1; - - if (bootfile_path_size < path_len) { + path_len = strlen(ctx->bootdir); + if (bootfile_path_size < path_len + 1) { printf("bootfile_path too small. (%zd < %zd)\n", bootfile_path_size, path_len); return -ENOSPC; } - strncpy(bootfile_path, bootfile, path_len); + strncpy(bootfile_path, ctx->bootdir, path_len); ret: bootfile_path[path_len] = '\0'; @@ -135,7 +126,7 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path, char addr_buf[18]; int err; - err = get_bootfile_path(file_path, relfile, sizeof(relfile), + err = get_bootfile_path(ctx, file_path, relfile, sizeof(relfile), ctx->allow_abs_path); if (err < 0) return err; @@ -1496,14 +1487,39 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg) boot_unattempted_labels(ctx, cfg); } -void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, - pxe_getfile_func getfile, void *userdata, - bool allow_abs_path) +int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, + pxe_getfile_func getfile, void *userdata, + bool allow_abs_path, const char *bootfile) { + const char *last_slash; + size_t path_len = 0; + + memset(ctx, '\0', sizeof(*ctx)); ctx->cmdtp = cmdtp; ctx->getfile = getfile; ctx->userdata = userdata; ctx->allow_abs_path = allow_abs_path; + + /* figure out the boot directory, if there is one */ + if (bootfile && strlen(bootfile) >= MAX_TFTP_PATH_LEN) + return -ENOSPC; + ctx->bootdir = strdup(bootfile ? bootfile : ""); + if (!ctx->bootdir) + return -ENOMEM; + + if (bootfile) { + last_slash = strrchr(bootfile, '/'); + if (last_slash) + path_len = (last_slash - bootfile) + 1; + } + ctx->bootdir[path_len] = '\0'; + + return 0; +} + +void pxe_destroy_ctx(struct pxe_context *ctx) +{ + free(ctx->bootdir); } int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt) diff --git a/cmd/pxe.c b/cmd/pxe.c index 4fa51d2e053..e319db51ef5 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -121,8 +121,6 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) struct pxe_context ctx; int err, i = 0; - pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false); - if (argc != 1) return CMD_RET_USAGE; @@ -136,6 +134,11 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (err < 0) return 1; + if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, + env_get("bootfile"))) { + printf("Out of memory\n"); + return CMD_RET_FAILURE; + } /* * Keep trying paths until we successfully get a file we're looking * for. @@ -144,6 +147,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) pxe_mac_path(&ctx, pxefile_addr_r) > 0 || pxe_ipaddr_paths(&ctx, pxefile_addr_r) > 0) { printf("Config file found\n"); + pxe_destroy_ctx(&ctx); return 0; } @@ -152,12 +156,14 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (get_pxelinux_path(&ctx, pxe_default_paths[i], pxefile_addr_r) > 0) { printf("Config file found\n"); + pxe_destroy_ctx(&ctx); return 0; } i++; } printf("Config file not found\n"); + pxe_destroy_ctx(&ctx); return 1; } @@ -175,8 +181,6 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) struct pxe_context ctx; int ret; - pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false); - if (argc == 1) { pxefile_addr_str = from_env("pxefile_addr_r"); if (!pxefile_addr_str) @@ -193,7 +197,13 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return 1; } + if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, + env_get("bootfile"))) { + printf("Out of memory\n"); + return CMD_RET_FAILURE; + } ret = pxe_process(&ctx, pxefile_addr_r, false); + pxe_destroy_ctx(&ctx); if (ret) return CMD_RET_FAILURE; diff --git a/cmd/sysboot.c b/cmd/sysboot.c index 7ee14df79e5..c45fed774d6 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; + pxe_getfile_func getfile; struct pxe_context ctx; char *pxefile_addr_str; char *filename; @@ -89,13 +90,12 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, env_set("bootfile", filename); } - pxe_setup_ctx(&ctx, cmdtp, NULL, NULL, true); if (strstr(argv[3], "ext2")) { - ctx.getfile = do_get_ext2; + getfile = do_get_ext2; } else if (strstr(argv[3], "fat")) { - ctx.getfile = do_get_fat; + getfile = do_get_fat; } else if (strstr(argv[3], "any")) { - ctx.getfile = do_get_any; + getfile = do_get_any; } else { printf("Invalid filesystem: %s\n", argv[3]); return 1; @@ -108,12 +108,19 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, return 1; } + if (pxe_setup_ctx(&ctx, cmdtp, getfile, NULL, true, filename)) { + printf("Out of memory\n"); + return CMD_RET_FAILURE; + } + if (get_pxe_file(&ctx, filename, pxefile_addr_r) < 0) { printf("Error reading config file\n"); + pxe_destroy_ctx(&ctx); return 1; } ret = pxe_process(&ctx, pxefile_addr_r, prompt); + pxe_destroy_ctx(&ctx); if (ret) return CMD_RET_FAILURE; diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 0cae0dabec3..543d0245c8a 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -86,6 +86,8 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path, * @getfile: Function called by PXE to read a file * @userdata: Data the caller requires for @getfile * @allow_abs_path: true to allow absolute paths + * @bootdir: Directory that files are loaded from ("" if no directory). This is + * allocated */ struct pxe_context { struct cmd_tbl *cmdtp; @@ -102,6 +104,7 @@ struct pxe_context { void *userdata; bool allow_abs_path; + char *bootdir; }; /** @@ -197,10 +200,20 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len); * @getfile: Function to call to read a file * @userdata: Data the caller requires for @getfile - stored in ctx->userdata * @allow_abs_path: true to allow absolute paths + * @bootfile: Bootfile whose directory loaded files are relative to, NULL if + * none + * @return 0 if OK, -ENOMEM if out of memory */ -void pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, - pxe_getfile_func getfile, void *userdata, - bool allow_abs_path); +int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, + pxe_getfile_func getfile, void *userdata, + bool allow_abs_path, const char *bootfile); + +/** + * pxe_destroy_ctx() - Destroy a PXE context + * + * @ctx: Context to destroy + */ +void pxe_destroy_ctx(struct pxe_context *ctx); /** * pxe_process() - Process a PXE file through to boot -- cgit v1.3.1 From 74b7a2b8815cf953ea0b72800bd9db7f0d6a119a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:05 -0600 Subject: pxe: Drop get_bootfile_path() This function no longer makes sense, since it is pretty easy to prepend the boot directory to the filename. Drop it and update its only caller. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin Reviewed-by: Ramon Fried --- boot/pxe_utils.c | 53 +++++------------------------------------------------ include/pxe_utils.h | 3 ++- 2 files changed, 7 insertions(+), 49 deletions(-) (limited to 'include') diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 5d47d30a9ee..48fb7076fd1 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -64,47 +64,6 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len) return 1; } -/** - * get_bootfile_path() - Figure out the path of a file to read - * - * Copies the boot directory into the supplied buffer. If there is no boot - * directory, set it to "" - * - * @ctx: PXE context - * @file_path: File path to read (relative to the PXE file) - * @bootfile_path: Place to put the bootfile path - * @bootfile_path_size: Size of @bootfile_path in bytes - * @allow_abs_path: true to allow an absolute path (where @file_path starts with - * '/', false to return an empty path (and success) in that case - * Returns 1 for success, -ENOSPC if bootfile_path_size is to small to hold the - * resulting path - */ -static int get_bootfile_path(struct pxe_context *ctx, const char *file_path, - char *bootfile_path, size_t bootfile_path_size, - bool allow_abs_path) -{ - size_t path_len = 0; - - /* Only syslinux allows absolute paths */ - if (file_path[0] == '/' && allow_abs_path) - goto ret; - - path_len = strlen(ctx->bootdir); - if (bootfile_path_size < path_len + 1) { - printf("bootfile_path too small. (%zd < %zd)\n", - bootfile_path_size, path_len); - - return -ENOSPC; - } - - strncpy(bootfile_path, ctx->bootdir, path_len); - - ret: - bootfile_path[path_len] = '\0'; - - return 1; -} - /** * get_relfile() - read a file relative to the PXE file * @@ -124,15 +83,13 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path, size_t path_len; char relfile[MAX_TFTP_PATH_LEN + 1]; char addr_buf[18]; - int err; - err = get_bootfile_path(ctx, file_path, relfile, sizeof(relfile), - ctx->allow_abs_path); - if (err < 0) - return err; + if (file_path[0] == '/' && ctx->allow_abs_path) + *relfile = '\0'; + else + strncpy(relfile, ctx->bootdir, MAX_TFTP_PATH_LEN); - path_len = strlen(file_path); - path_len += strlen(relfile); + path_len = strlen(file_path) + strlen(relfile); if (path_len > MAX_TFTP_PATH_LEN) { printf("Base path too long (%s%s)\n", relfile, file_path); diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 543d0245c8a..8b50f2e6861 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -202,7 +202,8 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len); * @allow_abs_path: true to allow absolute paths * @bootfile: Bootfile whose directory loaded files are relative to, NULL if * none - * @return 0 if OK, -ENOMEM if out of memory + * @return 0 if OK, -ENOMEM if out of memory, -E2BIG if bootfile is larger than + * MAX_TFTP_PATH_LEN bytes */ int pxe_setup_ctx(struct pxe_context *ctx, struct cmd_tbl *cmdtp, pxe_getfile_func getfile, void *userdata, -- cgit v1.3.1 From 3bfb0f719a196558f909ca568f3803f86a190509 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:06 -0600 Subject: lib: Add tests for simple_itoa() Add test and a comment for this function. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin --- include/vsprintf.h | 13 ++++++++++++- test/print_ut.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/vsprintf.h b/include/vsprintf.h index 83d187e53d4..4479df0af3f 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -172,7 +172,18 @@ int sprintf(char *buf, const char *fmt, ...) * See the vsprintf() documentation for format string extensions over C99. */ int vsprintf(char *buf, const char *fmt, va_list args); -char *simple_itoa(ulong i); + +/** + * simple_itoa() - convert an unsigned integer to a string + * + * This returns a static string containing the decimal representation of the + * given value. The returned value may be overwritten by other calls to the + * same function, so should be used immediately + * + * @val: Value to convert + * @return string containing the decimal representation of @val + */ +char *simple_itoa(ulong val); /** * Format a string and place it in a buffer diff --git a/test/print_ut.c b/test/print_ut.c index 11d8580e55c..4fbb15b6d3c 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -328,6 +329,22 @@ static int print_do_hex_dump(struct unit_test_state *uts) } PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC); +static int print_itoa(struct unit_test_state *uts) +{ + ut_asserteq_str("123", simple_itoa(123)); + ut_asserteq_str("0", simple_itoa(0)); + ut_asserteq_str("2147483647", simple_itoa(0x7fffffff)); + ut_asserteq_str("4294967295", simple_itoa(0xffffffff)); + if (sizeof(ulong) == 8) { + ut_asserteq_str("9223372036854775807", + simple_itoa((1UL << 63) - 1)); + ut_asserteq_str("18446744073709551615", simple_itoa(-1)); + } + + return 0; +} +PRINT_TEST(print_itoa, 0); + int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(print_test); -- cgit v1.3.1 From 4a255ea3b65e7793eea97a90ad00dc2b59889683 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:07 -0600 Subject: lib: Add a function to convert a string to a hex value Add an xtoa() function, similar to itoa() but for hex instead. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin --- include/vsprintf.h | 16 ++++++++++++++-- lib/vsprintf.c | 20 ++++++++++++++++++-- test/print_ut.c | 24 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/vsprintf.h b/include/vsprintf.h index 4479df0af3f..b4746301462 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -177,14 +177,26 @@ int vsprintf(char *buf, const char *fmt, va_list args); * simple_itoa() - convert an unsigned integer to a string * * This returns a static string containing the decimal representation of the - * given value. The returned value may be overwritten by other calls to the - * same function, so should be used immediately + * given value. The returned value may be overwritten by other calls to other + * simple_... functions, so should be used immediately * * @val: Value to convert * @return string containing the decimal representation of @val */ char *simple_itoa(ulong val); +/** + * simple_xtoa() - convert an unsigned integer to a hex string + * + * This returns a static string containing the hexadecimal representation of the + * given value. The returned value may be overwritten by other calls to other + * simple_... functions, so should be used immediately + * + * @val: Value to convert + * @return string containing the hexecimal representation of @val + */ +char *simple_xtoa(ulong num); + /** * Format a string and place it in a buffer * diff --git a/lib/vsprintf.c b/lib/vsprintf.c index d7ee35b4773..e634bd70b66 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -816,11 +816,12 @@ int vprintf(const char *fmt, va_list args) } #endif +static char local_toa[22]; + char *simple_itoa(ulong i) { /* 21 digits plus null terminator, good for 64-bit or smaller ints */ - static char local[22]; - char *p = &local[21]; + char *p = &local_toa[21]; *p-- = '\0'; do { @@ -830,6 +831,21 @@ char *simple_itoa(ulong i) return p + 1; } +char *simple_xtoa(ulong num) +{ + /* 16 digits plus nul terminator, good for 64-bit or smaller ints */ + char *p = &local_toa[17]; + + *--p = '\0'; + do { + p -= 2; + hex_byte_pack(p, num & 0xff); + num >>= 8; + } while (num > 0); + + return p; +} + /* We don't seem to have %'d in U-Boot */ void print_grouped_ull(unsigned long long int_val, int digits) { diff --git a/test/print_ut.c b/test/print_ut.c index 4fbb15b6d3c..152a8c3334f 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -335,16 +335,40 @@ static int print_itoa(struct unit_test_state *uts) ut_asserteq_str("0", simple_itoa(0)); ut_asserteq_str("2147483647", simple_itoa(0x7fffffff)); ut_asserteq_str("4294967295", simple_itoa(0xffffffff)); + + /* Use #ifdef here to avoid a compiler warning on 32-bit machines */ +#ifdef CONFIG_PHYS_64BIT if (sizeof(ulong) == 8) { ut_asserteq_str("9223372036854775807", simple_itoa((1UL << 63) - 1)); ut_asserteq_str("18446744073709551615", simple_itoa(-1)); } +#endif /* CONFIG_PHYS_64BIT */ return 0; } PRINT_TEST(print_itoa, 0); +static int print_xtoa(struct unit_test_state *uts) +{ + ut_asserteq_str("7f", simple_xtoa(127)); + ut_asserteq_str("00", simple_xtoa(0)); + ut_asserteq_str("7fffffff", simple_xtoa(0x7fffffff)); + ut_asserteq_str("ffffffff", simple_xtoa(0xffffffff)); + + /* Use #ifdef here to avoid a compiler warning on 32-bit machines */ +#ifdef CONFIG_PHYS_64BIT + if (sizeof(ulong) == 8) { + ut_asserteq_str("7fffffffffffffff", + simple_xtoa((1UL << 63) - 1)); + ut_asserteq_str("ffffffffffffffff", simple_xtoa(-1)); + } +#endif /* CONFIG_PHYS_64BIT */ + + return 0; +} +PRINT_TEST(print_xtoa, 0); + int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(print_test); -- cgit v1.3.1 From 4d79e884adf6842beb94566bf5249c07a84a5b51 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:08 -0600 Subject: pxe: Return the file size from the getfile() function It is pretty strange that the pxe code uses the 'filesize' environment variable find the size of a file it has just read. Partly this is because it uses the command-line interpreter to parse its request to load the file. As a first step towards unwinding this, return it directly from the getfile() function. This makes the code a bit longer, for now, but will be cleaned up in future patches. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin Reviewed-by: Ramon Fried --- boot/pxe_utils.c | 70 ++++++++++++++++++++++++++++++++--------------------- cmd/pxe.c | 7 +++++- cmd/sysboot.c | 21 +++++++++++++--- include/pxe_utils.h | 13 +++++++++- 4 files changed, 79 insertions(+), 32 deletions(-) (limited to 'include') diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 48fb7076fd1..a7a84f26c1d 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -30,6 +30,20 @@ #define MAX_TFTP_PATH_LEN 512 +int pxe_get_file_size(ulong *sizep) +{ + const char *val; + + val = from_env("filesize"); + if (!val) + return -ENOENT; + + if (strict_strtoul(val, 16, sizep) < 0) + return -EINVAL; + + return 0; +} + /** * format_mac_pxe() - obtain a MAC address in the PXE format * @@ -75,14 +89,17 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len) * @ctx: PXE context * @file_path: File path to read (relative to the PXE file) * @file_addr: Address to load file to + * @filesizep: If not NULL, returns the file size in bytes * Returns 1 for success, or < 0 on error */ static int get_relfile(struct pxe_context *ctx, const char *file_path, - unsigned long file_addr) + unsigned long file_addr, ulong *filesizep) { size_t path_len; char relfile[MAX_TFTP_PATH_LEN + 1]; char addr_buf[18]; + ulong size; + int ret; if (file_path[0] == '/' && ctx->allow_abs_path) *relfile = '\0'; @@ -103,7 +120,13 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path, sprintf(addr_buf, "%lx", file_addr); - return ctx->getfile(ctx, relfile, addr_buf); + ret = ctx->getfile(ctx, relfile, addr_buf, &size); + if (ret < 0) + return log_msg_ret("get", ret); + if (filesizep) + *filesizep = size; + + return 1; } /** @@ -117,29 +140,17 @@ static int get_relfile(struct pxe_context *ctx, const char *file_path, * Returns 1 for success, or < 0 on error */ int get_pxe_file(struct pxe_context *ctx, const char *file_path, - unsigned long file_addr) + ulong file_addr) { - unsigned long config_file_size; - char *tftp_filesize; + ulong size; int err; char *buf; - err = get_relfile(ctx, file_path, file_addr); + err = get_relfile(ctx, file_path, file_addr, &size); if (err < 0) return err; - /* - * the file comes without a NUL byte at the end, so find out its size - * and add the NUL byte. - */ - tftp_filesize = from_env("filesize"); - if (!tftp_filesize) - return -ENOENT; - - if (strict_strtoul(tftp_filesize, 16, &config_file_size) < 0) - return -EINVAL; - - buf = map_sysmem(file_addr + config_file_size, 1); + buf = map_sysmem(file_addr + size, 1); *buf = '\0'; unmap_sysmem(buf); @@ -184,12 +195,13 @@ int get_pxelinux_path(struct pxe_context *ctx, const char *file, * @file_path: File path to read (relative to the PXE file) * @envaddr_name: Name of environment variable which contains the address to * load to + * @filesizep: Returns the file size in bytes * Returns 1 on success, -ENOENT if @envaddr_name does not exist as an * environment variable, -EINVAL if its format is not valid hex, or other * value < 0 on other error */ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path, - const char *envaddr_name) + const char *envaddr_name, ulong *filesizep) { unsigned long file_addr; char *envaddr; @@ -201,7 +213,7 @@ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path, if (strict_strtoul(envaddr, 16, &file_addr) < 0) return -EINVAL; - return get_relfile(ctx, file_path, file_addr); + return get_relfile(ctx, file_path, file_addr, filesizep); } /** @@ -357,8 +369,8 @@ static void label_boot_fdtoverlay(struct pxe_context *ctx, goto skip_overlay; /* Load overlay file */ - err = get_relfile_envaddr(ctx, overlayfile, - "fdtoverlay_addr_r"); + err = get_relfile_envaddr(ctx, overlayfile, "fdtoverlay_addr_r", + NULL); if (err < 0) { printf("Failed loading overlay %s\n", overlayfile); goto skip_overlay; @@ -443,21 +455,25 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label) } if (label->initrd) { - if (get_relfile_envaddr(ctx, label->initrd, "ramdisk_addr_r") < 0) { + ulong size; + + if (get_relfile_envaddr(ctx, label->initrd, "ramdisk_addr_r", + &size) < 0) { printf("Skipping %s for failure retrieving initrd\n", label->name); return 1; } initrd_addr_str = env_get("ramdisk_addr_r"); - strncpy(initrd_filesize, env_get("filesize"), 9); + strcpy(initrd_filesize, simple_xtoa(size)); strncpy(initrd_str, initrd_addr_str, 18); strcat(initrd_str, ":"); strncat(initrd_str, initrd_filesize, 9); } - if (get_relfile_envaddr(ctx, label->kernel, "kernel_addr_r") < 0) { + if (get_relfile_envaddr(ctx, label->kernel, "kernel_addr_r", + NULL) < 0) { printf("Skipping %s for failure retrieving kernel\n", label->name); return 1; @@ -599,7 +615,7 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label) if (fdtfile) { int err = get_relfile_envaddr(ctx, fdtfile, - "fdt_addr_r"); + "fdt_addr_r", NULL); free(fdtfilefree); if (err < 0) { @@ -1403,7 +1419,7 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg) if (IS_ENABLED(CONFIG_CMD_BMP)) { /* display BMP if available */ if (cfg->bmp) { - if (get_relfile(ctx, cfg->bmp, image_load_addr)) { + if (get_relfile(ctx, cfg->bmp, image_load_addr, NULL)) { if (CONFIG_IS_ENABLED(CMD_CLS)) run_command("cls", 0); bmp_display(image_load_addr, diff --git a/cmd/pxe.c b/cmd/pxe.c index e319db51ef5..81703386c42 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -25,15 +25,20 @@ const char *pxe_default_paths[] = { }; static int do_get_tftp(struct pxe_context *ctx, const char *file_path, - char *file_addr) + char *file_addr, ulong *sizep) { char *tftp_argv[] = {"tftp", NULL, NULL, NULL}; + int ret; tftp_argv[1] = file_addr; tftp_argv[2] = (void *)file_path; if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv)) return -ENOENT; + ret = pxe_get_file_size(sizep); + if (ret) + return log_msg_ret("tftp", ret); + ctx->pxe_file_size = *sizep; return 1; } diff --git a/cmd/sysboot.c b/cmd/sysboot.c index c45fed774d6..6344ecd357b 100644 --- a/cmd/sysboot.c +++ b/cmd/sysboot.c @@ -9,43 +9,58 @@ static char *fs_argv[5]; static int do_get_ext2(struct pxe_context *ctx, const char *file_path, - char *file_addr) + char *file_addr, ulong *sizep) { #ifdef CONFIG_CMD_EXT2 + int ret; + fs_argv[0] = "ext2load"; fs_argv[3] = file_addr; fs_argv[4] = (void *)file_path; if (!do_ext2load(ctx->cmdtp, 0, 5, fs_argv)) return 1; + ret = pxe_get_file_size(sizep); + if (ret) + return log_msg_ret("tftp", ret); #endif return -ENOENT; } static int do_get_fat(struct pxe_context *ctx, const char *file_path, - char *file_addr) + char *file_addr, ulong *sizep) { #ifdef CONFIG_CMD_FAT + int ret; + fs_argv[0] = "fatload"; fs_argv[3] = file_addr; fs_argv[4] = (void *)file_path; if (!do_fat_fsload(ctx->cmdtp, 0, 5, fs_argv)) return 1; + ret = pxe_get_file_size(sizep); + if (ret) + return log_msg_ret("tftp", ret); #endif return -ENOENT; } static int do_get_any(struct pxe_context *ctx, const char *file_path, - char *file_addr) + char *file_addr, ulong *sizep) { #ifdef CONFIG_CMD_FS_GENERIC + int ret; + fs_argv[0] = "load"; fs_argv[3] = file_addr; fs_argv[4] = (void *)file_path; if (!do_load(ctx->cmdtp, 0, 5, fs_argv, FS_TYPE_ANY)) return 1; + ret = pxe_get_file_size(sizep); + if (ret) + return log_msg_ret("tftp", ret); #endif return -ENOENT; } diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 8b50f2e6861..194a5ed8cc7 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -77,7 +77,7 @@ struct pxe_menu { struct pxe_context; typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path, - char *file_addr); + char *file_addr, ulong *filesizep); /** * struct pxe_context - context information for PXE parsing @@ -88,6 +88,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path, * @allow_abs_path: true to allow absolute paths * @bootdir: Directory that files are loaded from ("" if no directory). This is * allocated + * @pxe_file_size: Size of the PXE file */ struct pxe_context { struct cmd_tbl *cmdtp; @@ -98,6 +99,7 @@ struct pxe_context { * @file_path: Path to the file * @file_addr: String containing the hex address to put the file in * memory + * @filesizep: Returns the file size in bytes * Return 0 if OK, -ve on error */ pxe_getfile_func getfile; @@ -105,6 +107,7 @@ struct pxe_context { void *userdata; bool allow_abs_path; char *bootdir; + ulong pxe_file_size; }; /** @@ -225,4 +228,12 @@ void pxe_destroy_ctx(struct pxe_context *ctx); */ int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt); +/** + * pxe_get_file_size() - Read the value of the 'filesize' environment variable + * + * @sizep: Place to put the value + * @return 0 if OK, -ENOENT if no such variable, -EINVAL if format is invalid + */ +int pxe_get_file_size(ulong *sizep); + #endif /* __PXE_UTILS_H */ -- cgit v1.3.1 From d50244e9d8583378770392fb429a0283b2b47885 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 14 Oct 2021 12:48:11 -0600 Subject: pxe: Allow calling the pxe_get logic directly Refactor this code so that we can call the 'pxe get' command without going through the command-line interpreter. This makes it easier to get the information we need, without going through environment variables. Signed-off-by: Simon Glass Reviewed-by: Artem Lapkin Tested-by: Artem Lapkin Reviewed-by: Ramon Fried --- cmd/pxe.c | 92 ++++++++++++++++++++++++++++++++++------------------- include/pxe_utils.h | 14 ++++++++ 2 files changed, 73 insertions(+), 33 deletions(-) (limited to 'include') diff --git a/cmd/pxe.c b/cmd/pxe.c index 81703386c42..db8e4697f24 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -104,6 +104,49 @@ static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_ return -ENOENT; } + +int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep) +{ + struct cmd_tbl cmdtp[] = {}; /* dummy */ + struct pxe_context ctx; + int i; + + if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, + env_get("bootfile"))) + return -ENOMEM; + /* + * Keep trying paths until we successfully get a file we're looking + * for. + */ + 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) + goto done; + + i = 0; + while (pxe_default_paths[i]) { + if (get_pxelinux_path(&ctx, pxe_default_paths[i], + pxefile_addr_r) > 0) + goto done; + i++; + } + + pxe_destroy_ctx(&ctx); + + return -ENOENT; +done: + *bootdirp = env_get("bootfile"); + + /* + * The PXE file size is returned but not the name. It is probably not + * that useful. + */ + *sizep = ctx.pxe_file_size; + pxe_destroy_ctx(&ctx); + + return 0; +} + /* * Entry point for the 'pxe get' command. * This Follows pxelinux's rules to download a config file from a tftp server. @@ -122,9 +165,10 @@ static int 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; + ulong pxefile_addr_r; + char *fname; + ulong size; + int ret; if (argc != 1) return CMD_RET_USAGE; @@ -134,43 +178,25 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (!pxefile_addr_str) return 1; - err = strict_strtoul(pxefile_addr_str, 16, + ret = strict_strtoul(pxefile_addr_str, 16, (unsigned long *)&pxefile_addr_r); - if (err < 0) + if (ret < 0) return 1; - if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, - env_get("bootfile"))) { + ret = pxe_get(pxefile_addr_r, &fname, &size); + switch (ret) { + case 0: + printf("Config file '%s' found\n", fname); + break; + case -ENOMEM: printf("Out of memory\n"); return CMD_RET_FAILURE; + default: + printf("Config file not found\n"); + return CMD_RET_FAILURE; } - /* - * Keep trying paths until we successfully get a file we're looking - * for. - */ - 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"); - pxe_destroy_ctx(&ctx); - - return 0; - } - - while (pxe_default_paths[i]) { - if (get_pxelinux_path(&ctx, pxe_default_paths[i], - pxefile_addr_r) > 0) { - printf("Config file found\n"); - pxe_destroy_ctx(&ctx); - return 0; - } - i++; - } - - printf("Config file not found\n"); - pxe_destroy_ctx(&ctx); - return 1; + return 0; } /* diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 194a5ed8cc7..b7037f841a6 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -236,4 +236,18 @@ int pxe_process(struct pxe_context *ctx, ulong pxefile_addr_r, bool prompt); */ int pxe_get_file_size(ulong *sizep); +/** + * pxe_get() - Get the PXE file from the server + * + * This tries various filenames to obtain a PXE file + * + * @pxefile_addr_r: Address to put file + * @bootdirp: Returns the boot filename, or NULL if none. This is the 'bootfile' + * option provided by the DHCP server. If none, returns NULL. For example, + * "rpi/info", which indicates that all files should be fetched from the + * "rpi/" subdirectory + * @sizep: Size of the PXE file (not bootfile) + */ +int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep); + #endif /* __PXE_UTILS_H */ -- cgit v1.3.1 From 7e713067eef3f713b989416df0dfd061b087ac0f Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Tue, 26 Oct 2021 14:31:18 +0200 Subject: Remove LYNX KDI remainders The last board that used to set CONFIG_LYNXKDI has been removed in commit 242836a893ae ("powerpc: ppc4xx: remove pcs440ep support"), doc/README.lynxkdi only talks about a MPC8260 board being supported, and the mpc8260 support has been removed four years ago in commit 2eb48ff7a210d ("powerpc, 8260: remove support for mpc8260") already, and common/lynxkdi.c only consists of an "#error" statement these days, so it seems like the LYNX KDI code is dead code nowadays. Let's remove it now. Signed-off-by: Thomas Huth --- boot/bootm_os.c | 25 ------------------- boot/image.c | 2 +- common/Makefile | 1 - common/lynxkdi.c | 23 ------------------ doc/README.lynxkdi | 57 -------------------------------------------- include/bootm.h | 1 - include/lynxkdi.h | 24 ------------------- scripts/config_whitelist.txt | 1 - 8 files changed, 1 insertion(+), 133 deletions(-) delete mode 100644 common/lynxkdi.c delete mode 100644 doc/README.lynxkdi delete mode 100644 include/lynxkdi.h (limited to 'include') diff --git a/boot/bootm_os.c b/boot/bootm_os.c index 39623f9126b..e635c72709c 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -138,28 +138,6 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], } #endif /* CONFIG_BOOTM_NETBSD*/ -#ifdef CONFIG_LYNXKDI -static int do_bootm_lynxkdi(int flag, int argc, char *const argv[], - bootm_headers_t *images) -{ - image_header_t *hdr = &images->legacy_hdr_os_copy; - - if (flag != BOOTM_STATE_OS_GO) - return 0; - -#if defined(CONFIG_FIT) - if (!images->legacy_hdr_valid) { - fit_unsupported_reset("Lynx"); - return 1; - } -#endif - - lynxkdi_boot((image_header_t *)hdr); - - return 1; -} -#endif /* CONFIG_LYNXKDI */ - #ifdef CONFIG_BOOTM_RTEMS static int do_bootm_rtems(int flag, int argc, char *const argv[], bootm_headers_t *images) @@ -570,9 +548,6 @@ static boot_os_fn *boot_os[] = { #ifdef CONFIG_BOOTM_NETBSD [IH_OS_NETBSD] = do_bootm_netbsd, #endif -#ifdef CONFIG_LYNXKDI - [IH_OS_LYNXOS] = do_bootm_lynxkdi, -#endif #ifdef CONFIG_BOOTM_RTEMS [IH_OS_RTEMS] = do_bootm_rtems, #endif diff --git a/boot/image.c b/boot/image.c index 3fa60b58279..992e72991da 100644 --- a/boot/image.c +++ b/boot/image.c @@ -106,7 +106,7 @@ static const table_entry_t uimage_os[] = { { IH_OS_INVALID, "invalid", "Invalid OS", }, { IH_OS_ARM_TRUSTED_FIRMWARE, "arm-trusted-firmware", "ARM Trusted Firmware" }, { IH_OS_LINUX, "linux", "Linux", }, -#if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC) +#if defined(USE_HOSTCC) { IH_OS_LYNXOS, "lynxos", "LynxOS", }, #endif { IH_OS_NETBSD, "netbsd", "NetBSD", }, diff --git a/common/Makefile b/common/Makefile index afaf8e5048a..c500bcd7d8a 100644 --- a/common/Makefile +++ b/common/Makefile @@ -41,7 +41,6 @@ obj-$(CONFIG_LCD) += lcd.o lcd_console.o endif obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o -obj-$(CONFIG_LYNXKDI) += lynxkdi.o obj-$(CONFIG_MENU) += menu.o obj-$(CONFIG_UPDATE_COMMON) += update.o obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o diff --git a/common/lynxkdi.c b/common/lynxkdi.c deleted file mode 100644 index 1c8e122c329..00000000000 --- a/common/lynxkdi.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) Orbacom Systems, Inc - * All rights reserved. - * - * Redistribution and use in source and binary forms are freely - * permitted provided that the above copyright notice and this - * paragraph and the following disclaimer are duplicated in all - * such forms. - * - * This software is provided "AS IS" and without any express or - * implied warranties, including, without limitation, the implied - * warranties of merchantability and fitness for a particular - * purpose. - */ - -#include -#include -#include -#include - -#include - -#error "Lynx KDI support not implemented for configured CPU" diff --git a/doc/README.lynxkdi b/doc/README.lynxkdi deleted file mode 100644 index 076f01862a1..00000000000 --- a/doc/README.lynxkdi +++ /dev/null @@ -1,57 +0,0 @@ - LYNX KDI SUPPORT - - Last Update: July 20, 2003 -======================================================================= - -This file describes support for LynuxWorks KDI within U-Boot. Support -is enabled by defining CONFIG_LYNXKDI. - - -LYNXOS AND BLUECAT SUPPORTED -============================ -Both LynxOS and BlueCat linux KDIs are supported. The implementation -automatically detects which is being booted. When you use mkimage -you should specify "lynxos" for both (see target-specific notes). - - -SUPPORTED ARCHITECTURE/TARGETS -============================== -The following targets have been tested: - --PowerPC MPC8260ADS - - -FILES TO LOOK AT -================ -include/lynxkdi.h -defines a simple struct passed to a kdi. -common/lynxkdi.c -implements the call to the kdi. -common/cmd_bootm.c -top-level command implementation ("bootm"). - - -==================================================================== -TARGET SPECIFIC NOTES -==================================================================== - -MPC8260ADS -=========== -The default LynxOS and BlueCat implementations require some -modifications to the config file. - -Edit include/configs/MPC8260ADS.h to use the following: - -#define CONFIG_SYS_IMMR 0xFA200000 -#define CONFIG_SYS_BCSR 0xFA100000 -#define CONFIG_SYS_BR1_PRELIM 0xFA101801 - -When creating a LynxOS or BlueCat u-boot image using mkimage, -you must specify the following: - -Both: -A ppc -O lynxos -T kernel -C none -LynxOS: -a 0x00004000 -e 0x00004020 -BlueCat: -a 0x00500000 -e 0x00507000 - -To pass the MAC address to BlueCat you should define the -"fcc2_ether_addr" parameter in the "bootargs" environment -variable. E.g.: - -==> setenv bootargs fcc2_ether_addr=00:11:22:33:44:55:66 diff --git a/include/bootm.h b/include/bootm.h index 7f88ec718b8..48fc668cf3b 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -39,7 +39,6 @@ extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks; int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); -void lynxkdi_boot(image_header_t *hdr); boot_os_fn *bootm_os_get_boot_func(int os); diff --git a/include/lynxkdi.h b/include/lynxkdi.h deleted file mode 100644 index 38640277b29..00000000000 --- a/include/lynxkdi.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * (C) Copyright 2003 - * Orbacom Systems, Inc. - */ - -#ifndef __LYNXKDI_H__ -#define __LYNXKDI_H__ - - -/* Boot parameter struct passed to kernel - */ -typedef struct lynxos_bootparms_t { - uint8_t rsvd1[2]; /* Reserved */ - uint8_t ethaddr[6]; /* Ethernet address */ - uint16_t flags; /* Boot flags */ - uint32_t rate; /* System frequency */ - uint32_t clock_ref; /* Time reference */ - uint32_t dramsz; /* DRAM size */ - uint32_t rsvd2; /* Reserved */ -} lynxos_bootparms_t; - - -#endif /* __LYNXKDI_H__ */ diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index f6ca93fa5cf..34c9ef0ced0 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -741,7 +741,6 @@ CONFIG_LQ038J7DH53 CONFIG_LS102XA_STREAM_ID CONFIG_LSCHLV2 CONFIG_LSXHL -CONFIG_LYNXKDI CONFIG_M41T94_SPI_CS CONFIG_M520x CONFIG_M5301x -- cgit v1.3.1