Skip to content

Commit

Permalink
Allow local overrides for build tools
Browse files Browse the repository at this point in the history
Add a mechanism to the Makefile that uses an optional `Makeconf.local` file to override
variables set in the main Makefile. This mechanism along with the changes allows non-standard
overrides for all tools used in the Make targets. Also add a README section on how this
enables building and running KTF on Fedora.

Signed-off-by: Bjoern Doebel <[email protected]>
  • Loading branch information
bjoernd authored and wipawel committed Aug 12, 2020
1 parent 739a9d2 commit 902502a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
cscope.*
*.iso
*.img
Makeconf.local
30 changes: 20 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ endif
endif

CC := gcc
LD := ld

GRUB_FILE := grub-file
GRUB_MKIMAGE := grub-mkimage
GRUB_MODULES := multiboot iso9660 biosdisk
XORRISO := xorriso
QEMU_BIN := qemu-system-x86_64
GDB := gdb

COMMON_FLAGS := -I$(ROOT)/include -pipe -MP -MMD -m64 -D__x86_64__

Expand All @@ -25,6 +33,8 @@ CFLAGS += -mno-red-zone -mno-mmx -mno-sse -mno-sse2
CFLAGS += -fno-stack-protector -fno-exceptions -fno-builtin
CFLAGS += -mcmodel=kernel -fno-pic -fno-asynchronous-unwind-tables -fno-unwind-tables

-include Makeconf.local

SOURCES := $(shell find . -name \*.c)
ASM_SOURCES := $(shell find . -name \*.S)
LINK_SCRIPT := $(shell find . -name \*.ld)
Expand All @@ -41,7 +51,7 @@ all: $(TARGET)
$(TARGET): $(OBJS)
@echo "LD " $@
@ $(CC) $(AFLAGS) -E -P -C -x c $(LINK_SCRIPT) -o $(PREP_LINK_SCRIPT)
@ ld -T $(PREP_LINK_SCRIPT) -o $@ $^
@ $(LD) -T $(PREP_LINK_SCRIPT) -o $@ $^

%.o: %.S
@echo "AS " $@
Expand Down Expand Up @@ -83,32 +93,32 @@ ISO_FILE := boot.iso
.PHONY: iso
iso: all
@echo "GEN ISO" $(ISO_FILE)
@ grub-file --is-x86-multiboot $(TARGET) || { echo "Multiboot not supported"; exit 1; }
@ $(GRUB_FILE) --is-x86-multiboot $(TARGET) || { echo "Multiboot not supported"; exit 1; }
@ cp $(TARGET) grub/boot/
@ grub-mkimage --format i386-pc-eltorito -p /boot/grub -o grub/boot.img multiboot iso9660 biosdisk
@ xorriso -as mkisofs -U -b boot.img -no-emul-boot -boot-load-size 4 -boot-info-table -o $(ISO_FILE) grub 2>> /dev/null
@ $(GRUB_MKIMAGE) --format i386-pc-eltorito -p /boot/grub -o grub/boot.img $(GRUB_MODULES)
@ $(XORRISO) -as mkisofs -U -b boot.img -no-emul-boot -boot-load-size 4 -boot-info-table -o $(ISO_FILE) grub 2>> /dev/null

.PHONY: boot
boot: all
@echo "QEMU START"
@qemu-system-x86_64 -cdrom $(ISO_FILE) $(QEMU_PARAMS)
@$(QEMU_BIN) -cdrom $(ISO_FILE) $(QEMU_PARAMS)

.PHONY: boot_debug
boot_debug: all iso
qemu-system-x86_64 -cdrom $(ISO_FILE) $(QEMU_PARAMS) $(QEMU_PARAMS_DEBUG)
$(QEMU_BIN) -cdrom $(ISO_FILE) $(QEMU_PARAMS) $(QEMU_PARAMS_DEBUG)

.PHONY: run
run: all
qemu-system-x86_64 -kernel $(TARGET) $(QEMU_PARAMS) $(QEMU_PARAMS_KERNEL)
$(QEMU_BIN) -kernel $(TARGET) $(QEMU_PARAMS) $(QEMU_PARAMS_KERNEL)

.PHONY: debug
debug: all
qemu-system-x86_64 -kernel $(TARGET) $(QEMU_PARAMS) $(QEMU_PARAMS_KERNEL) $(QEMU_PARAMS_DEBUG)
$(QEMU_BIN) -kernel $(TARGET) $(QEMU_PARAMS) $(QEMU_PARAMS_KERNEL) $(QEMU_PARAMS_DEBUG)

.PHONY: gdb
gdb: debug
gdb $(TARGET) -ex 'target remote :1234' -ex 'b _start' -ex 'c'
killall -9 qemu-system-x86_64
$(GDB) $(TARGET) -ex 'target remote :1234' -ex 'b _start' -ex 'c'
killall -9 $(QEMU_BIN)

define all_sources
find $(ROOT) -name "*.[hcsS]"
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ The `make` command generates the `kernel64.bin` multiboot-compatible ELF file, t
The `make iso` command takes the `kernel64.bin`, places it in `grub/boot/` directory hierarchy and generates a `boot.iso`
out of the `grub/` (using `grub/boot/grub/grub.cfg` as a default GRUB config).

#### Fedora

KTF builds and runs on Fedora, but you will need to tweak some of the commands. Create a Makeconf.local file with the
following content (tested with Fedora 32):

```
GRUB_FILE := grub2-file
GRUB_MKIMAGE := grub2-mkimage
GRUB_MODULES += normal
QEMU_BIN := qemu-kvm
```

### Running the kernel

#### QEMU (KVM or not)
Expand Down

0 comments on commit 902502a

Please sign in to comment.