Skip to content

OpenOCD build error #2

Open
Open
@kristofmulier

Description

@kristofmulier

To build OpenOCD for several platforms (Windows, Linux, MacOS), I use the xPack (https://xpack.github.io/) build scripts. The build procedure with xPack for OpenOCD is described here:
https://xpack.github.io/dev-tools/openocd/

Unfortunately, the build fails when applied on this hpmicro/riscv-openocd repo. I'll describe what goes wrong. Hopefully someone can help me out.

1. Prerequisites

For the sake of doing a really clean build, I decided to install a brand new Ubuntu 22.04.2 LTS virtual machine. Then I installed the prerequisites as requested by the xPack project (https://xpack.github.io/xbb/prerequisites/):

# Update apt and apt-get
# ----------------------
$ sudo apt update
$ sudo apt-get update

# Install curl & git
# ------------------
$ sudo apt install --yes curl git

# Install Docker
# --------------
$ sudo apt install ca-certificates curl gnupg

$ sudo mkdir -m 0755 -p /etc/apt/keyrings

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

$ echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

$ sudo apt update
$ sudo apt-get update
$ sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
$ sudo docker run hello-world

# Configure Docker to run as a regular user
# -----------------------------------------
$ sudo groupadd docker
$ sudo gpasswd -a ${USER} docker
$ sudo service docker restart
# Reboot machine
$ docker run hello-world

# Install npm/xpm
# ---------------
$ mkdir -pv "${HOME}/Downloads/"
$ curl --output "${HOME}/Downloads/install-nvm-node-npm-xpm.sh" https://raw.githubusercontent.com/xpack/assets/master/scripts/install-nvm-node-npm-xpm.sh
$ cat "${HOME}/Downloads/install-nvm-node-npm-xpm.sh"
# Restart terminal
$ bash "${HOME}/Downloads/install-nvm-node-npm-xpm.sh"
# Restart terminal
$ echo "node: $(node --version)"
node: v18.16.1
$ echo "npm: $(npm --version)"
npm: 9.8.0
$ echo "xpm: $(xpm --version)"
xpm: 0.16.2

# GCC development headers and libraries
# -------------------------------------
$ sudo apt-get install --yes g++ libc6-dev libstdc++6
$ sudo apt-get install --yes g++-multilib
$ sudo apt-get install --yes linux-headers-generic

2. Build OpenOCD

After installing the prerequisites, we can start with the build.

2.1 Download build scripts

The first step is to download the build scripts:

# Delete previous repo
$ rm -rf ~/Work/xpacks/openocd-xpack.git

# Clone build scripts
$ git clone --recurse-submodules https://github.com/xpack-dev-tools/openocd-xpack.git ~/Work/xpacks/openocd-xpack.git

2.2 Modify build scripts

The file ~/Work/xpacks/openocd-xpack.git/scripts/application.sh determines where the OpenOCD source code gets pulled for the build. Open the script:

$ cd ~/Work/xpacks/openocd-xpack.git/scripts/
$ gedit application.sh

Scroll down in the script until you see this:

# -----------------------------------------------------------------------------
    
# If you want to build OpenOCD from another repo then uncomment the
# following defines and tweak as needed.
    
# XBB_APPLICATION_OPENOCD_GIT_URL="https://github.com/openocd-org/openocd.git"
# XBB_APPLICATION_OPENOCD_GIT_BRANCH="master"
# XBB_APPLICATION_OPENOCD_GIT_COMMIT="HEAD"
    
# -----------------------------------------------------------------------------

So I uncommented these lines and made sure it pointed to the OpenOCD repo from hpmicro:

XBB_APPLICATION_OPENOCD_GIT_URL="https://github.com/hpmicro/riscv-openocd.git"
XBB_APPLICATION_OPENOCD_GIT_BRANCH="master"
XBB_APPLICATION_OPENOCD_GIT_COMMIT="HEAD"

2.3 Start build

To start the build for Linux, I issued these commands:

$ cd ~
$ docker info
$ git -C ~/Work/xpacks/openocd-xpack.git pull

$ xpm run install -C ~/Work/xpacks/openocd-xpack.git
$ xpm run docker-prepare --config linux-x64 -C ~/Work/xpacks/openocd-xpack.git
$ xpm run docker-build --config linux-x64 -C ~/Work/xpacks/openocd-xpack.git

When I want to rerun the build, I issue this command:

$ xpm run deep-clean --config linux-x64 -C ~/Work/xpacks/openocd-xpack.git

The options are:

  • --config darwin-x64
  • --config darwin-arm64
  • --config linux-x64
  • --config win32-x64
  • --config linux-arm64
  • --config linux-arm

2.4 Results

Normally the resulting OpenOCD build should be available here:

~/Work/xpacks/openocd-xpack.git/build/linux-x64/deploy/xpack-openocd-... .tar.gz

or here:

~/Work/xpacks/openocd-xpack.git/build/win32-x64/deploy/xpack-openocd-... .zip

Unfortunately, the build failed. The build output is available here:
https://new.embeetle.com/downloads/misc/openocd_hpmicro_build_output.txt

If I follow the same procedure, but instead of building the hpmicro OpenOCD repo, I build the official OpenOCD repo, then it works. In other words, the three lines at the bottom of the file ~/Work/xpacks/openocd-xpack.git/scripts/application.sh would then be:

XBB_APPLICATION_OPENOCD_GIT_URL="https://github.com/openocd-org/openocd.git"
XBB_APPLICATION_OPENOCD_GIT_BRANCH="master"
XBB_APPLICATION_OPENOCD_GIT_COMMIT="HEAD"

Building this official OpenOCD repo results in this output:
https://new.embeetle.com/downloads/misc/openocd_build_output.txt

3. Question

Using the same build procedure, why does building the hpmicro OpenOCD (https://github.com/hpmicro/riscv-openocd.git) fail and the official OpenOCD (https://github.com/openocd-org/openocd.git) succeed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions