All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND v1] pxe_utils: add localcmd defination
@ 2021-03-02  3:29 Artem Lapkin
  0 siblings, 0 replies; only message in thread
From: Artem Lapkin @ 2021-03-02  3:29 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=$tftp_remote_ip && 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>

---
v1:
- fix free(label->localcmd) add proper realloc for multiline localcmd
---
 cmd/pxe_utils.c | 39 ++++++++++++++++++++++++++++++++++++++-
 cmd/pxe_utils.h |  1 +
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index f1ed671a..1fab3d9a 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 +476,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 +698,8 @@ enum token_type {
 	T_APPEND,
 	T_INITRD,
 	T_LOCALBOOT,
+	T_LOCALCMD,
+	T_LOCALCMD2,
 	T_DEFAULT,
 	T_PROMPT,
 	T_INCLUDE,
@@ -721,6 +734,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 +1117,7 @@ static int parse_label(char **c, struct pxe_menu *cfg)
 	int len;
 	char *s = *c;
 	struct pxe_label *label;
+	char *add, *p;
 	int err;
 
 	label = label_create();
@@ -1177,6 +1193,27 @@ 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) {
+				err = parse_sliteral(c, &add);
+				if (err) {
+					p = realloc(label->localcmd,
+						    strlen(label->localcmd) +
+						    strlen(add) + 2);
+					if (p) {
+						label->localcmd = p;
+						sprintf(label->localcmd,
+							"%s\n%s",
+							label->localcmd, add);
+					}
+					free(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] only message in thread

only message in thread, other threads:[~2021-03-02  3:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02  3:29 [RESEND v1] pxe_utils: add localcmd defination Artem Lapkin

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.