# Fedora-Developer-Rawhide-20220705.n.0 (SiFive HiFive Unmatched, Rev 3A0 and 3B0)

Fedora Developer Rawhide (F33) release for SiFive HiFive Unmatched development boards. Both revision 3A0 (very rare) and 3B0 (general availability board; you most likely have this) supported.

This image was produced on July 5th, 2022.

All the images were compressed with `--block-size=16777216` options passed to `xz` and should work with NBD setup.

## Images

The following images are available for download:

- `Fedora-Developer-Rawhide-20220705.n.0-mmc-firmware.raw.img.xz` - firmware (U-Boot SPL and U-Boot proper with OpenSBI in M-mode) for MMC/microSD card.

- `Fedora-Developer-Rawhide-20220705.n.0-spi-nor-firmware.raw.img.xz` - firmware (U-Boot SPL, U-Boot proper with OpenSBI in M-mode and U-Boot environment partition) for SPI-NOR Flash.

- `Fedora-Developer-Rawhide-20220705.n.0-mmc.raw.img.xz` - all-in-one images for MMC/microSD card. This includes the firmware, `/boot` and `/` (root) partition. This is very common way to run, but has a high impact on IO performance.

- `Fedora-Developer-Rawhide-20220705.n.0-nvme.raw.img.xz` - contains only `/boot` and `/` (root) partition for M.2 NVMe storage. The firmware must be in MMC/microSD or SPI-NOR Flash (based on `BOOTSEL` value).

## Suggested Configuration After Booted

### Temperature Sensors

Create a file `/etc/sensors.d/unmatched.conf` with:

```
chip "tmp451-*"

  label temp1 "M/B Temp"
  label temp2 "CPU Temp"
```

Now command `sensors` will show:

```
[..]
tmp451-i2c-0-4c
Adapter: i2c-ocores
M/B Temp:     +30.1°C  (low  =  +0.0°C, high = +85.0°C)
                       (crit = +85.0°C, hyst = +75.0°C)
CPU Temp:     +36.9°C  (low  =  +0.0°C, high = +85.0°C)
                       (crit = +85.0°C, hyst = +75.0°C)
```

### Load Additional Kernel Modules

Not all kernel modules are loaded as the boot. Create file `/etc/modules-load.d/unmatched.conf` with:

```
# Load SPI-NOR block device driver
mtdblock

# Load DA9063 WDT driver
da9063_wdt

# LED triggers
ledtrig-default-on
ledtrig-heartbeat
```

`mtdblock` allows presenting flash memroy as a block device and thus allows using `dd` to flash a new firmware to SPI-NOR Flash. `da9063_wdt` is Watchdog timer for DA9063 PMIC. Based on DA9063 OTP configuration WDT can only shutdown SiFive HiFive Unmatched, but not reset it. `ledtrig-default-on` and `ledtrig-heartbeat` are LED triggers that you can use for D12 and D2 LEDs.

### Configure D12 (green) LED for heartbeat trigger

It's very useful to have a heartbeat LED and advice would be to use D12 (green) LED for that. Create a file `/etc/udev/rules.d/99-pwm-leds.rules` with:

```
# D12 LED: heartbeat
SUBSYSTEM=="leds", KERNEL=="green:d12", ACTION=="add", ATTR{trigger}="heartbeat"
```

You can also do that via sysfs under `/sys/devices/platform/pwmleds/leds/green:d12` directory by executing `echo heartbeat > trigger` . If you `cat trigger` it will show all possible triggers and which one is currently selected.

### Install Watchdog Package

You can use WDT manually (`wdctl` and use `/dev/watchdog0` device), but you can also use `watchdog` package to set it up.

Install the package:

```
dnf install http://fedora.riscv.rocks/kojifiles/packages/watchdog/5.15/8.fc33/riscv64/watchdog-5.15-8.fc33.riscv64.rpm
```

Modify the configuration file `/etc/watchdog.conf` and uncomment `watchdog-device = /dev/watchdog` line.

Now enable the service files:

```
systemctl enable --now watchdog.service
```

### Load Firmware to SPI-NOR Flash

If `mtdblock` driver is loaded you can simply use `dd` command to write a new firmware blob into SPI-NOR Flash:

```
sudo dd of=/dev/mtdblock0 if=./Fedora-Developer-Rawhide-20220705.n.0-spi-nor-firmware.raw.img bs=1K iflag=fullblock oflag=direct conv=fsync status=progress
```

Note that by default (i.e. out of the factory) SPI-NOR Flash is empty.

### Use Firmware From SPI-NOR Flash (BOOTSEL/MSEL)

By default configuration on your board is to boot from MMC/microSD and the configuration looks like this:

```
  +----------> CHIPIDSEL
  | +--------> MSEL3
  | | +------> MSEL2
  | | | +----> MSEL1
  | | | | +--> MSEL0
  | | | | |
 +-+-+-+-+-+
 | |X| |X|X| ON(1)
 | | | | | |
 |X| |X| | | OFF(0)
 +-+-+-+-+-+
BOOT MODE SEL
```

To switch it to SPI-NOR set it to:

```
  +----------> CHIPIDSEL
  | +--------> MSEL3
  | | +------> MSEL2
  | | | +----> MSEL1
  | | | | +--> MSEL0
  | | | | |
 +-+-+-+-+-+
 | | |X|X| | ON(1)
 | | | | | |
 |X|X| | |X| OFF(0)
 +-+-+-+-+-+
BOOT MODE SEL
```

You can find more information about this in FU740 and SiFive HiFive Unmatched documentation on SiFive website.
