Home » Big Data » Beagle Bone Black Notes: How to build a kernel for a Beagle Bone Black from scratch – Part 1

Beagle Bone Black Notes: How to build a kernel for a Beagle Bone Black from scratch – Part 1

Pre-built kernels are available for Debian Wheezy, Ubuntu of various versions, however, to build your own modules to get things working for all sorts of reasons (example: you have a wifi USB module that is not supported in the pre-built kernels), then you need to get and patch the kernel source for ARM7 and build your own using a gcc cross-compiler configuration to have it available to build whatever modules you would like.

Reference Sites:

My process

0: Get build environment ready

  • step 0.0:  install Debian/Ubuntu on  a machine or VM environment and update/patch it up I prefer 64-bit Linux
  • step 0.1:  “sudo apt-get update && sudo apt-get upgrade”
  • step 0.2:  “sudo apt-get dist-upgrade”
  • step 0.3:  “sudo apt-get install <stuff>”

1: Get communication to Beagle Bone Black into a “known working state”

  • step 1.0:  grab an image from armhf:  http://www.armhf.com/index.php/boards/beaglebone-black/
  • step 1.1:  follow the directions to setup the image on an MMC card http://www.armhf.com/index.php/getting-started-with-ubuntu-img-file/
  • step 1.2:  make sure to extend the partition table of the MMC card at some point to get the full capacity of the card:   method 1  method 2
  • step 1.3:
    • plug in MMC
    • boot Beagle Bone Black (hereafter referred to as BBB)
    • figure out how to connect:
      • USB serial on PC plugged into mini USB port on BBB
        • configure usb network interface of PC (usb0 on Linux) for with no gateway
      • ssh to a DHCP address on eth0 of the BBB (figure out IP by DHCP server logs of leases)
      • connect a USB-serial console cable to BBB..  
  • step 1.4:  login
    • username: debian  or ubuntu  or root depending on which image was used.
    • Password should be: debian, ubuntu or temppwd, depending on the specific image
  • step 1.5:  configure BBB for network connectivity
    • eth0 with a static IP, usb0 and possibly change DNS config in /etc/resolvconf/resolv.conf.d/original to work when using a static IP
example: /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
# loopback network interface
auto lo
iface lo inet loopback

auto usb0
allow-hotplug usb0
iface usb0 inet static
# primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
 # dns-namservers
# wireless network interface
#auto wlan0
#allow-hotplug wlan0
#iface wlan0 inet static
# address
# netmask
# gateway
# dns-nameservers
# wpa-ssid "myssid"
# wpa-psk "mypsk"

example: /etc/resolvconf/resolv.conf.d/original

search the8thlayerof.net

2: Setup cross-compilation build environment

adapted from:  http://eewiki.net/display/linuxonarm/BeagleBone+Black#BeagleBoneBlack-BasicRequirements

  • step 2.0:  install 32-bit versions of key components
    • sudo apt-get update && sudo apt-get upgrade && sudo apt-get install libc6:i386 libstdc++6:i386 libncurses5:i386 zlib1g:i386
  • step 2.1:  create a directory structure to download and compile the kernel in
    • cd ~/ ; mkdir  BeagleBoneBlack; mkdir BeagleBoneBlack/cross-compile; cd BeagleBoneBlack/cross-compile; mkdir <distribution - debian|ubuntu>; cd <distribution>;
  • step 2.2:  download / extract cross-compiler
    • wget -c https://launchpad.net/linaro-toolchain-binaries/trunk/2013.07/+download/gcc-linaro-arm-linux-gnueabihf-4.8-2013.07-1_linux.tar.xz
    • tar xJf gcc-linaro-arm-linux-gnueabihf-4.8-2013.07-1_linux.tar.xz
    • export CC=`pwd`/gcc-linaro-arm-linux-gnueabihf-4.8-2013.07-1_linux/bin/arm-linux-gnueabihf-
  • step 2.3:  test setup
    • ${CC}gcc --version
      arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2013.07-1 - Linaro GCC 2013.07) 4.8.2 20130624 (prerelease)
      Copyright (C) 2013 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions.  There is NO

3: Build U-Boot

  • step 3.0:  Download U-Boot
    • git clone git://git.denx.de/u-boot.git
    • cd u-boot/
    • git checkout v2013.07 -b tmp
  • step 3.1:  Configure and Build U-Boot
    • wget https://raw.github.com/eewiki/u-boot-patches/master/v2013.07/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
    • patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
    • make ARCH=arm CROSS_COMPILE=${CC} distclean
    • make ARCH=arm CROSS_COMPILE=${CC} am335x_evm_config
    • make ARCH=arm CROSS_COMPILE=${CC}

4: Upgrade device tree compiler

  • step 4.0:  Download and upgrade dtc
    • cd ..
    • wget -c https://raw.github.com/RobertCNelson/tools/master/pkgs/dtc.sh
    • chmod +x dtc.sh
    • ./dtc.sh

5: Build Kernel and modules

  • step 5.0:  Download kernel
    • git clone git://github.com/RobertCNelson/linux-dev.git
    • cd linux-dev/
    • git checkout origin/am33x-v3.8 -b tmp
  • step 5.1:  setup git for kernel build (Name and email)
  • step 5.2:  Build kernel

    • ./build_kernel.sh
    • cd ..

6: Get rootfs setup on flash card

  • step 6.0:  Download , verify and extract rootfs
  • debian:
    • wget -c https://rcn-ee.net/deb/minfs/wheezy/debian-7.1-minimal-armhf-2013-08-25.tar.xz
    • md5sum debian-7.1-minimal-armhf-2013-08-25.tar.xz
    • tar xJf debian-7.1-minimal-armhf-2013-08-25.tar.xz
    • ubuntu:
      • wget -c https://rcn-ee.net/deb/minfs/raring/ubuntu-13.04-minimal-armhf-2013-08-25.tar.xz
      • md5sum ubuntu-13.04-minimal-armhf-2013-08-25.tar.xz
      • tar xJf ubuntu-13.04-minimal-armhf-2013-08-25.tar.xz
  • step 6.1:   figure out what device your MMC appears as in build machine
    • ls /dev
    • insert an MMC or a USB<->MMC adapter
    • ls /dev
    • look for changes which have appeared.  In my case, with a USB flash adapter, MMC cards appears as /dev/sdb
  • step 6.2:  setup a temp export for ease of use, wipe disk and setup partition table
    • export DISK=/dev/sdb
    • sudo dd if=/dev/zero of=${DISK} bs=1M count=16
    • sudo fdisk /dev/sdb
      • p (print)
      • d (delete any existing partitions)
      • w (write and exit)
    • sudo partprobe
    • sudo fdisk /dev/sdb
      • p (print partition table
      • n (new partition)
      • 1 (partition number)
      • <enter>  (accept start at 2048)
      • +100M
      • t  (change partition type
      • 1 (partition 1)
      • b (change to FAT32)
      • p (print partition table)
      • n (new partition)
      • 2 (partition #2)
      • <enter>  (accept default start at 4096)
      • <enter> (accept default, last sector on the flash card)
      • p (print)
      • w (write and exit)
    • sudo partprobe
  • step 6.3:  format partitions
    • sudo mkfs.vfat -F 32 ${DISK}1 -n boot
    • sudo mkfs.ext4 ${DISK}2 -L rootfs
  • step 6.4:  mount partitions
    • sudo mkdir /media/boot
    • sudo mkdir /media/rootfs
    • sudo mount ${DISK}1 /media/boot/
    • sudo mount ${DISK}2 /media/rootfs/
  • step 6.5:  install U-Boot on flash card
    • sudo cp -v ./u-boot/MLO /media/boot/
    • sudo cp -v ./u-boot/u-boot.img /media/boot/
  • step 6.6:   save uEnv.txt into the build directory
  • step 6.7:   copy the uEnv.txt file into /media/boot
    • sudo cp -v ./uEnv.txt /media/boot/
  • step 6.8:   install rootfs 
    • look in linux-dev/deploy
    • ls..   check version   ie:  3.8.13-bone28
    • export environment variable for kernel version
      • export kernel_version=3.8.13-bone28
    • copy rootfs
      • sudo tar xfvp ./<distribution>/arm*-rootfs-*.tar -C /media/rootfs/
      • example:
        • sudo tar xfvp ./ubuntu-13.04-minimal-armhf-2013-08-25/armhf-rootfs-ubuntu-raring.tar -C /media/rootfs

7: Get kernel setup on flash card

  • step 7.0:  copy kernel files, device tree files and modules
    • sudo cp -v ./linux-dev/deploy/${kernel_version}.zImage /media/boot/zImage
    • sudo mkdir -p /media/boot/dtbs/
    • sudo tar xfov ./linux-dev/deploy/${kernel_version}-dtbs.tar.gz -C /media/boot/dtbs/
    • sudo tar xfv ./linux-dev/deploy/${kernel_version}-firmware.tar.gz -C /media/rootfs/lib/firmware
    • sudo tar xfv ./linux-dev/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/

8: edit configuration files on flash card

  • step 8.0:  edit  /etc/fstab in the MMC
    • sudo nano /media/rootfs/etc/fstab


/dev/mmcblk0p2   /           auto   errors=remount-ro   0   1
/dev/mmcblk0p1   /boot/uboot auto   defaults            0   2

  • step 8.1: edit /etc/network/interfaces
    • sudo nano /media/rootfs/etc/network/interfaces


auto lo

iface lo inet loopback
auto eth0
iface eth0 inet dhcp
  • step 8.2: 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"

9: Configure a Serial console for debugging access

  • step 9.0:  
    • debian:  edit  /etc/inittab in the MMC
      • sudo nano /media/rootfs/etc/inittab
      • add:
        • T0:23:respawn:/sbin/getty -L ttyO0 115200 vt102
    • ubuntu: create serial.conf
      • sudo nano /media/rootfs/etc/init/serial.conf
      • start on stopped rc RUNLEVEL=[2345]
        stop on runlevel [!2345]

        exec /sbin/getty 115200 ttyO0

10: sync MMC and remove

  • sudo sync


  1. Pete says:

    Step 2.0 doesn’t work:
    # apt-get install libc6:i386 libstdc++6:i386 libncurses5:i386 zlib1g:i386

    when run, yields:

    # apt-get install libc6:i386 libstdc++6:i386 libncurses5:i386 zlib1g:i386
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package libc6
    E: Unable to locate package libstdc++6
    E: Couldn’t find any package by regex ‘libstdc++6′
    E: Unable to locate package libncurses5
    E: Unable to locate package zlib1g

    Fresh install, version 11-Sept-2014:
    # uname -a
    Linux debian-dev 3.2.0-4-amd64 #1 SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux

    • Pete says:

      Update: before running these installs, it is necessary to add the extra architecture, thus:
      # dpkg –add-architecture i386
      followed by:
      # apt-get update

      then the i386 installs will run properly

    • Sam Crooks says:

      What version are you building ? These notes were written last year, and I suspect some things have changed since

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: