-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile.common
201 lines (162 loc) · 5.83 KB
/
Makefile.common
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
BUILD_BASE = .objs
FW_BASE = .firmwares
# Base ESPRESSIF directory, contains SDK, esptool
ESPRESSIF_ROOT ?= ${HOME}/esp-open-sdk
# Base directory for the compiler
COMPILE_ROOT ?= ${ESPRESSIF_ROOT}/xtensa-lx106-elf/bin
# Base directory of the ESP8266 SDK package, absolute
SDK_BASE ?= ${ESPRESSIF_ROOT}/esp_iot_sdk_v1.0.0
# Esptool.py path and port
ESPTOOL ?= ${ESPRESSIF_ROOT}/esptool/esptool.py
ESPPORT ?= /dev/ttyUSB0
GEN_APPBIN = $(SDK_BASE)/tools/gen_appbin.py
# name for the target project
TARGET ?= app
# name fot the prject
PROJECT ?= ESPPROJECT
# which modules (subdirectories) of the project to include in compiling
MODULES += user
# include dev
DEVS := ${ROOT}/dev ${ROOT}/dev/driver ${ROOT}/dev/utils
####
#### create .version file when it's not existed yet
#### 0.0.1 is the default version to start
#### todo: check version, should be like 100.101.255
####
ifeq ("$(wildcard ./.version)","")
$(shell touch ./.version && echo "0.0.2" > ./.version)
endif
VERSION := $(shell cat ./.version)
# libraries used in this project, mainly provided by the SDK
LIBS += c gcc hal pp phy net80211 lwip wpa main
# compiler flags using during compilation of source files
CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH
CFLAGS += -DVERSION='"$(VERSION)"'
CFLAGS += -DPROJECT='"$(PROJECT)"'
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
# linker script used for the above linkier step
IMAGE ?= 1
OTA ?= 1
# files for flashing, w/o OTA
BIN_NAME_1 = 0x00000
BIN_NAME_2 = 0x40000
BIN_NAME_OTA = user$(IMAGE)
###
### define linker and output bin w/out OTA update option
###
ifeq ($(OTA), 0)
BOOT = 0 ### no boot need
BIN_NAME_1 := $(addprefix $(FW_BASE)/,$(BIN_NAME_1).bin)
BIN_NAME_2 := $(addprefix $(FW_BASE)/,$(BIN_NAME_2).bin)
BIN_OUT = $(BIN_NAME_1) $(BIN_NAME_2)
LD_SCRIPT = eagle.app.v6.ld
else
BOOT = 2 ### support boot v1.2+
BIN_NAME_OTA := $(addprefix $(FW_BASE)/,$(BIN_NAME_OTA).bin)
LD_SCRIPT = eagle.app.v6.new.512.app$(IMAGE).ld
BIN_OUT = $(BIN_NAME_OTA)
endif
mode = 0 ### flash mode
freqdiv = 0 ### flash clk div
size = 0 ### flash size
# various paths from the SDK used in this project
SDK_LIBDIR = lib
SDK_LDDIR = ld
SDK_INCDIR = include
# select which tools to use as compiler, librarian and linker
CC := $(COMPILE_ROOT)/xtensa-lx106-elf-gcc
AR := $(COMPILE_ROOT)/xtensa-lx106-elf-ar
LD := $(COMPILE_ROOT)/xtensa-lx106-elf-gcc
OBJCOPY := ${COMPILE_ROOT}/xtensa-lx106-elf-objcopy
OBJDUMP := ${COMPILE_ROOT}/xtensa-lx106-elf-objdump
### APPS
APP_ROOT := $(ROOT)/apps
ifdef APPS
APPINCLUDES = ${foreach APP, $(APPS), ${wildcard $(APP_ROOT)/$(APP)/Makefile.$(APP)}}
-include $(APPINCLUDES)
APP_DIR += $(addprefix $(APP_ROOT)/,$(APPS))
endif
####
#### no user configurable options below here
####
SRC_DIR += $(MODULES) $(DEVS) $(APP_DIR)
SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
SRC_FILE := ${foreach sdir, $(SRC_DIR), ${subst ${sdir}/,,${wildcard $(sdir)/*.c}}}
OBJ_FILE := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC_FILE))
LIBS := $(addprefix -l,$(LIBS))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
TARGET_OUT:= $(addprefix $(BUILD_BASE)/,$(TARGET).out)
LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT))
INCDIR := $(addprefix -I,$(SRC_DIR))
CFLAGS += $(INCDIR) $(SDK_INCDIR)
V ?= $(VERBOSE)
ifeq ("$(V)","1")
Q :=
vecho := @true
else
Q := @
vecho := @echo
endif
vpath %.c $(SRC_DIR)
.PHONY: all flash clean $(TARGET_OUT)
all: $(FW_BASE) $(BUILD_BASE) $(BIN_OUT)
$(vecho) "Project $(PROJECT), version $(VERSION)"
$(BIN_NAME_1): $(TARGET_OUT)
$(vecho) "No boot needed."
@mv eagle.app.flash.bin $@
$(vecho) "Generate $@ successully"
$(BIN_NAME_2): $(TARGET_OUT)
@mv eagle.app.v6.irom0text.bin $@
@rm eagle.app.v6.*
$(vecho) "Generate $@ successully"
$(BIN_NAME_OTA): $(TARGET_OUT)
@COMPILE=gcc python $(GEN_APPBIN) $< $(BOOT) $(mode) $(freqdiv) $(size)
$(vecho) "Support boot_v1.2 and +"
@mv eagle.app.flash.bin $@
@rm eagle.app.v6.*
@echo "Generate $@ successully"
$(TARGET_OUT): $(APP_AR)
###
### TWO link script for user1 and user2
### force to build *.out with new link script
###
$(vecho) "LD $@"
$(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
@$(OBJCOPY) --only-section .text -O binary $@ eagle.app.v6.text.bin
@$(OBJCOPY) --only-section .data -O binary $@ eagle.app.v6.data.bin
@$(OBJCOPY) --only-section .rodata -O binary $@ eagle.app.v6.rodata.bin
@$(OBJCOPY) --only-section .irom0.text -O binary $@ eagle.app.v6.irom0text.bin
@COMPILE=gcc python $(GEN_APPBIN) $@ $(BOOT) $(mode) $(freqdiv) $(size)
$(APP_AR): $(OBJ_FILE)
$(Q) $(AR) cru $@ $^
### Provide way to create $(BUILD_BASE) if it has been removed by make clean
$(BUILD_BASE):
$(Q) mkdir -p $@
$(FW_BASE):
$(Q) mkdir -p $@
flash:
ifeq ($(OTA), 0)
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(BIN_NAME_1) 0x40000 $(BIN_NAME_2)
else
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(ROOT)/tools/bin/boot_v1.3b3.bin 0x01000 $(BIN_NAME_OTA) 0x7e000 $(ROOT)/tools/bin/blank.bin
endif
${ROOT}/tools/serialdump-linux -b115200 ${ESPPORT}
login:
${ROOT}/tools/serialdump-linux -b115200 ${ESPPORT}
clean:
$(Q) rm -f $(APP_AR)
$(Q) rm -f $(TARGET_OUT)
$(Q) rm -rf $(BUILD_BASE)
$(Q) rm -rf $(FW_BASE)
### Automatic dependency generation
${BUILD_BASE}/%.d: %.c | $(BUILD_BASE)
@set -e; rm -f $@; \
$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,$(BUILD_BASE)/\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
${BUILD_BASE}/%.o : %.c
$(vecho) "CC -c $< -o $@"
$(Q) $(CC) $(CFLAGS) -c $< -o $@
-include ${addprefix $(BUILD_BASE)/,$(SRC_FILE:.c=.d)}