Loading...
 

Boot from removable storage - Buildroot

Below we will show how to copy kernel and Buildroot root filesystem binaries to a microSD card or USB device, as well as how to set up boot parameters in U-Boot to boot from them.

Buildroot filesystem and images can be either:

Preparing removable media


The instructions below on how to prepare your micro SD card are identical to how you would go about preparing a USB device.

Insert the microSD card in your local Linux machine and you should see the SD card listed most probably as /dev/sd* device (or /dev/mmcblk0*) so make sure to check with lsblk:

user@laptop:/$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238,5G  0 disk
├─sda1   8:1    0   487M  0 part /boot/efi
├─sda2   8:2    0 234,1G  0 part /
└─sda3   8:3    0   3,9G  0 part [SWAP]
sdb      8:16   1   478M  0 disk
├─sdb1   8:17   1   100M  0 part
└─sdb2   8:18   1   377M  0 part


Our microSD card was recognized as /dev/sdb/. Since we will be formatting our SD card, we want to clear everything from it first (back up the content from your SD card before this):

user@laptop:/$ sudo dd if=/dev/zero of=/dev/sdb bs=1M count=100


Now we will create a new partition (sdb1) on the empty SD card:

user@laptop:/$ (echo n; echo p; echo 1; echo ''; echo ''; echo w) | sudo fdisk /dev/sdb


and format it as EXT4 with:

  • For e2fsprogs < 1.43 use:
user@laptop:/$ sudo mkfs.ext4 /dev/sdb1
  • For e2fsprogs >=1.43 use:
user@laptop:/$ sudo mkfs.ext4 -O ^metadata_csum,^64bit /dev/sdb1


Next, mount this partition on your local Linux machine (e.g. to /mnt/sdcard):

user@laptop:/$ sudo mkdir -p /mnt/sdcard
user@laptop:/$ sudo mount /dev/sdb1 /mnt/sdcard


Head into the mounted directory and there extract the Buildroot root file system (rootfs.tar.gz):

user@laptop:/$ cd /mnt/sdcard
user@laptop:/mnt/sdcard$ sudo tar -xvf /home/user/buildroot/output/images/rootfs.tar.gz


If you downloaded the rootfs archive from Tech Spec page, adjust the path above to point to where you stored the downloaded archive.

Next thing needed is to copy the kernel (here we will use v4.4.8) image (named Image) and the device tree generated for ESPRESSObin (named armada-3720-community.dtb) to our SD card into a new directory named boot/:

user@laptop:/mnt/sdcard$ sudo mkdir -p boot
user@laptop:/mnt/sdcard$ sudo cp /home/user/kernel/4.4.8/arch/arm64/boot/Image boot/
user@laptop:/mnt/sdcard$ sudo cp /home/user/kernel/4.4.8/arch/arm64/boot/dts/marvell/armada-3720-community.dtb boot/


The SD card is now ready and contains the necessary images. Exit the mounted directory and unmount it from your local machine with:

user@laptop:/mnt/sdcard$ cd
user@laptop:/$ sudo umount /mnt/sdcard

 

Setting U-Boot parameters


For the ESPRESSObin to boot the images we have placed on the SD card, we must configure valid U-Boot parameters to do so. 

Micro SD card


Unplug the SD card from your local machine and plug it into the SD card slot on the ESPRESSObin, plug the power adapter and connect to the board via micro USB cable and Serial connection.

When the boot starts, hit any key to stop autoboot and get to the Marvell U-Boot prompt:

Hit any key to stop autoboot:
Marvell>>


Optionally, check that the SD card has necessary files we have transferred using ext4ls command:

ext4ls  <dev[:part]> [directory]


So in our case, we want to list contents from mmc device 0 and its first partition:

Marvell>> ext4ls mmc 0:1
Marvell>> ext4ls mmc 0:1 boot


There are only a few variables required to boot from the microSD card. You can list all existing parameters with printenv command.

First, set the proper boot image name and device tree path and name:

Marvell>> setenv image_name boot/Image
Marvell>> setenv fdt_name boot/armada-3720-community.dtb


Next, define the bootmmc variable which we will use to boot from the microSD card:

Marvell>> setenv bootmmc 'mmc dev 0; ext4load mmc 0:1 $kernel_addr $image_name;ext4load mmc 0:1 $fdt_addr $fdt_name;setenv bootargs $console root=/dev/mmcblk0p1 rw rootwait; booti $kernel_addr - $fdt_addr'


Be careful to set the root variable to point to where you have extracted the root file system (first partition in our case). You can save the set variables at any time using the saveenv command.

Alternately, you can set identical values to the bootcmd variable for the ESPRESSObin to automatically boot from the micro SD card:

Marvell>> setenv bootcmd 'mmc dev 0; ext4load mmc 0:1 $kernel_addr $image_name;ext4load mmc 0:1 $fdt_addr $fdt_name;setenv bootargs $console root=/dev/mmcblk0p1 rw rootwait; booti $kernel_addr - $fdt_addr'

 

 Note
An important thing here is to check the values for default kernel load address (variable kernel_addr) and dtb load address (variable fdt_addr). If the kernel image is too large, it will overwrite the fdt table loaded to the memory. In such cases it is needed to modify fdt_addr to avoid dtb being overwritten by the kernel copy. To reassign dtb load address to, for example, 0x1800000, we would use:

Marvell>> setenv fdt_addr 0x1800000


Finally, boot up the ESPRESSObin with run bootmmc or if you set the bootcmd variable simply type reset:

Marvell>> run bootmmc
Welcome to Buildroot
buildroot login:


Log in with root. An example bootlog can be viewed here.

USB device


Unplug the USB device from your local machine and plug it into a USB port on the ESPRESSObin, plug the power adapter and connect to the board via micro USB cable and Serial connection.

When the boot starts, hit any key to stop autoboot and get to the Marvell U-Boot prompt:

Hit any key to stop autoboot:
Marvell>>

First, we need to verify that the USB is recognized with usb start:

Marvell>> usb start


and check that the file system, kernel image, and dtb file have been transferred correctly with the ext4ls command:

Marvell>> ext4ls usb 0:1
Marvell>> ext4ls usb 0:1 boot


Adjust the commands above to how you partitioned your USB device.

There are only a few variables required to boot from the USB device. You can print the currently defined variables at any point using printenv.

First, set proper image and device tree path and name:

Marvell>> setenv image_name boot/Image
Marvell>> setenv fdt_name boot/armada-3720-community.dtb


and set bootusb variable which we will use to boot from the USB device:

Marvell>> setenv bootusb 'usb start;ext4load usb 0:1 $kernel_addr $image_name;ext4load usb 0:1 $fdt_addr $fdt_name;setenv bootargs $console root=/dev/sda1 rw rootwait; booti $kernel_addr - $fdt_addr'


Be careful to set the root path above to point to where you have extracted the Buildroot file system (first partition in our case). You can save the set variables at any time using the saveenv command.

Alternately, you can set identical values to the bootcmd variable for the ESPRESSObin to automatically boot from the USB device:

Marvell>> setenv bootcmd 'usb start;ext4load usb 0:1 $kernel_addr $image_name;ext4load usb 0:1 $fdt_addr $fdt_name;setenv bootargs $console root=/dev/sda1 rw rootwait; booti $kernel_addr - $fdt_addr'


Finally, boot the ESPRESSObin either with run bootusb or if you set the bootcmd variable simply type reset (log in with root):

Marvell>> run bootusb