Skip to contentSkip to conversation

Use structs instead of hardcoded offsets in x86 boot decompressor.

PATCH Superseded Kristian Høgsberg 2 participants 8 messages May 29, 2008 x86

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 Use structs instead of hardcoded offsets in x86 boot decompressor.

Just a minor cleanup, making it easier to access the command line in the following "Honor quiet in decompressor" patch.

---

Updated this one to be less intrusive; we just re-#define RM_SCREEN_INFO to access the boot_params struct instead of using the hard-coded offset.

 arch/x86/boot/compressed/misc.c |   10 +++-------
 1 files changed, 3 insertions(+), 7 deletions(-)
arch/x86/boot/compressed/misc.c +3 -7
index 90456ce..102b68e 100644
@@ -30,6 +30,7 @@
 #include <asm/io.h>
 #include <asm/page.h>
 #include <asm/boot.h>
+#include <asm/bootparam.h>
 
 /* WARNING!!
  * This code is compiled with -fPIC and it is relocated dynamically
@@ -187,13 +188,8 @@ static void gzip_release(void **);
 /*
  * This is set up by the setup-routine at boot-time
  */
-static unsigned char *real_mode; /* Pointer to real-mode data */
-
-#define RM_EXT_MEM_K   (*(unsigned short *)(real_mode + 0x2))
-#ifndef STANDARD_MEMORY_BIOS_CALL
-#define RM_ALT_MEM_K   (*(unsigned long *)(real_mode + 0x1e0))
-#endif
-#define RM_SCREEN_INFO (*(struct screen_info *)(real_mode+0))
+static struct boot_params *real_mode;		/* Pointer to real-mode data */
+#define RM_SCREEN_INFO (real_mode->screen_info)
 
 extern unsigned char input_data[];
 extern int input_len;
Signature · 1 line
1.5.4.5
#1 lore raw

PATCH 2/2 Honor 'quiet' command line option in real mode boot decompressor.

This patch lets the early real mode decompressor parse the kernel command line and look for the 'quiet' option. When 'quiet' is passed we suppress the "Decompressing Linux... Parsing ELF... done." messages.

This is in line with how the rest of the kernel suppresses informational debug spew when quiet is given.

---

Ok, I flipped the default on this patch since turning off those important messages by default is apparently quite controversial. With this patch we still print the decompression status messages, but if quiet is seen on the kernel command we suppress them.

 arch/x86/boot/compressed/misc.c |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)
arch/x86/boot/compressed/misc.c +28 -3
index 102b68e..b548379 100644
@@ -190,6 +190,7 @@ static void gzip_release(void **);
  */
 static struct boot_params *real_mode;		/* Pointer to real-mode data */
 #define RM_SCREEN_INFO (real_mode->screen_info)
+static int quiet;
 
 extern unsigned char input_data[];
 extern int input_len;
@@ -391,7 +392,8 @@ static void parse_elf(void *output)
 		return;
 	}
 
-	putstr("Parsing ELF... ");
+	if (!quiet)
+		putstr("Parsing ELF... ");
 
 	phdrs = malloc(sizeof(*phdrs) * ehdr.e_phnum);
 	if (!phdrs)
@@ -419,11 +421,28 @@ static void parse_elf(void *output)
 	}
 }
 
+static const char *strnstr(const char *string, int len, const char *s)
+{
+	int i, j;
+
+	for (i = 0; i < len; i++) {
+		for (j = 0; i + j < len && s[j]; j++)
+			if (string[i + j] != s[j])
+				break;
+		if (s[j] == '\0')
+			return string + i;
+	}
+
+	return NULL;
+}
+
 asmlinkage void decompress_kernel(void *rmode, memptr heap,
 				  unsigned char *input_data,
 				  unsigned long input_len,
 				  unsigned char *output)
 {
+	const char * cmdline;  
+
 	real_mode = rmode;
 
 	if (RM_SCREEN_INFO.orig_video_mode == 7) {
@@ -437,6 +456,10 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
 	lines = RM_SCREEN_INFO.orig_video_lines;
 	cols = RM_SCREEN_INFO.orig_video_cols;
 
+	cmdline = (char *) real_mode->hdr.cmd_line_ptr;
+	if (strnstr(cmdline, real_mode->hdr.cmdline_size, "quiet"))
+		quiet = 1;
+
 	window = output;		/* Output buffer (Normally at 1M) */
 	free_mem_ptr     = heap;	/* Heap */
 	free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
@@ -461,9 +484,11 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
 #endif
 
 	makecrc();
-	putstr("\nDecompressing Linux... ");
+	if (!quiet)
+		putstr("\nDecompressing Linux... ");
 	gunzip();
 	parse_elf(output);
-	putstr("done.\nBooting the kernel.\n");
+	if (!quiet)
+		putstr("done.\nBooting the kernel.\n");
 	return;
 }
Signature · 1 line
1.5.4.5
#2 lore raw

Re: [PATCH 2/2] Honor 'quiet' command line option in real mode boot decompressor.

Quoted 8 lines · Kristian Høgsberg

This patch lets the early real mode decompressor parse the kernel command line and look for the 'quiet' option. When 'quiet' is passed we suppress the "Decompressing Linux... Parsing ELF... done." messages.

This is in line with how the rest of the kernel suppresses informational debug spew when quiet is given.

You know... we already have a command-line parser in the real-mode part of the boot code, and it already extracts the "quiet" option: we should be able to do this by passing a bit in "loadflags" (bit 5 suggested.) This would have the additional benefit of making it really easy for hypervisors that don't support writing to the screen at all to disable those messages.

What do you think?

-hpa

#3 lore raw

Re: [PATCH 2/2] Honor 'quiet' command line option in real mode boot decompressor.

Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · Kristian Høgsberg

This patch lets the early real mode decompressor parse the kernel command line and look for the 'quiet' option. When 'quiet' is passed we suppress the "Decompressing Linux... Parsing ELF... done." messages.

Quoted 8 lines
Quoted 4 lines

This is in line with how the rest of the kernel suppresses informational debug spew when quiet is given.

You know... we already have a command-line parser in the real-mode part of the boot code, and it already extracts the "quiet" option: we should be able to do this by passing a bit in "loadflags" (bit 5 suggested.)

Hmm, as far as I understand the boot code, the decompressor consists of just head_32/64.S and misc.c plus the #included inflate.c and the compressed image in piggy.o. In this environment there is no command line parser, it's only available once the image has been decompressed.

Or are you suggesting parsing the "quiet" option in the bootloader and then setting the loadflags bit from there? That's certainly doable, and I can update grub accordingly, but just parsing the command line seems like a simple, more local fix. I don't have a strong preference, though.

cheers,
Kristian

#4 lore raw

Re: [PATCH 2/2] Honor 'quiet' command line option in real mode boot decompressor.

Quoted 7 lines · Kristian Høgsberg
Quoted 1 line

You know... we already have a command-line parser in the real-mode part of the boot code, and it already extracts the "quiet" option: we should be able to do this by passing a bit in "loadflags" (bit 5 suggested.)

Hmm, as far as I understand the boot code, the decompressor consists of just head_32/64.S and misc.c plus the #included inflate.c and the compressed image in piggy.o. In this environment there is no command line parser, it's only available once the image has been decompressed.

Quoted 5 lines

Or are you suggesting parsing the "quiet" option in the bootloader and then setting the loadflags bit from there? That's certainly doable, and I can update grub accordingly, but just parsing the command line seems like a simple, more local fix. I don't have a strong preference, though.

I think you're missing something: the decompressor is the *second stage* of the boot code; the first stage is the real-mode code (arch/x86/boot).
I'm suggesting passing the flag from the real-mode code to the
decompressor, not from the boot loader (in the common case.)

-hpa

#5 lore raw

Re: [PATCH 2/2] Honor 'quiet' command line option in real mode boot decompressor.

Quoted 16 lines · H. Peter Anvin
Quoted 9 lines · Kristian Høgsberg
Quoted 3 lines

You know... we already have a command-line parser in the real-mode part of the boot code, and it already extracts the "quiet" option: we should be able to do this by passing a bit in "loadflags" (bit 5 suggested.)

Hmm, as far as I understand the boot code, the decompressor consists of just head_32/64.S and misc.c plus the #included inflate.c and the compressed image in piggy.o. In this environment there is no command line parser, it's only available once the image has been decompressed.

Quoted 5 lines

Or are you suggesting parsing the "quiet" option in the bootloader and then setting the loadflags bit from there? That's certainly doable, and I can update grub accordingly, but just parsing the command line seems like a simple, more local fix. I don't have a strong preference, though.

Quoted 4 lines

I think you're missing something: the decompressor is the *second stage* of the boot code; the first stage is the real-mode code (arch/x86/boot).
I'm suggesting passing the flag from the real-mode code to the
decompressor, not from the boot loader (in the common case.)

Indeed, I had it the wrong way around. I like the bootflag approach, updated patches coming up.

thanks,
Kristian

#6 lore raw
In reply to Kristian Høgsberg
Quoted 4 lines · Kristian Høgsberg

Updated this one to be less intrusive; we just re-#define RM_SCREEN_INFO to access the boot_params struct instead of using the hard-coded offset.

Any reason to leave it in as a macro at all, instead of just s/RM_SCREEN_INFO/real_mode->screen_info/g?

We have already gotten rid of most of these macros in the primary kernel.

-hpa

P.S. Sorry for not giving you feedback sooner.

#7 lore raw
Quoted 8 lines · H. Peter Anvin
Quoted 4 lines · Kristian Høgsberg

Updated this one to be less intrusive; we just re-#define RM_SCREEN_INFO to access the boot_params struct instead of using the hard-coded offset.

Any reason to leave it in as a macro at all, instead of just s/RM_SCREEN_INFO/real_mode->screen_info/g?

Only to keep the patch smaller. Accessing the struct directly is definitely nicer, I'll do the sed job when I resubmit with the other patch.

cheers,
Kristian