arch/i386/boot/zImage
or arch/i386/boot/bzImage
respectively. Here is how the image is built:- C and assembly source files are compiled into ELF relocatable object format (.o) and some of them are grouped logically into archives (.a) using ar(1).To know more about ELF go through http://subramanyaachar.blogspot.com/2011/05/understanding-elf-1.html
- Using ld(1), the above .o and .a are linked into
vmlinux
which is a statically linked, non-stripped ELF 32-bit LSB 80386 executable file. System.map
is produced by nm vmlinux, irrelevant or uninteresting symbols are grepped out.- Enter directory
arch/i386/boot
. - Bootsector asm code
bootsect.S
is preprocessed either with or without -D__BIG_KERNEL__, depending on whether the target is bzImage or zImage, intobbootsect.s
orbootsect.s
respectively. bbootsect.s
is assembled and then converted into 'raw binary' form calledbbootsect
(orbootsect.s
assembled and raw-converted intobootsect
for zImage).- Setup code
setup.S
(setup.S
includesvideo.S
) is preprocessed intobsetup.s
for bzImage orsetup.s
for zImage. In the same way as the bootsector code, the difference is marked by -D__BIG_KERNEL__ present for bzImage. The result is then converted into 'raw binary' form calledbsetup
. - Enter directory
arch/i386/boot/compressed
and convert/usr/src/linux/vmlinux
to $tmppiggy (tmp filename) in raw binary format, removing.note
and.comment
ELF sections. - gzip -9 < $tmppiggy > $tmppiggy.gz
- Link $tmppiggy.gz into ELF relocatable (ld -r)
piggy.o
. - Compile compression routines
head.S
andmisc.c
(still inarch/i386/boot/compressed
directory) into ELF objectshead.o
andmisc.o
. - Link together
head.o
,misc.o
andpiggy.o
intobvmlinux
(orvmlinux
for zImage, don't mistake this for/usr/src/linux/vmlinux
!). Note the difference between -Ttext 0x1000 used forvmlinux
and -Ttext 0x100000 forbvmlinux
, i.e. for bzImage compression loader is high-loaded. - Convert
bvmlinux
to 'raw binary'bvmlinux.out
removing.note
and.comment
ELF sections. - Go back to
arch/i386/boot
directory and, using the program tools/build, cat togetherbbootsect
,bsetup
andcompressed/bvmlinux.out
intobzImage
(delete extra 'b' above forzImage
). This writes important variables likesetup_sects
androot_dev
at the end of the bootsector.
We will see later where this limitation comes from.
The upper limit on the bzImage size produced at this step is about 2.5M for booting with LILO and 0xFFFF paragraphs (0xFFFF0 = 1048560 bytes) for booting raw image, e.g. from floppy disk or CD-ROM (El-Torito emulation mode).
Note that while tools/build does validate the size of boot sector, kernel image and lower bound of setup size, it does not check the *upper* bound of said setup size. Therefore it is easy to build a broken kernel by just adding some large ".space" at the end of
setup.S
.To Be continued
No comments:
Post a Comment