Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] Probe initrd header only if explicitly specified
@ 2008-08-26 13:11 Atsushi Nemoto
  2008-08-26 13:27 ` Geert Uytterhoeven
  0 siblings, 1 reply; 5+ messages in thread
From: Atsushi Nemoto @ 2008-08-26 13:11 UTC (permalink / raw)
  To: linux-mips; +Cc: ralf

Currently init_initrd() probes initrd header at the last page of
kernel image, but it is valid only if addinitrd was used.  If
addinitrd was not used, the area contains garbage so probing there
might misdetect initrd header (magic number is not strictly robust).

This patch introduces CONFIG_PROBE_INITRD_HEADER to enable this
probing explicitly.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
 arch/mips/Kconfig        |    9 +++++++++
 arch/mips/kernel/setup.c |   35 +++++++++++++++++++----------------
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 4da736e..49896a2 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1886,6 +1886,15 @@ config STACKTRACE_SUPPORT
 
 source "init/Kconfig"
 
+config PROBE_INITRD_HEADER
+	bool "Probe initrd header created by addinitrd"
+	depends on BLK_DEV_INITRD
+	help
+	  Probe initrd header at the last page of kernel image.
+	  Say Y here if you are using arch/mips/boot/addinitrd.c to
+	  add initrd or initramfs image to the kernel image.
+	  Otherwise, say N.
+
 menu "Bus options (PCI, PCMCIA, EISA, ISA, TC)"
 
 config HW_HAS_EISA
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 2aae76b..da5af63 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -160,30 +160,33 @@ early_param("rd_size", rd_size_early);
 static unsigned long __init init_initrd(void)
 {
 	unsigned long end;
-	u32 *initrd_header;
 
 	/*
 	 * Board specific code or command line parser should have
 	 * already set up initrd_start and initrd_end. In these cases
 	 * perfom sanity checks and use them if all looks good.
 	 */
-	if (initrd_start && initrd_end > initrd_start)
-		goto sanitize;
+	if (!initrd_start || initrd_end <= initrd_start) {
+#ifdef CONFIG_PROBE_INITRD_HEADER
+		u32 *initrd_header;
 
-	/*
-	 * See if initrd has been added to the kernel image by
-	 * arch/mips/boot/addinitrd.c. In that case a header is
-	 * prepended to initrd and is made up by 8 bytes. The fisrt
-	 * word is a magic number and the second one is the size of
-	 * initrd.  Initrd start must be page aligned in any cases.
-	 */
-	initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8;
-	if (initrd_header[0] != 0x494E5244)
+		/*
+		 * See if initrd has been added to the kernel image by
+		 * arch/mips/boot/addinitrd.c. In that case a header is
+		 * prepended to initrd and is made up by 8 bytes. The fisrt
+		 * word is a magic number and the second one is the size of
+		 * initrd.  Initrd start must be page aligned in any cases.
+		 */
+		initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8;
+		if (initrd_header[0] != 0x494E5244)
+			goto disable;
+		initrd_start = (unsigned long)(initrd_header + 2);
+		initrd_end = initrd_start + initrd_header[1];
+#else
 		goto disable;
-	initrd_start = (unsigned long)(initrd_header + 2);
-	initrd_end = initrd_start + initrd_header[1];
+#endif
+	}
 
-sanitize:
 	if (initrd_start & ~PAGE_MASK) {
 		pr_err("initrd start must be page aligned\n");
 		goto disable;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Probe initrd header only if explicitly specified
  2008-08-26 13:11 Atsushi Nemoto
@ 2008-08-26 13:27 ` Geert Uytterhoeven
  2008-08-26 13:31   ` Atsushi Nemoto
  0 siblings, 1 reply; 5+ messages in thread
From: Geert Uytterhoeven @ 2008-08-26 13:27 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: linux-mips, ralf

On Tue, 26 Aug 2008, Atsushi Nemoto wrote:
> +		 * prepended to initrd and is made up by 8 bytes. The fisrt
                                                                      ^^^^^
								      first
(I know this typo existed before)

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Probe initrd header only if explicitly specified
  2008-08-26 13:27 ` Geert Uytterhoeven
@ 2008-08-26 13:31   ` Atsushi Nemoto
  0 siblings, 0 replies; 5+ messages in thread
From: Atsushi Nemoto @ 2008-08-26 13:31 UTC (permalink / raw)
  To: geert; +Cc: linux-mips, ralf

On Tue, 26 Aug 2008 15:27:31 +0200 (CEST), Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > +		 * prepended to initrd and is made up by 8 bytes. The fisrt
>                                                                       ^^^^^
> 								      first
> (I know this typo existed before)

Thanks, I'll update soon.
---
Atsushi Nemoto

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Probe initrd header only if explicitly specified
@ 2008-08-26 13:34 Atsushi Nemoto
  2008-08-26 21:29 ` Ralf Baechle
  0 siblings, 1 reply; 5+ messages in thread
From: Atsushi Nemoto @ 2008-08-26 13:34 UTC (permalink / raw)
  To: linux-mips; +Cc: ralf

Currently init_initrd() probes initrd header at the last page of
kernel image, but it is valid only if addinitrd was used.  If
addinitrd was not used, the area contains garbage so probing there
might misdetect initrd header (magic number is not strictly robust).

This patch introduces CONFIG_PROBE_INITRD_HEADER to enable this
probing explicitly.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
revised with spell-check.

 arch/mips/Kconfig        |    9 +++++++++
 arch/mips/kernel/setup.c |   35 +++++++++++++++++++----------------
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 4da736e..49896a2 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1886,6 +1886,15 @@ config STACKTRACE_SUPPORT
 
 source "init/Kconfig"
 
+config PROBE_INITRD_HEADER
+	bool "Probe initrd header created by addinitrd"
+	depends on BLK_DEV_INITRD
+	help
+	  Probe initrd header at the last page of kernel image.
+	  Say Y here if you are using arch/mips/boot/addinitrd.c to
+	  add initrd or initramfs image to the kernel image.
+	  Otherwise, say N.
+
 menu "Bus options (PCI, PCMCIA, EISA, ISA, TC)"
 
 config HW_HAS_EISA
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 2aae76b..16f8edf 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -160,30 +160,33 @@ early_param("rd_size", rd_size_early);
 static unsigned long __init init_initrd(void)
 {
 	unsigned long end;
-	u32 *initrd_header;
 
 	/*
 	 * Board specific code or command line parser should have
 	 * already set up initrd_start and initrd_end. In these cases
 	 * perfom sanity checks and use them if all looks good.
 	 */
-	if (initrd_start && initrd_end > initrd_start)
-		goto sanitize;
+	if (!initrd_start || initrd_end <= initrd_start) {
+#ifdef CONFIG_PROBE_INITRD_HEADER
+		u32 *initrd_header;
 
-	/*
-	 * See if initrd has been added to the kernel image by
-	 * arch/mips/boot/addinitrd.c. In that case a header is
-	 * prepended to initrd and is made up by 8 bytes. The fisrt
-	 * word is a magic number and the second one is the size of
-	 * initrd.  Initrd start must be page aligned in any cases.
-	 */
-	initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8;
-	if (initrd_header[0] != 0x494E5244)
+		/*
+		 * See if initrd has been added to the kernel image by
+		 * arch/mips/boot/addinitrd.c. In that case a header is
+		 * prepended to initrd and is made up by 8 bytes. The first
+		 * word is a magic number and the second one is the size of
+		 * initrd.  Initrd start must be page aligned in any cases.
+		 */
+		initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8;
+		if (initrd_header[0] != 0x494E5244)
+			goto disable;
+		initrd_start = (unsigned long)(initrd_header + 2);
+		initrd_end = initrd_start + initrd_header[1];
+#else
 		goto disable;
-	initrd_start = (unsigned long)(initrd_header + 2);
-	initrd_end = initrd_start + initrd_header[1];
+#endif
+	}
 
-sanitize:
 	if (initrd_start & ~PAGE_MASK) {
 		pr_err("initrd start must be page aligned\n");
 		goto disable;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Probe initrd header only if explicitly specified
  2008-08-26 13:34 [PATCH] Probe initrd header only if explicitly specified Atsushi Nemoto
@ 2008-08-26 21:29 ` Ralf Baechle
  0 siblings, 0 replies; 5+ messages in thread
From: Ralf Baechle @ 2008-08-26 21:29 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: linux-mips

On Tue, Aug 26, 2008 at 10:34:57PM +0900, Atsushi Nemoto wrote:

> Currently init_initrd() probes initrd header at the last page of
> kernel image, but it is valid only if addinitrd was used.  If
> addinitrd was not used, the area contains garbage so probing there
> might misdetect initrd header (magic number is not strictly robust).
> 
> This patch introduces CONFIG_PROBE_INITRD_HEADER to enable this
> probing explicitly.

Applied though I think the solution isn't quite the most elegant ...

  Ralf

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-08-26 21:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-26 13:34 [PATCH] Probe initrd header only if explicitly specified Atsushi Nemoto
2008-08-26 21:29 ` Ralf Baechle
  -- strict thread matches above, loose matches on Subject: below --
2008-08-26 13:11 Atsushi Nemoto
2008-08-26 13:27 ` Geert Uytterhoeven
2008-08-26 13:31   ` Atsushi Nemoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox