forked from piersfinlayson/otb-iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
276 lines (225 loc) · 9.58 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
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
#
# OTB-IOT - Out of The Box Internet Of Things
#
# Copyright (C) 2016 Piers Finlayson
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
include hardware
# SDK versions, etc
SDK_BASE = /opt/esp-open-sdk
ESP_SDK = sdk
# Build tools
XTENSA_DIR = $(SDK_BASE)/xtensa-lx106-elf/bin
OBJDUMP = $(XTENSA_DIR)/xtensa-lx106-elf-objdump
OBJCOPY = $(XTENSA_DIR)/xtensa-lx106-elf-objcopy
NM = $(XTENSA_DIR)/xtensa-lx106-elf-nm
CC = $(XTENSA_DIR)/xtensa-lx106-elf-gcc
LD = $(XTENSA_DIR)/xtensa-lx106-elf-gcc
AR = $(XTENSA_DIR)/xtensa-lx106-elf-ar
ESPTOOL2 = /usr/bin/esptool2
ESPTOOL_PY = python2 $(XTENSA_DIR)/esptool.py
# Compile options
CFLAGS = -Os -Iinclude -I$(SDK_BASE)/sdk/include -mlongcalls -c -ggdb -Wpointer-arith -Wundef -Wno-address -Wl,-El -fno-inline-functions -nostdlib -mtext-section-literals -DICACHE_FLASH -Werror -D__ets__ -Ilib/rboot $(HW_DEFINES)
HTTPD_CFLAGS = -Ilib/httpd -DHTTPD_MAX_CONNECTIONS=5 -std=c99
RBOOT_CFLAGS = -Ilib/rboot -Ilib/rboot/appcode -DBOOT_BIG_FLASH -DBOOT_CONFIG_CHKSUM -DBOOT_IROM_CHKSUM
MQTT_CFLAGS = -Ilib/mqtt -Ilib/httpd -Ilib/brzo_i2c -std=c99
OTB_CFLAGS = -Ilib/httpd -Ilib/mqtt -Ilib/rboot -Ilib/rboot/appcode -Ilib/brzo_i2c -std=c99 -DOTB_IOT_V0_3
I2C_CFLAGS = -Ilib/i2c
# esptool.py options
ESPBAUD = 230400
ESPPORT = /dev/ttyUSB0
ESPTOOL_PY_OPTS=--port $(ESPPORT) --baud $(ESPBAUD)
# esptool2 options
E2_OPTS = -quiet -bin -boot0
SPI_SIZE = 4M
SPI_SPEED = 40
ifeq ($(SPI_SIZE), 256K)
E2_OPTS += -256
else ifeq ($(SPI_SIZE), 512K)
E2_OPTS += -512
else ifeq ($(SPI_SIZE), 1M)
E2_OPTS += -1024
else ifeq ($(SPI_SIZE), 2M)
E2_OPTS += -2048
else ifeq ($(SPI_SIZE), 4M)
E2_OPTS += -4096
else ifeq ($(SPI_SIZE), 8M)
E2_OPTS += -8192
else ifeq ($(SPI_SIZE), 16M)
E2_OPTS += -16384
endif
ifeq ($(SPI_MODE), qio)
E2_OPTS += -qio
else ifeq ($(SPI_MODE), dio)
E2_OPTS += -dio
else ifeq ($(SPI_MODE), qout)
E2_OPTS += -qout
else ifeq ($(SPI_MODE), dout)
E2_OPTS += -dout
endif
ifeq ($(SPI_SPEED), 20)
E2_OPTS += -20
else ifeq ($(SPI_SPEED), 26)
E2_OPTS += -26.7
else ifeq ($(SPI_SPEED), 40)
E2_OPTS += -40
else ifeq ($(SPI_SPEED), 80)
E2_OPTS += -80
endif
# Check image size
# 983040 is 0xf0000. If factory image is written to 0x305000 and the SDK writes
# at 0x3fc000 then we have a bit over 0xf0000 for the app image - so leave a
# bit of contingency
CHECK_APP_IMAGE_FILE_SIZE = \
if [ ! -f "bin/app_image.bin" ]; then \
echo "bin/app_image.bin does not exist" ; exit 1 ; \
fi; \
FILE_SIZE=$$(du -b "bin/app_image.bin" | cut -f 1) ; \
if [ $$FILE_SIZE -gt 983040 ]; then \
echo "bin/app_image.bin too large" ; exit 1 ; \
fi
# Link options
LD_DIR = ld
LDLIBS = -Wl,--start-group -lc -lcirom -lgcc -lhal -lphy -lpp -lnet80211 -lwpa -lmain2 -llwip -lssl -Wl,--end-group
LDFLAGS = -T$(LD_DIR)/eagle.app.v6.ld -nostdlib -Wl,--no-check-sections -Wl,-static -L$(SDK_BASE)/$(ESP_SDK)/lib -u call_user_start -u Cache_Read_Enable_New -Lbin
RBOOT_LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
LD_SCRIPT = $(LD_DIR)/eagle.app.v6.ld
# Source and object directories
OTB_SRC_DIR = src
OTB_OBJ_DIR = obj/otb
HTTPD_SRC_DIR = lib/httpd
HTTPD_OBJ_DIR = obj/httpd
RBOOT_SRC_DIR = lib/rboot
RBOOT_OBJ_DIR = obj/rboot
MQTT_SRC_DIR = lib/mqtt
MQTT_OBJ_DIR = obj/mqtt
I2C_SRC_DIR = lib/brzo_i2c
I2C_OBJ_DIR = obj/brzo_i2c
# Object files
otbObjects = $(OTB_OBJ_DIR)/otb_ds18b20.o \
$(OTB_OBJ_DIR)/otb_mqtt.o \
$(OTB_OBJ_DIR)/otb_i2c.o \
$(OTB_OBJ_DIR)/otb_i2c_pca9685.o \
$(OTB_OBJ_DIR)/otb_i2c_mcp23017.o \
$(OTB_OBJ_DIR)/otb_i2c_pcf8574.o \
$(OTB_OBJ_DIR)/otb_i2c_24xxyy.o \
$(OTB_OBJ_DIR)/otb_led.o \
$(OTB_OBJ_DIR)/otb_wifi.o \
$(OTB_OBJ_DIR)/otb_main.o \
$(OTB_OBJ_DIR)/otb_util.o \
$(OTB_OBJ_DIR)/otb_rboot.o \
$(OTB_OBJ_DIR)/otb_gpio.o \
$(OTB_OBJ_DIR)/otb_conf.o \
$(OTB_OBJ_DIR)/otb_httpd.o \
$(OTB_OBJ_DIR)/otb_cmd.o \
$(OTB_OBJ_DIR)/otb_flash.o \
$(OTB_OBJ_DIR)/otb_relay.o \
$(RBOOT_OBJ_DIR)/rboot_ota.o \
$(RBOOT_OBJ_DIR)/rboot-api.o \
$(RBOOT_OBJ_DIR)/rboot-bigflash.o \
$(OTB_OBJ_DIR)/strcasecmp.o \
$(OTB_OBJ_DIR)/pin_map.o
otbDep = $(otbObjects:%.o=%.d)
mqttObjects = $(MQTT_OBJ_DIR)/mqtt.o \
$(MQTT_OBJ_DIR)/proto.o \
$(MQTT_OBJ_DIR)/ringbuf.o \
$(MQTT_OBJ_DIR)/mqtt_msg.o \
$(MQTT_OBJ_DIR)/queue.o \
$(MQTT_OBJ_DIR)/utils.o
mqttDep = $(mqttObjects:%.o=%.d)
httpdObjects = $(HTTPD_OBJ_DIR)/auth.o \
$(HTTPD_OBJ_DIR)/captdns.o \
$(HTTPD_OBJ_DIR)/espfs.o \
$(HTTPD_OBJ_DIR)/heatshrink_decoder.o \
$(HTTPD_OBJ_DIR)/httpd.o \
$(HTTPD_OBJ_DIR)/httpd-nonos.o \
$(HTTPD_OBJ_DIR)/httpdespfs.o \
$(HTTPD_OBJ_DIR)/sha1.o \
$(HTTPD_OBJ_DIR)/stdout.o
httpdDep = $(httpdObjects:%.o=%.d)
rbootObjects = $(RBOOT_OBJ_DIR)/rboot.o \
$(RBOOT_OBJ_DIR)/rboot-stage2a.o \
$(RBOOT_OBJ_DIR)/appcode/rboot-api.o \
$(RBOOT_OBJ_DIR)/appcode/rboot-bigflash.o
rbootDep = $(rbootObjects:%.o=%.d)
i2cObjects = $(I2C_OBJ_DIR)/brzo_i2c.o
i2cDep = $(i2cObjects:%.o=%.d)
all: directories bin/app_image.bin bin/rboot.bin
bin/app_image.bin: bin/app_image.elf
$(NM) -n $^ > bin/symbols
$(OBJDUMP) -d $^ > bin/disassembly
$(ESPTOOL2) -bin -iromchksum -boot2 -1024 $^ $@ .text .data .rodata
@$(CHECK_APP_IMAGE_FILE_SIZE)
bin/app_image.elf: libmain2 otb_objects httpd_objects mqtt_objects i2c_objects obj/html/libwebpages-espfs.a
$(LD) $(LDFLAGS) -o bin/app_image.elf $(otbObjects) $(httpdObjects) $(mqttObjects) $(i2cObjects) $(LDLIBS) obj/html/libwebpages-espfs.a
# can replace with our own version (from rboot-bigflash.c)
libmain2:
$(OBJCOPY) -W Cache_Read_Enable_New $(SDK_BASE)/$(ESP_SDK)/lib/libmain.a bin/libmain2.a
-include $(otbDep) $(mqttDep) $(httpdDep) $(rbootDep)
otb_objects: $(otbObjects)
httpd_objects: $(httpdObjects)
mqtt_objects: $(mqttObjects)
i2c_objects: $(i2cObjects)
$(OTB_OBJ_DIR)/%.o: $(OTB_SRC_DIR)/%.c
$(CC) $(CFLAGS) $(OTB_CFLAGS) -MMD -c $< -o $@
$(HTTPD_OBJ_DIR)/%.o: $(HTTPD_SRC_DIR)/%.c
$(CC) $(CFLAGS) $(HTTPD_CFLAGS) -MMD -c $< -o $@
$(MQTT_OBJ_DIR)/%.o: $(MQTT_SRC_DIR)/%.c
$(CC) $(CFLAGS) $(MQTT_CFLAGS) -MMD -c $< -o $@
$(I2C_OBJ_DIR)/%.o: $(I2C_SRC_DIR)/%.c
$(CC) $(CFLAGS) $(I2C_CFLAGS) -MMD -c $< -o $@
$(RBOOT_OBJ_DIR)/%.o: $(RBOOT_SRC_DIR)/%.c
$(CC) $(CFLAGS) $(RBOOT_CFLAGS) $(OTB_CFLAGS) -MMD -c $< -o $@
$(RBOOT_OBJ_DIR)/rboot-stage2a.o: $(RBOOT_SRC_DIR)/rboot-stage2a.c $(RBOOT_SRC_DIR)/rboot-private.h $(RBOOT_SRC_DIR)/rboot.h
$(CC) $(CFLAGS) $(RBOOT_CFLAGS) -MMD -c $< -o $@
bin/rboot-stage2a.elf: $(RBOOT_OBJ_DIR)/rboot-stage2a.o
$(LD) -T$(LD_DIR)/rboot-stage2a.ld $(RBOOT_LDFLAGS) -Wl,--start-group $^ -Wl,--end-group -o $@
$(RBOOT_OBJ_DIR)/rboot-hex2a.h: bin/rboot-stage2a.elf
$(ESPTOOL2) -quiet -header $< $@ .text
$(RBOOT_OBJ_DIR)/rboot.o: $(RBOOT_SRC_DIR)/rboot.c $(RBOOT_SRC_DIR)/rboot-private.h $(RBOOT_SRC_DIR)/rboot.h $(RBOOT_OBJ_DIR)/rboot-hex2a.h
$(CC) $(CFLAGS) $(RBOOT_CFLAGS) -I$(RBOOT_OBJ_DIR) -MMD -c $< -o $@
bin/rboot.elf: $(RBOOT_OBJ_DIR)/rboot.o
$(LD) -T$(LD_SCRIPT) $(RBOOT_LDFLAGS) -Wl,--start-group $^ -Wl,--end-group -o $@
bin/rboot.bin: bin/rboot.elf
$(ESPTOOL2) $(E2_OPTS) $< $@ .text .rodata
webpages.espfs:
cd html; find . | ../tools/mkespfsimage > ../obj/html/webpages.espfs; cd ..
obj/html/libwebpages-espfs.a: webpages.espfs
$(OBJCOPY) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.irom0.literal \
obj/html/webpages.espfs obj/html/webpages.espfs.o.tmp
$(LD) -nostdlib -Wl,-r obj/html/webpages.espfs.o.tmp -o obj/html/webpages.espfs.o -Wl,-T ld/webpages.espfs.ld
$(AR) cru $@ obj/html/webpages.espfs.o
flash_boot: bin/rboot.bin
$(ESPTOOL_PY) $(ESPTOOL_PY_OPTS) write_flash -ff 40m -fs 32m 0x0 bin/rboot.bin
flash_app: bin/app_image.bin
$(ESPTOOL_PY) $(ESPTOOL_PY_OPTS) write_flash 0x2000 bin/app_image.bin
flash_app2: bin/app_image.bin
$(ESPTOOL_PY) $(ESPTOOL_PY_OPTS) write_flash 0x202000 bin/app_image.bin
flash_factory: bin/app_image.bin
$(ESPTOOL_PY) $(ESPTOOL_PY_OPTS) write_flash 0x302000 bin/app_image.bin
flash: flash_boot flash_app
flash_sdk:
$(ESPTOOL_PY) $(ESPTOOL_PY_OPTS) write_flash 0x3fc000 $(SDK_BASE)/$(ESP_SDK)/bin/esp_init_data_default.bin
flash_initial: erase_flash flash_sdk flash_boot flash_app flash_factory
flash_initial_40mhz: erase_flash flash_boot flash_app flash_factory flash_40mhz
connect:
platformio serialports monitor -b 115200
clean:
@rm -fr bin obj
erase_flash:
$(ESPTOOL_PY) $(ESPTOOL_PY_OPTS) erase_flash
flash_40mhz:
$(ESPTOOL_PY) $(ESPTOOL_PY_OPTS) write_flash 0x3fc000 flash/esp_init_data_40mhz_xtal.hex
directories:
mkdir -p bin $(OTB_OBJ_DIR) $(HTTPD_OBJ_DIR) $(RBOOT_OBJ_DIR) $(RBOOT_OBJ_DIR) $(RBOOT_OBJ_DIR) $(MQTT_OBJ_DIR) $(I2C_OBJ_DIR) obj/html