Loongarch64 libressl fatal error: bn_arch.h: No such file or directory

my config is default other than selecting loongarch64 as target, I wonder if tools/mkimage/Makefile could be adjusted to stop build dumpimage

i believe it can be omitted in the makefile. Its been a while since I looked at the uboot tools source.

can you build it on its own ..

make package/uboot-tools/compile V=s

make package/uboot-tools/compile V=s does not work, the error seems not even related to u-boot build. I looked at u-boot source briefly, u-boot also uses make menuconfig and it has option like:

    Architecture select (Sandbox)  ---> 

where there is no LoongArch architecture to choose

and

    Tools options  ---> 

where it has:

┌─dddddddddddddddddddddddddddddddddddddd Use OpenSSL's libcrypto library for host tools                                         ┐
  │ CONFIG_TOOLS_LIBCRYPTO:                                                                                                       │  
  │                                                                                                                               │  
  │ Cryptographic signature, verification, and encryption of images is                                                            │  
  │ provided by host tools using OpenSSL's libcrypto. Select 'n' here if                                                          │  
  │ you wish to build host tools without OpenSSL. mkimage will not have                                                           │  
  │ the ability to sign images.                                                                                                   │  
  │ This selection does not affect target features, such as runtime FIT                                                           │  
  │ signature verification.                                                                                                       │  
  │                                                                                                                               │  
  │ Symbol: TOOLS_LIBCRYPTO [=y]                                                                                                  │  
  │ Type  : bool                                                                                                                  │  
  │ Prompt: Use OpenSSL's libcrypto library for host tools                                                                        │  
  │   Location:                                                                                                                   │  
  │     -> Tools options                                                                                                          │  
  │   Defined at tools/Kconfig:27                                                                                                 │  
  │   Selected by [y]:                                                                                                            │  
  │   - TOOLS_KWBIMAGE [=y]                                      

but the u-boot menconfig options seems not editable in openwrt build, right?

you'll need to edit the makefile. Since this is a new exploration you can probably remove these entries from the openwrt makfile..

package/boot/uboot-tools/Makefile

define Build/Configure
	$(call Build/Compile/Default,tools-only_defconfig)
  -	$(SED) 's/CONFIG_TOOLS_LIBCRYPTO=y/# CONFIG_TOOLS_LIBCRYPTO is not set/' $(PKG_BUILD_DIR)/.config
  - $(SED) 's/CONFIG_TOOLS_KWBIMAGE=y/# CONFIG_TOOLS_KWBIMAGE is not set/' $(PKG_BUILD_DIR)/.config
endef

see if it makes a difference

what about the tools/mkimage/Makefile?

[root@fedora openwrt]# cat tools/mkimage/Makefile 
#
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk

PKG_NAME:=mkimage
PKG_VERSION:=2025.10

PKG_SOURCE:=u-boot-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:= \
	https://mirror.cyberbits.eu/u-boot \
	https://ftp.denx.de/pub/u-boot \
	ftp://ftp.denx.de/pub/u-boot
PKG_HASH:=b4f032848e56cc8f213ad59f9132c084dbbb632bc29176d024e58220e0efdf4a

HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/u-boot-$(PKG_VERSION)

include $(INCLUDE_DIR)/host-build.mk

define Host/Configure
	$(MAKE) -C $(HOST_BUILD_DIR) \
		HOSTCFLAGS="$(HOST_CFLAGS)" \
		HOSTLDFLAGS="$(HOST_LDFLAGS)" \
		PKG_CONFIG_EXTRAARGS="--static" \
		V=$(if $(findstring c,$(OPENWRT_VERBOSE)),1) \
		tools-only_config

	sed -i 's/CONFIG_TOOLS_MKEFICAPSULE=y/# CONFIG_TOOLS_MKEFICAPSULE is not set/' $(HOST_BUILD_DIR)/.config
endef

define Host/Compile
	$(MAKE) -C $(HOST_BUILD_DIR) \
		HOSTCFLAGS="$(HOST_CFLAGS)" \
		HOSTLDFLAGS="$(HOST_LDFLAGS)" \
		PKG_CONFIG_EXTRAARGS="--static" \
		V=$(if $(findstring c,$(OPENWRT_VERBOSE)),1) \
		tools-only
endef

define Host/Install
	$(CP) $(HOST_BUILD_DIR)/tools/mkimage $(STAGING_DIR_HOST)/bin/
	$(CP) $(HOST_BUILD_DIR)/tools/mkenvimage $(STAGING_DIR_HOST)/bin/
endef

define Host/Clean
	rm -f $(STAGING_DIR_HOST)/bin/mkimage
	rm -f $(STAGING_DIR_HOST)/bin/mkenvimage
endef

$(eval $(call HostBuild))

can you unset mkimage from menuconfig ? maybe try unsetting it just to see it the build succeeds. You may even be able to bump past it to evaluate the rest of the build. Just tack on the -i flag to your make command (-i ignore errors)

make -j $(nproc) V=s -i

I just tried make -j1 V=s -i, the build process continued, waiting for the rest of build :slight_smile:

keep in mind (or a close watch on the build) all errors will be ignored now. Its good to log the output and grep it for errors after build completes. And you need to eventually do something about the conflicts ... but using the -i will give you some gratification which can be important on such a project.

1 Like

it finally finished with below, core dumped ? I assume the image would be under target/linux/loongarch64/image, but there is no image there. I will address the mkimage error first then and see what other errors I may have.

IPKG_INSTROOT=/usr/src/openwrt/build_dir/target-loongarch64_generic_musl/root.orig-loongarch64 /usr/src/openwrt/staging_dir/host/bin/fakeroot /usr/src/openwrt/staging_dir/host/bin/apk --root /usr/src/openwrt/build_dir/target-loongarch64_generic_musl/root.orig-loongarch64 --keys-dir /usr/src/openwrt --no-logfile --preserve-env list --quiet --manifest --no-network --repositories-file /dev/null | sort | sed 's/ / - /'  > /usr/src/openwrt/bin/targets/loongarch64/generic/openwrt-loongarch64-generic-generic.manifest
/usr/src/openwrt/staging_dir/host/bin/fakeroot: line 185: 1240676 Segmentation fault      (core dumped) FAKEROOTKEY=$FAKEROOTKEY LD_LIBRARY_PATH="$PATHS" LD_PRELOAD="$FAKEROOT_LIB" "$@"
make[5]: Leaving directory '/usr/src/openwrt/target/linux/loongarch64/image'
make[4]: Leaving directory '/usr/src/openwrt/target/linux/loongarch64'
make[3]: Leaving directory '/usr/src/openwrt/target/linux'

Good work! The build would fail in the end because of the fatal error you bumped past. fix the conflict for dump image and you should be all set.

unfortunately, after removing the SSL dependency for mkimage/u-boot as you suggested, the core dump from fakeroot issue persisted

yes thats to be expected, i only suggested this so that you coiuld evaluate the remainder of the build.

you likely need to add and ifndef.. def .. endif for the ssl declaration in one of the conflicting packages so that its only included once. or maybe something like this in one of the makefiles the makefile

 ifeq ($(ARCH),loongarch64) ...

Sorry this does not work, I think for now I can come to conclusion that there is no error in the rest of build except fakeroot coredump and mkimage/u-boot SSL conflicts, I think fakeroot coredump is most likely affected by the mkimage/u-boot SSL conflicts. I even tried to remove mkimage from the build as following diff, then fakeroot core dumped. I tried openwrt build on an x86 build machine selecting loongarch as target, the build works fine, I am going to upgrade the libressl to 4.1.0 in openwrt on x86 build machine and see if I can reproduce the issue.


[root@fedora openwrt]# git diff
diff --git a/package/boot/uboot-tools/Makefile b/package/boot/uboot-tools/Makefile
index 6e0c996f6d..520d458d90 100644
--- a/package/boot/uboot-tools/Makefile
+++ b/package/boot/uboot-tools/Makefile
@@ -70,8 +70,6 @@ endef
 
 define Build/Configure
        $(call Build/Compile/Default,tools-only_defconfig)
-       $(SED) 's/CONFIG_TOOLS_LIBCRYPTO=y/# CONFIG_TOOLS_LIBCRYPTO is not set/' $(PKG_BUILD_DIR)/.config
-       $(SED) 's/CONFIG_TOOLS_KWBIMAGE=y/# CONFIG_TOOLS_KWBIMAGE is not set/' $(PKG_BUILD_DIR)/.config
 endef
 
 MAKE_FLAGS += \
diff --git a/tools/Makefile b/tools/Makefile
index 79d3954fef..b8a34d59fd 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -55,7 +55,7 @@ tools-y += m4
 tools-y += make-ext4fs
 tools-y += meson
 tools-y += missing-macros
-tools-y += mkimage
+#tools-y += mkimage
 tools-y += mklibs
 tools-y += mtd-utils
 tools-y += mtools
@@ -120,7 +120,7 @@ $(curdir)/llvm-bpf/compile := $(curdir)/cmake/compile
 $(curdir)/make-ext4fs/compile := $(curdir)/zlib/compile
 $(curdir)/meson/compile := $(curdir)/ninja/compile
 $(curdir)/missing-macros/compile := $(curdir)/autoconf/compile
-$(curdir)/mkimage/compile += $(curdir)/bison/compile $(curdir)/libressl/compile
+#$(curdir)/mkimage/compile += $(curdir)/bison/compile $(curdir)/libressl/compile
 $(curdir)/mklibs/compile := $(curdir)/libtool/compile
 $(curdir)/mold/compile := $(curdir)/cmake/compile $(curdir)/zlib/compile $(curdir)/zstd/compile
 $(curdir)/mpc/compile := $(curdir)/mpfr/compile $(curdir)/gmp/compile
diff --git a/tools/libressl/Makefile b/tools/libressl/Makefile
index 4072194763..33f642dde9 100644
--- a/tools/libressl/Makefile
+++ b/tools/libressl/Makefile
@@ -8,8 +8,8 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=libressl
-PKG_VERSION:=3.7.3
-PKG_HASH:=7948c856a90c825bd7268b6f85674a8dcd254bae42e221781b24e3f8dc335db3
+PKG_VERSION:=4.1.0
+PKG_HASH:=0f71c16bd34bdaaccdcb96a5d94a4921bfb612ec6e0eba7a80d8854eefd8bb61
 
 PKG_CPE_ID:=cpe:/a:openbsd:libressl
 

@anon63541380 @Hostle I can reproduce the same SSL conflict issue on x86 build machine after upgrading libressl from 3.7.3 to 4.1.0 as diff below:

diff --git a/tools/libressl/Makefile b/tools/libressl/Makefile
index 4072194763..33f642dde9 100644
--- a/tools/libressl/Makefile
+++ b/tools/libressl/Makefile
@@ -8,8 +8,8 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=libressl
-PKG_VERSION:=3.7.3
-PKG_HASH:=7948c856a90c825bd7268b6f85674a8dcd254bae42e221781b24e3f8dc335db3
+PKG_VERSION:=4.1.0
+PKG_HASH:=0f71c16bd34bdaaccdcb96a5d94a4921bfb612ec6e0eba7a80d8854eefd8bb61
 
 PKG_CPE_ID:=cpe:/a:openbsd:libressl

SSL conflicts while building dumpimage

  HOSTLD  tools/dumpimage
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-ecdsa.o): in function `ecdsa_sign':
ecdsa.c:(.text+0xd50): multiple definition of `ecdsa_sign'; tools/generated/lib/ecdsa/ecdsa-libcrypto.o:ecdsa-libcrypto.c:(.text+0xab0): first defined here
/usr/bin/ld: /usr/src/openwrt/staging_dir/host/lib/libcrypto.a(libcrypto_la-ecdsa.o): in function `ecdsa_verify':
ecdsa.c:(.text+0x12d0): multiple definition of `ecdsa_verify'; tools/generated/lib/ecdsa/ecdsa-libcrypto.o:ecdsa-libcrypto.c:(.text+0xc30): first defined here
collect2: error: ld returned 1 exit status
make[5]: *** [scripts/Makefile.host:106: tools/dumpimage] Error 1
make[4]: *** [Makefile:2434: tools-only] Error 2
make[4]: Leaving directory '/usr/src/openwrt/build_dir/host/u-boot-2025.10'
make[3]: *** [Makefile:54: /usr/src/openwrt/build_dir/host/u-boot-2025.10/.built] Error 2
make[3]: Leaving directory '/usr/src/openwrt/tools/mkimage'
time: tools/mkimage/compile#10.20#1.46#11.67
    ERROR: tools/mkimage failed to build.

maybe I am miss something while upgrading libressl to 4.1.0 in openwrt build? somewhere else in the build needs to be changed too for libressl upgrade?

It MAY clash with host openssl-static / openssl-devel package.

Here is the reproduction steps on x86 build machine

git clone https://github.com/openwrt/openwrt.git
cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a

make menuconfig to select loongarch target

change tools/libressl/Makefile to 4.1.0

make defconfig download clean

FORCE_UNSAFE_CONFIGURE=1 make -j6 V=s world

anyway to avoid the clash?

revert the patch and test 3.7.3 ..? seems like an bug introduce with the new commit.

3.7.3 works fine on x86 build machine, but on loongarch build machine, libressl is required to upgrde to 4.1.0 that started supporting loongarch

Run ar t on that library and check for duplicate object files (it is grandfather of t(APE)ar , same command switches)