Thursday, May 7, 2015

Beaglebone Black Development Part 4 - Bootloader, Linux Kernel and Filesystem

This is the fourth in a series of embedded Linux development tutorials.  This covers Beaglebone Black and shows steps to build the bootloader, Linux kernel and prepare a Debian 8 (Jessie) filesystem.   The commands and scripts are from
BeagleBone Black - Linux on ARM - eewiki.  That site is updated often so check there for the latest versions of the tools and sources.

To use these instructions you need to set up your Linux system as shown in  Debian Jessie Host Setup for Embedded Linux Development Part 3 - BeagleBone Black.  This tutorial continues in Beaglebone Black Development Part 5 - Installing Linux to eMMC using Micro SD.

4 Building the Bootloader, Linux Kernel and Filesystem

4.1 Building U-Boot


Download the source to u-boot with git. The git clone command takes about 10 minutes to complete.

user@debian:~$ cd ~/bbb

user@debian:~/bbb$ git clone git://git.denx.de/u-boot.git

user@debian:~/bbb$ cd u-boot/

user@debian:~/bbb/u-boot$ git checkout v2015.04 -b tmp
Apply patches to u-boot  for from TI.

user@debian:~/bbb/u-boot$ wget -c https://rcn-ee.com/repos/git/u-boot-patches/v2015.04/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
user@debian:~/bbb/u-boot$ patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch

The output of the patch command should have no errors.

patching file configs/am335x_evm_defconfig
patching file include/configs/am335x_evm.h

Now we can configure and build u-boot.
user@debian:~/bbb/u-boot$ source ~/am335x/armcc-vars

user@debian:~/bbb/u-boot$ make distclean
user@debian:~/bbb/u-boot$ make am335x_evm_defconfig

Now you can build the entire u-boot image with the make command.
user@debian:~/bbb/u-boot$ make

This will take a minute or two and you will see many object files being created (CC) and linked (LD); if the build was successful the last few lines look like this:
 CC      spl/drivers/watchdog/omap_wdt.o
 LD      spl/drivers/watchdog/built-in.o
 LD      spl/u-boot-spl
 OBJCOPY spl/u-boot-spl.bin
 MKIMAGE MLO

4.2 Upgrade the device tree compiler package


The dtc upgrade is maintained by Robert Nelson. The upgrade script will install a few additional development tools it needs, then builds and installs dtc.

user@debian:~$ cd ~/am335x/
user@debian:~/am335x$ wget -c https://raw.github.com/RobertCNelson/tools/master/pkgs/dtc.sh
user@debian:~/am335x$ chmod +x dtc.sh
user@debian:~/am335x$ ./dtc.sh

It should end with a successful install into /usr/local/bin/.
...
CC libfdt/fdt_empty_tree.o
AR libfdt/libfdt.a
LD fdtget
CC fdtput.o
LD fdtput
LD libfdt/libfdt-1.4.0.so
Installing into: /usr/local/bin/
CHK version_gen.h
INSTALL

If you get a timeout error try the command again.


4.3 Linux Kernel Build


4.3.1 Initial build


Warning: The initial build process can take an hour or more to complete.

Set up the kernel build scripts from Robert Nelson.
user@debian:~/bbb$ cd ~/bbb
user@debian:~/bbb$ git clone https://github.com/RobertCNelson/bb-kernel

Download the mainline 3.8 kernel into the workspace.
user@debian:~/bbb$ cd bb-kernel/
user@debian:~/bbb/bb-kernel$ git checkout origin/am33x-v3.8 -b tmp

First, set the toolchain variables if you haven’t already.
user@debian:~/bbb/bb-kernel$ source ~/am335x/armcc-vars

Perform the build using Robert Nelson’s script.  This step can take hours to run.
user@debian:~/bbb/bb-kernel$ ./build_kernel.sh


After a long while it will pause at a menu screen.
linuxconf-yes.png
Tab over to highlight exit then press enter and it will continue to build the kernel.  This takes another hour.  

Here is an example of what you see when it’s finished:

`/home/user/bbb/bb-kernel/deploy/tmp/omap4-panda-es.dtb'
`./arch/arm/boot/dts/am335x-evmsk.dtb' -> `/home/user/bbb/bb-kernel/deploy/tmp/am335x-evmsk.dtb'
Compressing 3.8.13-bone70.5-dtbs.tar.gz...
-rw-r--r-- 1 user user 37K Mar 11 15:03 /home/user/bbb/bb-kernel/deploy/3.8.13-bone70.5-dtbs.tar.gz
-----------------------------
Script Complete
eewiki.net: [user@localhost:~$ export kernel_version=3.8.13-bone70.5]
-----------------------------

Save the export command in a file so you can easily set the the kernel_version variable.
user@debian:~/bbb/bb-kernel$ echo ‘export kernel_version=3.8.13-bone70.5’ > kernel_version

You can execute the export command by sourcing the file.
user@debian:~/bbb/bb-kernel$ source kernel_version

4.3.2 Rebuilding the Kernel


If you do not need to get the latest kernel source from the internet you can build the source on disk by using the rebuild script.  This only takes a few minutes.

user@debian:~/bbb/bb-kernel$ source ~/am335x/armcc-vars
user@debian:~/bbb/bb-kernel$ ./tools/rebuild.sh

4.4 Preparing a Root Filesystem


4.4.1 Download a pre-built Debian 8 root filesystem.


user@debian:~$ cd ~/bbb
user@debian:~/bbb$ mkdir rootfs
user@debian:~/bbb$ cd rootfs
user@debian:~/bbb/rootfs$ wget -c https://rcn-ee.com/rootfs/eewiki/minfs/debian-8.0-minimal-armhf-2015-04-27.tar.xz

Verify the image is correct.
user@debian:~/bbb/rootfs$ md5sum debian-8.0-minimal-armhf-2015-04-27.tar.xz

The md5sum command output should match this:
384b8681a5550eb139ad6e368aabd142  debian-8.0-minimal-armhf-2015-04-27.tar.xz

Uncompress the archive file.
user@debian:~/bbb/rootfs$ tar xf debian-8.0-minimal-armhf-2015-04-27.tar.xz

No comments: