Skip to content

Instantly share code, notes, and snippets.

@calibius
Last active March 17, 2021 03:55
Show Gist options
  • Save calibius/c314cd8588a7d9096fbff559891fccd6 to your computer and use it in GitHub Desktop.
Save calibius/c314cd8588a7d9096fbff559891fccd6 to your computer and use it in GitHub Desktop.
Building custom kernel for Void Linux rpi4 from Piraty's PR & quick reference for un-git-savy users

!!! Set up build environment

(Assuming you're using Void. If not, see Static XBPS for other distros, but first ask yourself why.)

  1. First, update your system.

    $ sudo xbps-install -Su
  2. Optional: install xtools

    $ sudo xbps-install xtools make xz qemu-user-static

!!Note: you could also directly clone Piraty's fork, but I don't show how to do that here. Both should methods work.

  1. Clone the void-packages git repository and install the bootstrap packages:

    $ cd
    $ git clone git://github.com/void-linux/void-packages.git
    $ cd void-packages
    $ ./xbps-src binary-bootstrap
  2. Config git with your email and name

    $ git config user.email "your@email.com"
    $ git config user.name "yourname"
  3. Add upstream

    $ git add upstream http://github.com/void-packages/void-packages.git
  4. Configure xbps_makejobs to utilize number of CPU cores +1. (replace <num>)

    echo XBPS_MAKEJOBS=<num> >~/void-packages/etc/conf 
$ cd 
$ git clone git://github.com/void-linux/void-mklive.git
$ cd mklive
$ make

$ cd void-packages
$ git fetch origin pull/26000/head:rpi4
$ git checkout -f rpi4
$ ./xbps-src -m masterdir.rpi4 binary-bootstrap
$ ./xbps-src -m masterdir.rpi4 -a aarch64-musl pkg rpi-base
#$ ./xbps-src -m masterdir.rpi4 -a aarch64-musl pkg rpi-kernel #unnecessary?
$ cd void-mklive
$ git fetch origin pull/153/head:rpi4
$ git checkout rpi4
$ make
###
$ d=$(date '+%Y%m%d')
$ repo="where/your/binpkgs/are" #eg ../void-packages/hostdir/binpkgs/rpi4
$ make XBPS_REPOSITORY="-r $repo" void-aarch64-musl-ROOTFS-$d.tar.xz void-rpi4-musl-$d.img.xz
# build the other images as well
#$ make XBPS_REPOSITORY="-r $repo" void-{armv6l,armv7l,aarch64}-musl-ROOTFS-$d.tar.xz void-rpi{1,2,3,4}-musl-$d.img.xz

You can also do this instead of the $ make ... for more customizability, ie installing packages etc:

cd void-mklive
make
sudo ./mkrootfs.sh aarch64
sudo ./mkplatformfs.sh -r ../void-packages/hostdir/binpkgs/rpi4/ -p "nano openvpn samba ufw transmission avahi socklog" rpi4-musl void-aarch64-musl-ROOTFS-*.tar.xz
sudo ./mkimage.sh -B 256MiB void-rpi4-musl-PLATFORMFS-*.tar.xz # -B: make /boot 256mb instead of 64mb

Clean up

:~/void-packages/ $ git checkout master && git brance -D rpi4
:~/void-mklive/ $ git checkout master && git brance -D rpi4

Troubleshooting

"Can't build crosstoolchain to itself" error.

If you see the below error message, then omit -a aarch64 from compile command.

$ ./xbps-src -a aarch64 pkg rpi-kernel
...
=> ERROR: cross-aarch64-linux-gnu-0.33_3: cannot be built, it's currently broken; see the build log:
=> ERROR: cross-aarch64-linux-gnu-0.33_3: Can't build crosstoolchain to itself

ERROR: rpi-base-3.0_1: cannot access wrksrc directory [/builddir/rpi-base-3.0]

=> rpi-base-3.0_1: building [meta] for aarch64-musl...
   [runtime] rpi3-base-3.0_1: not found (subpkg, ignored)
   [runtime] chrony-4.0_2: found (https://alpha.de.repo.voidlinux.org/current/aarch64)
   [runtime] rpi-firmware-20201123_4: found (https://alpha.de.repo.voidlinux.org/current/aarch64)
   [runtime] rpi3-kernel-5.4.83_2: found (/host/binpkgs/rpi4)
   [runtime] chrony-4.0_2: found (https://alpha.de.repo.voidlinux.org/current/aarch64)
   [runtime] rpi-firmware-20201123_4: found (https://alpha.de.repo.voidlinux.org/current/aarch64)
   [runtime] rpi4-kernel-5.4.83_2: found (/host/binpkgs/rpi4)
/void-packages/common/xbps-src/shutils/common.sh: line 31: cd: /builddir/rpi-base-3.0: No such file or directory
=> ERROR: rpi-base-3.0_1: cannot access wrksrc directory [/builddir/rpi-base-3.0]

mkdir masterdir.rpi4/builddir/rpi-base-3.0 seemed to resolve it...

repo="where/your/binpkgs/are"

I had to specify the exact branch, which is just the folder that contains the `.xbps files. Hopefully it gets you somewhere!

-repo="/home/user/void-packages/hostdir/binpkgs"
+repo="/home/user/void-packages/hostdir/binpkgs/<branch>"

The rest of your issues I do not quite understand exactly how to fix, sorry.


References / FAQs / Links

Usage info

mkrootfs.sh -h usage (The Void Linux rootfs maker for ARM platforms)

Usage: ./mkrootfs.sh [options] Supported architectures: i686, i686-musl, x86_64, x86_64-musl, armv5tel, armv5tel-musl, armv6l, armv6l-musl, armv7l, armv7l-musl aarch64, aarch64-musl, mipsel, mipsel-musl, ppc, ppc-musl ppc64le, ppc64le-musl, ppc64, ppc64-musl

Options Info
-b Set an alternative base-system package (defaults to base-voidstrap)
-c Set XBPS cache directory (defaults to $PWD/xbps-cachedir-)
-C Full path to the XBPS configuration file
-h Show this help
-r Set XBPS repository (may be set multiple times)
-x Use threads to compress the image (dynamic if unset)
-o Filename to write the ROOTFS archive to
-V Show version

mkimage.sh -h usage (The Void Linux image maker for ARM platforms)

Usage: ./mkimage.sh [options] The argument expects a tarball generated by void-mkrootfs. The platform is guessed automatically by its name. Accepted sizes suffixes: KiB, MiB, GiB, TiB, EiB.

Options Info
-b Set /boot filesystem type (defaults to FAT)
-B Set /boot filesystem size (defaults to 64MiB)
-r Set / filesystem type (defaults to EXT4)
-s Set total image size (defaults to 2GB)
-o Set image filename (guessed automatically)
-x Use threads to compress the image (dynamic if unset)
-h Show this help
-V Show version

Resulting image will have 2 partitions, /boot and /.

mkplatformfs.sh -h usage (The Void Linux filesystem tool to produce a rootfs for a particular platform)

Usage: ./mkplatformfs.sh [options] Supported platforms: i686, x86_64, GCP, bananapi, beaglebone, cubieboard2, cubietruck, odroid-c2, odroid-u2, rpi, rpi2 (armv7), rpi3 (aarch64), ci20, pinebookpro, pinephone

Options Info
-b Set an alternative base-system package (defaults to base-system)
-p Additional packages to install into the rootfs (separated by blanks)
-k Call "cmd " after building the rootfs
-c Set XBPS cache directory (defaults to $PWD/xbps-cachedir-)
-C Full path to the XBPS configuration file
-r Set XBPS repository (may be set multiple times)
-x Use threads to compress the image (dynamic if unset)
-o Filename to write the PLATFORMFS archive to
-n Do not compress the image, instead print out the rootfs directory
-h Show this help
-V Show version

Checking out pull requests locally

(from here)

Find the ID number of the inactive pull request. This is the sequence of digits right after the pull request's title. Fetch the reference to the pull request based on its ID number, creating a new branch in the process:

$ git fetch origin pull/ID/head:BRANCHNAME

Switch to the new branch that's based on this pull request:

[master] $ git checkout BRANCHNAME
> Switched to a new branch 'BRANCHNAME'

Rebasing branch on origin

https://stackoverflow.com/q/7929369 :

I have a cloned project from a master branch from remote repository remote_repo. I create a new branch and I commit to that branch. Other programmers pushed to remote_repo to the master branch.

I need now to rebase my local branch RB onto remote_repo's master branch.

How to do this? What commands to type to a terminal?

$ git pull --rebase origin master
$ git fetch origin
$ git reset --hard origin/master

$ git clone --depth=1

  • Omitting the --depth=1 will download the entire repository, including the full history of all branches, but this takes much longer and occupies much more storage. From docs:

    --depth

    Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules.

To ensure that a package is only updated from the same repository used to install it, you can repolock it via xbps-pkgdb(1):

$ xbps-pkgdb -m repolock <package>

To remove the repolock:

$ xbps-pkgdb -m repounlock <package>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment