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