Loading...
 

Boot from removable storage - Buildroot

Creating bootable Micro SD card/USB stick


MACCHIATObin has a rich set of interfaces available on its main board including one Micro SD card slot and one USB3.0 port. This section will give an example of how to create a Micro SD Card/USB stick containing the Buildroot file system for MACCHIATObin. For instructions on how to build the Buildroot file system please refer to the page Build from source - Buildroot. For a complete illustration of the interfaces available on MACCHIATObin board, please go to page Ports and Interfaces.

First, insert the Micro SD card in your local Linux machine, or use a USB Micro SD card reader if your machine does not have a Micro SD card slot. The example instructions below shows the case of Micro SD card in a card reader, which is identical to a USB stick. Once you have the removable storage inserted in you Linux machine, you may check the presence of the storage with the lsblk command:

mcbin@buildserver:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238.5G  0 disk
├─sda1   8:1    0 230.6G  0 part /
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0   7.9G  0 part [SWAP]
sdb      8:16   0   3.7T  0 disk
└─sdb1   8:17   0   3.7T  0 part /media/disk1
sdc      8:32   0 238.5G  0 disk
└─sdc1   8:33   0 238.5G  0 part /media/disk2
sde      8:64   1   7.4G  0 disk
└─sde1   8:65   1   7.4G  0 part


We can see from the output above the sde is the Micro SD card we have inserted in. The Micro SD card has one partition named sde1 which takes all the space in the card. We can utilize this partition and format it to the ext4 file system. Please be sure to backup the content before formatting. If you want to re-partitioning the Micro SD card, use the fdisk tool in your Linux machine. You'll also need to backup the content before re-partition.

mcbin@buildserver:~$ sudo mkfs.ext4 /dev/sde1
mke2fs 1.42.13 (17-May-2015)
/dev/sde1 contains a vfat file system
Proceed anyway? (y,n) y
Creating filesystem with 1939456 4k blocks and 485760 inodes
(truncated output)


Next we mount the partition to the Linux machine(e.g. we will mount it to /mnt/):

mcbin@buildserver:~$ sudo mount /dev/sde1 /mnt/


Now let's extract the Buildroot file system we created in the page Build from source - Buildroot to the Micro SD card.

mcbin@buildserver:~$ cd /mnt/
mcbin@buildserver:/mnt$ sudo tar -xvf ~/buildroot/output/images/rootfs.tar.gz


To confirm the content in the Micro SD card once the untar process is done:

mcbin@buildserver:/mnt$ ls
bin  dev  etc  home  lib  lib64  libexec  linuxrc  marvell  media  mnt  opt  proc  root  run  sbin  sys  tmp  usr  var


In order to make the Micro SD card as a standalone boot device, we also need to copy the kernel binary and dtb file over to the Micro SD card. The process of building the kernel binary is available at the page Build from source - Kernel.

mcbin@buildserver:/mnt$ sudo mkdir boot
mcbin@buildserver:/mnt$ sudo cp ~/kernel/4.4.52/arch/arm64/boot/Image boot/
mcbin@buildserver:/mnt$ sudo cp ~/kernel/4.4.52/arch/arm64/boot/dts/marvell/armada-8040-mcbin.dtb boot/


The boot directory will look like below once the copy is done: 

mcbin@buildserver:/mnt$ ls boot
armada-8040-mcbin.dtb  Image


Now the Micro SD card is ready, let's exit the mount directory and umount the Micro SD card.

mcbin@buildserver:/mnt$ cd
mcbin@buildserver:~$ sudo umount /mnt

 

Setting U-Boot parameters

 

Using Micro SD card

Remove the SD card from your local machine and plug it into the Micro SD card slot on the MACCHIATObin, plug the power adapter and connect to the board via Micro USB cable and serial connection as described in Quick Start Guide, section Serial Connection.

For the MACCHIATObin to boot the images we have placed on the Micro SD card, we must configure valid U-Boot parameters to do so. When the boot starts, hit any key to stop autoboot and get to the Marvell U-Boot prompt:

Hit any key to stop autoboot:  0
Marvell>>
Marvell>>


First we need to select the Micro SD card using mmc command:

Marvell>> mmc dev 1
switch to partitions #0, OK
mmc1 is current device

 
Then we can check the files on the Micro SD card with the ext4ls command which is used for listing the files from the ext4-formatting partition. The command syntax is as follows:

ext4ls <dev[:part]> [directory]


In the case of Micro SD card we have created in the section above, the dev number is 1, the partition number is also 1 as we create the sde1 partition in the example above.

Marvell>> ext4ls mmc 1:1 /


To list the boot directory in the Micro SD card, we would use:

Marvell>> ext4ls mmc 1:1 /boot


Now on to setting U-Boot parameters. You can list all existing parameters with printenv command. There are only a few variables we need to set (other needed variables should be set by default) in order to boot from the Micro SD card. First we set proper boot image name and device tree name:

Marvell>> setenv image_name boot/Image
Marvell>> setenv fdt_name boot/armada-8040-mcbin.dtb


Next we setup the boot command by creating the bootmmc variable. We will use this variable to boot the Micro SD card:

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


After this we will save the variables we have set so far:

Marvell>> save

 
You can save the variables at any desired moment. Note that you can also setup the bootcmd variable for the MACCHIATObin to automatically boot from the Micro SD card every time you power up the board:

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


Now we simply boot the kernel with:

Marvell>> run bootmmc


after the kernel is successfully booted, you should get to the Buildroot login console:

Welcome to Buildroot
buildroot login:


Now login with root and you should get the Buildroot command line interface:

buildroot login: root
#

 

Using USB Stick

If you are using the USB stick to store the kernel image/dtb and root file system for MACCHIATObin, you'll need to configure the U-Boot environment variables differently than those for Micro SD card in order to pick up the content from the USB stick.

Assuming you already have the USB stick with root file system created, first you'll need to setup the proper connections on MACCHIATObin, plug in the USB stick to the USB3.0 port and power on the board. When the U-Boot starts please hit enter key to stop the autoboot process.

Hit any key to stop autoboot:  0
Marvell>>
Marvell>>


Do usb reset command under U-Boot command line to activate the USB stick, the example below shows there is one USB storage device being detected.

Marvell>> usb reset
(Re)start USB...
USB0:   Register 2000120 NbrPorts 2
Starting the controller
USB XHCI 1.00
scanning bus 0 for devices... 2 USB Device(s) found
       scanning usb for storage devices... 1 Storage Device(s) found
       scanning usb for ethernet devices... 0 Ethernet Device(s) found


Then you may use the ext4ls command to list the files in the USB stick you have attached to the MACCHIATObin board. The command syntax is:

ext4ls  <dev[:part]> [directory]


In this example the interface will be usb, dev should be 0, first partition should be 1:

Marvell>> ext4ls usb 0:1 /


To list the content under the boot directory:

Marvell>> ext4ls usb 0:1 /boot


You can use the command printenv to print all the existing variables under U-Boot. To boot the kernel and root file system from the USB stick, you'll just need to change a few of the parameters. First, setup the correct kernel image name and device tree name:

Marvell>> setenv image_name boot/Image
Marvell>> setenv fdt_name boot/armada-8040-mcbin.dtb


Next step is to create a new variable bootusb to hold the command to boot from USB stick:

Marvell>> setenv bootusb 'usb reset; 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'


Use save command to save the variables to the on-board SPI flash.

Marvell>> save


You can also setup the bootcmd variable for MACCHIATObin to automatically boot from the USB stick every time you power on the board.

Marvell>> setenv bootcmd 'usb reset; 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'
Marvell>> save


Now we can boot the kernel with:

Marvell>> run bootusb


after the kernel is successfully booted, you should get to the Buildroot login console:

Welcome to Buildroot
buildroot login:


Login with root and you'll get the Buildroot command line interface:

buildroot login: root
#