-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
105 lines (80 loc) · 2.91 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
CROSS_TOOL_TARGET ?= arm-none-eabi
ARCH=arm
# BOARD?=rpi2
BOARD?=integrator
ifeq ($(BOARD),rpi2)
TARGET ?= armv7-unknown-linux-gnueabihf
MACHINE=raspi2 -smp 4
QEMU=qemu-system-arm
RUSTCFLAGS=
KERN_TYPE=raw
endif
ifeq ($(BOARD),rpi)
# TODO later change to something with floats
TARGET ?= arm-unknown-linux-gnueabi
RUSTCFLAGS=-Ctarget-cpu=arm1176jzf-s
KERN_TYPE=raw
endif
ifeq ($(BOARD),integrator)
TARGET ?= arm-unknown-linux-gnueabi
MACHINE=integratorcp -m 128 -cpu arm1176
QEMU=qemu-system-arm
RUSTCFLAGS=-Ctarget-cpu=arm1176jz-s
KERN_TYPE=elf
endif
linker_script=src/arch/$(ARCH)/board/$(BOARD)/linker.ld
stub=src/arch/$(ARCH)/board/$(BOARD)/stub.S
stub_object=target/$(TARGET)/stub.o
os_lib=target/$(TARGET)/debug/libos.a
glue=src/arch/$(ARCH)/board/$(BOARD)/glue.c
glue_object=target/$(TARGET)/glue.o
CHANNEL=nightly
LIB_COMPILER=$(shell find ~/.multirust/ -name $(TARGET)|grep $(CHANNEL))/lib/libcompiler_builtins*.rlib
AS=$(TARGET)-as
CPP=$(TARGET)-cpp
LD=$(TARGET)-ld
CC=$(TARGET)-cc
OBJCOPY=$(TARGET)-objcopy
.PHONY: toolchain
toolchain:
rustup override set $(CHANNEL)
rustup target add $(TARGET)
emulate: target/kernel.elf
$(QEMU) -machine $(MACHINE) -kernel target/kernel.elf -serial stdio -s
emulate-debug: target/kernel.raw
$(QEMU) -machine $(MACHINE) -kernel target/kernel.$(KERN_TYPE) -serial stdio -s -S
.PHONY: cargo
cargo:
# see here: https://mail.mozilla.org/pipermail/rust-dev/2014-March/009153.html
cargo rustc --features board-$(BOARD) --target=$(TARGET) -- $(RUSTCFLAGS)
$(os_lib): cargo
$(stub_object): $(stub)
$(CPP) $(stub) | $(AS) -g -o $(stub_object)
$(glue_object): $(glue)
$(CC) -Wall -Wextra -Werror -nostdlib -nostartfiles -ffreestanding -std=gnu99 -c $(glue) -o $(glue_object)
target/kernel.elf: $(os_lib) $(linker_script) $(stub_object) $(glue_object)
$(LD) -n --gc-sections -T $(linker_script) -o target/kernel.elf \
$(stub_object) $(glue_object) $(os_lib) $(LIB_COMPILER)
target/kernel.raw: target/kernel.elf
$(OBJCOPY) -S -O binary target/kernel.elf target/kernel.raw
target/kernel7.img: target/kernel.raw
cp target/kernel.raw target/kernel7.img
target/kernel.img: target/kernel.raw
cp target/kernel.raw target/kernel.img
build: target/kernel.elf target/kernel.raw target/kernel.img target/kernel7.img
debugosx: build container
# qemu-system-arm -machine versatilepb -cpu arm1136 -m 128 -kernel target/kernel.elf -s -S&
@echo Now use this command to debug:
@echo docker run --rm -t -i -v $(shell pwd):$(shell pwd):ro -v $(shell cd;pwd)/.cargo/registry/src/:$(shell cd;pwd)/.cargo/registry/src/:ro --net="host" arm-cross-tools
@echo Followed by:
@echo arm-none-eabi-gdb -ex \'target remote 192.168.99.1:1234\' $(shell pwd)/target/kernel.elf
.PHONY: clean
clean:
cargo clean
.PHONY: container
container:
docker build -t arm-cross-tools tools/arm-cross-tools
docker build -t qemu-rpi tools/qemu
# cargo:
# cargo build --target $(TARGET)
# cargo rustc --target $(TARGET) -- -Z no-landing-pads