1#!/bin/bash 2# 3# Creates a "firmware SD Card" with u-boot for the SiFive Unmatched board 4# based on https://u-boot.readthedocs.io/en/latest/board/sifive/unmatched.html 5# 6 7if [[ $# -ne 1 ]]; then 8 echo "Usage: $0 /dev/sdX" 9 echo "WARNING: Everything on target block device will be erased!" 10 exit 1 11fi 12 13if [[ $(whoami) != "root" ]]; then 14 echo "Run me as root! sudo $0" 15 exit 1 16fi 17 18DEVICE=$1 19URI_BASE="https://raw.githubusercontent.com/haiku/firmware/master/u-boot/riscv64/unmatched" 20 21echo "Unmounting SD Card at $DEVICE..." 22umount -q $DEVICE* 23 24echo "Setting up SD Card at $DEVICE..." 25sgdisk -g --clear -a 1 \ 26 --new=1:34:2081 --change-name=1:spl --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \ 27 --new=2:2082:10273 --change-name=2:uboot --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \ 28 $DEVICE 29 30echo "Writing u-boot to $DEVICE..." 31curl -s $URI_BASE/u-boot-spl.bin --output - | dd of=$DEVICE seek=34 32curl -s $URI_BASE/u-boot.itb --output - | dd of=$DEVICE seek=2082 33 34echo "Complete! Here are the next steps:" 35echo " 1) Plug the SD Card into the Unmatched board" 36echo " 2) Write haiku-mmc.image to a USB drive" 37echo " 3) Plug the USB drive into the Unmatched" 38echo "Enjoy Haiku!" 39