Installing Debian On SiFiveHiFiveUnmatched

 

ubuntu@ubuntu:~/linux-5.14$ ls ./arch/riscv/boot/dts/sifive/
fu540-c000.dtsi  hifive-unleashed-a00.dtb  hifive-unmatched-a00.dtb  Makefile
fu740-c000.dtsi  hifive-unleashed-a00.dts  hifive-unmatched-a00.dts
ubuntu@ubuntu:~/linux-5.14$ 

 

 

cat hifive-unleashed-a00.dts
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/* Copyright (c) 2018-2019 SiFive, Inc */

#include "fu540-c000.dtsi"
#include <dt-bindings/gpio/gpio.h>

 

cat hifive-unmatched-a00.dts
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/* Copyright (c) 2020 SiFive, Inc */

#include "fu740-c000.dtsi"

 

Important Note

 

 

Debian on the ?HiFive Unmatched is very new. There are no official images available yet.

You could find some experimental images in (signed with ?Deiv's key):

This images are built with the same instructions in the next section. You just need to decompress them and burn to sd-card.

 

Installing Debian on HiFive

The easiest way at present to run Debian binaries on a ?HiFive is to generate an sdcard image with all the Debian stock parts.

 

Preparing disk image

 

# create image file
dd if=/dev/zero of=debian-sid-risc-v-sifive-unmatched.img bs=1M count=4096

# Partition image with correct disk IDs
sudo sgdisk -g --clear --set-alignment=1 \
       --new=1:34:+1M:    --change-name=1:'u-boot-spl'    --typecode=1:5b193300-fc78-40cd-8002-e86c45580b47 \
       --new=2:2082:+4M:  --change-name=2:'opensbi-uboot' --typecode=2:2e54b353-1271-4842-806f-e436d6af6985 \
       --new=3:16384:+130M:   --change-name=3:'boot'      --typecode=3:0x0700  --attributes=3:set:2  \
       --new=4:286720:-0   --change-name=4:'rootfs'       --typecode=4:0x8300 \
       debian-sid-risc-v-sifive-unmatched.img
       
# Mount image in loop device
sudo losetup --partscan --find --show debian-sid-risc-v-sifive-unmatched.img

# format partitions
sudo mkfs.vfat /dev/loop0p3
sudo mkfs.ext4 /dev/loop0p4
sudo e2label /dev/loop0p3 boot
sudo e2label /dev/loop0p4 rootfs

 

Installing debian sid+riscv-port on image

 

# mount root partition
sudo mount /dev/loop0p4 /mnt

# install base files
sudo apt-get install debootstrap qemu-user-static binfmt-support debian-ports-archive-keyring
sudo debootstrap --arch=riscv64 --keyring /usr/share/keyrings/debian-ports-archive-keyring.gpg --include=debian-ports-archive-keyring unstable /mnt http://deb.debian.org/debian-ports

# mount boot partition
sudo mount /dev/loop0p3 /mnt/boot

# chroot into base filesystem and made basic configuration
sudo chroot /mnt

Inside created chroot:

 

# Update package information
apt-get update

# Set up basic networking
cat >>/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
EOF

# Set root password 'sifive'
passwd

# Change hostname
echo unmatched > /etc/hostname

# Set up fstab
cat > /etc/fstab <<EOF
# <file system> <mount point>   <type>  <options>       <dump>  <pass>

/dev/mmcblk0p4 /               ext4    errors=remount-ro 0       1
/dev/mmcblk0p3 /boot           vfat    nodev,noexec,ro   0       2
EOF

# Install kernel and bootloader infrastructure
apt-get install linux-image-riscv64 u-boot-menu u-boot-sifive
apt-get clean

# add needed modules in initrd
echo mmc_spi >>/etc/initramfs-tools/modules 
#update-initramfs -u (TODO: add more space in boot)
rm /boot/initrd*
update-initramfs -c -k all

# Set up u-boot (TODO: better integration for kernel updates)
cp /usr/lib/linux-image-5.14.0-3-riscv64/sifive/hifive-unmatched-a00.dtb /boot/
echo U_BOOT_FDT=\"hifive-unmatched-a00.dtb\" >> /etc/default/u-boot
echo U_BOOT_PARAMETERS=\"rw rootwait console=ttySIF0,115200 earlycon\" >> /etc/default/u-boot
u-boot-update

# Install ssh server and ntp
apt-get install openssh-server openntpd ntpdate
apt-get clean

# set the time immediately at startup
sed -i 's/^DAEMON_OPTS="/DAEMON_OPTS="-s /' /etc/default/openntpd

# exit chroot
exit

Once out of chroot:

 

sudo rm /mnt/root/.bash_history

 

Setup bootloaders

 

sudo dd if=/mnt/usr/lib/u-boot/sifive_unmatched/u-boot-spl.bin of=/dev/loop0p1 bs=4k iflag=fullblock oflag=direct conv=fsync status=progress
sudo dd if=/mnt/usr/lib/u-boot/sifive_unmatched/u-boot.itb of=/dev/loop0p2 bs=4k iflag=fullblock oflag=direct conv=fsync status=progress

 

Finish and write image to sdcard

 

sudo umount /mnt/boot
sudo umount /mnt

sudo losetup -d /dev/loop0

# take care of writing to the correct sdcard-device
sudo dd if=debian-sid-risc-v-sifive-unmatched.img of=/dev/sdcard-device bs=64k iflag=fullblock oflag=direct conv=fsync status=progress


How to install Ubuntu on RISC-V HiFive boards

 

posted on 2022-03-21 20:23  tycoon3  阅读(92)  评论(0)    收藏  举报

导航