Makefile 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. #
  2. # Makefile for meta-id - https://github.com/jeelabs/meta-id
  3. #
  4. # Makefile heavily adapted to meta-id and wireless flashing by Thorsten von Eicken
  5. # Lots of work, in particular to support windows, by brunnels
  6. # Original from esphttpd and others...
  7. #
  8. # Start by setting the directories for the toolchain a few lines down
  9. # the default target will build the firmware images
  10. # `make flash` will flash the esp serially
  11. # `make wiflash` will flash the esp over wifi
  12. # `VERBOSE=1 make ...` will print debug info
  13. # `ESP_HOSTNAME=my.esp.example.com make wiflash` is an easy way to override a variable
  14. # optional local configuration file
  15. -include local.conf
  16. # The Wifi station configuration can be hard-coded here, which makes meta-id come up in STA+AP
  17. # mode trying to connect to the specified AP *only* if the flash wireless settings are empty!
  18. # This happens on a full serial flash and avoids having to hunt for the AP...
  19. # STA_SSID ?=
  20. # STA_PASS ?=
  21. # The SOFTAP configuration can be hard-coded here, the minimum parameters to set are AP_SSID && AP_PASS
  22. # The AP SSID has to be at least 8 characters long, same for AP PASSWORD
  23. # The AP AUTH MODE can be set to:
  24. # 0 = AUTH_OPEN,
  25. # 1 = AUTH_WEP,
  26. # 2 = AUTH_WPA_PSK,
  27. # 3 = AUTH_WPA2_PSK,
  28. # 4 = AUTH_WPA_WPA2_PSK
  29. # SSID hidden default 0, ( 0 | 1 )
  30. # Max connections default 4, ( 1 ~ 4 )
  31. # Beacon interval default 100, ( 100 ~ 60000ms )
  32. #
  33. # AP_SSID ?=esp_link_test
  34. # AP_PASS ?=esp_link_test
  35. # AP_AUTH_MODE ?=4
  36. # AP_SSID_HIDDEN ?=0
  37. # AP_MAX_CONN ?=4
  38. # AP_BEACON_INTERVAL ?=100
  39. AP_SSID ?=.META_NNNN
  40. AP_PASS ?=
  41. AP_AUTH_MODE ?=0
  42. # If CHANGE_TO_STA is set to "yes" the meta-id module will switch to station mode
  43. # once successfully connected to an access point. Else it will stay in STA+AP mode.
  44. CHANGE_TO_STA ?= no
  45. # hostname or IP address for wifi flashing
  46. ESP_HOSTNAME ?= meta-id
  47. # --------------- toolchain configuration ---------------
  48. # Base directory for the compiler. Needs a / at the end.
  49. # Typically you'll install https://github.com/pfalcon/esp-open-sdk
  50. # IMPORTANT: use esp-open-sdk `make STANDALONE=n`: the SDK bundled with esp-open-sdk will *not* work!
  51. XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
  52. # Firmware version
  53. # WARNING: if you change this expect to make code adjustments elsewhere, don't expect
  54. # that meta-id will magically work with a different version of the SDK!!!
  55. SDK_VERS ?= esp_iot_sdk_v2.1.0
  56. # Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
  57. # http://bbs.espressif.com/viewforum.php?f=46
  58. # USING THE SDK BUNDLED WITH ESP-OPEN-SDK WILL NOT WORK!!!
  59. SDK_BASE ?= $(wildcard ../$(SDK_VERS))
  60. # If the firmware isn't there, see whether it got downloaded as part of esp-open-sdk
  61. # This used to work at some point, but is not supported, uncomment if you feel lucky ;-)
  62. #ifeq ($(SDK_BASE),)
  63. #SDK_BASE := $(wildcard $(XTENSA_TOOLS_ROOT)/../../$(SDK_VERS))
  64. #endif
  65. # Clean up SDK path
  66. SDK_BASE := $(abspath $(SDK_BASE))
  67. $(info SDK is $(SDK_BASE))
  68. # Path to bootloader file
  69. BOOTFILE ?= $(SDK_BASE/bin/boot_v1.6.bin)
  70. # Esptool.py path and port, only used for 1-time serial flashing
  71. # Typically you'll use https://github.com/themadinventor/esptool
  72. # Windows users use the com port i.e: ESPPORT ?= com3
  73. ESPTOOL ?= $(abspath ../esp-open-sdk/esptool/esptool.py)
  74. ESPPORT ?= /dev/ttyUSB0
  75. ESPBAUD ?= 230400
  76. # --------------- chipset configuration ---------------
  77. # Pick your flash size: "512KB", "1MB", or "4MB"
  78. FLASH_SIZE ?= 4MB
  79. # The pin assignments below are used when the settings in flash are invalid, they
  80. # can be changed via the web interface
  81. # GPIO pin used to reset attached microcontroller, acative low
  82. MCU_RESET_PIN ?= 12
  83. # GPIO pin used with reset to reprogram MCU (ISP=in-system-programming, unused with AVRs), active low
  84. MCU_ISP_PIN ?= 13
  85. # GPIO pin used for "connectivity" LED, active low
  86. LED_CONN_PIN ?= 0
  87. # GPIO pin used for "serial activity" LED, active low
  88. LED_SERIAL_PIN ?= 14
  89. # --------------- meta-id modules config options ---------------
  90. # Optional Modules: mqtt rest socket web-server syslog
  91. MODULES ?= mqtt
  92. # --------------- esphttpd config options ---------------
  93. # If GZIP_COMPRESSION is set to "yes" then the static css, js, and html files will be compressed
  94. # with gzip before added to the espfs image and will be served with gzip Content-Encoding header.
  95. # This could speed up the downloading of these files, but might break compatibility with older
  96. # web browsers not supporting gzip encoding because Accept-Encoding is simply ignored.
  97. # Enable this option if you have large static files to serve (for e.g. JQuery, Twitter bootstrap)
  98. # If you have text based static files with different extensions what you want to serve compressed
  99. # then you will need to add the extension to the following places:
  100. # - Add the extension to this Makefile at the webpages.espfs target to the find command
  101. # - Add the extension to the gzippedFileTypes array in the user/httpd.c file
  102. #
  103. # Adding JPG or PNG files (and any other compressed formats) is not recommended, because GZIP
  104. # compression does not work effectively on compressed files.
  105. GZIP_COMPRESSION ?= yes
  106. # If COMPRESS_W_HTMLCOMPRESSOR is set to "yes" then the static css and js files will be compressed with
  107. # htmlcompressor and yui-compressor. This option works only when GZIP_COMPRESSION is set to "yes".
  108. # https://code.google.com/p/htmlcompressor/#For_Non-Java_Projects
  109. # http://yui.github.io/yuicompressor/
  110. # enabled by default.
  111. COMPRESS_W_HTMLCOMPRESSOR ?= yes
  112. HTML_COMPRESSOR ?= htmlcompressor-1.5.3.jar
  113. YUI_COMPRESSOR ?= yuicompressor-2.4.8.jar
  114. # -------------- End of config options -------------
  115. HTML_PATH = $(abspath ./html)/
  116. WIFI_PATH = $(HTML_PATH)wifi/
  117. TEXT_PATH = $(HTML_PATH)text/
  118. FONT_PATH = $(HTML_PATH)fonts/
  119. ESP_FLASH_MAX ?= 503808 # max bin file
  120. ifeq ("$(FLASH_SIZE)","512KB")
  121. # Winbond 25Q40 512KB flash, typ for esp-01 thru esp-11
  122. ESP_SPI_SIZE ?= 0 # 0->512KB (256KB+256KB)
  123. ESP_FLASH_MODE ?= 0 # 0->QIO
  124. ESP_FLASH_FREQ_DIV ?= 0 # 0->40Mhz
  125. ET_FS ?= 4m # 4Mbit flash size in esptool flash command
  126. ET_FF ?= 40m # 40Mhz flash speed in esptool flash command
  127. ET_INIT_DATA ?= 0x7C000 # where to flash esp_init_data_default.bin
  128. ET_BLANK ?= 0x7E000 # where to flash blank.bin to erase wireless settings
  129. else ifeq ("$(FLASH_SIZE)","1MB")
  130. # ESP-01E
  131. ESP_SPI_SIZE ?= 2 # 2->1MB (512KB+512KB)
  132. ESP_FLASH_MODE ?= 0 # 0->QIO
  133. ESP_FLASH_FREQ_DIV ?= 15 # 15->80MHz
  134. ET_FS ?= 8m # 8Mbit flash size in esptool flash command
  135. ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
  136. ET_INIT_DATA ?= 0xFC000 # where to flash esp_init_data_default.bin
  137. ET_BLANK ?= 0xFE000 # where to flash blank.bin to erase wireless settings
  138. else ifeq ("$(FLASH_SIZE)","2MB")
  139. # Manuf 0xA1 Chip 0x4015 found on wroom-02 modules
  140. # Here we're using two partitions of approx 0.5MB because that's what's easily available in terms
  141. # of linker scripts in the SDK. Ideally we'd use two partitions of approx 1MB, the remaining 2MB
  142. # cannot be used for code (esp8266 limitation).
  143. ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB)
  144. ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
  145. ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
  146. :q
  147. ET_FS ?= 16m # 16Mbit flash size in esptool flash command
  148. ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
  149. ET_INIT_DATA ?= 0x1FC000 # where to flash esp_init_data_default.bin
  150. ET_BLANK ?= 0x1FE000 # where to flash blank.bin to erase wireless settings
  151. else
  152. # Winbond 25Q32 4MB flash, typ for esp-12
  153. # Here we're using two partitions of approx 0.5MB because that's what's easily available in terms
  154. # of linker scripts in the SDK. Ideally we'd use two partitions of approx 1MB, the remaining 2MB
  155. # cannot be used for code (esp8266 limitation).
  156. ESP_SPI_SIZE ?= 4 # 6->4MB (1MB+1MB) or 4->4MB (512KB+512KB)
  157. ESP_FLASH_MODE ?= 0 # 0->QIO, 2->DIO
  158. ESP_FLASH_FREQ_DIV ?= 15 # 15->80Mhz
  159. ET_FS ?= 32m # 32Mbit flash size in esptool flash command
  160. ET_FF ?= 80m # 80Mhz flash speed in esptool flash command
  161. ET_INIT_DATA ?= 0x3FC000 # where to flash esp_init_data_default.bin
  162. ET_BLANK ?= 0x3FE000 # where to flash blank.bin to erase wireless settings
  163. endif
  164. # --------------- meta-id version ---------------
  165. # Version-fu :-) This code assumes that a new maj.minor is started using a "vN.M.0" tag on master
  166. # and that thereafter the desired patchlevel number is just the number of commits since the tag.
  167. #
  168. # Get the current branch name if not using travis
  169. TRAVIS_BRANCH?=$(shell git symbolic-ref --short HEAD --quiet)
  170. # Use git describe to get the latest version tag, commits since then, sha and dirty flag, this
  171. # results is something like "v1.2.0-13-ab6cedf-dirty"
  172. NO_TAG ?= "no-tag"
  173. VERSION := $(shell (git describe --tags --match 'v*.0' --long --dirty || echo $(NO_TAG)) | sed -re 's/(\.0)?-/./')
  174. # If not on master then insert the branch name
  175. ifneq ($(TRAVIS_BRANCH),master)
  176. ifneq ($(findstring V%,$(TRAVIS_BRANCH)),)
  177. VERSION := $(shell echo $(VERSION) | sed -e 's/-/-$(TRAVIS_BRANCH)-/')
  178. endif
  179. endif
  180. VERSION :=$(VERSION)
  181. $(info VERSION is $(VERSION))
  182. # Output directors to store intermediate compiled files
  183. # relative to the project directory
  184. BUILD_BASE = build
  185. FW_BASE = firmware
  186. # name for the target project
  187. TARGET = httpd
  188. # espressif tool to concatenate sections for OTA upload using bootloader v1.2+
  189. APPGEN_TOOL ?= gen_appbin.py
  190. CFLAGS=
  191. # set defines for optional modules
  192. ifneq (,$(findstring mqtt,$(MODULES)))
  193. CFLAGS += -DMQTT
  194. endif
  195. ifneq (,$(findstring rest,$(MODULES)))
  196. CFLAGS += -DREST
  197. endif
  198. ifneq (,$(findstring syslog,$(MODULES)))
  199. CFLAGS += -DSYSLOG
  200. endif
  201. ifneq (,$(findstring web-server,$(MODULES)))
  202. CFLAGS += -DWEBSERVER
  203. endif
  204. ifneq (,$(findstring socket,$(MODULES)))
  205. CFLAGS += -DSOCKET
  206. endif
  207. # flag to disable espconn_secure functions
  208. CFLAGS += -DNOSSL
  209. # which modules (subdirectories) of the project to include in compiling
  210. LIBRARIES_DIR = libraries
  211. MODULES += espfs httpd cmd serial meta-id user
  212. MODULES += $(foreach sdir,$(LIBRARIES_DIR),$(wildcard $(sdir)/*))
  213. EXTRA_INCDIR = include .
  214. # libraries used in this project, mainly provided by the SDK
  215. LIBS = c gcc hal phy pp net80211 wpa main lwip_536 crypto pwm
  216. # compiler flags using during compilation of source files
  217. CFLAGS += -Os -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
  218. -nostdlib -mlongcalls -mtext-section-literals -ffunction-sections -fdata-sections \
  219. -D__ets__ -DICACHE_FLASH -Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) \
  220. -DMCU_RESET_PIN=$(MCU_RESET_PIN) -DMCU_ISP_PIN=$(MCU_ISP_PIN) \
  221. -DLED_CONN_PIN=$(LED_CONN_PIN) -DLED_SERIAL_PIN=$(LED_SERIAL_PIN) \
  222. -DVERSION="meta-id $(VERSION)"
  223. # linker flags used to generate the main object file
  224. LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--gc-sections
  225. # linker script used for the above linker step
  226. LD_SCRIPT := build/eagle.esphttpd.v6.ld
  227. LD_SCRIPT1 := build/eagle.esphttpd1.v6.ld
  228. LD_SCRIPT2 := build/eagle.esphttpd2.v6.ld
  229. # various paths from the SDK used in this project
  230. SDK_LIBDIR = lib
  231. SDK_LDDIR = ld
  232. SDK_INCDIR = include include/json
  233. SDK_TOOLSDIR = tools
  234. # select which tools to use as compiler, librarian and linker
  235. CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
  236. AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar
  237. LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
  238. OBJCP := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
  239. OBJDP := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objdump
  240. ELF_SIZE := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-size
  241. ####
  242. SRC_DIR := $(MODULES)
  243. BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))
  244. SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
  245. SDK_LDDIR := $(addprefix $(SDK_BASE)/,$(SDK_LDDIR))
  246. SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
  247. SDK_TOOLS := $(addprefix $(SDK_BASE)/,$(SDK_TOOLSDIR))
  248. APPGEN_TOOL := $(addprefix $(SDK_TOOLS)/,$(APPGEN_TOOL))
  249. SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
  250. OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC)) $(BUILD_BASE)/espfs_img.o
  251. LIBS := $(addprefix -l,$(LIBS))
  252. APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
  253. USER1_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).user1.out)
  254. USER2_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).user2.out)
  255. INCDIR := $(addprefix -I,$(SRC_DIR))
  256. EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR))
  257. MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
  258. V ?= $(VERBOSE)
  259. ifeq ("$(V)","1")
  260. Q :=
  261. vecho := @true
  262. else
  263. Q := @
  264. vecho := @echo
  265. endif
  266. ifneq ($(strip $(STA_SSID)),)
  267. CFLAGS += -DSTA_SSID="$(STA_SSID)"
  268. endif
  269. ifneq ($(strip $(STA_PASS)),)
  270. CFLAGS += -DSTA_PASS="$(STA_PASS)"
  271. endif
  272. ifneq ($(strip $(AP_SSID)),)
  273. CFLAGS += -DAP_SSID="$(AP_SSID)"
  274. endif
  275. ifneq ($(strip $(AP_PASS)),)
  276. CFLAGS += -DAP_PASS="$(AP_PASS)"
  277. endif
  278. ifneq ($(strip $(AP_AUTH_MODE)),)
  279. CFLAGS += -DAP_AUTH_MODE="$(AP_AUTH_MODE)"
  280. endif
  281. ifneq ($(strip $(AP_SSID_HIDDEN)),)
  282. CFLAGS += -DAP_SSID_HIDDEN="$(AP_SSID_HIDDEN)"
  283. endif
  284. ifneq ($(strip $(AP_MAX_CONN)),)
  285. CFLAGS += -DAP_MAX_CONN="$(AP_MAX_CONN)"
  286. endif
  287. ifneq ($(strip $(AP_BEACON_INTERVAL)),)
  288. CFLAGS += -DAP_BEACON_INTERVAL="$(AP_BEACON_INTERVAL)"
  289. endif
  290. ifeq ("$(GZIP_COMPRESSION)","yes")
  291. CFLAGS += -DGZIP_COMPRESSION
  292. endif
  293. ifeq ("$(CHANGE_TO_STA)","yes")
  294. CFLAGS += -DCHANGE_TO_STA
  295. endif
  296. vpath %.c $(SRC_DIR)
  297. define compile-objects
  298. $1/%.o: %.c
  299. $(vecho) "CC $$<"
  300. $(Q)$(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
  301. endef
  302. .PHONY: all checkdirs clean webpages.espfs wiflash
  303. all: checkdirs $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin
  304. $(USER1_OUT): $(APP_AR) $(LD_SCRIPT1)
  305. $(vecho) "LD $@"
  306. $(Q) $(LD) -L$(SDK_LIBDIR) -T$(LD_SCRIPT1) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
  307. @echo Dump : $(OBJDP) -x $(USER1_OUT)
  308. @echo Disass: $(OBJDP) -d -l -x $(USER1_OUT)
  309. # $(Q) $(OBJDP) -x $(TARGET_OUT) | egrep espfs_img
  310. $(USER2_OUT): $(APP_AR) $(LD_SCRIPT2)
  311. $(vecho) "LD $@"
  312. $(Q) $(LD) -L$(SDK_LIBDIR) -T$(LD_SCRIPT2) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
  313. # $(Q) $(OBJDP) -x $(TARGET_OUT) | egrep espfs_img
  314. $(FW_BASE):
  315. $(vecho) "FW $@"
  316. $(Q) mkdir -p $@
  317. $(FW_BASE)/user1.bin: $(USER1_OUT) $(FW_BASE)
  318. $(Q) $(OBJCP) --only-section .text -O binary $(USER1_OUT) eagle.app.v6.text.bin
  319. $(Q) $(OBJCP) --only-section .data -O binary $(USER1_OUT) eagle.app.v6.data.bin
  320. $(Q) $(OBJCP) --only-section .rodata -O binary $(USER1_OUT) eagle.app.v6.rodata.bin
  321. $(Q) $(OBJCP) --only-section .irom0.text -O binary $(USER1_OUT) eagle.app.v6.irom0text.bin
  322. $(Q) $(ELF_SIZE) -A $(USER1_OUT) |grep -v " 0$$" |grep .
  323. $(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python2 $(APPGEN_TOOL) $(USER1_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE) 0 >/dev/null
  324. $(Q) rm -f eagle.app.v6.*.bin
  325. $(Q) mv eagle.app.flash.bin $@
  326. @echo " user1.bin uses $$(stat -c '%s' $@) bytes of" $(ESP_FLASH_MAX) "available"
  327. $(Q) if [ $$(stat -c '%s' $@) -gt $$(( $(ESP_FLASH_MAX) )) ]; then echo "$@ too big!"; false; fi
  328. $(FW_BASE)/user2.bin: $(USER2_OUT) $(FW_BASE)
  329. $(Q) $(OBJCP) --only-section .text -O binary $(USER2_OUT) eagle.app.v6.text.bin
  330. $(Q) $(OBJCP) --only-section .data -O binary $(USER2_OUT) eagle.app.v6.data.bin
  331. $(Q) $(OBJCP) --only-section .rodata -O binary $(USER2_OUT) eagle.app.v6.rodata.bin
  332. $(Q) $(OBJCP) --only-section .irom0.text -O binary $(USER2_OUT) eagle.app.v6.irom0text.bin
  333. $(Q) COMPILE=gcc PATH=$(XTENSA_TOOLS_ROOT):$(PATH) python2 $(APPGEN_TOOL) $(USER2_OUT) 2 $(ESP_FLASH_MODE) $(ESP_FLASH_FREQ_DIV) $(ESP_SPI_SIZE) 1 >/dev/null
  334. $(Q) rm -f eagle.app.v6.*.bin
  335. $(Q) mv eagle.app.flash.bin $@
  336. $(Q) if [ $$(stat -c '%s' $@) -gt $$(( $(ESP_FLASH_MAX) )) ]; then echo "$@ too big!"; false; fi
  337. $(APP_AR): $(OBJ)
  338. $(vecho) "AR $@"
  339. $(Q) $(AR) cru $@ $^
  340. checkdirs: $(BUILD_DIR)
  341. $(BUILD_DIR):
  342. $(Q) mkdir -p $@
  343. wiflash: all
  344. ./wiflash $(ESP_HOSTNAME) $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin
  345. baseflash: all
  346. $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash 0x01000 $(FW_BASE)/user1.bin
  347. flash: all
  348. $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
  349. 0x00000 "$(SDK_BASE)/bin/boot_v1.6.bin" 0x01000 $(FW_BASE)/user1.bin \
  350. $(ET_BLANK) $(SDK_BASE)/bin/blank.bin
  351. fullflash: all
  352. $(Q) $(ESPTOOL) --port $(ESPPORT) --baud $(ESPBAUD) write_flash -fs $(ET_FS) -ff $(ET_FF) \
  353. 0x00000 "$(SDK_BASE)/bin/boot_v1.6.bin" 0x01000 $(FW_BASE)/user1.bin \
  354. $(ET_INIT_DATA) $(SDK_BASE)/bin/esp_init_data_default.bin $(ET_BLANK) $(SDK_BASE)/bin/blank.bin
  355. tools/$(HTML_COMPRESSOR):
  356. $(Q) echo "The jar files in the tools dir are missing, they should be in the source repo"
  357. $(Q) echo "The following commands can be used to fetch them, but the URLs have changed..."
  358. $(Q) echo mkdir -p tools
  359. $(Q) echo "cd tools; wget --no-check-certificate https://github.com/yui/yuicompressor/releases/download/v2.4.8/$(YUI_COMPRESSOR) -O $(YUI_COMPRESSOR)"
  360. $(Q) echo "cd tools; wget --no-check-certificate https://htmlcompressor.googlecode.com/files/$(HTML_COMPRESSOR) -O $(HTML_COMPRESSOR)"
  361. ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
  362. $(BUILD_BASE)/espfs_img.o: tools/$(HTML_COMPRESSOR)
  363. endif
  364. $(BUILD_BASE)/espfs_img.o: html/ html/wifi/ html/text/ espfs/mkespfsimage/mkespfsimage
  365. # $(Q) rm -rf html_compressed; mkdir html_compressed; mkdir html_compressed/wifi; mkdir html_compressed/text;mkdir html_compressed/fonts;
  366. $(Q) rm -rf html_compressed; mkdir html_compressed; mkdir html_compressed/fonts;
  367. $(Q) cp -r html/*.ico html_compressed;
  368. $(Q) cp -r html/*.css html_compressed;
  369. $(Q) cp -r html/*.js html_compressed;
  370. # $(Q) cp -r html/wifi/*.js html_compressed/wifi;
  371. $(Q) cp -r html/Lato-Embed.ttf html_compressed/fonts;
  372. ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
  373. $(Q) echo "Compressing assets with htmlcompressor. This may take a while..."
  374. $(Q) java -jar tools/$(HTML_COMPRESSOR) \
  375. -t html --remove-surrounding-spaces max --remove-quotes --remove-intertag-spaces \
  376. -o $(abspath ./html_compressed)/ \
  377. $(HTML_PATH)head- \
  378. $(HTML_PATH)*.html
  379. # $(Q) java -jar tools/$(HTML_COMPRESSOR) \
  380. # -t html --remove-surrounding-spaces max --remove-quotes --remove-intertag-spaces \
  381. # -o $(abspath ./html_compressed)/text/ \
  382. # $(TEXT_PATH)*.html
  383. # $(Q) java -jar tools/$(HTML_COMPRESSOR) \
  384. # -t html --remove-surrounding-spaces max --remove-quotes --remove-intertag-spaces \
  385. # -o $(abspath ./html_compressed)/wifi/ \
  386. # $(WIFI_PATH)*.html
  387. $(Q) echo "Compressing assets with yui-compressor. This may take a while..."
  388. $(Q) for file in `find html_compressed -type f -name "*.js"`; do \
  389. java -jar tools/$(YUI_COMPRESSOR) $$file --line-break 0 -o $$file; \
  390. done
  391. $(Q) for file in `find html_compressed -type f -name "*.css"`; do \
  392. java -jar tools/$(YUI_COMPRESSOR) $$file -o $$file; \
  393. done
  394. else
  395. $(Q) cp -r html/head- html_compressed;
  396. $(Q) cp -r html/*.html html_compressed;
  397. $(Q) cp -r html/text/*.html html_compressed/text;
  398. # $(Q) cp -r html/wifi/*.html html_compressed/wifi;
  399. endif
  400. ifeq (,$(findstring mqtt,$(MODULES)))
  401. $(Q) rm -rf html_compressed/mqtt.html
  402. $(Q) rm -rf html_compressed/mqtt.js
  403. endif
  404. $(Q) for file in `find html_compressed -type f -name "*.htm*"`; do \
  405. cat html_compressed/head- $$file >$${file}-; \
  406. mv $$file- $$file; \
  407. done
  408. $(Q) rm html_compressed/head-
  409. $(Q) cd html_compressed; find . \! -name \*- | ../espfs/mkespfsimage/mkespfsimage > ../build/espfs.img; cd ..;
  410. $(Q) ls -sl build/espfs.img
  411. $(Q) cd build; $(OBJCP) -I binary -O elf32-xtensa-le -B xtensa --rename-section .data=.espfs \
  412. espfs.img espfs_img.o; cd ..
  413. # edit the loader script to add the espfs section to the end of irom with a 4 byte alignment.
  414. # we also adjust the sizes of the segments 'cause we need more irom0
  415. build/eagle.esphttpd1.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.1024.app1.ld
  416. $(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
  417. -e '/^ irom0_0_seg/ s/6B000/7C000/' \
  418. $(SDK_LDDIR)/eagle.app.v6.new.1024.app1.ld >$@
  419. build/eagle.esphttpd2.v6.ld: $(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld
  420. $(Q) sed -e '/\.irom\.text/{' -e 'a . = ALIGN (4);' -e 'a *(.espfs)' -e '}' \
  421. -e '/^ irom0_0_seg/ s/6B000/7C000/' \
  422. $(SDK_LDDIR)/eagle.app.v6.new.1024.app2.ld >$@
  423. espfs/mkespfsimage/mkespfsimage: espfs/mkespfsimage/
  424. $(Q) $(MAKE) -C espfs/mkespfsimage GZIP_COMPRESSION="$(GZIP_COMPRESSION)"
  425. release: all
  426. $(Q) rm -rf release; mkdir -p release/meta-id-$(VERSION)
  427. $(Q) egrep -a 'meta-id [a-z0-9.]+ - 201' $(FW_BASE)/user1.bin | cut -b 1-80
  428. $(Q) egrep -a 'meta-id [a-z0-9.]+ - 201' $(FW_BASE)/user2.bin | cut -b 1-80
  429. $(Q) cp $(FW_BASE)/user1.bin $(FW_BASE)/user2.bin $(SDK_BASE)/bin/blank.bin \
  430. "$(SDK_BASE)/bin/boot_v1.7.bin" "$(SDK_BASE)/bin/esp_init_data_default.bin" \
  431. wiflash avrflash megaflash release/meta-id-$(VERSION)
  432. $(Q) tar zcf meta-id-$(VERSION).tgz -C release meta-id-$(VERSION)
  433. $(Q) echo "Release file: meta-id-$(VERSION).tgz"
  434. $(Q) rm -rf release
  435. docker:
  436. $(Q) docker build -t jeelabs/meta-id .
  437. clean:
  438. $(Q) rm -f $(APP_AR)
  439. $(Q) rm -f $(TARGET_OUT)
  440. $(Q) find $(BUILD_BASE) -type f | xargs rm -f
  441. $(Q) make -C espfs/mkespfsimage/ clean
  442. $(Q) rm -rf $(FW_BASE)
  443. $(Q) rm -f webpages.espfs
  444. ifeq ("$(COMPRESS_W_HTMLCOMPRESSOR)","yes")
  445. $(Q) rm -rf html_compressed
  446. endif
  447. $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
  448. depend:
  449. makedepend -p${BUILD_BASE}/ -Y -- $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) -I${XTENSA_TOOLS_ROOT}../xtensa-lx106-elf/include -I${XTENSA_TOOLS_ROOT}../lib/gcc/xtensa-lx106-elf/4.8.2/include -- */*.c
  450. # Rebuild version at least at every Makefile change
  451. ${BUILD_BASE}/meta-id/main.o: Makefile
  452. # DO NOT DELETE