-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (124 loc) · 4.28 KB
/
Makefile
File metadata and controls
154 lines (124 loc) · 4.28 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
# ===== Toolchain =====
CC := arm-none-eabi-gcc
AS := arm-none-eabi-as
OBJCOPY := arm-none-eabi-objcopy
OBJDUMP := arm-none-eabi-objdump
# ===== Output dirs =====
BUILD_BOOT := build/flash/boot
BUILD_MAIN := build/flash/main
# ===== Linker scripts =====
LDS_BOOT := ld/LinkerScript_boot.ld
LDS_MAIN := ld/LinkerScript_main.ld
# ===== Flags =====
CPUFLAGS := -mcpu=cortex-m7 -mthumb
RWOS_RESTORE_SELFTEST ?= 0
CFLAGS := -g -O3 -ffreestanding -Wall -Wextra $(CPUFLAGS) -Iinclude -DRWOS_RESTORE_SELFTEST=$(RWOS_RESTORE_SELFTEST)
ASFLAGS := -g $(CPUFLAGS)
LDFLAGS_BASE := -g -nostartfiles -nodefaultlibs -nostdlib -ffreestanding $(CPUFLAGS)
# ===== Shared sources (compiled into BOTH images) =====
CSRCS_COMMON := \
$(wildcard src/drivers/*/*.c) \
$(wildcard src/kernel/*.c) \
$(wildcard src/scheduler/*.c) \
$(wildcard src/allocators/*.c) \
$(wildcard src/common_io/*.c)
ASRCS_COMMON := \
$(wildcard src/startup/*.s) \
$(wildcard src/kernel/*.s) \
$(wildcard src/drivers/*/*.s)
# ===== Boot image sources =====
CSRCS_BOOT := \
$(CSRCS_COMMON) \
$(wildcard src/bootmenu/*.c)
ASRCS_BOOT := $(ASRCS_COMMON)
# ===== Main image sources =====
CSRCS_MAIN := \
$(CSRCS_COMMON) \
$(wildcard src/terminal/*.c)
ASRCS_MAIN := $(ASRCS_COMMON)
# ===== Objects =====
BOOT_COBJS := $(patsubst src/%.c,$(BUILD_BOOT)/%.o,$(CSRCS_BOOT))
BOOT_ASOBJS := $(patsubst src/%.s,$(BUILD_BOOT)/%.o,$(ASRCS_BOOT))
BOOT_OBJS := $(BOOT_COBJS) $(BOOT_ASOBJS)
MAIN_COBJS := $(patsubst src/%.c,$(BUILD_MAIN)/%.o,$(CSRCS_MAIN))
MAIN_ASOBJS := $(patsubst src/%.s,$(BUILD_MAIN)/%.o,$(ASRCS_MAIN))
MAIN_OBJS := $(MAIN_COBJS) $(MAIN_ASOBJS)
# ===== Artifacts =====
BOOT_ELF := $(BUILD_BOOT)/boot.elf
BOOT_HEX := $(BUILD_BOOT)/boot.hex
BOOT_BIN := $(BUILD_BOOT)/boot.bin
BOOT_LST := $(BUILD_BOOT)/boot.lst
BOOT_MAP := $(BUILD_BOOT)/boot.map
MAIN_ELF := $(BUILD_MAIN)/main.elf
MAIN_HEX := $(BUILD_MAIN)/main.hex
MAIN_BIN := $(BUILD_MAIN)/main.bin
MAIN_LST := $(BUILD_MAIN)/main.lst
MAIN_MAP := $(BUILD_MAIN)/main.map
# ===== mkdir helper (POSIX) =====
define MKDIRP
@mkdir -p "$(dir $@)"
endef
# ===== Default (must be first target) =====
all: $(BOOT_HEX) $(MAIN_HEX)
# ===== Serial console =====
PICOCOM ?= picocom
TTY ?= /dev/ttyUSB0
BAUD ?= 115200
EMAP ?= delbs
.PHONY: connect
connect:
@command -v $(PICOCOM) >/dev/null 2>&1 || { echo "$(PICOCOM) is not installed; install picocom or set PICOCOM to another terminal program."; exit 1; }
@printf 'waiting for %s' $(TTY)
@while [ ! -c "$(TTY)" ]; do printf '.'; sleep 0.2; done
@printf '\nlaunching %s\n' $(PICOCOM)
@$(PICOCOM) -b $(BAUD) --emap $(EMAP) $(TTY)
# ===== Compile rules =====
$(BUILD_BOOT)/%.o: src/%.c
$(MKDIRP)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_BOOT)/%.o: src/%.s
$(MKDIRP)
$(AS) $(ASFLAGS) $< -o $@
$(BUILD_MAIN)/%.o: src/%.c
$(MKDIRP)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_MAIN)/%.o: src/%.s
$(MKDIRP)
$(AS) $(ASFLAGS) $< -o $@
# ===== Link =====
$(BOOT_ELF): $(BOOT_OBJS)
$(CC) $(LDFLAGS_BASE) -T $(LDS_BOOT) -Wl,-Map=$(BOOT_MAP),--cref $(BOOT_OBJS) -o $@
$(MAIN_ELF): $(MAIN_OBJS)
$(CC) $(LDFLAGS_BASE) -T $(LDS_MAIN) -Wl,-Map=$(MAIN_MAP),--cref $(MAIN_OBJS) -o $@
# ===== Convert =====
$(BOOT_HEX): $(BOOT_ELF)
$(OBJCOPY) -O ihex $(BOOT_ELF) $(BOOT_HEX)
$(OBJCOPY) -O binary $(BOOT_ELF) $(BOOT_BIN)
$(OBJDUMP) -d $(BOOT_ELF) > $(BOOT_LST)
$(MAIN_HEX): $(MAIN_ELF)
$(OBJCOPY) -O ihex $(MAIN_ELF) $(MAIN_HEX)
$(OBJCOPY) -O binary $(MAIN_ELF) $(MAIN_BIN)
$(OBJDUMP) -d $(MAIN_ELF) > $(MAIN_LST)
# ===== Flash both images =====
# reset_config srst_only: use hardware SRST before connecting so the debugger
# can reach the core even when the MCU is in Standby (debug port power-gated).
flash: all
openocd -f interface/stlink.cfg -f target/stm32f7x.cfg \
-c "reset_config srst_only srst_nogate" \
-c "init; reset halt" \
-c "program $(BOOT_HEX) verify" \
-c "program $(MAIN_HEX) verify" \
-c "reset run; exit"
# ===== Convenience target: clean -> debug build -> flash =====
debug-flash:
@$(MAKE) clean
@$(MAKE) all RWOS_RESTORE_SELFTEST=0
@$(MAKE) flash RWOS_RESTORE_SELFTEST=0
# ===== Explicit selftest build/flash (restore loader selftest enabled) =====
selftest-flash:
@$(MAKE) clean
@$(MAKE) all RWOS_RESTORE_SELFTEST=1
@$(MAKE) flash RWOS_RESTORE_SELFTEST=1
clean:
@rm -rf build
.PHONY: all flash clean connect debug-flash selftest-flash