hpmicro / riscv-openocd

Fork of OpenOCD that has RISC-V support
Other
1 stars 1 forks source link

OpenOCD build error #2

Open kristofmulier opened 1 year ago

kristofmulier commented 1 year ago

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:

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?

jhqian commented 1 year ago

Not sure what's going there, but the branch name is "riscv" rather name "master". And we've added some information about how to build openocd for windows on ubuntu https://github.com/hpmicro/riscv-openocd/wiki/Build-OpenOCD.

kristofmulier commented 1 year ago

Hi @jhqian I've tried with the branch name riscv instead of master:

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

Unfortunately, the build still fails.

However, today I tried the build procedure you sent to me over WeChat: https://github.com/hpmicro/riscv-openocd/wiki/Build-OpenOCD

I launched my Ubuntu VM and cloned the HPMicro OpenOCD repository:

image

Next, I followed the steps from the page you sent me. Unfortunately, it seems to go wrong already in the ./bootstrap step. This is what I get:

$ cd ~/openocd_hpmicro/riscv-openocd

$ sudo apt-get install -y autoconf automake autotools-dev bc bison \
     build-essential curl dejagnu expect flex gawk gperf libtool patchutils texinfo

$ sudo apt install libudev-dev libhidapi-dev libusb-1.0-0-dev

$ ./bootstrap
+ aclocal --warnings=all
+ libtoolize --automake --copy
+ autoconf --warnings=all
configure.ac:13: error: possibly undefined macro: AC_MSG_WARN
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:48: error: possibly undefined macro: AC_DEFINE
configure.ac:339: error: possibly undefined macro: AC_MSG_ERROR
configure.ac:598: error: possibly undefined macro: AC_MSG_NOTICE

$ ./configure
configure: error: cannot find required auxiliary files: config.guess config.sub compile missing install-sh

Thank you for your help.

jhqian commented 1 year ago

Perhaps, pkg-config is not installed. Give it a try?

jhqian commented 1 year ago

Hi @kristofmulier , any luck?

kristofmulier commented 1 year ago

# Navigate into the repository
# ============================
$ cd ~/openocd_hpmicro/riscv-openocd

# Install 'pkg-config'
# ====================
$ sudo apt install pkg-config
[sudo] password for kristof: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  pkg-config
0 upgraded, 1 newly installed, 0 to remove and 152 not upgraded.
Need to get 48,2 kB of archives.
After this operation, 134 kB of additional disk space will be used.
Get:1 http://be.archive.ubuntu.com/ubuntu jammy/main amd64 pkg-config amd64 0.29.2-1ubuntu3 [48,2 kB]
Fetched 48,2 kB in 0s (175 kB/s)
Selecting previously unselected package pkg-config.
(Reading database ... 236177 files and directories currently installed.)
Preparing to unpack .../pkg-config_0.29.2-1ubuntu3_amd64.deb ...
Unpacking pkg-config (0.29.2-1ubuntu3) ...
Setting up pkg-config (0.29.2-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...

# Try again to build OpenOCD
# ==========================

# STEP 1
# ------
$ ./bootstrap
+ aclocal --warnings=all
+ libtoolize --automake --copy
+ autoconf --warnings=all
+ autoheader --warnings=all
+ automake --warnings=all --gnu --add-missing --copy
configure.ac:22: installing 'build-aux/compile'
configure.ac:34: installing 'build-aux/config.guess'
configure.ac:34: installing 'build-aux/config.sub'
configure.ac:17: installing 'build-aux/install-sh'
configure.ac:17: installing 'build-aux/missing'
Makefile.am: installing './INSTALL'
Makefile.am: installing 'build-aux/depcomp'
Makefile.am:24: installing 'build-aux/mdate-sh'
Makefile.am:24: installing 'build-aux/texinfo.tex'
Setting up submodules
Submodule 'jimtcl' (https://github.com/msteveb/jimtcl.git) registered for path 'jimtcl'
Submodule 'src/jtag/drivers/libjaylink' (https://gitlab.zapb.de/libjaylink/libjaylink.git) registered for path 'src/jtag/drivers/libjaylink'
Submodule 'tools/git2cl' (https://git.savannah.nongnu.org/git/git2cl.git) registered for path 'tools/git2cl'
Cloning into '/home/kristof/openocd_hpmicro/riscv-openocd/jimtcl'...
Cloning into '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink'...
Cloning into '/home/kristof/openocd_hpmicro/riscv-openocd/tools/git2cl'...
Submodule path 'jimtcl': checked out '70b007b63669a709b0e8aef34a22658047815cc2'
Submodule path 'src/jtag/drivers/libjaylink': checked out '9aa7a5957c07bb6e862fc1a6d3153d109c7407e4'
Submodule path 'tools/git2cl': checked out '8373c9f74993e218a08819cbcdbab3f3564bbeba'
Generating build system...
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/config.guess'
libtoolize: copying file 'build-aux/config.sub'
libtoolize: copying file 'build-aux/install-sh'
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:38: warning: The macro `AC_PROG_CC_C99' is obsolete.
configure.ac:38: You should run autoupdate.
./lib/autoconf/c.m4:1659: AC_PROG_CC_C99 is expanded from...
configure.ac:38: the top level
configure.ac:43: installing 'build-aux/ar-lib'
configure.ac:37: installing 'build-aux/compile'
configure.ac:30: installing 'build-aux/missing'
libjaylink/Makefile.am: installing 'build-aux/depcomp'
Bootstrap complete. Quick build instructions:
./configure ....

# STEP 2
# ------
$ ./configure
checking for makeinfo... no
configure: WARNING: Info documentation will not be built.
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking for ranlib... ranlib
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.23... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... (cached) ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for an ANSI C-conforming const... yes
checking for unsigned long long int... yes
checking for long long int... yes
checking for library containing ioperm... none required
checking for library containing dlopen... none required
checking for library containing openpty... none required
checking for sys/socket.h... yes
checking for elf.h... yes
checking how to run the C preprocessor... gcc -E
checking for dirent.h... yes
checking for fcntl.h... yes
checking for malloc.h... yes
checking for netdb.h... yes
checking for poll.h... yes
checking for pthread.h... yes
checking for strings.h... (cached) yes
checking for sys/ioctl.h... yes
checking for sys/param.h... yes
checking for sys/select.h... yes
checking for sys/stat.h... (cached) yes
checking for sys/sysctl.h... no
checking for sys/time.h... yes
checking for sys/types.h... (cached) yes
checking for unistd.h... (cached) yes
checking for arpa/inet.h... yes
checking for ifaddrs.h... yes
checking for netinet/in.h... yes
checking for netinet/tcp.h... yes
checking for net/if.h... yes
checking whether to enable assertions... yes
checking for _Bool... yes
checking for stdbool.h that conforms to C99... yes
checking whether byte ordering is bigendian... no
checking for strndup... yes
checking for strnlen... yes
checking for gettimeofday... yes
checking for usleep... yes
checking for vasprintf... yes
checking for realpath... yes
checking whether to build a release... no
checking whether to build Doxygen as HTML... yes
checking whether to build Doxygen as PDF... no
checking whether to enable verbose USB I/O messages... no
checking whether to enable verbose USB communication messages... no
checking whether to enable malloc free space logging... no
checking for libusb-1.0... yes
configure: libusb-1.0 header bug workaround: LIBUSB1_CFLAGS changed to "-isystem /usr/include/libusb-1.0"
checking for capstone... no
checking for hidapi... no
checking for hidapi-hidraw... yes
checking for libftdi1... no
checking for libftdi... no
checking for libgpiod... no
checking for libjaylink >= 0.2... no
checking for environ in unistd.h and stdlib.h... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
=== configuring in jimtcl (/home/kristof/openocd_hpmicro/riscv-openocd/jimtcl)
configure: running /bin/bash ./configure.gnu --disable-option-checking '--prefix=/usr/local'  --cache-file=/dev/null --srcdir=.
Host System...x86_64-pc-linux-gnu
Build System...x86_64-pc-linux-gnu
C compiler... cc -g -O2
C++ compiler... c++ -g -O2
Build C compiler...cc
Checking for stdlib.h...ok
Checking for long long...ok
Checking for sizeof int...4
Checking for time.h...ok
Checking for sys/time.h...ok
Checking for sys/socket.h...ok
Checking for netinet/in.h...ok
Checking for arpa/inet.h...ok
Checking for netdb.h...ok
Checking for util.h...not found
Checking for pty.h...ok
Checking for sys/un.h...ok
Checking for dlfcn.h...ok
Checking for unistd.h...ok
Checking for dirent.h...ok
Checking for crt_externs.h...not found
Checking for execinfo.h...ok
Checking for sizeof time_t...8
Checking libs for inet_ntop...none needed
Checking libs for socket...none needed
Checking for ualarm...ok
Checking for lstat...ok
Checking for fork...ok
Checking for vfork...ok
Checking for system...ok
Checking for select...ok
Checking for execvpe...ok
Checking for geteuid...ok
Checking for mkstemp...ok
Checking for realpath...ok
Checking for isatty...ok
Checking for regcomp...ok
Checking for waitpid...ok
Checking for sigaction...ok
Checking for sys_signame...not found
Checking for sys_siglist...not found
Checking for isascii...ok
Checking for syslog...ok
Checking for opendir...ok
Checking for readlink...ok
Checking for sleep...ok
Checking for usleep...ok
Checking for pipe...ok
Checking for getaddrinfo...ok
Checking for utimes...ok
Checking for shutdown...ok
Checking for socketpair...ok
Checking for isinf...ok
Checking for isnan...ok
Checking for link...ok
Checking for symlink...ok
Checking for fsync...ok
Checking for dup...ok
Checking for umask...ok
Checking for localtime...ok
Checking for gmtime...ok
Checking for strptime...ok
Checking for clock_gettime...ok
Checking libs for backtrace...none needed
Checking libs for openpty...none needed
Checking for sysinfo...ok
Checking for struct sysinfo.uptime...ok
Checking for struct stat.st_mtimespec...not found
Checking for struct stat.st_mtim...ok
Checking for struct flock...ok
Checking for sys/types.h...(cached) ok
Checking if -D_FILE_OFFSET_BITS=64 is needed...no
Checking for fseeko...ok
Checking for ftello...ok
Checking for make...ok
Checking for asciidoc...no
Checking for sed...ok
Checking for _NSGetEnviron...not found
Checking environ declared in unistd.h...yes
Checking for sys/types.h...(cached) ok
Checking for sys/stat.h...(cached) ok
Checking for mkdir with one arg...no
Checking for S_IXUSR...ok
Checking for S_IRWXG...ok
Checking for S_IRWXO...ok
Checking for termios.h...ok
Enabling line editing
Checking for inline support...yes
Enabling references
Building static library
Extension aio...enabled
Extension array...enabled
Extension clock...enabled
Extension eventloop...enabled
Extension exec...enabled
Extension file...enabled
Extension readdir...enabled
Extension glob...enabled
Extension history...enabled
Extension interp...enabled
Checking libs for dlopen...none needed
Extension load...enabled
Extension nshelper...enabled
Extension namespace...enabled
Extension oo...enabled
Extension pack...enabled
Extension package...enabled
Extension posix...enabled
Extension regexp...enabled
Extension signal...enabled
Extension stdlib...enabled
Extension syslog...enabled
Extension tclcompat...enabled
Extension tree...enabled
Using built-in regexp
Jim static extensions: aio array clock eventloop exec file glob history interp load namespace nshelper oo pack package posix readdir regexp signal stdlib syslog tclcompat tree
Created jim-config.h
Created jimautoconf.h
Created Makefile from Makefile.in
Created tests/Makefile from tests/Makefile.in
Created examples.api/Makefile from examples.api/Makefile.in
Created build-jim-ext from build-jim-ext.in
Created jimtcl.pc from jimtcl.pc.in
=== configuring in src/jtag/drivers/libjaylink (/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink)
configure: running /bin/bash ./configure.gnu --disable-option-checking '--prefix=/usr/local'  --cache-file=/dev/null --srcdir=.
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking for ar... ar
checking the archiver (ar) interface... ar
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for libusb-1.0 >= 1.0.16... yes
checking whether byte ordering is bigendian... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating libjaylink/Makefile
config.status: creating libjaylink/version.h
config.status: creating libjaylink.pc
config.status: creating Doxyfile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

libjaylink configuration summary:
 - Package version ................ 0.2.0
 - Library version ................ 1:0:1
 - Installation prefix ............ /usr/local
 - Building on .................... x86_64-pc-linux-gnu
 - Building for ................... x86_64-pc-linux-gnu

Enabled transports:
 - USB ............................ yes
 - TCP ............................ yes

OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices        yes (auto)
cJTAG OSCAN1 tunneled thru MPSSE        yes (auto)
ST-Link Programmer                      yes (auto)
TI ICDI JTAG Programmer                 yes (auto)
Keil ULINK JTAG Programmer              yes (auto)
Altera USB-Blaster II Compatible        yes (auto)
Bitbang mode of FT232R based devices    yes (auto)
Versaloon-Link JTAG Programmer          yes (auto)
TI XDS110 Debug Probe                   yes (auto)
CMSIS-DAP v2 Compliant Debugger         yes (auto)
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Olimex ARM-JTAG-EW Programmer           yes (auto)
Raisonance RLink JTAG Programmer        yes (auto)
USBProg JTAG Programmer                 yes (auto)
Andes JTAG Programmer (deprecated)      no
CMSIS-DAP Compliant Debugger            yes (auto)
Nu-Link Programmer                      yes (auto)
Cypress KitProg Programmer              yes (auto)
Altera USB-Blaster Compatible           no
ASIX Presto Adapter                     no
OpenJTAG Adapter                        no
Linux GPIO bitbang through libgpiod     no
SEGGER J-Link Programmer                yes (auto)
Bus Pirate                              yes (auto)
Use Capstone disassembly framework      no

# STEP 3
# ------
$ make -j16
mkdir -p src
cat src/helper/startup.tcl src/jtag/startup.tcl src/target/startup.tcl src/server/startup.tcl src/flash/startup.tcl | ./src/helper/bin2char.sh > src/startup_tcl.inc || { rm -f src/startup_tcl.inc; false; }
make  all-recursive
make[1]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd'
Making all in jimtcl
make[2]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd/jimtcl'
    MKLDEXT _load-static-exts.c
    CC  jim-subcmd.o
    CC  jim-interactive.o
    CC  jim-format.o
    CC  jim.o
    CC  utf8.o
    CC  jimregexp.o
    CC  jimiocompat.o
    CC  linenoise.o
    CC  jim-tty.o
    CC  jim-aio.o
    CC  jim-array.o
    CC  jim-clock.o
    CC  jim-eventloop.o
    CC  jim-exec.o
    CC  jim-file.o
    CC  jim-history.o
    CC  jim-interp.o
    CC  jim-load.o
    CC  jim-namespace.o
    CC  jim-pack.o
    CC  jim-package.o
    CC  jim-posix.o
    CC  jim-readdir.o
    CC  jim-regexp.o
    CC  jim-signal.o
    CC  jim-syslog.o
    TCLEXT  _glob.c
    CC  glob.o
    TCLEXT  _nshelper.c
    TCLEXT  _oo.c
    CC  nshelper.o
    CC  oo.o
    TCLEXT  _stdlib.c
    TCLEXT  _tclcompat.c
    CC  stdlib.o
    CC  tclcompat.o
    TCLEXT  _tree.c
    CC  jimsh.o
    CC  tree.o
    TCLEXT  _initjimsh.c
    CC  _load-static-exts.o
    CC  initjimsh.o
    AR  libjim.a
    LINK    jimsh
[TOO MUCH OUTPUT...]

# STEP 4
# ------
$ make install
make  install-recursive
make[1]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd'
Making install in jimtcl
make[2]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd/jimtcl'
make[2]: Nothing to be done for 'install'.
make[2]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd/jimtcl'
Making install in src/jtag/drivers/libjaylink
make[2]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink'
Making install in libjaylink
make[3]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink/libjaylink'
make[4]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink/libjaylink'
make[4]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink/libjaylink'
make[3]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink/libjaylink'
make[3]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink'
make[4]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink'
make[4]: Nothing to be done for 'install-exec-am'.
make[4]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink'
make[3]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink'
make[2]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd/src/jtag/drivers/libjaylink'
make[2]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd'
restore=: && backupdir=".am$$" && \
am__cwd=`pwd` && CDPATH="${ZSH_VERSION+.}:" && cd . && \
rm -rf $backupdir && mkdir $backupdir && \
if (echo makeinfo missing; true --version) >/dev/null 2>&1; then \
  for f in doc/openocd.info doc/openocd.info-[0-9] doc/openocd.info-[0-9][0-9] doc/openocd.i[0-9] doc/openocd.i[0-9][0-9]; do \
    if test -f $f; then mv $f $backupdir; restore=mv; else :; fi; \
  done; \
else :; fi && \
cd "$am__cwd"; \
if echo makeinfo missing; true   -I doc -I ./doc \
 -o doc/openocd.info ./doc/openocd.texi; \
then \
  rc=0; \
  CDPATH="${ZSH_VERSION+.}:" && cd .; \
else \
  rc=$?; \
  CDPATH="${ZSH_VERSION+.}:" && cd . && \
  $restore $backupdir/* `echo "./doc/openocd.info" | sed 's|[^/]*$||'`; \
fi; \
rm -rf $backupdir; exit $rc
makeinfo missing
cd . && git config core.hooksPath ./git-hooks || true
make[3]: Entering directory '/home/kristof/openocd_hpmicro/riscv-openocd'
 /usr/bin/mkdir -p '/usr/local/bin'
  /bin/bash ./libtool   --mode=install /usr/bin/install -c src/openocd '/usr/local/bin'
libtool: install: /usr/bin/install -c src/openocd /usr/local/bin/openocd
/usr/bin/install: cannot create regular file '/usr/local/bin/openocd': Permission denied
make[3]: *** [Makefile:2060: install-binPROGRAMS] Error 1
make[3]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd'
make[2]: *** [Makefile:5141: install-am] Error 2
make[2]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd'
make[1]: *** [Makefile:4827: install-recursive] Error 1
make[1]: Leaving directory '/home/kristof/openocd_hpmicro/riscv-openocd'
make: *** [Makefile:5134: install] Error 2
jhqian commented 1 year ago

hi @kristofmulier , it's been successfully built, but failed to be installed. please make sure your user has proper access to the targeting installation directory, or use 'sudo'.

kristofmulier commented 1 year ago

Hi Ryan, Thank you very much. Since it's built successfully, I should now be able to find the exectuable and the .so files around it. However, I can't find them. Where exactly should I look for the build output?

jhqian commented 1 year ago

openocd binary should be found in src directory

kristofmulier commented 1 year ago

Great, thank you @jhqian !

If I want to distribute this OpenOCD to our users, should I then distribute the whole src/ folder? Like this:

image

Or should I extract just a few files from here?

Other OpenOCD distributions have a structure like this:

image

They have folders like contrib, distro-info, scripts, ... that I cannot see in the src/ folder from the HPMicro build. So I'm a bit confused at this point.

I just want to make sure that the OpenOCD version we distribute to our users is complete and works "out of the box" on as many computers as possible.

jhqian commented 1 year ago

no need to pack the whole src folder, only the binary itself (if it's linked with static libraries) and some default tcl scripts located in "tcl" folder. make sure openocd config path is correctly set in your tool (please refer to https://openocd.org/doc/html/Running.html for more details about config path)

kristofmulier commented 1 year ago

Thank you @jhqian . I'll try this out and let you know if it works.

kristofmulier commented 1 year ago

Hi @jhqian , Thank you very much for all your help. We achieved a successful build. I'll repeat the steps here in this post, for future reference.

Ubuntu

On Ubuntu, I build OpenOCD this way:

$ mkdir ~/hpmicro
$ cd ~/hpmicro
$ git clone https://github.com/hpmicro/riscv-openocd.git
$ cd riscv-openocd/
$ sudo apt install -y autoconf automake autotools-dev bc bison build-essential curl dejagnu expect flex gawk gperf libtool patchutils texinfo pkg-config
$ sudo apt install -y libudev-dev libhidapi-dev libusb-1.0-0-dev
$ ./bootstrap
$ ./configure
$ make -j16
$ make install

This is basically the same as explained on the GitHub page https://github.com/hpmicro/riscv-openocd/wiki/Build-OpenOCD however, that GitHub page forgot the pkg-config package.

To distribute OpenOCD, it should be sufficient to just pack the src/openocd executable alongside the src/tcl folder:

📁 openocd_hpmicro_0.11.0_dev202239_64b
 ├ 📁 tcl
 └ 🗎 openocd

AlmaLinux (Docker)

We have a Docker image based on AlmaLinux. We prefer to build executables on this Docker installation, such that we're sure it will run on most Linux systems. Our Docker installation uses yum instead of apt repositories. That causes some headaches for the package installations. My colleage Johan fixed the problems. I'll document them here for future reference.

I got started like this:

$ mkdir /data/hpmicro
$ cd /data/hpmicro
$ git clone https://github.com/hpmicro/riscv-openocd.git
$ cd riscv-openocd/
$ yum install -y autoconf automake autotools-dev bc bison build-essential curl dejagnu expect flex gawk gperf libtool patchutils texinfo pkg-config
    Error: Unable to find a match: autotools-dev build-essential
$ yum install -y libudev-dev libhidapi-dev libusb-1.0-0-dev
    Error: Unable to find a match: libudev-dev libhidapi-dev libusb-1.0-0-dev

Our Docker Linux couldn't find these packages:

In a Docker shell, yum search <search-term> will look for packages containing <search-term> in their name or description. This is one way to figure out the correct package names. It usually requires some trial and error.

$ yum install xorg-x11-util-macros.noarch

Now ./bootstrap works, but ./configure fails with:

./configure: line 4961: syntax error near unexpected token `0.23'
./configure: line 4961: `PKG_PROG_PKG_CONFIG(0.23)'

After some searching for this error, Johan tried:

$ autoreconf -i -I /usr/share/aclocal/
    libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
    libtoolize: You should add the contents of 'm4/libtool.m4' to 'aclocal.m4'.
    libtoolize: You should add the contents of 'm4/ltversion.m4' to 'aclocal.m4'.
    configure.ac:38: warning: The macro `AC_PROG_CC_C99' is obsolete.
    configure.ac:38: You should run autoupdate.
    ./lib/autoconf/c.m4:1659: AC_PROG_CC_C99 is expanded from...
    configure.ac:38: the top level
    libtoolize: You should add the contents of the following files to 'aclocal.m4':
    libtoolize:   '/usr/local/share/aclocal/libtool.m4'
    libtoolize:   '/usr/local/share/aclocal/ltversion.m4'
    libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
    libtoolize: and rerunning libtoolize and aclocal.
    libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
    libtoolize: 'AC_PROG_RANLIB' is rendered obsolete by 'LT_INIT'

Now ./configure works. However, make still fails:

$ make
    make  all-recursive
    make[1]: Entering directory '/data/hpmicro/riscv-openocd'
    Making all in jimtcl
    make[2]: Entering directory '/data/hpmicro/riscv-openocd/jimtcl'
    make[2]: *** No rule to make target 'all'.  Stop.
    make[2]: Leaving directory '/data/hpmicro/riscv-openocd/jimtcl'
    make[1]: *** [Makefile:4827: all-recursive] Error 1
    make[1]: Leaving directory '/data/hpmicro/riscv-openocd'
    make: *** [Makefile:2005: all] Error 2

Ideas, not tried:

$ yum groupinstall "Development Tools"
$ yum install libusb-devel.x86_64

Our Docker image is based on AlmaLinux. Johan posted a question on the AlmaLinux forum to ask how to find the yum equivalent for the missing packages. See How to find the yum install equivalent for apt install instructions - Support - AlmaLinux

In other words, we couldn't complete the OpenOCD build on our Docker system.

Solution (for now): Johan used the Ubuntu compilation instructions (except for $ make install which is not needed) to compile OpenOCD on his Linux Mint desktop. The resulting OpenOCD executable can be found in src/openocd.

Johan then copied that executable into our Docker system. There is only one shared object missing: libhidapi-hidraw.so.0. He then copied that shared object from his Mint desktop into Docker and redefined LD_LIBRARY_PATH there to make OpenOCD find that shared object. OpenOCD then works, even without all the above addditional installs. Since it works on our Docker system, it should work on most Linux distros.

Next, he removed the src/openocd from his Linux Mint and ran make there again to see the link command:

./libtool
    --tag=CC
    --mode=link gcc
    -Wall
    -Wstrict-prototypes
    -Wformat-security
    -Wshadow
    -Wextra
    -Wno-unused-parameter
    -Wbad-function-cast
    -Wcast-align
    -Wredundant-decls
    -Wpointer-arith
    -Wundef
    -Wno-error=deprecated-declarations
    -Werror
    -DFD_SETSIZE=128
    -g
    -O2
    -o src/openocd src/main.o src/libopenocd.la
    ./jimtcl/libjim.a
    -lutil
    -ldl
    -Wl,-rpath,"\$ORIGIN"

Then Johan ran the same command again on his Linux Mint, with one extra option: -Wl,-rpath,"\$ORIGIN". This makes sure that the resulting executable will look in the directory containing it ($ORIGIN; you can also specify a relative path here) for libhidapi-hidraw.so.0 or any other shared library it needs. The resulting openocd now runs without setting LD_LIBRARY_PATH.

I packed Johan's openocd executable alongside the tcl folder and the libhidapi-hidraw.so.0 shared object. So, our OpenOCD distribution now looks like this:

📁 openocd_hpmicro_0.11.0_dev202239_64b
 ├ 📁 tcl
 ├ 🗎 libhidapi-hidraw.so.0
 └ 🗎 openocd

It works on our Docker installation (and therefore also on most Linux distros). You can download it directly from our server through this link:

https://new.embeetle.com/downloads/beetle_tools/linux/openocd_hpmicro_0.11.0_dev202239_64b.7z

jhqian commented 1 year ago

Thank you, @kristofmulier