How to find the toolchain bundle ID from a specific SDK release

I'm trying to use nrfutil as part of a script that sets up the toolchain environment automatically using direnv.

For example:

nrfutil sdk-manager toolchain env --as-script --toolchain-bundle-id $TOOLCHAIN_BUNDLE_ID

I'd like to know how the bundle ID can be read/calculated assuming that the script has access to the files in a specific NCS SDK release. I thought the bundle ID might be the toolchain checksum, but when I run ./nrf/scripts/print_toolchain_checksum.sh it does not match the bundle ID.

For example, when I check out this app: https://github.com/hello-nrfcloud/firmware

❯ cat nrf/VERSION
2.8.0-rc2

❯ nrfutil sdk-manager toolchain list
Version     Toolchain
v2.8.0-rc2  /opt/nordic/ncs/toolchains/15b490767d

❯ ./nrf/scripts/print_toolchain_checksum.sh
b81a7cd864

How can the toolchain bundle ID be calculated from the files in the SDK release?

Parents
  • It appears that the print_toolchain_checksum.sh script only returns the bundle ID for the linux toolchain.

    When I run the same commands on a Ubuntu x86_64 machine, the checksum matches the bundle ID:

    $ cat nrf/VERSION
    2.8.0-rc2
    
    $ nrfutil sdk-manager toolchain list
    Version     Toolchain
    v2.8.0-rc2  /home/chris/ncs/toolchains/b81a7cd864
    
    $ ./nrf/scripts/print_toolchain_checksum.sh
    b81a7cd864

    The problem is that for users on macOS, print_toolchain_checksum.sh can't be used to calculate the correct toolchain bundle ID for the SDK. Why are there different toolchain bundle IDs based on OS? The bundle ID only appears to be unique across OS, but not architecture, given that macos-aarch64 and macos-x86_64 use identical bundle IDs for a given SDK release.

    Is there a method for calculating the bundle ID that returns the correct bundle ID on each OS?

    For now, I've switched to just using the NCS version instead of the bundle ID. Here's the contents of the .envrc file I'm using in the root of my NCS workspaces:

    NCS_VERSION="v$(cat ./nrf/VERSION)"
    eval "$(nrfutil sdk-manager toolchain env --as-script --ncs-version $NCS_VERSION)"
    source zephyr/zephyr-env.sh
    

  • Looking more closely at print_toolchain_checksum.sh, there are different tool-versions-${OS}.yml files for each OS, but print_toolchain_checksum.sh hard codes the one for Linux.

    When the correct file for the OS is used in the checksum calculation, the checksum matches the bundle ID for that OS.

    Here's an .envrc that works on macOS and Linux:

    # Detect OS
    case "$(uname -s)" in
      Darwin)
        TOOLS_OS="darwin"
        # On macOS, detect *hardware* arch (Rosetta-safe)
        if sysctl -n hw.optional.arm64 2>/dev/null | grep -q '^1$'; then
            ARCH="aarch64"
        else
            ARCH="x86_64"
        fi
        ;;
      Linux)
        TOOLS_OS="linux"
        # On Linux, just trust uname -m
        ARCH="$(uname -m)"
        # Only support x86_64 Linux
        if [ "$ARCH" != "x86_64" ]; then
            echo "This script only supports x86_64 Linux. Detected architecture: $ARCH"
            return 0
        fi
        ;;
      *)
        # Unsupported OS - exit early without doing anything
        echo "This script only supports Linux and macOS. Detected OS: $(uname -s)"
        return 0
        ;;
    esac
    
    BASEDIR="./nrf/scripts"
    REQUIREMENTS=$BASEDIR/requirements-fixed.txt
    TOOLS_VERSIONS=$BASEDIR/tools-versions-${TOOLS_OS}.yml
    TOOLCHAIN_VERSION=$(cat ${REQUIREMENTS} ${TOOLS_VERSIONS} | tr -d '\r' | sha256sum | head -c 10)
    eval "$(nrfutil sdk-manager toolchain env --as-script --toolchain-bundle-id ${TOOLCHAIN_VERSION})"
    source ./zephyr/zephyr-env.sh
    

    It would be nice if the Nordic folks can update the print_toolchain_checksum.sh script so it works on both macOS and Linux.

Reply
  • Looking more closely at print_toolchain_checksum.sh, there are different tool-versions-${OS}.yml files for each OS, but print_toolchain_checksum.sh hard codes the one for Linux.

    When the correct file for the OS is used in the checksum calculation, the checksum matches the bundle ID for that OS.

    Here's an .envrc that works on macOS and Linux:

    # Detect OS
    case "$(uname -s)" in
      Darwin)
        TOOLS_OS="darwin"
        # On macOS, detect *hardware* arch (Rosetta-safe)
        if sysctl -n hw.optional.arm64 2>/dev/null | grep -q '^1$'; then
            ARCH="aarch64"
        else
            ARCH="x86_64"
        fi
        ;;
      Linux)
        TOOLS_OS="linux"
        # On Linux, just trust uname -m
        ARCH="$(uname -m)"
        # Only support x86_64 Linux
        if [ "$ARCH" != "x86_64" ]; then
            echo "This script only supports x86_64 Linux. Detected architecture: $ARCH"
            return 0
        fi
        ;;
      *)
        # Unsupported OS - exit early without doing anything
        echo "This script only supports Linux and macOS. Detected OS: $(uname -s)"
        return 0
        ;;
    esac
    
    BASEDIR="./nrf/scripts"
    REQUIREMENTS=$BASEDIR/requirements-fixed.txt
    TOOLS_VERSIONS=$BASEDIR/tools-versions-${TOOLS_OS}.yml
    TOOLCHAIN_VERSION=$(cat ${REQUIREMENTS} ${TOOLS_VERSIONS} | tr -d '\r' | sha256sum | head -c 10)
    eval "$(nrfutil sdk-manager toolchain env --as-script --toolchain-bundle-id ${TOOLCHAIN_VERSION})"
    source ./zephyr/zephyr-env.sh
    

    It would be nice if the Nordic folks can update the print_toolchain_checksum.sh script so it works on both macOS and Linux.

Children
Related