-
Notifications
You must be signed in to change notification settings - Fork 47
/
Makefile.common
293 lines (246 loc) · 8.4 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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
SDK_VERSION = 1.4
# SDK_VERSION = 1.5
# SDK_VERSION = 1.5.x
BUILD_BASE = .objs
FW_BASE = .firmwares
# change this, with your configuration
COMPILE_ROOT ?= ${HOME}/esp-open-sdk/xtensa-lx106-elf/bin
# fota setting
FOTA_PROFILE ?= DEMO
FOTA_CONFIGFILE ?= ${HOME}/.fotaclient-config.json
# say 512, 1024, 4096
FLASH_SIZE ?= 4096
# base directory of the ESP8266 SDK package, absolute
SDK_BASE = ${ROOT}/esp-sdk
# ssptool.py path and port
ESPPORT ?= /dev/ttyUSB0
ESPTOOL = $(ROOT)/tools/esptool/esptool.py
# script to gen bin
GEN_APPBIN = $(ROOT)/esp-sdk/tools/gen_appbin.py
# script to upload firmware for OTA
##FOTA_CLIENT = $(ROOT)/tools/fotaclient/fota-client.js
FOTA_CLIENT = $(ROOT)/work/espupload.php
# name for the target project
TARGET ?= app
# name for 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.1" > ./.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 crypto
# 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
PRE_SDK_1_5 = 1
BOOTBIN = boot_v1.4\(b1\).bin
ifeq ($(SDK_VERSION), 1.5)
PRE_SDK_1_5 = 0
else ifeq ($(SDK_VERSION), 1.5.x)
PRE_SDK_1_5 = 0
BOOTBIN = boot_v1.5.bin
endif
# linker script used for the above linkier step
IMAGE ?= 1
OTA ?= 1
napp =
ifeq ($(PRE_SDK_1_5), 0)
ifeq ($(OTA), 0)
napp = 0
else
ifeq ($(IMAGE), 2)
napp = 2
else
napp = 1
endif
endif
endif
# files for flashing, w/o OTA
ifeq ($(FLASH_SIZE), 512)
flash = 512
else ifeq ($(FLASH_SIZE), 1024)
flash = 1024
else ifeq ($(FLASH_SIZE), 4096)
flash = 2048
endif
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
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 ifeq ($(OTA), 1)
BOOT = 2
BIN_NAME_OTA := $(addprefix $(FW_BASE)/,$(BIN_NAME_OTA).bin)
ifeq ($(FLASH_SIZE), 512)
LD_SCRIPT = eagle.app.v6.new.$(flash).app$(IMAGE).ld
else ifeq ($(FLASH_SIZE), 1024)
LD_SCRIPT = eagle.app.v6.new.$(flash).app$(IMAGE).ld
else ifeq ($(FLASH_SIZE), 4096)
LD_SCRIPT = eagle.app.v6.new.$(flash).ld
endif
BIN_OUT = $(BIN_NAME_OTA)
endif
ifeq ($(OTA), 1)
ifeq ($(IMAGE), 2)
ifeq ($(FLASH_SIZE), 512)
IMAGE_ADDRESS = 0x41000
else ifeq ($(FLASH_SIZE), 1024)
IMAGE_ADDRESS = 0x81000
endif
else
IMAGE_ADDRESS = 0x01000
endif
endif
mode = 0
freqdiv = 0
ifeq ($(FLASH_SIZE), 256)
size = 1
else ifeq ($(FLASH_SIZE), 1024)
size = 2
else ifeq ($(FLASH_SIZE), 2048)
size = 3
else ifeq ($(FLASH_SIZE), 4096)
size = 6
else
size = 0
endif
# 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)
@mv eagle.app.flash.bin $@
@rm eagle.app.v6.*
$(vecho) "Support boot_v1.2 and +"
@echo "Generate $@ successully"
$(TARGET_OUT): $(APP_AR)
###
### TWO link script for user1 and user2
### force to build *.out with new link script
###
$(vecho) "LD $(LD_SCRIPT) $@"
$(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) $(napp)
$(vecho) "$(GEN_APPBIN) $@ $(BOOT) $(mode) $(freqdiv) $(size) $(napp)"
$(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 ($(FLASH_SIZE), 512)
ifeq ($(OTA), 0)
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(BIN_NAME_1) 0x40000 $(BIN_NAME_2) 0x7C000 $(ROOT)/esp-sdk/bin/esp_init_data_default.bin 0x7E000 $(ROOT)/esp-sdk/bin/blank.bin
else ifeq ($(OTA), 1)
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(ROOT)/esp-sdk/bin/$(BOOTBIN) $(IMAGE_ADDRESS) $(BIN_NAME_OTA) 0x7C000 $(ROOT)/esp-sdk/bin/esp_init_data_default.bin 0x7E000 $(ROOT)/esp-sdk/bin/blank.bin
endif
else ifeq ($(FLASH_SIZE), 1024)
ifeq ($(OTA), 0)
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(BIN_NAME_1) 0x80000 $(BIN_NAME_2) 0xFC000 $(ROOT)/esp-sdk/bin/esp_init_data_default.bin 0xFE000 $(ROOT)/esp-sdk/bin/blank.bin
else ifeq ($(OTA), 1)
-$(ESPTOOL) --port $(ESPPORT) write_flash -fs 8m 0x00000 $(ROOT)/esp-sdk/bin/$(BOOTBIN) $(IMAGE_ADDRESS) $(BIN_NAME_OTA) 0xFC000 $(ROOT)/esp-sdk/bin/esp_init_data_default.bin 0xFE000 $(ROOT)/esp-sdk/bin/blank.bin
endif
else ifeq ($(FLASH_SIZE), 4096)
ifeq ($(OTA), 0)
-$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 $(BIN_NAME_1) 0x80000 $(BIN_NAME_2) 0xFC000 $(ROOT)/esp-sdk/bin/esp_init_data_default.bin 0xFE000 $(ROOT)/esp-sdk/bin/blank.bin
else ifeq ($(OTA), 1)
-$(ESPTOOL) --port $(ESPPORT) write_flash -fs 32m-c1 0x00000 $(ROOT)/esp-sdk/bin/$(BOOTBIN) $(IMAGE_ADDRESS) $(BIN_NAME_OTA) 0x3FC000 $(ROOT)/esp-sdk/bin/esp_init_data_default.bin 0x3FE000 $(ROOT)/esp-sdk/bin/blank.bin
endif
endif
# ${ROOT}/tools/serialdump-linux -b115200 ${ESPPORT}
# screen ${ESPPORT} 115200
login:
${ROOT}/tools/serialdump-linux -b115200 ${ESPPORT}
# screen ${ESPPORT} 115200
IMAGE1 := $(addprefix $(FW_BASE)/, user1.bin)
IMAGE2 := $(addprefix $(FW_BASE)/, user2.bin)
register:
-$(FOTA_CLIENT) --application $(PROJECT) --version $(VERSION) --i1 $(IMAGE1) --i2 $(IMAGE2)
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)}