Loading...
 

Bootloader recovery via SATA

This tutorial will show you how to recover your ESPRESSObin board using a SATA drive on Linux. This method is highly useful in recovering a bricked board without the need to remove the onboard SPI flash.

The SATA bootloader image (U-Boot version 17.10) can be either:

1. Built manually using instructions in Build from source - Bootloader, SATA section.
2. Downloaded from our Tech Spec page under Bootloader - SATA images.

 Warning
Whether using manually built or prebuilt images, make sure to use the image according to the size of your ESPRESSObin's DDR memory (i.e. users with 1GB DDR ESPRESSObin must use the bootloader image supporting 1GB DDR memory).


Of course, you also need to have an SPI bootloader image ready in order to recover the SPI bootloader. The procedure for building SPI bootloader images is shown in Build from source - Bootloader.

SATA drive requirements


Here is what you will need to connect and power on the SATA drive:

  • spare HDD/SSD
  • female Molex cable to power the SATA drive to the power supply on ESPRESSObin (alternatively, the SATA drive can be powered on with an external power supply)
  • SATA cable for data connection


Before proceeding, make sure to back up all data on your HDD/SSD as writing the SATA boot image on the disk will destroy all data on it.

SATA boot mode


ESPRESSObin supports booting from various devices by manually relocating on-board wire jumpers J10, J3 and J11. These jumpers are located next to the SATA data cable, as can be seen below:

ESPRESSObin Jumpers

whereas their representations can be seen in the picture below:

ESPRESSObin Jumpers Closeup

To set ESPRESSObin boot mode to SATA, arrange the jumpers in the following manner:

J10J3J11
2-32-31-2


Other boot options and their respective jumper arrangement can be found in the official Globalscale's ESPRESSObin Quick Start Guide.

Writing SATA bootloader image on SATA drive


There are several methods which can be used to format the SATA drive and write the SATA boot image on it. Below we will cover how to do this on your local Linux machine or using the ESPRESSObin board itself.

Linux machine


Connect the SATA drive to your Linux machine and check with lsblk that the drive is recognized, for example:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 1023M 0 part /boot
├─sda2 8:2 0 5G 0 part [SWAP]
└─sda3 8:3 0 232.5G 0 part /
sdb 8:0 1 1.8T 0 disk


In our case, the SATA drive has been listed as /dev/sdb. Make sure to write to the correct SATA drive.

We will write the image to a disk in RAW format meaning no partitioning will be done. If needed, delete the partitions and create a new DOS disklabel on your SATA drive using fdisk (of course, replace sdX with the drive letter of your SATA drive):

espressobin@buildserver:~$ (echo d; echo o; echo w) | sudo fdisk /dev/sdX


and write the SATA bootloader image with:

espressobin@buildserver:~$ sudo dd if=flash-image-sata.bin of=/dev/sdX conv=fdatasync
1413+1 records in
1413+1 records out
723920 bytes (724 kB, 707 KiB) copied, 0.472965 s, 1.5 MB/s


Now safely remove the SATA drive from your local Linux machine, hook it up to the ESPRESSObin and head on to Boot from SATA section.

ESPRESSObin


If your local machine does not have an eSATA port, you can alternatively use ESPRESSObin (running Ubuntu 16.04 as shown in Creating Ubuntu filesystem) to write the image on the SATA drive. This is not doable if you have bricked your ESPRESSObin, but can be useful if you have a second, working ESPRESSObin unit.

For the SATA drive to be recognized, head into your 4.4.52 kernel build directory and launch make menuconfig:

espressobin@buildserver:~/kernel/4.4.52$ make menuconfig


There search for and select the following options:

Symbol: SATA_MV [=y]
 Type  : tristate
 Prompt: Marvell SATA support
   Location:
     -> Device Drivers
       -> Serial ATA and Parallel ATA drivers (libata) (ATA [=y])
         -> ATA SFF support (for legacy IDE and PATA) (ATA_SFF [=y])
 (1)       -> ATA BMDMA support (ATA_BMDMA [=y])
   Defined at drivers/ata/Kconfig:328
   Depends on: ATA [=y] && ATA_SFF [=y] && ATA_BMDMA [=y] && (PCI [=y] || ARCH_DOVE || ARCH_MV78XX0 || ARCH_MVEBU || ARCH_ORION5X || COMPILE_TEST [=n])
   Selects: GENERIC_PHY [=y]

 

Symbol: ATA_GENERIC [=y]
 Type  : tristate
 Prompt: Generic ATA support
   Location:
     -> Device Drivers
       -> Serial ATA and Parallel ATA drivers (libata) (ATA [=y])
 (1)     -> ATA SFF support (for legacy IDE and PATA) (ATA_SFF [=y])
   Defined at drivers/ata/Kconfig:1007
   Depends on: ATA [=y] && ATA_SFF [=y] && PCI [=y] && ATA_BMDMA [=y]


Now compile the kernel with:

espressobin@buildserver:~/kernel/4.4.52$ make -j4


The above kernel configuration works also for kernel 4.4.8.

Once the build is finished, transfer the images to your SD card and boot ESPRESSObin from it as instructed in Boot from MicroSD card/USB stick - Ubuntu.

Once in Ubuntu, transfer the SATA bootloader image to the board via USB, web server or some other method to your liking. Plug the SATA drive to the ESPRESSObin, power it on and check that the drive was recognized (here it is listed as /dev/sda):

root@localhost:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 1.8T 0 disk
mmcblk0 179:0 0 14.9G 0 disk


If needed, reformat the drive and create a new DOS disklabel:

root@localhost:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: E6C6F139-2646-47B9-81B2-A8CB539B3D14

Device Start End Sectors Size Type
/dev/sda1 2048 3907029134 3907027087 1.8T Microsoft basic data

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: E6C6F139-2646-47B9-81B2-A8CB539B3D14

Command (m for help): o
Created a new DOS disklabel with disk identifier 0xa5e90866.

Command (m for help): p
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa5e90866

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


Now write the image to the SATA drive using the dd tool:

root@localhost:~# dd if=flash-image-sata.bin of=/dev/sda conv=fdatasync
1413+1 records in
1413+1 records out
723920 bytes (724 kB, 707 KiB) copied, 0.472965 s, 1.5 MB/s


Once finished, power off the board and follow further steps to boot from the SATA drive.

Recovering SPI bootloader


As shown in SATA boot mode section, rearrange the onboard jumpers on the ESPRESSObin to SATA boot mode. Connect to the board via serial, power it on and you should see the new bootloader loaded. Now you can recover the SPI bootloader using a working SPI image, the bubt command and any of the methods covered in Update the Bootloader.

After the SPI bootloader image has been written, make sure to switch the onboard jumpers back to SPI boot:

J10J3J11
1-22-32-3


Power on the board. If all went well, your board should now boot from the onboard SPI.