Makefile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. # none sdkota espboot rboot
  2. OTA ?= none
  3. OTA_APP_ADDR = 0x2000
  4. OTA_BOOTLOADER_PATH = ../esp-bootloader/firmware/espboot.bin
  5. THISDIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
  6. # Base directory for the compiler. Needs a / at the end; if not set it'll use the tools that are in
  7. # the PATH.
  8. XTENSA_TOOLS_ROOT ?=
  9. # base directory of the ESP8266 SDK package, absolute
  10. SDK_BASE ?= /home/curiousmuch/ideasX-repositories/esp8266/esp-open-sdk/sdk
  11. #Esptool.py path and port
  12. ESPTOOL ?= /home/curiousmuch/ideasX-repositories/esp8266/esp-open-sdk/esptool/esptool.py
  13. ESPPORT ?= /dev/ttyUSB0
  14. #ESPPORT ?= /dev/tty.wchusbserial1410
  15. #ESPDELAY indicates seconds to wait between flashing the two binary images
  16. ESPDELAY ?= 3
  17. #ESPBAUD ?= 115200
  18. ESPBAUD ?= 460800
  19. # 40m 26m 20m 80m
  20. ESP_FREQ = 40m
  21. # qio qout dio dout
  22. ESP_MODE = dio
  23. #4m 2m 8m 16m 32m
  24. ESP_SIZE = 32m
  25. VERBOSE = yes
  26. FLAVOR = debug
  27. # name for the target project
  28. TARGET ?= ideasX_
  29. # name for the target when compiling as library
  30. TARGET_LIB ?= ideasX.a
  31. # which modules (subdirectories) of the project to include in compiling
  32. USER_MODULES = user driver gdbstub log hal interface include mqtt
  33. USER_INC = include
  34. USER_LIB =
  35. # which modules (subdirectories) of the project to include when compiling as library
  36. LIB_MODULES = mqtt
  37. SDK_LIBDIR = lib
  38. SDK_LIBS = c gcc phy pp net80211 wpa main lwip crypto ssl json
  39. #SDK_LIBS = c gcc phy pp net80211 wpa main lwip crypto ssl json driver
  40. SDK_INC = include include/json
  41. # Output directors to store intermediate compiled files
  42. # relative to the project directory
  43. BUILD_BASE = build
  44. FIRMWARE_BASE = firmware
  45. # Opensdk patches stdint.h when compiled with an internal SDK. If you run into compile problems pertaining to
  46. # redefinition of int types, try setting this to 'yes'.
  47. USE_OPENSDK ?= yes
  48. DATETIME := $(shell date "+%Y-%b-%d_%H:%M:%S_%Z")
  49. # select which tools to use as compiler, librarian and linker
  50. CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
  51. AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar
  52. LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
  53. OBJCOPY := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
  54. ####
  55. #### no user configurable options below here
  56. ####
  57. SRC_DIR := $(USER_MODULES)
  58. SRC_DIR_LIB := $(LIB_MODULES)
  59. BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(USER_MODULES))
  60. INCDIR := $(addprefix -I,$(SRC_DIR))
  61. EXTRA_INCDIR := $(addprefix -I,$(USER_INC))
  62. MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
  63. SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
  64. SDK_LIBS := $(addprefix -l,$(SDK_LIBS))
  65. SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INC))
  66. SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
  67. SRC_LIB := $(foreach sdir,$(SRC_DIR_LIB),$(wildcard $(sdir)/*.c))
  68. ASMSRC = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.S))
  69. ASMSRC_LIB = $(foreach sdir,$(SRC_DIR_LIB),$(wildcard $(sdir)/*.S))
  70. OBJ = $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
  71. OBJ_LIB = $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC_LIB))
  72. OBJ += $(patsubst %.S,$(BUILD_BASE)/%.o,$(ASMSRC))
  73. OBJ_LIB += $(patsubst %.c,$(BUILD_BASE)/%.o,$(ASMSRC_LIB))
  74. APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET).a)
  75. TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
  76. # compiler flags using during compilation of source files
  77. CFLAGS = -g \
  78. -Wpointer-arith \
  79. -Wundef \
  80. -Wl,-EL \
  81. -Wno-implicit-function-declaration \
  82. -fno-inline-functions \
  83. -nostdlib \
  84. -mlongcalls \
  85. -mtext-section-literals \
  86. -ffunction-sections \
  87. -fdata-sections \
  88. -fno-builtin-printf\
  89. -DICACHE_FLASH \
  90. -DBUILD_TIME=\"$(DATETIME)\"
  91. # linker flags used to generate the main object file
  92. LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
  93. ifeq ($(FLAVOR),debug)
  94. LDFLAGS += -g -O2
  95. CFLAGS += -DMQTT_DEBUG_ON -DDEBUG_ON
  96. endif
  97. ifeq ($(FLAVOR),release)
  98. LDFLAGS += -g -O0
  99. endif
  100. V ?= $(VERBOSE)
  101. ifeq ("$(V)","yes")
  102. Q :=
  103. vecho := @true
  104. else
  105. Q := @
  106. vecho := @echo
  107. endif
  108. ifeq ("$(USE_OPENSDK)","yes")
  109. CFLAGS += -DUSE_OPENSDK
  110. else
  111. CFLAGS += -D_STDINT_Hlocal
  112. endif
  113. #ifneq ("$(wildcard $(THISDIR)/include/user_config.local.h)","")
  114. #CFLAGS += -DLOCAL_CONFIG_AVAILABLE
  115. #endif
  116. ESPTOOL_OPTS=--port $(ESPPORT) --baud $(ESPBAUD)
  117. #32m
  118. ESP_INIT_DATA_DEFAULT_ADDR = 0xfc000
  119. ifeq ("$(ESP_SIZE)","16m")
  120. ESP_INIT_DATA_DEFAULT_ADDR = 0x1fc000
  121. else ifeq ("$(ESP_SIZE)","32m")
  122. ESP_INIT_DATA_DEFAULT_ADDR = 0x3fc000
  123. endif
  124. ifeq ("$(OTA)","espboot")
  125. OUTPUT := $(addprefix $(FIRMWARE_BASE)/,$(TARGET)-0x2000.bin)
  126. ESPTOOL_WRITE = write_flash --flash_freq $(ESP_FREQ) --flash_mode $(ESP_MODE) --flash_size $(ESP_SIZE) \
  127. 0x00000 $(OTA_BOOTLOADER_PATH) \
  128. $(OTA_APP_ADDR) $(OUTPUT) \
  129. $(ESP_INIT_DATA_DEFAULT_ADDR) $(SDK_BASE)/bin/esp_init_data_default.bin
  130. ESPTOOL_FLASHDEF=--version=2
  131. LD_SCRIPT = -Tld/with-espboot-flash-at-0x2000-size-1M.ld
  132. else
  133. OUTPUT := $(addprefix $(FIRMWARE_BASE)/,$(TARGET))
  134. ESPTOOL_WRITE = write_flash --flash_freq $(ESP_FREQ) --flash_mode $(ESP_MODE) --flash_size $(ESP_SIZE) \
  135. 0x00000 $(OUTPUT)0x00000.bin \
  136. 0x10000 $(OUTPUT)0x10000.bin \
  137. $(ESP_INIT_DATA_DEFAULT_ADDR) $(SDK_BASE)/bin/esp_init_data_default.bin
  138. ESPTOOL_FLASHDEF=
  139. #LD_SCRIPT = -T$(SDK_BASE)/ld/eagle.app.v6.new.2048.ld
  140. LD_SCRIPT = -T$(SDK_BASE)/ld/eagle.app.v6.ld
  141. endif
  142. OUTPUT_LIB := $(addprefix $(FIRMWARE_BASE)/,$(TARGET_LIB))
  143. vpath %.c $(SRC_DIR)
  144. define compile-objects
  145. $1/%.o: %.c
  146. $(vecho) "CC $$<"
  147. $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
  148. endef
  149. .PHONY: all lib checkdirs clean
  150. all: touch checkdirs $(OUTPUT)
  151. lib: checkdirs $(OUTPUT_LIB)
  152. touch:
  153. $(vecho) "-------------------------------------------\n"
  154. $(vecho) "BUID TIME $(DATETIME)"
  155. $(vecho) "-------------------------------------------\n"
  156. $(Q) touch user/user_main.c
  157. checkdirs: $(BUILD_DIR) $(FIRMWARE_BASE)
  158. $(OUTPUT): $(TARGET_OUT)
  159. $(vecho) "FW $@"
  160. $(Q) python2 $(ESPTOOL) elf2image $(ESPTOOL_FLASHDEF) $< -o $(OUTPUT)
  161. $(OUTPUT_LIB): $(OBJ_LIB)
  162. $(vecho) "AR $@"
  163. $(Q) $(AR) cru $@ $^
  164. $(BUILD_DIR):
  165. $(Q) mkdir -p $@
  166. $(FIRMWARE_BASE):
  167. $(Q) mkdir -p $@
  168. $(TARGET_OUT): $(APP_AR)
  169. $(vecho) "LD $@"
  170. $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(SDK_LIBS) $(APP_AR) -Wl,--end-group -o $@
  171. $(APP_AR): $(OBJ)
  172. $(vecho) "AR $@"
  173. $(Q) $(AR) cru $@ $^
  174. flash:
  175. python2 $(ESPTOOL) $(ESPTOOL_OPTS) $(ESPTOOL_WRITE)
  176. wipe:
  177. python2 $(ESPTOOL) $(ESPTOOL_OPTS) erase_flash
  178. fast: all flash openport
  179. openport:
  180. $(vecho) "After flash, terminal will enter serial port screen"
  181. $(vecho) "Please exit with command:"
  182. $(vecho) "\033[0;31m" "Ctrl + A + k" "\033[0m"
  183. #@read -p "Press any key to continue... " -n1 -s
  184. @screen $(ESPPORT) 115200
  185. clean:
  186. $(Q) rm -rf $(BUILD_DIR)
  187. $(Q) rm -rf $(FIRMWARE_BASE)
  188. $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))