Buildroot for the i.MX6 sabre sd platform in a few commands

Document created by Vincent Stehle Employee on Dec 26, 2013Last modified by Vincent Stehle Employee on Mar 18, 2015
Version 15Show Document
  • View in full screen mode

br-sabresd.png

Here is a quick summary at building a bootloader, a kernel and a root filesystem for the i.MX 6 sabre sd platform, using buildroot.

 

This assumes you have a "working" Linux development environment at hand (e.g. Debian).

 

Buildroot is a fine build system, which makes deploying Linux on embedded platforms really easy. It is comparable to Yocto in spirit, but much simpler. Thanks to my colleague Gilles Talis, buildroot now has builtin support for the i.MX6 sabre sd platform.

 

Get buildroot sources

 

We will use git to fetch buildroot sources:


$ git clone git://git.busybox.net/buildroot


This should create a buildroot directory with all the latest sources (after a while).


Note that for more stability you might want to checkout a release instead of the latest version; to do so, list the available release tags with e.g. git tag -l '201*', and git checkout <the-desired-tag>.

 

Compile

 

The beauty of buildroot is that it will take care of everything for you, including preparing a cross compiler. You can download and build everything by doing:

 

$ cd buildroot

$ make freescale_imx6sabresd_defconfig

$ make

 

This should download and build everything, so it will take a while.

 

buildroot detects the number of CPUs you have in your machine and builds with parallel jobs automatically; no need to specify any -j argument to make here.

 

All build results fall under the output/images folder:

 

output/images/

+- rootfs.ext2

+- rootfs.tar

+- u-boot.bin

`- uImage

 

Format the SD card

 

As for Debian, we need to format the SD card with two partitions; one small FAT partition to contain the Linux kernel, and one large ext4 partition, which will contain the root filesystem with the buildroot generated userspace. Also, we need to make sure we leave some space for u-boot starting from offset 1024B.


Here is an example SD card layout:

 

+-----+------+--------+-----+---------------+-----------------

| MBR |  ... | u-boot | ... | FAT partition | Linux partition ...

+-----+------+--------+-----+---------------+-----------------

0     512    1024           1M              ~257M

 

(offsets in bytes)

 

Here is an example SD card layout, as displayed by fdisk:

 

Device    Boot      Start         End      Blocks   Id  System

/dev/sdc1            2048      526335      262144    c  W95 FAT32 (LBA)

/dev/sdc2          526336     8054783     3764224   83  Linux

 

(units: 512B sectors)

 

You can format the FAT boot partition with:

 

# mkfs.vfat /dev/<your-sd-card-first-partition>


Your SD card first partition is typically something in /dev/sd<X>1 or/dev/mmcblk<X>p1.


You can format the Linux partition with:

 

# mkfs.ext4 /dev/<your-sd-card-second-partition>


Your SD card second partition is typically something in /dev/sd<X>2 or/dev/mmcblk<X>p2.


Put on SD


As explained here, u-boot should reside at offset 1024B of your SD card. Also, as buildroot generates an u-boot.bin (and not an u-boot.imx) we should skip its first KB, too. In summary, to put u-boot on your SD, do:

 

  # dd if=output/images/u-boot.bin of=/dev/<your-sd-card> bs=1k seek=1 skip=1

  # sync

 

Your SD card device is typically something in /dev/sd<X> or /dev/mmcblk<X>. Note that you need write permissions on the SD card for the command to succeed, so you might need to su - as root, or use sudo, or do a chmod a+w as root on the SD card device node to grant permissions to users.

 

Similarly to what this post describes, you can copy the kernel to the FAT boot partition with:

 

# mount /dev/<your-sd-card-second-partition> /mnt

# cp output/images/uImage /mnt/

# umount /mnt


Your SD card first partition is typically something in /dev/sd<X>1 or/dev/mmcblk<X>p1.


And not unlike what is done in this post, You can install your generated root filesystem to the Linux partition with:

 

# mount /dev/<your-sd-card-second-partition> /mnt

# tar -C /mnt -xvf output/images/rootfs.tar

# umount /mnt


Your SD card second partition is typically something in /dev/sd<X>2 or/dev/mmcblk<X>p2.

 

Boot!


Your SD card is ready for booting. Insert it in the SD card slot of your i.MX6 sabre sd platform, connect to the USB to UART port with a serial terminal set to 115200 baud, no parity, 8bit data and power up the platform.


Like with Debian, u-boot default settings will not allow it to boot from the SD card, so we need to interrupt it by pressing enter at u-boot prompt for the first boot and setup u-boot environment to fix this:


MX6Q SABRESD U-Boot > setenv bootargs_mmc 'setenv bootargs ${bootargs} root=/dev/mmcblk1p2 rootwait'

MX6Q SABRESD U-Boot > setenv bootcmd_mmc 'run bootargs_base bootargs_mmc; mmc dev 2; fatload mmc 2:1 ${loadaddr} ${kernel}; bootm'

MX6Q SABRESD U-Boot > setenv bootcmd 'run bootcmd_mmc'

MX6Q SABRESD U-Boot > saveenv

Saving Environment to MMC...

Writing to MMC(2)... done

 

As this is saved in the SD card it need only to be done once at first boot. You can reboot your board or type boot; your buildroot system should boot to a prompt:

 

(...)

Welcome to Buildroot

buildroot login:

 

From there you may login as root.

 

Enjoy!


Tweak


buildroot uses Linux kernel kconfig to handle its configuration. So, as for the Linux kernel, changes to the configuration can be done with e.g.:


$ make menuconfig


Most of the options can be tuned from there, including (most importantly) which packages get installed into the generated root filesystem. This is configuration section 'Filesystem images'.


Further details are documented in buildroot manual.


Tips


  • ccache is natively supported by buildroot and can be easily enabled with configuration option BR2_CCACHE.
  • If you only use the generated rootfs.tar as described in this post and do not care about the rootfs.ext2, you might as well save a few seconds of build by disabling its generation. This is done with configuration option BR2_TARGET_ROOTFS_EXT2.
  • It is recommended to install an ssh server inside the target for further development. This is conveniently done with configuration option BR2_PACKAGE_OPENSSH.

 

See also...

 

3 people found this helpful

Attachments

    Outcomes