build both BIOS and EFI images
This commit is contained in:
parent
a91ea8d620
commit
8f9881889b
10
Makefile
10
Makefile
@ -2,6 +2,10 @@
|
|||||||
all:
|
all:
|
||||||
./rscons build
|
./rscons build
|
||||||
|
|
||||||
.PHONY: run
|
.PHONY: run-efi
|
||||||
run:
|
run-efi:
|
||||||
qemu-system-x86_64 -bios OVMF.fd -hda build/hos.img
|
qemu-system-x86_64 -bios OVMF.fd -hda build/hos-efi.img
|
||||||
|
|
||||||
|
.PHONY: run-bios
|
||||||
|
run-bios:
|
||||||
|
qemu-system-x86_64 -hda build/hos-bios.img
|
||||||
|
39
Rsconscript
39
Rsconscript
@ -3,6 +3,7 @@ configure do
|
|||||||
check_program "genext2fs"
|
check_program "genext2fs"
|
||||||
check_program "grub-mkstandalone"
|
check_program "grub-mkstandalone"
|
||||||
check_program "mformat", on_fail: "Install the mtools package"
|
check_program "mformat", on_fail: "Install the mtools package"
|
||||||
|
check_program "xorriso"
|
||||||
end
|
end
|
||||||
|
|
||||||
build do
|
build do
|
||||||
@ -13,10 +14,36 @@ build do
|
|||||||
# HOS partition size (MiB)
|
# HOS partition size (MiB)
|
||||||
HOS_PART_SIZE = 4
|
HOS_PART_SIZE = 4
|
||||||
|
|
||||||
class Image < Builder
|
class BiosImage < Builder
|
||||||
def run(options)
|
def run(options)
|
||||||
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||||
print_run_message("Generating disk image #{@target}", nil)
|
print_run_message("Generating BIOS boot image #{@target}", nil)
|
||||||
|
Dir.mktmpdir do |tmpdir|
|
||||||
|
# Create iso directory.
|
||||||
|
FileUtils.mkdir_p("#{tmpdir}/iso/boot/grub")
|
||||||
|
File.open("#{tmpdir}/iso/boot/grub/grub.cfg", "wb") do |fh|
|
||||||
|
fh.write(<<EOF)
|
||||||
|
menuentry "HOS" {
|
||||||
|
multiboot /hos.elf
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
@sources.each do |source|
|
||||||
|
FileUtils.cp(source, "#{tmpdir}/iso")
|
||||||
|
end
|
||||||
|
# Build bootable GRUB image.
|
||||||
|
system(*%W[grub-mkrescue -o #{@target} #{tmpdir}/iso], err: "#{@env.build_root}/grub-mkrescue.log")
|
||||||
|
end
|
||||||
|
@cache.register_build(@target, nil, @sources, @env)
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class EfiImage < Builder
|
||||||
|
def run(options)
|
||||||
|
unless @cache.up_to_date?(@target, nil, @sources, @env)
|
||||||
|
print_run_message("Generating EFI boot image #{@target}", nil)
|
||||||
Dir.mktmpdir do |tmpdir|
|
Dir.mktmpdir do |tmpdir|
|
||||||
# Build a standalone GRUB.
|
# Build a standalone GRUB.
|
||||||
File.open("#{tmpdir}/grub.cfg", "wb") do |fh|
|
File.open("#{tmpdir}/grub.cfg", "wb") do |fh|
|
||||||
@ -63,13 +90,15 @@ EOF
|
|||||||
end
|
end
|
||||||
|
|
||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env.add_builder(Image)
|
env.add_builder(EfiImage)
|
||||||
env["CCFLAGS"] += %w[-ffreestanding -Wall -O2]
|
env.add_builder(BiosImage)
|
||||||
|
env["CCFLAGS"] += %w[-ffreestanding -Wall]
|
||||||
env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld]
|
env["LDFLAGS"] += %w[-ffreestanding -nostdlib -T src/link.ld]
|
||||||
env["LIBS"] += %w[gcc]
|
env["LIBS"] += %w[gcc]
|
||||||
env["OBJDUMP"] = "i686-elf-objdump"
|
env["OBJDUMP"] = "i686-elf-objdump"
|
||||||
env.Program("^/hos.elf", glob("src/**/*.{S,c}"))
|
env.Program("^/hos.elf", glob("src/**/*.{S,c}"))
|
||||||
env.Disassemble("^/hos.elf.txt", "^/hos.elf")
|
env.Disassemble("^/hos.elf.txt", "^/hos.elf")
|
||||||
env.Image("build/hos.img", %w[^/hos.elf])
|
env.EfiImage("build/hos-efi.img", %w[^/hos.elf])
|
||||||
|
env.BiosImage("build/hos-bios.img", %w[^/hos.elf])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user