<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello Arnout<br>
    <br>
    <div class="moz-cite-prefix">On 14/04/2019 19:55, Arnout
      Vandecappelle wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

On 14/04/2019 15:43, Mark Corbin wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">This patch adds support for the SiFive HiFive Unleashed board and
generates a system that attempts to closely match the output
produced by the Freedom Unleashed Software Development Kit
(sifive/freedom-u-sdk repository) release v1_0.

The kernel patch has been generated from the Linux 4.19 tree of
the sifive/riscv-linux repository (commit id
20eeb6522e3302c5f6e435c0bdba40ff57ffa41a).

Signed-off-by: Mark Corbin <a class="moz-txt-link-rfc2396E" href="mailto:mark.corbin@embecosm.com"><mark.corbin@embecosm.com></a>
---
 ...es-for-SiFive-HiFive-Unleashed-board.patch | 3704 +++++++++++++++++
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 Yikes. Why not just download the tarball from github, like we do for so many
other boards? E.g. imx8mpico does that as well.</pre>
    </blockquote>
    <br>
    I can either set up a github repository for my patched 4.20 kernel
    or I can use an existing 4.19 repository (see comments later in this
    email). Either way I will remove the patch.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">diff --git a/board/sifive/u540-unleashed/linux.config.fragment b/board/sifive/u540-unleashed/linux.config.fragment
new file mode 100644
index 0000000000..c73a3d3cc3
--- /dev/null
+++ b/board/sifive/u540-unleashed/linux.config.fragment
@@ -0,0 +1,652 @@
+CONFIG_AFS_FS=m
+CONFIG_AF_RXRPC=m
+CONFIG_AUTOFS4_FS=m
+CONFIG_AUTOFS_FS=m
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 If you're going to give a config fragment, make it a minimal fragment. There is
something to be said for turning off drivers that you don't need, maybe, but
definitely don't go and enable random filesystems etc.

[snip]
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+CONFIG_EXTRA_FIRMWARE="radeon/BTC_rlc.bin radeon/CAICOS_mc.bin radeon/CAICOS_me.bin radeon/CAICOS_pfp.bin radeon/CAICOS_smc.bin radeon/SUMO_uvd.bin"
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 This might be a relevant one, but do we really need all of them?</pre>
    </blockquote>
    <br>
    I used the config from the existing freedom-u-sdk as a template, so
    I ended up with all the features that were enabled in that version.
    I will generate a minimal config fragment.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">


</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+CONFIG_HZ=100
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 Huh? This is a blind option, how does it even end up in a config fragment?</pre>
    </blockquote>
    <br>
    I'll take a look at that.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+CONFIG_SERIAL_SIFIVE=y
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 This might be one you want to keep, and maybe a few others as well...

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">diff --git a/board/sifive/u540-unleashed/post-image.sh b/board/sifive/u540-unleashed/post-image.sh
new file mode 100755
index 0000000000..c8e5682626
--- /dev/null
+++ b/board/sifive/u540-unleashed/post-image.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+# When using a CPIO initramfs image as part of the kernel we
+# need to rebuild the riscv-pk (bbl) bootloader again after the
+# kernel has been rebuilt with the rootfs image.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 Yes that's annoying. But why do we use a linked-in cpio, and not the usual ext4
on SD card?</pre>
    </blockquote>
    <br>
    I was trying to keep things close to the existing freedom-u-sdk as I
    thought that it would be friendlier for existing developers/board
    users. I don't have a problem with using a separate ext4 partition
    on the SD card for the rootfs.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+
+make riscv-pk-rebuild
+
+exit $?
diff --git a/board/sifive/u540-unleashed/readme.txt b/board/sifive/u540-unleashed/readme.txt
new file mode 100644
index 0000000000..3b2f42ca91
--- /dev/null
+++ b/board/sifive/u540-unleashed/readme.txt
@@ -0,0 +1,91 @@
+SiFive HiFive Unleashed
+=======================
+
+This file describes how to use the pre-defined Buildroot
+configuration for the SiFive HiFive Unleashed board.
+
+Further information about the HiFive Unleashed board can be found
+at <a class="moz-txt-link-freetext" href="https://www.sifive.com/boards/hifive-unleashed">https://www.sifive.com/boards/hifive-unleashed</a>
+
+Introduction
+============
+
+The default board configuration (and these instructions) have
+been created to match the system produced by the Freedom Unleashed
+Software Development Kit as closely as possible. This is based on
+the freedom-u-sdk v1_0 release that can be found at
+https://github.com/sifive/freedom-u-sdk/tree/v1_0
+
+Building
+========
+
+Configure Buildroot using the default board configuration:
+
+  $ make sifive_u540_unleashed_defconfig
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 Why is it u540 instead of hifive?</pre>
    </blockquote>
    <br>
    I was trying to relate it to a more specific hardware architecture
    (in this case the Freedom U540 processor) rather than just the
    'HiFive' product name.  I guess that this will only really be
    necessary when/if there are other boards in the 'HiFive Unleashed'
    series. I can change it to 'sifive_hifive_unleashed_defconfig' for
    now and update it as necessary in the future.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+
+Customise the build as necessary:
+
+  $ make menuconfig
+
+Start the build:
+
+  $ make
+
+Result of the build
+===================
+
+Once the build has finished you will have the following files:
+
+    output/images/
+    +-- bbl
+    +-- bbl.bin
+    +-- rootfs.cpio
+    +-- rootfs.cpio.gz
+    +-- rootfs.tar
+    +-- vmlinux
+    
+
+Creating a bootable SD card
+===========================
+
+At the current time the genimage utility (v10) used by Buildroot
+does not support GPT partitions which are required by the HiFive
+Unleashed FSBL. This means that a bootable SD card must be created
+manually using the instructions below.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 You can still do that from a post-image script. Cfr. pc_x86_64_efi_defconfig
and board/pc/post-image-efi-gpt.sh.</pre>
    </blockquote>
    <br>
    That looks like a better idea. I'll update the scripts to produce an
    sdcard.img file.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+
+Create the partitions on the SD card:
+
+  $ sudo sgdisk --clear \
+        --new=1:2048:67583  \
+        --change-name=1:bootloader \
+        --typecode=1:2E54B353-1271-4842-806F-E436D6AF6985 \
+        --new=2:264192: \
+        --change-name=2:root \
+        --typecode=2:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \
+        /dev/mmcblk0
+
+The first partition will contain the kernel and the combined rootfs
+ram disk image (bbl.bin). The second partition is just an empty
+Linux filesystem that can be used to expand or replace the initramfs
+image in the kernel.
+
+Copy the kernel and combined rootfs image to the SD card:
+
+  $ sudo dd if=output/images/bbl.bin of=/dev/mmcblk0p1 bs=4096
+
+Create an empty ext3 filesystem on the second partition:
+
+  $ sudo mkfs.ext3 /dev/mmcblk0p2
+
+Make sure that the all DIP switches are set to the off position for
+default boot mode (MSEL mode = 1111), insert the SD card and power
+up the board.
+
+Connect the USB cable and open minicom (/dev/ttyUSB1, 115200, 8N1).
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 How do you know it is ttyUSB1? It is usually USB0...</pre>
    </blockquote>
    <br>
    There are two USB serial devices on the board - the console always
    seems to be on USB1 on my board. I can be more cautious and say
    '/dev/ttyUSBx' instead.<br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+
+See the 'SiFive HiFive Unleashed Getting Started Guide' for
+more details (<a class="moz-txt-link-freetext" href="https://www.sifive.com/documentation">https://www.sifive.com/documentation</a>).
+
+--
+
+Mark Corbin <a class="moz-txt-link-rfc2396E" href="mailto:mark.corbin@embecosm.com"><mark.corbin@embecosm.com></a> April 2019
diff --git a/configs/sifive_u540_unleashed_defconfig b/configs/sifive_u540_unleashed_defconfig
new file mode 100644
index 0000000000..b56ae1b164
--- /dev/null
+++ b/configs/sifive_u540_unleashed_defconfig
@@ -0,0 +1,29 @@
+# Architecture
+BR2_riscv=y
+BR2_RISCV_64=y
+
+# Patches
+BR2_GLOBAL_PATCH_DIR="board/sifive/patches"
+
+# Linux headers same as kernel, a 4.20 series
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_20=y
+
+# System
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/sifive/u540-unleashed/post-image.sh"
+
+# Kernel
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.20.17"
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 Oh, now I see, you're porting the changes done by sifive from 4.19 to 4.20...
Is that also what the freedom-u-sdk does? I don't think so...</pre>
    </blockquote>
    <br>
    I'm not sure that the freedom-u-sdk has moved to 4.19 yet (the v1_0
    release uses 4.15), but there is a patched 4.19 kernel tree
    available in the master branch. I've generated a patch for 4.20.17
    based on this patched 4.19 tree. I wanted to move to the most recent
    version of the 4.20 kernel that Buildroot supported, but I guess
    that I could also just look at using the patched 4.19 branch that
    already exists.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
+BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="board/sifive/u540-unleashed/linux.config.fragment"
+BR2_LINUX_KERNEL_VMLINUX=y
+#BR2_LINUX_KERNEL_IMAGE=y
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 Don't leave commented-out things in there.</pre>
    </blockquote>
    <br>
    Ok.<br>
    <br>
    <blockquote type="cite"
      cite="mid:7261729c-385b-8dd1-e969-72f95c9ac0be@mind.be">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">+
+# Bootloader
+BR2_TARGET_RISCV_PK=y
+
+# Filesystem
+BR2_TARGET_ROOTFS_CPIO=y
+BR2_TARGET_ROOTFS_CPIO_GZIP=y
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
 It doesn't make sense to compress the cpio, because it's the uncompressed one
that gets linked into the kernel.

 And setting ROOTFS_CPIO explicitly is not needed, it's selected by INITRAMFS.</pre>
    </blockquote>
    <br>
    I think that it probably makes sense to move to a separate rootfs.<br>
    <br>
    Thanks for the feedback.<br>
    <br>
    Mark<br>
    -- <br>
    <div class="moz-signature"><br>
      <b>Mark Corbin</b><br>
      Embedded Operating Systems Lead<br>
      <br>
      Embecosm Ltd.<br>
      Palamos House #208, 66/67 High Street, Lymington, SO41
      9AL, UK<br>
      Phone: +44 1590 610184     Mobile: +44 7765 703479<br>
      Email: <a href="mailto:mark.corbin@embecosm.com">mark.corbin@embecosm.com</a>     Web:
      <a href="https://www.embecosm.com">https://www.embecosm.com<br>
      </a>
      <br>
      Company No. 6577021 (England & Wales).<br>
      --</div>
  </body>
</html>