Clean up build process
parent
3fc40ce6be
commit
379d8dbcdc
30
Makefile
30
Makefile
|
@ -1,11 +1,27 @@
|
||||||
BUILD_DIR=./build
|
BUILD_DIR=./build
|
||||||
|
export QEMU?=qemu-system-x86_64
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: bios
|
||||||
|
bios: $(BUILD_DIR)/bios.bin $(BUILD_DIR)/bios.img
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
||||||
all: $(BUILD_DIR)/bootloader.bin
|
|
||||||
|
|
||||||
include make/bios
|
|
||||||
include make/bootloader
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -drf $(BUILD_DIR)
|
rm -drf $(BUILD_DIR)
|
||||||
|
cd bootloader; cargo clean
|
||||||
|
|
||||||
|
qemu: $(BUILD_DIR)/bios.img
|
||||||
|
$(QEMU) \
|
||||||
|
-d cpu_reset \
|
||||||
|
-no-reboot \
|
||||||
|
-smp 4 -m 2048 \
|
||||||
|
-chardev stdio,id=debug,signal=off,mux=on \
|
||||||
|
-serial chardev:debug \
|
||||||
|
-mon chardev=debug \
|
||||||
|
-machine q35 \
|
||||||
|
-net none \
|
||||||
|
-enable-kvm \
|
||||||
|
-cpu host \
|
||||||
|
-drive file="$<",format=raw
|
||||||
|
|
||||||
|
include make/bios
|
54
make/bios
54
make/bios
|
@ -1,12 +1,56 @@
|
||||||
BIOS_SRC = ./bios
|
# Build script for BIOS (legacy) boot.
|
||||||
STAGE3_BIN = $(BUILD_DIR)/stage3.elf
|
#
|
||||||
|
# This compiles our bootloader as a static library,
|
||||||
|
# and wraps it in a multistage loader.
|
||||||
|
|
||||||
$(BUILD_DIR)/bootloader.bin: $(wildcard $(BIOS_SRC)/*.asm) $(STAGE3_BIN)
|
|
||||||
|
# Compile bootloader as library
|
||||||
|
LIB_SRC = ./bootloader/Cargo.toml ./bootloader/Cargo.lock $(shell find ./bootloader/src -type f)
|
||||||
|
$(BUILD_DIR)/bios.lib: $(LIB_SRC)
|
||||||
|
@mkdir -p $(BUILD_DIR)
|
||||||
|
env RUSTFLAGS="-C soft-float" \
|
||||||
|
cargo rustc \
|
||||||
|
--manifest-path="./bootloader/Cargo.toml" \
|
||||||
|
-Z build-std=core,alloc \
|
||||||
|
-Z build-std-features=compiler-builtins-mem \
|
||||||
|
--target "./bootloader/targets/x86-unknown-none.json" \
|
||||||
|
--lib \
|
||||||
|
--release \
|
||||||
|
-- \
|
||||||
|
--emit link="$(CURDIR)/$@"
|
||||||
|
|
||||||
|
# Link bootloader
|
||||||
|
BIOS_LD = ./bootloader/linkers/x86-unknown-none.ld
|
||||||
|
$(BUILD_DIR)/bios.elf: $(BUILD_DIR)/bios.lib $(BIOS_LD)
|
||||||
|
ld \
|
||||||
|
-m elf_i386 \
|
||||||
|
--gc-sections \
|
||||||
|
-z max-page-size=0x1000 \
|
||||||
|
-T "$(BIOS_LD)" \
|
||||||
|
-o "$@" \
|
||||||
|
"$<"
|
||||||
|
|
||||||
|
objcopy --only-keep-debug "$@" "$@.sym"
|
||||||
|
objcopy --strip-debug "$@"
|
||||||
|
|
||||||
|
# Wrap bootloader in three-stage BIOS loader
|
||||||
|
BIOS_SRC = ./bios
|
||||||
|
$(BUILD_DIR)/bios.bin: $(wildcard $(BIOS_SRC)/*.asm) $(BUILD_DIR)/bios.elf
|
||||||
@mkdir -p "$(BUILD_DIR)"
|
@mkdir -p "$(BUILD_DIR)"
|
||||||
nasm \
|
nasm \
|
||||||
-f bin \
|
-f bin \
|
||||||
-o "$@" \
|
-o "$@" \
|
||||||
-l "$@.lst" \
|
-l "$@.lst" \
|
||||||
-D STAGE3="$(STAGE3_BIN)" \
|
-D STAGE3="$(BUILD_DIR)/bios.elf" \
|
||||||
-i "$(BIOS_SRC)" \
|
-i "$(BIOS_SRC)" \
|
||||||
"$(BIOS_SRC)/bootloader.asm"
|
"$(BIOS_SRC)/main.asm"
|
||||||
|
|
||||||
|
# Build demo disk image
|
||||||
|
$(BUILD_DIR)/bios.img: $(BUILD_DIR)/bios.bin
|
||||||
|
rm -f "$@.partial"
|
||||||
|
fallocate -l 256MiB "$@.partial"
|
||||||
|
parted -s -a minimal "$@.partial" mklabel msdos
|
||||||
|
parted -s -a minimal "$@.partial" mkpart primary 2MiB 100%
|
||||||
|
dd if="$<" of="$@.partial" bs=1 count=512 conv=notrunc
|
||||||
|
dd if="$<" of="$@.partial" bs=512 skip=1 seek=1 conv=notrunc
|
||||||
|
mv "$@.partial" "$@"
|
|
@ -1,29 +0,0 @@
|
||||||
STAGE3_SRC = ./bootloader/Cargo.toml ./bootloader/Cargo.lock $(shell find ./bootloader/src -type f)
|
|
||||||
STAGE3_LD = ./bootloader/linkers/x86-unknown-none.ld
|
|
||||||
|
|
||||||
# Compile stage 3 bootloader
|
|
||||||
$(BUILD_DIR)/stage3.lib.a: $(STAGE3_SRC)
|
|
||||||
@mkdir -p $(BUILD_DIR)
|
|
||||||
env RUSTFLAGS="-C soft-float" \
|
|
||||||
cargo rustc \
|
|
||||||
--manifest-path="./bootloader/Cargo.toml" \
|
|
||||||
-Z build-std=core,alloc \
|
|
||||||
-Z build-std-features=compiler-builtins-mem \
|
|
||||||
--target "./bootloader/targets/x86-unknown-none.json" \
|
|
||||||
--lib \
|
|
||||||
--release \
|
|
||||||
-- \
|
|
||||||
--emit link="$(CURDIR)/$@"
|
|
||||||
|
|
||||||
# Link stage 3 bootloader
|
|
||||||
$(BUILD_DIR)/stage3.elf: $(BUILD_DIR)/stage3.lib.a $(STAGE3_LD)
|
|
||||||
ld \
|
|
||||||
-m elf_i386 \
|
|
||||||
--gc-sections \
|
|
||||||
-z max-page-size=0x1000 \
|
|
||||||
-T "$(STAGE3_LD)" \
|
|
||||||
-o "$@" \
|
|
||||||
"$<"
|
|
||||||
|
|
||||||
objcopy --only-keep-debug "$@" "$@.sym"
|
|
||||||
objcopy --strip-debug "$@"
|
|
Loading…
Reference in New Issue