[PATCH v2 2/2] pxe_utils: Clean up {bootm,zboot}_argv generation

Zhaofeng Li hello at zhaofeng.li
Wed Oct 20 09:18:15 CEST 2021


Signed-off-by: Zhaofeng Li <hello at zhaofeng.li>
Cc: Simon Glass <sjg at chromium.org>
Cc: Bin Meng <bmeng.cn at gmail.com>
---
 cmd/pxe_utils.c | 45 +++++++++++++++++++++++++++------------------
 1 file changed, 27 insertions(+), 18 deletions(-)

diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c
index 78ebfdcc79..b79fcb6418 100644
--- a/cmd/pxe_utils.c
+++ b/cmd/pxe_utils.c
@@ -442,15 +442,17 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
 {
 	char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
 	char *zboot_argv[] = { "zboot", NULL, "0", NULL, NULL };
-	char initrd_str[28];
+	char *kernel_addr = NULL;
+	char *initrd_addr_str = NULL;
 	char initrd_filesize[10];
+	char initrd_str[28];
 	char mac_str[29] = "";
 	char ip_str[68] = "";
 	char *fit_addr = NULL;
 	int bootm_argc = 2;
 	int zboot_argc = 3;
 	int len = 0;
-	ulong kernel_addr;
+	ulong kernel_addr_r;
 	void *buf;
 
 	label_print(label);
@@ -476,16 +478,12 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
 			return 1;
 		}
 
-		bootm_argv[2] = initrd_str;
-		strncpy(bootm_argv[2], env_get("ramdisk_addr_r"), 18);
-		strcat(bootm_argv[2], ":");
-		strncat(bootm_argv[2], env_get("filesize"), 9);
-		bootm_argc = 3;
-
+		initrd_addr_str = env_get("ramdisk_addr_r");
 		strncpy(initrd_filesize, env_get("filesize"), 9);
-		zboot_argv[3] = env_get("ramdisk_addr_r");
-		zboot_argv[4] = initrd_filesize;
-		zboot_argc = 5;
+
+		strncpy(initrd_str, initrd_addr_str, 18);
+		strcat(initrd_str, ":");
+		strncat(initrd_str, initrd_filesize, 9);
 	}
 
 	if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
@@ -536,20 +534,19 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
 		printf("append: %s\n", finalbootargs);
 	}
 
-	bootm_argv[1] = env_get("kernel_addr_r");
-	zboot_argv[1] = env_get("kernel_addr_r");
+	kernel_addr = env_get("kernel_addr_r");
 
 	/* for FIT, append the configuration identifier */
 	if (label->config) {
-		int len = strlen(bootm_argv[1]) + strlen(label->config) + 1;
+		int len = strlen(kernel_addr) + strlen(label->config) + 1;
 
 		fit_addr = malloc(len);
 		if (!fit_addr) {
 			printf("malloc fail (FIT address)\n");
 			return 1;
 		}
-		snprintf(fit_addr, len, "%s%s", bootm_argv[1], label->config);
-		bootm_argv[1] = fit_addr;
+		snprintf(fit_addr, len, "%s%s", kernel_addr, label->config);
+		kernel_addr = fit_addr;
 	}
 
 	/*
@@ -653,6 +650,18 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
 		}
 	}
 
+	bootm_argv[1] = kernel_addr;
+	zboot_argv[1] = kernel_addr;
+
+	if (initrd_addr_str) {
+		bootm_argv[2] = initrd_str;
+		bootm_argc = 3;
+
+		zboot_argv[3] = initrd_addr_str;
+		zboot_argv[4] = initrd_filesize;
+		zboot_argc = 5;
+	}
+
 	if (!bootm_argv[3])
 		bootm_argv[3] = env_get("fdt_addr");
 
@@ -662,8 +671,8 @@ static int label_boot(struct cmd_tbl *cmdtp, struct pxe_label *label)
 		bootm_argc = 4;
 	}
 
-	kernel_addr = genimg_get_kernel_addr(bootm_argv[1]);
-	buf = map_sysmem(kernel_addr, 0);
+	kernel_addr_r = genimg_get_kernel_addr(kernel_addr);
+	buf = map_sysmem(kernel_addr_r, 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);
-- 
2.33.0



More information about the U-Boot mailing list