-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
212 lines (154 loc) · 5.27 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
# none
OTA ?= none
# Base directory for the compiler. Needs a / at the end; if not set it'll use the tools that are in
# the PATH.
XTENSA_TOOLS_ROOT ?=
# base directory of the ESP8266 SDK package, absolute
SDK_BASE ?= C:/Espressif/ESP8266_RTOS_SDK
#Esptool.py path and port
ESPTOOL ?= esptool.py
ESPPORT ?= COM8
#ESPPORT ?= /dev/tty.wchusbserial1410
#ESPDELAY indicates seconds to wait between flashing the two binary images
ESPDELAY ?= 3
#ESPBAUD ?= 115200
ESPBAUD ?= 460800
# 40m 26m 20m 80m
ESP_FREQ = 40m
# qio qout dio dout
ESP_MODE = qio
#4m 2m 8m 16m 32m
ESP_SIZE = 32m
VERBOSE = yes
FLAVOR = debug
# name for the target project
TARGET ?= esp8266-rtos-app
# which modules (subdirectories) of the project to include in compiling
USER_MODULES = user driver
USER_INC = include
USER_LIB =
SDK_LIBDIR = lib
# SDK_LIBS = c gcc hal phy pp net80211 wpa main lwip crypto wps airkiss smartconfig ssl json
SDK_LIBS = gcc hal phy pp net80211 wpa crypto main freertos lwip minic smartconfig
# SDK_INC = include include/json
SDK_INC = extra_include include include/espressif include/json include/udhcp include/lwip include/lwip/lwip include/lwip/ipv4 include/lwip/ipv6
# Output directors to store intermediate compiled files
# relative to the project directory
BUILD_BASE = build
FIRMWARE_BASE = firmware
# Opensdk patches stdint.h when compiled with an internal SDK. If you run into compile problems pertaining to
# redefinition of int types, try setting this to 'yes'.
USE_OPENSDK ?= no
DATETIME := $(shell date "+%Y-%b-%d_%H:%M:%S_%Z")
# select which tools to use as compiler, librarian and linker
CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
OBJCOPY := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
####
#### no user configurable options below here
####
SRC_DIR := $(USER_MODULES)
BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(USER_MODULES))
INCDIR := $(addprefix -I,$(SRC_DIR))
EXTRA_INCDIR := $(addprefix -I,$(USER_INC))
MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_LIBS := $(addprefix -l,$(SDK_LIBS))
SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INC))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
ASMSRC = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.S))
OBJ = $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
OBJ += $(patsubst %.S,$(BUILD_BASE)/%.o,$(ASMSRC))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET).a)
TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
# compiler flags using during compilation of source files
# CFLAGS = -g \
# -Wpointer-arith \
# -Wundef \
# -Wl,-EL \
# -fno-inline-functions \
# -nostdlib \
# -mlongcalls \
# -mtext-section-literals \
# -ffunction-sections \
# -fdata-sections \
# -fno-builtin-printf\
# -DICACHE_FLASH \
# -DBUID_TIME=\"$(DATETIME)\"
CFLAGS = -g -std=gnu90 -Os -Wpointer-arith -Wundef -Werror \
-Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals \
-mno-serialize-volatile -D__ets__ -DICACHE_FLASH -DBUID_TIME=\"$(DATETIME)\"
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
ifeq ($(FLAVOR),debug)
LDFLAGS += -g -O0
endif
ifeq ($(FLAVOR),release)
LDFLAGS += -g -O2
endif
V ?= $(VERBOSE)
ifeq ("$(V)","yes")
Q :=
vecho := @true
else
Q := @
vecho := @echo
endif
# ifeq ("$(USE_OPENSDK)","yes")
# CFLAGS += -DUSE_OPENSDK
# else
# CFLAGS += -D_STDINT_H
# endif
define maplookup
$(patsubst $(strip $(1)):%,%,$(filter $(strip $(1)):%,$(2)))
endef
ESPTOOL_OPTS=--port $(ESPPORT) --baud $(ESPBAUD)
#32m
ESP_INIT_DATA_DEFAULT_ADDR = 0xfc000
ifeq ("$(ESP_SIZE)","16m")
ESP_INIT_DATA_DEFAULT_ADDR = 0x1fc000
else ifeq ("$(ESP_SIZE)","32m")
ESP_INIT_DATA_DEFAULT_ADDR = 0x3fc000
endif
OUTPUT := $(addprefix $(FIRMWARE_BASE)/,$(TARGET))
ESPTOOL_WRITE = write_flash --flash_freq $(ESP_FREQ) --flash_mode $(ESP_MODE) --flash_size $(ESP_SIZE) \
0x00000 $(OUTPUT)0x00000.bin \
0x20000 $(OUTPUT)0x20000.bin \
$(ESP_INIT_DATA_DEFAULT_ADDR) $(SDK_BASE)/bin/esp_init_data_default.bin
ESPTOOL_FLASHDEF=
LD_SCRIPT = -T$(SDK_BASE)/ld/eagle.app.v6.ld
vpath %.c $(SRC_DIR)
define compile-objects
$1/%.o: %.c
$(vecho) "CC $$<"
$(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
endef
.PHONY: all checkdirs clean
# all: touch checkdirs $(OUTPUT)
all: checkdirs $(OUTPUT)
# touch:
# $(vecho) "-------------------------------------------\n"
# $(vecho) "BUID TIME $(DATETIME)"
# $(vecho) "-------------------------------------------\n"
# $(Q) touch user/user_main.c
checkdirs: $(BUILD_DIR) $(FIRMWARE_BASE)
$(OUTPUT): $(TARGET_OUT)
$(vecho) "FW $@"
$(Q) $(ESPTOOL) elf2image $(ESPTOOL_FLASHDEF) $< -o $(OUTPUT)
$(BUILD_DIR):
$(Q) mkdir -p $@
$(FIRMWARE_BASE):
$(Q) mkdir -p $@
$(TARGET_OUT): $(APP_AR)
$(vecho) "LD $@"
$(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(SDK_LIBS) $(APP_AR) -Wl,--end-group -o $@
$(APP_AR): $(OBJ)
$(vecho) "AR $@"
$(Q) $(AR) cru $@ $^
flash:
$(ESPTOOL) $(ESPTOOL_OPTS) $(ESPTOOL_WRITE)
clean:
$(Q) rm -rf $(BUILD_DIR)
$(Q) rm -rf $(FIRMWARE_BASE)
$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))