Add more modern build script for kernel and disk image based on osdev Bare Bones template
GRUB is not identifying the kernel as multiboot compatible. Possibly because I am using x86_64 instead of i686. Need to investigate further.
This commit is contained in:
1 parent
bbf212d5a2
commit
0adc6e395c
4 files changed
+229
No files matched your search
+68
@@ -1,3 +1,71 @@
|
||||
configure do
|
||||
check_c_compiler "x86_64-elf-gcc", on_fail: "Install cross compiler from x86_64-cross directory"
|
||||
check_program "genext2fs"
|
||||
check_program "grub-mkstandalone"
|
||||
check_program "mformat", on_fail: "Install the mtools package"
|
||||
end
|
||||
|
||||
build do
|
||||
require "tmpdir"
|
||||
|
||||
# EFI (w/ GRUB) partition size (MiB)
|
||||
EFI_PART_SIZE = 8
|
||||
# HOS partition size (MiB)
|
||||
HOS_PART_SIZE = 4
|
||||
|
||||
class Image < Builder
|
||||
def run(options)
|
||||
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||
print_run_message("Generating disk image #{@target}", nil)
|
||||
Dir.mktmpdir do |tmpdir|
|
||||
# Build a standalone GRUB.
|
||||
File.open("#{tmpdir}/grub.cfg", "wb") do |fh|
|
||||
fh.write(<<EOF)
|
||||
insmod part_gpt
|
||||
configfile (hd0,gpt2)/grub.cfg
|
||||
EOF
|
||||
end
|
||||
system(*%W[grub-mkstandalone -O x86_64-efi -o #{tmpdir}/BOOTX64.EFI boot/grub/grub.cfg=#{tmpdir}/grub.cfg])
|
||||
# Create EFI partition.
|
||||
system(*%W[dd if=/dev/zero of=#{tmpdir}/efi.part bs=1M count=#{EFI_PART_SIZE}], err: "/dev/null")
|
||||
system(*%W[mformat -i #{tmpdir}/efi.part ::])
|
||||
system(*%W[mmd -i #{tmpdir}/efi.part ::/EFI])
|
||||
system(*%W[mmd -i #{tmpdir}/efi.part ::/EFI/BOOT])
|
||||
system(*%W[mcopy -i #{tmpdir}/efi.part #{tmpdir}/BOOTX64.EFI ::/EFI/BOOT])
|
||||
# Create ext2 HOS partition.
|
||||
FileUtils.mkdir_p("#{tmpdir}/ext2")
|
||||
@sources.each do |source|
|
||||
FileUtils.cp(source, "#{tmpdir}/ext2")
|
||||
end
|
||||
File.open("#{tmpdir}/ext2/grub.cfg", "wb") do |fh|
|
||||
fh.write(<<EOF)
|
||||
insmod part_gpt
|
||||
insmod multiboot
|
||||
set root=(hd0,gpt2)
|
||||
multiboot /hos.elf
|
||||
EOF
|
||||
end
|
||||
system(*%W[genext2fs -b #{HOS_PART_SIZE * 1024} -d #{tmpdir}/ext2 #{tmpdir}/ext2.part])
|
||||
# Create full disk image.
|
||||
system(*%W[dd if=/dev/zero of=#{@target} bs=1M count=#{EFI_PART_SIZE + HOS_PART_SIZE + 2}], err: "/dev/null")
|
||||
system(*%W[parted -s #{@target} mklabel gpt])
|
||||
system(*%W[parted -s #{@target} mkpart efi 1MiB #{EFI_PART_SIZE + 1}MiB])
|
||||
system(*%W[parted -s #{@target} mkpart hos #{EFI_PART_SIZE + 1}MiB #{EFI_PART_SIZE + HOS_PART_SIZE + 1}MiB])
|
||||
system(*%W[dd if=#{tmpdir}/efi.part of=#{@target} bs=1M seek=1 conv=notrunc], err: "/dev/null")
|
||||
system(*%W[dd if=#{tmpdir}/ext2.part of=#{@target} bs=1M seek=#{1 + EFI_PART_SIZE} conv=notrunc], err: "/dev/null")
|
||||
end
|
||||
@cache.register_build(@target, nil, @sources, @env)
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
Environment.new do |env|
|
||||
env.add_builder(Image)
|
||||
env["CCFLAGS"] += %w[-ffreestanding -Wall -O2]
|
||||
env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld]
|
||||
env["LIBS"] += %w[gcc]
|
||||
env.Program("^/hos.elf", glob("src/**/*.{S,c}"))
|
||||
env.Image("build/hos.img", %w[^/hos.elf])
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user