Select Page

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: 8.3-2019.03 from here
$ sudo tar xvf ~/Downloads/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf.tar.xz -C /opt/
$ export CC=/opt/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-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-linux-gnueabihf-gcc (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36)) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Bootloader: U-Boot

Build U-Boot For BeagleBone

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

Download
$ cd ~/bbb_build
$ git clone https://github.com/u-boot/u-boot
$ cd u-boot/
$ git checkout v2019.04 -b v2019.04
Patches
$ cd ~/bbb_build/u-boot
$ wget -c https://github.com/eewiki/u-boot-patches/raw/master/v2019.04/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
$ wget -c https://github.com/eewiki/u-boot-patches/raw/master/v2019.04/0002-U-Boot-BeagleBone-Cape-Manager.patch
 
$ 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
$ make ARCH=arm CROSS_COMPILE=${CC}

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 https://github.com/RobertCNelson/bb-kernel
$ 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

Build

$ ./build_kernel.sh

Development/Hacking:

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

Root File System

Debian 9

User : debian
Password : temppwd

Download

$ cd ~/bbb_build
$ wget -c https://rcn-ee.com/rootfs/eewiki/minfs/debian-10.4-minimal-armhf-2020-05-10.tar.xz

Verify

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

sha256sum output

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

Extract

$ 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

 

 

 

 

 

 

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__
4M,,L,*
__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 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

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”

Networking

Edit: /etc/network/interfaces

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

Add

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
Add

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

Remove microSD/SD card

$ sudo chown root:root /media/rootfs/
$ sudo chmod 755 /media/rootfs/
$ sync
$ sudo umount /media/rootfs

Boot new image

  • Connect the Micro SD Card to the BBB SD Card Connector
  • Power-Up the BBB ( You can use mini USB (P4) )
  • Connect Serial Cable to Beagleboard as explained here
  • Press and Hold S2 Button then press and release S3 Button

Note: To boot from the microSD card , you need to hold the button S2, this button is near the host USB port, on the other side of the ethernet port. If this is not held, the board may follow its default boot order and try booting from the onboard eMMC, if a uboot image is available on the onboard eMMC, our uboot image will not be built.

Flashing eMMC

To set up the standalone microSD image to automatically flash the eMMC on powerup. Login as debian (password = temppwd) and edit /boot/uEnv.txt with your preferred editor.

In /boot/uEnv.txt:

##enable BBB: eMMC Flasher:
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh

Change to:

##enable BBB: eMMC Flasher:
cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh