[PATCH] Externally visible buffer for CONFIG_CMDLINE

Michal Ostrowski mostrows at watson.ibm.com
Mon Aug 8 23:32:16 EST 2005


I've included a better patch which does similar things to the bzImage
wrapper code as we discussed at OLS.

On Mon, 8 Aug 2005 15:32:32 +1000
Paul Mackerras <paulus at samba.org> wrote:

> Michal Ostrowski writes:
> 
> > +#ifdef CONFIG_CMDLINE
> > +const char builtin_cmdline[COMMAND_LINE_SIZE]
> > +       __attribute__((section("__builtin_cmdline"))) = CONFIG_CMDLINE;
> > +#endif
> 
> Where does the __builtin_cmdline section get linked, given that it
> isn't mentioned explicitly in the vmlinux.lds?

There is no need to actually specify it in vmlinux.lds.  The linker will
simply create that section.  The linker will also create symbols which
let me reference the boundaries of this section (e.g.
__start___builtin_cmdline).   In my builds it ends up after .rodata and
before .pci_fixup.

-- 
Michal Ostrowski

# HG changeset patch
# User mostrows at heater.watson.ibm.com
# Node ID 8b371ee4b3b31923857f540a28fdcd3d2a42233c
# Parent  9f5416993abdaa44f3ecc9095372eeb5e9816704
Allow for built-in command line to be edited in binary images.

Define buffers for the built-in command-line strings in the bzImage
wrapper and in the early boot program.  The buffers reside in sections
called "__builtin_cmdline" and so can be easily accessed and modified
by tools.  This avoid the need to reconfigure and re-build in order to
change a built-in command line.

Precedence is always given to an existing /chosen/bootargs property
(but if one is not present bzImage wrapper will create one with the
contents of it's built-in command-line buffer).

Signed-off-by: Michal Ostrowski <mostrows at earthlink.net>

diff -r 9f5416993abd -r 8b371ee4b3b3 arch/ppc64/boot/main.c
--- a/arch/ppc64/boot/main.c	Mon Aug  8 03:00:07 2005
+++ b/arch/ppc64/boot/main.c	Mon Aug  8 13:28:34 2005
@@ -14,9 +14,11 @@
 #include <linux/string.h>
 #include <asm/processor.h>
 #include <asm/page.h>
+#include <asm/setup.h>
 
 extern void *finddevice(const char *);
 extern int getprop(void *, const char *, void *, int);
+extern int setprop(void *, const char *, void *, int);
 extern void printf(const char *fmt, ...);
 extern int sprintf(char *buf, const char *fmt, ...);
 void gunzip(void *, int, unsigned char *, int *);
@@ -73,6 +75,11 @@
 
 #undef DEBUG
 
+#ifdef CONFIG_CMDLINE
+char builtin_cmdline[COMMAND_LINE_SIZE]
+	__attribute__((section("__builtin_cmdline"))) = CONFIG_CMDLINE;
+#endif
+
 static unsigned long claim_base = PROG_START;
 
 static unsigned long try_claim(unsigned long size)
@@ -97,6 +104,7 @@
 {
 	unsigned long i;
 	kernel_entry_t kernel_entry;
+	char cmdline[COMMAND_LINE_SIZE];
 	Elf64_Ehdr *elf64;
 	Elf64_Phdr *elf64ph;
 
@@ -109,6 +117,15 @@
 	stderr = stdout;
 	if (getprop(chosen_handle, "stdin", &stdin, sizeof(stdin)) != 4)
 		exit();
+
+#ifdef CONFIG_CMDLINE
+	i = getprop(chosen_handle, "bootargs", cmdline, sizeof(cmdline));
+	if (i <= 0 || cmdline[0] == 0) {
+		setprop(chosen_handle, "bootargs", builtin_cmdline, 
+			strlen(builtin_cmdline));
+	}
+	
+#endif /* CONFIG_CMDLINE */
 
 	printf("\n\rzImage starting: loaded at 0x%x\n\r", (unsigned)_start);
 
diff -r 9f5416993abd -r 8b371ee4b3b3 arch/ppc64/boot/prom.c
--- a/arch/ppc64/boot/prom.c	Mon Aug  8 03:00:07 2005
+++ b/arch/ppc64/boot/prom.c	Mon Aug  8 13:28:34 2005
@@ -38,6 +38,7 @@
 void exit(void);
 void *finddevice(const char *name);
 int getprop(void *phandle, const char *name, void *buf, int buflen);
+int setprop(void *phandle, const char *name, void *buf, int buflen);
 void chrpboot(int a1, int a2, void *prom);	/* in main.c */
 
 int printf(char *fmt, ...);
@@ -175,6 +176,32 @@
 	} args;
 
 	args.service = "getprop";
+	args.nargs = 4;
+	args.nret = 1;
+	args.phandle = phandle;
+	args.name = name;
+	args.buf = buf;
+	args.buflen = buflen;
+	args.size = -1;
+	(*prom)(&args);
+	return args.size;
+}
+
+int
+setprop(void *phandle, const char *name, void *buf, int buflen)
+{
+	struct prom_args {
+		char *service;
+		int nargs;
+		int nret;
+		void *phandle;
+		const char *name;
+		void *buf;
+		int buflen;
+		int size;
+	} args;
+
+	args.service = "setprop";
 	args.nargs = 4;
 	args.nret = 1;
 	args.phandle = phandle;
diff -r 9f5416993abd -r 8b371ee4b3b3 arch/ppc64/kernel/prom.c
--- a/arch/ppc64/kernel/prom.c	Mon Aug  8 03:00:07 2005
+++ b/arch/ppc64/kernel/prom.c	Mon Aug  8 13:28:34 2005
@@ -72,6 +72,10 @@
 	u32 size;
 };
 
+#ifdef CONFIG_CMDLINE
+const char builtin_cmdline[COMMAND_LINE_SIZE]
+	__attribute__((section("__builtin_cmdline"))) = CONFIG_CMDLINE;
+#endif
 
 typedef int interpret_func(struct device_node *, unsigned long *,
 			   int, int, int);
@@ -870,7 +874,7 @@
 	}
 #ifdef CONFIG_CMDLINE
 	if (l == 0 || (l == 1 && (*p) == 0))
-		strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+		strlcpy(cmd_line, builtin_cmdline, sizeof(builtin_cmdline));
 #endif /* CONFIG_CMDLINE */
 
 	DBG("Command line is: %s\n", cmd_line);
diff -r 9f5416993abd -r 8b371ee4b3b3 arch/ppc64/kernel/prom_init.c
--- a/arch/ppc64/kernel/prom_init.c	Mon Aug  8 03:00:07 2005
+++ b/arch/ppc64/kernel/prom_init.c	Mon Aug  8 13:28:34 2005
@@ -56,6 +56,10 @@
 extern const struct linux_logo logo_linux_clut224;
 #endif
 
+#ifdef CONFIG_CMDLINE
+extern const char builtin_cmdline[COMMAND_LINE_SIZE];
+#endif
+
 /*
  * Properties whose value is longer than this get excluded from our
  * copy of the device tree. This value does need to be big enough to
@@ -477,7 +481,7 @@
 #ifdef CONFIG_CMDLINE
 	if (l == 0) /* dbl check */
 		strlcpy(RELOC(prom_cmd_line),
-			RELOC(CONFIG_CMDLINE), sizeof(prom_cmd_line));
+			RELOC(builtin_cmdline), sizeof(prom_cmd_line));
 #endif /* CONFIG_CMDLINE */
 	prom_printf("command line: %s\n", RELOC(prom_cmd_line));
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://ozlabs.org/pipermail/linuxppc64-dev/attachments/20050808/0b5c1514/attachment.pgp 


More information about the Linuxppc64-dev mailing list