Building the Linux Kernel - Cross-compiling for a BeagleBone Black

From EdWiki

Revision as of 15:28, 27 November 2020 by Jshankar (Talk | contribs) (TI BSP)

Building the Linux Kernel - Cross-compiling for a BeagleBone Black

Install GNU toolchain for the A-Profile Architecture

$ cd ~/Downloads
$ Download GNU Toolchain for the A-profile Architecture: 9.2-2019.12 from here
$ sudo tar xvf ~/Downloads/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz -C /opt/
$ export CC=/opt/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-

Install Dependencies

$ sudo apt-get install bison flex lzop lzma libmpc-dev u-boot-tools libncurses5-dev:amd64 gettext
$ mkdir ~/bbb_build
$ cd ~/bbb_build

Test Cross Compiler

$ ${CC}gcc --version

arm-none-linux-gnueabihf-gcc (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 9.2.1 20191025
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

Bootloader: U-Boot

Das U-Boot – the Universal Boot Loader: U-Boot patch archive: u-boot-patches


$ cd ~/bbb_build
$ git clone
$ cd u-boot/
$ git checkout v2019.04 -b v2019.04


$ cd ~/bbb_build/u-boot
$ wget -c
$ wget -c
$ patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
$ patch -p1 < 0002-U-Boot-BeagleBone-Cape-Manager.patch

Configure and Build

$ make ARCH=arm CROSS_COMPILE=${CC} distclean
$ make ARCH=arm CROSS_COMPILE=${CC} am335x_evm_defconfig

Linux Kernel

This script will build the kernel, modules, device tree binaries and copy them to the deploy directory.

Mainline - Download

$ cd ~/bbb_build
$ git clone
$ cd bb-kernel/

For am33x-rt-v5.4 (Longterm 5.4.x + Real-Time Linux):

$ git checkout origin/am33x-rt-v5.4 -b am33x-rt-v5.4


$ ./


first run (to setup baseline tree): ./ then modify files under KERNEL directory then run (to rebuild with your changes): ./tools/

Root File System

Debian 9

User : debian
Password : temppwd


$ cd ~/bbb_build
$ wget -c


$ sha256sum debian-10.4-minimal-armhf-2020-05-10.tar.xz

sha256sum output

cd598e42850cbef87602bf15ee343abfbf0d8c6ba81028c741672b5f24263534  debian-10.4-minimal-armhf-2020-05-10.tar.xz


$ tar xf debian-10.4-minimal-armhf-2020-05-10.tar.xz

Setup microSD card

We need to access the External Drive to be utilized by the target device. Run lsblk to help figure out what linux device has been reserved for your External Drive.

$ lsblk

Dev sd card.jpg

Thus you would use:

$ export DISK=/dev/sdb

Erase partition table/labels on microSD card:

$ sudo dd if=/dev/zero of=${DISK} bs=1M count=10

Install Bootloader

$ cd ~/bbb_build
$ sudo dd if=./u-boot/MLO of=${DISK} count=1 seek=1 bs=128k
$ sudo dd if=./u-boot/u-boot.img of=${DISK} count=2 seek=1 bs=384k

Create Partition Layout

$ sudo sfdisk ${DISK} <<-__EOF__

Format Partition

With mkfs.ext4 1.43, we need to make sure metadata_csum and 64bit are disabled. As the version of U-Boot needed for this target CAN NOT correctly handle reading files with these newer ext4 options.

$ sudo mkfs.ext4 -L rootfs -O ^metadata_csum,^64bit ${DISK}1

Mount Partition

On most systems these partitions may will be auto-mounted...

$ sudo mkdir -p /media/rootfs/
$ sudo mount ${DISK}1 /media/rootfs/

Backup Bootloader

This version of MLO/u-boot.img will be used on the "eMMC" flasher script on this page.

$ cd ~/bbb_build
$ sudo mkdir -p /media/rootfs/opt/backup/uboot/
$ sudo cp -v ./u-boot/MLO /media/rootfs/opt/backup/uboot/
$ sudo cp -v ./u-boot/u-boot.img /media/rootfs/opt/backup/uboot/

Install Kernel and Root File System

Copy and paste that "export kernel_version=4.X.Y-Z" exactly as shown in your own build/desktop environment and hit enter to create an environment variable to be used later.

$ export kernel_version=5.4.70-bone-rt-r38

Copy Root File System

$ ~/bbb_build
$ sudo tar xfvp ./debian-10.4-minimal-armhf-2020-05-10/armhf-rootfs-debian-buster.tar -C /media/rootfs/
$ sync
$ sudo chown root:root /media/rootfs/
$ sudo chmod 755 /media/rootfs/

Set uname_r in /boot/uEnv.txt

$ cd ~/bbb_build
$ sudo sh -c "echo 'uname_r=${kernel_version}' >> /media/rootfs/boot/uEnv.txt"

Copy Kernel Image

$ cd ~/bbb_build
$ sudo cp -v ./bb-kernel/deploy/${kernel_version}.zImage /media/rootfs/boot/vmlinuz-${kernel_version}

Copy Kernel Device Tree Binaries

$ cd ~/bbb_build
$ sudo mkdir -p /media/rootfs/boot/dtbs/${kernel_version}/
$ sudo tar xfv ./bb-kernel/deploy/${kernel_version}-dtbs.tar.gz -C /media/rootfs/boot/dtbs/${kernel_version}/

Copy Kernel Modules

$ cd ~/bbb_build
$ sudo tar xfv ./bb-kernel/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/

File Systems Table (/etc/fstab)

$ sudo sh -c "echo '/dev/mmcblk0p1 / auto errors=remount-ro 0 1' >> /media/rootfs/etc/fstab"


Edit: /etc/network/interfaces

$ sudo nano /media/rootfs/etc/network/interfaces


auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

Networking: Using a shared SD card with Multiple BeagleBone

To always enable the Ethernet interface as eth0.
Edit: /etc/udev/rules.d/70-persistent-net.rules

$ sudo nano /media/rootfs/etc/udev/rules.d/70-persistent-net.rules


# BeagleBone: net device ()
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Remove microSD/SD card

$ sync
$ sudo umount /media/rootfs

Plug the microSD card in to beaglebone black and press hold "Boot Switch" button and power it up.