参见:riscv - FreeBSD Wiki
安装所需的软件包
sudo pkg install opensbi u-boot-qemu-riscv64 qemu
FreeBSD.2FRISC-V_virtual_machine_image" style="background-color:transparent;">下载 FreeBSD/RISC-V 虚拟机映像
fetch https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/riscv64/Latest/FreeBSD-15.0-CURRENT-riscv-riscv64.raw.xz
xz --decompress FreeBSD-15.0-CURRENT-riscv-riscv64.raw.xz
https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/riscv64/Latest/FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw.xz
扩展映像(可选)
truncate -s 10G FreeBSD-15.0-CURRENT-riscv-riscv64.raw
安装glib
pkg install glib
QEMU 中的引导映像
qemu-system-riscv64 -machine virt -m 2048M -smp 2 -nographic \-bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf \-kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin \-drive file=FreeBSD-15.0-CURRENT-riscv-riscv64.raw,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \-netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 -device virtio-net-device,netdev=net0
启动了opensmi
OpenSBI v1.4____ _____ ____ _____/ __ \ / ____| _ \_ _|| | | |_ __ ___ _ __ | (___ | |_) || || | | | '_ \ / _ \ '_ \ \___ \| _ < | || |__| | |_) | __/ | | |____) | |_) || |_\____/| .__/ \___|_| |_|_____/|____/_____|| ||_|Platform Name : riscv-virtio,qemu
提示:
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (0 ms)
Using virtio-net#1 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x84000000
Loading: *
TFTP error: 'Access violation' (2)
QEMU 中引导14映像成功
wget -c http://mirrors.ustc.edu.cn/freebsd/releases/VM-IMAGES/14.0-RELEASE/riscv64/Latest/FreeBSD-14.0-RELEASE-riscv-riscv64.raw.xzxz --decompress FreeBSD-14.0-RELEASE-riscv-riscv64.raw.xztruncate -s 10G FreeBSD-14.0-RELEASE-riscv-riscv64.rawqemu-system-riscv64 -machine virt -m 2048M -smp 2 -nographic -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf -kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin -drive file=FreeBSD-14.0-RELEASE-riscv-riscv64.raw,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 -device virtio-net-device,netdev=net0
引导后的输出:
May 4 15:10:10 freebsd login[847]: ROOT LOGIN (root) ON ttyu0
FreeBSD 14.0-RELEASE (GENERIC) #0 releng/14.0-n265380-f9716eee8ab4: Fri Nov 10 05:23:33 UTC 2023Welcome 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 hierTo change this login announcement, see motd(5).
root@freebsd:~ # uname -a
FreeBSD freebsd 14.0-RELEASE FreeBSD 14.0-RELEASE #0 releng/14.0-n265380-f9716eee8ab4: Fri Nov 10 05:23:33 UTC 2023 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/riscv.riscv64/sys/GENERIC riscv
目前网络还没有通,待续。
调试
运行qemu-system-riscv64报错
/usr/local/bin/qemu-system-riscv64
ld-elf.so.1: /usr/local/bin/qemu-system-riscv64: Undefined symbol "g_once_init_enter_pointer"
安装glib搞定。
pkg install glib
Message from qemu-9.0.0:
--
FreeBSD host notes
==================
- Needs to set net.link.tap.user_open sysctl in order to use /dev/tap*
networking as non-root. Don't forget to adjust device node permissions in
/etc/devfs.rules.
- Expect timer problems when guest kernel HZ is > hosts. The linux 2.6
kernel uses 1000 by default btw. (changed to 250 later, and recent linux
kernels now no longer have a fixed HZ, aka `tickless kernel'...)
Enabling /dev/rtc doesn't seem to help either (not included since it needs
a patch to emulators/rtc.)
- The -smb option (smb-export local dir to guest using the default
slirp networking) needs the samba port/package installed
in addition to qemu. (SAMBA knob.)
- If you want to use usb devices connected to the host in the guest
yot can use usbredir over the network (see below); also unless you are
running qemu as root you then need to fix permissions for /dev/ugen*
device nodes: if you are on 5.x or later (devfs) put a rule in
/etc/devfs.rules, activate it in /etc/rc.conf and run /etc/rc.d/devfs
restart. Example devfs.rules:
[ugen_ruleset=20]
add path 'ugen*' mode 660 group operator
corresponding rc.conf line:
devfs_system_ruleset="ugen_ruleset"
- Still usb: since the hub is no longer attached to the uchi controller and
the wakeup mechanism, resume interrupt is not implemented yet linux guests
will suspend the bus, i.e. they wont see devices usb_add'ed after its
(linux') uhci module got loaded. Workaround: either add devices before
linux loads the module or rmmod and modprobe it afterwards. [Not sure
if this still applies to the new libusb host code used on recent
10-current.]
- If you get repeated `atapi_poll called!' console messages with FreeBSD
guests or other weird cdrom problems then thats probably because the guest
has atapicam loaded, which for reasons still to be determined has problems
with qemu's now by default enabled cdrom dma. You can build the port with
CDROM_DMA disabled to disable it. [Looks like this is fixed in recent
FreeBSD guest versions.]
- If you build qemu wihout SDL and then get crashes running it try passing it
-nographic. This should probably be default in that case...
- qemu's network boot roms (-boot n) have a bug when bootfiles sizes are a
multiple of blksize, if this affects you (like with FreeBSD's /boot/pxeboot)
you can do like
cp /boot/pxeboot pxeboot-qemu && chmod +w pxeboot-qemu && echo >>pxeboot-qemu
and then use pxeboot-qemu. Actually you need recent btx code
(from after 7.0 was released) because of the real mode boot
problem, so use at least pxeboot from there. And I just did that
for the pxeboot extracted out of
ftp://ftp.freebsd.org/pub/FreeBSD/snapshots/200805/7.0-STABLE-200805-i386-bootonly.iso
and placed it here:
http://people.freebsd.org/~nox/qemu/pxeboot-qemu
- If you use slirp (usernet, the default) and want to mount nfs into the guest
and you are not running qemu as root, then mountd(8) on the exporting box
needs to be run with -n in order to accept requests from ports >= 1024.
qemu启动后报错TFTP error: 'Access violation' (2)
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (0 ms)
Using virtio-net#1 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x84000000
Loading: *
TFTP error: 'Access violation' (2)
发现启动后的ip跟本机不在同一网段....创建多ip
/etc/rc.conf文件中这样配置:
ifconfig_wlan0_alias0="inet 10.0.2.1 netmask 255.255.255.0"
命令行这样配置:
#设置接口le1地址
ifconfig wlan0 add 10.0.2.1 netmask 255.255.255.0
创建了ip地址后还是无法通信....
qemu启动后无法退出
not allowed from main input shell.
大约设计就是这样的
fetch下载虚拟机速度很快,文件很小
发现下载文件只有32个字节,个人认为应该是这个文件:https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/riscv64/Latest/FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw.xz
重新针对zfs这个文件进行操作
fetch https://download.freebsd.org/snapshots/VM-IMAGES/15.0-CURRENT/riscv64/Latest/FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw.xz xz --decompress FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw.xz
truncate -s 10G FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw
qemu-system-riscv64 -machine virt -m 2048M -smp 2 -nographic \-bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf \-kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin \-drive file=FreeBSD-15.0-CURRENT-riscv-riscv64-zfs.raw,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \-netdev user,id=net0,ipv6=off,hostfwd=tcp::8022-:22 -device virtio-net-device,netdev=net0
ok,没有以前的报错了
换zfs镜像后启动报错 cannot open /boot/lua/loader.lua
Setting currdev to disk0p3:
ERROR: cannot open /boot/lua/loader.lua: no such file or directory.
前面还有信息:
Device 0: QEMU VirtIO Block Device
Type: Hard Disk
Capacity: 10240.0 MB = 10.0 GB (20971520 x 512)
... is now current device
Scanning virtio 0:1...
Failed to load '/'
Failed to load EFI variables
Missing RNG device for EFI_RNG_PROTOCOL
BootOrder not defined
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootriscv64.efi
710356 bytes read in 17 ms (39.8 MiB/s)
Booting /efi\boot\bootriscv64.efi
怀疑是不是因为zfs映像的问题? 换用14.0的映像试试。
http://mirrors.ustc.edu.cn/freebsd/releases/VM-IMAGES/14.0-RELEASE/riscv64/Latest/FreeBSD-14.0-RELEASE-riscv-riscv64.raw.xz
换用14映像后,启动成功!