Let us automate embedded Linux development using buildroot.
In this post, I’m going to describe the procedure to create a complete Embedded Linux software for Raspberry Pi using buildroot. We will be configuring buildroot to create a complete package which includes following components
- Device tree
- Cross compiler
These components are pretty much necessary to boot Raspberry Pi board. Only sad part here is, Rpi buildroot default configuration won’t generate u-boot bootloader, which is a conventional embedded Linux component. In fact, Rpi demos doesn’t come with u-boot.
So, in the part-2, we will customize the buildroot and add support for u-boot.
Development Environment :
Nothing much required for buildroot setup.
- Ubuntu 14.04
- Internet to download buildroot and packages
Required Ubuntu tools and dependencies:
Common tools are required such as, minicom, git, ncurses etc… Run below commands as a root user to install in your Ubuntu computer.
$ sudo apt-get install minicom git ncurses-dev gedit flex bison $ sudo apt-get install texinfo g++ gettext u-boot-tools autoconf
Raspberry Pi BSP development with Buildroot:
Let’s get started with buildroot setup.
1. Run below command to clone mainline buildroot source.
$ git clone git://git.buildroot.net/buildroot
2. Change directory to buildroot
$ cd buildroot/
3. Checkout a particular git tag or git branch. To verify available buildroot tags, run below command.
$ git tag
Now checkout a particular tag or branch based on the requirement. Say latest 2016 tag.
$ git checkout 2016.02 -b 2016.02
4. Once done with checkout process, have a glance at buildroot folder structure.
5. Now, you need to identify and apply the raspberry pi board specific configuration.
In the buildroot, configuration files are available in the ‘./configs’ folder. Run below command to verify the list of available configuration files.
$ ls configs/
6. In particular, to find raspberry configuration run below command.
$ ls configs/raspberrypi*
You will get terminal messages as shown below.
$ ls configs/raspberrypi* configs/raspberrypi2_defconfig configs/raspberrypi_defconfig
So, there are two configuration files available. Since, there is a change in the ARM core of rpi previous versions and Rpi-2,3, its is required to have two different configuration files.
raspberrypi2_defconfig – This configuration is for raspberry pi 2 and later versions of boards
raspberrypi_defconfig – This configuration is for raspberry pi cm, raspberry pi b, raspberry pi b+ boards and other earlier versions.
7. Now apply desired configuration file.
For raspberry Pi A/B A+/B+ boards, run this command
$ make raspberrypi_defconfig
For Raspberry PI 2 run this command
$ make raspberrypi2_defconfig
8. No compile the buildroot.
$ make -j4
Compilation process takes several hours based on in the Internet speed and type of host machine. You may also get build errors during compilation . So try to monitor the build process.
9. Once done with the compilation, final images will be stored in the below path.
$ ls output/images/
bcm2708-rpi-b-plus.dtb - Rpi B+ and A + device tree bcm2708-rpi-b.dtb - Rpi B and A device tree bcm2708-rpi-cm.dtb - Rpi Computer module device tree rootfs.ext4 - Root filesystem rpi-firmware/ ├── bootcode.bin - Second stage bootloader ├── cmdline.txt - For Boot parameter ├── config.txt - System configuration file ├── fixup.dat - For SDRAM configuration b/w CPU and GPU └── start.elf - GPU firmware zImage - Kernel image sdcard.img - Disk image for SD cards
10. Other important component is cross compiler, which can be found in the below path.
$ ls output/host/usr/bin/arm-buildroot-linux-uclibcgnueabihf-*
Now, you are done with basic buildroot setup for Raspberry PI boards. We will be using this buildroot setup for future development.
Create bootable SD card:
Disk image makes our life more easier. Follow below post and flash sdcard.img to a SD card.
In the upcoming post, we will see the procedure to boot till Linux prompt.