All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pxe_utils: add localcmd defination
@ 2021-02-26  5:39 Artem Lapkin
  2021-05-08  7:38 ` Ramon Fried
  0 siblings, 1 reply; 2+ messages in thread
From: Artem Lapkin @ 2021-02-26  5:39 UTC (permalink / raw)
  To: u-boot

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@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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] pxe_utils: add localcmd defination
  2021-02-26  5:39 [PATCH] pxe_utils: add localcmd defination Artem Lapkin
@ 2021-05-08  7:38 ` Ramon Fried
  0 siblings, 0 replies; 2+ messages in thread
From: Ramon Fried @ 2021-05-08  7:38 UTC (permalink / raw)
  To: u-boot

On Fri, Feb 26, 2021 at 3:45 PM Artem Lapkin <email2tema@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@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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-08  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26  5:39 [PATCH] pxe_utils: add localcmd defination Artem Lapkin
2021-05-08  7:38 ` Ramon Fried

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.