[PATCH] pxe_utils: add localcmd defination
Ramon Fried
rfried.dev at gmail.com
Sat May 8 09:38:22 CEST 2021
On Fri, Feb 26, 2021 at 3:45 PM Artem Lapkin <email2tema at gmail.com> wrote:
>
> pxe localboot usage too much limited, i think be useful improve it
> welcome for any suggestions and feedbacks...
>
> 1) add localcmd defination which can used with localboot by default
> localboot get from env, now we can define it in pxe script
> 2) localcmd can use without localboot
> 3) multiline usage for localcmd
> 4) add short alias ! for localcmd
> 5) localcmd eval as uboot script (run_command_list)
> 6) label + localcmd simple usage uboot pxe menu with uboot commands
>
> Usage examples
>
> # standalone usage
> LABEL update_uboot
> LOCALCMD ip=$tftpip && tftpboot $ip:boot.scr.uimg && script
>
> LABEL reset
> # multiline usage
> LOCALCMD echo RESET
> LOCALCMD reset
>
> LABEL reset again
> # multiline alias usage
> ! echo RESET
> ! reset
>
> LABEL localboot
> # redefile localcmd for localboot
> LOCALBOOT 1
> LOCALCMD echo temporary redefine localcmd
>
> Signed-off-by: Artem Lapkin <art at khadas.com>
> ---
> cmd/pxe_utils.c | 29 ++++++++++++++++++++++++++++-
> cmd/pxe_utils.h | 1 +
> 2 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
> index f1ed671a..fdf532ec 100644
> --- a/cmd/pxe_utils.c
> +++ b/cmd/pxe_utils.c
> @@ -271,6 +271,9 @@ static void label_destroy(struct pxe_label *label)
> if (label->kernel)
> free(label->kernel);
>
> + if (label->localcmd)
> + free(label->localcmd);
> +
> if (label->config)
> free(label->config);
>
> @@ -322,7 +325,10 @@ static int label_localboot(struct pxe_label *label)
> {
> char *localcmd;
>
> - localcmd = from_env("localcmd");
> + if (label->localcmd)
> + localcmd = label->localcmd;
> + else
> + localcmd = from_env("localcmd");
>
> if (!localcmd)
> return -ENOENT;
> @@ -470,6 +477,11 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
> return 0;
> }
>
> + if (label->localcmd) {
> + if (!label->localboot_val)
> + return run_command_list(label->localcmd, strlen(label->localcmd), 0);
> + }
> +
> if (!label->kernel) {
> printf("No kernel given, skipping %s\n",
> label->name);
> @@ -687,6 +699,8 @@ enum token_type {
> T_APPEND,
> T_INITRD,
> T_LOCALBOOT,
> + T_LOCALCMD,
> + T_LOCALCMD2,
> T_DEFAULT,
> T_PROMPT,
> T_INCLUDE,
> @@ -721,6 +735,8 @@ static const struct token keywords[] = {
> {"kernel", T_KERNEL},
> {"linux", T_LINUX},
> {"localboot", T_LOCALBOOT},
> + {"localcmd", T_LOCALCMD},
> + {"!", T_LOCALCMD2},
> {"append", T_APPEND},
> {"initrd", T_INITRD},
> {"include", T_INCLUDE},
> @@ -1102,6 +1118,7 @@ static int parse_label(char **c, struct pxe_menu *cfg)
> int len;
> char *s = *c;
> struct pxe_label *label;
> + char *add;
> int err;
>
> label = label_create();
> @@ -1177,6 +1194,16 @@ static int parse_label(char **c, struct pxe_menu *cfg)
> err = parse_integer(c, &label->localboot_val);
> break;
>
> + case T_LOCALCMD:
> + case T_LOCALCMD2:
> + if (label->localcmd) {
> + if (parse_sliteral(c, &add))
> + sprintf(label->localcmd, "%s\n%s", label->localcmd, add);
> + } else {
> + err = parse_sliteral(c, &label->localcmd);
> + }
> + break;
> +
> case T_IPAPPEND:
> err = parse_integer(c, &label->ipappend);
> break;
> diff --git a/cmd/pxe_utils.h b/cmd/pxe_utils.h
> index bbdc606b..cdac1327 100644
> --- a/cmd/pxe_utils.h
> +++ b/cmd/pxe_utils.h
> @@ -49,6 +49,7 @@ struct pxe_label {
> int attempted;
> int localboot;
> int localboot_val;
> + char *localcmd;
> struct list_head list;
> };
>
> --
> 2.25.1
>
Hi Artem,
What is the source of these additions ? is something you came up with
or are those from pxelinux ?
Anyway, those needs to be split to separate patches, and each patch
must contain also explanation of the feature,
Add documentation to docs/README.pxe
Thanks,
Ramon.
More information about the U-Boot
mailing list