Jump to content

User:Alexeymin/Kernel development in chroot using abuild: Difference between revisions

From postmarketOS Wiki
Aleksas (talk | contribs)
m Fixing few typos
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=== Are you tired of the fact that every time you build your kernel in pmbootstrap it starts building it from scratch? Does it take too much time? and envkernel does not work/broken? Then this is for you! ===
=== Are you tired of the fact that every time you build your kernel in pmbootstrap it starts building it from scratch? Does it take too much time and envkernel does not work/broken? Then this is for you! ===


Prepare config and chroots:
Prepare config and chroots:
Line 16: Line 16:
  pmbootstrap chroot
  pmbootstrap chroot


In native chroot verify that all deps are installed (this is run as root user inside chroot):
In native chroot verify that all deps are installed (this is run as root user inside chroot) (basically install everything from <code>makedepends=</code> of your APKBUILD):


  apk add abuild build-base ccache git devicepkg-dev mkbootimg postmarketos-base ccache-cross-symlinks gcc-aarch64 g++-aarch64 crossdirect ncurses-dev bash bc bison elfutils-dev flex gmp-dev installkernel linux-headers openssl-dev perl sed
  apk add abuild build-base ccache git devicepkg-dev mkbootimg postmarketos-base ccache-cross-symlinks gcc-aarch64 g++-aarch64 crossdirect ncurses-dev bash bc bison elfutils-dev flex gmp-dev installkernel linux-headers openssl-dev perl sed
Line 32: Line 32:
  abuild fetch verify unpack prepare
  abuild fetch verify unpack prepare


Setup environment (done only once after <code>su pmos</code>):
Setup environment (done only once after <code>su pmos</code>), example for aarch64 mainline:


  export ARCH=arm64
  export ARCH=arm64
Line 38: Line 38:
  export CROSS_COMPILE=aarch64-alpine-linux-musl-
  export CROSS_COMPILE=aarch64-alpine-linux-musl-
  export CC=aarch64-alpine-linux-musl-gcc
  export CC=aarch64-alpine-linux-musl-gcc
Example for armv7 downstream kernel compiled with gcc6:
export ARCH=arm
export CARCH=armv7
export CROSS_COMPILE=gcc6-armv7-alpine-linux-musleabihf-
export CC=gcc6-armv7-alpine-linux-musleabihf-gcc


Build (repeat multiple times during development): this does not restart full kernel build every time, rebuilds only changed files with appropriate flags and options specified in APKBUILD. Basically, <code>abuild build</code> calls your <code>build()</code> function from APKBUILD:
Build (repeat multiple times during development): this does not restart full kernel build every time, rebuilds only changed files with appropriate flags and options specified in APKBUILD. Basically, <code>abuild build</code> calls your <code>build()</code> function from APKBUILD:
Line 58: Line 65:


Hope it helps!
Hope it helps!
{{note|Keep in mind that running <code>pmbootstrap zap</code> in other terminals will delete all chroots so it's easy to lose all your work, everything inside a chroot! Use git / other ways to safely store your work.}}




[[Category:Guide]]
[[Category:Guide]]
[[Category:Technical Reference]]
[[Category:Technical Reference]]

Latest revision as of 14:15, 12 January 2021

Are you tired of the fact that every time you build your kernel in pmbootstrap it starts building it from scratch? Does it take too much time and envkernel does not work/broken? Then this is for you!

Prepare config and chroots:

pmbootstrap -y zap
pmbootstrap init    # for your device

Start building your kernel but cancel early; download all source and checksum; wait until it and starts build, this way we'll have all sources unpacked and placed where needed, and dependencies prepared:

pmbootstrap checksum linux-your-kernel
pmbootstrap build --force --arch aarch64 linux-your-kernel
^C  # press Ctrl+C as soon as pmbootstrap log starts to show building process

Switch to native chroot:

pmbootstrap chroot

In native chroot verify that all deps are installed (this is run as root user inside chroot) (basically install everything from makedepends= of your APKBUILD):

apk add abuild build-base ccache git devicepkg-dev mkbootimg postmarketos-base ccache-cross-symlinks gcc-aarch64 g++-aarch64 crossdirect ncurses-dev bash bc bison elfutils-dev flex gmp-dev installkernel linux-headers openssl-dev perl sed

The following build commands (make or abuild invocations) are run in native chroot as pmos user, because abuild does not recommend running as root!

su pmos
export HOME=/home/pmos
cd /home/pmos/build   # the directory where APKBUILD file is

You can restart all your build from the beginning with this:

cd /home/pmos/build   # the directory where APKBUILD file is
rm -rf src
abuild fetch verify unpack prepare

Setup environment (done only once after su pmos), example for aarch64 mainline:

export ARCH=arm64
export CARCH=aarch64
export CROSS_COMPILE=aarch64-alpine-linux-musl-
export CC=aarch64-alpine-linux-musl-gcc

Example for armv7 downstream kernel compiled with gcc6:

export ARCH=arm
export CARCH=armv7
export CROSS_COMPILE=gcc6-armv7-alpine-linux-musleabihf-
export CC=gcc6-armv7-alpine-linux-musleabihf-gcc

Build (repeat multiple times during development): this does not restart full kernel build every time, rebuilds only changed files with appropriate flags and options specified in APKBUILD. Basically, abuild build calls your build() function from APKBUILD:

abuild -df build

OR manually, without "setup environment" stage, example commands:

cd /home/pmos/build/src   # or whatever the directory after unpacking kernel archive would be
make ARCH=arm64 CROSS_COMPILE=aarch64-alpine-linux-musl- defconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-alpine-linux-musl- menuconfig
make ARCH=arm64 CROSS_COMPILE=aarch64-alpine-linux-musl- -j9
make ARCH=arm64 mrproper

If you want to create package:

abuild rootpkg

It will place build package in /mnt/pmbootstrap-packages path inside chroot, which is the same as ~/.local/var/pmbootstrap/packages/ in host system.

Hope it helps!

Note Keep in mind that running pmbootstrap zap in other terminals will delete all chroots so it's easy to lose all your work, everything inside a chroot! Use git / other ways to safely store your work.