Skip to contentSkip to conversation

New option to avoid copying old root param from 1st kernel cmdline

PATCH In review [email protected] 2 participants 5 messages Oct 28, 2015 – Oct 29, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover New option to avoid copying old root param from 1st kernel cmdline

Hi,

Here is the update patches for adding a new option --dt-no-old-root. Per previously discussion with Simon, we should consider the compatibility issue for changing the old behavior. Thus a new option is necessary

The 1st patch move the copying code to another function. The other two patches are for adding arch dependent option for arm and ppc64.

Tested kexec load on both arm and ppc64 machines.

For the latter two patches, some usage lines are over 80 characters, but I just keep same with original formats. I prefer to fix it in other patches. If you think it really need being fixed in this patchset please let me know, I can update them again.

Thanks
Dave

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#1 lore raw

PATCH 1/3 fs2dt.c: move copy old root param as a new function

Split the copy old root param code to a new function dt_copy_old_root_param Also add a global variable dt_no_old_root, do not copy root param when dt_no_old_root == 1. It will be used in later patches.

---
 kexec/fs2dt.c |   66 +++++++++++++++++++++++++++++++++++-----------------------
 kexec/fs2dt.h |    1 
 2 files changed, 41 insertions(+), 26 deletions(-)
kexec/fs2dt.c +40 -26
@@ -53,6 +53,7 @@ extern unsigned char reuse_initrd;
 /* Used for enabling printing message from purgatory code
  * Only has implemented for PPC64 */
 int my_debug;
+int dt_no_old_root;
 
 /* This provides the behaviour of hte existing ppc64 implementation */
 static void pad_structure_block(size_t len) {
@@ -511,6 +512,37 @@ static int comparefunc(const struct dire
 	return strcmp(str1, str2);
 }
 
+/* grab root= from the old command line */
+static void dt_copy_old_root_param(void)
+{
+	FILE *fp;
+	char filename[MAXPATH];
+	char *last_cmdline = NULL;
+	char *p, *old_param;
+	size_t len = 0;
+
+	strcpy(filename, pathname);
+	strcat(filename, "bootargs");
+	fp = fopen(filename, "r");
+	if (fp) {
+		if (getline(&last_cmdline, &len, fp) == -1)
+			die("unable to read %s\n", filename);
+
+		p = strstr(last_cmdline, "root=");
+		if (p) {
+			old_param = strtok(p, " ");
+			len = strlen(local_cmdline);
+			if (len != 0)
+				strcat(local_cmdline, " ");
+			strcat(local_cmdline, old_param);
+		}
+	}
+	if (last_cmdline)
+		free(last_cmdline);
+
+	fclose(fp);
+}
+
 /*
  * put a node (directory) in the property structure.  first properties
  * then children.
@@ -579,8 +611,11 @@ static void putnode(void)
 		reserve(initrd_base, initrd_size);
 	}
 
-	/* Add cmdline to the second kernel.  Check to see if the new
-	 * cmdline has a root=.  If not, use the old root= cmdline.  */
+	/*
+	 * Add cmdline to the second kernel. Use the old root= cmdline if there
+	 * is no root= in the new command line and there's no --dt-no-old-root
+	 * option being used.
+	 */
 	if (!strcmp(basename,"chosen/")) {
 		size_t result;
 		size_t cmd_len = 0;
@@ -598,30 +633,9 @@ static void putnode(void)
 			param = strstr(local_cmdline, "root=");
 		}
 
-		/* ... if not, grab root= from the old command line */
-		if (!param) {
-			FILE *fp;
-			char *last_cmdline = NULL;
-			char *old_param;
-
-			strcpy(filename, pathname);
-			strcat(filename, "bootargs");
-			fp = fopen(filename, "r");
-			if (fp) {
-				if (getline(&last_cmdline, &cmd_len, fp) == -1)
-					die("unable to read %s\n", filename);
-
-				param = strstr(last_cmdline, "root=");
-				if (param) {
-					old_param = strtok(param, " ");
-					if (cmd_len != 0)
-						strcat(local_cmdline, " ");
-					strcat(local_cmdline, old_param);
-				}
-			}
-			if (last_cmdline)
-				free(last_cmdline);
-		}
+		if (!param && !dt_no_old_root)
+			dt_copy_old_root_param();
+
 		strcat(local_cmdline, " ");
 		cmd_len = strlen(local_cmdline);
 		cmd_len = cmd_len + 1;
kexec/fs2dt.h +1 -0
@@ -31,6 +31,7 @@ extern struct bootblock bb[1];
 /* Used for enabling printing message from purgatory code
  * Only has implemented for PPC64 */
 int my_debug;
+extern int dt_no_old_root;
 
 void reserve(unsigned long long where, unsigned long long length);
 void create_flatten_tree(char **, off_t *, const char *);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

PATCH 2/3 arm: add arch option --dt-no-old-root

In reply to [email protected]

When createing fdt from /proc/device-tree, if there's local --command-line option provided but there's no root= specified, kexec-tools will copy the root= param from 1st kernel cmdline by default. In case one want kexec boot without root= it will be impossible.

Thus add the new option so that one can provide --dt-no-old-root for above mentioned case.

---
 kexec/arch/arm/include/arch/options.h |    4 +++-
 kexec/arch/arm/kexec-arm.c            |   29 ++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)
kexec/arch/arm/include/arch/options.h +3 -1
@@ -1,7 +1,8 @@
 #ifndef KEXEC_ARCH_ARM_OPTIONS_H
 #define KEXEC_ARCH_ARM_OPTIONS_H
 
-#define OPT_ARCH_MAX   (OPT_MAX+0)
+#define OPT_DT_NO_OLD_ROOT	(OPT_MAX+0)
+#define OPT_ARCH_MAX		(OPT_MAX+1)
 
 #define OPT_APPEND	'a'
 #define OPT_RAMDISK	'r'
@@ -15,6 +16,7 @@
  */
 #define KEXEC_ARCH_OPTIONS \
 	KEXEC_OPTIONS \
+	{ "dt-no-old-root",	0, 0, OPT_DT_NO_OLD_ROOT }, \
 
 #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR ""
 
kexec/arch/arm/kexec-arm.c +28 -1
@@ -16,6 +16,7 @@
 #include "../../kexec-syscall.h"
 #include "kexec-arm.h"
 #include <arch/options.h>
+#include "../../fs2dt.h"
 
 #define MAX_MEMORY_RANGES 64
 #define MAX_LINE 160
@@ -89,11 +90,37 @@ void arch_usage(void)
 	       "               including the .bss section, as reported\n"
 	       "               by 'arm-linux-size vmlinux'. If not\n"
 	       "               specified, this value is implicitly set\n"
-	       "               to the compressed images size * 4.\n");
+	       "               to the compressed images size * 4.\n"
+	       "     --dt-no-old-root\n"
+	       "               do not reuse old kernel root= param.\n"
+	       "               while creating flatten device tree.\n");
 }
 
 int arch_process_options(int argc, char **argv)
 {
+	/* We look for all options so getopt_long doesn't start reordering
+	 * argv[] before file_type[n].load() gets a look in.
+	 */
+	static const struct option options[] = {
+		KEXEC_ALL_OPTIONS
+		{ 0, 0, NULL, 0 },
+	};
+	static const char short_options[] = KEXEC_ALL_OPT_STR;
+	int opt;
+
+	opterr = 0; /* Don't complain about unrecognized options here */
+	while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
+		switch(opt) {
+		case OPT_DT_NO_OLD_ROOT:
+			dt_no_old_root = 1;
+			break;
+		default:
+			break;
+		}
+	}
+	/* Reset getopt for the next pass; called in other source modules */
+	opterr = 1;
+	optind = 1;
 	return 0;
 }
 

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#3 lore raw

PATCH 3/3 ppc64: add arch option --dt-no-old-root

In reply to [email protected]

When createing fdt from /proc/device-tree, if there's local --command-line option provided but there's no root= specified, kexec-tools will copy the root= param from 1st kernel cmdline by default. In case one want kexec boot without root= it will be impossible.

Thus add the new option so that one can provide --dt-no-old-root for above mentioned case.

---
 kexec/arch/ppc64/include/arch/options.h |    4 +++-
 kexec/arch/ppc64/kexec-ppc64.c          |    5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)
kexec/arch/ppc64/include/arch/options.h +3 -1
@@ -2,7 +2,8 @@
 #define KEXEC_ARCH_PPC64_OPTIONS_H
 
 #define OPT_ELF64_CORE		(OPT_MAX+0)
-#define OPT_ARCH_MAX		(OPT_MAX+1)
+#define OPT_DT_NO_OLD_ROOT	(OPT_MAX+1)
+#define OPT_ARCH_MAX		(OPT_MAX+2)
 
 /* All 'local' loader options: */
 #define OPT_APPEND		(OPT_ARCH_MAX+0)
@@ -14,6 +15,7 @@
 #define KEXEC_ARCH_OPTIONS \
 	KEXEC_OPTIONS \
 	{ "elf64-core-headers", 0, 0, OPT_ELF64_CORE }, \
+	{ "dt-no-old-root",	0, 0, OPT_DT_NO_OLD_ROOT }, \
 
 #define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR ""
 
kexec/arch/ppc64/kexec-ppc64.c +5 -0
@@ -869,6 +869,8 @@ int file_types = sizeof(file_type) / siz
 void arch_usage(void)
 {
 	fprintf(stderr, "     --elf64-core-headers Prepare core headers in ELF64 format\n");
+	fprintf(stderr, "     --dt-no-old-root Do not reuse old kernel root= param.\n" \
+	                "                      while creating flatten device tree.\n");
 }
 
 struct arch_options_t arch_options = {
@@ -895,6 +897,9 @@ int arch_process_options(int argc, char
 		case OPT_ELF64_CORE:
 			arch_options.core_header_type = CORE_TYPE_ELF64;
 			break;
+		case OPT_DT_NO_OLD_ROOT:
+			dt_no_old_root = 1;
+			break;
 		}
 	}
 	/* Reset getopt for the next pass; called in other source modules */

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw
In reply to [email protected]
Quoted 9 lines · On Wed, Oct 28, 2015 at 01:41:34PM +0800, [email protected] wrote:

Hi,

Here is the update patches for adding a new option --dt-no-old-root. Per previously discussion with Simon, we should consider the compatibility issue for changing the old behavior. Thus a new option is necessary

The 1st patch move the copying code to another function. The other two patches are for adding arch dependent option for arm and ppc64.

Quoted 6 lines

Tested kexec load on both arm and ppc64 machines.

For the latter two patches, some usage lines are over 80 characters, but I just keep same with original formats. I prefer to fix it in other patches. If you think it really need being fixed in this patchset please let me know, I can update them again.

Thanks, I have applied these and included them in kexec-tools 2.0.11-rc1.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec