New user's registration have been closed due to high spamming and low trafic on this forum. Please contact forum admins directly if you need an account. Thanks !

How to build a kernel for Debian on Excito B3

Discuss development on Bubba
Post Reply
fredrikj
Posts: 45
Joined: 27 Jul 2011, 12:31

How to build a kernel for Debian on Excito B3

Post by fredrikj »

I would like to learn how to build a custom kernel package for Debian on Excito B3. However I need some help with that.

I'm a developer by trade and quite comfortable managing Debian systems. Howerver C is not my home turf and I suppose the kernel needs to be cross compiled on a X86_64 to avoid a compile cycle measured in days.

I have found https://github.com/Excito/kernel-5.10 and I suppose a good start is to check out that repository on my laptop. Then what? Merge it with a more recent upstream repo? How? And then?

Help! :)
fredrikj
Posts: 45
Joined: 27 Jul 2011, 12:31

Re: How to build a kernel for Debian on Excito B3

Post by fredrikj »

My primary goal is to be able to build the most recent kernel version of Debian, 5.10.162.

An awesome but perhaps less likely stretch goal for me is to attempt the most recent Debian testing kernel. Right now 6.1.12.

https://tracker.debian.org/pkg/linux
Gordon
Posts: 1461
Joined: 10 Aug 2011, 03:18

Re: How to build a kernel for Debian on Excito B3

Post by Gordon »

I have not built a uImage kernel for quite some time now. Too much of a hassle. The last one I built I configured with an initrd to serve as a secondary 'BIOS' that enables me to boot a regular zImage. This idea originally came from Sakaki and I refined it to be more transparent towards the final running system. I have the methods as well as the preboot kernel available on my GitHub account (https://github.com/gordonb3/bubba-b3-kernel). To build your own kernel you also need the buildkernel-b3 script from Sakaki (https://github.com/sakaki-/buildkernel-b3).

You can simply build a new kernel on the B3 itself. Make sure that you have screen installed and started so that you will not have to keep the SSH connection open. Yes building on the B3 will take quite some time and so if sources allow I do use a x86 virtual machine for cross compiling because I found that x86_64 crossdev creates paths that are typical for the host operating system and you end up with items ending up in e.g. /usr/lib64 and it doesn't work on the B3.
Gordon
Posts: 1461
Joined: 10 Aug 2011, 03:18

Re: How to build a kernel for Debian on Excito B3

Post by Gordon »

Oh, to create a kernel:
  • install the kernel source package
  • copy `.config` from your current running kernel (or that from that GitHub page) into the main source directory (where Makefile is)
  • run `make menuconfig` (also do this if you do not intend to make changes to the config)
  • if you do want to add functions or modules you can select them here
  • exit menuconfig
  • if using the method I linked above run `build-zImage-b3`
  • to create a uImage: run `make zImage && make kirkwood-b3.dtb && make modules_install`, then follow up with the following commands

    Code: Select all

        pushd arch/arm/boot
        # per https://lists.debian.org/debian-boot/2012/08/msg00804.html
        echo -n -e \\x11\\x3f\\x3f\\xee >  cache_head_patch
        echo -n -e \\x01\\x35\\xc3\\xe3 >> cache_head_patch
        echo -n -e \\x11\\x3f\\x2f\\xee >> cache_head_patch
        echo -n -e \\x00\\x30\\xa0\\xe3 >> cache_head_patch
        echo -n -e \\x17\\x3f\\x07\\xee >> cache_head_patch
        cat cache_head_patch zImage dts/kirkwood-b3.dtb > zImage-dts-appended
        rm cache_head_patch
        mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 \
          -n "Bubba B3 kernel" -d zImage-dts-appended ../../../uImage
        rm zImage-dts-appended
        popd
MouettE
Site admin
Posts: 341
Joined: 06 Oct 2011, 19:45

Re: How to build a kernel for Debian on Excito B3

Post by MouettE »

Building custom kernel for the b3's debian system is one area where documentation is ... well absent. It's not overly complicated but I admit I never took the time to write it. Note that the goal is to create a kernel deb package.

You can either build this package directly on the b3 (at least 8 hours) or cross-compile it on another system (~20-30 minutes on a reasonably modern computer). To cross compile, you need to install cross compilation tools and dependencies with the following commands on a debian system or chroot :

Code: Select all

dpkg --add-architecture armel
apt update
apt install crossbuild-essential-armel device-tree-compiler u-boot-tools bc gawk bison flex libncurses-dev libssl-dev devscripts git git-buildpackage
If you compile directly on a b3, you just need to install build dependencies :

Code: Select all

apt update
apt install build-essential device-tree-compiler u-boot-tools bc gawk bison flex libncurses-dev libssl-dev devscripts git git-buildpackage
After that, you can clone the repository (as a regular user of course):

Code: Select all

git clone https://github.com/Excito/kernel-5.10.git
I use quilt to manage the patches, you should configure it following this guide.

Now everything is in place. You could compile a binary-only package with these commands:
  • Cross-compiling :

    Code: Select all

    dpkg-buildpackage -aarmel -us -uc -b
  • Directly on the b3 :

    Code: Select all

    dpkg-buildpackage -us -uc -b
There are a serie of patches for the platform which include the kernel configuration itself. If you want to edit this configuration, begin by applying all the patches (configuration is the last one) :

Code: Select all

quilt push -a
Then apply the configuration (remove ARCH=arm if you run this directly on the b3) :

Code: Select all

make ARCH=arm bubba3_defconfig
You can then edit the configuration with the usual tools :

Code: Select all

make ARCH=arm menuconfig
Once you're happy with your configuration, generate the new configuration file and refresh the configuration patch:

Code: Select all

make ARCH=arm savedefconfig
mv defconfig arch/arm/bubba3_defconfig
quilt refresh
After that you can recompile the binary package with the above dpkg-buildpackage command, upload and test it on the b3.

In order to compile a newer version, you need first to port the patches in debian/patches for this version. This is a different beast as sometimes kernel changes between the versions break things and you need to update the patches. Quilt makes this easy though as long as you're careful.

Note that as bookworm is in soft freeze, it seems that the included kernel will be 6.1 series. I will soon start working on creating a 6.1 package for the b3.
fredrikj
Posts: 45
Joined: 27 Jul 2011, 12:31

Re: How to build a kernel for Debian on Excito B3

Post by fredrikj »

Thanks Mouette and Gordon for your help!

Now I have something to do the next rainy weekend here. And the south of Sweden is quite rainy this time of the year, so sooner rather than later i believe. ;)

I'll be back with a followup on my progress.

Thanks again, this has been on my TODO-list for quite some time!
MouettE
Site admin
Posts: 341
Joined: 06 Oct 2011, 19:45

Re: How to build a kernel for Debian on Excito B3

Post by MouettE »

FYI I created a 6.1 repository and ported the patchset and configuration. It compiles fine but I did not test it yet.
Post Reply