SiFive HiFive Unleashed User manual

SiFive HiFive Unleashed Getting Started Guide
v1p2
© SiFive, Inc.

SiFive HiFive Unleashed Getting Started
Guide
Proprietary Notice
Copyright © 2018, SiFive Inc. All rights reserved.
Information in this document is provided “as is,” with all faults.
SiFive expressly disclaims all warranties, representations, and conditions of any kind, whether
express or implied, including, but not limited to, the implied warranties or conditions of mer-
chantability, fitness for a particular purpose and non-infringement.
SiFive does not assume any liability rising out of the application or use of any product or circuit,
and specifically disclaims any and all liability, including without limitation indirect, incidental, spe-
cial, exemplary, or consequential damages.
SiFive reserves the right to make changes without further notice to any products herein.
Release Information
Version Date Changes
v1p2 February 18, 2020 • Updated software development flow
v1p1 April 06, 2018
• Updated introduction
• Added component diagrams
• Added links to schematics and design files
• Added software development flow
v1p0 March 09, 2018 • Initial Release

Contents
1 Introduction .............................................................................................................. 3
1.1 HiFive Unleashed Components ....................................................................................3
1.2 HiFive Unleashed Schematics......................................................................................3
2Required Hardware ...............................................................................................4
3 Optional Hardware ................................................................................................5
4 Board Setup.............................................................................................................. 6
5 Boot and Run ......................................................................................................... 11
5.1 Connecting with ssh .................................................................................................. 11
5.2 Connecting with USB console ....................................................................................11
5.3 Knobs on the HiFive Unleashed .................................................................................12
5.4 HiFive Unleashed Boot..............................................................................................12
6 Firmware Update.................................................................................................. 14
7 Software Development Flow ..........................................................................15
7.1 Supported Platforms .................................................................................................15
7.2 Software Development with the Freedom Unleashed SDK............................................15
7.2.1 Install Prerequisite Packages ............................................................................15
7.2.2 Clone the freedom-u-sdk Repository ..................................................................16
7.2.3 Build the System ..............................................................................................16
7.2.4 Copy the System to an SD Card ........................................................................16
8 Connector Pinout.................................................................................................19
8.1 FMC Connector ........................................................................................................ 19
8.2 Low Speed I/O Expansion Connectors........................................................................23
8.3 MicroUSB Connector.................................................................................................24
1

Chapter 1
Introduction
HiFive Unleashed is a Linux development platform for SiFive’s Freedom U540 SoC, the world’s
first 4+1 64-bit multi-core Linux-capable RISC-V SoC. The HiFive Unleashed has 8GB DDR4,
32MB QuadSPI Flash, a Gigabit Ethernet port, and a MicroSD card slot for more external stor-
age. Additionally, the HiFive Unleashed supports adding new features, such as PCI Express
(PCIe), through the FMC connector and low-speed I/O expansion connectors.
1.1 HiFive Unleashed Components
1.2 HiFive Unleashed Schematics
Schematics and design files for HiFive Unleashed are available at:
https://www.sifive.com/products/hifive-unleashed
3

Chapter 2
Required Hardware
Using the HiFive Unleashed Development Kit requires the following hardware:
HiFive Unleashed Development Kit
SiFive’s HiFive Unleashed development kit is based around SiFive’s FU540-C000 SoC. It can
be purchased from Crowd Supply:
http://www.crowdsupply.com/sifive/hifive-unleashed
USB A to Micro-B Cable
Any standard USB Type A Male to Micro-B Male cable can be used to interface with the HiFive
Unleashed.
http://store.digilentinc.com/usb-a-to-micro-b-cable
12V DC Power Wall Adapter
The HiFive Unleashed Development Kit requires an external 12V, 2A power supply. When not
powering directly from the FMC expansion module, a 12V DC Wall Adapter with a 5.5 outer
diameter, 2.5 mm center-positive barrel plug, must be plugged into DC power jack on the HiFive
Unleashed. If powering directly from the FMC expansion module, then unplug the 12V DC
power wall adapter from the development kit. Power should not be supplied from 2 different
external sources.
4

Chapter 3
Optional Hardware
Ethernet Cable
HiFive Unleashed Development Kit has an RJ45 Ethernet port that enables the FU540-C000 to
connect to an 10/100/1000 Base-T network.
FMC Expansion Carrier Card
Additional functionality can be added to the HiFive Unleashed Development Kit through the
FMC connector. The FMC expansion carrier card typically has an FPGA to enable third-party
developers to add new logic to the development kit.
The HiFive Unleashed Development Kit can be directly powered from the FMC expansion car-
rier card. When powering from the FMC expansion carrier card, do not plug in the 12V DC
adapter into the HiFive Unleashed.
5

• Ensure the fan is plugged in.
• Set all pins in the DIP-switch block to the LEFT. The ON position=0; therefore, this sets
MSEL to mode 1111. See the boot modes table in next section for more information on
MSEL.
7

8

• Insert an SD-card programmed with bbl+linux. The github repository sifive/
freedom-u-sdk produces an image suitable for writing to a partition with GUID type
2E54B353-1271-4842-806F-E436D6AF6985.
• If available, connect the board to a network switch. The board will run DHCP on boot and
start an ssh server. The MAC address is 70:b3:d5:92:fX:XX, where X:XX is replaced by
the board number converted to hexadecimal. For example, if the board is H5U-00063, then
the last digits of the MAC address are 0:3f.
9

• If available, connect the board via USB to a developer machine. The USB connector has
two serial interfaces. The first contains the linux console running at 115200Hz. The second
provides JTAG suitable for use with openocd.
• Plug in the HiFive Unleashed; the fan should begin to spin.
• Turn on the HiFive Unleashed; after 30s a LED should begin to regularly blink a heartbeat.
10

Chapter 5
Boot and Run
Follow the steps from the previous section to power on the board. Once the heartbeat LED is
pulsing regularly, you can connect to the board.
There are two ways to connect to the HiFive Unleashed: ssh and serial. The serial interface is
slower and cannot receive files, so ssh is recommended.
5.1 Connecting with ssh
On power-on, the default freedom-u-sdk image obtains an IP address from DHCP and starts
an ssh server. The MAC address of the board is 70:b3:d5:92:fX:XX, where X:XX is replaced
by the board number converted to hexadecimal. Ask your network administrator which IP
address your board has obtained. Add the following to your .ssh/config, filling in the IP
address:
Host hifiveu
HostName xxx.yyy.zzz.aaa
User root
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
To connect, run ssh hifiveu. The password is sifive.
5.2 Connecting with USB console
With a USB cable connected to the HiFive Unleashed, you can access the console. The console
both shows the linux boot process and can be used to log in to the device.
From Mac OS, run: sudo screen /dev/tty.usbserial-*01 115200
From Linux, run: sudo screen /dev/serial/by-path/*-port0 115200
Hit enter a few times to see the login prompt. Username root, password sifive.
11

To quit screen, hit Control-a,\,y. If you do not quit properly, you can end up with multiple
screens running at the same time. This manifests as lost characters both sent and received.
5.3 Knobs on the HiFive Unleashed
SD cards formatted by the freedom-u-sdk contains a second partition which can be used for
persistent storage. You can access this storage by executing mount /dev/mmcblk0p2 /mnt.
However, the linux mmc_spi driver is extremely slow, so this should not be used for large files.
Report core frequency: echo $(cat /sys/devices/platform/soc/10000000.prci/rate)
5.4 HiFive Unleashed Boot
The Freedom U500 supports several boot methods. The general flow follows multiple stages:
1. ROM0 (0x1004): Decode MSEL and jump to the address found in 0x1100 +
8*MSEL. For MSEL > 4, the process proceeds to the next step.
2. ROM1 (0x1_0000): Decode MSEL to determine which media contains the First
Stage Boot Loader (FSBL). The media is expected to be formatted with a GPT parti-
tion table (even on SPI flash). The entire contents of the first partition with GUID
type 5B193300-FC78-40CD-8002-E86C45580B47 are downloaded into the L2 side-
band memory and execution transfers there. ROM1 contains a hard-coded DTB
block passed in a1 to the FSBL, which ignores it.
3. FSBL (0x800_0000): Initialize core PPLs, DDR, and Ethernet PHY. Decode MSEL
to determine which media contains the Berkeley Boot Loader (BBL). The media is
expected to contain a GPT-formatted partition table. The contents of the first parti-
tion with GUID type 2E54B353-1271-4842-806F-E436D6AF6985 are downloaded
into DDR memory and execution transfers there. The FSBL contains an embedded
DTB describing both the Freedom U500 SoC and HiFive Unleashed board. The
DTB is updated with the board MAC address and DDR capacity and passed to BBL
in a1.
4. BBL (0x8000_0000): Initialize the RISC-V supervisor binary interface (SBI). Jump to
the embedded linux kernel payload, passing a redacted DTB in a1.
5. Linux (0xffff_ffe0_0000_0000): Initializes all devices, starts DHCP + ssh.
12

Both ROM1 and the FSBL find the next boot loader stage based on the MSEL setting. All possi-
ble values are enumerated below. The three SPI interfaces on the Freedom U500 SoC can be
used to download media either from SPI flash (using x4 data pins or x1) or an SD card, using
the SPI protocol. ROM1 downloads the FSBL at 10MHz, while the FSBL uses 50MHz for SPI
and 20MHz for SD.
MSEL FSBL BBL Purpose
0000 - - loops forever waiting for debugger
0001 - - jump directly to 0x2000_0000 (memory-mapped SPI0)
0010 - - jump directly to 0x3000_0000 (memory-mapped SPI1)
0011 - - jump directly to 0x4000_0000 (uncached ChipLink)
0100 - - jump directly to 0x6000_0000 (cached ChipLink)
0101 SPI0 x1 SPI0 x1 -
0110 SPI0 x4 SPI0 x4 Rescue image from flash (preprogrammed)
0111 SPI1 x4 SPI1 x4 -
1000 SPI1 SD SPI1 SD -
1001 SPI2 x1 SPI2 x1 -
1010 SPI0 x4 SPI1 SD -
1011 SPI2 SD SPI2 SD Rescue image from SD card
1100 SPI1 x1 SPI2 SD -
1101 SPI1 x4 SPI2 SD -
1110 SPI0 x1 SPI2 SD -
1111 SPI0 x4 SPI2 SD Default boot mode
Table 1: MSEL Boot Mode Straps
13

Chapter 6
Firmware Update
As new features are added, the HiFive Unleashed may receive periodic updates. These updates
can include changes to the First Stage Boot Loader (FSBL), the Device Tree Blob (DTB), the
recovery Linux kernel, or the default user kernel. To keep things simple, all of these are updated
in lock-step. The newest firmware can always be found on the SiFive website.
Firmware updates for the HiFive Unleashed consist of two files:
1. hifive-unleashed-a00-A.B-YYYY-MM-DD.gpt, an image which should be written
to the flash chip. This contains the FSBL, DTB, and recovery kernel.
2. hifive-unleashed-a00-A.B-YYYY-MM-DD.bin, an image which may optionally be
written to the SD card. This contains the default user kernel.
To upgrade, follow these steps:
1. Switch the MSEL DIP switches to 0110
2. Power-on the board
3. Copy the two files to the board with scp
4. Execute: flashcp -v hifive-unleashed-a00-A.B-YYYY-MM-DD.gpt /dev/mtd0
to upgrade the contents of the flash.
5. Optional: cat hifive-unleashed-a00-A.B-YYYY-MM-DD.bin > /dev/
mmcblk0p1; sync to upgrade the contents of the SD card. This may be necessary if
the DTB is changed in a manner incompatible with older kernels. However, this step
will also destroy any customizations the user has made to the kernel.
6. Restore the MSEL DIP switches to 1111
14

Chapter 7
Software Development Flow
This document, as well as the binaries shipped with the HiFive Unleashed (and available on the
SiFive website), concern an older, Buildroot-based version of freedom-u-sdk, which lives on
the v1_0 branch. This Buildroot version will be deprecated in the future.
A new, OpenEmbedded-based version of freedom-u-sdk is available at:
http://github.com/sifive/freedom-u-sdk (default branch)
To try the OpenEmbedded version, visit the freedom-u-sdk GitHub repo for instructions on
building a disk image, installing it on a SD card, and booting it on your HiFive Unleashed. Note
that some details in Chapters 4, 5, 6, and 7 of this document are specific to the Buildroot ver-
sion.
7.1 Supported Platforms
This document assumes you are running on a modern Linux system. It has been tested on
"bare metal" Linux systems and Linux systems running as a virtual machine. The process docu-
mented here was tested using Ubuntu 16.04.4, and this operating system is the only version
which is guaranteed to run with the Buildroot-based version.
7.2 Software Development with the Freedom Unleashed
SDK
7.2.1 Install Prerequisite Packages
Before starting, use the apt-get the command to install prerequisite packages:
sudo apt-get install autoconf automake autotools-dev bc bison \
build-essential curl flex gawk gdisk git gperf libgmp-dev \
libmpc-dev libmpfr-dev libncurses-dev libssl-dev libtool \
15

patchutils python screen texinfo unzip zlib1g-dev
7.2.2 Clone the freedom-u-sdk Repository
After installing the prerequisite packages, clone and initialize the freedom-u-sdk with these
commands:
git clone https://github.com/sifive/freedom-u-sdk.git
cd freedom-u-sdk
git checkout v1_0
git submodule update --init --recursive
Note: this command can take up to thirty minutes or one hour to complete.
7.2.3 Build the System
Once the repository has been cloned and its sub-modules initialized, you are ready to build the
system. Simply issue a make command from the freedom-u-sdk directory:
unset RISCV
make
Note: this command can take several hours on a fast machine.
7.2.4 Copy the System to an SD Card
Assuming all prerequisite packages were installed and the freedom-u-sdk repository’s sub-
modules were successfully initialized, the make command from the previous step should com-
plete with a message describing how to copy the boot image to an SD card.
Before executing this command, you will need to know the device name of your SD card. You
will also need to delete Master Boot Record (MBR) partitions from the SD card and create a
GUID Partition Table with no partitions defined.
Under current revisions of Ubuntu Linux, it is not uncommon for SD cards to be auto-mounted
upon insertion if they contain a valid partition table and file system. You may use the mount
command to determine if this is the case. They should be unmounted before proceeding.
For example purposes, we will assume the device name of your SD card is /dev/exb. (This is
almost certainly not the name of an actual device; you will need to substitute the name of your
actual SD card device for /dev/exb in the commands which follow.)
If your SD card was auto-mounted when you inserted it, you can likely find the device name by
running the mount command. You may also find the name of the device by running the dmesg
command and looking for log entries with the word "mounted".
If this is the first time you have installed a freedom-u-sdk image onto an SD card, it likely still
has a legacy partition table in the Master Boot Record. Before proceeding, you must delete par-
16

titions in the legacy partition table and create a new GUID Partition Table (GPT). You only need
to do this once, so if you have done this before, you should skip this step.
The transcript below shows the user using the gdisk program to delete partitions defined in the
MBR partition table and creating a GPT (GUID Partition Table). Bolded text is user input. Before
proceeding to the next step, ensure that you have followed a similar procedure. The next step
will fail if an existing MBR partition table remains on the SD card.
$sudo gdisk /dev/exb
GPT fdisk (gdisk) version 1.0.1
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
Warning! Secondary partition table overlaps the last partition by
33 blocks!
You will need to delete this partition or resize it in another utility.
Command (? for help): p
Disk /dev/exb: 61440 sectors, 30.0 MiB
Logical sector size: 512 bytes
Disk identifier (GUID): E2725DE1-5C7D-47A4-AADB-1C87907A1E50
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 61406
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 10239 4.0 MiB 8300 Linux filesystem
2 10240 61439 25.0 MiB 8300 Linux filesystem
Command (? for help): d
Partition number (1-2): 2
Command (? for help): d
Using 1
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y
Command (? for help): p
Disk /dev/exb: 61440 sectors, 30.0 MiB
Logical sector size: 512 bytes
Disk identifier (GUID): E1CE61B3-E5AD-422D-8974-A612BBEC9DE1
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 61406
Partitions will be aligned on 2048-sector boundaries
17

Total free space is 61373 sectors (30.0 MiB)
Number Start (sector) End (sector) Size Code Name
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/exb.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
$
Once the MBR partition table and it’s partitions have been deleted, you can continue with the
process of writing the system to the SD card:
sudo make DISK=/dev/exb format-boot-loader
This command is known to fail with slower USB SD card devices. It should succeed if repeated.
The SD card should now contain a bootable linux image. Refer to previous chapters for instruc-
tions in how to boot your HiFive Unleashed board.
If you encounter difficulties while following this procedure, please visit the SiFive Developer
Forums ( https://forums.sifive.com/ ). Other users may have encountered similar problems and
posted usable solutions.
18
Table of contents
Other SiFive Motherboard manuals