Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 KB | None | 0 0
  1. #############################################################
  2. #
  3. # Root Level Makefile
  4. #
  5. # Version 2.0
  6. #
  7. # (c) by CHERTS <sleuthhound@gmail.com>
  8. #
  9. #############################################################
  10.  
  11. BUILD_BASE = build
  12. FW_BASE = firmware
  13.  
  14. # Base directory for the compiler
  15. XTENSA_TOOLS_ROOT ?= c:/Espressif/xtensa-lx106-elf/bin
  16.  
  17. # base directory of the ESP8266 SDK package, absolute
  18. SDK_BASE ?= c:/Espressif/ESP8266_SDK
  19. SDK_TOOLS ?= c:/Espressif/utils
  20.  
  21. # esptool path and port
  22. ESPTOOL ?= $(SDK_TOOLS)/esptool.exe
  23. ESPPORT ?= COM3
  24. # Baud rate for programmer
  25. BAUD ?= 115200
  26.  
  27. # SPI_SPEED = 40, 26, 20, 80
  28. SPI_SPEED ?= 40
  29. # SPI_MODE: qio, qout, dio, dout
  30. SPI_MODE ?= dio
  31. # SPI_SIZE_MAP
  32. # 0 : 512 KB (256 KB + 256 KB)
  33. # 1 : 256 KB
  34. # 2 : 1024 KB (512 KB + 512 KB)
  35. # 3 : 2048 KB (512 KB + 512 KB)
  36. # 4 : 4096 KB (512 KB + 512 KB)
  37. # 5 : 2048 KB (1024 KB + 1024 KB)
  38. # 6 : 4096 KB (1024 KB + 1024 KB)
  39. SPI_SIZE_MAP ?= 6
  40.  
  41. ifeq ($(SPI_SPEED), 26.7)
  42. freqdiv = 1
  43. flashimageoptions = -ff 26m
  44. else
  45. ifeq ($(SPI_SPEED), 20)
  46. freqdiv = 2
  47. flashimageoptions = -ff 20m
  48. else
  49. ifeq ($(SPI_SPEED), 80)
  50. freqdiv = 15
  51. flashimageoptions = -ff 80m
  52. else
  53. freqdiv = 0
  54. flashimageoptions = -ff 40m
  55. endif
  56. endif
  57. endif
  58.  
  59. ifeq ($(SPI_MODE), QOUT)
  60. mode = 1
  61. flashimageoptions += -fm qout
  62. else
  63. ifeq ($(SPI_MODE), DIO)
  64. mode = 2
  65. flashimageoptions += -fm dio
  66. else
  67. ifeq ($(SPI_MODE), DOUT)
  68. mode = 3
  69. flashimageoptions += -fm dout
  70. else
  71. mode = 0
  72. flashimageoptions += -fm qio
  73. endif
  74. endif
  75. endif
  76.  
  77. ifeq ($(SPI_SIZE_MAP), 1)
  78. size_map = 1
  79. flash = 256
  80. flashimageoptions += -fs 2m
  81. else
  82. ifeq ($(SPI_SIZE_MAP), 2)
  83. size_map = 2
  84. flash = 1024
  85. flashimageoptions += -fs 8m
  86. else
  87. ifeq ($(SPI_SIZE_MAP), 3)
  88. size_map = 3
  89. flash = 2048
  90. flashimageoptions += -fs 16m
  91. else
  92. ifeq ($(SPI_SIZE_MAP), 4)
  93. size_map = 4
  94. flash = 4096
  95. flashimageoptions += -fs 32m
  96. else
  97. ifeq ($(SPI_SIZE_MAP), 5)
  98. size_map = 5
  99. flash = 2048
  100. flashimageoptions += -fs 16m
  101. else
  102. ifeq ($(SPI_SIZE_MAP), 6)
  103. size_map = 6
  104. flash = 4096
  105. flashimageoptions += -fs 32m
  106. else
  107. size_map = 0
  108. flash = 512
  109. flashimageoptions += -fs 4m
  110. endif
  111. endif
  112. endif
  113. endif
  114. endif
  115. endif
  116.  
  117. # name for the target project
  118. TARGET = app
  119.  
  120. # which modules (subdirectories) of the project to include in compiling
  121. MODULES = driver user
  122. EXTRA_INCDIR = include $(SDK_BASE)/../extra/include
  123.  
  124. # libraries used in this project, mainly provided by the SDK
  125. LIBS = c gcc hal phy pp net80211 lwip wpa main
  126.  
  127. # compiler flags using during compilation of source files
  128. CFLAGS = -Os -g -O2 -std=gnu90 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -mno-serialize-volatile -D__ets__ -DICACHE_FLASH
  129.  
  130. # linker flags used to generate the main object file
  131. LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
  132.  
  133. # linker script used for the above linkier step
  134. LD_SCRIPT = eagle.app.v6.ld
  135.  
  136. # various paths from the SDK used in this project
  137. SDK_LIBDIR = lib
  138. SDK_LDDIR = ld
  139. SDK_INCDIR = include include/json
  140.  
  141. # select which tools to use as compiler, librarian and linker
  142. CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
  143. AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar
  144. LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
  145. OBJCOPY := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objcopy
  146. OBJDUMP := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump
  147.  
  148. # no user configurable options below here
  149. SRC_DIR := $(MODULES)
  150. BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))
  151. SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
  152. SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
  153. SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
  154. OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
  155. LIBS := $(addprefix -l,$(LIBS))
  156. APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
  157. TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
  158.  
  159. LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT))
  160.  
  161. INCDIR := $(addprefix -I,$(SRC_DIR))
  162. EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR))
  163. MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
  164.  
  165. V ?= $(VERBOSE)
  166. ifeq ("$(V)","1")
  167. Q :=
  168. vecho := @true
  169. else
  170. Q := @
  171. vecho := @echo
  172. endif
  173.  
  174. vpath %.c $(SRC_DIR)
  175.  
  176. define compile-objects
  177. $1/%.o: %.c
  178. $(vecho) "CC $$<"
  179. $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
  180. endef
  181.  
  182. .PHONY: all checkdirs clean flash flashinit flashonefile rebuild
  183.  
  184. all: checkdirs $(TARGET_OUT)
  185.  
  186. $(TARGET_OUT): $(APP_AR)
  187. $(vecho) "LD $@"
  188. $(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
  189. $(vecho) "------------------------------------------------------------------------------"
  190. $(vecho) "Section info:"
  191. $(Q) $(OBJDUMP) -h -j .data -j .rodata -j .bss -j .text -j .irom0.text $@
  192. $(vecho) "------------------------------------------------------------------------------"
  193. $(Q) $(ESPTOOL) elf2image $(TARGET_OUT) -o$(FW_BASE)/ $(flashimageoptions)
  194. $(vecho) "------------------------------------------------------------------------------"
  195. $(vecho) "Generate 0x00000.bin and 0x40000.bin successully in folder $(FW_BASE)."
  196. $(vecho) "0x00000.bin-------->0x00000"
  197. $(vecho) "0x40000.bin-------->0x40000"
  198. $(vecho) "Done"
  199.  
  200. $(APP_AR): $(OBJ)
  201. $(vecho) "AR $@"
  202. $(Q) $(AR) cru $@ $^
  203.  
  204. checkdirs: $(BUILD_DIR) $(FW_BASE)
  205.  
  206. $(BUILD_DIR):
  207. $(Q) mkdir -p $@
  208.  
  209. $(FW_BASE):
  210. $(Q) mkdir -p $@
  211.  
  212. flashonefile: all
  213. $(SDK_TOOLS)/gen_flashbin.exe $(FW_BASE)/0x00000.bin $(FW_BASE)/0x40000.bin 0x40000
  214. $(Q) mv eagle.app.flash.bin $(FW_BASE)/
  215. $(vecho) "Generate eagle.app.flash.bin successully in folder $(FW_BASE)."
  216. $(vecho) "eagle.app.flash.bin-------->0x00000"
  217. $(ESPTOOL) -p $(ESPPORT) -b $(BAUD) write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/eagle.app.flash.bin
  218.  
  219. flash: all
  220. $(ESPTOOL) -p $(ESPPORT) -b $(BAUD) write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/0x00000.bin 0x40000 $(FW_BASE)/0x40000.bin
  221.  
  222. # ===============================================================
  223. # From http://bbs.espressif.com/viewtopic.php?f=10&t=305
  224. # master-device-key.bin is only need if using espressive services
  225. # master_device_key.bin 0x3e000 is not used , write blank
  226. # See 2A-ESP8266__IOT_SDK_User_Manual__EN_v1.1.0.pdf
  227. # http://bbs.espressif.com/download/file.php?id=532
  228. #
  229. # System parameter area is the last 16KB of flash
  230. # 512KB flash - system parameter area starts from 0x7C000
  231. # download blank.bin to 0x7E000 as initialization.
  232. # 1024KB flash - system parameter area starts from 0xFC000
  233. # download blank.bin to 0xFE000 as initialization.
  234. # 2048KB flash - system parameter area starts from 0x1FC000
  235. # download blank.bin to 0x1FE000 as initialization.
  236. # 4096KB flash - system parameter area starts from 0x3FC000
  237. # download blank.bin to 0x3FE000 as initialization.
  238. # ===============================================================
  239.  
  240. # FLASH SIZE
  241. flashinit:
  242. $(vecho) "Flash init data:"
  243. $(vecho) "Default config (Clear SDK settings):"
  244. $(vecho) "blank.bin-------->0x3e000"
  245. $(vecho) "blank.bin-------->0x3fc000"
  246. $(vecho) "esp_init_data_default.bin-------->0x3fc000"
  247. $(ESPTOOL) -p $(ESPPORT) write_flash $(flashimageoptions) \
  248. 0x3e000 $(SDK_BASE)/bin/blank.bin \
  249. 0x3fc000 $(SDK_BASE)/bin/esp_init_data_default.bin \
  250. 0x3fe000 $(SDK_BASE)/bin/blank.bin
  251.  
  252. rebuild: clean all
  253.  
  254. clean:
  255. $(Q) rm -f $(APP_AR)
  256. $(Q) rm -f $(TARGET_OUT)
  257. $(Q) rm -rf $(BUILD_DIR)
  258. $(Q) rm -rf $(BUILD_BASE)
  259. $(Q) rm -rf $(FW_BASE)
  260.  
  261. $(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement