x86 boot enhancements, boot bean counting 8/11

x86 boot enhancements, boot bean counting 8/11

Post by Eric W. Biederm » Fri, 19 Apr 2002 02:20:08



Linus please apply,

Rework the actual build/link step for kernel images.  
- remove the need for objcopy
- Kill the ROOT_DEV Makefile variable, the implementation
  was only half correct and there are much better ways
  to specify your root device than modifying the kernel Makefile.
- Don't loose information when the executable is built

Except for a few extra fields in setup.S the binary image
is unchanged.

Eric

diff -uNr linux-2.5.8.boot.footprint/Makefile linux-2.5.8.boot.build/Makefile
--- linux-2.5.8.boot.footprint/Makefile Tue Apr 16 11:10:42 2002
+++ linux-2.5.8.boot.build/Makefile     Wed Apr 17 01:20:18 2002
@@ -93,15 +93,6 @@
 AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS)

 #
-# ROOT_DEV specifies the default root-device when making the image.
-# This can be either FLOPPY, CURRENT, /dev/xxxx or empty, in which case
-# the default of FLOPPY is used by 'build'.
-# This is i386 specific.
-#
-
-export ROOT_DEV = CURRENT
-
-#
 # If you want to preset the SVGA mode, uncomment the next line and
 # set SVGA_MODE to whatever number you want.
 # Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode.
diff -uNr linux-2.5.8.boot.footprint/arch/i386/boot/Makefile linux-2.5.8.boot.build/arch/i386/boot/Makefile
--- linux-2.5.8.boot.footprint/arch/i386/boot/Makefile  Sun Aug  5 14:13:19 2001
+++ linux-2.5.8.boot.build/arch/i386/boot/Makefile      Wed Apr 17 01:20:18 2002
@@ -12,13 +12,11 @@
                $(TOPDIR)/include/linux/autoconf.h \
                $(TOPDIR)/include/asm/boot.h

-zImage: $(CONFIGURE) bootsect setup compressed/vmlinux tools/build
-       $(OBJCOPY) compressed/vmlinux compressed/vmlinux.out
-       tools/build bootsect setup compressed/vmlinux.out $(ROOT_DEV) > zImage
-
-bzImage: $(CONFIGURE) bbootsect bsetup compressed/bvmlinux tools/build
-       $(OBJCOPY) compressed/bvmlinux compressed/bvmlinux.out
-       tools/build -b bbootsect bsetup compressed/bvmlinux.out $(ROOT_DEV) > bzImage
+zImage: $(CONFIGURE) tools/build $(TOPDIR)/vmlinux realmode compressed/vmlinux
+       tools/build $(TOPDIR)/vmlinux realmode compressed/vmlinux zImage
+
+bzImage: $(CONFIGURE) tools/build $(TOPDIR)/vmlinux brealmode compressed/bvmlinux
+       tools/build -b $(TOPDIR)/vmlinux brealmode compressed/bvmlinux bzImage

 compressed/vmlinux: $(TOPDIR)/vmlinux
        @$(MAKE) -C compressed vmlinux
@@ -39,49 +37,43 @@
 install: $(CONFIGURE) $(BOOTIMAGE)
        sh -x ./install.sh $(KERNELRELEASE) $(BOOTIMAGE) $(TOPDIR)/System.map "$(INSTALL_PATH)"

-tools/build: tools/build.c
+tools/build: tools/build.c $(TOPDIR)/include/linux/version.h $(TOPDIR)/include/linux/compile.h $(TOPDIR)/include/asm-i386/boot.h
        $(HOSTCC) $(HOSTCFLAGS) -o $@ $< -I$(TOPDIR)/include

-bootsect: bootsect.o
-       $(LD) -Ttext 0x0 -s --oformat binary -o $@ $<
-
 bootsect.o: bootsect.s
        $(AS) -o $@ $<

 bootsect.s: bootsect.S Makefile $(BOOT_INCL)
        $(CPP) $(CPPFLAGS) -traditional $(SVGA_MODE) $(RAMDISK) $< -o $@

-bbootsect: bbootsect.o
-       $(LD) -Ttext 0x0 -s --oformat binary $< -o $@
-
 bbootsect.o: bbootsect.s
        $(AS) -o $@ $<

 bbootsect.s: bootsect.S Makefile $(BOOT_INCL)
        $(CPP) $(CPPFLAGS) -D__BIG_KERNEL__ -traditional $(SVGA_MODE) $(RAMDISK) $< -o $@

-setup: setup.o
-       $(LD) -Ttext 0x0 -s --oformat binary -e begtext -o $@ $<
-
 setup.o: setup.s
        $(AS) -o $@ $<

 setup.s: setup.S video.S Makefile $(BOOT_INCL) $(TOPDIR)/include/linux/version.h $(TOPDIR)/include/linux/compile.h
        $(CPP) $(CPPFLAGS) -D__ASSEMBLY__ -traditional $(SVGA_MODE) $(RAMDISK) $< -o $@

-bsetup: bsetup.o
-       $(LD) -Ttext 0x0 -s --oformat binary -e begtext -o $@ $<
-
 bsetup.o: bsetup.s
        $(AS) -o $@ $<

 bsetup.s: setup.S video.S Makefile $(BOOT_INCL) $(TOPDIR)/include/linux/version.h $(TOPDIR)/include/linux/compile.h
        $(CPP) $(CPPFLAGS) -D__BIG_KERNEL__ -D__ASSEMBLY__ -traditional $(SVGA_MODE) $(RAMDISK) $< -o $@

+realmode: bootsect.o setup.o
+       $(LD) -T realmode.lds -o $@ $^
+
+brealmode: bbootsect.o bsetup.o
+       $(LD) -T realmode.lds -o $@ $^
+
 dep:

 clean:
        rm -f tools/build
-       rm -f setup bootsect zImage compressed/vmlinux.out
-       rm -f bsetup bbootsect bzImage compressed/bvmlinux.out
+       rm -f realmode zImage
+       rm -f brealmode bzImage
        @$(MAKE) -C compressed clean
diff -uNr linux-2.5.8.boot.footprint/arch/i386/boot/bootsect.S linux-2.5.8.boot.build/arch/i386/boot/bootsect.S
--- linux-2.5.8.boot.footprint/arch/i386/boot/bootsect.S        Sun Mar 10 20:07:02 2002
+++ linux-2.5.8.boot.build/arch/i386/boot/bootsect.S    Wed Apr 17 01:20:18 2002
@@ -54,7 +54,7 @@
 #endif

 .code16
-.text
+.section ".bootsect", "ax", @progbits

 .global _start
 _start:
diff -uNr linux-2.5.8.boot.footprint/arch/i386/boot/realmode.lds linux-2.5.8.boot.build/arch/i386/boot/realmode.lds
--- linux-2.5.8.boot.footprint/arch/i386/boot/realmode.lds      Wed Dec 31 17:00:00 1969
+++ linux-2.5.8.boot.build/arch/i386/boot/realmode.lds  Wed Apr 17 01:20:18 2002
@@ -0,0 +1,18 @@
+OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
+ENTRY(_start)
+OUTPUT_ARCH(i386)
+SECTIONS
+{
+       .bootsect 0 : AT(0x10000) {
+               *(.bootsect)
+       }
+       .setup 0 : AT(LOADADDR(.bootsect) + SIZEOF(.bootsect)) {
+               *(.setup)
+       }
+       .setup.heap SIZEOF(.setup) : AT(LOADADDR(.setup) + SIZEOF(.setup)) {
+               *(.setup.heap)
+       }
+       /DISCARD/ : {
+               *(*)
+       }
+}
diff -uNr linux-2.5.8.boot.footprint/arch/i386/boot/setup.S linux-2.5.8.boot.build/arch/i386/boot/setup.S
--- linux-2.5.8.boot.footprint/arch/i386/boot/setup.S   Wed Apr 17 01:05:46 2002
+++ linux-2.5.8.boot.build/arch/i386/boot/setup.S       Wed Apr 17 01:20:18 2002
@@ -80,7 +80,7 @@
 .code16
 .globl _setup, _esetup

-.text
+.section ".setup", "ax", @progbits
 _setup:        

 start:
@@ -171,6 +171,9 @@
                .long   (_esetup_heap - _setup) + DELTA_BOOTSECT
 real_filesz:                           # Datasize of the real mode kernel
                .long (_esetup - _setup) + DELTA_BOOTSECT
+kern_base:     .long   KERNEL_START    # Kernel load address
+kern_memsz:    .long   0x00000000      # Kernel memory usage
+kern_filesz:   .long   0x00000000      # Kernel datasize
 trampoline:    call    start_of_setup
                # Don't let the E820 map overlap code
                . = (E820MAP - DELTA_BOOTSECT) + (E820MAX * E820ENTRY_SIZE)
diff -uNr linux-2.5.8.boot.footprint/arch/i386/boot/tools/build.c linux-2.5.8.boot.build/arch/i386/boot/tools/build.c
--- linux-2.5.8.boot.footprint/arch/i386/boot/tools/build.c     Wed Apr 17 01:04:21 2002
+++ linux-2.5.8.boot.build/arch/i386/boot/tools/build.c Wed Apr 17 01:22:21 2002
@@ -1,19 +1,24 @@
+
 /*
  *  $Id: build.c,v 1.5 1997/05/19 12:29:58 mj Exp $
  *
  *  Copyright (C) 1991, 1992  Linus Torvalds
  *  Copyright (C) 1997 Martin Mares
+ *  Copyright (C) 2002 Eric Biederman
+ *
  */

 /*
  * This file builds a disk-image from three different files:
  *
- * - bootsect: exactly 512 bytes of 8086 machine code, loads the rest
- * - setup: 8086 machine code, sets up system parm
+ * - vmlinux: kernel before compression
+ * - realmode: composed of:
+ *    - bootsect: exactly 512 bytes of 8086 machine code, loads the rest
+ *    - setup: 8086 machine code, sets up system parm
  * - system: 80386 code for actual system
  *
  * It does some checking that all files are of the correct type, and
- * just writes the result to stdout, removing headers and padding to
+ * just writes the result, removing headers and padding to
  * the right amount. It also writes some system data to stderr.
  */

@@ -22,26 +27,29 @@
  * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
  * Cross compiling fixes by Gertjan van Wingerde, July 1996
  * Rewritten by Martin Mares, April 1997
+ * Rewriten by Eric Biederman to remove the need for objcopy and
+ *   to stop losing information. 29 Mary 2002
  */

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <stddef.h>
 #include <stdint.h>
 #include <byteswap.h>
 #include <endian.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/sysmacros.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <errno.h>
+#include <elf.h>
+/* To stay in sync with the kernel we must include these headers */
+#include <linux/version.h>
+#include <linux/compile.h>
 #include <asm/boot.h>

-typedef unsigned char byte;
-typedef unsigned short word;
-typedef unsigned long u32;
-
 #define DEFAULT_MAJOR_ROOT 0
 #define DEFAULT_MINOR_ROOT 0

@@ -64,6 +72,84 @@
 #define le64_to_cpu(x) bswap_64(x)
 #endif

+
+/* Input segments */
+#define IKERN  0
+#define IREAL  1
+#define IZKERN 2
+#define ISEGS  3
+
+/* Segments of the output file */
+#define OREAL 0
+#define OKERN 1
+#define OBSS1 2
+#define OBSS2 3
+#define OSEGS 4
+
+struct file_seg
+{
+       size_t mem_addr;
+       size_t mem_size;
+       size_t data_size;
+       off_t  file_offset;
+       size_t entry;
+       unsigned char *data;
+};
+
+struct boot_params {
+       uint8_t  reserved1[0x1f1];              /* 0x000 */
+       uint8_t  setup_sects;                   /* 0x1f1 */
+       uint16_t mount_root_rdonly;             /* 0x1f2 */
+       uint16_t syssize;                       /* 0x1f4 */
+       uint16_t swapdev;                       /* 0x1f6 */
+       uint16_t ramdisk_flags;                 /* 0x1f8 */
+#define RAMDISK_IMAGE_START_MASK       0x07FF
+#define RAMDISK_PROMPT_FLAG            0x8000
+#define RAMDISK_LOAD_FLAG              0x4000  
+       uint16_t vid_mode;                      /* 0x1fa */
+       uint16_t root_dev;                      /* 0x1fc */
+       uint8_t  reserved9[1];                  /* 0x1fe */
+       uint8_t  aux_device_info;               /* 0x1ff */
+       /* 2.00+ */
+       uint8_t  jump[2];                       /* 0x200 */
+       uint8_t  header_magic[4];               /* 0x202 */
+       uint16_t version;                       /* 0x206 */
+       uint8_t  reserved11[8];                 /* 0x208 */
+       uint8_t  type_of_loader;                /* 0x210 */
+#define LOADER_LILO            0x00
+#define LOADER_LOADLIN         0x10
+#define LOADER_BOOTSECT_LOADER 0x20
+#define LOADER_SYSLINUX        0x30
+#define LOADER_ETHERBOOT       0x40
+#define LOADER_UNKNOWN         0xFF
+       uint8_t  loadflags;                     /* 0x211 */
+#define LOADFLAG_LOADED_HIGH  1
+#define LOADFLAG_STAY_PUT     0x40
+#define LOADFLAG_CAN_USE_HEAP 0x80
+       uint8_t  reserved12[2];                 /* 0x212 */
+       uint32_t code32_start;                  /* 0x214 */
+       uint32_t initrd_start;                  /* 0x218 */
+       uint32_t initrd_size;                   /* 0x21c */
+       uint8_t  reserved13[4];                 /* 0x220 */
+       /* 2.01+ */
+       uint16_t heap_end_ptr;                  /* 0x224 */
+       uint8_t  reserved14[2];                 /* 0x226 */
+       /* 2.02+ */
+       uint32_t cmd_line_ptr;                  /* 0x228 */
+       /*
...

read more »

 
 
 

x86 boot enhancements, boot bean counting 8/11

Post by Martin Daleck » Fri, 19 Apr 2002 02:30:10



> Linus please apply,

> Rework the actual build/link step for kernel images.  
> - remove the need for objcopy
> - Kill the ROOT_DEV Makefile variable, the implementation
>   was only half correct and there are much better ways
>   to specify your root device than modifying the kernel Makefile.
> - Don't loose information when the executable is built

Coudl you please use sufficiently large fields for kdev_t variables?
This way if we once have bigger device id spaces one will not have
to mess with the boot code again.
Thank you.

Quote:> +
> +struct boot_params {
> +  uint8_t  reserved1[0x1f1];              /* 0x000 */
> +  uint8_t  setup_sects;                   /* 0x1f1 */
> +  uint16_t mount_root_rdonly;             /* 0x1f2 */
> +  uint16_t syssize;                       /* 0x1f4 */
> +  uint16_t swapdev;                       /* 0x1f6 */

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this should be uint32_t

Quote:> +  uint16_t ramdisk_flags;                 /* 0x1f8 */
> +#define RAMDISK_IMAGE_START_MASK          0x07FF
> +#define RAMDISK_PROMPT_FLAG               0x8000
> +#define RAMDISK_LOAD_FLAG         0x4000  
> +  uint16_t vid_mode;                      /* 0x1fa */
> +  uint16_t root_dev;                      /* 0x1fc */

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this should be uint32_t

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

x86 boot enhancements, boot bean counting 8/11

Post by Eric W. Biederm » Fri, 19 Apr 2002 02:50:09




> > Linus please apply,
> > Rework the actual build/link step for kernel images.  - remove the need for
> > objcopy
> > - Kill the ROOT_DEV Makefile variable, the implementation
> >   was only half correct and there are much better ways
> >   to specify your root device than modifying the kernel Makefile.
> > - Don't loose information when the executable is built

> Coudl you please use sufficiently large fields for kdev_t variables?
> This way if we once have bigger device id spaces one will not have
> to mess with the boot code again.
> Thank you.

1) This patch doesn't change anything except to document which fields
   are present, and how big they are, and no there isn't enough room
   to trivially expand these fields.
2) Exporting kdev_t from the kernel would be very bad.
3) swapdev is long dead, and root_dev while it works is unnecessary,
   you can specify it on the command line just fine.

So we already are future proofed, and the change you suggest would be
a bad one.  The compiled in command line fully supports the ability
to set your root device, so no functionality is lost.

Like I said in my intro a lot of this code simply makes what the boot
processes is currently doing more visible.

Eric
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

x86 boot enhancements, boot bean counting 8/11

Post by Martin Daleck » Fri, 19 Apr 2002 18:10:06





>>>Linus please apply,
>>>Rework the actual build/link step for kernel images.  - remove the need for
>>>objcopy
>>>- Kill the ROOT_DEV Makefile variable, the implementation
>>>  was only half correct and there are much better ways
>>>  to specify your root device than modifying the kernel Makefile.
>>>- Don't loose information when the executable is built

>>Coudl you please use sufficiently large fields for kdev_t variables?
>>This way if we once have bigger device id spaces one will not have
>>to mess with the boot code again.
>>Thank you.

> 1) This patch doesn't change anything except to document which fields
>    are present, and how big they are, and no there isn't enough room
>    to trivially expand these fields.
> 2) Exporting kdev_t from the kernel would be very bad.
> 3) swapdev is long dead, and root_dev while it works is unnecessary,
>    you can specify it on the command line just fine.

> So we already are future proofed, and the change you suggest would be
> a bad one.  The compiled in command line fully supports the ability
> to set your root device, so no functionality is lost.

> Like I said in my intro a lot of this code simply makes what the boot
> processes is currently doing more visible.

Fine that explains it. Sorry for bogging you about it.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/