Skip to content

Commit

Permalink
Fix toolchain issues
Browse files Browse the repository at this point in the history
Fix IDF version detection
Fix python detection
  • Loading branch information
mikee47 committed Jan 3, 2024
1 parent 41cb471 commit 7091536
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
1 change: 0 additions & 1 deletion Sming/Arch/Esp32/Components/esp32/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ endif

GLOBAL_CFLAGS += -DSOC_XTAL_FREQ_MHZ=CONFIG_XTAL_FREQ

IDF_VERSION := $(firstword $(subst -, ,$(IDF_VER)))
IDF_VERSION_4 := $(filter v4%,$(IDF_VERSION))

ifneq (,$(filter esp32s3-v4.3%,$(ESP_VARIANT)-$(IDF_VER)))
Expand Down
23 changes: 11 additions & 12 deletions Sming/Arch/Esp32/Tools/idf_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ def get_tool_info(soc):
compiler_prefix = None
compiler_version = None
for tool in tools_info['tools']:
if soc in tool['supported_targets']:
desc = tool['description']
if desc.startswith('Toolchain'):
compiler_prefix = tool['name']
compiler_version = tool['versions'][0]['name']
break
print(f"{compiler_prefix} {compiler_version}")

# ESP32_COMPILER_PREFIX=compiler_prefix
# IDF_TARGET_ARCH_RISCV=is_riscv


if tool.get('install') != 'always':
continue
if soc not in tool['supported_targets']:
continue
desc = tool['description']
if not desc.startswith('Toolchain'):
continue
tool_name = tool['name']
tool_version = tool['versions'][0]['name']
break
print(f"{tool_name} {tool_version}")


if __name__ == '__main__':
Expand Down
7 changes: 6 additions & 1 deletion Sming/Arch/Esp32/Tools/install.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ set IDF_REQUIREMENTS="%IDF_PATH%\requirements.txt"
if not exist "%IDF_REQUIREMENTS%" set IDF_REQUIREMENTS="%IDF_PATH%\tools\requirements\requirements.core.txt"
python -m pip install -r "%IDF_REQUIREMENTS%"

if "%INSTALL_IDF_VER%"=="5.0" python "%IDF_PATH%\tools\idf_tools.py" --non-interactive install-python-env
if "%INSTALL_IDF_VER%" == "5.0" goto :install_python
if "%INSTALL_IDF_VER%" == "5.2" goto :install_python
goto :EOF

:install_python
python "%IDF_PATH%\tools\idf_tools.py" --non-interactive install-python-env
44 changes: 25 additions & 19 deletions Sming/Arch/Esp32/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ endif

export IDF_PATH := $(call FixPath,$(IDF_PATH))

# Extract IDF version
ifndef IDF_VER
IDF_VER := $(shell (cd $$IDF_PATH && git describe --always --tags --dirty) | cut -c 1-31)
endif
IDF_VERSION := $(firstword $(subst -, ,$(IDF_VER)))

# By default, downloaded tools will be installed under $HOME/.espressif directory
# (%USERPROFILE%/.espressif on Windows). This path can be modified by setting
# IDF_TOOLS_PATH variable prior to running this tool.
Expand All @@ -27,40 +33,43 @@ ESP_VARIANT := $(SMING_SOC)
export ESP_VARIANT

IDF_TOOL_INFO := $(shell $(PYTHON) $(ARCH_TOOLS)/idf_tools.py $(SMING_SOC))
ESP32_COMPILER_PREFIX := $(word 1,$(IDF_TOOL_INFO))
ESP32_TOOLSET_PREFIX := $(word 1,$(IDF_TOOL_INFO))
ESP32_COMPILER_VERSION := $(word 2,$(IDF_TOOL_INFO))
ifeq (xtensa-esp-elf,$(ESP32_TOOLSET_PREFIX))
ESP32_COMPILER_PREFIX := xtensa-$(ESP_VARIANT)-elf
else
ESP32_COMPILER_PREFIX := $(ESP32_TOOLSET_PREFIX)
IDF_TARGET_ARCH_RISCV := $(findstring riscv,$(ESP32_COMPILER_PREFIX))
endif

# $1 => Root directory
# $2 => Sub-directory
# $1 => Tool sub-path/name
define FindTool
$(lastword $(sort $(wildcard $(IDF_TOOLS_PATH)/$1/*))$2)
$(lastword $(sort $(wildcard $(IDF_TOOLS_PATH)/$1*)))
endef

DEBUG_VARS += ESP32_COMPILER_PATH ESP32_ULP_PATH ESP32_OPENOCD_PATH ESP32_PYTHON_PATH

ifndef ESP32_COMPILER_PATH
ESP32_COMPILER_PATH := $(IDF_TOOLS_PATH)/tools/$(ESP32_COMPILER_PREFIX)/$(ESP32_COMPILER_VERSION)/$(ESP32_COMPILER_PREFIX)
ESP32_COMPILER_PATH := $(IDF_TOOLS_PATH)/tools/$(ESP32_TOOLSET_PREFIX)/$(ESP32_COMPILER_VERSION)/$(ESP32_TOOLSET_PREFIX)
endif

ifndef ESP32_ULP_PATH
ESP32_ULP_PATH := $(call FindTool,tools/$(ESP_VARIANT)ulp-elf)
ESP32_ULP_PATH := $(call FindTool,tools/$(ESP_VARIANT)ulp-elf/)
endif

ifndef ESP32_OPENOCD_PATH
ESP32_OPENOCD_PATH := $(call FindTool,tools/openocd-esp32)
ESP32_OPENOCD_PATH := $(call FindTool,tools/openocd-esp32/)
endif

ifndef ESP32_PYTHON_PATH
ESP32_PYTHON_PATH := $(call FindTool,python_env)
ifneq (,$(wildcard $(ESP32_PYTHON_PATH)/bin))
ESP32_PYTHON_PATH := $(ESP32_PYTHON_PATH)/bin
else ifneq (,$(wildcard $(ESP32_PYTHON_PATH)/Scripts))
ESP32_PYTHON_PATH := $(ESP32_PYTHON_PATH)/Scripts
ESP32_PYTHON_PATH := $(call FindTool,python_env/idf$(subst v,,$(IDF_VERSION)))
ifndef ESP32_PYTHON_PATH
ESP32_PYTHON_PATH := $(dir $(PYTHON))
else ifeq ($(UNAME),Windows)
ESP32_PYTHON := $(ESP32_PYTHON_PATH)/Scripts/python
else
$(error Failed to find ESP32 Python installation)
ESP32_PYTHON := $(ESP32_PYTHON_PATH)/bin/python
endif
ESP32_PYTHON = $(ESP32_PYTHON_PATH)/python
endif

# Required by v4.2 SDK
Expand All @@ -80,7 +89,7 @@ IDF_PATH_LIST := \
ifeq ($(UNAME),Windows)
DEBUG_VARS += ESP32_NINJA_PATH
ifndef ESP32_NINJA_PATH
ESP32_NINJA_PATH := $(call FindTool,tools/ninja)
ESP32_NINJA_PATH := $(call FindTool,tools/ninja/)
endif
ifeq (,$(wildcard $(ESP32_NINJA_PATH)/ninja.exe))
$(error Failed to find NINJA)
Expand All @@ -89,7 +98,7 @@ IDF_PATH_LIST += $(ESP32_NINJA_PATH)

DEBUG_VARS += ESP32_IDFEXE_PATH
ifndef ESP32_IDFEXE_PATH
ESP32_IDFEXE_PATH := $(call FindTool,tools/idf-exe)
ESP32_IDFEXE_PATH := $(call FindTool,tools/idf-exe/)
endif
IDF_PATH_LIST += $(ESP32_IDFEXE_PATH)
endif
Expand All @@ -114,9 +123,6 @@ OBJDUMP := $(TOOLSPEC)-objdump
GDB := $(TOOLSPEC)-gdb
SIZE := $(TOOLSPEC)-size

# Extracting IDF version
IDF_VER := $(shell (cd $$IDF_PATH && git describe --always --tags --dirty) | cut -c 1-31)

# [ Sming specific flags ]
DEBUG_VARS += IDF_PATH IDF_VER

Expand Down
1 change: 0 additions & 1 deletion Tools/ci/setenv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ if ($IsWindows) {

$env:PATH = "$env:PYTHON_PATH;$env:PYTHON_PATH\Scripts;$env:PATH"
$env:PYTHON = "$env:PYTHON_PATH\python"
$env:ESP32_PYTHON_PATH = "$env:PYTHON_PATH"

$env:PATH = "$env:PROGRAMFILES\CMake\bin;$env:PATH"

Expand Down
1 change: 0 additions & 1 deletion Tools/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export ESP_HOME=${ESP_HOME:=/opt/esp-quick-toolchain}
# Esp32
export IDF_PATH=${IDF_PATH:=/opt/esp-idf}
export IDF_TOOLS_PATH=${IDF_TOOLS_PATH:=/opt/esp32}
export ESP32_PYTHON_PATH=${ESP32_PYTHON_PATH:=/usr/bin}

# Rp2040
export PICO_TOOLCHAIN_PATH=${PICO_TOOLCHAIN_PATH:=/opt/rp2040}

0 comments on commit 7091536

Please sign in to comment.