From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933720AbbGGU1X (ORCPT ); Tue, 7 Jul 2015 16:27:23 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:16640 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758020AbbGGUUz (ORCPT ); Tue, 7 Jul 2015 16:20:55 -0400 From: Yinghai Lu To: Kees Cook , "H. Peter Anvin" , Baoquan He Cc: linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH 20/42] x86, boot: Add printf support for early console in compressed/misc.c Date: Tue, 7 Jul 2015 13:20:06 -0700 Message-Id: <1436300428-21163-21-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1436300428-21163-1-git-send-email-yinghai@kernel.org> References: <1436300428-21163-1-git-send-email-yinghai@kernel.org> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/boot/compressed/Makefile | 2 +- arch/x86/boot/compressed/misc.c | 38 ++++++++++++++++++++++++++++++++++++++ arch/x86/boot/compressed/misc.h | 7 +++++++ arch/x86/boot/compressed/printf.c | 5 +++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 arch/x86/boot/compressed/printf.c diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 66461b4..8fc7dd9 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -54,7 +54,7 @@ $(obj)/misc.o: $(obj)/../voffset.h 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 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 6b2a308..ee73b7b 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -387,6 +387,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap, unsigned char *output_orig = output; unsigned long output_run_size; unsigned char *virt_offset; + unsigned long init_size; real_mode = rmode; @@ -414,6 +415,37 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap, output_run_size = output_len > run_size ? output_len : run_size; + init_size = real_mode->hdr.init_size; + debug_putstr("decompress_kernel:\n"); + debug_printf(" input: [0x%010lx-0x%010lx]\n", + (unsigned long)input_data, + (unsigned long)input_data + input_len - 1); + debug_printf(" output: [0x%010lx-0x%010lx] 0x%08lx: output_len\n", + (unsigned long)output, + (unsigned long)output + output_len - 1, + (unsigned long)output_len); + debug_printf(" [0x%010lx-0x%010lx] 0x%08lx: run_size\n", + (unsigned long)output, + (unsigned long)output + run_size - 1, + (unsigned long)run_size); + debug_printf(" [0x%010lx-0x%010lx] 0x%08lx: output_run_size\n", + (unsigned long)output, + (unsigned long)output + output_run_size - 1, + (unsigned long)output_run_size); + debug_printf(" [0x%010lx-0x%010lx] 0x%08lx: init_size\n", + (unsigned long)output, + (unsigned long)output + init_size - 1, + (unsigned long)init_size); + debug_printf("ZO text/data: [0x%010lx-0x%010lx]\n", + (unsigned long)input_data + input_len, + (unsigned long)output + init_size - 1); + debug_printf(" ZO heap: [0x%010lx-0x%010lx]\n", + (unsigned long)heap, + (unsigned long)heap + BOOT_HEAP_SIZE - 1); + debug_printf(" VO bss/brk: [0x%010lx-0x%010lx]\n", + (unsigned long)output + (VO___bss_start - VO__text), + (unsigned long)output + run_size - 1); + /* * The memory hole needed for the kernel is the larger of either * the entire decompressed kernel plus relocation table, or the @@ -422,6 +454,12 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap, choose_kernel_location(input_data, input_len, &output, output_run_size, &virt_offset); + if (output != output_orig) + debug_printf(" new output: [0x%010lx-0x%010lx] 0x%08lx: output_run_size\n", + (unsigned long)output, + (unsigned long)output + output_run_size - 1, + (unsigned long)output_run_size); + /* Validate memory location choices. */ if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1)) error("Destination address inappropriately aligned"); diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index b44a7c0..410e5d3 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -38,14 +38,21 @@ void __putstr(const char *s); void error(char *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 diff --git a/arch/x86/boot/compressed/printf.c b/arch/x86/boot/compressed/printf.c new file mode 100644 index 0000000..a3a080d --- /dev/null +++ b/arch/x86/boot/compressed/printf.c @@ -0,0 +1,5 @@ +#include "misc.h" + +#define puts(__x) __putstr(__x) + +#include "../printf.c" -- 1.8.4.5