同上篇boot.img生成过程类似,不再一一分析,仅记录编译过程log。
https://blog.csdn.net/baidu_31504167/article/details/89136605
第一步:根据diskboot.S生成diskboot_image-diskboot.o文件。
【编译过程log如下】
gcc -DHAVE_CONFIG_H -I. -I…/…/grub-core -I… -Wall -W -DGRUB_MACHINE_PCBIOS=1 -DGRUB_MACHINE=I386_PC -m32 -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/include -I…/…/include -I…/include -DGRUB_FILE=“boot/i386/pc/diskboot.S” -I. -I…/…/grub-core -I… -I…/… -I…/…/include -I…/include -I…/…/grub-core/lib/libgcrypt-grub/src/ -D_FILE_OFFSET_BITS=64 -g -m32 -msoft-float -DGRUB_FILE=“boot/i386/pc/diskboot.S” -I. -I…/…/grub-core -I… -I…/… -I…/…/include -I…/include -I…/…/grub-core/lib/libgcrypt-grub/src/ -DASM_FILE=1 -MT boot/i386/pc/diskboot_image-diskboot.o -MD -MP -MF boot/i386/pc/.deps-core/diskboot_image-diskboot.Tpo -c -o boot/i386/pc/diskboot_image-diskboot.o `test -f ‘boot/i386/pc/diskboot.S’ || echo ‘…/…/grub-core/’`boot/i386/pc/diskboot.S
第二步:将diskboot_image-diskboot.o文件链接成diskboot.image文件。
链接选项中最重要的是将代码段定义在内存的绝对地址0x8000上。
【编译过程log如下】
gcc -Os -Wall -W -Wshadow -Wpointer-arith -Wundef -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wmain -Wmissing-braces -Wmissing-format-attribute -Wmultichar -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wswitch -Wtrigraphs -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wwrite-strings -Wnested-externs -Wstrict-prototypes -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wextra -Wattributes -Wendif-labels -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmissing-field-initializers -Wnonnull -Woverflow -Wvla -Wpointer-to-int-cast -Wstrict-aliasing -Wvariadic-macros -Wvolatile-register-var -Wpointer-sign -Wmissing-include-dirs -Wmissing-prototypes -Wmissing-declarations -Wformat=2 -march=i386 -m32 -mrtd -mregparm=3 -falign-jumps=1 -falign-loops=1 -falign-functions=1 -freg-struct-return -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -msoft-float -fno-dwarf2-cfi-asm -mno-stack-arg-probe -fno-asynchronous-unwind-tables -fno-unwind-tables -Qn -fno-stack-protector -Wtrampolines -Werror -fno-builtin -m32 -Wl,-melf_i386 -Wl,–build-id=none -nostdlib -Wl,-N -Wl,-S -Wl,-N -Wl,-Ttext,0x8000 -o diskboot.image boot/i386/pc/diskboot_image-diskboot.o
第三步:利用objcopy命令根据diskboot.image生成diskboot.img文件。
其中利用-R参数删除一些不必要的section。
【编译过程log如下】
if test x0 = x1; then …/grub-macho2img diskboot.image diskboot.img; else objcopy -O binary --strip-unneeded -R .note -R .comment -R .note.gnu.build-id -R .MIPS.abiflags -R .reginfo -R .rel.dyn -R .note.gnu.gold-version -R .ARM.exidx diskboot.image diskboot.img; fi