|
20 | 20 | import sys |
21 | 21 | from os.path import isfile, join |
22 | 22 | from pathlib import Path |
| 23 | +import importlib.util |
23 | 24 |
|
24 | 25 | from SCons.Script import ( |
25 | 26 | ARGUMENTS, |
|
40 | 41 | platform = env.PioPlatform() |
41 | 42 | projectconfig = env.GetProjectConfig() |
42 | 43 | terminal_cp = locale.getpreferredencoding().lower() |
43 | | -FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32") |
44 | | -platformio_dir = projectconfig.get("platformio", "core_dir") |
| 44 | +platform_dir = Path(env.PioPlatform().get_dir()) |
| 45 | +framework_dir = platform.get_package_dir("framework-arduinoespressif32") |
| 46 | +core_dir = projectconfig.get("platformio", "core_dir") |
| 47 | +build_dir = Path(projectconfig.get("platformio", "build_dir")) |
45 | 48 |
|
46 | 49 | # Setup Python virtual environment and get executable paths |
47 | | -PYTHON_EXE, esptool_binary_path = setup_python_environment(env, platform, platformio_dir) |
| 50 | +PYTHON_EXE, esptool_binary_path = setup_python_environment(env, platform, core_dir) |
48 | 51 |
|
| 52 | +# Initialize board configuration and MCU settings |
| 53 | +board = env.BoardConfig() |
| 54 | +board_id = env.subst("$BOARD") |
| 55 | +mcu = board.get("build.mcu", "esp32") |
| 56 | +is_xtensa = mcu in ("esp32", "esp32s2", "esp32s3") |
| 57 | +toolchain_arch = "xtensa-%s" % mcu |
| 58 | +filesystem = board.get("build.filesystem", "littlefs") |
| 59 | + |
| 60 | + |
| 61 | +def load_board_script(env): |
| 62 | + if not board_id: |
| 63 | + return |
| 64 | + |
| 65 | + script_path = platform_dir / "boards" / f"{board_id}.py" |
| 66 | + |
| 67 | + if script_path.exists(): |
| 68 | + try: |
| 69 | + spec = importlib.util.spec_from_file_location( |
| 70 | + f"board_{board_id}", |
| 71 | + str(script_path) |
| 72 | + ) |
| 73 | + board_module = importlib.util.module_from_spec(spec) |
| 74 | + spec.loader.exec_module(board_module) |
| 75 | + |
| 76 | + if hasattr(board_module, 'configure_board'): |
| 77 | + board_module.configure_board(env) |
| 78 | + |
| 79 | + except Exception as e: |
| 80 | + print(f"Error loading board script {board_id}.py: {e}") |
49 | 81 |
|
50 | 82 | def BeforeUpload(target, source, env): |
51 | 83 | """ |
@@ -412,12 +444,8 @@ def switch_off_ldf(): |
412 | 444 | projectconfig.set(env_section, "lib_ldf_mode", "off") |
413 | 445 |
|
414 | 446 |
|
415 | | -# Initialize board configuration and MCU settings |
416 | | -board = env.BoardConfig() |
417 | | -mcu = board.get("build.mcu", "esp32") |
418 | | -is_xtensa = mcu in ("esp32", "esp32s2", "esp32s3") |
419 | | -toolchain_arch = "xtensa-%s" % mcu |
420 | | -filesystem = board.get("build.filesystem", "littlefs") |
| 447 | +# Board specific script |
| 448 | +load_board_script(env) |
421 | 449 |
|
422 | 450 | # Set toolchain architecture for RISC-V based ESP32 variants |
423 | 451 | if not is_xtensa: |
@@ -706,7 +734,7 @@ def firmware_metrics(target, source, env): |
706 | 734 | "espressif32.html#over-the-air-ota-update\n" |
707 | 735 | ) |
708 | 736 | env.Replace( |
709 | | - UPLOADER=str(Path(FRAMEWORK_DIR).resolve() / "tools" / "espota.py"), |
| 737 | + UPLOADER=str(Path(framework_dir).resolve() / "tools" / "espota.py"), |
710 | 738 | UPLOADERFLAGS=["--debug", "--progress", "-i", "$UPLOAD_PORT"], |
711 | 739 | UPLOADCMD=f'"{PYTHON_EXE}" "$UPLOADER" $UPLOADERFLAGS -f $SOURCE', |
712 | 740 | ) |
|
0 commit comments