Building embedded linux system using mainline kernel for beaglebone black

In my previous post i have explained how to build embedded linux system using official BeagleBoard and BeagleBone kernel repository. There are many kernel repository out there for beaglebone. In this post i am going to explain a way to build embedded linux using mainline kernel.  As you go through the post you will understand that almost all the steps are identical to my previous post.
Beaglebone Black booting process
 Beaglebone Black boot process
ARM Cross Compiler Setup

Before jumping deep into the wonderful world of building embedded linux from scratch , let us set up arm cross compiler. Create  a directory and name it lfs. Please make sure to use this directory to try this post  so that it will be easy to keep track of things.Now traverse in to the lfs directory.

cd lfs
I have used Debian Distribution  for compiling and building embedded linux. I suggest you to use the same or else you can use Virtual machine. You can download virtual image copies at osboxes . You can either download for VM ware or for Virtual Box.

Download ARM gcc cross compiler and untar it.

wget -c
tar xf gcc-linaro-6.2.1-2016.11-i686_arm-linux-gnueabihf.tar.xz
export CC=`pwd`/gcc-linaro-6.2.1-2016.11-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

To check the version type

${CC}gcc --version
arm-linux-gnueabihf-gcc (Linaro GCC 6.2-2016.11) 6.2.1 20161016
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

Downloading mainline kernel source and untar it

tar xvf linux-4.10.2.tar.xz
cd linux-4.10.2


Compiling the kernel with beaglebone default configuration

sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- omap2plus_defconfig
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage dtbs LOADADDR=0x80008000 -j

Move up one level.

cd ..

Clone boot loader U-Boot.

git clone git:// u-boot/
cd u-boot

Compiling the U-Boot with beaglebone default configuration

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- am335x_boneblack_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

After compiling U-Boot if you list the files you should see something like this.


api        drivers   MAINTAINERS      spl       
arch       dts       Makefile
board      examples  MLO              test                u-boot-nodtb.bin
cmd        fs        MLO.byteswap     tools               u-boot.srec
common     include   net              u-boot              u-boot.sym  Kbuild    post             u-boot.bin
configs    Kconfig   README           u-boot.cfg
disk       lib       scripts          u-boot.cfg.configs
doc        Licenses  snapshot.commit  u-boot.img

Prepare microSD card

If you have come till here i assume that you have successfully cross compiled linux kernel and U-Boot. Next step is pretty simple . All you need to do just take a sd card and make two partition. First partition is FAT32, it will contain u-boot files and second partition is ext4 which will contain root file system. For this we will use GParted tool. Just follow these simple steps to make two partition. Open GParted and select the sd card.
Please re-check the partition name.
Right click on the partition and unmount all the partitions. And delete all the partions. Once done, right click and make new partition.First is the of size 100 MB.A window will appear, enter 100 in New size (MiB) and choose file system as fat32. And name label as BOOT as shown in the below image.
Now again right click on the un allocated space and make new partition. Enter 1000 in New size(MiB) and choose file system as ext4. And label it as rootfs as shown in the image.
Next step is to mark the first partition as boot.

You need to copy MLO, u-boot.img from lfs/u-boot directory, am335x-boneblack.dtb from  lfs/linux/arch/arm/boot/dts directory, uImage from lfs/linux/arch/arm/boot to BOOT partition of the microSD card.

Higher Level block diagram  of microSD card

And make a file called uEnv.txt in BOOT partition and copy  below code.

arg=setenv bootargs console=ttyO0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait
image=load mmc 0:1 ${loadaddr} uImage ;
fdt=load mmc 0:1 ${fdtaddr} am335x-bonegreen.dtb ;
uenvcmd=run arg;load image;load fdt;bootm ${loadaddr} - ${fdtaddr};

Now you need to download  the  root file system. I have created a minimal file system using BusyBox.

wget -c

Copy the downloaded file to rootfs partition and untar it.

sudo cp rootfs.tar /media/$USER/rootfs/
cd /media/$USER/rootfs/
sudo tar xvf rfs.rar
sudo rm rfs.tar

Make sure you are in lfs/linux directory and the arm gcc compiler is in environment variable. If not go to lfs directory and export it.

export CC=`pwd`/gcc-linaro-6.2.1-2016.11-i686_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
${CC}gcc --version
arm-linux-gnueabihf-gcc (Linaro GCC 6.2-2016.11) 6.2.1 20161016
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

Compile the kernel modules and install the modules.

sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j4 modules
sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=/media/$USER/rootfs/ modules_install

Un mount the microSD card

sudo umount /media/$USER/BOOT
sudo umount /media/$USER/rfs
 Plug the microSD card in to beaglebone black and press S2 button  and power it up . Make sure you are using serial cable adapter.
 Now you will see linux booting in the serial terminal. You can check the linux version by typing uname -a.

Leave a Reply

Your email address will not be published. Required fields are marked *