From: jbeulich@suse.com
Subject: allow non-pv-ops kernel to be built as bzImage
Patch-mainline: n/a
References: FATE#313527 FATE#314491

This, by enabling the EFI_STUB config option, is a prerequisite for
secure boot.

The XEN_ADVANCED_COMPRESSION part could be merged into the 2.6.30
patch (but is probably better kept here).

--- sle11sp3.orig/arch/x86/Kconfig	2013-04-23 15:45:06.000000000 +0200
+++ sle11sp3/arch/x86/Kconfig	2013-04-23 17:18:39.000000000 +0200
@@ -1565,7 +1565,7 @@ config EFI
 
 config EFI_STUB
        bool "EFI stub support"
-       depends on EFI && !XEN
+       depends on EFI && (!XEN || XEN_BZIMAGE)
        ---help---
           This kernel feature allows a bzImage to be loaded directly
 	  by EFI firmware without the use of a bootloader.
@@ -1747,6 +1747,30 @@ config PHYSICAL_ALIGN
 
 	  Don't change this unless you know what you are doing.
 
+config XEN_BZIMAGE
+	bool "Produce bzImage (rather than ELF) format executable"
+#	depends on XEN && (XEN_COMPAT >= (XEN_UNPRIVILEGED_GUEST ? 0x030402 : 0x040000))
+	depends on XEN
+	depends on !XEN_COMPAT_030002_AND_LATER
+	depends on !XEN_COMPAT_030004_AND_LATER
+	depends on !XEN_COMPAT_030100_AND_LATER
+	depends on !XEN_COMPAT_030200_AND_LATER
+	depends on !XEN_COMPAT_030300_AND_LATER
+	depends on !XEN_COMPAT_030400_AND_LATER
+#	depends on XEN_UNPRIVILEGED_GUEST || !XEN_COMPAT_030402_AND_LATER
+	select HAVE_KERNEL_BZIP2 if XEN_ADVANCED_COMPRESSION
+	select HAVE_KERNEL_LZMA if XEN_ADVANCED_COMPRESSION
+#	select HAVE_KERNEL_XZ if XEN_ADVANCED_COMPRESSION && (XEN_COMPAT > 0x040100)
+	select HAVE_KERNEL_XZ if XEN_ADVANCED_COMPRESSION && !XEN_COMPAT_040000_AND_LATER && !XEN_COMPAT_040100_AND_LATER
+	select HAVE_KERNEL_LZO if XEN_ADVANCED_COMPRESSION && !XEN_COMPAT_040000_AND_LATER
+	---help---
+	  Select whether, at the price of being incompatible with pre-3.4
+	  (pre-4.0 for Dom0) hypervisor versions, you want the final image
+	  to be in bzImage format, including the option to compress its
+	  embedded ELF image with methods better than gzip.
+	  Note that this is a prerequiste for building a kernel that can be
+	  used for secure boot from UEFI.
+
 config HOTPLUG_CPU
 	bool "Support for hot-pluggable CPUs"
 	depends on SMP && HOTPLUG
--- sle11sp3.orig/arch/x86/Makefile	2013-03-07 16:26:05.000000000 +0100
+++ sle11sp3/arch/x86/Makefile	2013-03-07 16:27:30.000000000 +0100
@@ -178,7 +178,9 @@ $(objtree)/arch/x86/include/generated/as
 	$(srctree)/include/xen/interface/arch-x86/xen*.h
 
 archprepare: $(objtree)/arch/x86/include/generated/asm/xen-hypercalls.h
+endif
 
+ifeq ($(CONFIG_XEN)-$(CONFIG_XEN_BZIMAGE),y-)
 # Default kernel to build
 all: vmlinuz
 
--- sle11sp3.orig/arch/x86/boot/Makefile	2012-12-04 13:40:37.000000000 +0100
+++ sle11sp3/arch/x86/boot/Makefile	2013-01-09 08:45:31.000000000 +0100
@@ -35,6 +35,8 @@ setup-y		+= video-vga.o
 setup-y		+= video-vesa.o
 setup-y		+= video-bios.o
 
+setup-$(CONFIG_XEN) := header.o version.o
+
 targets		+= $(setup-y)
 hostprogs-y	:= mkcpustr tools/build
 
@@ -198,7 +200,7 @@ $(obj)/vmlinux-stripped: OBJCOPYFLAGS :=
 $(obj)/vmlinux-stripped: vmlinux FORCE
 	$(call if_changed,objcopy)
 
-ifndef CONFIG_XEN
+ifneq ($(CONFIG_XEN)-$(CONFIG_XEN_BZIMAGE),y-)
 bzImage := bzImage
 else
 bzImage := vmlinuz
--- sle11sp3.orig/arch/x86/boot/boot.h	2015-01-16 14:55:00.000000000 +0100
+++ sle11sp3/arch/x86/boot/boot.h	2013-01-09 08:45:31.000000000 +0100
@@ -23,8 +23,12 @@
 #include <stdarg.h>
 #include <linux/types.h>
 #include <linux/edd.h>
+#ifndef CONFIG_XEN
 #include <asm/boot.h>
 #include <asm/setup.h>
+#else
+#include <asm/bootparam.h>
+#endif
 #include "bitops.h"
 #include <asm/cpufeature.h>
 #include <asm/processor-flags.h>
--- sle11sp3.orig/arch/x86/boot/compressed/Makefile	2015-01-16 14:55:00.000000000 +0100
+++ sle11sp3/arch/x86/boot/compressed/Makefile	2013-01-09 08:45:31.000000000 +0100
@@ -19,6 +19,9 @@ KBUILD_AFLAGS  := $(KBUILD_CFLAGS) -D__A
 GCOV_PROFILE := n
 
 LDFLAGS := -m elf_$(UTS_MACHINE)
+ifeq ($(CONFIG_XEN),y)
+LDFLAGS += -e 0
+endif
 LDFLAGS_vmlinux := -T
 
 hostprogs-y	:= mkpiggy
@@ -34,6 +37,9 @@ $(obj)/efi_stub_$(BITS).o: KBUILD_CLFAGS
 ifeq ($(CONFIG_EFI_STUB), y)
 	VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o
 endif
+ifeq ($(CONFIG_XEN), y)
+	VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/piggy.o
+endif
 
 $(obj)/vmlinux: $(VMLINUX_OBJS) FORCE
 	$(call if_changed,ld)
--- sle11sp3.orig/arch/x86/boot/header.S	2015-01-16 14:55:00.000000000 +0100
+++ sle11sp3/arch/x86/boot/header.S	2013-01-09 08:45:31.000000000 +0100
@@ -393,6 +393,9 @@ setup_data:		.quad 0			# 64-bit physical
 
 pref_address:		.quad LOAD_PHYSICAL_ADDR	# preferred load addr
 
+#ifdef CONFIG_XEN
+#define ZO_startup_32 0
+#endif
 #define ZO_INIT_SIZE	(ZO__end - ZO_startup_32 + ZO_z_extract_offset)
 #define VO_INIT_SIZE	(VO__end - VO__text)
 #if ZO_INIT_SIZE > VO_INIT_SIZE
@@ -408,6 +411,7 @@ handover_offset:	.long 0x30		# offset to
 
 	.section ".entrytext", "ax"
 start_of_setup:
+#ifndef CONFIG_XEN
 #ifdef SAFE_RESET_DISK_CONTROLLER
 # Reset the disk controller.
 	movw	$0x0000, %ax		# Reset disk controller
@@ -490,3 +494,4 @@ setup_corrupt:
 
 	.data
 dummy:	.long	0
+#endif /* CONFIG_XEN */
--- sle11sp3.orig/arch/x86/boot/tools/build.c	2015-01-16 14:55:00.000000000 +0100
+++ sle11sp3/arch/x86/boot/tools/build.c	2013-01-09 08:45:31.000000000 +0100
@@ -44,8 +44,10 @@ typedef unsigned long  u32;
 #define DEFAULT_MINOR_ROOT 0
 #define DEFAULT_ROOT_DEV (DEFAULT_MAJOR_ROOT << 8 | DEFAULT_MINOR_ROOT)
 
+#ifndef CONFIG_XEN
 /* Minimal number of setup sectors */
 #define SETUP_SECT_MIN 5
+#endif
 #define SETUP_SECT_MAX 64
 
 /* This must be large enough to hold the entire setup */
@@ -253,8 +255,8 @@ int main(int argc, char ** argv)
 	c = fread(buf, 1, sizeof(buf), file);
 	if (ferror(file))
 		die("read-error on `setup'");
-	if (c < 1024)
-		die("The setup must be at least 1024 bytes");
+	if (c <= 512)
+		die("The setup must be more than 512 bytes");
 	if (get_unaligned_le16(&buf[510]) != 0xAA55)
 		die("Boot block hasn't got boot flag (0xAA55)");
 	fclose(file);
@@ -267,8 +269,10 @@ int main(int argc, char ** argv)
 
 	/* Pad unused space with zeros */
 	setup_sectors = (c + 511) / 512;
+#ifdef SETUP_SECT_MIN
 	if (setup_sectors < SETUP_SECT_MIN)
 		setup_sectors = SETUP_SECT_MIN;
+#endif
 	i = setup_sectors*512;
 	memset(buf+c, 0, i-c);
 
--- sle11sp3.orig/drivers/xen/Kconfig	2012-10-19 16:10:24.000000000 +0200
+++ sle11sp3/drivers/xen/Kconfig	2013-01-09 08:45:31.000000000 +0100
@@ -402,6 +402,17 @@ config XEN_VCPU_INFO_PLACEMENT
 	  This allows faster access to the per-vCPU shared info
 	  structure.
 
+config XEN_ADVANCED_COMPRESSION
+	def_bool y
+#	depends on XEN && (XEN_UNPRIVILEGED_GUEST || X86) && (XEN_COMPAT >= 0x040000)
+	depends on XEN && (XEN_UNPRIVILEGED_GUEST || X86)
+	depends on !XEN_COMPAT_030002_AND_LATER
+	depends on !XEN_COMPAT_030004_AND_LATER
+	depends on !XEN_COMPAT_030100_AND_LATER
+	depends on !XEN_COMPAT_030200_AND_LATER
+	depends on !XEN_COMPAT_030300_AND_LATER
+	depends on !XEN_COMPAT_030400_AND_LATER
+
 endmenu
 
 config HAVE_IRQ_IGNORE_UNHANDLED
