1414
1515import fnmatch
1616import os
17- import contextlib
1817import json
1918import requests
2019import socket
3231# Constants
3332RETRY_LIMIT = 3
3433SUBPROCESS_TIMEOUT = 300
35- MKLITTLEFS_VERSION_320 = "3.2.0"
36- MKLITTLEFS_VERSION_400 = "4.0.0"
3734DEFAULT_DEBUG_SPEED = "5000"
3835DEFAULT_APP_OFFSET = "0x10000"
3936ARDUINO_ESP32_PACKAGE_URL = "https://raw.githubusercontent.com/espressif/arduino-esp32/master/package/package_esp32_index.template.json"
@@ -337,11 +334,11 @@ def _handle_existing_tool(
337334
338335 # Then remove the main tool directory (if it still exists)
339336 safe_remove_directory (paths ['tool_path' ])
340-
337+
341338 return self .install_tool (tool_name , retry_count + 1 )
342339
343340 def _configure_arduino_framework (self , frameworks : List [str ]) -> None :
344- """Configure Arduino framework with dynamic library URL fetching. """
341+ """Configure Arduino framework"""
345342 if "arduino" not in frameworks :
346343 return
347344
@@ -442,6 +439,7 @@ def _install_common_idf_packages(self) -> None:
442439 def _configure_check_tools (self , variables : Dict ) -> None :
443440 """Configure static analysis and check tools based on configuration."""
444441 check_tools = variables .get ("check_tool" , [])
442+ self .install_tool ("contrib-piohome" )
445443 if not check_tools :
446444 return
447445
@@ -457,37 +455,38 @@ def _ensure_mklittlefs_version(self) -> None:
457455 try :
458456 with open (piopm_path , 'r' , encoding = 'utf-8' ) as f :
459457 package_data = json .load (f )
460- if package_data .get ('version' ) != MKLITTLEFS_VERSION_320 :
458+ version = package_data .get ('version' , '' )
459+ if not version .startswith ("3." ):
461460 os .remove (piopm_path )
462- logger .info ("Outdated mklittlefs version removed" )
461+ logger .info (f"Incompatible mklittlefs version { version } removed (required: 3.x) " )
463462 except (json .JSONDecodeError , KeyError ) as e :
464463 logger .error (f"Error reading mklittlefs package data: { e } " )
465464
466465 def _setup_mklittlefs_for_download (self ) -> None :
467- """Setup mklittlefs for download functionality with version 4.0.0 ."""
466+ """Setup mklittlefs for download functionality with version 4.x ."""
468467 mklittlefs_dir = os .path .join (self .packages_dir , "tool-mklittlefs" )
469- mklittlefs400_dir = os .path .join (
470- self .packages_dir , "tool-mklittlefs-4.0.0 "
468+ mklittlefs4_dir = os .path .join (
469+ self .packages_dir , "tool-mklittlefs4 "
471470 )
472471
473- # Ensure mklittlefs 3.2.0 is installed
472+ # Ensure mklittlefs 3.x is installed
474473 if not os .path .exists (mklittlefs_dir ):
475474 self .install_tool ("tool-mklittlefs" )
476475 if os .path .exists (os .path .join (mklittlefs_dir , "tools.json" )):
477476 self .install_tool ("tool-mklittlefs" )
478477
479- # Install mklittlefs 4.0.0
480- if not os .path .exists (mklittlefs400_dir ):
481- self .install_tool ("tool-mklittlefs-4.0.0 " )
482- if os .path .exists (os .path .join (mklittlefs400_dir , "tools.json" )):
483- self .install_tool ("tool-mklittlefs-4.0.0 " )
478+ # Install mklittlefs 4.x
479+ if not os .path .exists (mklittlefs4_dir ):
480+ self .install_tool ("tool-mklittlefs4 " )
481+ if os .path .exists (os .path .join (mklittlefs4_dir , "tools.json" )):
482+ self .install_tool ("tool-mklittlefs4 " )
484483
485- # Copy mklittlefs 4.0.0 over 3.2.0
486- if os .path .exists (mklittlefs400_dir ):
484+ # Copy mklittlefs 4.x over 3.x
485+ if os .path .exists (mklittlefs4_dir ):
487486 package_src = os .path .join (mklittlefs_dir , "package.json" )
488- package_dst = os .path .join (mklittlefs400_dir , "package.json" )
487+ package_dst = os .path .join (mklittlefs4_dir , "package.json" )
489488 safe_copy_file (package_src , package_dst )
490- shutil .copytree (mklittlefs400_dir , mklittlefs_dir , dirs_exist_ok = True )
489+ shutil .copytree (mklittlefs4_dir , mklittlefs_dir , dirs_exist_ok = True )
491490 self .packages .pop ("tool-mkfatfs" , None )
492491
493492 def _handle_littlefs_tool (self , for_download : bool ) -> None :
@@ -542,6 +541,7 @@ def configure_default_packages(self, variables: Dict, targets: List[str]) -> Any
542541 self ._configure_arduino_framework (frameworks )
543542 self ._configure_espidf_framework (frameworks , variables , board_config , mcu )
544543 self ._configure_mcu_toolchains (mcu , variables , targets )
544+ self ._handle_littlefs_tool (for_download = False ) # Ensure mklittlefs is installed
545545
546546 if "espidf" in frameworks :
547547 self ._install_common_idf_packages ()
0 commit comments