Created
February 19, 2024 19:35
-
-
Save jepler/a1eb2fb95c48ede5cb6035caa57de783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 5b3d37f6f19e951e412a921b877b61eb57e76668 Mon Sep 17 00:00:00 2001 | |
From: Jeff Epler <[email protected]> | |
Date: Mon, 19 Feb 2024 13:25:38 -0600 | |
Subject: [PATCH] espressif: add a script to check for incompatibilities... | |
betweek sdkconfig and circuitpython. For now there's a single check, | |
for CIRCUITPY_STORAGE_EXTEND & CIRCUITPY_DUALBANK that require | |
there to be an ota_1 partition. | |
--- | |
ports/espressif/Makefile | 7 ++++- | |
ports/espressif/tools/check-sdkconfig.py | 38 ++++++++++++++++++++++++ | |
2 files changed, 44 insertions(+), 1 deletion(-) | |
create mode 100755 ports/espressif/tools/check-sdkconfig.py | |
diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile | |
index 52145d21b7..7eff93736b 100644 | |
--- a/ports/espressif/Makefile | |
+++ b/ports/espressif/Makefile | |
@@ -417,7 +417,12 @@ endif | |
do-sdkconfig: $(BUILD)/esp-idf/config/sdkconfig.h | |
QSTR_GLOBAL_REQUIREMENTS += $(BUILD)/esp-idf/config/sdkconfig.h | |
$(BUILD)/esp-idf/config/sdkconfig.h: boards/$(BOARD)/sdkconfig boards/$(BOARD)/mpconfigboard.mk CMakeLists.txt | $(BUILD)/esp-idf | |
- IDF_PATH=$(IDF_PATH) cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-$(IDF_TARGET).cmake -DIDF_TARGET=$(IDF_TARGET) -GNinja | |
+ $(STEPECHO) "LINK $@" | |
+ $(Q)env IDF_PATH=$(IDF_PATH) cmake -S . -B $(BUILD)/esp-idf -DSDKCONFIG=$(BUILD)/esp-idf/sdkconfig -DSDKCONFIG_DEFAULTS="$(SDKCONFIGS)" -DCMAKE_TOOLCHAIN_FILE=$(IDF_PATH)/tools/cmake/toolchain-$(IDF_TARGET).cmake -DIDF_TARGET=$(IDF_TARGET) -GNinja | |
+ $(Q)$(PYTHON) tools/check-sdkconfig.py \ | |
+ CIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK) \ | |
+ CIRCUITPY_STORAGE_EXTEND=$(CIRCUITPY_STORAGE_EXTEND) \ | |
+ $@ | |
# build a lib | |
# Adding -d explain -j 1 -v to the ninja line will output debug info | |
diff --git a/ports/espressif/tools/check-sdkconfig.py b/ports/espressif/tools/check-sdkconfig.py | |
new file mode 100755 | |
index 0000000000..2f807cfe20 | |
--- /dev/null | |
+++ b/ports/espressif/tools/check-sdkconfig.py | |
@@ -0,0 +1,38 @@ | |
+#!/usr/bin/env python3 | |
+import sys | |
+ | |
+sdk_config = {} | |
+ | |
+config_h = sys.argv[-1] | |
+with open(config_h) as f: | |
+ for row in f: | |
+ if row.startswith("#define "): | |
+ _, k, v = row.strip().split(None, 2) | |
+ # ad-hoc handle lines like '#define CONFIG_TCP_MSL CONFIG_LWIP_TCP_MSL' | |
+ v = sdk_config.get(k, v) | |
+ if v[0] == '"': | |
+ v = eval(v) # Assume it is a simple C string | |
+ | |
+ # ad-hoc convert to integer | |
+ try: | |
+ v = int(v) | |
+ except ValueError: | |
+ pass | |
+ sdk_config[k] = v | |
+ | |
+del sys.argv[-1] | |
+ | |
+circuitpy_config = {} | |
+for arg in sys.argv[1:]: | |
+ k, v = arg.split("=", 1) | |
+ circuitpy_config[k] = int(v) | |
+ | |
+partition_table = sdk_config.get("CONFIG_PARTITION_TABLE_FILENAME") | |
+for var in ("CIRCUITPY_STORAGE_EXTEND", "CIRCUITPY_DUALBANK"): | |
+ if circuitpy_config.get(var): | |
+ with open(partition_table) as f: | |
+ content = f.read() | |
+ if not "ota_1" in content: | |
+ raise SystemExit(f"{var} is incompatible with {partition_table=} (no ota_1 partition)") | |
+ | |
+ # Add more checks here | |
-- | |
2.39.2 | |
also strings are handled in the .h parser but not in the command-line arg parser
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Let's never call
eval()
. Someone might submit a poison PR with bad things in the sdkconfig.