-
Notifications
You must be signed in to change notification settings - Fork 78
/
Makefile.real
971 lines (825 loc) · 36.9 KB
/
Makefile.real
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# Select the board to build for: if not given on the command line,
# then default to GENERIC.
BOARD ?= GENERIC
# If the build directory is not given, make it reflect the board name.
BUILD ?= build-$(BOARD)
BOARD_DIR ?= boards/$(BOARD)
ifeq ($(wildcard $(BOARD_DIR)/.),)
$(error Invalid BOARD specified: $(BOARD_DIR))
endif
include ../../py/mkenv.mk
# Optional (not currently used for ESP32)
-include mpconfigport.mk
ifneq ($(SDKCONFIG),)
$(error Use the BOARD variable instead of SDKCONFIG)
endif
# Expected to set SDKCONFIG
include $(BOARD_DIR)/mpconfigboard.mk
# qstr definitions (must come before including py.mk)
QSTR_DEFS = qstrdefsport.h
QSTR_GLOBAL_DEPENDENCIES = $(BOARD_DIR)/mpconfigboard.h
QSTR_GLOBAL_REQUIREMENTS = $(SDKCONFIG_H)
# MicroPython feature configurations
MICROPY_ROM_TEXT_COMPRESSION ?= 1
MICROPY_PY_USSL = 0
MICROPY_SSL_AXTLS = 0
MICROPY_PY_BTREE = 1
MICROPY_VFS_FAT = 1
MICROPY_VFS_LFS2 = 1
#FROZEN_DIR = scripts
FROZEN_MPY_DIR = modules
# include py core make definitions
include $(TOP)/py/py.mk
GIT_SUBMODULES = lib/berkeley-db-1.xx
PORT ?= /dev/ttyUSB0
BAUD ?= 460800
FLASH_MODE ?= dio
FLASH_FREQ ?= 40m
FLASH_SIZE ?= 4MB
CROSS_COMPILE ?= xtensa-esp32-elf-
OBJDUMP = $(CROSS_COMPILE)objdump
SDKCONFIG_COMBINED = $(BUILD)/sdkconfig.combined
SDKCONFIG_H = $(BUILD)/sdkconfig.h
# The git hash of the currently supported ESP IDF version.
# These correspond to v3.3.2 and v4.0.1.
ESPIDF_SUPHASH_V3 := 9e70825d1e1cbf7988cf36981774300066580ea7
ESPIDF_SUPHASH_V4 := 4c81978a3e2220674a432a588292a4c860eef27b
define print_supported_git_hash
$(info Supported git hash (v3.3): $(ESPIDF_SUPHASH_V3))
$(info Supported git hash (v4.0) (experimental): $(ESPIDF_SUPHASH_V4))
endef
# paths to ESP IDF and its components
ifeq ($(ESPIDF),)
ifneq ($(IDF_PATH),)
ESPIDF = $(IDF_PATH)
else
$(info The ESPIDF variable has not been set, please set it to the root of the esp-idf repository.)
$(info See README.md for installation instructions.)
dummy := $(call print_supported_git_hash)
$(error ESPIDF not set)
endif
endif
ESPCOMP = $(ESPIDF)/components
ESPTOOL ?= $(ESPCOMP)/esptool_py/esptool/esptool.py
ESPCOMP_KCONFIGS = $(shell find $(ESPCOMP) -name Kconfig)
ESPCOMP_KCONFIGS_PROJBUILD = $(shell find $(ESPCOMP) -name Kconfig.projbuild)
# verify the ESP IDF version
ESPIDF_CURHASH := $(shell git -C $(ESPIDF) show -s --pretty=format:'%H')
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V3))
$(info Building with ESP IDF v3)
else ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
$(info Building with ESP IDF v4)
PYPARSING_VERSION = $(shell python3 -c 'import pyparsing; print(pyparsing.__version__)')
ifneq ($(PYPARSING_VERSION),2.3.1)
$(info ** ERROR **)
$(info EDP IDF requires pyparsing version less than 2.4)
$(info You will need to set up a Python virtual environment with pyparsing 2.3.1)
$(info Please see README.md for more information)
$(error Incorrect pyparsing version)
endif
else
$(info ** WARNING **)
$(info The git hash of ESP IDF does not match the supported version)
$(info The build may complete and the firmware may work but it is not guaranteed)
$(info ESP IDF path: $(ESPIDF))
$(info Current git hash: $(ESPIDF_CURHASH))
dummy := $(call print_supported_git_hash)
endif
# pretty format of ESP IDF version, used internally by the IDF
IDF_VER := $(shell git -C $(ESPIDF) describe)
ifeq ($(shell which $(CC) 2> /dev/null),)
$(info ** ERROR **)
$(info Cannot find C compiler $(CC))
$(info Add the xtensa toolchain to your PATH. See README.md)
$(error C compiler missing)
endif
# Support BLE by default.
# Can be explicitly disabled on the command line or board config.
MICROPY_PY_BLUETOOTH ?= 1
ifeq ($(MICROPY_PY_BLUETOOTH),1)
SDKCONFIG += boards/sdkconfig.ble
# Use NimBLE on ESP32.
MICROPY_BLUETOOTH_NIMBLE ?= 1
# Use Nimble bindings, but ESP32 IDF provides the Nimble library.
MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY = 1
include $(TOP)/extmod/nimble/nimble.mk
endif
# include sdkconfig to get needed configuration values
include $(SDKCONFIG)
################################################################################
# Compiler and linker flags
INC += -I.
INC += -I$(TOP)
INC += -I$(BUILD)
INC_ESPCOMP += -I$(ESPCOMP)/bootloader_support/include
INC_ESPCOMP += -I$(ESPCOMP)/bootloader_support/include_bootloader
INC_ESPCOMP += -I$(ESPCOMP)/console
INC_ESPCOMP += -I$(ESPCOMP)/driver/include
INC_ESPCOMP += -I$(ESPCOMP)/driver/include/driver
INC_ESPCOMP += -I$(ESPCOMP)/efuse/include
INC_ESPCOMP += -I$(ESPCOMP)/efuse/esp32/include
INC_ESPCOMP += -I$(ESPCOMP)/esp32/include
INC_ESPCOMP += -I$(ESPCOMP)/espcoredump/include
INC_ESPCOMP += -I$(ESPCOMP)/soc/include
INC_ESPCOMP += -I$(ESPCOMP)/soc/esp32/include
INC_ESPCOMP += -I$(ESPCOMP)/heap/include
INC_ESPCOMP += -I$(ESPCOMP)/log/include
INC_ESPCOMP += -I$(ESPCOMP)/nvs_flash/include
INC_ESPCOMP += -I$(ESPCOMP)/freertos/include
INC_ESPCOMP += -I$(ESPCOMP)/esp_ringbuf/include
INC_ESPCOMP += -I$(ESPCOMP)/esp_event/include
INC_ESPCOMP += -I$(ESPCOMP)/tcpip_adapter/include
INC_ESPCOMP += -I$(ESPCOMP)/lwip/lwip/src/include
INC_ESPCOMP += -I$(ESPCOMP)/lwip/port/esp32/include
INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/apps
INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/apps/sntp
INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/mbedtls/include
INC_ESPCOMP += -I$(ESPCOMP)/mbedtls/port/include
INC_ESPCOMP += -I$(ESPCOMP)/mdns/include
INC_ESPCOMP += -I$(ESPCOMP)/mdns/private_include
INC_ESPCOMP += -I$(ESPCOMP)/spi_flash/include
INC_ESPCOMP += -I$(ESPCOMP)/ulp/include
INC_ESPCOMP += -I$(ESPCOMP)/vfs/include
INC_ESPCOMP += -I$(ESPCOMP)/xtensa-debug-module/include
INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/include
INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/port/include
INC_ESPCOMP += -I$(ESPCOMP)/app_trace/include
INC_ESPCOMP += -I$(ESPCOMP)/app_update/include
INC_ESPCOMP += -I$(ESPCOMP)/pthread/include
INC_ESPCOMP += -I$(ESPCOMP)/smartconfig_ack/include
INC_ESPCOMP += -I$(ESPCOMP)/sdmmc/include
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
INC_ESPCOMP += -I$(ESPCOMP)/esp_common/include
INC_ESPCOMP += -I$(ESPCOMP)/esp_eth/include
INC_ESPCOMP += -I$(ESPCOMP)/esp_event/private_include
INC_ESPCOMP += -I$(ESPCOMP)/esp_rom/include
INC_ESPCOMP += -I$(ESPCOMP)/esp_wifi/include
INC_ESPCOMP += -I$(ESPCOMP)/esp_wifi/esp32/include
INC_ESPCOMP += -I$(ESPCOMP)/lwip/include/apps/sntp
INC_ESPCOMP += -I$(ESPCOMP)/spi_flash/private_include
INC_ESPCOMP += -I$(ESPCOMP)/wpa_supplicant/include/esp_supplicant
INC_ESPCOMP += -I$(ESPCOMP)/xtensa/include
INC_ESPCOMP += -I$(ESPCOMP)/xtensa/esp32/include
ifeq ($(CONFIG_BT_NIMBLE_ENABLED),y)
INC_ESPCOMP += -I$(ESPCOMP)/bt/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/common/osi/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/common/btc/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/common/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/porting/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/port/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/ans/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/bas/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/gap/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/gatt/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/ias/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/lls/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/tps/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/util/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/store/ram/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/nimble/host/store/config/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/porting/npl/freertos/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/nimble/ext/tinycrypt/include
INC_ESPCOMP += -I$(ESPCOMP)/bt/host/nimble/esp-hci/include
endif
else
INC_ESPCOMP += -I$(ESPCOMP)/ethernet/include
INC_ESPCOMP += -I$(ESPCOMP)/expat/expat/expat/lib
INC_ESPCOMP += -I$(ESPCOMP)/expat/port/include
INC_ESPCOMP += -I$(ESPCOMP)/json/include
INC_ESPCOMP += -I$(ESPCOMP)/json/port/include
INC_ESPCOMP += -I$(ESPCOMP)/micro-ecc/micro-ecc
INC_ESPCOMP += -I$(ESPCOMP)/nghttp/port/include
INC_ESPCOMP += -I$(ESPCOMP)/nghttp/nghttp2/lib/includes
ifeq ($(CONFIG_NIMBLE_ENABLED),y)
INC_ESPCOMP += -I$(ESPCOMP)/bt/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/porting/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/port/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/ans/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/bas/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/gap/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/gatt/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/ias/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/lls/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/services/tps/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/util/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/store/ram/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/nimble/host/store/config/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/porting/npl/freertos/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/nimble/ext/tinycrypt/include
INC_ESPCOMP += -I$(ESPCOMP)/nimble/esp-hci/include
endif
endif
INC_NEWLIB += -I$(ESPCOMP)/newlib/platform_include
INC_NEWLIB += -I$(ESPCOMP)/newlib/include
ifeq ($(MICROPY_PY_BLUETOOTH),1)
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH=1
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE=1
endif
# these flags are common to C and C++ compilation
CFLAGS_COMMON = -Os -ffunction-sections -fdata-sections -fstrict-volatile-bitfields \
-mlongcalls -nostdlib \
-Wall -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable \
-Wno-error=unused-variable -Wno-error=deprecated-declarations \
-DESP_PLATFORM
CFLAGS_BASE = -std=gnu99 $(CFLAGS_COMMON) -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H
CFLAGS = $(CFLAGS_BASE) $(INC) $(INC_ESPCOMP) $(INC_NEWLIB)
CFLAGS += -DIDF_VER=\"$(IDF_VER)\"
CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA)
CFLAGS += -I$(BOARD_DIR)
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
CFLAGS += -DMICROPY_ESP_IDF_4=1
endif
# this is what ESPIDF uses for c++ compilation
CXXFLAGS = -std=gnu++11 $(CFLAGS_COMMON) $(INC) $(INC_ESPCOMP) $(CXXFLAGS_MOD)
LDFLAGS = -nostdlib -Map=$(@:.elf=.map) --cref
LDFLAGS += --gc-sections -static -EL
LDFLAGS += -u call_user_start_cpu0 -u uxTopUsedPriority -u ld_include_panic_highint_hdl
LDFLAGS += -u __cxa_guard_dummy # so that implementation of static guards is taken from cxx_guards.o instead of libstdc++.a
LDFLAGS += -L$(ESPCOMP)/esp32/ld
LDFLAGS += -L$(ESPCOMP)/esp_rom/esp32/ld
LDFLAGS += -T $(BUILD)/esp32_out.ld
LDFLAGS += -T $(BUILD)/esp32.project.ld
LDFLAGS += -T esp32.rom.ld
LDFLAGS += -T esp32.rom.libgcc.ld
LDFLAGS += -T esp32.peripherals.ld
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
LIBSTDCXX_FILE_NAME = $(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)
# Debugging/Optimization
ifeq ($(DEBUG), 1)
CFLAGS += -g
COPT = -O0
else
#CFLAGS += -fdata-sections -ffunction-sections
COPT += -Os -DNDEBUG
#LDFLAGS += --gc-sections
endif
# Options for mpy-cross
MPY_CROSS_FLAGS += -march=xtensawin
# Enable SPIRAM support if CONFIG_ESP32_SPIRAM_SUPPORT=y in sdkconfig
ifeq ($(CONFIG_ESP32_SPIRAM_SUPPORT),y)
CFLAGS_COMMON += -mfix-esp32-psram-cache-issue
LIBC_LIBM = $(ESPCOMP)/newlib/lib/libc-psram-workaround.a $(ESPCOMP)/newlib/lib/libm-psram-workaround.a
else
# Additional newlib symbols that can only be used with spiram disabled.
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
LDFLAGS += -T esp32.rom.newlib-funcs.ld
LDFLAGS += -T esp32.rom.newlib-locale.ld
LDFLAGS += -T esp32.rom.newlib-data.ld
else
LDFLAGS += -T esp32.rom.spiram_incompatible_fns.ld
endif
LIBC_LIBM = $(ESPCOMP)/newlib/lib/libc.a $(ESPCOMP)/newlib/lib/libm.a
endif
################################################################################
# List of MicroPython source and object files
SRC_C = \
main.c \
uart.c \
gccollect.c \
mphalport.c \
fatfs_port.c \
help.c \
modutime.c \
moduos.c \
machine_timer.c \
machine_pin.c \
machine_touchpad.c \
machine_adc.c \
machine_dac.c \
machine_i2c.c \
machine_pwm.c \
machine_uart.c \
modmachine.c \
modnetwork.c \
network_lan.c \
network_ppp.c \
mpnimbleport.c \
modsocket.c \
modesp.c \
esp32_partition.c \
esp32_rmt.c \
esp32_ulp.c \
modesp32.c \
espneopixel.c \
machine_hw_spi.c \
machine_wdt.c \
mpthreadport.c \
machine_rtc.c \
machine_sdcard.c \
$(wildcard $(BOARD_DIR)/*.c) \
$(SRC_MOD)
SRC_CXX += \
$(SRC_MOD_CXX)
EXTMOD_SRC_C += $(addprefix extmod/,\
modonewire.c \
)
LIB_SRC_C = $(addprefix lib/,\
mp-readline/readline.c \
netutils/netutils.c \
timeutils/timeutils.c \
utils/pyexec.c \
utils/interrupt_char.c \
utils/sys_stdio_mphal.c \
)
DRIVERS_SRC_C = $(addprefix drivers/,\
bus/softspi.c \
dht/dht.c \
)
OBJ_MP =
OBJ_MP += $(PY_O)
OBJ_MP += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ_MP += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
OBJ_MP += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o))
OBJ_MP += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
OBJ_MP += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o))
# Only enable this for the MicroPython source: ignore warnings from esp-idf.
$(OBJ_MP): CFLAGS += -Wdouble-promotion -Wfloat-conversion
# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_CXX) $(EXTMOD_SRC_C) $(LIB_SRC_C) $(DRIVERS_SRC_C)
# Append any auto-generated sources that are needed by sources listed in SRC_QSTR
SRC_QSTR_AUTO_DEPS +=
################################################################################
# Generate sdkconfig.h from sdkconfig
$(SDKCONFIG_COMBINED): $(SDKCONFIG)
$(Q)$(MKDIR) -p $(dir $@)
$(Q)$(CAT) $^ > $@
$(SDKCONFIG_H): $(SDKCONFIG_COMBINED)
$(ECHO) "GEN $@"
$(Q)$(MKDIR) -p $(dir $@)
$(Q)$(PYTHON) $(ESPIDF)/tools/kconfig_new/confgen.py \
--output header $@ \
--config $< \
--kconfig $(ESPIDF)/Kconfig \
--env "IDF_TARGET=esp32" \
--env "IDF_CMAKE=n" \
--env "COMPONENT_KCONFIGS=$(ESPCOMP_KCONFIGS)" \
--env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)" \
--env "IDF_PATH=$(ESPIDF)"
$(Q)touch $@
$(HEADER_BUILD)/qstrdefs.generated.h: $(SDKCONFIG_H) $(BOARD_DIR)/mpconfigboard.h
################################################################################
# List of object files from the ESP32 IDF components
ESPIDF_BOOTLOADER_SUPPORT_O = $(patsubst %.c,%.o,\
$(filter-out $(ESPCOMP)/bootloader_support/src/bootloader_init.c,\
$(wildcard $(ESPCOMP)/bootloader_support/src/*.c) \
$(wildcard $(ESPCOMP)/bootloader_support/src/idf/*.c) \
))
ESPIDF_DRIVER_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/driver/*.c))
ESPIDF_EFUSE_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/efuse/esp32/*.c)\
$(wildcard $(ESPCOMP)/efuse/src/*.c)\
)
$(BUILD)/$(ESPCOMP)/esp32/dport_access.o: CFLAGS += -Wno-array-bounds
ESPIDF_ESP32_O = \
$(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp32/*.c)) \
$(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp32/hwcrypto/*.c)) \
$(patsubst %.S,%.o,$(wildcard $(ESPCOMP)/esp32/*.S)) \
ESPIDF_ESP_RINGBUF_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_ringbuf/*.c))
ESPIDF_HEAP_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/heap/*.c))
ESPIDF_SOC_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/soc/esp32/*.c) \
$(wildcard $(ESPCOMP)/soc/src/*.c) \
$(wildcard $(ESPCOMP)/soc/src/hal/*.c) \
)
$(BUILD)/$(ESPCOMP)/cxx/cxx_guards.o: CXXFLAGS += -Wno-error=sign-compare
ESPIDF_CXX_O = $(patsubst %.cpp,%.o,$(wildcard $(ESPCOMP)/cxx/*.cpp))
ESPIDF_PTHREAD_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/pthread/*.c))
# Assembler .S files need only basic flags, and in particular should not have
# -Os because that generates subtly different code.
# We also need custom CFLAGS for .c files because FreeRTOS has headers with
# generic names (eg queue.h) which can clash with other files in the port.
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
CFLAGS_ASM = -I$(BUILD) -I$(ESPCOMP)/esp32/include -I$(ESPCOMP)/soc/esp32/include -I$(ESPCOMP)/freertos/include/freertos -I. -I$(ESPCOMP)/xtensa/include -I$(ESPCOMP)/xtensa/esp32/include -I$(ESPCOMP)/esp_common/include
else
CFLAGS_ASM = -I$(BUILD) -I$(ESPCOMP)/esp32/include -I$(ESPCOMP)/soc/esp32/include -I$(ESPCOMP)/freertos/include/freertos -I.
endif
$(BUILD)/$(ESPCOMP)/freertos/portasm.o: CFLAGS = $(CFLAGS_ASM)
$(BUILD)/$(ESPCOMP)/freertos/xtensa_context.o: CFLAGS = $(CFLAGS_ASM)
$(BUILD)/$(ESPCOMP)/freertos/xtensa_intr_asm.o: CFLAGS = $(CFLAGS_ASM)
$(BUILD)/$(ESPCOMP)/freertos/xtensa_vectors.o: CFLAGS = $(CFLAGS_ASM)
$(BUILD)/$(ESPCOMP)/freertos/xtensa_vector_defaults.o: CFLAGS = $(CFLAGS_ASM)
$(BUILD)/$(ESPCOMP)/freertos/%.o: CFLAGS = $(CFLAGS_BASE) -I. -I$(BUILD) $(INC_ESPCOMP) $(INC_NEWLIB) -I$(ESPCOMP)/freertos/include/freertos -D_ESP_FREERTOS_INTERNAL
ESPIDF_FREERTOS_O = \
$(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/freertos/*.c)) \
$(patsubst %.S,%.o,$(wildcard $(ESPCOMP)/freertos/*.S)) \
ESPIDF_VFS_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/vfs/*.c))
ESPIDF_LOG_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/log/*.c))
ESPIDF_XTENSA_DEBUG_MODULE_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/xtensa-debug-module/*.c))
ESPIDF_TCPIP_ADAPTER_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/tcpip_adapter/*.c))
ESPIDF_APP_TRACE_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/app_trace/*.c))
ESPIDF_APP_UPDATE_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/app_update/*.c))
ESPIDF_NEWLIB_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/newlib/*.c))
$(BUILD)/$(ESPCOMP)/nvs_flash/src/nvs_api.o: CXXFLAGS += -Wno-error=sign-compare
ESPIDF_NVS_FLASH_O = $(patsubst %.cpp,%.o,$(wildcard $(ESPCOMP)/nvs_flash/src/*.cpp))
ESPIDF_SMARTCONFIG_ACK_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/smartconfig_ack/*.c))
ESPIDF_SPI_FLASH_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/spi_flash/*.c))
ESPIDF_ULP_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/ulp/*.c))
$(BUILD)/$(ESPCOMP)/lwip/%.o: CFLAGS += -Wno-address -Wno-unused-variable -Wno-unused-but-set-variable
ESPIDF_LWIP_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/lwip/apps/dhcpserver/*.c) \
$(wildcard $(ESPCOMP)/lwip/lwip/src/api/*.c) \
$(wildcard $(ESPCOMP)/lwip/lwip/src/apps/sntp/*.c) \
$(wildcard $(ESPCOMP)/lwip/lwip/src/core/*.c) \
$(wildcard $(ESPCOMP)/lwip/lwip/src/core/*/*.c) \
$(wildcard $(ESPCOMP)/lwip/lwip/src/netif/*.c) \
$(wildcard $(ESPCOMP)/lwip/lwip/src/netif/*/*.c) \
$(wildcard $(ESPCOMP)/lwip/lwip/src/netif/*/*/*.c) \
$(wildcard $(ESPCOMP)/lwip/port/esp32/*.c) \
$(wildcard $(ESPCOMP)/lwip/port/esp32/*/*.c) \
)
ESPIDF_MBEDTLS_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/mbedtls/mbedtls/library/*.c) \
$(wildcard $(ESPCOMP)/mbedtls/port/*.c) \
$(wildcard $(ESPCOMP)/mbedtls/port/esp32/*.c) \
)
ESPIDF_MDNS_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/mdns/*.c))
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
$(BUILD)/$(ESPCOMP)/wpa_supplicant/%.o: CFLAGS += -DCONFIG_WPA3_SAE -DCONFIG_IEEE80211W -DESP_SUPPLICANT -DIEEE8021X_EAPOL -DEAP_PEER_METHOD -DEAP_TLS -DEAP_TTLS -DEAP_PEAP -DEAP_MSCHAPv2 -DUSE_WPA2_TASK -DCONFIG_WPS2 -DCONFIG_WPS_PIN -DUSE_WPS_TASK -DESPRESSIF_USE -DESP32_WORKAROUND -DCONFIG_ECC -D__ets__ -Wno-strict-aliasing -I$(ESPCOMP)/wpa_supplicant/src -Wno-implicit-function-declaration
else
$(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 -DALLOW_EVEN_MOD -D__ets__ -Wno-strict-aliasing
endif
ESPIDF_WPA_SUPPLICANT_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/wpa_supplicant/port/*.c) \
$(wildcard $(ESPCOMP)/wpa_supplicant/src/*/*.c) \
)
ESPIDF_SDMMC_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/sdmmc/*.c))
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
ESPIDF_ESP_COMMON_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_common/src/*.c))
ESPIDF_ESP_EVENT_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_event/*.c))
ESPIDF_ESP_WIFI_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_wifi/src/*.c))
ifeq ($(CONFIG_BT_NIMBLE_ENABLED),y)
ESPIDF_BT_NIMBLE_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/bt/controller/*.c) \
$(wildcard $(ESPCOMP)/bt/common/btc/core/*.c) \
$(wildcard $(ESPCOMP)/bt/common/osi/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/esp-hci/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/ext/tinycrypt/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/ans/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/bas/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/gap/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/gatt/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/ias/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/lls/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/services/tps/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/store/config/src/ble_store_config.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/store/config/src/ble_store_nvs.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/store/ram/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/host/util/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/nimble/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/porting/nimble/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/nimble/porting/npl/freertos/src/*.c) \
$(wildcard $(ESPCOMP)/bt/host/nimble/port/src/*.c) \
)
endif
$(BUILD)/$(ESPCOMP)/esp_eth/src/esp_eth_mac_dm9051.o: CFLAGS += -fno-strict-aliasing
ESPIDF_ESP_ETH_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/esp_eth/src/*.c))
ESPIDF_XTENSA_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/xtensa/*.c) \
$(wildcard $(ESPCOMP)/xtensa/esp32/*.c) \
)
else
ESPIDF_JSON_O = $(patsubst %.c,%.o,$(wildcard $(ESPCOMP)/json/cJSON/cJSON*.c))
ESPIDF_ETHERNET_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/ethernet/*.c) \
$(wildcard $(ESPCOMP)/ethernet/eth_phy/*.c) \
)
ifeq ($(CONFIG_NIMBLE_ENABLED),y)
ESPIDF_BT_NIMBLE_O = $(patsubst %.c,%.o,\
$(wildcard $(ESPCOMP)/bt/*.c) \
$(wildcard $(ESPCOMP)/nimble/esp-hci/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/ext/tinycrypt/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/services/ans/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/services/bas/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/services/gap/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/services/gatt/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/services/ias/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/services/lls/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/services/tps/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/store/config/src/ble_store_config.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/store/config/src/ble_store_nvs.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/store/ram/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/host/util/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/nimble/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/porting/nimble/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/nimble/porting/npl/freertos/src/*.c) \
$(wildcard $(ESPCOMP)/nimble/port/src/*.c) \
)
endif
endif
OBJ_ESPIDF =
LIB_ESPIDF =
BUILD_ESPIDF_LIB = $(BUILD)/esp-idf
define gen_espidf_lib_rule
OBJ_ESPIDF += $(addprefix $$(BUILD)/,$(2))
LIB_ESPIDF += $(1)
$(BUILD_ESPIDF_LIB)/$(1)/lib$(1).a: $(addprefix $$(BUILD)/,$(2))
$(ECHO) "AR $$@"
$(Q)$(AR) cru $$@ $$^
endef
$(eval $(call gen_espidf_lib_rule,bootloader_support,$(ESPIDF_BOOTLOADER_SUPPORT_O)))
$(eval $(call gen_espidf_lib_rule,driver,$(ESPIDF_DRIVER_O)))
$(eval $(call gen_espidf_lib_rule,efuse,$(ESPIDF_EFUSE_O)))
$(eval $(call gen_espidf_lib_rule,esp32,$(ESPIDF_ESP32_O)))
$(eval $(call gen_espidf_lib_rule,esp_ringbuf,$(ESPIDF_ESP_RINGBUF_O)))
$(eval $(call gen_espidf_lib_rule,heap,$(ESPIDF_HEAP_O)))
$(eval $(call gen_espidf_lib_rule,soc,$(ESPIDF_SOC_O)))
$(eval $(call gen_espidf_lib_rule,cxx,$(ESPIDF_CXX_O)))
$(eval $(call gen_espidf_lib_rule,pthread,$(ESPIDF_PTHREAD_O)))
$(eval $(call gen_espidf_lib_rule,freertos,$(ESPIDF_FREERTOS_O)))
$(eval $(call gen_espidf_lib_rule,vfs,$(ESPIDF_VFS_O)))
$(eval $(call gen_espidf_lib_rule,json,$(ESPIDF_JSON_O)))
$(eval $(call gen_espidf_lib_rule,log,$(ESPIDF_LOG_O)))
$(eval $(call gen_espidf_lib_rule,xtensa-debug-module,$(ESPIDF_XTENSA_DEBUG_MODULE_O)))
$(eval $(call gen_espidf_lib_rule,tcpip_adapter,$(ESPIDF_TCPIP_ADAPTER_O)))
$(eval $(call gen_espidf_lib_rule,app_trace,$(ESPIDF_APP_TRACE_O)))
$(eval $(call gen_espidf_lib_rule,app_update,$(ESPIDF_APP_UPDATE_O)))
$(eval $(call gen_espidf_lib_rule,newlib,$(ESPIDF_NEWLIB_O)))
$(eval $(call gen_espidf_lib_rule,nvs_flash,$(ESPIDF_NVS_FLASH_O)))
$(eval $(call gen_espidf_lib_rule,smartconfig_ack,$(ESPIDF_SMARTCONFIG_ACK_O)))
$(eval $(call gen_espidf_lib_rule,spi_flash,$(ESPIDF_SPI_FLASH_O)))
$(eval $(call gen_espidf_lib_rule,ulp,$(ESPIDF_ULP_O)))
$(eval $(call gen_espidf_lib_rule,lwip,$(ESPIDF_LWIP_O)))
$(eval $(call gen_espidf_lib_rule,mbedtls,$(ESPIDF_MBEDTLS_O)))
$(eval $(call gen_espidf_lib_rule,mdns,$(ESPIDF_MDNS_O)))
$(eval $(call gen_espidf_lib_rule,wpa_supplicant,$(ESPIDF_WPA_SUPPLICANT_O)))
$(eval $(call gen_espidf_lib_rule,sdmmc,$(ESPIDF_SDMMC_O)))
$(eval $(call gen_espidf_lib_rule,bt_nimble,$(ESPIDF_BT_NIMBLE_O)))
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
$(eval $(call gen_espidf_lib_rule,esp_common,$(ESPIDF_ESP_COMMON_O)))
$(eval $(call gen_espidf_lib_rule,esp_event,$(ESPIDF_ESP_EVENT_O)))
$(eval $(call gen_espidf_lib_rule,esp_wifi,$(ESPIDF_ESP_WIFI_O)))
$(eval $(call gen_espidf_lib_rule,esp_eth,$(ESPIDF_ESP_ETH_O)))
$(eval $(call gen_espidf_lib_rule,xtensa,$(ESPIDF_XTENSA_O)))
else
$(eval $(call gen_espidf_lib_rule,ethernet,$(ESPIDF_ETHERNET_O)))
endif
# Create all destination build dirs before compiling IDF source
OBJ_ESPIDF_DIRS = $(sort $(dir $(OBJ_ESPIDF))) $(BUILD_ESPIDF_LIB) $(addprefix $(BUILD_ESPIDF_LIB)/,$(LIB_ESPIDF))
$(OBJ_ESPIDF): | $(OBJ_ESPIDF_DIRS)
$(OBJ_ESPIDF_DIRS):
$(MKDIR) -p $@
# Make all IDF object files depend on sdkconfig
$(OBJ_ESPIDF): $(SDKCONFIG_H)
# Add all IDF components to the set of libraries
LIB = $(foreach lib,$(LIB_ESPIDF),$(BUILD_ESPIDF_LIB)/$(lib)/lib$(lib).a)
################################################################################
# ESP IDF ldgen
LDGEN_FRAGMENTS = $(shell find $(ESPCOMP) -name "*.lf")
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
LDGEN_LIBRARIES=$(foreach lib,$(LIB_ESPIDF),$(BUILD_ESPIDF_LIB)/$(lib)/lib$(lib).a)
$(BUILD_ESPIDF_LIB)/ldgen_libraries: $(LDGEN_LIBRARIES) $(ESPIDF)/make/ldgen.mk
printf "$(foreach library,$(LDGEN_LIBRARIES),$(library)\n)" > $(BUILD_ESPIDF_LIB)/ldgen_libraries
$(BUILD)/esp32.project.ld: $(ESPCOMP)/esp32/ld/esp32.project.ld.in $(LDGEN_FRAGMENTS) $(SDKCONFIG_COMBINED) $(BUILD_ESPIDF_LIB)/ldgen_libraries
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(ESPIDF)/tools/ldgen/ldgen.py \
--input $< \
--output $@ \
--config $(SDKCONFIG_COMBINED) \
--kconfig $(ESPIDF)/Kconfig \
--fragments $(LDGEN_FRAGMENTS) \
--libraries-file $(BUILD_ESPIDF_LIB)/ldgen_libraries \
--env "IDF_TARGET=esp32" \
--env "IDF_CMAKE=n" \
--env "COMPONENT_KCONFIGS=$(ESPCOMP_KCONFIGS)" \
--env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)" \
--env "IDF_PATH=$(ESPIDF)" \
--objdump $(OBJDUMP)
else
LDGEN_SECTIONS_INFO = $(foreach lib,$(LIB_ESPIDF),$(BUILD_ESPIDF_LIB)/$(lib)/lib$(lib).a.sections_info)
LDGEN_SECTION_INFOS = $(BUILD_ESPIDF_LIB)/ldgen.section_infos
define gen_sections_info_rule
$(1).sections_info: $(1)
$(ECHO) "GEN $(1).sections_info"
$(Q)$(OBJDUMP) -h $(1) > $(1).sections_info
endef
$(eval $(foreach lib,$(LIB_ESPIDF),$(eval $(call gen_sections_info_rule,$(BUILD_ESPIDF_LIB)/$(lib)/lib$(lib).a))))
$(LDGEN_SECTION_INFOS): $(LDGEN_SECTIONS_INFO) $(ESPIDF)/make/ldgen.mk
$(Q)printf "$(foreach info,$(LDGEN_SECTIONS_INFO),$(info)\n)" > $@
$(BUILD)/esp32.project.ld: $(ESPCOMP)/esp32/ld/esp32.project.ld.in $(LDGEN_FRAGMENTS) $(SDKCONFIG_COMBINED) $(LDGEN_SECTION_INFOS)
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(ESPIDF)/tools/ldgen/ldgen.py \
--input $< \
--output $@ \
--config $(SDKCONFIG_COMBINED) \
--kconfig $(ESPIDF)/Kconfig \
--fragments $(LDGEN_FRAGMENTS) \
--sections $(LDGEN_SECTION_INFOS) \
--env "IDF_TARGET=esp32" \
--env "IDF_CMAKE=n" \
--env "COMPONENT_KCONFIGS=$(ESPCOMP_KCONFIGS)" \
--env "COMPONENT_KCONFIGS_PROJBUILD=$(ESPCOMP_KCONFIGS_PROJBUILD)" \
--env "IDF_PATH=$(ESPIDF)"
endif
################################################################################
# Main targets
all: $(BUILD)/firmware.bin
.PHONY: idf-version deploy erase
idf-version:
$(ECHO) "ESP IDF supported hash: $(ESPIDF_SUPHASH)"
$(BUILD)/firmware.bin: $(BUILD)/bootloader.bin $(BUILD)/partitions.bin $(BUILD)/application.bin
$(ECHO) "Create $@"
$(Q)$(PYTHON) makeimg.py $^ $@
deploy: $(BUILD)/firmware.bin
$(ECHO) "Writing $^ to the board"
$(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) write_flash -z --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) 0x1000 $^
erase:
$(ECHO) "Erasing flash"
$(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) erase_flash
################################################################################
# Declarations to build the application
OBJ = $(OBJ_MP)
APP_LD_ARGS =
APP_LD_ARGS += $(LDFLAGS_MOD)
APP_LD_ARGS += $(addprefix -T,$(LD_FILES))
APP_LD_ARGS += --start-group
APP_LD_ARGS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
APP_LD_ARGS += -L$(dir $(LIBSTDCXX_FILE_NAME)) -lstdc++
APP_LD_ARGS += $(LIBC_LIBM)
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
APP_LD_ARGS += -L$(ESPCOMP)/xtensa/esp32 -lhal
APP_LD_ARGS += -L$(ESPCOMP)/bt/controller/lib -lbtdm_app
APP_LD_ARGS += -L$(ESPCOMP)/esp_wifi/lib_esp32 -lcore -lmesh -lnet80211 -lphy -lrtc -lpp -lsmartconfig -lcoexist
else
APP_LD_ARGS += $(ESPCOMP)/esp32/libhal.a
APP_LD_ARGS += -L$(ESPCOMP)/bt/lib -lbtdm_app
APP_LD_ARGS += -L$(ESPCOMP)/esp32/lib -lcore -lmesh -lnet80211 -lphy -lrtc -lpp -lwpa -lsmartconfig -lcoexist -lwps -lwpa2
endif
APP_LD_ARGS += $(OBJ)
APP_LD_ARGS += $(LIB)
APP_LD_ARGS += --end-group
$(BUILD)/esp32_out.ld: $(SDKCONFIG_H)
$(Q)$(CC) -I$(BUILD) -C -P -x c -E $(ESPCOMP)/esp32/ld/esp32.ld -o $@
$(BUILD)/application.bin: $(BUILD)/application.elf
$(ECHO) "Create $@"
$(Q)$(ESPTOOL) --chip esp32 elf2image --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) --flash_size $(FLASH_SIZE) $<
$(BUILD)/application.elf: $(OBJ) $(LIB) $(BUILD)/esp32_out.ld $(BUILD)/esp32.project.ld
$(ECHO) "LINK $@"
$(Q)$(LD) $(LDFLAGS) -o $@ $(APP_LD_ARGS)
$(Q)$(SIZE) $@
################################################################################
# Declarations to build the bootloader
BOOTLOADER_LIB_DIR = $(BUILD)/bootloader
BOOTLOADER_LIB_ALL =
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
$(BUILD)/bootloader/$(ESPCOMP)/%.o: CFLAGS += -DBOOTLOADER_BUILD=1 -I$(ESPCOMP)/bootloader_support/include_priv -I$(ESPCOMP)/bootloader_support/include -I$(ESPCOMP)/efuse/include -I$(ESPCOMP)/esp_rom/include -Wno-error=format \
-I$(ESPCOMP)/esp_common/include \
-I$(ESPCOMP)/xtensa/include \
-I$(ESPCOMP)/xtensa/esp32/include
else
$(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)/efuse/include -I$(ESPCOMP)/esp32 -Wno-error=format
endif
# libbootloader_support.a
BOOTLOADER_LIB_ALL += bootloader_support
BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
bootloader_support/src/bootloader_clock.o \
bootloader_support/src/bootloader_common.o \
bootloader_support/src/bootloader_flash.o \
bootloader_support/src/bootloader_flash_config.o \
bootloader_support/src/bootloader_init.o \
bootloader_support/src/bootloader_random.o \
bootloader_support/src/bootloader_utility.o \
bootloader_support/src/flash_qio_mode.o \
bootloader_support/src/esp_image_format.o \
bootloader_support/src/flash_encrypt.o \
bootloader_support/src/flash_partitions.o \
)
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ += $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
bootloader_support/src/esp32/bootloader_sha.o \
bootloader_support/src/bootloader_flash_config.o \
bootloader_support/src/esp32/secure_boot.o \
)
else
BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ += $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
bootloader_support/src/bootloader_sha.o \
bootloader_support/src/secure_boot_signatures.o \
bootloader_support/src/secure_boot.o \
)
endif
$(BOOTLOADER_LIB_DIR)/libbootloader_support.a: $(BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
# liblog.a
BOOTLOADER_LIB_ALL += log
BOOTLOADER_LIB_LOG_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
log/log.o \
)
$(BOOTLOADER_LIB_DIR)/liblog.a: $(BOOTLOADER_LIB_LOG_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
# libspi_flash.a
BOOTLOADER_LIB_ALL += spi_flash
BOOTLOADER_LIB_SPI_FLASH_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
spi_flash/spi_flash_rom_patch.o \
)
$(BOOTLOADER_LIB_DIR)/libspi_flash.a: $(BOOTLOADER_LIB_SPI_FLASH_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V3))
# libmicro-ecc.a
BOOTLOADER_LIB_ALL += micro-ecc
BOOTLOADER_LIB_MICRO_ECC_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
micro-ecc/micro-ecc/uECC.o \
)
$(BOOTLOADER_LIB_DIR)/libmicro-ecc.a: $(BOOTLOADER_LIB_MICRO_ECC_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
endif
# libsoc.a
$(BUILD)/bootloader/$(ESPCOMP)/soc/esp32/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conversion
BOOTLOADER_LIB_ALL += soc
BOOTLOADER_LIB_SOC_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/soc/,\
esp32/cpu_util.o \
esp32/gpio_periph.o \
esp32/rtc_clk.o \
esp32/rtc_clk_init.o \
esp32/rtc_init.o \
esp32/rtc_periph.o \
esp32/rtc_pm.o \
esp32/rtc_sleep.o \
esp32/rtc_time.o \
esp32/rtc_wdt.o \
esp32/sdio_slave_periph.o \
esp32/sdmmc_periph.o \
esp32/soc_memory_layout.o \
esp32/spi_periph.o \
src/memory_layout_utils.o \
)
$(BOOTLOADER_LIB_DIR)/libsoc.a: $(BOOTLOADER_LIB_SOC_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
# libmain.a
BOOTLOADER_LIB_ALL += main
BOOTLOADER_LIB_MAIN_OBJ = $(addprefix $(BUILD)/bootloader/$(ESPCOMP)/,\
bootloader/subproject/main/bootloader_start.o \
)
$(BOOTLOADER_LIB_DIR)/libmain.a: $(BOOTLOADER_LIB_MAIN_OBJ)
$(ECHO) "AR $@"
$(Q)$(AR) cr $@ $^
# all objects files
BOOTLOADER_OBJ_ALL = \
$(BOOTLOADER_LIB_BOOTLOADER_SUPPORT_OBJ) \
$(BOOTLOADER_LIB_LOG_OBJ) \
$(BOOTLOADER_LIB_SPI_FLASH_OBJ) \
$(BOOTLOADER_LIB_MICRO_ECC_OBJ) \
$(BOOTLOADER_LIB_SOC_OBJ) \
$(BOOTLOADER_LIB_MAIN_OBJ)
$(BOOTLOADER_OBJ_ALL): $(SDKCONFIG_H)
BOOTLOADER_LIBS =
BOOTLOADER_LIBS += -Wl,--start-group
BOOTLOADER_LIBS += $(BOOTLOADER_OBJ)
BOOTLOADER_LIBS += -L$(BUILD)/bootloader $(addprefix -l,$(BOOTLOADER_LIB_ALL))
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
BOOTLOADER_LIBS += -L$(ESPCOMP)/esp_wifi/lib_esp32 -lrtc
else
BOOTLOADER_LIBS += -L$(ESPCOMP)/esp32/lib -lrtc
endif
BOOTLOADER_LIBS += -L$(dir $(LIBGCC_FILE_NAME)) -lgcc
BOOTLOADER_LIBS += -Wl,--end-group
BOOTLOADER_LDFLAGS =
BOOTLOADER_LDFLAGS += -nostdlib
BOOTLOADER_LDFLAGS += -L$(ESPIDF)/lib
BOOTLOADER_LDFLAGS += -L$(ESPIDF)/ld
BOOTLOADER_LDFLAGS += -u call_user_start_cpu0
BOOTLOADER_LDFLAGS += -Wl,--gc-sections
BOOTLOADER_LDFLAGS += -static
BOOTLOADER_LDFLAGS += -Wl,-EL
BOOTLOADER_LDFLAGS += -Wl,-Map=$(@:.elf=.map) -Wl,--cref
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.ld
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/bootloader/subproject/main/esp32.bootloader.rom.ld
ifeq ($(ESPIDF_CURHASH),$(ESPIDF_SUPHASH_V4))
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp_rom/esp32/ld/esp32.rom.ld
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
else
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.ld
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.rom.spiram_incompatible_fns.ld
endif
BOOTLOADER_LDFLAGS += -T $(ESPCOMP)/esp32/ld/esp32.peripherals.ld
BOOTLOADER_OBJ_DIRS = $(sort $(dir $(BOOTLOADER_OBJ_ALL)))
$(BOOTLOADER_OBJ_ALL): | $(BOOTLOADER_OBJ_DIRS)
$(BOOTLOADER_OBJ_DIRS):
$(MKDIR) -p $@
$(BUILD)/bootloader/%.o: %.c
$(call compile_c)
$(BUILD)/bootloader.bin: $(BUILD)/bootloader.elf
$(ECHO) "Create $@"
$(Q)$(ESPTOOL) --chip esp32 elf2image --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) --flash_size $(FLASH_SIZE) $<
$(BUILD)/bootloader.elf: $(BOOTLOADER_OBJ) $(addprefix $(BOOTLOADER_LIB_DIR)/lib,$(addsuffix .a,$(BOOTLOADER_LIB_ALL)))
$(ECHO) "LINK $@"
$(Q)$(CC) $(BOOTLOADER_LDFLAGS) -o $@ $(BOOTLOADER_LIBS)
################################################################################
# Declarations to build the partitions
PYTHON2 ?= python2
# Can be overriden by mkconfigboard.mk.
PART_SRC ?= partitions.csv
$(BUILD)/partitions.bin: $(PART_SRC)
$(ECHO) "Create $@"
$(Q)$(PYTHON2) $(ESPCOMP)/partition_table/gen_esp32part.py -q $< $@
################################################################################
include $(TOP)/py/mkrules.mk