(→uBoot mkimage) |
(Updated to 3.14.1 and DeviceTree) |
||
Line 1: | Line 1: | ||
== Compiling the BeagleBone Black Kernel == | == Compiling the BeagleBone Black Kernel == | ||
− | The following contains instructions for building the BeagleBone Black kernel on Ubuntu | + | The following contains instructions for building the BeagleBone Black kernel on Ubuntu 14.04. |
== Prerequisites == | == Prerequisites == | ||
Line 7: | Line 7: | ||
=== ARM Cross Compiler === | === ARM Cross Compiler === | ||
− | To compile the linux kernel for the BeagleBone Black, you must first have an ARM cross compiler installed. I use gcc-4.7-arm-linux-gnueabi-base that comes with Ubuntu | + | To compile the linux kernel for the BeagleBone Black, you must first have an ARM cross compiler installed. I use gcc-4.7-arm-linux-gnueabi-base that comes with Ubuntu 14.04. To install the compiler run: |
<PRE> | <PRE> | ||
Line 54: | Line 54: | ||
git clone git://github.com/beagleboard/kernel.git | git clone git://github.com/beagleboard/kernel.git | ||
cd kernel | cd kernel | ||
− | git checkout 3. | + | git checkout 3.14 |
./patch.sh | ./patch.sh | ||
cp configs/beaglebone kernel/arch/arm/configs/beaglebone_defconfig | cp configs/beaglebone kernel/arch/arm/configs/beaglebone_defconfig | ||
Line 61: | Line 61: | ||
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- beaglebone_defconfig -j4 | make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- beaglebone_defconfig -j4 | ||
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage dtbs LOADADDR=0x80008000 -j4 | make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage dtbs LOADADDR=0x80008000 -j4 | ||
− | |||
</PRE> | </PRE> | ||
Line 85: | Line 84: | ||
<PRE> | <PRE> | ||
− | ln -s /path to linux/arch/arm/boot/uImage | + | ln -s /path to linux/arch/arm/boot/uImage uImage-BBB-3.14.1 |
+ | ln -s /path to linux/arch/arm/boot/dts/am335x-boneblack.dtb am335x-boneblack.dtb | ||
</PRE> | </PRE> | ||
Line 99: | Line 99: | ||
These variables can be saved to non-volatile memory to speed up development. | These variables can be saved to non-volatile memory to speed up development. | ||
− | Next load the image | + | Next load the Kernel image and device tree binary blob: |
<PRE> | <PRE> | ||
− | tftpboot | + | tftpboot ${fdtaddr} am335x-boneblack.dtb |
+ | tftpboot ${kloadaddr} uImage-BBB-3.14.1 | ||
</PRE> | </PRE> | ||
Line 112: | Line 113: | ||
And boot from the memory location: | And boot from the memory location: | ||
<PRE> | <PRE> | ||
− | bootm | + | bootm ${kloadaddr} - ${fdtaddr} |
</PRE> | </PRE> | ||
Line 144: | Line 145: | ||
setenv ipaddr 192.168.0.250 | setenv ipaddr 192.168.0.250 | ||
setenv serverip 192.168.0.251 | setenv serverip 192.168.0.251 | ||
− | tftpboot | + | tftpboot ${fdtaddr} am335x-boneblack.dtb |
+ | tftpboot ${kloadaddr} uImage-BBB-3.14.1 | ||
setenv bootargs console=ttyO0,115200n8 root=/dev/nfs rw nfsroot=192.168.0.251:/home/cpeacock/export/rootfs ip=192.168.0.250:::::eth0 | setenv bootargs console=ttyO0,115200n8 root=/dev/nfs rw nfsroot=192.168.0.251:/home/cpeacock/export/rootfs ip=192.168.0.250:::::eth0 | ||
− | bootm | + | bootm ${kloadaddr} - ${fdtaddr} |
</PRE> | </PRE> | ||
The following contains instructions for building the BeagleBone Black kernel on Ubuntu 14.04.
To compile the linux kernel for the BeagleBone Black, you must first have an ARM cross compiler installed. I use gcc-4.7-arm-linux-gnueabi-base that comes with Ubuntu 14.04. To install the compiler run:
sudo apt-get install gcc-arm-linux-gnueabi
The Beaglebone patches and build scripts are stored in a git repository. Install git:
sudo apt-get install git
And configure with your identity.
git config --global user.email "your.email@here.com"
The kernel is compressed using lzo. Install the lzop parallel file compressor:
sudo apt-get install lzop
The bootloader used on the BeagleBone black is u-boot. u-boot has a special image format called uImage. It includes parameters such as descriptions, the machine/architecture type, compression type, load address, checksums etc. To make these images, you need to have a mkimage tool that comes part of the u-Boot distribution. Download u-boot, make and install the u-boot tools:
wget ftp://ftp.denx.de/pub/u-boot/u-boot-latest.tar.bz2 tar -xjf u-boot-latest.tar.bz2 cd into u-boot directory make tools-only sudo install tools/mkimage /usr/local/bin
Here we compile the BeagleBone Black Kernel, and generate an uImage file with the DTB blob appended to the kernel for ease of use.
git clone git://github.com/beagleboard/kernel.git cd kernel git checkout 3.14 ./patch.sh cp configs/beaglebone kernel/arch/arm/configs/beaglebone_defconfig wget http://arago-project.org/git/projects/?p=am33x-cm3.git\;a=blob_plain\;f=bin/am335x-pm-firmware.bin\;hb=HEAD -O kernel/firmware/am335x-pm-firmware.bin cd kernel make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- beaglebone_defconfig -j4 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage dtbs LOADADDR=0x80008000 -j4
Now we build any kernel modules:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules -j4
And if you have your rootfs ready, you can install them:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=/home/cpeacock/export/rootfs modules_install
Rather than flashing your newly created kernel to find out it doesn't work or it is not quite configured correctly, a better way is to load the kernel into RAM and boot it from there. u-boot allows kernel images to be loaded via TFTP.
To speed up development, I create an 'export' directory. A TFTP server is then configured to use this directory as the TFTP root.
From the export directory, add symbolic links to the kernel images. This way, you can recompile the kernel and the new image is instantly available without having to move it.
ln -s /path to linux/arch/arm/boot/uImage uImage-BBB-3.14.1 ln -s /path to linux/arch/arm/boot/dts/am335x-boneblack.dtb am335x-boneblack.dtb
To test your kernel, bring up a serial console to the BeagleBone Black. First we will need to configure the IP addresses. The ipaddr variable contains the IP address for the BeagleBone Black, while the serverip variable is the address of the TFTP server containing the kernel image.
setenv ipaddr 192.168.0.250 setenv serverip 192.168.0.251
These variables can be saved to non-volatile memory to speed up development.
Next load the Kernel image and device tree binary blob:
tftpboot ${fdtaddr} am335x-boneblack.dtb tftpboot ${kloadaddr} uImage-BBB-3.14.1
Let's use the existing root filesystem, and send kernel messages to ttyO0:
setenv bootargs console=ttyO0,115200n8 quiet root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait
And boot from the memory location:
bootm ${kloadaddr} - ${fdtaddr}
The example shown is to use the filesystem already in place (i.e. ext4 on mmcblk0p2). The preferred option is to export a root NFS filesystem.
Booting from NFS has the added advantage that you can compile userland binaries on your development box, install them to the NFS export and have instant access to them on your target system.
This requires a root filesystem to be present on your development box with binaries that have been cross compiled for ARM. Various distributions exist to assist you with this. It is assumed a NFS Server is installed and configured properly to export this directory.
Angstrom BeagleBone demo files can be downloaded from here
Download the raw filesystem and decompress:
mkdir rootfs wget http://downloads.angstrom-distribution.org/demo/beaglebone/Angstrom-systemd-image-eglibc-ipk-v2012.12-beaglebone-2013.09.12.rootfs.tar.xz tar -xJf Angstrom-systemd-image-eglibc-ipk-v2012.12-beaglebone-2013.09.12.rootfs.tar.xz -C rootfs
At this point you will need to ensure your kernel modules are present. If not, run the following from your kernel folder to install the modules on your rootfs:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=/home/cpeacock/export/rootfs modules_install
In uBoot, you can now issue the following commands to load your kernel from TFTP and your rootfs over NFS:
setenv ipaddr 192.168.0.250 setenv serverip 192.168.0.251 tftpboot ${fdtaddr} am335x-boneblack.dtb tftpboot ${kloadaddr} uImage-BBB-3.14.1 setenv bootargs console=ttyO0,115200n8 root=/dev/nfs rw nfsroot=192.168.0.251:/home/cpeacock/export/rootfs ip=192.168.0.250:::::eth0 bootm ${kloadaddr} - ${fdtaddr}
If your NFS root freezes during boot with a message similar to:
nfs: server 192.168.0.251 not responding, still trying
Then it is possible the network connection used by the NFS connection has been re-configured. On Angstrom, this connection is re-established by the Connection Manager (ConnMan.) To quickly overcome this problem, remove /lib/systemd/system/connman.service from your rootFS.