-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
153 lines (117 loc) · 4.17 KB
/
Makefile
File metadata and controls
153 lines (117 loc) · 4.17 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
### Dev Configuration ###
BSP ?= rpi3
DEV_SERIAL ?= /dev/tty.usbserial-0001
### End of Configuration ###
define color_header
@tput setaf 6 2> /dev/null || true
@printf '\n%s\n' $(1)
@tput sgr0 2> /dev/null || true
endef
define color_progress_prefix
@tput setaf 2 2> /dev/null || true
@tput bold 2 2> /dev/null || true
@printf '%12s ' $(1)
@tput sgr0 2> /dev/null || true
endef
ifeq ($(shell uname -s),Linux)
DU_ARGUMENTS = --block-size=1024 --apparent-size
else ifeq ($(shell uname -s),Darwin)
DU_ARGUMENTS = -k -A
endif
define disk_usage_KiB
@printf '%s KiB\n' `du $(DU_ARGUMENTS) $(1) | cut -f1`
endef
QEMU_MISSING_STRING = "This board is not yet supported for QEMU."
ifeq ($(BSP),rpi3)
TARGET = aarch64-unknown-none-softfloat
KERNEL_BIN = kernel8.img
QEMU_BINARY = qemu-system-aarch64
QEMU_MACHINE_TYPE = raspi3b
QEMU_RELEASE_ARGS = -display none -serial stdio
OBJDUMP_BINARY = aarch64-elf-objdump
NM_BINARY = aarch64-elf-nm
READELF_BINARY = aarch64-elf-readelf
LD_SCRIPT_PATH = $(shell pwd)/src/bsp/rpi
RUSTC_MISC_ARGS = -C target-cpu=cortex-a53
else ifeq ($(BSP),rpi4)
TARGET = aarch64-unknown-none-softfloat
KERNEL_BIN = kernel8.img
QEMU_BINARY = qemu-system-aarch64
QEMU_MACHINE_TYPE = raspi4b
QEMU_RELEASE_ARGS = -display none -serial stdio
OBJDUMP_BINARY = aarch64-elf-objdump
NM_BINARY = aarch64-elf-nm
READELF_BINARY = aarch64-elf-readelf
LD_SCRIPT_PATH = $(shell pwd)/src/bsp/rpi
RUSTC_MISC_ARGS = -C target-cpu=cortex-a72
endif
export LD_SCRIPT_PATH
KERNEL_MANIFEST = Cargo.toml
KERNEL_LINKER_SCRIPT = kernel.ld
LAST_BUILD_CONFIG = target/$(BSP).build_config
KERNEL_ELF = target/$(TARGET)/release/kernel
KERNEL_ELF_DEPS = $(filter-out %: ,$(file < $(KERNEL_ELF).d)) $(KERNEL_MANIFEST) $(LAST_BUILD_CONFIG)
RUSTFLAGS = $(RUSTC_MISC_ARGS) -C link-arg=--library-path=$(LD_SCRIPT_PATH) -C link-arg=--script=$(KERNEL_LINKER_SCRIPT)
RUSTFLAGS_PEDANTIC = $(RUSTFLAGS) -D warnings -D missing_docs
FEATURES = --features bsp_$(BSP)
COMPILER_ARGS = --target=$(TARGET) $(FEATURES) --release
RUSTC_CMD = cargo rustc $(COMPILER_ARGS)
DOC_CMD = cargo doc $(COMPILER_ARGS)
CLIPPY_CMD = cargo clippy $(COMPILER_ARGS)
OBJCOPY_CMD = rust-objcopy --strip-all -O binary
COMET_DEBUG_CMD = comet debug
COMET_DEBUG_ARGS = --port $(DEV_SERIAL)
COMET_UPLOAD_CMD = comet upload
COMET_UPLOAD_ARGS = --port $(DEV_SERIAL) --file os.img
COMET_TEST_CMD = comet test
COMET_TEST_ARGS = -b $(QEMU_BINARY) -a "-M $(QEMU_MACHINE_TYPE) $(QEMU_RELEASE_ARGS)"
EXEC_QEMU = $(QEMU_BINARY) -M $(QEMU_MACHINE_TYPE)
.PHONY: all doc qemu qemu-asm debug upload test clippy clean readelf objdump nm check
all: $(KERNEL_BIN)
$(LAST_BUILD_CONFIG):
@rm -f target/*.build_config
@mkdir -p target
@touch $(LAST_BUILD_CONFIG)
$(KERNEL_ELF): $(KERNEL_ELF_DEPS)
$(call color_header, "Compiling kernel ELF - $(BSP)")
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(RUSTC_CMD)
$(KERNEL_BIN): $(KERNEL_ELF)
$(call color_header, "Generating stripped binary")
@$(OBJCOPY_CMD) $(KERNEL_ELF) $(KERNEL_BIN)
$(call color_progress_prefix, "Name")
@echo $(KERNEL_BIN)
$(call color_progress_prefix, "Size")
$(call disk_usage_KiB, $(KERNEL_BIN))
doc:
$(call color_header, "Generating docs")
@$(DOC_CMD) --document-private-items --open
ifeq ($(QEMU_MACHINE_TYPE),)
qemu qemu-asm:
$(call color_header, "$(QEMU_MISSING_STRING)")
else
qemu: $(KERNEL_BIN)
$(call color_header, "Launching QEMU")
@$(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN)
qemu-asm: $(KERNEL_BIN)
$(call color_header, "Launching QEMU in assembly mode")
@$(EXEC_QEMU) $(QEMU_RELEASE_ARGS) -kernel $(KERNEL_BIN) -d in_asm
endif
debug:
@$(COMET_SERIAL_CMD) $(COMET_SERIAL_ARGS)
upload:
@$(COMET_UPLOAD_CMD) $(COMET_UPLOAD_ARGS)
test:
@$(COMET_TEST_CMD) $(COMET_TEST_ARGS)
clippy:
@RUSTFLAGS="$(RUSTFLAGS_PEDANTIC)" $(CLIPPY_CMD)
clean:
rm -rf target $(KERNEL_BIN)
readelf: $(KERNEL_ELF)
$(call color_header, "Reading ELF file")
@$(READELF_BINARY) --headers $(KERNEL_ELF)
objdump: $(KERNEL_ELF)
$(call color_header, "Disassembling ELF file")
@$(OBJDUMP_BINARY) --disassemble --demangle --section .text --section .rodata $(KERNEL_ELF) | rustfilt
nm: $(KERNEL_ELF)
$(call color_header, "Reading symbols")
@$(NM_BINARY) --demangle --print-size $(KERNEL_ELF) | sort | rustfilt