Skip to content

Commit f4b9153

Browse files
committed
Update support for ESP-IDF according to v3.3 // Issue #224
1 parent 2c1b430 commit f4b9153

File tree

28 files changed

+13135
-238
lines changed

28 files changed

+13135
-238
lines changed

builder/frameworks/espidf.py

Lines changed: 171 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,21 @@ def build_component(path, component_config):
157157
CPPDEFINES=component_config.get("cpp_defines", []),
158158
)
159159

160-
return envsafe.BuildLibrary(
160+
component = envsafe.BuildLibrary(
161161
join("$BUILD_DIR", "%s" % basename(path)), path,
162-
src_filter=component_config.get("src_filter", "+<*> -<test*>")
162+
src_filter=component_config.get("src_filter", "+<*> -<test*>"))
163+
164+
component_sections = env.Command(
165+
"${SOURCE}.sections_info", component,
166+
env.VerboseAction(
167+
"xtensa-esp32-elf-objdump -h $SOURCE > $TARGET", "Generating $TARGET")
163168
)
164169

170+
# Section files are used in linker script generation process
171+
env.Depends("$BUILD_DIR/esp32.project.ld", component_sections)
172+
173+
return component
174+
165175

166176
def get_sdk_configuration(config_path):
167177
if not isfile(config_path):
@@ -180,13 +190,13 @@ def get_sdk_configuration(config_path):
180190
return config
181191

182192

183-
def find_valid_config_file():
193+
def find_valid_example_file(filename):
184194
search_path = join(
185-
platform.get_dir(), "examples", "*", "src", "sdkconfig.h")
195+
platform.get_dir(), "examples", "*", "src", filename)
186196
files = glob(search_path)
187197
if not files:
188198
sys.stderr.write(
189-
"Error: Could not find default \"sdkconfig.h\" file\n")
199+
"Error: Could not find default %s file\n" % filename)
190200
env.Exit(1)
191201
return files[0]
192202

@@ -302,6 +312,26 @@ def build_wpa_supplicant_lib():
302312
join(FRAMEWORK_DIR, "components", "wpa_supplicant"), config)
303313

304314

315+
def build_wifi_provisioning_lib():
316+
src_filter = "-<*>"
317+
for d in ["proto-c", "src"]:
318+
src_filter += " +<%s>" % d
319+
320+
if not (is_set("CONFIG_BT_ENABLED", sdk_params) and is_set(
321+
"CONFIG_BLUEDROID_ENABLED", sdk_params)):
322+
src_filter += " -<src/scheme_ble.c>"
323+
324+
inc_dirs = ["src", "proto-c", "../protocomm/proto-c"]
325+
326+
config = {
327+
"inc_dirs": inc_dirs,
328+
"src_filter": src_filter
329+
}
330+
331+
return build_component(
332+
join(FRAMEWORK_DIR, "components", "wifi_provisioning"), config)
333+
334+
305335
def build_heap_lib(sdk_params):
306336
src_filter = "+<*> -<test*>"
307337
if is_set("CONFIG_HEAP_POISONING_DISABLED", sdk_params):
@@ -375,11 +405,68 @@ def build_espidf_bootloader():
375405
join("$BUILD_DIR", "bootloader.elf"),
376406
envsafe.CollectBuildFiles(
377407
join("$BUILD_DIR", "bootloader"),
378-
join(FRAMEWORK_DIR, "components", "bootloader", "subproject", "main")
408+
join(FRAMEWORK_DIR, "components", "bootloader", "subproject",
409+
"main")
379410
)
380411
)
381412

382413

414+
def generate_section_info(target, source, env):
415+
with open(target[0].get_path(), "w") as fp:
416+
fp.write("\n".join(s.get_path() + ".sections_info" for s in source))
417+
418+
return None
419+
420+
421+
def find_framework_service_files(search_path):
422+
result = {}
423+
result['lf_files'] = list()
424+
result['kconfig_files'] = list()
425+
result['kconfig_build_files'] = list()
426+
for d in listdir(search_path):
427+
for f in listdir(join(search_path, d)):
428+
if f == "linker.lf":
429+
result['lf_files'].append(join(search_path, d, f))
430+
elif f == "Kconfig.projbuild":
431+
result['kconfig_build_files'].append(join(search_path, d, f))
432+
elif f == "Kconfig":
433+
result['kconfig_files'].append(join(search_path, d, f))
434+
435+
result['lf_files'].append(
436+
join(FRAMEWORK_DIR, "components", "esp32", "ld", "esp32_fragments.lf"))
437+
438+
return result
439+
440+
441+
def generate_project_ld_script(target, source, env):
442+
project_files = find_framework_service_files(
443+
join(FRAMEWORK_DIR, "components"))
444+
445+
args = {
446+
"script": join(FRAMEWORK_DIR, "tools", "ldgen", "ldgen.py"),
447+
"sections": source[0].get_path(),
448+
"input": join(
449+
FRAMEWORK_DIR, "components", "esp32", "ld", "esp32.project.ld.in"),
450+
"sdk_header": join(env.subst("$PROJECTSRC_DIR"), "sdkconfig.h"),
451+
"fragments": " ".join(
452+
["\"%s\"" % f for f in project_files.get("lf_files")]),
453+
"output": target[0].get_path(),
454+
"kconfig": join(FRAMEWORK_DIR, "Kconfig"),
455+
"kconfigs_projbuild": "COMPONENT_KCONFIGS_PROJBUILD=%s" % "#".join(
456+
["%s" % f for f in project_files.get("kconfig_build_files")]),
457+
"kconfig_files": "COMPONENT_KCONFIGS=%s" % "#".join(
458+
["%s" % f for f in project_files.get("kconfig_files")]),
459+
}
460+
461+
cmd = ('"$PYTHONEXE" "{script}" --sections "{sections}" --input "{input}" '
462+
'--config "{sdk_header}" --fragments {fragments} --output "{output}" '
463+
'--kconfig "{kconfig}" --env "{kconfigs_projbuild}" '
464+
'--env "{kconfig_files}" --env "IDF_CMAKE=n" '
465+
'--env "IDF_TARGET=\\\"esp32\\\""').format(**args)
466+
467+
env.Execute(cmd)
468+
469+
383470
def build_arduino_framework():
384471
core = env.BoardConfig().get("build.core")
385472

@@ -473,14 +560,18 @@ def configure_exceptions(sdk_params):
473560
"libcoap", "include", "coap"),
474561
join(FRAMEWORK_DIR, "components", "console"),
475562
join(FRAMEWORK_DIR, "components", "driver", "include"),
563+
join(FRAMEWORK_DIR, "components", "efuse", "include"),
564+
join(FRAMEWORK_DIR, "components", "efuse", "esp32", "include"),
476565
join(FRAMEWORK_DIR, "components", "esp-tls"),
477566
join(FRAMEWORK_DIR, "components", "esp_adc_cal", "include"),
478567
join(FRAMEWORK_DIR, "components", "esp_event", "include"),
479568
join(FRAMEWORK_DIR, "components", "esp_http_client", "include"),
480569
join(FRAMEWORK_DIR, "components", "esp_http_server", "include"),
570+
join(FRAMEWORK_DIR, "components", "esp_https_server", "include"),
481571
join(FRAMEWORK_DIR, "components", "esp_https_ota", "include"),
482572
join(FRAMEWORK_DIR, "components", "esp_ringbuf", "include"),
483573
join(FRAMEWORK_DIR, "components", "esp32", "include"),
574+
join(FRAMEWORK_DIR, "components", "espcoredump", "include"),
484575
join(FRAMEWORK_DIR, "components", "ethernet", "include"),
485576
join(FRAMEWORK_DIR, "components", "expat", "expat", "lib"),
486577
join(FRAMEWORK_DIR, "components", "expat", "port", "include"),
@@ -525,6 +616,8 @@ def configure_exceptions(sdk_params):
525616
join(FRAMEWORK_DIR, "components", "spiffs", "include"),
526617
join(FRAMEWORK_DIR, "components", "tcp_transport", "include"),
527618
join(FRAMEWORK_DIR, "components", "tcpip_adapter", "include"),
619+
join(FRAMEWORK_DIR, "components", "unity", "include"),
620+
join(FRAMEWORK_DIR, "components", "unity", "unity", "src"),
528621
join(FRAMEWORK_DIR, "components", "ulp", "include"),
529622
join(FRAMEWORK_DIR, "components", "vfs", "include"),
530623
join(FRAMEWORK_DIR, "components", "wear_levelling", "include"),
@@ -557,14 +650,17 @@ def configure_exceptions(sdk_params):
557650
if (d == "include"):
558651
env.Prepend(CPPPATH=[join(root, d)])
559652

560-
561653
env.Prepend(
562654
CFLAGS=["-Wno-old-style-declaration"],
563655

564656
CPPDEFINES=[
565657
"WITH_POSIX",
658+
"UNITY_INCLUDE_CONFIG_H",
566659
("IDF_VER", '\\"%s\\"' %
567-
platform.get_package_version("framework-espidf"))
660+
platform.get_package_version("framework-espidf")),
661+
("PROJECT_VER", '\\"%s\\"' % "1.0.0"),
662+
("PROJECT_NAME", '\\"%s\\"' % basename(env.subst("$PROJECT_DIR")))
663+
568664
],
569665

570666
CCFLAGS=[
@@ -582,8 +678,9 @@ def configure_exceptions(sdk_params):
582678
env.Append(
583679
LINKFLAGS=[
584680
"-u", "__cxa_guard_dummy",
681+
"-u", "esp_app_desc",
585682
"-u", "ld_include_panic_highint_hdl",
586-
"-T", "esp32.common.ld",
683+
"-T", "esp32.project.ld",
587684
"-T", "esp32.rom.ld",
588685
"-T", "esp32.peripherals.ld",
589686
"-T", "esp32.rom.libgcc.ld",
@@ -607,35 +704,40 @@ def configure_exceptions(sdk_params):
607704
env.Replace(ASFLAGS=[])
608705

609706
#
610-
# Handle missing sdkconfig.h
707+
# Handle missing sdkconfig files
611708
#
612709

613-
sdk_config_file = join(env.subst("$PROJECTSRC_DIR"), "sdkconfig.h")
614710

615-
if not isfile(sdk_config_file):
616-
print("Warning! Cannot find \"sdkconfig.h\" file. "
617-
"Default \"sdkconfig.h\" will be added to your project!")
618-
copy(find_valid_config_file(), sdk_config_file)
619-
else:
620-
is_new = False
621-
with open(sdk_config_file) as fp:
622-
for l in fp.readlines():
623-
if "CONFIG_PTHREAD_STACK_MIN" in l:
624-
is_new = True
625-
break
626-
627-
if not is_new:
628-
print("Warning! Detected an outdated \"sdkconfig.h\" file. "
629-
"The old \"sdkconfig.h\" will be replaced by the new one.")
630-
631-
new_config = find_valid_config_file()
632-
copy(
633-
sdk_config_file,
634-
join(env.subst("$PROJECTSRC_DIR"), "sdkconfig.h.bak")
635-
)
636-
copy(new_config, sdk_config_file)
711+
def process_project_configs(filename):
712+
config = join(env.subst("$PROJECTSRC_DIR"), filename)
713+
if not isfile(config):
714+
print("Warning! Cannot find %s file. Default "
715+
"file will be added to your project!" % filename)
716+
copy(find_valid_example_file(filename), config)
717+
else:
718+
is_new = False
719+
with open(config) as fp:
720+
for l in fp.readlines():
721+
if "CONFIG_APP_COMPILE_TIME_DATE" in l:
722+
is_new = True
723+
break
724+
725+
if not is_new:
726+
print("Warning! Detected an outdated %s file. The old "
727+
"file will be replaced by the new one." % filename)
728+
729+
new_config = find_valid_example_file(filename)
730+
copy(config, join(
731+
env.subst("$PROJECTSRC_DIR"), "%s.bak" % filename))
732+
copy(new_config, config)
733+
637734

638-
sdk_params = get_sdk_configuration(sdk_config_file)
735+
process_project_configs("sdkconfig")
736+
sdk_config = join(env.subst("$PROJECTSRC_DIR"), "sdkconfig")
737+
738+
process_project_configs("sdkconfig.h")
739+
sdk_config_header = join(env.subst("$PROJECTSRC_DIR"), "sdkconfig.h")
740+
sdk_params = get_sdk_configuration(sdk_config_header)
639741

640742
configure_exceptions(sdk_params)
641743

@@ -689,35 +791,23 @@ def configure_exceptions(sdk_params):
689791

690792
libs = []
691793

692-
if ulp_lib:
693-
if not is_ulp_enabled(sdk_params):
694-
print("Warning! ULP is not properly configured. "
695-
"Add the next configuration lines to your sdkconfig.h:")
696-
print (" #define CONFIG_ULP_COPROC_ENABLED 1")
697-
print (" #define CONFIG_ULP_COPROC_RESERVE_MEM 1024")
698-
699-
libs.append(ulp_lib)
700-
env.Append(
701-
CPPPATH=[join("$BUILD_DIR", "ulp_app")],
702-
LIBPATH=[join("$BUILD_DIR", "ulp_app")],
703-
LINKFLAGS=["-T", "ulp_main.ld"]
704-
)
705-
706794
ignore_dirs = (
707795
"bootloader",
708796
"esptool_py",
709-
"espcoredump",
710797
"idf_test",
711798
"partition_table"
712799
)
713800

714801
special_src_filter = {
715802
"app_trace": "+<*> -<test> -<sys_view> -<gcov>",
803+
"asio": "-<*> +<asio/asio/src/asio.cpp>",
716804
"aws_iot": "-<*> +<port> +<aws-iot-device-sdk-embedded-C/src>",
717805
"esp32": "-<*> +<*.[sSc]*> +<hwcrypto>",
718806
"bootloader_support": "+<*> -<test> -<src/bootloader_init.c>",
719807
"soc": "+<*> -<test> -<esp32/test>",
720-
"spi_flash": "+<*> -<test*> -<sim>"
808+
"spi_flash": "+<*> -<test*> -<sim>",
809+
"efuse": "+<*> -<test*>",
810+
"unity": "-<*> +<unity/src> +<*.c>"
721811
}
722812

723813
special_env = (
@@ -726,17 +816,17 @@ def configure_exceptions(sdk_params):
726816
"lwip",
727817
"protocomm",
728818
"libsodium",
729-
"wpa_supplicant"
819+
"wpa_supplicant",
820+
"wifi_provisioning"
730821
)
731822

732823
for d in listdir(join(FRAMEWORK_DIR, "components")):
733824
if d in special_src_filter or d in special_env or d in ignore_dirs:
734825
continue
735826
component_dir = join(FRAMEWORK_DIR, "components", d)
736827
if isdir(component_dir):
737-
libs.append(
738-
build_component(component_dir,
739-
extract_component_config(component_dir)))
828+
libs.append(build_component(
829+
component_dir, extract_component_config(component_dir)))
740830

741831

742832
for component, src_filter in special_src_filter.items():
@@ -751,9 +841,35 @@ def configure_exceptions(sdk_params):
751841
build_heap_lib(sdk_params),
752842
build_rtos_lib(),
753843
build_libsodium_lib(),
754-
build_wpa_supplicant_lib()
844+
build_wpa_supplicant_lib(),
845+
build_wifi_provisioning_lib()
755846
))
756847

848+
project_sections = env.Command(
849+
join("$BUILD_DIR", "ldgen.section_infos"), libs, generate_section_info)
850+
851+
project_linker_script = env.Command(
852+
join("$BUILD_DIR", "esp32.project.ld"),
853+
project_sections, generate_project_ld_script,
854+
ENV={"PYTHONPATH": join(FRAMEWORK_DIR, "platformio", "package_deps",
855+
"py%d" % sys.version_info.major)})
856+
857+
env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", project_linker_script)
858+
859+
if ulp_lib:
860+
if not is_ulp_enabled(sdk_params):
861+
print("Warning! ULP is not properly configured."
862+
"Add next configuration lines to your sdkconfig.h:")
863+
print (" #define CONFIG_ULP_COPROC_ENABLED 1")
864+
print (" #define CONFIG_ULP_COPROC_RESERVE_MEM 1024")
865+
866+
libs.append(ulp_lib)
867+
env.Append(
868+
CPPPATH=[join("$BUILD_DIR", "ulp_app")],
869+
LIBPATH=[join("$BUILD_DIR", "ulp_app")],
870+
LINKFLAGS=["-T", "ulp_main.ld"]
871+
)
872+
757873
#
758874
# Process Arduino core
759875
#

0 commit comments

Comments
 (0)