Skip to contentSkip to conversation

RFC/Patch: Support for other bootloaders

PATCH Michal Ostrowski 1 participant 1 message Mar 21, 2005

lore
Share & tools
lore
#0 lore raw

I need to net-boot xen on an HS20 blade. HS20's have a Broadcom NIC, which is not supported by grub. The attached patch allows me to build a Xen image which I can boot using PXELinux (and the entire SysLinux family of boot-loaders).

PXELinux should work with any PXE-enabled NIC and thus does not face the same driver-support issues as grub.

This functionality is enabled by using the Linux code that is wrapped around a vmlinux to form a zImage. I've come up with two ways of doing this; as part of the xen build, or a seperate shell-script ("mkzen").

Both methods reach into a specified Linux-kernel build tree to grab the bits for the wrapper. The result, from the boot-loader's point of view looks identical to a zImage.

However, running in this environment, Xen must now accept arguments in the format used between a zImage and a vmlinux and distinguish between this format and the multi-boot format.

Also, since grub is not being used, loading of multiple modules is not supported. Thus I've created a tool to package multiple images, with parameter lists into a "meta-ramdisk". My patch also includes code for Xen to extract multiple images from such a meta-ramdisk.

Comments/suggestions appreciated.

Signature · 1 line
Michal Ostrowski <[email protected]>

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet

#   2005/03/20 16:10:07-05:00 [email protected] 
#   Support being booted by arbitrary boot-loaders with bzImage code from Linux.
#   Wrap xen with Linux's bzImage code, either through support in Makefiles or via 
#   the mkzen script.  Both methods require that one specify the location
#   of a linux i386 build tree, from which we extract the necessary bits.
#   
#   Booting with the bzImage code requires that xen recognize parameters in the format 
#   that vmlinux expects. Have __setup_xen be able to recognize both kinds of parameter
#   formats.

#
# Using non-grub boot-loaders means that we'll only see one module loaded in addition
# to the "kernel" image.
#
# Add a "mkmetard" tool to create "meta-ramdisks" which can include multiple modules with
# parameters, all packaged into one ramdisk image.
#
# Support decomposition of meta-ramdisks in xen.
#

# xen/arch/x86/mkzen
#   2005/03/20 16:10:06-05:00 [email protected] +76 -0
# 
# xen/tools/Makefile
#   2005/03/20 16:10:06-05:00 [email protected] +3 -1
#   Built the mkmetard tool.
# 
# xen/include/xen/multiboot.h
#   2005/03/20 16:10:06-05:00 [email protected] +4 -0
#   Reasonable max number of MBI modules.
# 
# xen/arch/x86/setup.c
#   2005/03/20 16:10:06-05:00 [email protected] +190 -44
#   Support being booted by arbitrary boot-loaders with bzImage code from Linux.
#   Thus, parameters may be passed via pointer in %esi.  Add appropriate checks to
#   detect parameters of this form vs. multi-boot.
#   
#   Add code to extract parameter and system data (e820 memory maps) from either multi-boot
#   or Linux parameter formats.
#   
#   If using Linux parameter format, it is possible that the single ramdisk is a "meta-ramdisk",
#   with a multi-boot-like record that describes multiple module images and parameter
#   strings.
# 
# xen/arch/x86/mkzen
#   2005/03/20 16:10:06-05:00 [email protected] +0 -0
#   BitKeeper file /home/mostrows/xen/xeno-unstable.bk/xen/arch/x86/mkzen
# 
# xen/arch/x86/boot/x86_32.S
#   2005/03/20 16:10:06-05:00 [email protected] +9 -7
#   Support being booted by arbitrary boot-loaders with bzImage code from Linux.
#   Thus, parameters may be passed via pointer in %esi.  Add appropriate checks to
#   detect parameters of this form vs. multi-boot.
# 
# xen/arch/x86/Makefile
#   2005/03/20 16:10:06-05:00 [email protected] +42 -0
#   Add target to build zenImg -- xen wrapped with Linux's bzImage machinery.
# 
# xen/Makefile
#   2005/03/20 16:10:06-05:00 [email protected] +3 -1
#   Build mkmetard.
# 
# xen/tools/mkmetard/mkmetard.c
#   2005/03/20 15:01:15-05:00 [email protected] +225 -0
# 
# xen/tools/mkmetard/Makefile
#   2005/03/20 15:01:15-05:00 [email protected] +10 -0
# 
# xen/tools/mkmetard/mkmetard.c
#   2005/03/20 15:01:15-05:00 [email protected] +0 -0
#   BitKeeper file /home/mostrows/xen/xeno-unstable.bk/xen/tools/mkmetard/mkmetard.c
# 
# xen/tools/mkmetard/Makefile
#   2005/03/20 15:01:15-05:00 [email protected] +0 -0
#   BitKeeper file /home/mostrows/xen/xeno-unstable.bk/xen/tools/mkmetard/Makefile
# 
diff -Nru a/xen/Makefile b/xen/Makefile
--- a/xen/Makefile	2005-03-20 16:15:16 -05:00
+++ b/xen/Makefile	2005-03-20 16:15:16 -05:00
@@ -27,7 +27,7 @@
 dist: install

build: $(TARGET).gz
-
+
install: $(TARGET).gz
[ -d $(DESTDIR)/boot ] || $(INSTALL_DIR) $(DESTDIR)/boot $(INSTALL_DATA) $(TARGET).gz $(DESTDIR)/boot
@@ -52,9 +52,11 @@
[ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm $(MAKE) -C arch/$(TARGET_ARCH) asm-offsets.s $(MAKE) include/asm-$(TARGET_ARCH)/asm-offsets.h
+ $(MAKE) -C tools/mkmetard
$(MAKE) -C common
$(MAKE) -C drivers
$(MAKE) -C arch/$(TARGET_ARCH)
+

 # drivers/char/console.o may contain static banner/compile info. Blow it away.
 delete-unfresh-files:
diff -Nru a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile
--- a/xen/arch/x86/Makefile	2005-03-20 16:15:16 -05:00
+++ b/xen/arch/x86/Makefile	2005-03-20 16:15:16 -05:00
@@ -15,7 +15,11 @@
 OBJS := $(patsubst cdb%.o,,$(OBJS))
 endif

+ifdef LINUX_BUILD
+default: $(TARGET) zenImg
+else
default: $(TARGET)
+endif

$(TARGET): $(TARGET)-syms boot/mkelf32
./boot/mkelf32 $(TARGET)-syms $(TARGET) 0x100000
@@ -32,6 +36,44 @@

boot/mkelf32: boot/mkelf32.c
$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
+
+
+ifdef LINUX_BUILD
+
+#
+# Check Makefile in Linux build dir. If it contains KERNELSRC, then use +# that as source dir, otherwise build==source dir +LINUX_SRC:= $(shell if grep -q KERNELSRC $(LINUX_BUILD)/Makefile ; then \
+ sed -e '/^KERNELSRC/!d' $(LINUX_BUILD)/Makefile | \
+ bash -c '( read A B C ; echo -n $$C)' ; \
+ else \
+ echo -n $(LINUX_BUILD); \
+ fi )
+
+$(TARGET).bin: $(TARGET)
+ $(OBJCOPY) -O binary -R .note -R .comment -S $^ $@
+
+$(TARGET).bin.gz: $(TARGET).bin
+ gzip -f -9 < $< > $@
+
+piggy.o: $(TARGET).bin.gz
+ $(LD) -m elf_i386 -r --format binary --oformat elf32-i386 \
+ -T $(LINUX_SRC)/arch/i386/boot/compressed/vmlinux.scr $< -o $@
+
+zen: $(LINUX_BUILD)/arch/i386/boot/compressed/head.o \
+ $(LINUX_BUILD)/arch/i386/boot/compressed/misc.o \
+ piggy.o
+ $(LD) -m elf_i386 -Ttext 0x100000 -e startup_32 $^ -o $@
+
+zenImg: zen
+ $(OBJCOPY) -O binary -R .note -R .comment -S $^ [email protected]
+ $(LINUX_BUILD)/arch/i386/boot/tools/build \
+ -b $(LINUX_BUILD)/arch/i386/boot/bootsect \
+ $(LINUX_BUILD)/arch/i386/boot/setup [email protected] > $@
+
+
+endif
+

clean:
rm -f *.o *.s *~ core boot/*.o boot/*~ boot/core boot/mkelf32

xen/arch/x86/boot/x86_32.S +9 -7
diff -Nru a/xen/arch/x86/boot/x86_32.S b/xen/arch/x86/boot/x86_32.S
@@ -55,7 +55,7 @@
         mov     %ecx,%gs
         ljmp    $(__HYPERVISOR_CS),$(1f)-__PAGE_OFFSET
 1:      lss     stack_start-__PAGE_OFFSET,%esp
-
+	
         /* Reset EFLAGS (subsumes CLI and CLD). */
 	pushl	$0
 	popf
@@ -82,15 +82,17 @@
         and     $0x7f,%cl   # CR4.PGE (global enable)
         mov     %ecx,%cr4
                 
+        /* Check for Multiboot bootloader */
+        cmp     $0x2BADB002,%eax
+        je     1f
+	/* No multi-boot?  Hope that we've got a Linux boot-params */
+	/* stashed in esi. Save in %ebx until stack is ready. */
+	movl	%esi, %ebx
+1:
         cmp     $(SECONDARY_CPU_FLAG),%ebx
         je      start_paging
                 
-        /* Check for Multiboot bootloader */
-        cmp     $0x2BADB002,%eax
-        jne     not_multiboot
-
-        /* Save the Multiboot info structure for later use. */
-	add     $__PAGE_OFFSET,%ebx
+	/* Stack is now ready, so store boot parameter pointer */
         push    %ebx
 
         /* Initialize BSS (no nasty surprises!) */
xen/arch/x86/mkzen new file +76 -0

77 lines not on this page · raw message

xen/arch/x86/setup.c +190 -44

289 lines not on this page · raw message

xen/include/xen/multiboot.h +4 -0
diff -Nru a/xen/include/xen/multiboot.h b/xen/include/xen/multiboot.h
@@ -28,6 +28,10 @@
 #define MBI_MEMMAP     (1<<6)
 #define MBI_LOADERNAME (1<<9)
 
+/* Make up some reasonable maximum that we support. */
+#define MAX_MBI_MODULES 4
+
+
 /* The symbol table for a.out.  */
 typedef struct {
     u32 tabsize;
xen/tools/Makefile +3 -1
diff -Nru a/xen/tools/Makefile b/xen/tools/Makefile
@@ -1,6 +1,8 @@
 
 default:
 	$(MAKE) -C figlet
+	$(MAKE) -C mkmetard
 
 clean:
-	$(MAKE) -C figlet clean
\ No newline at end of file
+	$(MAKE) -C figlet clean
+	$(MAKE) -C mkmetard clean
\ No newline at end of file
xen/tools/mkmetard/Makefile new file +10 -0
diff -Nru a/xen/tools/mkmetard/Makefile b/xen/tools/mkmetard/Makefile
@@ -0,0 +1,10 @@
+
+include ../../../Config.mk
+
+CFLAGS += -DBUILD_ARCH=$(XEN_COMPILE_ARCH) -DTARGET_ARCH=$(XEN_TARGET_ARCH)
+CFLAGS += -I$(BASEDIR)/include
+mkmetard: mkmetard.c
+	$(HOSTCC) $(CFLAGS) -o $@ $<
+
+clean:
+	rm -f *.o mkmetard
xen/tools/mkmetard/mkmetard.c new file +225 -0

225 lines not on this page · raw message