-
Notifications
You must be signed in to change notification settings - Fork 70
/
Makefile
executable file
·72 lines (59 loc) · 1.49 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
all: stm32-unlocked.bin
stm32-unlocked.bin: breath.bin graph.bin
./patch-airsense ../cpap/stm32.bin $@
serve:
mkdocs serve
deploy:
mkdocs gh-deploy
# The breath extension replaces the function at 0x80bb734 with
# a simple on/off timer for alternating between two pressures.
# It can't be too long or it will overlap another function.
#
# TODO: add a size check
#
# To add another extension at a different address in the firmware,
# define a .elf target and a variable with the offset that it will
# be patched into the image.
breath.elf: breath.o stubs.o
breath-offset := 0x80bb734
#
# The graphing is too large to fit directly in the location at 0x8067d2c,
# so it is in high in the flash and the function pointer is fixed up at 0x80f9c88
graph.elf: graph.o stubs.o
graph-offset := 0x80fd000
# If there is a new version of the ghidra XML, the stubs.S
# file will be regenerated so that the addresses and functions
# are at the correct address in the ELF image.
stubs.S: stm32.bin.xml
./ghidra2stubs < $< > $@
CROSS ?= arm-none-eabi-
CC := $(CROSS)gcc
AS := $(CC)
LD := $(CROSS)ld
OBJCOPY := $(CROSS)objcopy
CFLAGS ?= \
-g \
-O3 \
-mcpu=cortex-m4 \
-mhard-float \
-mthumb \
-W \
-Wall \
-nostdlib \
-nostdinc \
ASFLAGS ?= $(CFLAGS)
LDFLAGS ?= \
--nostdlib \
--no-dynamic-linker \
--Ttext $($*-offset) \
--entry start \
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.S
$(AS) $(ASFLAGS) -c -o $@ $<
%.elf:
$(LD) $(LDFLAGS) -o $@ $^
%.bin: %.elf
$(OBJCOPY) -Obinary $< $@
clean:
$(RM) *.o stubs.S