Открытая архитектура RISC-V воодушевляет, но еще предстоит проделать большую работу, чтобы довести экосистему до уровня Arm или архитектуры x86, от кремния до программного обеспечения. Прогресс осуществляется поэтапно, и одним из этих шагов — выпуск Canonical 64-битных образов RISC-V (RISCV64) Ubuntu для некоторых плат SiFive HiFive, а также эмулятора QEMU с открытым исходным кодом.
В частности, Canonical выпустила образ Ubuntu 20.04.2 LTS для HiFive Unleashed и QEMU и образ Ubuntu 21.04 для HiFive Unleashed, HiFive Unmatched и QEMU. Обратите внимание, что это только образы серверов, и еще нет образа рабочего стола, как для Ubuntu 21.04 на Raspberry Pi 2/3/4.
В QEMU можно было запускать RISC-V Linux по крайней мере в течение трех лет, но когда мы попробовали, это была минимальная система, основанная на Busybox, поэтому давайте попробуем еще раз с Ubuntu 21.04, следуя инструкциям, приведенным в Discourse .
У нас есть ноутбук AMD Ryzen под управлением Ubuntu 20.04, открываем окно терминала, чтобы сначала установить зависимости.
sudo apt install qemu-system-misc opensbi u-boot-qemu qemu-utils
затем загружаем и извлекаем образ Ubuntu 21.04 для HiFive Unmatched:
wget https://cdimage.ubuntu.com/releases/21.04/release/ubuntu-21.04-preinstalled-server-riscv64+unmatched.img.xz
xz -dk ubuntu-21.04-preinstalled-server-riscv64+unmatched.img.xz
Теперь мы можем установить Ubuntu 21.04 RISCV64 на нашем компьютере:
qemu-system-riscv64 -machine virt -nographic -m 2048 -smp 1 -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 -drive file=ubuntu-21.04-preinstalled-server-riscv64+unmatched.img,format=raw,if=virtio
Но резко останавливается:
OpenSBI v0.8
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : riscv-virtio,qemu
Platform Features : timer,mfdeleg
Platform HART Count : 1
Boot HART ID : 0
Boot HART ISA : rv64imafdcsu
BOOT HART Features : pmp,scounteren,mcounteren
BOOT HART PMP Count : 16
Firmware Base : 0x80000000
Firmware Size : 92 KB
Runtime SBI Version : 0.2
MIDELEG : 0x0000000000000222
MEDELEG : 0x000000000000b109
PMP0 : 0x0000000080000000-0x000000008001ffff (A)
PMP1 : 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.10+dfsg-1ubuntu0~20.04.2 (Jan 08 2021 - 13:03:11 +0000)
CPU: rv64imafdcsu
Model: riscv-virtio,qemu
DRAM: 2 GiB
In: uart@10000000
Out: uart@10000000
Err: uart@10000000
Net: eth0: virtio-net#0
Hit any key to stop autoboot: 0
Device 0: 1af4 VirtIO Block Device
Type: Hard Disk
Capacity: 3584.0 MB = 3.5 GB (7340032 x 512)
... is now current device
Scanning virtio 0:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
743 bytes read in 5 ms (144.5 KiB/s)
U-Boot menu
1: Ubuntu 21.04 5.11.0-1007-generic
2: Ubuntu 21.04 5.11.0-1007-generic (rescue target)
Enter choice: 1
1: Ubuntu 21.04 5.11.0-1007-generic
Retrieving file: /boot/initrd.img-5.11.0-1007-generic
182268553 bytes read in 269 ms (646.2 MiB/s)
Retrieving file: /boot/vmlinuz-5.11.0-1007-generic
27355136 bytes read in 50 ms (521.8 MiB/s)
append: root=LABEL=cloudimg-rootfs ro earlycon
Unhandled exception: Load access fault
EPC: 00000000fffb6b26 RA: 00000000fff74b14 TVAL: 0000000000000000
EPC: 0000000080249b26 RA: 0000000080207b14 reloc adjusted
### ERROR ### Please RESET the board ###
Это связано с тем, что Ubuntu 21.04 Hirsute не может загружаться с версией u-boot-qemu, представленной в Ubuntu 20.04, в настоящее время, поддерживается только версия в Ubuntu 21.04. Итак, попробуем вместо этого образ Ubuntu 20.04 RISC-V:
wget https://cdimage.ubuntu.com/releases/20.04.2/release/ubuntu-20.04.2-preinstalled-server-riscv64.img.xz
xz -dk ubuntu-20.04.2-preinstalled-server-riscv64.img.xz
qemu-system-riscv64 -machine virt -nographic -m 2048 -smp 2 -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 -drive file=ubuntu-20.04.2-preinstalled-server-riscv64.img,format=raw,if=virtio
Отлично! Через несколько минут мы можем получить доступ к командной строке, используя имя пользователя и пароль «ubuntu»:
OpenSBI v0.8
____ _____ ____ _____
/ __ \ / ____| _ \_ _|
| | | |_ __ ___ _ __ | (___ | |_) || |
| | | | '_ \ / _ \ '_ \ \___ \| _ < | |
| |__| | |_) | __/ | | |____) | |_) || |_
\____/| .__/ \___|_| |_|_____/|____/_____|
| |
|_|
Platform Name : riscv-virtio,qemu
Platform Features : timer,mfdeleg
Platform HART Count : 2
Boot HART ID : 1
Boot HART ISA : rv64imafdcsu
BOOT HART Features : pmp,scounteren,mcounteren
BOOT HART PMP Count : 16
Firmware Base : 0x80000000
Firmware Size : 100 KB
Runtime SBI Version : 0.2
MIDELEG : 0x0000000000000222
MEDELEG : 0x000000000000b109
PMP0 : 0x0000000080000000-0x000000008001ffff (A)
PMP1 : 0x0000000000000000-0xffffffffffffffff (A,R,W,X)
U-Boot 2020.10+dfsg-1ubuntu0~20.04.2 (Jan 08 2021 - 13:03:11 +0000)
CPU: rv64imafdcsu
Model: riscv-virtio,qemu
DRAM: 2 GiB
In: uart@10000000
Out: uart@10000000
Err: uart@10000000
Net: eth0: virtio-net#0
Hit any key to stop autoboot: 0
Device 0: 1af4 VirtIO Block Device
Type: Hard Disk
Capacity: 3584.0 MB = 3.5 GB (7340032 x 512)
... is now current device
Scanning virtio 0:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
631 bytes read in 2 ms (307.6 KiB/s)
U-Boot menu
1: Ubuntu 20.04.2 LTS 5.8.0-14-generic
2: Ubuntu 20.04.2 LTS 5.8.0-14-generic (rescue target)
Enter choice: 1
1: Ubuntu 20.04.2 LTS 5.8.0-14-generic
Retrieving file: /boot/initrd.img-5.8.0-14-generic
160037936 bytes read in 250 ms (610.5 MiB/s)
Retrieving file: /boot/vmlinuz-5.8.0-14-generic
20094612 bytes read in 47 ms (407.7 MiB/s)
append: root=LABEL=cloudimg-rootfs ro earlycon
Moving Image from 0x84000000 to 0x80200000, end=81622f80
## Flattened Device Tree blob at ff74bea0
Booting using the fdt blob at 0xff74bea0
Using Device Tree in place at 00000000ff74bea0, end 00000000ff74fe1d
Starting kernel ...
...
-----END SSH HOST KEY KEYS-----
[ 263.760272] cloud-init[665]: Cloud-init v. 20.4.1-0ubuntu1~20.04.1 running 'modules:final' at Mon, 28 Jun 2021 04:36:41 +0000. Up 257.45 seconds.
[ 263.773658] cloud-init[665]: ci-info: no authorized SSH keys fingerprints found for user ubuntu.
[ 263.782580] cloud-init[665]: Cloud-init v. 20.4.1-0ubuntu1~20.04.1 finished at Mon, 28 Jun 2021 04:36:47 +0000. Datasource DataSourceNoCloud [seed=/var/lib/cloud/seed/nocloud-net][dsmode=net]. Up 263.41 seconds
Ubuntu 20.04.2 LTS ubuntu ttyS0
ubuntu login: ubuntu
Password:
You are required to change your password immediately (administrator enforced)
Changing password for ubuntu.
Current password:
New password:
Retype new password:
Bad: new password is too simple
New password:
Retype new password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-14-generic riscv64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon Jun 28 04:37:40 UTC 2021
System load: 1.08
Usage of /: 76.8% of 3.22GB
Memory usage: 8%
Swap usage: 0%
Processes: 90
Users logged in: 0
IPv4 address for eth0: 10.0.2.15
IPv6 address for eth0: fec0::5054:ff:fe12:3456
0 updates can be installed immediately.
0 of these updates are security updates.
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
ubuntu@ubuntu:~$
Мы действительно находимся в двухъядерной 64-битной системе RISC-V, мы использовали параметр «smp 2» в командной строке:
ubuntu@ubuntu:~$ cat /proc/cpuinfo
processor : 0
hart : 1
isa : rv64imafdcsu
mmu : sv48
processor : 1
hart : 0
isa : rv64imafdcsu
mmu : sv48
У нас есть Ethernet, работающий нормально:
ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
valid_lft 79022sec preferred_lft 79022sec
inet6 fec0::5054:ff:fe12:3456/64 scope site dynamic mngtmpaddr noprefixroute
valid_lft 86299sec preferred_lft 14299sec
inet6 fe80::5054:ff:fe12:3456/64 scope link
valid_lft forever preferred_lft forever
Таким образом, мы смогли подключиться к главному компьютеру по SSH, но не смогли подключиться к сеансу QEMU по SSH. Поэтому мы выключили Ubuntu RISC-V, добавили перенаправление TCP, чтобы включить SSH на порт 2222, и перезапустили QEMU.
qemu-system-riscv64 -machine virt -nographic -m 2048 -smp 1 -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-net-device,netdev=eth0 -netdev user,id=eth0,hostfwd=tcp::2222-:22 -drive file=ubuntu-20.04.2-preinstalled-server-riscv64.img,format=raw,if=virtio
Нам удалось войти в QEMU через SSH следующим образом:
jaufranc@cnx-laptop-4:~/edev/sandbox/ubuntu-risc-v$ ssh -p 2222 ubuntu@localhost
The authenticity of host '[localhost]:2222 ([127.0.0.1]:2222)' can't be established.
ECDSA key fingerprint is SHA256:XvWsfVDD4C4qaH0g1VU1mY47+tcGx6E0GRVjX5mORvM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[localhost]:2222' (ECDSA) to the list of known hosts.
ubuntu@localhost's password:
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.8.0-14-generic riscv64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon Jun 28 07:08:20 UTC 2021
System load: 0.18
Usage of /: 78.3% of 3.22GB
Memory usage: 8%
Swap usage: 0%
Processes: 81
Users logged in: 1
IPv4 address for eth0: 10.0.2.15
IPv6 address for eth0: fec0::5054:ff:fe12:3456
0 updates can be installed immediately.
0 of these updates are security updates.
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Mon Jun 28 07:05:11 2021
ubuntu@ubuntu:~$
Таким образом, можно легко передавать файлы между QEMU и хост-устройством в любом направлении.
Выражаем свою благодарность источнику из которого взята и переведена статья, сайту cnx-software.com.
Оригинал статьи вы можете прочитать здесь.