-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
227 lines (182 loc) · 5.8 KB
/
Makefile
File metadata and controls
227 lines (182 loc) · 5.8 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Available arguments:
# * General options:
# - `V`: Verbose level: (empty), 1, 2
# - `TARGET_DIR`: Artifact output directory (cargo target directory)
# - `EXTRA_CONFIG`: Extra config specification file
# - `UIMAGE`: To generate U-Boot image
# - `LD_SCRIPT`: Use a custom linker script file.
# * App options:
# - `A` or `APP`: Path to the application
# - `FEATURES`: Features os modules to be enabled.
# - `APP_FEATURES`: Features of (rust) apps to be enabled.
# * QEMU options:
# - `BLK`: Enable storage devices (virtio-blk)
# - `NET`: Enable network devices (virtio-net)
# - `GRAPHIC`: Enable display devices and graphic output (virtio-gpu)
# - `BUS`: Device bus type: mmio, pci
# - `MEM`: Memory size (default is 128M)
# - `DISK_IMG`: Path to the virtual disk image
# - `ACCEL`: Enable hardware acceleration (KVM on linux)
# - `QEMU_LOG`: Enable QEMU logging (log file is "qemu.log")
# - `NET_DUMP`: Enable network packet dump (log file is "netdump.pcap")
# - `NET_DEV`: QEMU netdev backend types: user, tap, bridge
# - `VFIO_PCI`: PCI device address in the format "bus:dev.func" to passthrough
# - `VHOST`: Enable vhost-net for tap backend (only for `NET_DEV=tap`)
# * Network options:
# - `IP`: IPv4 address (default is 10.0.2.15 for QEMU user netdev)
# - `GW`: Gateway IPv4 address (default is 10.0.2.2 for QEMU user netdev)
# Enable unstable features
export RUSTC_BOOTSTRAP := 1
export DWARF := y
V ?=
LTO ?=
TARGET_DIR ?= $(PWD)/target
EXTRA_CONFIG ?=
UIMAGE ?= n
export UNITTEST ?= n
# App options
A := $(PWD)/entry
APP ?= $(A)
export MEMTRACK := n
ifeq ($(MEMTRACK), y)
APP_FEATURES += kapi/memtrack
endif
.DEFAULT_GOAL := all
BUILD_TARGETS := all build run justrun debug clippy disasm rootfs
KCONFIG_TARGETS := menuconfig defconfig saveconfig oldconfig
CLEAN_TARGETS := clean clean_c distclean
UTILITY_TARGETS := clippy doc doc_check_missing fmt unittest unittest_no_fail_fast
NON_BUILD_TARGETS := $(KCONFIG_TARGETS) $(CLEAN_TARGETS) $(UTILITY_TARGETS)
CURRENT_GOAL := $(or $(MAKECMDGOALS),$(.DEFAULT_GOAL))
IS_BUILD := $(filter $(BUILD_TARGETS),$(CURRENT_GOAL))
IS_NON_BUILD := $(filter $(NON_BUILD_TARGETS),$(CURRENT_GOAL))
# Install dependencies
include scripts/make/deps.mk
# .config check
ifneq ($(IS_BUILD),)
ifeq ($(wildcard .config),)
$(error ❌ No .config found. Please run: make menuconfig)
endif
include scripts/make/kconfig.mk
include scripts/make/deps.mk
export K_ARCH=$(ARCH)
export K_MODE=$(MODE)
export K_LOG=$(LOG)
export K_TARGET=$(TARGET)
export K_IP=$(IP)
export K_GW=$(GW)
# Binutils
CROSS_COMPILE ?= $(ARCH)-linux-musl-
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
RANLIB := $(CROSS_COMPILE)ranlib
LD := rust-lld -flavor gnu
OBJDUMP ?= rust-objdump -d --print-imm-hex --x86-asm-syntax=intel
OBJCOPY ?= rust-objcopy --binary-architecture=$(ARCH)
GDB ?= gdb
# Paths
OUT_DIR ?= $(PWD)
LD_SCRIPT ?= $(abspath $(TARGET_DIR)/$(TARGET)/$(MODE)/linker_$(PLAT_NAME).lds)
APP_NAME := xkernel
OUT_ELF := $(OUT_DIR)/$(APP_NAME)_$(PLAT_NAME).elf
OUT_BIN := $(patsubst %.elf,%.bin,$(OUT_ELF))
OUT_UIMG := $(patsubst %.elf,%.uimg,$(OUT_ELF))
ifeq ($(UIMAGE), y)
FINAL_IMG := $(OUT_UIMG)
else
FINAL_IMG := $(OUT_BIN)
endif
all: build
include scripts/make/features.mk
include scripts/make/utils.mk
include scripts/make/build.mk
include scripts/make/qemu.mk
ifeq ($(PLAT_NAME), aarch64-raspi4)
include scripts/make/raspi4.mk
else ifeq ($(PLAT_NAME), aarch64-bsta1000b)
include scripts/make/bsta1000b-fada.mk
endif
ROOTFS_URL = https://github.com/Starry-OS/rootfs/releases/download/20250917
ROOTFS_IMG = rootfs-$(ARCH).img
endif # end of IS_BUILD
menuconfig:
@xconf menuconfig -k Kconfig -s .
@if [ -f .config ]; then \
echo "✅ Configuration saved to .config"; \
else \
echo "ℹ️ No changes saved"; \
fi
rootfs:
@if [ ! -f $(ROOTFS_IMG) ]; then \
echo "Image not found, downloading..."; \
curl -f -L $(ROOTFS_URL)/$(ROOTFS_IMG).xz -O; \
xz -d $(ROOTFS_IMG).xz; \
fi
@cp $(ROOTFS_IMG) $(DISK_IMG)
teefs:
$(MAKE) -C tee_apps ARCH=$(ARCH)
defconfig:
@xconf saveconfig -o .config -k Kconfig -s .
@echo "✅ Default configuration saved to .config"
saveconfig:
@xconf saveconfig -o .config -k Kconfig -s .
oldconfig:
@if [ ! -f .config ]; then \
echo "$(RED_C)Error$(END_C): .config not found."; \
echo "Please run 'make defconfig' or 'make menuconfig' first."; \
exit 1; \
fi
@xconf oldconfig -c .config -k Kconfig -s .
# Generate const definitions before build
gen-const: .config
@echo "📝 Generating Rust const definitions from .config..."
@xconf gen-const
@echo "✅ Generated config.rs"
build: gen-const $(OUT_DIR) $(FINAL_IMG)
disasm:
$(OBJDUMP) $(OUT_ELF) | less
run: build justrun
justrun:
$(call run_qemu)
debug: build
$(call run_qemu_debug) &
$(GDB) $(OUT_ELF) \
-ex 'target remote localhost:1234' \
-ex 'b __kplat_main' \
-ex 'continue' \
-ex 'disp /16i $$pc'
clippy: gen-const
ifeq ($(origin ARCH), command line)
$(call cargo_clippy,--target $(TARGET))
else
$(call cargo_clippy)
endif
doc:
$(call cargo_doc)
doc_check_missing:
$(call cargo_doc)
fmt:
cargo +nightly fmt --all
unittest:
$(call unit_test)
unittest_no_fail_fast:
$(call unit_test,--no-fail-fast)
disk_img:
ifneq ($(wildcard $(DISK_IMG)),)
@printf "$(YELLOW_C)warning$(END_C): disk image \"$(DISK_IMG)\" already exists!\n"
else
$(call make_disk_image,fat32,$(DISK_IMG))
endif
clean: clean_c
rm -rf $(APP)/*.bin $(APP)/*.elf
cargo clean
@rm -f target/kbuild/config.rs .cargo/config.toml
distclean: clean
@rm -f .config .config.old auto.conf autoconf.h
@echo "✅ Removed all configuration files"
clean_c::
rm -rf $(app-objs)
.PHONY: all defconfig oldconfig menuconfig saveconfig gen-const \
build disasm run justrun debug \
clippy doc doc_check_missing fmt fmt_c unittest unittest_no_fail_fast \
disk_img clean distclean clean_c