Rebuilding the Kernel¶
These instructions aim to help you rebuild the kernel for the development board separately from the process of building a new image in its entirety. It also covers the process of installing the kernel and other binaries on the board. The building step can be performed without any modifications to the board.
While it is possible to replace an existing kernel with a new one, you may find it useful to attach a USB to serial adapter to the board so that can interact with the bootloader and select a different kernel to run. This makes it possible to install new kernels alongside the original one and fall back to the original one if the new ones fail to work.
Install the necessary packages for your system. On Debian-based systems, you
can do this with the
sudo apt install crossbuild-essential-arm64 build-essential gcc-aarch64-linux-gnu bison
On Fedora, use the
sudo dnf install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
It should now be possible to cross-compile the kernel for the development board.
Clone the linux-emcraft repository and enter the working directory:
git clone https://source.puri.sm/Librem5/linux-emcraft.git cd linux-emcraft
For simplicity, we create a directory to hold the modules that will be built:
Compile the kernel, optionally using
ccache if installed:
# With ccache: CROSS_COMPILE='ccache aarch64-linux-gnu-' \ INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=_modules \ make ARCH=arm64 librem5-evk_defconfig all modules_install # Without ccache: CROSS_COMPILE=aarch64-linux-gnu- \ INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=_modules \ make ARCH=arm64 librem5-evk_defconfig all modules_install
You can also pass the
-j command line option to
make if you want to
compile many files in parallel, specifying the number of parallel builds as an
argument to the option.
Connect the development board to a network and find its IP address. Log in as
root and create the
boot2 directory inside the existing
From the workstation, copy the kernel and device tree binary to the board,
pureos with the IP address of the development board:
scp arch/arm64/boot/Image root@pureos:/boot/boot2/ scp arch/arm64/boot/dts/freescale/librem5-evk.dtb root@pureos:/boot/boot2/dtbs/
build symlinks from the modules directory and
copy the directory for the corresponding kernel version to the correct location
on the board, replacing
$KERNEL_VERSION with the version of the kernel that
rm _modules/lib/modules/$KERNEL_VERSION/source rm _modules/lib/modules/$KERNEL_VERSION/build scp -r _modules/lib/modules/$KERNEL_VERSION root@pureos:/lib/modules/
The board should now be ready to reboot into the new kernel.
Plug in the USB to serial adapter and open a serial connection, replacing
ttyUSB0 with the appropriate device file if necessary:
picocom -b 115200 /dev/ttyUSB0
Reboot the development board and wait until you see the following text:
Hit any key to stop autoboot:
Press Return and enter the following commands at the U-Boot prompt:
setenv bootdir boot2/ boot
The new kernel should be loaded and run.
To boot into the old kernel, reboot and let it autoboot. This should work as long as the old kernel image, device tree binary and modules are still installed.
If you need to restore the system to use a working kernel and bootloader, follow the instructions in Flashing eMMC.