vak: (Daemon)
Serge Vakulenko ([personal profile] vak) wrote2024-12-15 10:07 pm

FreeBSD на RISC-V

Поддержка архитектуры RISC-V в FreeBSD всё ещё в процессе разработки. Но уже можно запустить ядро на симуляторе QEMU. Вот как это делается.
wget https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/riscv64/Latest/FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.raw.xz
xz --decompress FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.raw.xz
qemu-img convert -f raw -O qcow2 FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.raw FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.qcow
qemu-img resize FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.qcow 16G

qemu-system-riscv64 \
-machine virt \
-nographic \
-m 2048M \
-smp 2 \
-bios fw_jump.elf \
-kernel u-boot.bin \
-drive file=FreeBSD-15.0-CURRENT-riscv-riscv64-ufs.qcow,if=none,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 \
-device virtio-net-device,netdev=net0
Вход как root без пароля. Пакетов для RISC-V ещё нету, как я понимаю, поэтому командой pkg ничего установить не удаётся.

Протокол загрузки:
OpenSBI v1.4
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|

Platform Name : riscv-virtio,qemu
Platform Features : medeleg
Platform HART Count : 2
Platform IPI Device : aclint-mswi
Platform Timer Device : aclint-mtimer @ 10000000Hz
Platform Console Device : uart8250
Platform HSM Device : ---
Platform PMU Device : ---
Platform Reboot Device : syscon-reboot
Platform Shutdown Device : syscon-poweroff
Platform Suspend Device : ---
Platform CPPC Device : ---
Firmware Base : 0x80000000
Firmware Size : 333 KB
Firmware RW Offset : 0x40000
Firmware RW Size : 77 KB
Firmware Heap Offset : 0x4a000
Firmware Heap Size : 37 KB (total), 2 KB (reserved), 9 KB (used), 25 KB (free)
Firmware Scratch Size : 4096 B (total), 328 B (used), 3768 B (free)
Runtime SBI Version : 2.0

Domain0 Name : root
Domain0 Boot HART : 1
Domain0 HARTs : 0*,1*
Domain0 Region00 : 0x0000000000100000-0x0000000000100fff M: (I,R,W) S/U: (R,W)
Domain0 Region01 : 0x0000000010000000-0x0000000010000fff M: (I,R,W) S/U: (R,W)
Domain0 Region02 : 0x0000000002000000-0x000000000200ffff M: (I,R,W) S/U: ()
Domain0 Region03 : 0x0000000080040000-0x000000008005ffff M: (R,W) S/U: ()
Domain0 Region04 : 0x0000000080000000-0x000000008003ffff M: (R,X) S/U: ()
Domain0 Region05 : 0x000000000c400000-0x000000000c5fffff M: (I,R,W) S/U: (R,W)
Domain0 Region06 : 0x000000000c000000-0x000000000c3fffff M: (I,R,W) S/U: (R,W)
Domain0 Region07 : 0x0000000000000000-0xffffffffffffffff M: () S/U: (R,W,X)
Domain0 Next Address : 0x0000000080200000
Domain0 Next Arg1 : 0x0000000082200000
Domain0 Next Mode : S-mode
Domain0 SysReset : yes
Domain0 SysSuspend : yes

Boot HART ID : 1
Boot HART Domain : root
Boot HART Priv Version : v1.12
Boot HART Base ISA : rv64imafdch
Boot HART ISA Extensions : sstc,zicntr,zihpm,zicboz,zicbom
Boot HART PMP Count : 16
Boot HART PMP Granularity : 2 bits
Boot HART PMP Address Bits: 54
Boot HART MHPM Info : 16 (0x0007fff8)
Boot HART MIDELEG : 0x0000000000001666
Boot HART MEDELEG : 0x0000000000f0b509


U-Boot 2024.07 (Nov 13 2024 - 06:04:30 +0000)

CPU: riscv
Model: riscv-virtio,qemu
DRAM: 2 GiB
Core: 28 devices, 13 uclasses, devicetree: board
Flash: 32 MiB
Loading Environment from nowhere... OK
In: serial,usbkbd
Out: serial,vidconsole
Err: serial,vidconsole
No USB controllers found
Net: eth0: virtio-net#1

Working FDT set to feefd370
Hit any key to stop autoboot: 2 1 0

Device 0: QEMU VirtIO Block Device
Type: Hard Disk
Capacity: 16384.0 MB = 16.0 GB (33554432 x 512)
... is now current device
Scanning virtio 0:1...
Failed to load '/'
Missing RNG device for EFI_RNG_PROTOCOL
Booting: virtio 0
Consoles: EFI console
Reading loader env vars from /efi/freebsd/loader.env
Setting currdev to disk0p1:
FreeBSD/riscv EFI loader, Revision 3.0
(Thu Dec 12 06:47:50 UTC 2024 root@releng3.nyi.freebsd.org)

Command line arguments: l
Image base: 0xfdd6a000
EFI version: 2.100
EFI Firmware: Das U-Boot (rev 8228.1792)
Console: comconsole (0)
Load Path: /\EFI\BOOT\BOOTRISCV64.EFI
Load Device: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(1,GPT,ec13e051-b859-11ef-81ea-0cc47ad8b808,0x22,0x10418)
BootCurrent: 0000
BootOrder: 0000[*]
BootInfo Path: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)
Ignoring Boot0000: Only one DP found
Trying ESP: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(1,GPT,ec13e051-b859-11ef-81ea-0cc47ad8b808,0x22,0x10418)
Setting currdev to disk0p1:
|Trying: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(2,GPT,ec13e05a-b859-11ef-81ea-0cc47ad8b808,0x1043a,0x200000)
Setting currdev to disk0p2:
/Trying: /VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,0000000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,6d00000001000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,8500000000000000)/VenHw(e61d73b9-a384-4acc-aeab-82e828f3628b,1600850000000000)/HD(3,GPT,ec13e05f-b859-11ef-81ea-0cc47ad8b808,0x21043a,0x1defb9e)
Setting currdev to disk0p3:
-\|/-\|/-\|/-\|/-\|/-\
Loading /boot/defaults/loader.conf
Loading /boot/defaults/loader.conf
Loading /boot/device.hints
|Loading /boot/loader.conf
/Loading /boot/loader.conf.local

s` `.....---.......--.``` -/
+o .--` /y:` +.
yo`:. :o `+-
y/ -/` -o/
.- ::/sy+:.
/ `-- /
`: :`
`: :`
/ /
.- -.
-- -.
`:` `:`
.-- `--.
.---.....----.
______ ____ _____ _____
| ____| | _ \ / ____| __ \
| |___ _ __ ___ ___ | |_) | (___ | | | |
| ___| '__/ _ \/ _ \| _ < \___ \| | | |
| | | | | __/ __/| |_) |____) | |__| |
| | | | | | || | | |
|_| |_| \___|\___||____/|_____/|_____/

Welcome to FreeBSD
1. Boot Multi user [Enter]
2. Boot Single user
3. Escape to loader prompt
4. Reboot
5. Cons: Video

Options:
6. Kernel: default/kernel (1 of 1)
7. Boot Options

Autoboot in 10 seconds. [Space] to pause
Autoboot in 9 seconds. [Space] to pause
Autoboot in 8 seconds. [Space] to pause
Autoboot in 7 seconds. [Space] to pause
Autoboot in 6 seconds. [Space] to pause
Autoboot in 5 seconds. [Space] to pause
Autoboot in 4 seconds. [Space] to pause
Autoboot in 3 seconds. [Space] to pause
Autoboot in 2 seconds. [Space] to pause
Autoboot in 1 seconds. [Space] to pause
Autoboot in 0 seconds. [Space] to pause
Loading kernel...
|//boot/kernel/kernel text=0x5f559e -\|text=0x1a41a8 /data=0x125b78 data=0xeb8+0x2871e0 0x8+0x12e448-+0x8+0x119e95\
Loading configured modules...
/etc/hostid size=0x25
|/boot/entropy size=0x1000
Using DTB provided by EFI at 0xfdec5000.
Kernel entry at 0xf5e00030...
Kernel args: (null)
Loading splash ok
---<<BOOT>>---
GDB: no debug ports present
KDB: debugger backends: ddb
KDB: current backend: ddb
Copyright (c) 1992-2024 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 15.0-CURRENT #0 main-n274168-af66ffbf69e4: Thu Dec 12 06:54:54 UTC 2024
root@releng3.nyi.freebsd.org:/usr/obj/usr/src/riscv.riscv64/sys/GENERIC riscv
FreeBSD clang version 19.1.5 (https://github.com/llvm/llvm-project.git llvmorg-19.1.5-0-gab4b5a2db582)
WARNING: WITNESS option enabled, expect reduced performance.
VT: init without driver.
SBI: OpenSBI v1.4
SBI Specification Version: 2.0
CPU 0 : Vendor=Unspecified Core=Unspecified (Hart 1)
marchid=0, mimpid=0
MMU: 0x7<Sv39,Sv48,Sv57>
ISA: 0x11ad<Atomic,Compressed,Double,Float,Hypervisor,Mult/Div>
S-mode Extensions: 0x1<Sstc>
real memory = 2147483648 (2048 MB)
avail memory = 2058252288 (1962 MB)
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
CPU 1 : Vendor=Unspecified Core=Unspecified (Hart 0)
random: unblocking device.
random: entropy device external interface
kbd0 at kbdmux0
ofwbus0: <Open Firmware Device Tree>
simplebus0: <Flattened device tree simple bus> on ofwbus0
simplebus1: <Flattened device tree simple bus> on ofwbus0
sbi0: <RISC-V Supervisor Binary Interface>
intc0: <RISC-V Local Interrupt Controller> on ofwbus0
sbi_ipi0: <RISC-V SBI Inter-Processor Interrupts> on sbi0
plic0: <RISC-V PLIC> mem 0xc000000-0xc5fffff irq 10,11,12,13 on simplebus1
timer0: <RISC-V Timer>
Timecounter "RISC-V Timecounter" frequency 10000000 Hz quality 1000
Event timer "RISC-V Eventtimer" frequency 10000000 Hz quality 1000
riscv_syscon0: <RISC-V syscon> mem 0x100000-0x100fff on simplebus1
rcons0: <RISC-V console>
syscon_power0: <Syscon poweroff> on ofwbus0
syscon_power1: <Syscon reboot> on ofwbus0
cpulist0: <Open Firmware CPU Group> on ofwbus0
cpu0: <Open Firmware CPU> on cpulist0
goldfish_rtc0: <Goldfish RTC> mem 0x101000-0x101fff irq 0 on simplebus1
goldfish_rtc0: registered as a time-of-day clock, resolution 1.000000s
uart0: <16550 or compatible> mem 0x10000000-0x100000ff irq 1 on simplebus1
uart0: console (115200,n,8,1)
virtio_mmio0: <VirtIO MMIO adapter> mem 0x10008000-0x10008fff irq 2 on simplebus1
vtblk0: <VirtIO Block Adapter> on virtio_mmio0
vtblk0: 16384MB (33554432 512 byte sectors)
virtio_mmio1: <VirtIO MMIO adapter> mem 0x10007000-0x10007fff irq 3 on simplebus1
vtnet0: <VirtIO Networking Adapter> on virtio_mmio1
vtnet0: Ethernet address: 52:54:00:12:34:56
pcib0: <Generic PCI host controller> mem 0x30000000-0x3fffffff on simplebus1
pci0: <PCI bus> on pcib0
Timecounters tick every 1.000 msec
usb_needs_explore_all: no devclass
sbi_ipi0: using for IPIs
Release APs
WARNING: WITNESS option enabled, expect reduced performance.
Trying to mount root from ufs:/dev/gpt/rootfs [rw]...
Setting hostuuid: 885f53db-0b21-4931-a438-dc26eae6ae1a.
Setting hostid: 0x2a875f1e.
Starting file system checks:
/dev/gpt/rootfs: FILE SYSTEM CLEAN; SKIPPING CHECKS
/dev/gpt/rootfs: clean, 2896661 free (53 frags, 362076 blocks, 0.0% fragmentation)
/dev/gpt/efiboot0: FILESYSTEM CLEAN; SKIPPING CHECKS
Mounting local filesystems:.
Setting up harvesting: [CALLOUT],[UMA],[FS_ATIME],SWI,INTERRUPT,NET_NG,[NET_ETHER],NET_TUN,MOUSE,KEYBOARD,ATTACH,CACHED
Feeding entropy: .
Setting hostname: freebsd.
ELF ldconfig path: /lib /usr/lib /usr/lib/compat
lo0: link state changed to UP
vtnet0: link state changed to UP
Starting Network: lo0 vtnet0.
lo0: flags=1008049<UP,LOOPBACK,RUNNING,MULTICAST,LOWER_UP> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
groups: lo
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
vtnet0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
options=80028<VLAN_MTU,JUMBO_MTU,LINKSTATE>
ether 52:54:00:12:34:56
inet6 fe80::5054:ff:fe12:3456%vtnet0 prefixlen 64 scopeid 0x1
media: Ethernet autoselect (10Gbase-T <full-duplex>)
status: active
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
Starting devd.
Starting dhclient.
DHCPREQUEST on vtnet0 to 255.255.255.255 port 67
DHCPACK from 10.0.2.2
bound to 10.0.2.15 -- renewal in 43200 seconds.
route: message indicates error: File exists
add host 127.0.0.1: gateway lo0 fib 0: route already in table
route: message indicates error: File exists
add host ::1: gateway lo0 fib 0: route already in table
add net fe80::: gateway ::1
add net ff02::: gateway ::1
add net ::ffff:0.0.0.0: gateway ::1
add net ::0.0.0.0: gateway ::1
Clearing /tmp (X related).
Creating and/or trimming log files.
Updating /var/run/os-release done.
Updating motd:.
Starting syslogd.
No core dumps found.
Mounting late filesystems:.
Starting cron.
Starting background file system checks in 60 seconds.

Mon Dec 16 05:49:21 UTC 2024

FreeBSD/riscv (freebsd) (ttyu0)

login: root
Password:
Last login: Mon Dec 16 05:42:22 on ttyu0
Dec 16 05:49:29 freebsd login[1219]: ROOT LOGIN (root) ON ttyu0
FreeBSD 15.0-CURRENT (GENERIC) #0 main-n274168-af66ffbf69e4: Thu Dec 12 06:54:54 UTC 2024

Welcome to FreeBSD!

Release Notes, Errata: https://www.FreeBSD.org/releases/
Security Advisories: https://www.FreeBSD.org/security/
FreeBSD Handbook: https://www.FreeBSD.org/handbook/
FreeBSD FAQ: https://www.FreeBSD.org/faq/
Questions List: https://www.FreeBSD.org/lists/questions/
FreeBSD Forums: https://forums.FreeBSD.org/

Documents installed with the system are in the /usr/local/share/doc/freebsd/
directory, or can be installed later with: pkg install en-freebsd-doc
For other languages, replace "en" with a language code like de or fr.

Show the version of FreeBSD installed: freebsd-version ; uname -a
Please include that output and any error messages when posting questions.
Introduction to manual pages: man man
FreeBSD directory layout: man hier

To change this login announcement, see motd(5).
root@freebsd:~ # df -m
Filesystem 1M-blocks Used Avail Capacity Mounted on
/dev/gpt/rootfs 14835 3520 10128 26% /
devfs 0 0 0 0% /dev
/dev/gpt/efiboot0 31 0 31 2% /boot/efi
root@freebsd:~ # uname -a
FreeBSD freebsd 15.0-CURRENT FreeBSD 15.0-CURRENT #0 main-n274168-af66ffbf69e4: Thu Dec 12 06:54:54 UTC 2024 root@releng3.nyi.freebsd.org:/usr/obj/usr/src/riscv.riscv64/sys/GENERIC riscv
root@freebsd:~ # poweroff
Shutdown NOW!
poweroff: [pid 1225]
root@freebsd:~ #
*** FINAL System shutdown message from root@freebsd ***

System going down IMMEDIATELY



System shutdown time has arrived
Dec 16 05:49:56 freebsd shutdown[1225]: power-down by root:
Stopping cron.
Waiting for PIDS: 1183.
Stopping devd.
Waiting for PIDS: 901.
Writing entropy file: .
Writing early boot entropy file: .
.
Terminated
Dec 16 05:50:02 freebsd syslogd: exiting on signal 15
Waiting (max 60 seconds) for system process `vnlru' to stop... done
Waiting (max 60 seconds) for system process `syncer' to stop...
Syncing disks, vnodes remaining... 1 0 0 done
All buffers synced.
Uptime: 1m25s
dmarck: (Default)

[personal profile] dmarck 2024-12-19 01:50 pm (UTC)(link)
про пакеты: поскольку реальных шелезяк достать сложно, можно на ближайшем amd64 собирать через poudriere+QEMU