Loading...
 

Boot from removable storage - OpenWrt

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 page will give an example of how to set up a Micro SD Card/USB stick containing the OpenWrt binaries for MACCHIATObin. For a complete illustration of the interfaces available on MACCHIATObin board, please go to page MACCHIATObin Interface list.

OpenWrt binaries for MACCHIATObin can be obtained in two ways:


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. Furthermore, the instructions below are the same no matter which kernel or OpenWrt version is used.

Once you have the removable storage inserted in you Linux machine, you may check the presence of the storage with the lsblk command:

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]
sdc      8:32   1   7,5G  0 disk 
└─sdc1   8:33   1   7,5G  0 part


We can see from the output above the sdc is the micro SD card we have inserted in. The Micro SD card has one partition named sdc1 which takes all the space in the card. We can utilize this partition and format it to the ext3 file system. Please be sure to backup the content before formatting.

Alternatively, you can re-partition the micro SD card using the fdisk tool in your Linux machine. You'll also need to backup the content before re-partition. So, after partitioning the micro SD card, format it as EXT4 with:

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


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

user@laptop:~$ sudo mkdir -p /mnt/sdcard
user@laptop:~$ sudo mount /dev/sdc1 /mnt/sdcard
user@laptop:~$ cd /mnt/sdcard


Now we will extract OpenWrt root file system on it:

user@laptop:/mnt/sdcard$ sudo tar -xzf /opt/openwrt/openwrt-dd/bin/mvebu64/openwrt-mvebu64-armada-a8k-machiatobin-rootfs.tar.gz -C .


Adjust the root file system path to point to the location where it was built or downloaded. Now, create a boot/ directory where the device tree file and image will be copied to:

user@laptop:/mnt/sdcard$ sudo mkdir -p boot/
user@laptop:/mnt/sdcard$ sudo cp /opt/openwrt/openwrt-dd/bin/mvebu64/armada-8040-mcbin.dtb boot/
user@laptop:/mnt/sdcard$ sudo cp /opt/openwrt/openwrt-dd/bin/mvebu64/openwrt-armada-a8k-MACHIATOBin-Image boot/
user@laptop:/mnt/sdcard$ ls boot/
armada-8040-mcbin.dtb  openwrt-armada-a8k-MACHIATOBin-Image


Again, adjust the path of the device tree file and image accordingly. Now that the Micro SD card is ready, exit the mounted director and unmount the SD card:

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

 

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 OpenWrt 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 created the sdc1 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/openwrt-armada-a8k-MACHIATOBin-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'


To preserve the configuration across reboots:

Marvell>> saveenv


You can save the variables at any desired moment. Additionally, you can setup the bootcmd variable for the MACCHIATObin to automatically boot from 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


and lastly boot the board with:

Marvell>> run bootmmc
switch to partitions #0, OK
mmc1 is current device
12408832 bytes read in 3606 ms (3.3 MiB/s)
35004 bytes read in 154 ms (221.7 KiB/s)
## Flattened Device Tree blob at 01800000
   Booting using the fdt blob at 0x1800000
   Using Device Tree in place at 0000000001800000, end 000000000180b8bb

Starting kernel ...

[Truncated output]

BusyBox v1.24.2 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 DESIGNATED DRIVER (Bleeding Edge, 50122)
 -----------------------------------------------------
  * 2 oz. Orange Juice         Combine all juices in a
  * 2 oz. Pineapple Juice      tall glass filled with
  * 2 oz. Grapefruit Juice     ice, stir well.
  * 2 oz. Cranberry Juice
 -----------------------------------------------------
root@OpenWrt:/#

 

Using USB device


If you are using the USB stick to store the OpenWrt kernel image/dtb and root file system for MACCHIATObin, you will 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 boot directory, we would use:

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/openwrt-armada-a8k-MACHIATOBin-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


View an example bootlog for 17.02 release here or for 17.06 release here.