Makefile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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
  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 driver
  39. SDK_INC = include include/json
  40. # Output directors to store intermediate compiled files
  41. # relative to the project directory
  42. BUILD_BASE = build
  43. FIRMWARE_BASE = firmware
  44. # Opensdk patches stdint.h when compiled with an internal SDK. If you run into compile problems pertaining to
  45. # redefinition of int types, try setting this to 'yes'.
  46. USE_OPENSDK ?= yes
  47. DATETIME := $(shell date "+%Y-%b-%d_%H:%M:%S_%Z")
  48. # select which tools to use as compiler, librarian and linker
  49. CC := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
  50. AR := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-ar
  51. LD := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-gcc
  52. OBJCOPY := $(XTENSA_TOOLS_ROOT)xtensa-lx106-elf-objcopy
  53. ####
  54. #### no user configurable options below here
  55. ####
  56. SRC_DIR := $(USER_MODULES)
  57. SRC_DIR_LIB := $(LIB_MODULES)
  58. BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(USER_MODULES))
  59. INCDIR := $(addprefix -I,$(SRC_DIR))
  60. EXTRA_INCDIR := $(addprefix -I,$(USER_INC))
  61. MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
  62. SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
  63. SDK_LIBS := $(addprefix -l,$(SDK_LIBS))
  64. SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INC))
  65. SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
  66. SRC_LIB := $(foreach sdir,$(SRC_DIR_LIB),$(wildcard $(sdir)/*.c))
  67. ASMSRC = $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.S))
  68. ASMSRC_LIB = $(foreach sdir,$(SRC_DIR_LIB),$(wildcard $(sdir)/*.S))
  69. OBJ = $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
  70. OBJ_LIB = $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC_LIB))
  71. OBJ += $(patsubst %.S,$(BUILD_BASE)/%.o,$(ASMSRC))
  72. OBJ_LIB += $(patsubst %.c,$(BUILD_BASE)/%.o,$(ASMSRC_LIB))
  73. APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET).a)
  74. TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
  75. # compiler flags using during compilation of source files
  76. CFLAGS = -g \
  77. -Wpointer-arith \
  78. -Wundef \
  79. -Wl,-EL \
  80. -Wno-implicit-function-declaration \
  81. -fno-inline-functions \
  82. -nostdlib \
  83. -mlongcalls \
  84. -mtext-section-literals \
  85. -ffunction-sections \
  86. -fdata-sections \
  87. -fno-builtin-printf\
  88. -DICACHE_FLASH \
  89. -DBUID_TIME=\"$(DATETIME)\"
  90. # linker flags used to generate the main object file
  91. LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
  92. ifeq ($(FLAVOR),debug)
  93. LDFLAGS += -g -O2
  94. CFLAGS += -DMQTT_DEBUG_ON -DDEBUG_ON
  95. endif
  96. ifeq ($(FLAVOR),release)
  97. LDFLAGS += -g -O0
  98. endif
  99. V ?= $(VERBOSE)
  100. ifeq ("$(V)","yes")
  101. Q :=
  102. vecho := @true
  103. else
  104. Q := @
  105. vecho := @echo
  106. endif
  107. ifeq ("$(USE_OPENSDK)","yes")
  108. CFLAGS += -DUSE_OPENSDK
  109. else
  110. CFLAGS += -D_STDINT_Hlocal
  111. endif
  112. ifneq ("$(wildcard $(THISDIR)/include/user_config.local.h)","")
  113. CFLAGS += -DLOCAL_CONFIG_AVAILABLE
  114. endif
  115. ESPTOOL_OPTS=--port $(ESPPORT) --baud $(ESPBAUD)
  116. #32m
  117. ESP_INIT_DATA_DEFAULT_ADDR = 0xfc000
  118. ifeq ("$(ESP_SIZE)","16m")
  119. ESP_INIT_DATA_DEFAULT_ADDR = 0x1fc000
  120. else ifeq ("$(ESP_SIZE)","32m")
  121. ESP_INIT_DATA_DEFAULT_ADDR = 0x3fc000
  122. endif
  123. ifeq ("$(OTA)","espboot")
  124. OUTPUT := $(addprefix $(FIRMWARE_BASE)/,$(TARGET)-0x2000.bin)
  125. ESPTOOL_WRITE = write_flash --flash_freq $(ESP_FREQ) --flash_mode $(ESP_MODE) --flash_size $(ESP_SIZE) \
  126. 0x00000 $(OTA_BOOTLOADER_PATH) \
  127. $(OTA_APP_ADDR) $(OUTPUT) \
  128. $(ESP_INIT_DATA_DEFAULT_ADDR) $(SDK_BASE)/bin/esp_init_data_default.bin
  129. ESPTOOL_FLASHDEF=--version=2
  130. LD_SCRIPT = -Tld/with-espboot-flash-at-0x2000-size-1M.ld
  131. else
  132. OUTPUT := $(addprefix $(FIRMWARE_BASE)/,$(TARGET))
  133. ESPTOOL_WRITE = write_flash --flash_freq $(ESP_FREQ) --flash_mode $(ESP_MODE) --flash_size $(ESP_SIZE) \
  134. 0x00000 $(OUTPUT)0x00000.bin \
  135. 0x10000 $(OUTPUT)0x10000.bin \
  136. $(ESP_INIT_DATA_DEFAULT_ADDR) $(SDK_BASE)/bin/esp_init_data_default.bin
  137. ESPTOOL_FLASHDEF=
  138. #LD_SCRIPT = -T$(SDK_BASE)/ld/eagle.app.v6.new.2048.ld
  139. LD_SCRIPT = -T$(SDK_BASE)/ld/eagle.app.v6.ld
  140. endif
  141. OUTPUT_LIB := $(addprefix $(FIRMWARE_BASE)/,$(TARGET_LIB))
  142. vpath %.c $(SRC_DIR)
  143. define compile-objects
  144. $1/%.o: %.c
  145. $(vecho) "CC $$<"
  146. $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
  147. endef
  148. .PHONY: all lib checkdirs clean
  149. all: touch checkdirs $(OUTPUT)
  150. lib: checkdirs $(OUTPUT_LIB)
  151. touch:
  152. $(vecho) "-------------------------------------------\n"
  153. $(vecho) "BUID TIME $(DATETIME)"
  154. $(vecho) "-------------------------------------------\n"
  155. $(Q) touch user/user_main.c
  156. checkdirs: $(BUILD_DIR) $(FIRMWARE_BASE)
  157. $(OUTPUT): $(TARGET_OUT)
  158. $(vecho) "FW $@"
  159. $(Q) $(ESPTOOL) elf2image $(ESPTOOL_FLASHDEF) $< -o $(OUTPUT)
  160. $(OUTPUT_LIB): $(OBJ_LIB)
  161. $(vecho) "AR $@"
  162. $(Q) $(AR) cru $@ $^
  163. $(BUILD_DIR):
  164. $(Q) mkdir -p $@
  165. $(FIRMWARE_BASE):
  166. $(Q) mkdir -p $@
  167. $(TARGET_OUT): $(APP_AR)
  168. $(vecho) "LD $@"
  169. $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(SDK_LIBS) $(APP_AR) -Wl,--end-group -o $@
  170. $(APP_AR): $(OBJ)
  171. $(vecho) "AR $@"
  172. $(Q) $(AR) cru $@ $^
  173. flash:
  174. $(ESPTOOL) $(ESPTOOL_OPTS) $(ESPTOOL_WRITE)
  175. wipe:
  176. $(ESPTOOL) $(ESPTOOL_OPTS) erase_flash
  177. fast: all flash openport
  178. openport:
  179. $(vecho) "After flash, terminal will enter serial port screen"
  180. $(vecho) "Please exit with command:"
  181. $(vecho) "\033[0;31m" "Ctrl + A + k" "\033[0m"
  182. #@read -p "Press any key to continue... " -n1 -s
  183. @screen $(ESPPORT) 115200
  184. clean:
  185. $(Q) rm -rf $(BUILD_DIR)
  186. $(Q) rm -rf $(FIRMWARE_BASE)
  187. $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))