FreeBSD RISCV 在QEME中实践

news/2024/9/25 9:37:56/

参见: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映像后,启动成功! 


http://www.ppmy.cn/news/1453977.html

相关文章

etcd源码流程---调试环境的搭建

etcd启动命令&#xff1a; name必须设置&#xff0c;否则会用default&#xff0c;集群内不同etcd实例的名字应该是唯一的&#xff0c;因为他会有一个map(name->ip)。如果initial-cluster-state设置为new&#xff0c;那么他会创建一个新的clusterid。需要在initial-cluster中…

爬取B站评论:Python技术实现详解

引言 在当今信息爆炸的互联网时代&#xff0c;用户生成的内容不断涌现&#xff0c;其中包括了各种各样的评论。而B站作为一个充满活力的视频分享平台&#xff0c;其评论区更是一个充满了各种各样精彩评论的宝藏地。那么&#xff0c;有没有一种简单的方法可以将这些评论收集起来…

OpenCV如何在图像中寻找轮廓(60)

返回:OpenCV系列文章目录&#xff08;持续更新中......&#xff09; 上一篇&#xff1a;OpenCV如何模板匹配(59) 下一篇 :OpenCV检测凸包(61) 目标 在本教程中&#xff0c;您将学习如何&#xff1a; 使用 OpenCV 函数 cv::findContours使用 OpenCV 函数 cv::d rawContours …

[QNX] mmap+cache/nocache+memcpy/asm_memcpy速度对比

mmap nocache介绍 以linux系统的nocache介绍&#xff1a; 在Linux系统中&#xff0c;使用mmap映射文件到内存时可以指定不使用缓存。这可以通过在调用mmap时将MAP_NOCACHE标志传递给mmap函数来实现。 MAP_NOCACHE标志告诉内核不要将映射的内存页缓存到文件系统缓存中&#xff…

设置UIProgressView的样式

UIProgressView是UIKit框架中的一个控件&#xff0c;用于显示任务的完成进度。你可以使用UIProgressView来展示任务的完成情况&#xff0c;例如下载文件、上传数据等。 要设置UIProgressView的样式&#xff0c;包括粗细、颜色等&#xff0c;你可以使用UIProgressView的一些属性…

Android 安装过程三 MSG_ON_SESSION_SEALED、MSG_STREAM_VALIDATE_AND_COMMIT的处理

Android 安装过程一 界面跳转 知道&#xff0c;在InstallInstalling Activity中&#xff0c;PackageInstallerSession对象创建之后&#xff0c;接着会打开它&#xff0c;然后将安装文件进行拷贝&#xff0c;拷贝完成之后&#xff0c;会对Session对象确认。   从Session对象确…

QT-QTCreator环境配置

准备工作&#xff1a; 下载QT: 链接&#xff1a;https://pan.baidu.com/s/1prJcsC4DGqhKiXvLuPQFVA?pwd60b3 提取码&#xff1a;60b3下载WindowsKits&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1QNiS3HpbH5M5kXx5AhkqnQ?pwde2h8 提取码&#xff1a;e2h8安装的…

微信小程序实现九宫格

微信小程序使用样式实现九宫格布局 使用微信小程序实现九宫格样式&#xff0c;可以直接使用样式进行编写&#xff0c;具体图片如下&#xff1a;1、js代码&#xff1a; Page({/*** 页面的初始数据*/data: {current: 4},// 监听activeClick(e) {let index e.currentTarget.dat…