[Librem-5-dev] Building and testing your own kernel

Guido Günther guido.gunther at puri.sm
Thu Dec 27 03:57:09 PST 2018


Hi,
On Thu, Dec 27, 2018 at 12:43:39PM +0100, Dorota Czaplejewicz via Librem-5-dev wrote:
> On Thu, 27 Dec 2018 19:20:56 +0800
> Andy Green via Librem-5-dev <librem-5-dev at lists.community.puri.sm> wrote:
>> 
> > Hi -
> > 
> > I can't find any existing notes about kernel build and test without 
> > overwriting the old kernel.  In the absence of any official information, 
> > here's how I did it.  It's not hard since Linux, Freescale, Emcraft and 
> > Purism (and gcc) guys already did the hard stuff.
> > 
> > 1) You'll need a serial connection so you can interrupt U-Boot.
> > 
> > I soldered a 0.1" pitch header for the serial console in and connected a 
> > 3.3V USB-Serial adapter as described in [1], which immediately worked at 
> > 115200.  There are instructions at [2] that you can use the power USB-C 
> > connector as a logical USB CDC ACM device to get the same result.  I 
> > tried it using the USB A - C cable that shipped with the device, but no 
> > ttyACM0 appeared on my box.
> > 
> > 2) Install your distro arm64 / aarch64 cross toolchain, or install an 
> > external one of a specific gcc version and add it to your path (out of 
> > scope for these notes).  For Fedora, it just means:
> > 
> >   $ sudo dnf install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
> > 
> > 3) Clone the kernel tree.
> > 
> >   $ git clone https://source.puri.sm/Librem5/linux-emcraft.git
> >   $ cd linux-emcraft
> >   $ mkdir mods
> > 
> > 4) Optionally choose the branch, tag or commit... by default it's 
> > imx8-4.18-wip branch HEAD, 2471a858f4e0 when I tried it, and you can 
> > just skip this step and build the latest.  If you want to force it to 
> > the exact older commit as was shipped with the dev board:
> > 
> >   $ git reset --hard  510718c9
> > 
> > 5) Build the kernel
> > 
> >   $ CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_STRIP=1 
> > INSTALL_MOD_PATH=mods make -j32 ARCH=arm64 librem5-evk_defconfig all 
> > modules_install
> > 
> >    Note 1:  CROSS_COMPILE should be set to the first part of your 
> > toolchain binaries.  The Fedora package "gcc-aarch64-linux-gnu" installs 
> > a toolchain named like "aarch64-linux-gnu-gcc".  So it's 
> > "aarch64-linux-gnu-" with that.
> > 
> >    Note 2: Change the -j32 to suit your build machine number of threads 
> > and memory... 32 means run 32 build steps in parallel.
> > 
> >    Note 3: The built modules are placed into ./mods/lib/modules/... and 
> > can be installed into the dev board rootfs.  But it seems that there's 
> > nothing critical for basic operation built as a module.
> > 
> > 6) Boot the device and confirm the network is working.  It's best to set 
> > up keys, but by default the root password is "root".  Sshd is already 
> > running and workable.  Find your ip address with ifconfig eth0.
> > 
> > On the dev board:
> > 
> >   # mkdir /boot/boot2
> >   # mkidr /boot/boot2/dtbs
> > 
> > On your build machine (replace 192.168.2.245 with its IP)
> > 
> >   $ scp ./arch/arm64/boot/Image root at 192.168.2.245:/boot/boot2
> >   $ scp ./arch/arm64/boot/dts/freescale/librem5-evk.dtb 
> > root at 192.168.2.245:/boot/boot2/dtbs
> > 
> > 7) If you want to copy the modules over too (these are in versioned 
> > directories, but caution: if you built the original shipped commit these 
> > will overwrite the shipped modules since the version will be the 
> > same...) it boots fine for normal operation (network etc) without them...
> > 
> >   $ scp -rp mods/lib root at 192.168.2.245:/
> > 
> > 8) Reboot the dev board
> > 
> >   # reboot
> > 
> > 9) Press a key to enter U-Boot.  Then paste the U-Boot commands one by one
> > 
> > setenv fdt_file /boot2/dtbs/librem5-evk.dtb
> > setenv image /boot2/Image
> > boot
> > 
> > You will see something like...
> > 
> > ...
> > u-boot=> boot
> > Booting from mmc ...
> > switch to partitions #0, OK
> > mmc0(part 0) is current device
> > ** File not found boot.scr **
> > ** Unrecognized filesystem type **
> > 40831 bytes read in 90 ms (442.4 KiB/s)
> > 18827776 bytes read in 941 ms (19.1 MiB/s)
> > ## Flattened Device Tree blob at 43000000
> >     Booting using the fdt blob at 0x43000000
> >     reserving fdt memory region: addr=40000000 size=20000
> >     Using Device Tree in place at 0000000043000000, end 000000004300cf7e
> > 
> > Starting kernel ...
> > 
> > [    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
> > [    0.000000] Linux version 4.18.11-00322-g2471a858f4e0 (agreen at learn) 
> > (gcc version 8.1.1 20180626 (Red Hat Cross 8.1.1-3) (GCC)) #1 SMP 
> > PREEMPT Thu Dec 27 14:17:58 CST 2018
> > [    0.000000] Machine model: Purism Librem 5 devkit
> > ...
> > 
> > If you reboot it again without interrupting U-Boot, it'll just boot into 
> > the original kernel as before.
> > 
> > -Andy
> > 
> > [1] 
> > https://developer.puri.sm/Librem5/Development_Environment/Boards/Troubleshooting.html#attaching-a-usb-to-serial-adapter
> > 
> > [2] 
> > https://developer.puri.sm/Librem5/Development_Environment/Boards/imx8.html#devkit-test-run
> 
> Hi Andy,
> 
> thank you for doing that work. We're normally building the kernel
> using image-builder [0], and we're currently using .debs for the kerne

Just for reference this is the command the scripts are using to build
the kernel:

   make -j4  ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bindeb-pkg

Installing such a kernel will replace your current kernel (if you run a
recent enough image that has

   https://source.puri.sm/Librem5/librem5-devkit-tools/blob/master/etc/kernel/postinst.d/update-Image

in place). If you did not flash a recent image the above snippet shows how
to replace /boot/Image.

Cheers,
 -- Guido


More information about the Librem-5-dev mailing list