Buildroot

Buildroot is a tool, that automates the whole creation of an embedded linux image: crosscompiler toolchain creation, kernel configuration and build and packages building.

Buildroot has a database of many packages that can be built and included in the image. All you have to do is configure it (using the kernel based KConfig) and run it:

Basic configuration

An example for a virtual qemu versatilepb based machine:

git clone git://git.buildroot.net/buildroot
cd buildroot
make qemu_arm_versatile_defconfig

make menuconfig

Use an external  binary toolchain so we don't have to wait:
Toolchain  --->
  Toolchain type (External toolchain)  --->
(buildroot will automatically select some binary toolchain)

You can change things like hostname, init system, root password, in System configuration or select a specific kernel in Kernel.

Package selection

In Target packages, you can select individual packages that you want in your image:

Target packages  --->
  Audio and video applications  --->
    [*] alsa-utils  --->
      [*]   alsamixer
    [*] mpg123

Note that selecting any of the alsa utils automatically selected alsa-lib under Libraries > Audio/Sound, so that you don't have to take care of the dependencies.

Advanced linux (kernel) configuration

To configure the kernel, just run make linux-menuconfig, kernel configuration will be saved in output/build/linux-VERSION/.config. You can copy it to board/something/someconfig.config and set it under Kernel > Configuration file path.

make linux-menuconfig
...
Device Drivers  --->
  [*] USB support  --->
    <*>   Support for Host-side USB
    <*>     OHCI HCD (USB 1.1) support
    <*>     USB Mass Storage support

"make linux-update-defconfig" would direclty save it as your currently
configured defconfig (i.e. replace "board/qemu/arm-versatile/linux-4.4.config") 
make linux-savedefconfig
cp output/build/linux-4.4.1/defconfig  board/qemu/arm-versatile/mediaplayer.config
make menuconfig
Kernel  --->
  Kernel configuration (Using a custom (def)config file)  --->
  (board/qemu/arm-versatile/mediaplayer.config) Configuration file path

Automate the configuration

Because buildroot uses KConfig, you can use the same savedefconfig / make xxx_defconfig features to save / use your config as with kernel.

buildroot saves defconfig according to the BR2_DEFCONFIG config item:
make menuconfig

Build options  --->
  (configs/qemu_arm_mediaplayer_defconfig) Location to save buildroot config

make savedefconfig

Because we cloned a git repo, we can either commit it to git, or even use git to just get a patch we could use to easily apply our configuration (we will also include the modified kernel defconfig in the same patch):

git status
Untracked files:
        configs/qemu_arm_mediaplayer_defconfig

git add configs/qemu_arm_mediaplayer_defconfig
git add board/qemu/arm-versatile/mediaplayer.config

You could commit to git at this point, let's just make a good old patch:

git diff --cached >mediaplayer.patch
cat mediaplayer.patch

diff --git a/board/qemu/arm-versatile/mediaplayer.config b/board/qemu/arm-versatile/mediaplayer.config
new file mode 100644
index 0000000..471513f
--- /dev/null
+++ b/board/qemu/arm-versatile/mediaplayer.config
@@ -0,0 +1,50 @@
+CONFIG_SYSVIPC=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+CONFIG_ARCH_VERSATILE=y
...
+CONFIG_USB=y
+CONFIG_USB_OHCI_HCD=y
+CONFIG_USB_STORAGE=y
...
diff --git a/configs/qemu_arm_mediaplayer_defconfig b/configs/qemu_arm_mediaplayer_defconfig
new file mode 100644
index 0000000..63ccc95
--- /dev/null
+++ b/configs/qemu_arm_mediaplayer_defconfig
@@ -0,0 +1,16 @@
+BR2_arm=y
+BR2_TOOLCHAIN_EXTERNAL=y
+BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+BR2_SYSTEM_DHCP="eth0"
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.4.1"
+BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
+BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/arm-versatile/linux-4.4.config"
...

Next time you can use either git apply or plain patch command to apply the change after a clean clone / unpack:

git apply mediaplayer.patch
OR
patch -p1 <mediaplayer.patch 
patching file board/qemu/arm-versatile/mediaplayer.config
patching file configs/qemu_arm_mediaplayer_defconfig

make qemu_arm_mediaplayer_defconfig

And build it:

make

Note: buildroot desn't build packages in parallel (i.e. as with -j1), however it will build each package with a parallel make according to the Build options > Number of jobs to run simultaneously setting (default is 0 which means to autodect, so you really don't need to change anything).

You can check board/qemu/arm-versatile/readme.txt for info on how to start qemu for this build/machine.

Vim logo FireFox logo CSS XHTML
Jozef Siska @ KAI FMFI UK YoYo @ KSP KAI (DAI) KSP