Skip to content

How to build filesystem and kernel images for ARC cores with Buildroot

Anton Kolesov edited this page May 29, 2015 · 20 revisions

Buildroot is an open source project (essentially a set of smart Makefiles) that automates the process of (optionally) building a tool-chain, downloading and cross-compiling various packages (including the kernel) and combining those into a binary image which can be run on target.

This article will focus on helping ARC users generate images of filesystems and Linux kernel for ARC cores using Buildroot.

Requirements

Buildroot is meant to be run on Linux host and because of that fact to proceed with instructions below it is necessary to have access to Linux-powered host computer (be it laptop, desktop or remote server) or virtual machine (for example VirtualBox or VMWare player).

It is likely that the Linux distribution on the user's host machine may not have all pre-requisite software packages already installed. The need to install these required software packages on the machine in turn requires root/administrator privileges. For users that don't have root privileges, a virtual machine environment may be more convenient.

Two most popular virtual machines available free of charge are VirtualBox from Oracle (Installing VirtualBox and extension packs) and VMWare Player (VMware Player Documentation).

Once virtual machine is installed Linux distribution of choice has to be installed as a guest OS in virtual machine. Please follow instructions provided for your virtual machine.

We recommend to use either Ubuntu LTS (as of writing this is 14.04) or CentOS 6 or 7. These distributions have pretty long life cycle (Ubuntu 14.04 will be supported by Canonical until April 2019, CentOS 6 will reach end of life in November 2020 and CentOS 7 in June 2024) so they will be around for quite some time and user may expect instructions below to work through all this time.

Prerequisites

Please refer to Buildroot documentation and in particular section System requirements that lists mandatory and optional packages needed for successful completion of Buildroot execution.

Depending on Linux distribution installed on development host procedure of package installation will differ. On RedHat-based distros (RedHat, CentOS, Fedora etc) user needs to run:

yum install -y subversion binutils bzip2 gcc gcc-c++ gawk gettext flex ncurses-devel zlib-devel make patch unzip perl-ExtUtils-MakeMaker glibc glibc-devel glibc-static quilt ncurses-lib sed sdcc intltool sharutils bison wget

On Debian-based distros (Debian, Ubuntu, Mint etc) user needs to run:

sudo apt-get install build-essential subversion libncurses5-dev zlib1g-dev gawk gcc-multilib flex git-core gettext libssl-dev

Getting Buildroot

Download latest official Buildroot release tarball from http://buildroot.uclibc.org/download.html (as of this writing it is version 2015.02).

$ wget http://buildroot.uclibc.org/downloads/buildroot-2015.02.tar.gz
$ tar -xf buildroot-2015.02.tar.gz

Configuring Buildroot

Now it is required to configure Buildroot so it generates executables for desired hardware, select origin of Linux kernel sources, its version and defconfig name, software packages to be built as well.

Below is a step-by-step Buildroot configuration guide with screen-shots:

$ cd buildroot-2015.02
$ make menuconfig

Select target architecture

Go to Target options -> Target Architecture

Select target architecture

Little-endian or big-endian ARC

Select preferred version of ARC core

As of this writing following ARC cores are supported:

  • ARC 750D
  • ARC 770D
  • ARC HS38

Modify toolchain configuration

To do it first return to the main menu with exit "button" until you're at the top-level menu and navigate to "Toolchain" sub-menu.

There're lots of options to enable. You only need to select either one if you do need it.

For example if you need C++ compiler then select Enable C++ support. Some packages that you can build with Buildroot may require support of particular features of toolchain so if that requirement is not met you'll need to go back to toolchain configuration to enable a missing feature.

As soon as this step is complete it's possible to build toolchain only. Just exit configuration utility saving your new configuration and issue make toolchain command in console.

Select software packages to be built

Buildroot has more than 1200 packages available that user may build with 1 mouse click. Go to "Target packages" and select packages you need.

Configure Linux kernel to be built

If there's a need to build not only toolchain and software packages but Linux kernel as well it is possible to do automatically with Buildroot.

Go to "Kernel" sub-menu, enable kernel building...

Select version, and output format.

If you're going to use JTAG to load built kernel image onto the target then select vmlinux. If you're going to load kernel via U-Boot then select uImage.

Filesystem images

Depending on your use-case you may need different type of filesystem image.

The most common use-cases are:

  1. Initial RAM filesystem built linked into Linux kernel.
    This builds filesystem in the same binary together with kernel itself and so user will need to load only one file on target and execute it. No additional storage is required in this case.

  2. jffs2 root filesystem
    This is used for putting root filesystem on embedded flash media on the target

  3. tar the root filesystem
    This will generate a tarball with full copy of root filesystem. Contents could be extracted for example on removable device (Sd/MMC-card, USB-flash drive or external HDD) and then attached to the target.

Building everything

Once user is done with configuration it's time to execute a build process. This is done as simple as issuing make command in terminal.

After build process is finished, results could be found in output/images/.

Note that buildroot also downloads tarballs with sources and this may take significantly longer compared to building itself especially if your internet connection is slow.

To address mentioned problem user may use so-called offline build. First user downloads all sources with make source command and then building itself could be done without connection to internet at all.

Example

Download and extract Buildroot

$ wget http://buildroot.uclibc.org/downloads/buildroot-2015.02.tar.gz
$ tar -xf buildroot-2015.02.tar.gz
$ cd buildroot-2015.02

Create file .config with the following contents in buildroot-2015.02 folder:

BR2_arcle=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_DEFCONFIG="fpga"
BR2_LINUX_KERNEL_VMLINUX=y
BR2_TARGET_ROOTFS_INITRAMFS=y

Configure Buildroot from our configuration:

make oldconfig

Build everything:

make

And now we're ready to run created binary in simulator (we will use nSIM via MDB in command-line mode, i.e. without MDB GUI):

mdb -a7 -nsim -Xlib -prop=nsim_mmu=3 -Xtimer0 -icache=16384,64,2,o -dcache=32768,64,4,o -prop=nsim_mem-dev=uart0 -prop=nsim_isa_atomic_option=1 -run -cl output/images/vmlinux

You'll see following output in the same console window:

Console now belongs to UART, hit CRTL-] to return to simulator.
Linux version 3.18.6 (abrodkin@abrodkin-e7440l) (gcc version 4.8.3 (Buildroot 2015.02) ) #2 PREEMPT Thu Mar 19 16:00:49 MSK 2015
Memory size set via devicetree 256M
Machine model: snps,arc-angel4
Early serial console at MMIO32 0xc0fc1000 (options '115200n8')
bootconsole [uart0] enabled

IDENTITY	: ARCVER [0x32] ARCNUM [0x0] CHIPID [ 0x0]
processor [0]	: ARC 700 (ARCompact ISA) 
CPU speed	: 80.00 Mhz
Timers		: Timer0 Timer1 
ISA Extn	: atomic 
		: mpy norm barrel-shift swap minmax swape
MMU [v3]	: 8k PAGE, JTLB 256 (128x2), uDTLB 8, uITLB 4 
I-Cache		: 16K, 2way/set, 64B Line, VIPT
D-Cache		: 32K, 4way/set, 64B Line, VIPT
Vector Table	: 0x80000000
Uncached Base	: 0xc0000000
OS ABI [v3]	: no-legacy-syscalls
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 32624
Kernel command line: earlycon=arc_uart,mmio32,0xc0fc1000,115200n8 console=ttyARC0,115200n8
PID hash table entries: 1024 (order: -1, 4096 bytes)
Dentry cache hash table entries: 32768 (order: 4, 131072 bytes)
Inode-cache hash table entries: 16384 (order: 3, 65536 bytes)
Memory: 256448K/262144K available (2250K kernel code, 122K rwdata, 688K rodata, 672K init, 230K bss, 5696K reserved)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Preemptible hierarchical RCU implementation.
NR_IRQS:128
Console: colour dummy device 80x25
Calibrating delay loop... 79.46 BogoMIPS (lpj=397312)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 2048 (order: 0, 8192 bytes)
Mountpoint-cache hash table entries: 2048 (order: 0, 8192 bytes)
devtmpfs: initialized
NET: Registered protocol family 16
Switched to clocksource ARC Timer1
NET: Registered protocol family 2
TCP established hash table entries: 2048 (order: 0, 8192 bytes)
TCP bind hash table entries: 2048 (order: 0, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP: reno registered
UDP hash table entries: 512 (order: 0, 8192 bytes)
UDP-Lite hash table entries: 512 (order: 0, 8192 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
futex hash table entries: 256 (order: -2, 3072 bytes)
msgmni has been set to 500
io scheduler noop registered (default)
c0fc1000.serial: ttyARC0 at MMIO 0x0 (irq = 5, base_baud = 5000000) is a arc-uart
console [ttyARC0] enabled
console [ttyARC0] enabled
bootconsole [uart0] disabled
bootconsole [uart0] disabled
emac_arc c0fc2000.ethernet: failed to retrieve host clock from device tree
emac_arc: probe of c0fc2000.ethernet failed with error -22
mousedev: PS/2 mouse device common for all mice
TCP: cubic registered
NET: Registered protocol family 17
NET: Registered protocol family 15
Freeing unused kernel memory: 672K (80002000 - 800aa000)
Starting logging: OK
Initializing random number generator... random: dd urandom read with 1 bits of entropy available
done.
Starting network...

Welcome to Buildroot
buildroot login:

To log in just say root and press Enter. Now you may play with simple utilities that are provided by Busybox, for example:

# ls /
bin      home     lib32    mnt      root     sys      var
dev      init     linuxrc  opt      run      tmp
etc      lib      media    proc     sbin 

To terminate debug session first press Ctrl-], then Ctrl-C four times in a row.

Clone this wiki locally