Building a package

Hello all,

I'd like to TRY to compile a package from NEWER sources for OLDER target openwrt version. (I understand some code may not compile, but I gotta give a try).

I'm doing it on modern Ubuntu 22.04. I'd wish to use smaller precompiled toolchain.

For that I

  1. downloaded TARGET old arch SDK (which IS toolchain as I understand, as there's quite a mess in naming)

  2. untar-ed it to a directory on Ubuntu22 (gcc, g++ etc etc are installed according instructions)

  3. run
    ./scripts/feeds update -a
    ./scripts/feeds install packageName

  4. When make menuconfig NO TARGET ARCHS are shown (as I understand, compilation will be automatically done for the downloaded target SDK);
    My packages appear (with dependencies) in the make menuconfig

  5. OK, now I'd like to compile NEW VERSION packages from sources.

QUESTIONS ARE:
Will this scheme work?
How do I get new sources say, for ip-full package? (I see Makefile and patches only on gitghub).

Any help would be great.

UPDATE:
Git-downloaded the full latest version of openwrt, unfortunately, it doesn't contain older target architectures

which version of openwrt do you need?

Did you follow the instructions at https://openwrt.org/docs/guide-developer/toolchain/using_the_sdk?

It would also help a lot if you told us the version and target of the SDK instead of just calling it NEWER and OLDER and TARGET.

That said: You need to tell the build system how to build the new version of your package. Every package has the build definition (it's a Makefile) in the package subdirectory. If you edit that, you get the quick 'n' dirty solution.

The cleaner option is to create a local package feed with the package you would like to compile.

1 Like

TNX for response. I'm trying to compile later version of ip-full for 18.06. TARGET, OLDER, NEWER were used me to understand if I'm on the right way.. In general, you see.

Of course I have read about using SDK. Together with other articles, and older versions - hard to swallow all... )

Host is Ubuntu 22.04
Toolchain is last 22.03.5 (git clone https://git.openwrt.org/openwrt/openwrt.git)
Target is 18.06.2 on ixp4xx device (4.9 kernel)
package needed is ip-full

UPDATE:
I was able to add old Intel ixp4xx architecture to my toolchain MANUALLY - make menuconfig sees and shows the architecture now.
Compiling make tools/install ... waiting for errors of course ))))

UPD1:
make tools/install - ok, finished!
make toolchain/install - ok!
make package/ip-full/download - didn't work (no source?)

make package/iproute2/download - ok!
make package/iproute2/prepare - ok!
make package/iproute2/compile - quit with errors like:

In file included from libebt_among.c:21:
/home/build/openwrt/staging_dir/toolchain-armeb_xscale_gcc-12.3.0_musl/include/linux/if_ether.h:142:8: error: redefinition of 'struct ethhdr'
  142 | struct ethhdr {
      |        ^~~~~~
In file included from /home/build/openwrt/staging_dir/toolchain-armeb_xscale_gcc-12.3.0_musl/include/netinet/ether.h:8,
                 from libebt_among.c:19:
/home/build/openwrt/staging_dir/toolchain-armeb_xscale_gcc-12.3.0_musl/include/netinet/if_ether.h:115:8: note: originally defined here
  115 | struct ethhdr {
      |        ^~~~~~
make[5]: *** [GNUmakefile:169: libebt_among.o] Error 1
make[5]: Leaving directory '/home/build/openwrt/build_dir/target-armeb_xscale_musl/linux-ixp4xx_generic/iptables-1.8.8/extensions'
make[4]: *** [Makefile:501: all-recursive] Error 1
make[4]: Leaving directory '/home/build/openwrt/build_dir/target-armeb_xscale_musl/linux-ixp4xx_generic/iptables-1.8.8'
make[3]: *** [Makefile:410: all] Error 2
make[3]: Leaving directory '/home/build/openwrt/build_dir/target-armeb_xscale_musl/linux-ixp4xx_generic/iptables-1.8.8'
make[2]: *** [Makefile:746: /home/build/openwrt/build_dir/target-armeb_xscale_musl/linux-ixp4xx_generic/iptables-1.8.8/.built] Error 2
make[2]: Leaving directory '/home/build/openwrt/package/network/utils/iptables'
time: package/network/utils/iptables/compile#0.25#0.06#0.29
    ERROR: package/network/utils/iptables failed to build.
make[1]: *** [package/Makefile:120: package/network/utils/iptables/compile] Error 1
make[1]: Leaving directory '/home/build/openwrt'
make: *** [/home/build/openwrt/include/toplevel.mk:232: package/iproute2/compile] Error 2

Toolchain needs to match the target version compiled.
If you are compiling for 18.06.x, you will need the 18.06 toolchain.

2 Likes

OK, what if I switch to it by changing git branch after git clone? E.g. git checkout v18.06.2

Moreover,

so what is "cross-compiling" then?

Cross-compiling means that although you are using a x86 host for compiling work, you are not compiling for x86, but for ARMsomething. So, the cross-compile toolchain running in x86 produces ARM binaries as compilation result.

1 Like

OK, I know that, but I meant something else.

I added kernel 4.9 description/hashes in 22.03, and toolchain recognized it. I suppose it uses 4.9 when target matches this kernel version... There were errors without 4.9 being described, but after - errors gone.

Much better.
After checking out the correct branch or tag, you need to rebuild the tools & toolchain.

But I still doubt that you will reach a compatible package as the end-result (if you try backporting a much newer ip-full to the ancient 18.06). Too many things have changed in the supporting libraries etc. (including the main musl C lib).

1 Like

Exactly. So I'd like to try my iterations (probably with older gcc g++) until I get lowest version of ip with XFRM (for 18.06).

(and don't ask me why ))) - the device is in production many years and very far from me, can't replace it)

To increase possibility of getting a compatible binary, you should use the exactly same toolchain as the original firmware was compiled with. Meaning, that if the device has an official 18.06.2 , you have hope. But if it is an OEM hacked derivative version of "almost OpenWrt", there is practically no hope.

Well, I used official OpenWrt sources... So it should be, unless those official repos don't use OEM revisions you mentioned...

I still don't get why you are compiling the toolchain yourself? Just download the prebuilt SDK for 18.06.2, it contains the complete toolchain and you are immediately ready to compile packages. If it doesn't work on an up-to-date Ubuntu (which is very likely), try running an older version in a virtual machine.

I do this regularly to build a private package for the current OpenWrt version. All I have to do is add my package feed to feeds.conf.default, refresh the feeds and build the package.

Didn't work 4 me. Tried on Ubuntu 22-04 and 18-04.May be I'll try again from the scratch tomorrow, now trying to finish via git.
Thank you for your feedback!

OK, successfully compiled iproute2:

on Ubuntu 18

git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt
git branch -a
git tag
git checkout v18.06.2
make tools/install
make toolchain/install
RENAME/DELETE openwrt/package/network/utils/iproute2
**COPY iproute2 folder (Makefile + patches + files) FROM 19.07 to path above**
./scripts/feeds update iproute2
make package/iproute2/prepare
make package/iproute2/compile

Got ip-full_5.0.0-2.1_armeb_xscale.ipk (native was version 4.16)

Copied to 18.06 device.

opkg install /path/to/ip-full_5.0.0-2.1_armeb_xscale.ipk
Installing ip-full (5.0.0-2.1) to root...
Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for ip-full:
 *      libelf
 *      libcap
 * opkg_install_cmd: Cannot install package ip-full.

Then installed libcap.

opkg install libcap
Installing libcap (2.25-2) to root...
Downloading http ://downloads.openwrt.org/releases/18.06.2/packages/armeb_xscale/packages/libcap_2.25-2_armeb_xscale.ipk
Configuring libcap.

root@OpenWrt:~# opkg install ip-full_5.0.0-2.1_armeb_xscale.ipk
Installing ip-full (5.0.0-2.1) to root...
Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for ip-full:
 *      libelf
 * opkg_install_cmd: Cannot install package ip-full.`

So libelf is an issue. But the package has compiled OK. I even installed ip-tiny with no problems, but seems not enough to get XFRM interface.

Most important is that stuff from at least 19.07 compiled for 18.06, so need to solve libelf to try further steps.

UPDATE2

Re-compiled iproute2 by changing depends from libelf to libelf1 in the Makefile.
Point is I couldn't trigger libelf to compile, and libelf1 is already in the standard repo.

and voila... iproute2 v5.0.0 from 19.07 was installed on 18.06.2 4.9 kernel

root@OpenWrt:~/with libelf1# opkg install ip-full_5.0.0-2.1_armeb_xscale.ipk
Installing ip-full (5.0.0-2.1) to root...
Configuring ip-full.

root@OpenWrt:~/with libelf1# opkg info ip-full
Package: ip-full
Version: 4.16.0-8
Depends: libc, libnl-tiny, libmnl
Provides: ip
Status: unknown ok not-installed
Section: net
Architecture: armeb_xscale
Size: 177202
Filename: ip-full_4.16.0-8_armeb_xscale.ipk
Description: Routing control utility (Full)

Package: ip-full
Version: 5.0.0-2.1
Depends: libc, libnl-tiny, libelf1, libcap
Provides: ip
Status: install user installed
Architecture: armeb_xscale
Installed-Time: 1694968656

Continuing experimenting as still no XFRM interface is available...

One more question:

Is there a way to integrate a target (ixp4xx) architecture into 22.03 toolchain?

I copied ixp4xx folder from the last supported release to 22.03 target/linux, so it is shown under make menuconfig, and I even was able to compile some packages.

But I decided to compile whole 22.03 image for ixp4xx. How make it to work?