From 1438d41347c6bd764356f7ac1e5f3c6254f36e3e Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 4 Apr 2023 13:28:50 +0200 Subject: [PATCH 1/2] dist/tools/esptools: upgrade to gcc 12.2 --- cpu/esp32/doc.txt | 11 ++- dist/tools/esptools/export.sh | 100 ++++++++++++++------- dist/tools/esptools/install.sh | 155 +++++++++++++++++++++++---------- 3 files changed, 184 insertions(+), 82 deletions(-) diff --git a/cpu/esp32/doc.txt b/cpu/esp32/doc.txt index 6c92a80f73..21ba43159d 100644 --- a/cpu/esp32/doc.txt +++ b/cpu/esp32/doc.txt @@ -485,6 +485,7 @@ The shell script `$RIOTBASE/dist/tools/esptools/install.sh` is used to install Espressif's precompiled versions of the following tools: - ESP32 vendor toolchain (for ESP32, ESP32-S2, ESP32-S3 and ESP32-C3) +- GDB for ESP32x SoCs based on Xtensa or RISC-V - OpenOCD for ESP32 (for ESP32, ESP32-S2, ESP32-S3 and ESP32-C3) - QEMU for ESP32 (only for ESP32) @@ -494,8 +495,10 @@ script takes an argument that specifies which tools to download and install: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $ dist/tools/esptools/install.sh -install.sh -tool = all | esp32 | esp32c3 | esp32s2 | esp32s3 | openocd | qemu +Usage: install.sh + install.sh gdb + = all | esp32 | esp32c3 | esp32s2 | esp32s3 | gdb | openocd | qemu + = xtensa | riscv ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Thus, either all tools or only certain tools can be installed. @@ -522,7 +525,9 @@ paths of the installed tools using again the environment variable $ . dist/tools/esptools/export.sh Usage: export.sh -tool = all | esp32 | esp32c3 | esp32s2 | esp32s3 | openocd | qemu + export.sh gdb + = all | esp32 | esp32c3 | esp32s2 | esp32s3 | gdb | openocd | qemu + = xtensa | riscv ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All the tools required for building a RIOT application for ESP32x SoCs should then diff --git a/dist/tools/esptools/export.sh b/dist/tools/esptools/export.sh index 19dee95036..a29121b32e 100755 --- a/dist/tools/esptools/export.sh +++ b/dist/tools/esptools/export.sh @@ -1,15 +1,14 @@ #!/bin/sh -ESP32_GCC_RELEASE="esp-2021r2-patch3" -ESP32_GCC_VERSION_DIR="8.4.0" +ESP32_GCC_RELEASE="esp-12.2.0_20230208" -ESP32_OPENOCD_VERSION="v0.11.0-esp32-20211220" +ESP32_OPENOCD_VERSION="v0.12.0-esp32-20230313" -if [ -z ${IDF_TOOLS_PATH} ]; then - IDF_TOOLS_PATH=${HOME}/.espressif +if [ -z "${IDF_TOOLS_PATH}" ]; then + IDF_TOOLS_PATH="${HOME}/.espressif" fi -TOOLS_PATH=${IDF_TOOLS_PATH}/tools +TOOLS_PATH="${IDF_TOOLS_PATH}/tools" export_arch() { @@ -28,15 +27,15 @@ export_arch() ;; *) echo "Unknown architecture $1" - exit 1 + return esac - TOOLS_DIR=${TOOLS_PATH}/${TARGET_ARCH}/${ESP32_GCC_RELEASE}-${ESP32_GCC_VERSION_DIR}/${TARGET_ARCH} - TOOLS_DIR_IN_PATH=`echo $PATH | grep ${TOOLS_DIR}` + TOOLS_DIR="${TOOLS_PATH}/${TARGET_ARCH}/${ESP32_GCC_RELEASE}/${TARGET_ARCH}" + TOOLS_DIR_IN_PATH="$(echo $PATH | grep "${TOOLS_DIR}")" - if [ -e ${TOOLS_DIR} ] && [ -z ${TOOLS_DIR_IN_PATH} ]; then + if [ -e "${TOOLS_DIR}" ] && [ -z "${TOOLS_DIR_IN_PATH}" ]; then echo "Extending PATH by ${TOOLS_DIR}/bin" - export PATH=${TOOLS_DIR}/bin:${PATH} + export PATH="${TOOLS_DIR}/bin:${PATH}" fi unset TOOLS_DIR @@ -44,13 +43,13 @@ export_arch() export_openocd() { - TOOLS_DIR=${TOOLS_PATH}/openocd-esp32/${ESP32_OPENOCD_VERSION} - TOOLS_DIR_IN_PATH=`echo $PATH | grep ${TOOLS_DIR}` - OPENOCD_DIR=${TOOLS_DIR}/openocd-esp32 + TOOLS_DIR="${TOOLS_PATH}/openocd-esp32/${ESP32_OPENOCD_VERSION}" + TOOLS_DIR_IN_PATH="$(echo $PATH | grep "${TOOLS_DIR}")" + OPENOCD_DIR="${TOOLS_DIR}/openocd-esp32" - if [ -e ${OPENOCD_DIR} ] && [ -z ${TOOLS_DIR_IN_PATH} ]; then + if [ -e "${OPENOCD_DIR}" ] && [ -z "${TOOLS_DIR_IN_PATH}" ]; then echo "Extending PATH by ${TOOLS_DIR}/bin" - export PATH=${OPENOCD_DIR}/bin:${PATH} + export PATH="${OPENOCD_DIR}/bin:${PATH}" export OPENOCD="${OPENOCD_DIR}/bin/openocd -s ${OPENOCD_DIR}/share/openocd/scripts" fi @@ -61,18 +60,18 @@ export_openocd() export_qemu() { # determine the platform using python - PLATFORM_SYSTEM=$(python3 -c "import platform; print(platform.system())") - PLATFORM_MACHINE=$(python3 -c "import platform; print(platform.machine())") - PLATFORM=${PLATFORM_SYSTEM}-${PLATFORM_MACHINE} + PLATFORM_SYSTEM="$(python3 -c "import platform; print(platform.system())")" + PLATFORM_MACHINE="$(python3 -c "import platform; print(platform.machine())")" + PLATFORM="${PLATFORM_SYSTEM}-${PLATFORM_MACHINE}" # map different platform names to a unique OS name - case ${PLATFORM} in + case "${PLATFORM}" in linux-amd64|linux64|Linux-x86_64|FreeBSD-amd64) - OS=linux-amd64 + OS="linux-amd64" ;; *) echo "error: OS architecture ${PLATFORM} not supported" - exit 1 + return ;; esac @@ -83,31 +82,70 @@ export_qemu() ESP32_QEMU_VERSION="esp-develop-20210220" fi - if [ -z ${IDF_TOOLS_PATH} ]; then - IDF_TOOLS_PATH=${HOME}/.espressif + if [ -z "${IDF_TOOLS_PATH}" ]; then + IDF_TOOLS_PATH="${HOME}/.espressif" fi - TOOLS_DIR=${TOOLS_PATH}/qemu-esp32/${ESP32_QEMU_VERSION}/qemu - TOOLS_DIR_IN_PATH=`echo $PATH | grep ${TOOLS_DIR}` + TOOLS_DIR="${TOOLS_PATH}/qemu-esp32/${ESP32_QEMU_VERSION}/qemu" + TOOLS_DIR_IN_PATH="$(echo $PATH | grep "${TOOLS_DIR}")" - if [ -e ${TOOLS_DIR} ] && [ -z ${TOOLS_DIR_IN_PATH} ]; then + if [ -e "${TOOLS_DIR}" ] && [ -z "${TOOLS_DIR_IN_PATH}" ]; then echo "Extending PATH by ${TOOLS_DIR}/bin" - export PATH=${TOOLS_DIR}/bin:${PATH} + export PATH="${TOOLS_DIR}/bin:${PATH}" fi unset TOOLS_DIR } -if [ -z $1 ]; then +export_gdb() +{ + case "$1" in + xtensa) + GDB_ARCH="xtensa-esp-elf-gdb" + ;; + riscv) + GDB_ARCH="riscv32-esp-elf-gdb" + ;; + *) + echo "error: Unknown platform $1, use xtensa or riscv" + return + esac + + GDB_VERSION="12.1_20221002" + + TOOLS_DIR="${TOOLS_PATH}/${GDB_ARCH}/${GDB_VERSION}/${GDB_ARCH}" + TOOLS_DIR_IN_PATH="$(echo $PATH | grep "${TOOLS_DIR}")" + + if [ -e "${TOOLS_DIR}" ] && [ -z "${TOOLS_DIR_IN_PATH}" ]; then + echo "Extending PATH by ${TOOLS_DIR}/bin" + export PATH="${TOOLS_DIR}/bin:${PATH}" + fi + + unset TOOLS_DIR +} + +if [ -z "$1" ]; then echo "Usage: export.sh " - echo "tool = all | esp32 | esp32c3 | esp32s2 | esp32s3 | openocd | qemu" + echo " export.sh gdb " + echo " = all | esp32 | esp32c3 | esp32s2 | esp32s3 | gdb | openocd | qemu" + echo " = xtensa | riscv" elif [ "$1" = "all" ]; then ARCH_ALL="esp32 esp32c3 esp32s2 esp32s3" for arch in ${ARCH_ALL}; do - export_arch $arch + export_arch "$arch" done + export_gdb xtensa + export_gdb riscv export_openocd export_qemu + export_gdb xtensa + export_gdb riscv +elif [ "$1" = "gdb" ]; then + if [ -z "$2" ]; then + echo "platform required: xtensa | riscv" + else + export_gdb "$2" + fi elif [ "$1" = "openocd" ]; then export_openocd elif [ "$1" = "qemu" ]; then diff --git a/dist/tools/esptools/install.sh b/dist/tools/esptools/install.sh index b2f6b32355..ea9edc157d 100755 --- a/dist/tools/esptools/install.sh +++ b/dist/tools/esptools/install.sh @@ -1,18 +1,18 @@ #!/bin/sh -ESP32_GCC_RELEASE="esp-2021r2-patch3" -ESP32_GCC_VERSION_DIR="8.4.0" -ESP32_GCC_VERSION_DOWNLOAD="gcc8_4_0" +ESP32_GCC_RELEASE="esp-12.2.0_20230208" +ESP32_GCC_VERSION_DIR="12.2.0" +ESP32_GCC_VERSION_DOWNLOAD="12.2.0_20230208" -ESP32_OPENOCD_VERSION="v0.11.0-esp32-20211220" -ESP32_OPENOCD_VERSION_TGZ="0.11.0-esp32-20211220" +ESP32_OPENOCD_VERSION="v0.12.0-esp32-20230313" +ESP32_OPENOCD_VERSION_TGZ="0.12.0-esp32-20230313" # set the tool path to the default if not already set if [ -z "${IDF_TOOLS_PATH}" ]; then - IDF_TOOLS_PATH=${HOME}/.espressif + IDF_TOOLS_PATH="${HOME}/.espressif" fi -TOOLS_PATH=${IDF_TOOLS_PATH}/tools +TOOLS_PATH="${IDF_TOOLS_PATH}/tools" # check the existence of either wget or curl and set the download tool if [ "$(which curl)" != "" ]; then @@ -31,29 +31,38 @@ if [ "$(which python3)" = "" ]; then fi # determine the platform using python -PLATFORM_SYSTEM=$(python3 -c "import platform; print(platform.system())") -PLATFORM_MACHINE=$(python3 -c "import platform; print(platform.machine())") -PLATFORM=${PLATFORM_SYSTEM}-${PLATFORM_MACHINE} +PLATFORM_SYSTEM="$(python3 -c "import platform; print(platform.system())")" +PLATFORM_MACHINE="$(python3 -c "import platform; print(platform.machine())")" +PLATFORM="${PLATFORM_SYSTEM}-${PLATFORM_MACHINE}" # map different platform names to a unique OS name -case ${PLATFORM} in - linux-amd64|linux64|Linux-x86_64|FreeBSD-amd64) - OS=linux-amd64 +case "${PLATFORM}" in + linux-amd64|linux64|Linux-x86_64|FreeBSD-amd64|x86_64-linux-gnu) + OS="x86_64-linux-gnu" + OS_OCD="linux-amd64" ;; - linux-arm64|Linux-arm64|Linux-aarch64|Linux-armv8l) - OS=linux-arm64 + linux-arm64|Linux-arm64|Linux-aarch64|Linux-armv8l|aarch64) + OS="aarch64-linux" + OS_OCD="linux-arm64" ;; - linux-armel|Linux-arm|Linux-armv7l) - OS=linux-armel + linux-armel|Linux-arm|Linux-armv7l|arm-linux-gnueabi) + OS="arm-linux-gnueabi" + OS_OCD="linux-armel" ;; - linux-armhf) - OS=linux-armhf + linux-armhf|arm-linux-gnueabihf) + OS="arm-linux-gnueabihf" + OS_OCD="linux-armhf" ;; - linux-i686|linux32|Linux-i686|FreeBSD-i386) - OS=linux-i686 + linux-i686|linux32|Linux-i686|FreeBSD-i386|i586-linux-gnu|i686-linux-gnu) + OS="i686-linux-gnu" ;; - Darwin-x86_64) - OS=macos + macos|osx|darwin|Darwin-x86_64|x86_64-apple-darwin) + OS="x86_64-apple-darwin" + OS_OCD="macos" + ;; + macos-arm64|Darwin-arm64|aarch64-apple-darwin|arm64-apple-darwin) + OS="aarch64-apple-darwin" + OS_OCD="macos-arm64" ;; *) echo "error: OS architecture ${PLATFORM} not supported" @@ -74,7 +83,7 @@ download() install_arch() { - case $1 in + case "$1" in esp32) TARGET_ARCH="xtensa-esp32-elf" ;; @@ -92,87 +101,137 @@ install_arch() exit 1 esac - TOOLS_DIR=${TOOLS_PATH}/${TARGET_ARCH}/${ESP32_GCC_RELEASE}-${ESP32_GCC_VERSION_DIR} + TOOLS_DIR="${TOOLS_PATH}/${TARGET_ARCH}/${ESP32_GCC_RELEASE}" - URL_PATH=https://github.com/espressif/crosstool-NG/releases/download - URL_TGZ=${TARGET_ARCH}-${ESP32_GCC_VERSION_DOWNLOAD}-${ESP32_GCC_RELEASE}-${OS}.tar.gz - URL=${URL_PATH}/${ESP32_GCC_RELEASE}/${URL_TGZ} + URL_PATH="https://github.com/espressif/crosstool-NG/releases/download" + URL_TGZ="${TARGET_ARCH}-${ESP32_GCC_VERSION_DOWNLOAD}-${OS}.tar.xz" + URL="${URL_PATH}/${ESP32_GCC_RELEASE}/${URL_TGZ}" echo "Creating directory ${TOOLS_DIR} ..." && \ mkdir -p "${TOOLS_DIR}" && \ cd "${TOOLS_DIR}" && \ echo "Downloading ${URL_TGZ} ..." && \ - download ${URL} ${URL_TGZ} && \ + download "${URL}" "${URL_TGZ}" && \ echo "Extracting ${URL_TGZ} in ${TOOLS_DIR} ..." && \ - tar xfz ${URL_TGZ} && \ + tar xfJ "${URL_TGZ}" && \ echo "Removing ${URL_TGZ} ..." && \ - rm -f ${URL_TGZ} && \ + rm -f "${URL_TGZ}" && \ echo "$1 toolchain installed in ${TOOLS_DIR}/$TARGET_ARCH" } install_openocd() { - TOOLS_DIR=${TOOLS_PATH}/openocd-esp32/${ESP32_OPENOCD_VERSION} + if [ "${OS_OCD}" = "" ]; then + echo "OS not supported by this OpenOCD version" + exit 1 + fi - URL_PATH=https://github.com/espressif/openocd-esp32/releases/download - URL_TGZ=openocd-esp32-${OS}-${ESP32_OPENOCD_VERSION_TGZ}.tar.gz - URL=${URL_PATH}/${ESP32_OPENOCD_VERSION}/${URL_TGZ} + TOOLS_DIR="${TOOLS_PATH}/openocd-esp32/${ESP32_OPENOCD_VERSION}" + + URL_PATH="https://github.com/espressif/openocd-esp32/releases/download" + URL_TGZ="openocd-esp32-${OS_OCD}-${ESP32_OPENOCD_VERSION_TGZ}.tar.gz" + URL="${URL_PATH}/${ESP32_OPENOCD_VERSION}/${URL_TGZ}" echo "Creating directory ${TOOLS_DIR} ..." && \ mkdir -p "${TOOLS_DIR}" && \ cd "${TOOLS_DIR}" && \ echo "Downloading ${URL_TGZ} ..." && \ - download ${URL} ${URL_TGZ} && \ + download "${URL}" "${URL_TGZ}" && \ echo "Extracting ${URL_TGZ} in ${TOOLS_DIR} ..." && \ - tar xfz ${URL_TGZ} && \ + tar xfz "${URL_TGZ}" && \ echo "Removing ${URL_TGZ} ..." && \ - rm -f ${URL_TGZ} && \ + rm -f "${URL_TGZ}" && \ echo "OpenOCD for ESP32x SoCs installed in ${TOOLS_DIR}/$TARGET_ARCH" } install_qemu() { - if [ ${OS} != "linux-amd64" ]; then + if [ "${OS}" != "x86_64-linux-gnu" ]; then echo "error: QEMU for ESP32 does not support OS ${OS}" exit 1 fi # qemu version depends on the version of ncurses lib if [ "$(ldconfig -p | grep libncursesw.so.6)" != "" ]; then - ESP32_QEMU_VERSION="esp-develop-20220203" + ESP32_QEMU_VERSION="esp-develop-7.2.0-20230223" + URL_TGZ="esp-qemu-xtensa-softmmu-develop_7.2.0_20230223-${OS}.tar.bz2" else ESP32_QEMU_VERSION="esp-develop-20210220" + URL_TGZ="qemu-${ESP32_QEMU_VERSION}.tar.bz2" fi - TOOLS_DIR=${TOOLS_PATH}/qemu-esp32/${ESP32_QEMU_VERSION} + TOOLS_DIR="${TOOLS_PATH}/qemu-esp32/${ESP32_QEMU_VERSION}" - URL_PATH=https://github.com/espressif/qemu/releases/download - URL_TGZ=qemu-${ESP32_QEMU_VERSION}.tar.bz2 - URL=${URL_PATH}/${ESP32_QEMU_VERSION}/${URL_TGZ} + URL_PATH="https://github.com/espressif/qemu/releases/download" + URL="${URL_PATH}/${ESP32_QEMU_VERSION}/${URL_TGZ}" echo "Creating directory ${TOOLS_DIR} ..." && \ mkdir -p "${TOOLS_DIR}" && \ cd "${TOOLS_DIR}" && \ echo "Downloading ${URL_TGZ} ..." && \ - download ${URL} ${URL_TGZ} && \ + download "${URL}" "${URL_TGZ}" && \ echo "Extracting ${URL_TGZ} in ${TOOLS_DIR} ..." && \ - tar xfj ${URL_TGZ} && \ + tar xfj "${URL_TGZ}" && \ echo "Removing ${URL_TGZ} ..." && \ - rm -f ${URL_TGZ} && \ + rm -f "${URL_TGZ}" && \ echo "QEMU for ESP32 installed in ${TOOLS_DIR}" } +install_gdb() +{ + case $1 in + xtensa) + GDB_ARCH="xtensa-esp-elf-gdb" + ;; + riscv) + GDB_ARCH="riscv32-esp-elf-gdb" + ;; + *) + echo "error: Unknown platform $1, use xtensa or riscv" + exit 1 + esac + + GDB_VERSION="12.1_20221002" + + TOOLS_DIR="${TOOLS_PATH}/${GDB_ARCH}/${GDB_VERSION}" + + URL_PATH="https://github.com/espressif/binutils-gdb/releases/download" + URL_TGZ="${GDB_ARCH}-${GDB_VERSION}-${OS}.tar.gz" + URL="${URL_PATH}/esp-gdb-v${GDB_VERSION}/${URL_TGZ}" +echo $URL_GET $URL + echo "Creating directory ${TOOLS_DIR} ..." && \ + mkdir -p "${TOOLS_DIR}" && \ + cd "${TOOLS_DIR}" && \ + echo "Downloading ${URL_TGZ} ..." && \ + download "${URL}" "${URL_TGZ}" && \ + echo "Extracting ${URL_TGZ} in ${TOOLS_DIR} ..." && \ + tar xfz "${URL_TGZ}" && \ + echo "Removing ${URL_TGZ} ..." && \ + rm -f "${URL_TGZ}" && \ + echo "GDB for $1 installed in ${TOOLS_DIR}" +} + if [ -z "$1" ]; then echo "Usage: install.sh " - echo "tool = all | esp32 | esp32c3 | esp32s2 | esp32s3 | openocd | qemu" + echo " install.sh gdb " + echo " = all | esp32 | esp32c3 | esp32s2 | esp32s3 | gdb | openocd | qemu" + echo " = xtensa | riscv" exit 1 elif [ "$1" = "all" ]; then ARCH_ALL="esp32 esp32c3 esp32s2 esp32s3" for arch in ${ARCH_ALL}; do install_arch "$arch" done + install_gdb xtensa + install_gdb riscv install_openocd install_qemu +elif [ "$1" = "gdb" ]; then + if [ -z "$2" ]; then + echo "platform required: xtensa | riscv" + exit 1 + fi + install_gdb "$2" elif [ "$1" = "openocd" ]; then install_openocd elif [ "$1" = "qemu" ]; then From a83d5ba9b195cbce79465f1193570e8d7be77020 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Thu, 11 May 2023 16:23:45 +0200 Subject: [PATCH 2/2] dist/tools/esptool: set --retry for curl in install.sh for stability --- dist/tools/esptools/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/tools/esptools/install.sh b/dist/tools/esptools/install.sh index ea9edc157d..b6a5784096 100755 --- a/dist/tools/esptools/install.sh +++ b/dist/tools/esptools/install.sh @@ -73,7 +73,7 @@ esac download() { if [ "${URL_GET}" = "curl" ]; then - curl -L "$1" -o "$2" + curl -L "$1" --retry 10 -o "$2" elif [ "${URL_GET}" = "wget" ]; then wget "$1" -O "$2" else