-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
43 lines (36 loc) · 1.18 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
toolchain ?= ~/opt/cross/bin
prefix ?= i686-elf
CC = $(toolchain)/$(prefix)-gcc
CC_FLAGS = -nostdlib -ffreestanding -Wall -I include
.phony: all
all: disk.img
disk.img: boot.bin kernel.elf
if [ -f disk.img ]; then rm disk.img; fi
truncate -s 1M disk.img
truncate -s 64M part_main # fat32 has a min size of 32M
mkfs.fat -F 32 part_main
cat part_main >> disk.img
rm part_main
truncate -s +512 disk.img # the last sector of the disk seems to not be used in fdisk partition
fdisk disk.img < fdisk.txt
dd if=boot.bin of=disk.img conv=notrunc bs=440 count=1
dd if=boot.bin of=disk.img conv=notrunc bs=512 skip=1 seek=1
if [ -d temp ]; then rm -rf temp; fi
mkdir temp && sudo mount -o loop,offset=1048576 disk.img temp
sudo cp kernel.elf temp
sudo umount temp && rm -r temp
boot.bin: boot/*.S boot/*.c
$(CC) $(CC_FLAGS) -T boot/bootloader.ld $^ -o boot.a -g
objcopy -O binary boot.a $@
kernel.elf: kernel/*.c kernel/*.S
$(CC) $(CC_FLAGS) -T kernel/kernel.ld -o $@ $^ -g
.phony: debug
debug: disk.img boot.a
qemu-system-i386 -s -S -hda disk.img -m 128M
.phony: run
run: disk.img boot.a
qemu-system-i386 -hda disk.img -m 128M
.phony: clean
clean:
rm *.a *.bin *.img *.elf
rm -r temp