Jump to content

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

From postmarketOS Wiki
mNo edit summary
No edit summary
Line 20: Line 20:
  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


The following build commands (make or abuild invocations) are run in native chroot as '''pmos''' user!
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
  su pmos
Line 32: Line 32:
  abuild fetch verify unpack prepare
  abuild fetch verify unpack prepare


Build (repeat multiple times during development): this does not restart full kernel build every time
Setup environment (done only once after <code>su pmos</code>):


  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
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:
  abuild -df build
  abuild -df build


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


  cd /home/pmos/build/src  # or whatever the directory after unpacking kernel archive would be
  cd /home/pmos/build/src  # or whatever the directory after unpacking kernel archive would be
Line 48: Line 51:
  make ARCH=arm64 mrproper
  make ARCH=arm64 mrproper


If you want to build as package:
If you want to create package:


  abuild package   # or
  abuild rootpkg
abuild rootpkg  # (?) not tested yet
 
It will place build package in <code>/mnt/pmbootstrap-packages</code> path inside chroot, which is the same as <code> ~/.local/var/pmbootstrap/packages/</code> in host system.


Hope it helps!
Hope it helps!
[[Category:Guide]]
[[Category:Technical Reference]]

Revision as of 01:09, 8 February 2020

Are you tired of the fact that every time you build your kernel in pmbootstrap it starts biulding 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):

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):

export ARCH=arm64
export CARCH=aarch64
export CROSS_COMPILE=aarch64-alpine-linux-musl-
export CC=aarch64-alpine-linux-musl-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, exmaple 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!