-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathmain.mf
261 lines (207 loc) · 9.95 KB
/
main.mf
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
define USAGE
Usage: make [command] [VARIABLES]
all......... Build the binaries
clean....... Clean the binaries
purge....... Clean the binaries and web stuff
debug....... Build a .map and .lst file. Useful for seeing what's going on
behind the scenes.
burn ....... Write firmware to chip using a regular serial port
burn_cutecom Write firmware to chip using a regular serial port, killing and
starting cutecom, a serial terminal
build_burn . Build the binaries then execute burn_cutecom
burnweb .... Write data for the Web-GUI to chip using a regular serial
port
netburn .... Same as 'burn' but transfer firmware over the network rather
than the serial port (if supported by the existing firmware
on the chip)
netweb ..... Same as 'burnweb' but transfer data over network if supported
by firmware currently on the chip
getips ..... Get a list with IPs of esp82xxs connected to your network
project .... Make the current working direcotry an esp82xx project
gitproject . Same as 'make project' but also initialiezes the current folder
as git repository and pushes it to GIT_ORIGIN.
Example:
make gitproject GIT_ORIGIN=https://github.com/USER/YREPO.git
cleanproject Remove the use* and web folders
usbburn .... Burn via PRE-RELEASE USB loader (will probably change)
usbweb ..... Burn webpage by PRE-RELEASE USB loader (will probably change)
initdefault Burn default initial data to ROM (may be needed after erase)
init3v3 .... Burn default values to rom but for use with system_get_vdd33
erase ...... Totally erase chip.
wipechip.... Write zeros to the chip
getips ..... Detect pssible IPs for ESP82XX modules, needs nmap, takes time
burnitall .. initdefault + burnweb + burn as a single run.
dumprom .... read the rom from the chip
bump_submodule . Update the git submodules
More commands: all, clean, purge, dumprom, cleanproject
endef
.PHONY : all clean purge netburn burnweb burn $(BIN_TARGET) netweb getips help project gitproject cleanproject build_burn burn_cutecom webmpfs
FW_FILE1 = image.elf-0x00000.bin
FW_FILE2 = image.elf-0x10000.bin
TARGET = image.elf
SRCS += esp82xx/fwsrc/uart.c \
esp82xx/fwsrc/esp82xxutil.c \
esp82xx/fwsrc/flash_rewriter.c \
esp82xx/fwsrc/http.c \
esp82xx/fwsrc/commonservices.c \
esp82xx/fwsrc/http_custom.c \
esp82xx/fwsrc/mdns.c \
esp82xx/fwsrc/mfs.c \
user/custom_commands.c \
user/user_main.c
LIBS += main lwip net80211 wpa phy crypto c espnow
ifneq ($(CUSTOMPP), 1)
LIBS += pp
endif
INCL = $(SDK)/include esp82xx/include .
CFLAGS = -mlongcalls -Os $(addprefix -I,$(INCL) $(call uniq, $(patsubst %/,%,$(dir $(SRCS))))) $(OPTS) -DVERSSTR='$(VERSSTR)' -g
LDFLAGS_CORE = -Wl,--relax -Wl,--gc-sections -nostdlib -L$(XTLIB) \
-L$(XTGCCLIB) $(addprefix $(SDK)/lib/lib,$(addsuffix .a,$(LIBS))) \
$(XTGCCLIB) -T $(LINKERSCRIPT) -T $(SDK)/ld/eagle.rom.addr.v6.ld
# -flto -Wl,--relax -Wl,--gc-sections
LINKFLAGS = $(LDFLAGS_CORE) -B$(XTLIB) $(LDFLAGS_POST)
BIN_TARGET = $(PROJECT_NAME)-$(VERSION)-binaries.zip
INIT_DATA_PLACE ?= 0x3FC000
BLANK_DATA_PLACE1 ?= 0x3FB000
BLANK_DATA_PLACE2 ?= 0x3FE000
ifneq (,$(findstring -DDEBUG,$(OPTS)))
$(warning Debug is enabled!)
FLASH_WRITE_FLAGS += --verify
endif
ifeq ($(SDK),$(PWD)/esp82xx/toolchain/esp_nonos_sdk)
SDK_DEP := esp82xx/toolchain/esp_nonos_sdk/Makefile
endif
##########################################################################RULES
help :
$(info $(value USAGE))
@true
all : $(FW_FILE1) $(FW_FILE2)
build_burn : all burn_cutecom
esp82xx/libgcc_stripped.a :
cp $(GCC_FOLDER)/lib/gcc/xtensa-lx106-elf/$(ESP_GCC_VERS)/libgcc.a esp82xx/libgcc_stripped.a
$(AR) dv esp82xx/libgcc_stripped.a _muldi3.o
$(AR) dv esp82xx/libgcc_stripped.a _mulsf3.o
$(AR) dv esp82xx/libgcc_stripped.a _divsi3.o
$(AR) dv esp82xx/libgcc_stripped.a _udivsi3.o
$(AR) dv esp82xx/libgcc_stripped.a _umodsi3.o
$(AR) dv esp82xx/libgcc_stripped.a _addsubsf3.o
$(AR) dv esp82xx/libgcc_stripped.a _fixdfsi.o
#$(AR) dv esp82xx/libgcc_stripped.a _divsf3.o
$(AR) dv esp82xx/libgcc_stripped.a _muldf3.o
$(AR) dv esp82xx/libgcc_stripped.a _divdf3.o
#$(AR) dv esp82xx/libgcc_stripped.a _divsf3.o
$(AR) dv esp82xx/libgcc_stripped.a _fixunssfsi.o
$(AR) dv esp82xx/libgcc_stripped.a _umoddi3.o
$(AR) dv esp82xx/libgcc_stripped.a _divdi3.o
$(AR) dv esp82xx/libgcc_stripped.a _udivdi3.o
$(AR) dv esp82xx/libgcc_stripped.a _truncdfsf2.o
#$(AR) dv esp82xx/libgcc_stripped.a _divsf3.o
#$(AR) dv esp82xx/libgcc_stripped.a _fixsfsi.o
$(AR) dv esp82xx/libgcc_stripped.a _floatunsidf.o
$(AR) dv esp82xx/libgcc_stripped.a _floatunsisf.o
$(AR) dv esp82xx/libgcc_stripped.a _floatsisf.o
$(AR) dv esp82xx/libgcc_stripped.a _floatsidf.o
$(FW_FILE1) $(FW_FILE2) : $(TARGET)
PATH=$(FOLDERPREFIX):$$PATH $(ESPTOOL_PY) elf2image $(TARGET)
@#no need to set things like dout, and memory size. This data is copied from the ESP back to itself on write.
$(TARGET) : $(SRCS) Makefile $(SDK_DEP) $(XTGCCLIB)
$(CC) $(CFLAGS) $(SRCS) -flto $(LINKFLAGS) -o $@
debug : $(TARGET)
nm -S -n $(TARGET) > image.map
$(PREFIX)objdump -S $(TARGET) > image.lst
$(PREFIX)size -A $(TARGET) | grep -v debug
ifeq ($(CHIP), 8285)
burn : $(FW_FILE1) $(FW_FILE2)
$(info NOTICE: Currently burning for ESP8285. If you are on a '66 reconfigure CHIP.)
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash $(FLASH_WRITE_FLAGS) -fs 8m -fm dout 0x00000 $(FW_FILE1) 0x10000 $(FW_FILE2))
burn_cutecom:
-killall cutecom
$(info NOTICE: Currently burning for ESP8285. If you are on a '66 reconfigure CHIP.)
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash $(FLASH_WRITE_FLAGS) -fs 8m -fm dout 0x00000 $(FW_FILE1) 0x10000 $(FW_FILE2))
-cutecom &
burnitall : $(FW_FILE1) $(FW_FILE2) $(SDK)/bin/blank.bin $(INIT_DATA_ROM) webmpfs
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash -fs 8m -fm dout $(FLASH_WRITE_FLAGS) 0x00000 $(FW_FILE1) 0x10000 $(FW_FILE2) $(MFS_PAGE_OFFSET) web/page.mpfs $(BLANK_DATA_PLACE1) $(SDK)/bin/blank.bin $(INIT_DATA_PLACE) $(INIT_DATA_ROM) $(BLANK_DATA_PLACE2) $(SDK)/bin/blank.bin)
else ifeq ($(CHIP), 8266)
burn : $(FW_FILE1) $(FW_FILE2)
$(info NOTICE: Currently burning for ESP8266. If you are on an '85 reconfigure CHIP.)
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash -fm dio $(FLASH_WRITE_FLAGS) 0x00000 $(FW_FILE1) 0x10000 $(FW_FILE2))
burn_cutecom:
-killall cutecom
$(info NOTICE: Currently burning for ESP8266. If you are on an '85 reconfigure CHIP.)
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash -fm dio $(FLASH_WRITE_FLAGS) 0x00000 $(FW_FILE1) 0x10000 $(FW_FILE2))
-cutecom &
burnitall : $(FW_FILE1) $(FW_FILE2) $(SDK)/bin/blank.bin $(INIT_DATA_ROM) webmpfs
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash -fm dio $(FLASH_WRITE_FLAGS) 0x00000 $(FW_FILE1) 0x10000 $(FW_FILE2) $(BLANK_DATA_PLACE1) $(SDK)/bin/blank.bin $(INIT_DATA_PLACE) $(INIT_DATA_ROM) $(BLANK_DATA_PLACE2) $(SDK)/bin/blank.bin $(MFS_PAGE_OFFSET) web/page.mpfs)
else
$(error Error: Unknown chip '$(CHIP)')
endif
webmpfs :
@cd web && $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) clean page.mpfs #Always rebuild page.mpfs
burnweb : webmpfs
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash $(MFS_PAGE_OFFSET) web/page.mpfs)
#If you have space, MFS should live at 0x100000. It can also live at
#0x10000. But, then it is limited to 180kB. You might need to do this if
# you have a 512kB, or 1M ESP variant.
netburn : $(FW_FILE1) $(FW_FILE2)
@cd web && $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) execute_reflash
web/execute_reflash $(IP) $(FW_FILE1) $(FW_FILE2)
netweb :
@cd web && $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) push
usbburn : $(FW_FILE1) $(FW_FILE2)
web/execute_reflash USB $(FW_FILE1) $(FW_FILE2)
usbweb : $(FW_FILE1) $(FW_FILE2)
@cd web && $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) usbpush
$(BIN_TARGET): $(FW_FILE1) $(FW_FILE2)
@cd web \
&& $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) page.mpfs \
&& $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) execute_reflash \
&& $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) pushtodev \
&& cd ..
zip $@ $(FW_FILE1) $(FW_FILE2) web/execute_reflash web/mfsmaker web/pushtodev web/page.mpfs
wipechip :
dd if=/dev/zero of=/tmp/zeroes bs=16M count=1
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) write_flash 0x0 /tmp/zeroes)
getips :
$(info Detecting possible IPs for ESP82XX modules...)
$(info Needs 'nmap' and takes some time especiallay if none are connected)
sudo nmap -sP 192.168.0.0/24 | grep -iP "espressif|esp" -B2 | grep -oP "(\d{1,3}\.){3,3}\d\d{1,3}"
clean :
$(RM) $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(SRCS))) $(TARGET) image.map image.lst $(CLEAN_EXTRA)
dumprom :
($(ESPTOOL_PY) $(FWBURNFLAGS) --port $(PORT) read_flash 0 1048576 dump.bin)
initdefault :
$(ESPTOOL_PY) $(BURNFLAGS) --port $(PORT) write_flash $(INIT_DATA_PLACE) $(INIT_DATA_ROM)
init3v3 :
$(ESPTOOL_PY) $(BURNFLAGS) --port $(PORT) write_flash $(INIT_DATA_PLACE) esp82xx/data/esp_init_data_adc33.bin
erase:
$(ESPTOOL_PY) $(BURNFLAGS) --port $(PORT) erase_flash
purge : clean
@cd web && $(MAKE) $(MFLAGS) $(MAKEOVERRIDES) clean
$(RM) $(FW_FILE1) $(FW_FILE2) $(BIN_TARGET)
bump_submodule :
cd esp82xx; git pull origin master; git submodule update --init --recursive; cd ..
Makefile : esp82xx/Makefile.example
user.cfg : esp82xx/user.cfg.example
web/page/index.html : esp82xx/web/page/index.html
web/page/example.js : esp82xx/web/page/example.js
Makefile user.cfg web/page/index.html web/page/example.js :
mkdir -p web/page user; \
cp -n $< $@; \
touch $@
project : Makefile user.cfg web/page/index.html web/page/example.js
ln -s $(patsubst %,../../%,$(wildcard esp82xx/web/page/jquery-*)) ../../esp82xx/web/page/menuinterface.js web/page/ 2>/dev/null; \
ln -s $(patsubst %,../%,$(wildcard esp82xx/web/*)) web/ 2>/dev/null; \
cp -rn esp82xx/fwsrc/user/ .;
ifeq ($(SDK),$(PWD)/esp82xx/toolchain/esp_nonos_sdk)
$(SDK_DEP) :
@echo "Warning: SDK is missing, trying to get it from github:" >&2
@cd esp82xx && git submodule update --init --recursive
endif
gitproject: project
git init .
git add .
git remote add origin $(GIT_ORIGIN)
git commit -m 'Initial commit'
git push
cleanproject :
$(RM) -r use* web/