Page MenuHomeFreeBSD

sysutils/opensbi: update to version v1.0
ClosedPublic

Authored by mhorne on Jan 11 2022, 2:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 8, 1:18 PM
Unknown Object (File)
Wed, Nov 6, 5:09 PM
Unknown Object (File)
Tue, Nov 5, 4:33 AM
Unknown Object (File)
Thu, Oct 31, 3:43 PM
Unknown Object (File)
Thu, Oct 31, 3:39 PM
Unknown Object (File)
Thu, Oct 17, 5:04 PM
Unknown Object (File)
Thu, Oct 17, 5:04 PM
Unknown Object (File)
Thu, Oct 17, 5:04 PM

Details

Summary

As the fu540 platform has been removed with this version, fallback to
building the generic platform only. Keep the platform logic around in
the Makefile in case we need it in the future.

Bump the PORTREVISION for sysutils/u-boot-sifive-fu540.

Test Plan

Build + testport in poudriere.

I will test booting in QEMU.

Diff Detail

Repository
R11 FreeBSD ports repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

@maciphone2_googlemail.com please test this update on your Unleashed board when possible, to ensure the workaround still works correctly.

It'd be nice to get the fu540 workaround upstream, which they'd probably want done via a field in sbi_platform (maybe a u64 errata/quirks to go next to u64 features?) rather than this ad-hoc global. Surely Linux is also affected?..

Changes make sense to me; I had also thought about what to do wrt the list of platforms in the past and came to the same conclusion

This revision is now accepted and ready to land.Jan 11 2022, 2:36 PM
sysutils/opensbi/Makefile
10–11

Oh, these can now go, you can build with Clang just fine now. Everything should auto-detect just fine.

sysutils/opensbi/Makefile
10–11

Oh I think you may need CC=clang though, it'll default to $(CROSS_COMPILE)gcc. LLVM=1 also ends up forcing llvm-ar and llvm-objcopy, and I think we have llvm-ar in 13 but not llvm-objcopy by default.

It'd be nice to get the fu540 workaround upstream, which they'd probably want done via a field in sbi_platform (maybe a u64 errata/quirks to go next to u64 features?) rather than this ad-hoc global. Surely Linux is also affected?..

The real solution is to fix how we construct the direct map, which is done only with 1G pages currently (thus overlapping the PMP protected region). I will have some time to work on this in the coming weeks.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252891

sysutils/opensbi/Makefile
10–11

Oh right, I will try this, thanks.

sysutils/opensbi/Makefile
10–11

Just make sure to also drop CROSS_COMPILE otherwise you'll end up with triple-prefixed ar/ld/objcopy

It'd be nice to get the fu540 workaround upstream, which they'd probably want done via a field in sbi_platform (maybe a u64 errata/quirks to go next to u64 features?) rather than this ad-hoc global. Surely Linux is also affected?..

The real solution is to fix how we construct the direct map, which is done only with 1G pages currently (thus overlapping the PMP protected region). I will have some time to work on this in the coming weeks.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252891

That's not really a FreeBSD bug though? It's legal to do... but if you wanted to I guess you could detect the FU540 and change how the DMAP is constructed. Would prefer firmware hides errata that it can, though. It's not like the PMP is actually doing much useful, there's no IOMMU/IOPMP to stop DMA interfering with M-mode on any of the SiFive cores.

It'd be nice to get the fu540 workaround upstream, which they'd probably want done via a field in sbi_platform (maybe a u64 errata/quirks to go next to u64 features?) rather than this ad-hoc global. Surely Linux is also affected?..

The real solution is to fix how we construct the direct map, which is done only with 1G pages currently (thus overlapping the PMP protected region). I will have some time to work on this in the coming weeks.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252891

That's not really a FreeBSD bug though? It's legal to do... but if you wanted to I guess you could detect the FU540 and change how the DMAP is constructed. Would prefer firmware hides errata that it can, though. It's not like the PMP is actually doing much useful, there's no IOMMU/IOPMP to stop DMA interfering with M-mode on any of the SiFive cores.

Typically yes, it is totally legal to map the fw reserved memory region. For the fu540 specifically, OpenSBI will give the region the 'nomap' property in the device tree, expecting the OS to respect this (and Linux does). Since we construct the direct map so naively, we do not honor the nomap request, thus triggering the errata.

It'd be nice to get the fu540 workaround upstream, which they'd probably want done via a field in sbi_platform (maybe a u64 errata/quirks to go next to u64 features?) rather than this ad-hoc global. Surely Linux is also affected?..

The real solution is to fix how we construct the direct map, which is done only with 1G pages currently (thus overlapping the PMP protected region). I will have some time to work on this in the coming weeks.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252891

That's not really a FreeBSD bug though? It's legal to do... but if you wanted to I guess you could detect the FU540 and change how the DMAP is constructed. Would prefer firmware hides errata that it can, though. It's not like the PMP is actually doing much useful, there's no IOMMU/IOPMP to stop DMA interfering with M-mode on any of the SiFive cores.

Typically yes, it is totally legal to map the fw reserved memory region. For the fu540 specifically, OpenSBI will give the region the 'nomap' property in the device tree, expecting the OS to respect this (and Linux does). Since we construct the direct map so naively, we do not honor the nomap request, thus triggering the errata.

I see. Blegh, that's kind of a gross way to do it, but I guess we have to... :(

@maciphone2_googlemail.com please test this update on your Unleashed board when possible, to ensure the workaround still works correctly.

O.K, I'll take a closer look and test it tonight or tomorrow.
I remember hacking u-boot for overclocking a few weeks or months ago, because overclocking 1GhZ-> 1.4Ghz was only possible directly in u-boot(not from system`s dtb) because of this errata, otherwise the machine would crash beforehand ...
thanks

Is it possible to upstream those local patches?

booting into the same pxe-server from the old u-boot(before patch) succeeded while with this patch 1st attempt failed... I will later test again (revert this patch) to ensure that I didn`t something wrong with ports/u-boot(boot parameters) etc.- ... it was patched from a newly and untouched cloned ports-tree from today ...

root@freebsd:/usr/ports # patch < D33845.patch
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/opensbi/Makefile
|===================================================================
|--- sysutils/opensbi/Makefile
|+++ sysutils/opensbi/Makefile
--------------------------
Patching file sysutils/opensbi/Makefile using Plan A...
Hunk #1 succeeded at 1.
Hunk #2 succeeded at 20.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/opensbi/distinfo
|===================================================================
|--- sysutils/opensbi/distinfo
|+++ sysutils/opensbi/distinfo
--------------------------
Patching file sysutils/opensbi/distinfo using Plan A...
Hunk #1 succeeded at 1.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/opensbi/files/patch-lib_sbi_sbi__hart.c
|===================================================================
|--- sysutils/opensbi/files/patch-lib_sbi_sbi__hart.c
|+++ sysutils/opensbi/files/patch-lib_sbi_sbi__hart.c
--------------------------
Patching file sysutils/opensbi/files/patch-lib_sbi_sbi__hart.c using Plan A...
Hunk #1 succeeded at 1 with fuzz 1.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/opensbi/files/patch-platform_generic_platform.c
|===================================================================
|--- sysutils/opensbi/files/patch-platform_generic_platform.c
|+++ sysutils/opensbi/files/patch-platform_generic_platform.c
--------------------------
Patching file sysutils/opensbi/files/patch-platform_generic_platform.c using Plan A...
Hunk #1 failed at 1.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_generic_platform.c.rej
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/opensbi/files/patch-platform_generic_sifive__fu540.c
|===================================================================
|--- /dev/null
|+++ sysutils/opensbi/files/patch-platform_generic_sifive__fu540.c
--------------------------
(Creating file sysutils/opensbi/files/patch-platform_generic_sifive__fu540.c...)
Patching file sysutils/opensbi/files/patch-platform_generic_sifive__fu540.c using Plan A...
Empty context always matches.
Hunk #1 succeeded at 1.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/opensbi/files/patch-platform_sifive_fu540_platform.c
|===================================================================
|--- sysutils/opensbi/files/patch-platform_sifive_fu540_platform.c
|+++ /dev/null
--------------------------
Patching file sysutils/opensbi/files/patch-platform_sifive_fu540_platform.c using Plan A...
Empty context always matches.
Hunk #1 failed at 0.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_sifive_fu540_platform.c.rej
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/opensbi/pkg-plist
|===================================================================
|--- sysutils/opensbi/pkg-plist
|+++ sysutils/opensbi/pkg-plist
--------------------------
Patching file sysutils/opensbi/pkg-plist using Plan A...
Hunk #1 succeeded at 2.
Hunk #2 succeeded at 29.
Hunk #3 succeeded at 42.
Hunk #4 succeeded at 69.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: sysutils/u-boot-sifive-fu540/Makefile
|===================================================================
|--- sysutils/u-boot-sifive-fu540/Makefile
|+++ sysutils/u-boot-sifive-fu540/Makefile
--------------------------
Patching file sysutils/u-boot-sifive-fu540/Makefile using Plan A...
Hunk #1 succeeded at 1.
done


----- ........




U-Boot SPL 2021.07 (Jan 13 2022 - 11:26:05 +0000)
Trying to boot from MMC1


U-Boot 2021.07 (Jan 13 2022 - 11:26:05 +0000)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  8 GiB
MMC:   spi@10050000:mmc@0: 0
Loading Environment from SPIFlash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
OK
In:    serial@10010000
Out:   serial@10010000
Err:   serial@10010000
Net:   sifive-reset reset: failed to get cltx_reset reset
eth0: ethernet@10090000
Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0 is current device
Couldn't find partition dhcp 0:1
SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
dhcp - boot image via network using DHCP/TFTP protocol

Usage:
dhcp [loadAddress] [[hostIPaddr:]bootfilename]
## Executing script at 88100000
Wrong image format for "source" command
SCRIPT FAILED: continuing...
ethernet@10090000: PHY present at 0
ethernet@10090000: Starting autonegotiation...
ethernet@10090000: Autonegotiation complete
ethernet@10090000: link up, 1000Mbps full-duplex (lpa: 0x3800)
BOOTP broadcast 1
DHCP client bound to address 192.168.2.3 (2 ms)
Using ethernet@10090000 device
TFTP from server 192.168.2.246; our IP address is 192.168.2.3
Filename 'boot.scr.uimg'.
Load address: 0x88100000
Loading: *
TFTP error: 'File not found' (1)
Not retrying...
ethernet@10090000: PHY present at 0
ethernet@10090000: Starting autonegotiation...
ethernet@10090000: Autonegotiation complete
ethernet@10090000: link up, 1000Mbps full-duplex (lpa: 0x3800)
BOOTP broadcast 1
DHCP client bound to address 192.168.2.3 (2 ms)
Using ethernet@10090000 device
TFTP from server 192.168.2.246; our IP address is 192.168.2.3
Filename 'boot/loader.efi'.
Load address: 0x84000000
Loading: #################################################################
	 ###############################
	 11 MiB/s
done
Bytes transferred = 1404828 (156f9c hex)
ethernet@10090000: PHY present at 0
ethernet@10090000: Starting autonegotiation...
ethernet@10090000: Autonegotiation complete
ethernet@10090000: link up, 1000Mbps full-duplex (lpa: 0x3800)
Using ethernet@10090000 device
TFTP from server 192.168.2.246; our IP address is 192.168.2.3
Filename 'dtb/'.
Load address: 0x88000000
Loading: *
TFTP error: 'File not found' (1)
Not retrying...
libfdt fdt_check_header(): FDT_ERR_BADMAGIC
Scanning disk mmc@0.blk...
** Unrecognized filesystem type **
** Unrecognized filesystem type **
Found 3 disks
No EFI system partition
Booting /boot\loader.efi



Consoles: EFI console  
    Reading loader env vars from /efi/freebsd/loader.env
FreeBSD/riscv EFI loader, Revision 1.1
(Thu Jan 13 10:48:16 CET 2022 root@maciphone.de)

   Command line arguments: l
   Image base: 0xfe5e2000
   EFI version: 2.80
   EFI Firmware: Das U-Boot (rev 8225.1792)
   Console: comconsole (0)
   Load Path: /boot\loader.efi
   Load Device: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b)/MAC(70b3d592f1d5,1)
Setting currdev to net0:
ethernet@10090000: PHY present at 0
ethernet@10090000: Starting autonegotiation...
Loading /boot/defaults/loader.conf complete
Loading /boot/defaults/loader.confps full-duplex (lpa: 0x3800)
Loading /boot/device.hintsrs (status=3)
Loading /boot/loader.conf
Loading /boot/defaults/loader.conf
Loading /boot/loader.conf.local
-


c\


   ______               ____   _____ _____  
  |  ____|             |  _ \ / ____|  __ \ 
  | |___ _ __ ___  ___ | |_) | (___ | |  | |
  |  ___| '__/ _ \/ _ \|  _ < \___ \| |  | |
  | |   | | |  __/  __/| |_) |____) | |__| |
  | |   | | |    |    ||     |      |      |
  |_|   |_|  \___|\___||____/|_____/|_____/      ```                        `
                                                s` `.....---.......--.```   -/
 +---------- Welcome to FreeBSD -----------+    +o   .--`         /y:`      +.
 |                                         |     yo`:.            :o      `+-
 |  1. Back to main menu [Backspace]       |      y/               -/`   -o/
 |  2. Load System Defaults                |     .-                  ::/sy+:.
 |                                         |     /                     `--  /
 |  Boot Options:                          |    `:                          :`
 |  3. Safe Mode  :off                     |    `:                          :`
 |  4. Single user:off                     |     /                          /
 |  5. Verbose    :On                      |     .-                        -.
 |                                         |      --                      -.
 |                                         |       `:`                  `:`
 |                                         |         .--             `--.
 |                                         |            .---.....----.
 +-----------------------------------------+

Loading kernel...
/boot/kernel/kernel text=0x61052c text=0x1358c4 data=0xf51a0 data=0xb54+0x1d7464 syms=[0x8+0xce730+0x8+0xefcf4]
Loading configured modules...
can't find '/boot/entropy'
/etc/hostid size=0x25
Using DTB provided by EFI at 0x87f00000.
Kernel entry at 0xf660002e...
Kernel args: (null)
---<<BOOT>>---
GDB: debug ports: uart
GDB: current port: uart
KDB: debugger backends: ddb gdb
KDB: current backend: ddb
Physical memory chunk(s):
  0x80000000 - 0x27fffffff,  8192 MB (2097152 pages)
Excluded memory regions:
  0x80000000 - 0x8003ffff,     0 MB (     64 pages) NoAlloc NoDump
  0xf6600000 - 0xf72a6fff,    12 MB (   3239 pages) NoAlloc 
Found 4 CPUs in the device tree
Copyright (c) 1992-2022 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
	The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 14.0-CURRENT #3 main-n249511-50f3a1e02960: Thu Jan 13 10:52:15 CET 2022
    root@maciphone.de:/usr/obj/usr/src/riscv.riscv64/sys/GENERIC-NODEBUG riscv
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
t[0] == 0xffffffd1f359f600
t[1] == 0x000000000000000c
t[2] == 0xffffffc000a0bc88
t[3] == 0x0000000000000000
t[4] == 0xffffffd1f359f600
t[5] == 0x0000000000000240
t[6] == 0xffffffc000003ce0
s[0] == 0xffffffc000003af0
s[1] == 0xffffffd1f356b600
s[2] == 0xffffffc000a0b784
s[3] == 0x0000000000000000
s[4] == 0xffffffc000a0b6d8
s[5] == 0xffffffc000a0b4c0
s[6] == 0xffffffc000a0b770
s[7] == 0x0000000000000001
s[8] == 0x0000000000000001
s[9] == 0x0000000000000001
s[10] == 0xffffffc000a0b758
s[11] == 0x0000000000000001
a[0] == 0xffffffd000800000
a[1] == 0x0000000000000000
a[2] == 0x0000000000000fff
a[3] == 0xffffffd000800000
a[4] == 0xffffffd000800001
a[5] == 0x0000000000000000
a[6] == 0x0000000000000001
a[7] == 0x0000000000000068
ra == 0xffffffc0005febf4
sp == 0xffffffc000003ae0
gp == 0xffffffc000003b18
tp == 0xffffffc00068460a
sepc == 0xffffffc0005f14e2
sstatus == 0x8000000200006100
panic: Memory access exception at 0xffffffc0005f14e2

cpuid = 0
time = 1
KDB: stack backtrace:
(null)() at 0xffffffc0005f4a68
(null)() at 0xffffffc000136946
(null)() at 0xffffffc0003a5150
(null)() at 0xffffffc00035c444
(null)() at 0xffffffc00035c2ec
(null)() at 0xffffffc000603cf4
(null)() at 0xffffffc0005f5080
(null)() at 0xffffffc0005febf0
(null)() at 0xffffffc0005cdbc0
(null)() at 0xffffffc000604ecc
(null)() at 0xffffffc0005b0cd0
(null)() at 0xffffffc0005b23ba
(null)() at 0xffffffc0005af34c
(null)() at 0xffffffc0005aeb14
(null)() at 0xffffffc0005adbb2
(null)() at 0xffffffc0005b9998
(null)() at 0xffffffc0002eb882
(null)() at 0xffffffc0000001ba
KDB: enter: panic
[ thread pid 0 tid 0 ]
Stopped at      0xffffffc0003a4f0e

ouch, I see it myself now :

Hunk #1 failed at 1.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_generic_platform.c.rej
...
Hunk #1 failed at 0.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_sifive_fu540_platform.c.rej

'will take a look at it tonight...

@mhorne

....
Hunk #1 failed at 1.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_generic_platform.c.rej
...
Hunk #1 failed at 0.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_sifive_fu540_platform.c.rej

well, whatever failed there, I patched (or removed) those files manually but that didn't matter...
I have ensured that every patch has arrived into the files by reading them.
I reverted the patches , installed u-boot : it successfully boots from pxe.
After applying the patch again: I'm so sorry but it failed again as sent in the previous dmesg.(booted into the same pxe-server)

So as a comparison :
Successful without D33845.patch :

U-Boot SPL 2021.07 (Jan 13 2022 - 22:45:38 +0000)
Trying to boot from MMC1
0000000200001800
sbi_trap_error: hart0: ra=0x00000000800004b6 sp=0x000000008001bf30
sbi_trap_error: hart0: gp=0x0000000000000000 tp=0x000000008001c000
sbi_trap_error: hart0: s

U-Boot 2021.07 (Jan 13 2022 - 22:45:38 +0000)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  118
sbi_trap_error: hart0: a28 GiB
00000085000008 a3=0x0000000000000000
sbi_trap_error: hart0: a4=0x0000000080000520 a5=0x000000000000007f
sbi_trap_error: hart0: a6=0x0000000000000000 a7=0x0000000000000000
sbi_trap_error: hart0: s2=0x000000008001c000 s3=0x0000000000000000
sbi_trap_error: hart0: s4=0x0000000000000000 s5=0x0000000000000000
sbi_trap_error: hart0: s6=0xffffffffffffffff s7=0x0000000000000004
sbi?or: hart0: s8=0x0000000000002000 MMC:   0000000800101spi@10050000:mmc@0: 0
harLoading Environment from SPIFlash... 0000000000000SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
rap_error: hart0: t2=0x0000000000000000 t3=0x0000000000000000
sbi_trap_error: hart0: t4=0x0000000000000000 t5=0x0000000000000000
sbi_trap_error: hart0: t6=0x0000000000000000
OK
In:    serial@10010000
Out:   serial@10010000
Err:   serial@10010000
Net:   sifive-reset reset: failed to get cltx_reset reset
eth0: ethernet@10090000
Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0 is current device
...
Thu Jan 13 23:48:12 UTC 
FreeBSD/riscv (rv64) (ttyu0)

login: root

panic with D33845.patch :

U-Boot SPL 2021.07 (Jan 14 2022 - 01:12:55 +0000)
Trying to boot from MMC1


U-Boot 2021.07 (Jan 14 2022 - 01:12:55 +0000)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  8 GiB
MMC:   spi@10050000:mmc@0: 0
Loading Environment from SPIFlash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
OK
In:    serial@10010000
Out:   serial@10010000
Err:   serial@10010000
Net:   sifive-reset reset: failed to get cltx_reset reset
eth0: ethernet@10090000
Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0 is current device
.....
KDB: enter: panic
[ thread pid 0 tid 0 ]
Stopped at      0xffffffc0003a4f0e

Of course, you are also welcome to contact me via email if you would like to test your patches further.(I'm currently not subscribed to the mailing lists)

I made an issue-request to the upstream :
https://github.com/riscv-software-src/opensbi/issues/239
.. in the hope that I haven't misunderstood the context of D33845

Build with base clang/LLVM when available.

This revision now requires review to proceed.Jan 18 2022, 8:44 PM

Is it possible to upstream those local patches?

No, unfortunately not. There are kernel changes to be made on our side which will soon make these patches unnecessary.

@mhorne

....
Hunk #1 failed at 1.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_generic_platform.c.rej
...
Hunk #1 failed at 0.
1 out of 1 hunks failed--saving rejects to sysutils/opensbi/files/patch-platform_sifive_fu540_platform.c.rej

well, whatever failed there, I patched (or removed) those files manually but that didn't matter...
I have ensured that every patch has arrived into the files by reading them.
I reverted the patches , installed u-boot : it successfully boots from pxe.
After applying the patch again: I'm so sorry but it failed again as sent in the previous dmesg.(booted into the same pxe-server)

Okay, I will follow up over email.

sysutils/opensbi/Makefile
30

What's wrong with STABLE-13's LLVM 13? Even 13.0-RELEASE's LLVM 12 *should* work, I believe as far back as 10 has been tested.

sysutils/opensbi/Makefile
30

It requires llvm-objcopy to complete the build, which is not installed by default on 13.0 and earlier. Looks like that's no longer the case on stable/13, so I will update to include that branch as well.

sysutils/opensbi/Makefile
30

Oh I think you may need CC=clang though, it'll default to $(CROSS_COMPILE)gcc. LLVM=1 also ends up forcing llvm-ar and llvm-objcopy, and I think we have llvm-ar in 13 but not llvm-objcopy by default.

That is, CC=clang rather than LLVM=1 is probably what we want as it'll then use whatever the default system objcopy etc are rather than forcing llvm-foo. Similarly for ld, it'll just use the default. All we need to do is stop it defaulting to CC=gcc (why can people not just use CC=cc...).

mhorne added inline comments.
sysutils/opensbi/Makefile
30

Thanks. It builds in a 12.3 jail, so this should be good enough.

root@freebsd:/usr/ports/sysutils/u-boot-sifive-fu540 # uname -a
FreeBSD freebsd 14.0-CURRENT FreeBSD 14.0-CURRENT #4 main-n250734-2bbaed4d7fca: Tue Nov 16 20:30:28 UTC 2021     root@freebsd:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG  amd64
root@freebsd:/usr/ports/sysutils/u-boot-sifive-fu540 # cc -v
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin

...
root@freebsd:/usr/ports # patch  < D33845.101606.patch
...
-c /usr/ports/sysutils/opensbi/work/opensbi-1.0/lib/sbi/riscv_atomic.c -o /usr/ports/sysutils/opensbi/work/opensbi-1.0/build/lib/sbi/riscv_atomic.o
 CC        lib/sbi/riscv_asm.o
 CC        lib/sbi/riscv_atomic.o
clang: error: unknown argument: '-mno-relax'
clang: error: unknown argument: '-mno-relax'
gmake[3]: *** [Makefile:431: /usr/ports/sysutils/opensbi/work/opensbi-1.0/build/lib/sbi/riscv_atomic.o] Error 1
gmake[3]: *** Waiting for unfinished jobs....
gmake[3]: *** [Makefile:431: /usr/ports/sysutils/opensbi/work/opensbi-1.0/build/lib/sbi/riscv_asm.o] Error 1
gmake[3]: Leaving directory '/usr/ports/sysutils/opensbi/work/opensbi-1.0'
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** Error code 1

Stop.
make[2]: stopped in /usr/ports/sysutils/opensbi
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/sysutils/opensbi
*** Error code 1

Stop.
make: stopped in /usr/ports/sysutils/u-boot-sifive-fu540
root@freebsd:/usr/ports/sysutils/u-boot-sifive-fu540 # uname -a
FreeBSD freebsd 14.0-CURRENT FreeBSD 14.0-CURRENT #4 main-n250734-2bbaed4d7fca: Tue Nov 16 20:30:28 UTC 2021     root@freebsd:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG  amd64
root@freebsd:/usr/ports/sysutils/u-boot-sifive-fu540 # cc -v
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin

...
root@freebsd:/usr/ports # patch  < D33845.101606.patch
...
-c /usr/ports/sysutils/opensbi/work/opensbi-1.0/lib/sbi/riscv_atomic.c -o /usr/ports/sysutils/opensbi/work/opensbi-1.0/build/lib/sbi/riscv_atomic.o
 CC        lib/sbi/riscv_asm.o
 CC        lib/sbi/riscv_atomic.o
clang: error: unknown argument: '-mno-relax'
clang: error: unknown argument: '-mno-relax'
gmake[3]: *** [Makefile:431: /usr/ports/sysutils/opensbi/work/opensbi-1.0/build/lib/sbi/riscv_atomic.o] Error 1
gmake[3]: *** Waiting for unfinished jobs....
gmake[3]: *** [Makefile:431: /usr/ports/sysutils/opensbi/work/opensbi-1.0/build/lib/sbi/riscv_asm.o] Error 1
gmake[3]: Leaving directory '/usr/ports/sysutils/opensbi/work/opensbi-1.0'
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** Error code 1

Stop.
make[2]: stopped in /usr/ports/sysutils/opensbi
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/sysutils/opensbi
*** Error code 1

Stop.
make: stopped in /usr/ports/sysutils/u-boot-sifive-fu540

What does which clang/clang -v say, not which cc/cc -v? Because Clang 13 definitely supports -mno-relax...

Also not sure why you cut off the output so late, there are useful things like what commands were actually run up there that we now can't see.

Arguably I should in fact have suggested CC=${CC} so we use whatever the system compiler is set to, not hard-coding Clang that's picked up from PATH. But if you have an ancient Clang in your PATH then you're probably in for a bad time anyway... -mno-relax first appeared in Clang *7* four years ago.

ouch, my bad , sorry, accidentally was set to clang 6 :-)... upgrading now

U-Boot SPL 2021.07 (Jan 18 2022 - 22:58:39 +0000)
Trying to boot from MMC1


U-Boot 2021.07 (Jan 18 2022 - 22:58:39 +0000)

CPU:   rv64imafdc
Model: SiFive HiFive Unleashed A00
DRAM:  8 GiB
MMC:   spi@10050000:mmc@0: 0
Loading Environment from SPIFlash... SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
OK
In:    serial@10010000
Out:   serial@10010000
Err:   serial@10010000
Net:   sifive-reset reset: failed to get cltx_reset reset
eth0: ethernet@10090000
Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0 is current device
Couldn't find partition dhcp 0:1
SF: Detected is25wp256 with page size 256 Bytes, erase size 4 KiB, total 32 MiB
dhcp - boot image via network using DHCP/TFTP protocol

Usage:
dhcp [loadAddress] [[hostIPaddr:]bootfilename]
## Executing script at 88100000
Wrong image format for "source" command
SCRIPT FAILED: continuing...
ethernet@10090000: PHY present at 0
ethernet@10090000: Starting autonegotiation...
ethernet@10090000: Autonegotiation complete
ethernet@10090000: link up, 1000Mbps full-duplex (lpa: 0x3800)
BOOTP broadcast 1
DHCP client bound to address 192.168.2.3 (2 ms)
Using ethernet@10090000 device
TFTP from server 192.168.2.246; our IP address is 192.168.2.3
Filename 'boot.scr.uimg'.
Load address: 0x88100000
Loading: *
TFTP error: 'File not found' (1)
Not retrying...
ethernet@10090000: PHY present at 0
ethernet@10090000: Starting autonegotiation...
ethernet@10090000: Autonegotiation complete
ethernet@10090000: link up, 1000Mbps full-duplex (lpa: 0x3800)
BOOTP broadcast 1
DHCP client bound to address 192.168.2.3 (2 ms)
Using ethernet@10090000 device
TFTP from server 192.168.2.246; our IP address is 192.168.2.3
Filename 'boot/loader.efi'.
Load address: 0x84000000
Loading: #################################################################
	 ###############################
	 10.9 MiB/s
......

Loading kernel...
/boot/kernel/kernel text=0x61052c text=0x1358c4 data=0xf51a0 data=0xb54+0x1d7464 syms=[0x8+0xce730+0x8+0xefcf4]
Loading configured modules...
can't find '/boot/entropy'
/etc/hostid size=0x25
Using DTB provided by EFI at 0x87f00000.
Kernel entry at 0xf660002e...
Kernel args: (null)
---<<BOOT>>---
GDB: debug ports: uart
GDB: current port: uart
KDB: debugger backends: ddb gdb
KDB: current backend: ddb
Copyright (c) 1992-2022 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
	The Regents of the University of California. All rights reserved.
FreeBSD is a registered trademark of The FreeBSD Foundation.
FreeBSD 14.0-CURRENT #3 main-n249511-50f3a1e02960: Thu Jan 13 10:52:15 CET 2022
    root@maciphone.de:/usr/obj/usr/src/riscv.riscv64/sys/GENERIC-NODEBUG riscv
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
VT: init without driver.
SBI: OpenSBI v1.0                              (!!!) 👍
SBI Specification Version: 0.3
CPU(0): Unknown Implementer Unknown Processor
real memory  = 8589934592 (8192 MB)
avail memory = 8334888960 (7948 MB)
Starting CPU 1 (hart 2)
Starting CPU 2 (hart 3)
Starting CPU 3 (hart 4)

thanks for great work !

This revision is now accepted and ready to land.Jan 18 2022, 11:13 PM
This revision was automatically updated to reflect the committed changes.
mhorne marked an inline comment as done.