On Fri, Oct 31, 2014 at 1:58 PM, Kees Cook <[email protected]> wrote:
> This is useful for reporting various addresses or other values while
> debugging early boot. For example, when CONFIG_X86_VERBOSE_BOOTUP is set,
> this is now visible at boot time:
>
>         early console in setup code
>         early console in decompress_kernel
>         input_data: 0x0000000001e1526e
>         input_len: 0x0000000000732236
>         output: 0x0000000001000000
>         output_len: 0x0000000001535640
>         run_size: 0x00000000021fb000
>         KASLR using RDTSC...
>
> Signed-off-by: Kees Cook <[email protected]>
> ---
> Since this displays run_size, this patch depends on Junjie Mao's patch
> "x86, kaslr: Prevent .bss from overlaping initrd"
>
> ---
>  arch/x86/boot/compressed/misc.c | 24 ++++++++++++++++++++++++
>  arch/x86/boot/compressed/misc.h | 11 +++++++++++
>  2 files changed, 35 insertions(+)
...

We can reuse printf.c in arch/x86/boot.

I had attached one in local tree for a while. or even sent it before
several years ago.

Thanks

Yinghai


Subject: [PATCH] x86, boot: Add printf support for early console in
compressed/misc.c

Reuse printf.c in x86 setup code.
And print out decompress_kernel input and output info.

Later decompresser code could print out more info for debug info.

Signed-off-by: Yinghai Lu <[email protected]>

---
 arch/x86/boot/compressed/Makefile |    2 +-
 arch/x86/boot/compressed/misc.c   |    8 ++++++++
 arch/x86/boot/compressed/misc.h   |    7 +++++++
 arch/x86/boot/compressed/printf.c |    5 +++++
 4 files changed, 21 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/boot/compressed/Makefile
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/Makefile
+++ linux-2.6/arch/x86/boot/compressed/Makefile
@@ -28,7 +28,7 @@ HOST_EXTRACFLAGS += -I$(srctree)/tools/i

 vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
     $(obj)/string.o $(obj)/cmdline.o \
-    $(obj)/piggy.o $(obj)/cpuflags.o
+    $(obj)/printf.o $(obj)/piggy.o $(obj)/cpuflags.o

 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o
Index: linux-2.6/arch/x86/boot/compressed/printf.c
===================================================================
--- /dev/null
+++ linux-2.6/arch/x86/boot/compressed/printf.c
@@ -0,0 +1,5 @@
+#include "misc.h"
+
+#define puts(__x)  __putstr(__x)
+
+#include "../printf.c"
Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -390,6 +390,14 @@ asmlinkage __visible void *decompress_ke
     output = choose_kernel_location(input_data, input_len,
                     output, output_len);

+    debug_putstr("decompress_kernel:\n");
+    debug_printf("  input: [0x%lx-0x%lx], output: 0x%lx, heap:
[0x%lx-0x%lx]\n",
+         (unsigned long)input_data,
+         (unsigned long)input_data + input_len - 1,
+         (unsigned long)output,
+         (unsigned long)heap,
+         (unsigned long)heap + BOOT_HEAP_SIZE - 1);
+
     /* Validate memory location choices. */
     if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))
         error("Destination address inappropriately aligned");
Index: linux-2.6/arch/x86/boot/compressed/misc.h
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.h
+++ linux-2.6/arch/x86/boot/compressed/misc.h
@@ -36,14 +36,21 @@ extern struct boot_params *real_mode;        /
 void __putstr(const char *s);
 #define error_putstr(__x)  __putstr(__x)

+/* printf.c */
+int sprintf(char *buf, const char *fmt, ...);
+int printf(const char *fmt, ...);
+
 #ifdef CONFIG_X86_VERBOSE_BOOTUP

 #define debug_putstr(__x)  __putstr(__x)
+#define debug_printf printf

 #else

 static inline void debug_putstr(const char *s)
 { }
+static inline int debug_printf(const char *fmt, ...)
+{ }

 #endif
Subject: [PATCH] x86, boot: Add printf support for early console in compressed/misc.c

Reuse printf.c in x86 setup code.
And print out decompress_kernel input and output info.

Later decompresser code could print out more info for debug info.

Signed-off-by: Yinghai Lu <[email protected]>

---
 arch/x86/boot/compressed/Makefile |    2 +-
 arch/x86/boot/compressed/misc.c   |    8 ++++++++
 arch/x86/boot/compressed/misc.h   |    7 +++++++
 arch/x86/boot/compressed/printf.c |    5 +++++
 4 files changed, 21 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/boot/compressed/Makefile
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/Makefile
+++ linux-2.6/arch/x86/boot/compressed/Makefile
@@ -28,7 +28,7 @@ HOST_EXTRACFLAGS += -I$(srctree)/tools/i
 
 vmlinux-objs-y := $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
 	$(obj)/string.o $(obj)/cmdline.o \
-	$(obj)/piggy.o $(obj)/cpuflags.o
+	$(obj)/printf.o $(obj)/piggy.o $(obj)/cpuflags.o
 
 vmlinux-objs-$(CONFIG_EARLY_PRINTK) += $(obj)/early_serial_console.o
 vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/aslr.o
Index: linux-2.6/arch/x86/boot/compressed/printf.c
===================================================================
--- /dev/null
+++ linux-2.6/arch/x86/boot/compressed/printf.c
@@ -0,0 +1,5 @@
+#include "misc.h"
+
+#define puts(__x)  __putstr(__x)
+
+#include "../printf.c"
Index: linux-2.6/arch/x86/boot/compressed/misc.c
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.c
+++ linux-2.6/arch/x86/boot/compressed/misc.c
@@ -390,6 +390,14 @@ asmlinkage __visible void *decompress_ke
 	output = choose_kernel_location(input_data, input_len,
 					output, output_len);
 
+	debug_putstr("decompress_kernel:\n");
+	debug_printf("  input: [0x%lx-0x%lx], output: 0x%lx, heap: [0x%lx-0x%lx]\n",
+		 (unsigned long)input_data,
+		 (unsigned long)input_data + input_len - 1,
+		 (unsigned long)output,
+		 (unsigned long)heap,
+		 (unsigned long)heap + BOOT_HEAP_SIZE - 1);
+
 	/* Validate memory location choices. */
 	if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))
 		error("Destination address inappropriately aligned");
Index: linux-2.6/arch/x86/boot/compressed/misc.h
===================================================================
--- linux-2.6.orig/arch/x86/boot/compressed/misc.h
+++ linux-2.6/arch/x86/boot/compressed/misc.h
@@ -36,14 +36,21 @@ extern struct boot_params *real_mode;		/
 void __putstr(const char *s);
 #define error_putstr(__x)  __putstr(__x)
 
+/* printf.c */
+int sprintf(char *buf, const char *fmt, ...);
+int printf(const char *fmt, ...);
+
 #ifdef CONFIG_X86_VERBOSE_BOOTUP
 
 #define debug_putstr(__x)  __putstr(__x)
+#define debug_printf printf
 
 #else
 
 static inline void debug_putstr(const char *s)
 { }
+static inline int debug_printf(const char *fmt, ...)
+{ }
 
 #endif
 

Reply via email to