Makefile 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. include ../../py/mkenv.mk
  2. # qstr definitions (must come before including py.mk)
  3. QSTR_DEFS = qstrdefsport.h
  4. MICROPY_PY_USSL = 0
  5. MICROPY_SSL_AXTLS = 0
  6. MICROPY_FATFS = 1
  7. MICROPY_PY_BTREE = 1
  8. #FROZEN_DIR = scripts
  9. FROZEN_MPY_DIR = modules
  10. # include py core make definitions
  11. include $(TOP)/py/py.mk
  12. PORT ?= /dev/ttyUSB0
  13. BAUD ?= 460800
  14. FLASH_MODE ?= dio
  15. FLASH_FREQ ?= 40m
  16. FLASH_SIZE ?= 4MB
  17. CROSS_COMPILE ?= xtensa-esp32-elf-
  18. ESPIDF_SUPHASH := 9a55b42f0841b3d38a61089b1dda4bf28135decd
  19. # paths to ESP IDF and its components
  20. ifeq ($(ESPIDF),)
  21. ifneq ($(IDF_PATH),)
  22. ESPIDF = $(IDF_PATH)
  23. else
  24. $(info The ESPIDF variable has not been set, please set it to the root of the esp-idf repository.)
  25. $(info See README.md for installation instructions.)
  26. $(info Supported git hash: $(ESPIDF_SUPHASH))
  27. $(error ESPIDF not set)
  28. endif
  29. endif
  30. ESPCOMP = $(ESPIDF)/components
  31. ESPTOOL ?= $(ESPCOMP)/esptool_py/esptool/esptool.py
  32. # verify the ESP IDF version
  33. ESPIDF_CURHASH := $(shell git -C $(ESPIDF) show -s --pretty=format:'%H')
  34. ifneq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH))
  35. $(info ** WARNING **)
  36. $(info The git hash of ESP IDF does not match the supported version)
  37. $(info The build may complete and the firmware may work but it is not guaranteed)
  38. $(info ESP IDF path: $(ESPIDF))
  39. $(info Current git hash: $(ESPIDF_CURHASH))
  40. $(info Supported git hash: $(ESPIDF_SUPHASH))
  41. endif
  42. # pretty format of ESP IDF version, used internally by the IDF
  43. IDF_VER := $(shell git -C $(ESPIDF) describe)
  44. INC += -I.
  45. INC += -I$(TOP)
  46. INC += -I$(TOP)/lib/mp-readline
  47. INC += -I$(TOP)/lib/netutils
  48. INC += -I$(TOP)/lib/timeutils
  49. INC += -I$(BUILD)
  50. INC_ESPCOMP += -I$(ESPCOMP)/bootloader_support/include
  51. INC_ESPCOMP += -I$(ESPCOMP)/driver/include
  52. INC_ESPCOMP += -I$(ESPCOMP)/driver/include/driver
  53. INC_ESPCOMP += -I$(ESPCOMP)/nghttp/port/include
  54. INC_ESPCOMP += -I$(ESPCOMP)/nghttp/nghttp2/lib/includes
  55. INC_ESPCOMP += -I$(ESPCOMP)/esp32/include
  56. INC_ESPCOMP += -I$(ESPCOMP)/soc/include
  57. INC_ESPCOMP += -I$(ESPCOMP)/soc/esp32/include
  58. INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include
  59. INC_ESPCOMP += -I$(ESPCOMP)/expat/include/expat
  60. INC_ESPCOMP += -I$(ESPCOMP)/expat/port/include
  61. INC_ESPCOMP += -I$(ESPCOMP)/heap/include
  62. INC_ESPCOMP += -I$(ESPCOMP)/json/include
  63. INC_ESPCOMP += -I$(ESPCOMP)/json/port/include
  64. INC_ESPCOMP += -I$(ESPCOMP)/log/include
  65. INC_ESPCOMP += -I$(ESPCOMP)/newlib/include
  66. INC_ESPCOMP += -I$(ESPCOMP)/nvs_flash/include
  67. INC_ESPCOMP += -I$(ESPCOMP)/freertos/include
  68. INC_ESPCOMP += -I$(ESPCOMP)/tcpip_adapter/include
  69. INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/lwip
  70. INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/lwip/port
  71. INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/lwip/posix
  72. INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/mbedtls/include
  73. INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/port/include
  74. INC_ESPCOMP += -I$(ESPCOMP)/spi_flash/include
  75. INC_ESPCOMP += -I$(ESPCOMP)/ulp/include
  76. INC_ESPCOMP += -I$(ESPCOMP)/vfs/include
  77. INC_ESPCOMP += -I$(ESPCOMP)/newlib/platform_include
  78. INC_ESPCOMP += -I$(ESPCOMP)/xtensa-debug-module/include
  79. INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/include
  80. INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/port/include
  81. INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include
  82. INC_ESPCOMP += -I$(ESPCOMP)/app_trace/include
  83. INC_ESPCOMP += -I$(ESPCOMP)/app_update/include
  84. INC_ESPCOMP += -I$(ESPCOMP)/pthread/include
  85. INC_ESPCOMP += -I$(ESPCOMP)/smartconfig_ack/include
  86. # these flags are common to C and C++ compilation
  87. CFLAGS_COMMON = -Os -ffunction-sections -fdata-sections -fstrict-volatile-bitfields \
  88. -mlongcalls -nostdlib \
  89. -Wall -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable \
  90. -Wno-error=unused-variable -Wno-error=deprecated-declarations \
  91. -DESP_PLATFORM
  92. CFLAGS_BASE = -std=gnu99 $(CFLAGS_COMMON) -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H
  93. CFLAGS = $(CFLAGS_BASE) $(INC) $(INC_ESPCOMP)
  94. CFLAGS += -DIDF_VER=\"$(IDF_VER)\"
  95. CFLAGS += $(CFLAGS_MOD)
  96. # this is what ESPIDF uses for c++ compilation
  97. CXXFLAGS = -std=gnu++11 $(CFLAGS_COMMON) $(INC) $(INC_ESPCOMP)
  98. LDFLAGS = -nostdlib -Map=$(@:.elf=.map) --cref
  99. LDFLAGS += --gc-sections -static -EL
  100. LDFLAGS += -u call_user_start_cpu0 -u uxTopUsedPriority -u ld_include_panic_highint_hdl
  101. LDFLAGS += -u __cxa_guard_dummy # so that implementation of static guards is taken from cxx_guards.o instead of libstdc++.a
  102. LDFLAGS += -L$(ESPCOMP)/esp32/ld
  103. LDFLAGS += -T $(BUILD)/esp32_out.ld
  104. LDFLAGS += -T ./esp32.custom_common.ld
  105. LDFLAGS += -T esp32.rom.ld
  106. LDFLAGS += -T esp32.peripherals.ld
  107. LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
  108. LIBSTDCXX_FILE_NAME = $(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)
  109. # Debugging/Optimization
  110. ifeq ($(DEBUG), 1)
  111. CFLAGS += -g
  112. COPT = -O0
  113. else
  114. #CFLAGS += -fdata-sections -ffunction-sections
  115. COPT += -Os -DNDEBUG
  116. #LDFLAGS += --gc-sections
  117. endif
  118. # Enable SPIRAM support if CONFIG_SPIRAM_SUPPORT=1
  119. ifeq ($(CONFIG_SPIRAM_SUPPORT),1)
  120. CFLAGS_COMMON += -mfix-esp32-psram-cache-issue -DCONFIG_SPIRAM_SUPPORT=1
  121. LIBC_LIBM = $(ESPCOMP)/newlib/lib/libc-psram-workaround.a $(ESPCOMP)/newlib/lib/libm-psram-workaround.a
  122. else
  123. LDFLAGS += -T esp32.rom.spiram_incompatible_fns.ld
  124. LIBC_LIBM = $(ESPCOMP)/newlib/lib/libc.a $(ESPCOMP)/newlib/lib/libm.a
  125. endif
  126. ################################################################################
  127. # List of MicroPython source and object files
  128. SRC_C = \
  129. main.c \
  130. uart.c \
  131. gccollect.c \
  132. mphalport.c \
  133. fatfs_port.c \
  134. help.c \
  135. modutime.c \
  136. moduos.c \
  137. machine_timer.c \
  138. machine_pin.c \
  139. machine_touchpad.c \
  140. machine_adc.c \
  141. machine_dac.c \
  142. machine_pwm.c \
  143. machine_uart.c \
  144. modmachine.c \
  145. modnetwork.c \
  146. network_lan.c \
  147. modsocket.c \
  148. modesp.c \
  149. esp32_ulp.c \
  150. modesp32.c \
  151. espneopixel.c \
  152. machine_hw_spi.c \
  153. machine_wdt.c \
  154. mpthreadport.c \
  155. machine_rtc.c \
  156. $(SRC_MOD)
  157. EXTMOD_SRC_C = $(addprefix extmod/,\
  158. modonewire.c \
  159. )
  160. LIB_SRC_C = $(addprefix lib/,\
  161. libm/math.c \
  162. libm/fmodf.c \
  163. libm/roundf.c \
  164. libm/ef_sqrt.c \
  165. libm/kf_rem_pio2.c \
  166. libm/kf_sin.c \
  167. libm/kf_cos.c \
  168. libm/kf_tan.c \
  169. libm/ef_rem_pio2.c \
  170. libm/sf_sin.c \
  171. libm/sf_cos.c \
  172. libm/sf_tan.c \
  173. libm/sf_frexp.c \
  174. libm/sf_modf.c \
  175. libm/sf_ldexp.c \
  176. libm/asinfacosf.c \
  177. libm/atanf.c \
  178. libm/atan2f.c \
  179. mp-readline/readline.c \
  180. netutils/netutils.c \
  181. timeutils/timeutils.c \
  182. utils/pyexec.c \
  183. utils/interrupt_char.c \
  184. utils/sys_stdio_mphal.c \
  185. )
  186. ifeq ($(MICROPY_FATFS), 1)
  187. LIB_SRC_C += \
  188. lib/oofatfs/ff.c \
  189. lib/oofatfs/option/unicode.c
  190. endif
  191. DRIVERS_SRC_C = $(addprefix drivers/,\
  192. bus/softspi.c \
  193. dht/dht.c \
  194. )
  195. OBJ_MP =
  196. OBJ_MP += $(PY_O)
  197. OBJ_MP += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
  198. OBJ_MP += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
  199. OBJ_MP += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
  200. OBJ_MP += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
  201. # List of sources for qstr extraction
  202. SRC_QSTR += $(SRC_C) $(EXTMOD_SRC_C) $(LIB_SRC_C) $(DRIVERS_SRC_C)
  203. # Append any auto-generated sources that are needed by sources listed in SRC_QSTR
  204. SRC_QSTR_AUTO_DEPS +=
  205. ################################################################################
  206. # List of object files from the ESP32 IDF components
  207. ESPIDF_DRIVER_O = $(addprefix $(ESPCOMP)/driver/,\
  208. uart.o \
  209. periph_ctrl.o \
  210. ledc.o \
  211. gpio.o \
  212. timer.o \
  213. spi_master.o \
  214. spi_common.o \
  215. rtc_module.o \
  216. )
  217. $(BUILD)/$(ESPCOMP)/esp32/dport_access.o: CFLAGS += -Wno-array-bounds
  218. ESPIDF_ESP32_O = $(addprefix $(ESPCOMP)/esp32/,\
  219. brownout.o \
  220. panic.o \
  221. esp_timer.o \
  222. esp_timer_esp32.o \
  223. ets_timer_legacy.o \
  224. event_default_handlers.o \
  225. fast_crypto_ops.o \
  226. task_wdt.o \
  227. cache_err_int.o \
  228. clk.o \
  229. core_dump.o \
  230. cpu_start.o \
  231. gdbstub.o \
  232. crosscore_int.o \
  233. ipc.o \
  234. int_wdt.o \
  235. event_loop.o \
  236. hwcrypto/sha.o \
  237. hwcrypto/aes.o \
  238. lib_printf.o \
  239. freertos_hooks.o \
  240. system_api.o \
  241. hw_random.o \
  242. phy_init.o \
  243. intr_alloc.o \
  244. dport_access.o \
  245. wifi_init.o \
  246. wifi_os_adapter.o \
  247. sleep_modes.o \
  248. spiram.o \
  249. spiram_psram.o \
  250. )
  251. ESPIDF_HEAP_O = $(addprefix $(ESPCOMP)/heap/,\
  252. heap_caps.o \
  253. heap_caps_init.o \
  254. multi_heap.o \
  255. )
  256. ESPIDF_SOC_O = $(addprefix $(ESPCOMP)/soc/,\
  257. esp32/cpu_util.o \
  258. esp32/rtc_clk.o \
  259. esp32/rtc_init.o \
  260. esp32/rtc_pm.o \
  261. esp32/rtc_sleep.o \
  262. esp32/rtc_time.o \
  263. esp32/soc_memory_layout.o \
  264. esp32/spi_periph.o \
  265. )
  266. ESPIDF_CXX_O = $(addprefix $(ESPCOMP)/cxx/,\
  267. cxx_guards.o \
  268. )
  269. ESPIDF_ETHERNET_O = $(addprefix $(ESPCOMP)/ethernet/,\
  270. emac_dev.o \
  271. emac_main.o \
  272. eth_phy/phy_tlk110.o \
  273. eth_phy/phy_lan8720.o \
  274. eth_phy/phy_common.o \
  275. )
  276. $(BUILD)/$(ESPCOMP)/expat/%.o: CFLAGS += -Wno-unused-function
  277. ESPIDF_EXPAT_O = $(addprefix $(ESPCOMP)/expat/,\
  278. library/xmltok_ns.o \
  279. library/xmltok.o \
  280. library/xmlparse.o \
  281. library/xmlrole.o \
  282. library/xmltok_impl.o \
  283. port/minicheck.o \
  284. port/expat_element.o \
  285. port/chardata.o \
  286. )
  287. ESPIDF_PTHREAD_O = $(addprefix $(ESPCOMP)/pthread/,\
  288. pthread.o \
  289. pthread_local_storage.o \
  290. )
  291. # Assembler .S files need only basic flags, and in particular should not have
  292. # -Os because that generates subtly different code.
  293. # We also need custom CFLAGS for .c files because FreeRTOS has headers with
  294. # generic names (eg queue.h) which can clash with other files in the port.
  295. CFLAGS_ASM = -I$(ESPCOMP)/esp32/include -I$(ESPCOMP)/soc/esp32/include -I$(ESPCOMP)/freertos/include/freertos -I.
  296. $(BUILD)/$(ESPCOMP)/freertos/portasm.o: CFLAGS = $(CFLAGS_ASM)
  297. $(BUILD)/$(ESPCOMP)/freertos/xtensa_context.o: CFLAGS = $(CFLAGS_ASM)
  298. $(BUILD)/$(ESPCOMP)/freertos/xtensa_intr_asm.o: CFLAGS = $(CFLAGS_ASM)
  299. $(BUILD)/$(ESPCOMP)/freertos/xtensa_vectors.o: CFLAGS = $(CFLAGS_ASM)
  300. $(BUILD)/$(ESPCOMP)/freertos/%.o: CFLAGS = $(CFLAGS_BASE) -I. $(INC_ESPCOMP) -I$(ESPCOMP)/freertos/include/freertos -D_ESP_FREERTOS_INTERNAL
  301. ESPIDF_FREERTOS_O = $(addprefix $(ESPCOMP)/freertos/,\
  302. croutine.o \
  303. event_groups.o \
  304. FreeRTOS-openocd.o \
  305. list.o \
  306. portasm.o \
  307. port.o \
  308. queue.o \
  309. ringbuf.o \
  310. tasks.o \
  311. timers.o \
  312. xtensa_context.o \
  313. xtensa_init.o \
  314. xtensa_intr_asm.o \
  315. xtensa_intr.o \
  316. xtensa_overlay_os_hook.o \
  317. xtensa_vector_defaults.o \
  318. xtensa_vectors.o \
  319. )
  320. ESPIDF_VFS_O = $(addprefix $(ESPCOMP)/vfs/,\
  321. vfs_uart.o \
  322. vfs.o \
  323. )
  324. ESPIDF_JSON_O = $(addprefix $(ESPCOMP)/json/cJSON/,\
  325. cJSON.o \
  326. cJSON_Utils.o \
  327. )
  328. ESPIDF_LOG_O = $(addprefix $(ESPCOMP)/log/,\
  329. log.o \
  330. )
  331. ESPIDF_XTENSA_DEBUG_MODULE_O = $(addprefix $(ESPCOMP)/xtensa-debug-module/,\
  332. eri.o \
  333. trax.o \
  334. )
  335. ESPIDF_TCPIP_ADAPTER_O = $(addprefix $(ESPCOMP)/tcpip_adapter/,\
  336. tcpip_adapter_lwip.o \
  337. )
  338. ESPIDF_APP_TRACE_O = $(addprefix $(ESPCOMP)/app_trace/,\
  339. app_trace.o \
  340. )
  341. ESPIDF_APP_UPDATE_O = $(addprefix $(ESPCOMP)/app_update/,\
  342. esp_ota_ops.o \
  343. )
  344. ESPIDF_NEWLIB_O = $(addprefix $(ESPCOMP)/newlib/,\
  345. time.o \
  346. select.o \
  347. syscalls.o \
  348. syscall_table.o \
  349. reent_init.o \
  350. locks.o \
  351. )
  352. ESPIDF_NGHTTP_O = $(addprefix $(ESPCOMP)/nghttp/,\
  353. nghttp2/lib/nghttp2_http.o \
  354. nghttp2/lib/nghttp2_version.o \
  355. nghttp2/lib/nghttp2_mem.o \
  356. nghttp2/lib/nghttp2_hd_huffman.o \
  357. nghttp2/lib/nghttp2_rcbuf.o \
  358. nghttp2/lib/nghttp2_callbacks.o \
  359. nghttp2/lib/nghttp2_session.o \
  360. nghttp2/lib/nghttp2_stream.o \
  361. nghttp2/lib/nghttp2_hd.o \
  362. nghttp2/lib/nghttp2_priority_spec.o \
  363. nghttp2/lib/nghttp2_buf.o \
  364. nghttp2/lib/nghttp2_option.o \
  365. nghttp2/lib/nghttp2_npn.o \
  366. nghttp2/lib/nghttp2_helper.o \
  367. nghttp2/lib/nghttp2_frame.o \
  368. nghttp2/lib/nghttp2_outbound_item.o \
  369. nghttp2/lib/nghttp2_hd_huffman_data.o \
  370. nghttp2/lib/nghttp2_pq.o \
  371. nghttp2/lib/nghttp2_queue.o \
  372. nghttp2/lib/nghttp2_submit.o \
  373. nghttp2/lib/nghttp2_map.o \
  374. port/http_parser.o \
  375. )
  376. ESPIDF_NVS_FLASH_O = $(addprefix $(ESPCOMP)/nvs_flash/,\
  377. src/nvs_types.o \
  378. src/nvs_page.o \
  379. src/nvs_item_hash_list.o \
  380. src/nvs_pagemanager.o \
  381. src/nvs_storage.o \
  382. src/nvs_api.o \
  383. )
  384. ESPIDF_OPENSSL_O = $(addprefix $(ESPCOMP)/openssl/,\
  385. )
  386. ESPIDF_SMARTCONFIG_ACK_O = $(addprefix $(ESPCOMP)/smartconfig_ack/,\
  387. smartconfig_ack.o \
  388. )
  389. ESPIDF_SPI_FLASH_O = $(addprefix $(ESPCOMP)/spi_flash/,\
  390. flash_mmap.o \
  391. partition.o \
  392. spi_flash_rom_patch.o \
  393. cache_utils.o \
  394. flash_ops.o \
  395. )
  396. ESPIDF_ULP_O = $(addprefix $(ESPCOMP)/ulp/,\
  397. ulp.o \
  398. )
  399. $(BUILD)/$(ESPCOMP)/lwip/%.o: CFLAGS += -Wno-address -Wno-unused-variable -Wno-unused-but-set-variable
  400. ESPIDF_LWIP_O = $(addprefix $(ESPCOMP)/lwip/,\
  401. api/pppapi.o \
  402. api/netbuf.o \
  403. api/api_lib.o \
  404. api/netifapi.o \
  405. api/tcpip.o \
  406. api/netdb.o \
  407. api/err.o \
  408. api/api_msg.o \
  409. api/sockets.o \
  410. apps/sntp/sntp.o \
  411. apps/dhcpserver.o \
  412. core/ipv4/ip_frag.o \
  413. core/ipv4/dhcp.o \
  414. core/ipv4/ip4_addr.o \
  415. core/ipv4/igmp.o \
  416. core/ipv4/ip4.o \
  417. core/ipv4/autoip.o \
  418. core/ipv4/icmp.o \
  419. core/ipv6/ip6_frag.o \
  420. core/ipv6/dhcp6.o \
  421. core/ipv6/inet6.o \
  422. core/ipv6/ip6_addr.o \
  423. core/ipv6/ip6.o \
  424. core/ipv6/nd6.o \
  425. core/ipv6/mld6.o \
  426. core/ipv6/ethip6.o \
  427. core/ipv6/icmp6.o \
  428. core/mem.o \
  429. core/init.o \
  430. core/memp.o \
  431. core/sys.o \
  432. core/tcp_in.o \
  433. core/dns.o \
  434. core/ip.o \
  435. core/pbuf.o \
  436. core/raw.o \
  437. core/tcp.o \
  438. core/def.o \
  439. core/netif.o \
  440. core/stats.o \
  441. core/timers.o \
  442. core/inet_chksum.o \
  443. core/udp.o \
  444. core/tcp_out.o \
  445. netif/slipif.o \
  446. netif/etharp.o \
  447. netif/ethernet.o \
  448. netif/lowpan6.o \
  449. netif/ethernetif.o \
  450. port/freertos/sys_arch.o \
  451. port/netif/wlanif.o \
  452. port/netif/ethernetif.o \
  453. port/vfs_lwip.o \
  454. )
  455. ESPIDF_MBEDTLS_O = $(addprefix $(ESPCOMP)/mbedtls/,\
  456. mbedtls/library/entropy.o \
  457. mbedtls/library/pkcs12.o \
  458. mbedtls/library/ccm.o \
  459. mbedtls/library/pk.o \
  460. mbedtls/library/sha1.o \
  461. mbedtls/library/x509_csr.o \
  462. mbedtls/library/ssl_cli.o \
  463. mbedtls/library/ecp.o \
  464. mbedtls/library/blowfish.o \
  465. mbedtls/library/x509.o \
  466. mbedtls/library/ecp_curves.o \
  467. mbedtls/library/error.o \
  468. mbedtls/library/ssl_ticket.o \
  469. mbedtls/library/entropy_poll.o \
  470. mbedtls/library/cipher.o \
  471. mbedtls/library/version_features.o \
  472. mbedtls/library/ripemd160.o \
  473. mbedtls/library/rsa.o \
  474. mbedtls/library/rsa_internal.o \
  475. mbedtls/library/md.o \
  476. mbedtls/library/md_wrap.o \
  477. mbedtls/library/sha256.o \
  478. mbedtls/library/dhm.o \
  479. mbedtls/library/ssl_cache.o \
  480. mbedtls/library/pkwrite.o \
  481. mbedtls/library/base64.o \
  482. mbedtls/library/asn1parse.o \
  483. mbedtls/library/ssl_tls.o \
  484. mbedtls/library/hmac_drbg.o \
  485. mbedtls/library/pem.o \
  486. mbedtls/library/version.o \
  487. mbedtls/library/gcm.o \
  488. mbedtls/library/memory_buffer_alloc.o \
  489. mbedtls/library/md2.o \
  490. mbedtls/library/ecdsa.o \
  491. mbedtls/library/ssl_srv.o \
  492. mbedtls/library/x509_crt.o \
  493. mbedtls/library/ecdh.o \
  494. mbedtls/library/asn1write.o \
  495. mbedtls/library/md4.o \
  496. mbedtls/library/debug.o \
  497. mbedtls/library/x509_create.o \
  498. mbedtls/library/ecjpake.o \
  499. mbedtls/library/oid.o \
  500. mbedtls/library/md5.o \
  501. mbedtls/library/ssl_ciphersuites.o \
  502. mbedtls/library/sha512.o \
  503. mbedtls/library/xtea.o \
  504. mbedtls/library/aes.o \
  505. mbedtls/library/cipher_wrap.o \
  506. mbedtls/library/arc4.o \
  507. mbedtls/library/bignum.o \
  508. mbedtls/library/pkparse.o \
  509. mbedtls/library/padlock.o \
  510. mbedtls/library/threading.o \
  511. mbedtls/library/x509_crl.o \
  512. mbedtls/library/pkcs11.o \
  513. mbedtls/library/aesni.o \
  514. mbedtls/library/timing.o \
  515. mbedtls/library/certs.o \
  516. mbedtls/library/pkcs5.o \
  517. mbedtls/library/ssl_cookie.o \
  518. mbedtls/library/camellia.o \
  519. mbedtls/library/havege.o \
  520. mbedtls/library/des.o \
  521. mbedtls/library/x509write_csr.o \
  522. mbedtls/library/platform.o \
  523. mbedtls/library/ctr_drbg.o \
  524. mbedtls/library/x509write_crt.o \
  525. mbedtls/library/pk_wrap.o \
  526. port/esp_bignum.o \
  527. port/esp_hardware.o \
  528. port/esp_sha1.o \
  529. port/esp_sha256.o \
  530. port/esp_sha512.o \
  531. )
  532. $(BUILD)/$(ESPCOMP)/wpa_supplicant/%.o: CFLAGS += -DEMBEDDED_SUPP -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_MSCHAPv2 -DEAP_TTLS -DEAP_TLS -DEAP_PEAP -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -D__ets__ -Wno-strict-aliasing
  533. ESPIDF_WPA_SUPPLICANT_O = $(addprefix $(ESPCOMP)/wpa_supplicant/,\
  534. src/crypto/aes-internal-enc.o \
  535. src/crypto/sha256-internal.o \
  536. src/crypto/md5-internal.o \
  537. src/crypto/aes-internal.o \
  538. src/crypto/sha1.o \
  539. src/crypto/aes-internal-dec.o \
  540. src/crypto/aes-unwrap.o \
  541. src/crypto/crypto_internal-rsa.o \
  542. src/crypto/dh_groups.o \
  543. src/crypto/crypto_internal.o \
  544. src/crypto/aes-wrap.o \
  545. src/crypto/sha1-internal.o \
  546. src/crypto/dh_group5.o \
  547. src/crypto/sha256.o \
  548. src/crypto/rc4.o \
  549. src/crypto/md5.o \
  550. src/crypto/aes-cbc.o \
  551. src/crypto/sha1-pbkdf2.o \
  552. src/crypto/bignum.o \
  553. src/crypto/crypto_internal-modexp.o \
  554. src/crypto/crypto_internal-cipher.o \
  555. src/fast_crypto/fast_aes-unwrap.o \
  556. src/fast_crypto/fast_aes-wrap.o \
  557. src/fast_crypto/fast_sha256.o \
  558. src/fast_crypto/fast_sha256-internal.o \
  559. port/os_xtensa.o \
  560. )
  561. OBJ_ESPIDF =
  562. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_NEWLIB_O))
  563. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_DRIVER_O))
  564. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_ESP32_O))
  565. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_HEAP_O))
  566. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_SOC_O))
  567. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_CXX_O))
  568. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_ETHERNET_O))
  569. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_EXPAT_O))
  570. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_PTHREAD_O))
  571. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_FREERTOS_O))
  572. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_VFS_O))
  573. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_JSON_O))
  574. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_LOG_O))
  575. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_LWIP_O))
  576. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_MBEDTLS_O))
  577. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_XTENSA_DEBUG_MODULE_O))
  578. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_TCPIP_ADAPTER_O))
  579. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_APP_TRACE_O))
  580. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_APP_UPDATE_O))
  581. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_NGHTTP_O))
  582. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_NVS_FLASH_O))
  583. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_OPENSSL_O))
  584. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_SMARTCONFIG_ACK_O))
  585. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_SPI_FLASH_O))
  586. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_ULP_O))
  587. OBJ_ESPIDF += $(addprefix $(BUILD)/, $(ESPIDF_WPA_SUPPLICANT_O))
  588. ################################################################################
  589. # Main targets
  590. all: $(BUILD)/firmware.bin
  591. .PHONY: idf-version deploy erase
  592. idf-version:
  593. $(ECHO) "ESP IDF supported hash: $(ESPIDF_SUPHASH)"
  594. $(BUILD)/firmware.bin: $(BUILD)/bootloader.bin $(BUILD)/partitions.bin $(BUILD)/application.bin
  595. $(ECHO) "Create $@"
  596. $(Q)$(PYTHON) makeimg.py $^ $@
  597. deploy: $(BUILD)/firmware.bin
  598. $(ECHO) "Writing $^ to the board"
  599. $(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) write_flash -z --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) 0x1000 $^
  600. erase:
  601. $(ECHO) "Erasing flash"
  602. $(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) erase_flash
  603. ################################################################################
  604. # Declarations to build the application
  605. OBJ = $(OBJ_MP) $(OBJ_ESPIDF)
  606. APP_LD_ARGS =
  607. APP_LD_ARGS += $(LDFLAGS_MOD)
  608. APP_LD_ARGS += --start-group
  609. APP_LD_ARGS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
  610. APP_LD_ARGS += -L$(dir $(LIBSTDCXX_FILE_NAME)) -lstdc++
  611. APP_LD_ARGS += $(LIBC_LIBM)
  612. APP_LD_ARGS += $(ESPCOMP)/esp32/libhal.a
  613. APP_LD_ARGS += -L$(ESPCOMP)/esp32/lib -lcore -lmesh -lnet80211 -lphy -lrtc -lpp -lwpa -lsmartconfig -lcoexist -lwps -lwpa2
  614. APP_LD_ARGS += $(OBJ)
  615. APP_LD_ARGS += --end-group
  616. $(BUILD)/esp32_out.ld: sdkconfig.h
  617. $(Q)$(CC) -I. -C -P -x c -E $(ESPCOMP)/esp32/ld/esp32.ld -o $@
  618. $(BUILD)/application.bin: $(BUILD)/application.elf
  619. $(ECHO) "Create $@"
  620. $(Q)$(ESPTOOL) --chip esp32 elf2image --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) --flash_size $(FLASH_SIZE) $<
  621. $(BUILD)/application.elf: $(OBJ) $(BUILD)/esp32_out.ld
  622. $(ECHO) "LINK $@"
  623. $(Q)$(LD) $(LDFLAGS) -o $@ $(APP_LD_ARGS)
  624. $(Q)$(SIZE) $@
  625. define compile_cxx
  626. $(ECHO) "CXX $<"
  627. $(Q)$(CXX) $(CXXFLAGS) -c -MD -o $@ $<
  628. @# The following fixes the dependency file.
  629. @# See http://make.paulandlesley.org/autodep.html for details.
  630. @# Regex adjusted from the above to play better with Windows paths, etc.
  631. @$(CP) $(@:.o=.d) $(@:.o=.P); \
  632. $(SED) -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
  633. -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
  634. $(RM) -f $(@:.o=.d)
  635. endef
  636. vpath %.cpp . $(TOP)
  637. $(BUILD)/%.o: %.cpp
  638. $(call compile_cxx)
  639. ################################################################################
  640. # Declarations to build the bootloader
  641. $(BUILD)/bootloader/$(ESPCOMP)/%.o: CFLAGS += -DBOOTLOADER_BUILD=1 -I$(ESPCOMP)/bootloader_support/include_priv -I$(ESPCOMP)/bootloader_support/include -I$(ESPCOMP)/micro-ecc/micro-ecc -I$(ESPCOMP)/esp32 -Wno-error=format
  642. BOOTLOADER_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
  643. bootloader_support/src/bootloader_clock.o \
  644. bootloader_support/src/bootloader_common.o \
  645. bootloader_support/src/bootloader_flash.o \
  646. bootloader_support/src/bootloader_init.o \
  647. bootloader_support/src/bootloader_random.o \
  648. bootloader_support/src/bootloader_sha.o \
  649. bootloader_support/src/bootloader_utility.o \
  650. bootloader_support/src/efuse.o \
  651. bootloader_support/src/flash_qio_mode.o \
  652. bootloader_support/src/secure_boot_signatures.o \
  653. bootloader_support/src/secure_boot.o \
  654. bootloader_support/src/esp_image_format.o \
  655. bootloader_support/src/flash_encrypt.o \
  656. bootloader_support/src/flash_partitions.o \
  657. log/log.o \
  658. spi_flash/spi_flash_rom_patch.o \
  659. soc/esp32/rtc_clk.o \
  660. soc/esp32/rtc_time.o \
  661. soc/esp32/cpu_util.o \
  662. micro-ecc/micro-ecc/uECC.o \
  663. bootloader/subproject/main/bootloader_start.o \
  664. )
  665. BOOTLOADER_LIBS =
  666. BOOTLOADER_LIBS += -Wl,--start-group
  667. BOOTLOADER_LIBS += $(BOOTLOADER_OBJ)
  668. BOOTLOADER_LIBS += -L$(ESPCOMP)/esp32/lib -lrtc
  669. BOOTLOADER_LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
  670. BOOTLOADER_LIBS += -Wl,--end-group
  671. BOOTLOADER_LDFLAGS =
  672. BOOTLOADER_LDFLAGS += -nostdlib
  673. BOOTLOADER_LDFLAGS += -L$(ESPIDF)/lib
  674. BOOTLOADER_LDFLAGS += -L$(ESPIDF)/ld
  675. BOOTLOADER_LDFLAGS += -u call_user_start_cpu0
  676. BOOTLOADER_LDFLAGS += -Wl,--gc-sections
  677. BOOTLOADER_LDFLAGS += -static
  678. BOOTLOADER_LDFLAGS += -Wl,-EL
  679. BOOTLOADER_LDFLAGS += -Wl,-Map=$(@:.elf=.map) -Wl,--cref
  680. BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.ld
  681. BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.rom.ld
  682. BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.ld
  683. BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.spiram_incompatible_fns.ld
  684. BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.peripherals.ld
  685. BOOTLOADER_OBJ_DIRS = $(sort $(dir $(BOOTLOADER_OBJ)))
  686. $(BOOTLOADER_OBJ): | $(BOOTLOADER_OBJ_DIRS)
  687. $(BOOTLOADER_OBJ_DIRS):
  688. $(MKDIR) -p $@
  689. $(BUILD)/bootloader/%.o: %.c
  690. $(call compile_c)
  691. $(BUILD)/bootloader.bin: $(BUILD)/bootloader.elf
  692. $(ECHO) "Create $@"
  693. $(Q)$(ESPTOOL) --chip esp32 elf2image --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) --flash_size $(FLASH_SIZE) $<
  694. $(BUILD)/bootloader.elf: $(BOOTLOADER_OBJ)
  695. $(ECHO) "LINK $@"
  696. $(Q)$(CC) $(BOOTLOADER_LDFLAGS) -o $@ $(BOOTLOADER_LIBS)
  697. ################################################################################
  698. # Declarations to build the partitions
  699. PYTHON2 ?= python2
  700. PART_SRC = partitions.csv
  701. $(BUILD)/partitions.bin: $(PART_SRC)
  702. $(ECHO) "Create $@"
  703. $(Q)$(PYTHON2) $(ESPCOMP)/partition_table/gen_esp32part.py -q $< $@
  704. ################################################################################
  705. include $(TOP)/py/mkrules.mk