This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push: new 7bfd62361 system/nxdiag: Add Espressif's HAL version 7bfd62361 is described below commit 7bfd6236169078f4569665e9bd49495c64b5abe7 Author: Lucas Saavedra Vaz <lucas....@espressif.com> AuthorDate: Tue Jun 27 18:08:36 2023 -0300 system/nxdiag: Add Espressif's HAL version Adds the currently used ESP HAL version to NXdiag's output. --- system/nxdiag/Makefile | 32 ++++++- system/nxdiag/nxdiag.c | 1 + tools/host_sysinfo.py | 249 ++++++++++++++++++++++++++++--------------------- 3 files changed, 171 insertions(+), 111 deletions(-) diff --git a/system/nxdiag/Makefile b/system/nxdiag/Makefile index d82d2eb95..ca8f7c776 100644 --- a/system/nxdiag/Makefile +++ b/system/nxdiag/Makefile @@ -20,7 +20,8 @@ include $(APPDIR)/Make.defs -NXTOOLSDIR = $(APPDIR)/tools +NXTOOLSDIR = $(APPDIR)$(DELIM)tools +NXDIAGDIR = $(APPDIR)$(DELIM)system$(DELIM)nxdiag # Sysinfo application info @@ -58,12 +59,29 @@ endif # Vendor-specific checks +# Espressif + ifeq ($(CONFIG_SYSTEM_NXDIAG_ESPRESSIF),y) + +ARCH_ESP_HALDIR = $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)chip$(DELIM)esp-hal-3rdparty + +# If the esp-hal-3rdparty directory is not in the arch directory, then it can be +# cloned to the nxdiag directory for debugging purposes. +HALDIR := $(shell if [ -d $(ARCH_ESP_HALDIR)$(DELIM).git ]; then echo "$(ARCH_ESP_HALDIR)"; else echo "$(NXDIAGDIR)$(DELIM)esp-hal-3rdparty"; fi) + +INFO_DEPS += espressif_prepare + +espressif_prepare: +ifeq ($(HALDIR),$(ARCH_ESP_HALDIR)) + (cd ${HALDIR} && git fetch -q --depth=10000 && git fetch -q --tags) +endif + ifdef ESPTOOL_BINDIR -NXDIAG_FLAGS += --espressif "$(ESPTOOL_BINDIR)" +NXDIAG_FLAGS += --espressif "$(ESPTOOL_BINDIR)" "$(HALDIR)" else -NXDIAG_FLAGS += --espressif "$(TOPDIR)" +NXDIAG_FLAGS += --espressif "$(TOPDIR)" "$(HALDIR)" endif + endif # Common build @@ -77,8 +95,12 @@ checkpython3: exit 1; \ fi -sysinfo.h : checkpython3 - @python3 $(NXTOOLSDIR)$(DELIM)host_sysinfo.py $(NXDIAG_FLAGS) > sysinfo.h || (echo "host_sysinfo.py failed $$?"; exit 1) +sysinfo.h : checkpython3 $(INFO_DEPS) + @python3 $(NXTOOLSDIR)$(DELIM)host_sysinfo.py $(NXDIAG_FLAGS) > sysinfo.h + if ([ $$? -ne 0 ]); then \ + echo "ERROR: Failed to generate sysinfo.h"; \ + exit 1; \ + fi context:: sysinfo.h diff --git a/system/nxdiag/nxdiag.c b/system/nxdiag/nxdiag.c index c15c30bee..b3e56240e 100644 --- a/system/nxdiag/nxdiag.c +++ b/system/nxdiag/nxdiag.c @@ -344,6 +344,7 @@ int main(int argc, char *argv[]) printf("Toolchain version:\n"); print_array(ESPRESSIF_TOOLCHAIN, ESPRESSIF_TOOLCHAIN_ARRAY_SIZE); printf("Esptool version: %s\n\n", ESPRESSIF_ESPTOOL); + printf("HAL version: %s\n\n", ESPRESSIF_HAL); #endif } diff --git a/tools/host_sysinfo.py b/tools/host_sysinfo.py index c76a01fc6..4904038f0 100755 --- a/tools/host_sysinfo.py +++ b/tools/host_sysinfo.py @@ -25,6 +25,139 @@ class validate_flags_arg(argparse.Action): setattr(namespace, self.dest, values) +# Vendor specific functions # + +# Espressif # + + +def get_espressif_bootloader_version(bindir): + """ + Get the bootloader version for Espressif chips from the bootloader binary. This + function works on Linux, Windows, and macOS. + + Args: + bindir (str): The path to the bootloader binary directory. + + Returns: + dict: A dictionary containing the bootloader version for each chip. + """ + + regex = r"^(?=.*\bv\d+(\.\d+){1,2}\b).+$" + bootloader_chips = [ + "esp32", + "esp32s2", + "esp32s3", + "esp32c2", + "esp32c3", + "esp32c6", + "esp32h2", + ] + bootloader_version = {} + + for chip in bootloader_chips: + file = "bootloader-{}.bin".format(chip) + path = os.path.join(bindir, file) + + if os.path.isfile(path): + if platform.system() == "Linux": + process = subprocess.Popen(["strings", path], stdout=subprocess.PIPE) + elif platform.system() == "Windows": + process = subprocess.Popen( + [ + "powershell", + "Get-Content -Raw -Encoding Byte {} |".format(path) + + " % { [char[]]$_ -join \"\" } | Select-String -Pattern '[\\x20-\\x7E]+'" + + " -AllMatches | % { $_.Matches } | % { $_.Value }", + ], + stdout=subprocess.PIPE, + ) + elif platform.system() == "Darwin": + process = subprocess.Popen( + ["strings", "-", path], stdout=subprocess.PIPE + ) + else: + bootloader_version[chip] = "Not supported on host OS" + break + + output, error = process.communicate() + strings_out = output.decode("utf-8", errors="ignore") + matches = re.finditer(regex, strings_out, re.MULTILINE) + + try: + bootloader_version[chip] = next(matches).group(0) + except StopIteration: + bootloader_version[chip] = "Unknown" + + else: + bootloader_version[chip] = "Bootloader image not found" + + return bootloader_version + + +def get_espressif_toolchain_version(): + """ + Get the version of different toolchains used by Espressif chips. + + Args: + None. + + Returns: + dict: A dictionary containing the toolchain version for each toolchain. + """ + + toolchain_version = {} + toolchain_bins = [ + "clang", + "gcc", + "xtensa-esp32-elf-gcc", + "xtensa-esp32s2-elf-gcc", + "xtensa-esp32s3-elf-gcc", + "riscv32-esp-elf-gcc", + "riscv64-unknown-elf-gcc", + ] + + for binary in toolchain_bins: + try: + version_output = subprocess.check_output( + [binary, "--version"], stderr=subprocess.STDOUT, universal_newlines=True + ) + version_lines = version_output.split("\n") + version = version_lines[0].strip() + toolchain_version[binary] = version + except (subprocess.CalledProcessError, FileNotFoundError): + toolchain_version[binary] = "Not found" + + return toolchain_version + + +def get_espressif_hal_version(hal_dir): + """ + Get the version of the ESP HAL used by Espressif chips. + + Args: + None. + + Returns: + str: The ESP HAL version. + """ + + hal_version = "Not found" + + try: + if os.path.isdir(os.path.join(hal_dir, ".git")): + hal_version_output = subprocess.check_output( + ["git", "describe", "--tags", "--always"], + cwd=hal_dir, + stderr=subprocess.STDOUT, + universal_newlines=True, + ) + hal_version = hal_version_output.strip() + except (subprocess.CalledProcessError, FileNotFoundError): + pass + + return hal_version + + # Common functions # @@ -417,112 +550,16 @@ def generate_header(args): info["ESPRESSIF_ESPTOOL"].split("-")[1] ) - output += "#endif /* __SYSTEM_INFO_H */\n" - - return output - - -# Vendor specific functions # - - -def get_espressif_bootloader_version(bindir): - """ - Get the bootloader version for Espressif chips from the bootloader binary. This - function works on Linux, Windows, and macOS. - - Args: - bindir (str): The path to the bootloader binary directory. - - Returns: - dict: A dictionary containing the bootloader version for each chip. - """ - - regex = r"^(?=.*\bv\d+(\.\d+){1,2}\b).+$" - bootloader_chips = [ - "esp32", - "esp32s2", - "esp32s3", - "esp32c2", - "esp32c3", - "esp32c6", - "esp32h2", - ] - bootloader_version = {} - - for chip in bootloader_chips: - file = "bootloader-{}.bin".format(chip) - path = os.path.join(bindir, file) + # Espressif HAL version - if os.path.isfile(path): - if platform.system() == "Linux": - process = subprocess.Popen(["strings", path], stdout=subprocess.PIPE) - elif platform.system() == "Windows": - process = subprocess.Popen( - [ - "powershell", - "Get-Content -Raw -Encoding Byte {} |".format(path) - + " % { [char[]]$_ -join \"\" } | Select-String -Pattern '[\\x20-\\x7E]+'" - + " -AllMatches | % { $_.Matches } | % { $_.Value }", - ], - stdout=subprocess.PIPE, - ) - elif platform.system() == "Darwin": - process = subprocess.Popen( - ["strings", "-", path], stdout=subprocess.PIPE - ) - else: - bootloader_version[chip] = "Not supported on host OS" - break - - output, error = process.communicate() - strings_out = output.decode("utf-8", errors="ignore") - matches = re.finditer(regex, strings_out, re.MULTILINE) - - try: - bootloader_version[chip] = next(matches).group(0) - except StopIteration: - bootloader_version[chip] = "Unknown" - - else: - bootloader_version[chip] = "Bootloader image not found" - - return bootloader_version - - -def get_espressif_toolchain_version(): - """ - Get the version of different toolchains used by Espressif chips. - - Args: - None. - - Returns: - dict: A dictionary containing the toolchain version for each toolchain. - """ - - toolchain_version = {} - toolchain_bins = [ - "clang", - "gcc", - "xtensa-esp32-elf-gcc", - "xtensa-esp32s2-elf-gcc", - "xtensa-esp32s3-elf-gcc", - "riscv32-esp-elf-gcc", - "riscv64-unknown-elf-gcc", - ] + info["ESPRESSIF_HAL"] = get_espressif_hal_version(args.espressif[1]) + output += 'static const char ESPRESSIF_HAL[] = "{}";\n\n'.format( + info["ESPRESSIF_HAL"] + ) - for binary in toolchain_bins: - try: - version_output = subprocess.check_output( - [binary, "--version"], stderr=subprocess.STDOUT, universal_newlines=True - ) - version_lines = version_output.split("\n") - version = version_lines[0].strip() - toolchain_version[binary] = version - except (subprocess.CalledProcessError, FileNotFoundError): - toolchain_version[binary] = "Not found" + output += "#endif /* __SYSTEM_INFO_H */\n" - return toolchain_version + return output # Main # @@ -604,10 +641,10 @@ if __name__ == "__main__": parser.add_argument( "--espressif", - nargs=1, + nargs=2, default=[], - metavar="ESPTOOL_BINDIR", - help="Get Espressif specific information. Requires the path to the bootloader binary directory.", + metavar=("ESPTOOL_BINDIR", "ESP_HAL_DIR"), + help="Get Espressif specific information. Requires the path to the bootloader binary and ESP HAL directories.", ) # Parse arguments