All of lore.kernel.org
 help / color / mirror / Atom feed
From: mostrows@watson.ibm.com
To: linuxppc-dev@ozlabs.org, paulus@samba.org
Subject: [PATCH] Editable kernel command-line in zImage binary.
Date: Fri, 9 Jun 2006 09:06:12 -0400	[thread overview]
Message-ID: <11498583723378-git-send-email-mostrows@watson.ibm.com> (raw)
In-Reply-To: <17545.17329.227226.926906@cargo.ozlabs.ibm.com>

zImage will set /chosen/bootargs (if it is otherwise empty) with the
contents of a buffer in the section "__builtin_cmdline".  This permits
tools to edit zImage binaries to set the command-line eventually
processed by vmlinux.

--
Signed-off-by: Michal Ostrowski <mostrows@watson.ibm.com>

---

 arch/powerpc/boot/main.c |   27 +++++++++++++++++++++++++++
 arch/powerpc/boot/prom.h |    7 +++++++
 2 files changed, 34 insertions(+), 0 deletions(-)

40bea6ace95796a1575437d6dfdbef671012ffc1
diff --git a/arch/powerpc/boot/main.c b/arch/powerpc/boot/main.c
index 816446f..c65a7ba 100644
--- a/arch/powerpc/boot/main.c
+++ b/arch/powerpc/boot/main.c
@@ -33,6 +33,14 @@ extern char _vmlinux_end[];
 extern char _initrd_start[];
 extern char _initrd_end[];
 
+/* A buffer that may be edited by tools operating on a zImage binary so as to
+ * edit the command line passed to vmlinux (by setting /chosen/bootargs).
+ * The buffer is put in it's own section so that tools may locate it easier.
+ */
+static char builtin_cmdline[512]
+	__attribute__((section("__builtin_cmdline")));
+
+
 struct addr_range {
 	unsigned long addr;
 	unsigned long size;
@@ -204,6 +212,23 @@ static int is_elf32(void *hdr)
 	return 1;
 }
 
+void export_cmdline(void* chosen_handle)
+{
+        int len;
+        char cmdline[2] = { 0, 0 };
+
+	if (builtin_cmdline[0] == 0) 
+		return;
+
+        len = getprop(chosen_handle, "bootargs", cmdline, sizeof(cmdline));
+        if (len > 0 && cmdline[0] != 0) 
+		return;
+
+	setprop(chosen_handle, "bootargs", builtin_cmdline,
+		strlen(builtin_cmdline) + 1);
+}
+
+
 void start(unsigned long a1, unsigned long a2, void *promptr, void *sp)
 {
 	int len;
@@ -289,6 +314,8 @@ void start(unsigned long a1, unsigned lo
 		memmove((void *)vmlinux.addr,(void *)vmlinuz.addr,vmlinuz.size);
 	}
 
+	export_cmdline(chosen_handle);
+
 	/* Skip over the ELF header */
 #ifdef DEBUG
 	printf("... skipping 0x%lx bytes of ELF header\n\r",
diff --git a/arch/powerpc/boot/prom.h b/arch/powerpc/boot/prom.h
index 3e2ddd4..a57b184 100644
--- a/arch/powerpc/boot/prom.h
+++ b/arch/powerpc/boot/prom.h
@@ -31,4 +31,11 @@ static inline int getprop(void *phandle,
 	return call_prom("getprop", 4, 1, phandle, name, buf, buflen);
 }
 
+
+static inline int setprop(void *phandle, const char *name,
+			  void *buf, int buflen)
+{
+	return call_prom("setprop", 4, 1, phandle, name, buf, buflen);
+}
+
 #endif				/* _PPC_BOOT_PROM_H_ */
-- 
1.1.4.g0b63-dirty

      reply	other threads:[~2006-06-09 13:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-30  2:01 [PATCH] Provide mechanism for editing builtin command-line in zImage binary mostrows
2006-05-30  2:27 ` Michal Ostrowski
2006-05-30 20:41 ` Mark A. Greer
2006-05-30 21:12   ` Michal Ostrowski
2006-05-31 20:04     ` Mark A. Greer
2006-05-31 20:26       ` Michal Ostrowski
2006-05-31 20:35         ` Matthew McClintock
2006-05-31 21:04           ` Michal Ostrowski
2006-06-09  9:47 ` Paul Mackerras
2006-06-09 13:06   ` mostrows [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11498583723378-git-send-email-mostrows@watson.ibm.com \
    --to=mostrows@watson.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.