RFC/Patch: Support for other bootloaders
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
@@ -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
@@ -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
@@ -1,6 +1,8 @@ default: $(MAKE) -C figlet + $(MAKE) -C mkmetard clean: - $(MAKE) -C figlet clean + $(MAKE) -C figlet clean + $(MAKE) -C mkmetard clean
xen/tools/mkmetard/Makefile new file +10 -0
@@ -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
Quoted 4 lines · Michal Ostrowski
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).
Did you try using mbootpack for this? (I haven't tested its output with PXELinux, so I don't know if it would work.)
Tim.
Signature · 10 lines
Tim Deegan (My opinions, not the University's) Systems Research Group University of Cambridge Computer Laboratory ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
Quoted 8 lines · Tim Deegan
Quoted 4 lines · Michal Ostrowski
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).
Did you try using mbootpack for this? (I haven't tested its output with PXELinux, so I don't know if it would work.)
No. This is the first I've heard of it.
Given the two implementations, let's compare and discuss...
My objective was to try to use the Linux bits as-is and to have Xen recognize that it is not loaded via GRUB (are there any other non-GRUB-related multi-boot implementations?). As you can see, the changes required for Xen to recognize the parameters as passed out of Linux's setup.S are not very complicated. Figuring out where everything is is the tough part.
I'm not attached at all to necessarily reach into a Linux build tree to extract a built setup and bootsect. I just think this is the easiest
way to do it. x86 BIOS code is just icky and so I'd like to be able to
avoid having to maintain or even change it. I think it's easier to
have Xen get data out of boot_params.
So, what I think it boils down to is whether Xen should accept parameters passed into it in Linux-style boot_params array, or only accept parameters in GRUB format.
Signature · 1 line
Michal Ostrowski <[email protected]>
Quoted 5 lines · Michal Ostrowski
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).
I think this breaks multiboot support because of:
+void __init __start_xen(void *params)
+{
...
+ multiboot_info_t *mbi = NULL;
+
+ if (MULTIBOOT_BOOTLOADER_MAGIC == *(u32*)params )
+ {
+ mbi = (struct multiboot_info_t*)__va(mbi);
I think this should be:
+ if (MULTIBOOT_BOOTLOADER_MAGIC == *(u32*)__va(params) )
+ {
+ mbi = (struct multiboot_info_t*)__va(params);
Also, have you tested your changes on a SMP or HT machine? I think you're lucky if it works at all because you rearranged some of the tests, and now the test for multiboot is no longer protected by the test if we're running on a secondary cpu (%ebx == 0).
Finally, I think the updated mbootpack is a sufficient solution -- we're trying to fix a limitation in most bootloaders and interposing something which works around this limitation seems like a sane approach...
christian
-------------------------------------------------------
This SF.net email is sponsored by Microsoft Mobile & Embedded DevCon 2005 Attend MEDC 2005 May 9-12 in Vegas. Learn more about the latest Windows Embedded(r) & Windows Mobile(tm) platforms, applications & content. Register by 3/29 & save $300 http://ads.osdn.com/?ad_id=6883&alloc_id=15149&op=click
Quoted 6 lines
Also, have you tested your changes on a SMP or HT machine? I think you're lucky if it works at all because you rearranged some of the tests, and now the test for multiboot is no longer protected by the test if we're running on a secondary cpu (%ebx == 0).
You're correct; my primary intention of the patch was for discussion, problems are to be expected.
Quoted 5 lines
Finally, I think the updated mbootpack is a sufficient solution -- we're trying to fix a limitation in most bootloaders and interposing something which works around this limitation seems like a sane approach...
My primary concern is of style, though aside from that mbootpack is clearly sufficient.
Signature · 1 line
Michal Ostrowski <[email protected]>