Building Embedded Linux from scratch for Beaglebone black

I thought of sharing my experience on building embedded linux from scratch for Beaglebone black. I have been searching the internet for many days, but failed to find a good resource about building  embedded linux from scratch for Beaglebone black. I came across many blogs which explains how to build embedded linux for beaglebone black, but in practical none of them worked for me. I know many of you have tried the same thing.Even though  there are many good blogs which explains theory on how to build embedded linux for beaglebone black. You will find many links on how to build embedded linux from scratch using Yocto or Buildroot. In my future post i will explain you how to build embedded linux using Yocto and Buildroot.
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 https://releases.linaro.org/components/toolchain/binaries/6.2-2016.11/arm-linux-gnueabihf/gcc-linaro-6.2.1-2016.11-i686_arm-linux-gnueabihf.tar.xz
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
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

Clone  the linux kernel from github.

git clone git://github.com/beagleboard/linux.git

 

After cloning the linux repository you will find the linux directory.

Change directory to linux and checkout linux kernel 4.1 version.

cd linux
git checkout 4.1

Compiling the kernel with beaglebone default configuration

sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bb.org_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://git.denx.de/u-boot.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.

ls

api        drivers   MAINTAINERS      spl                 u-boot.lds
arch       dts       Makefile         System.map          u-boot.map
board      examples  MLO              test                u-boot-nodtb.bin
cmd        fs        MLO.byteswap     tools               u-boot.srec
common     include   net              u-boot              u-boot.sym
config.mk  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.

loadaddr=0x82000000
fdtaddr=0x88000000
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 http://www.bootembedded.com/downloads/rootfs.tar

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
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

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
sync

 

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.

 

 


6 thoughts on “Building Embedded Linux from scratch for Beaglebone black”

Leave a Reply

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