I’m continuing to mess with NixOS-Pi on BTRFS subvolume-based compressed root. It seems like it would be a lot easier if I could get it working with qemu – I’ve burned through several SD cards over the last year+ on this project, and I’m tired of burning, walking across the room to the Pi, unplugging, replugging, etc.
Unfortunately I can’t get keyboard or network / SSH access to work.
The host I’m running from is arch linux, x86_64.
My setup process is basically:
$ wget 'https://hydra.nixos.org/build/182205320/download/1/nixos-sd-image-22.05.1322.915f5a5b3cc-aarch64-linux.img.zst'
$ zstd -d nixos-sd-image-22.05.1322.915f5a5b3cc-aarch64-linux.img.zst
$ qemu-img resize -f raw nixos-sd-image-22.05.1322.915f5a5b3cc-aarch64-linux.img 4G
$ mv nixos-sd-image-22.05.1322.915f5a5b3cc-aarch64-linux.img nixos-22.05.img
Next, I mount the image and copy u-boot-rpi3.bin
from partition 1, and bcm2837-rpi-3-b.dtb
from /boot/nixos/0s76maj95yj311viyg7yhrrp300ag8s6-linux-5.15.49-dtbs/broadcom/
.
Finally, I run this:
#!/usr/bin/env bash
# nixos.sh
# $ qemu-system-aarch64 --version
# QEMU emulator version 7.0.0
# Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
set -Eeuf -o pipefail
set -x
main() {
local img=${1:-./nixos-22.05.img}
qemu-system-aarch64 \
-M raspi3b \
-dtb ./bcm2837-rpi-3-b.dtb \
-m 1G \
-smp 4 \
-drive "format=raw,file=${img}" \
-kernel ./u-boot-rpi3.bin \
-device usb-net,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
-usb -device usb-host,hostbus=1,hostaddr=2 \
-append "console=ttyAMA0 root=/dev/mmcblk0p2 rw rootwait" \
-serial stdio
}
main "$@"
I see what looks like a pretty normal boot process which eventually gets to a login prompt.
At the login prompt, my USB keyboard doesn’t seem to work (I’ve confirmed those bus numbers), but it does get stuck in the qemu window; I have to SSH into the host from another machine and run this to get my keyboard back:
$ sudo sh -c 'echo 0000:01:00.0 > /sys/bus/pci/drivers/xhci_hcd/unbind'
$ sudo sh -c 'echo 0000:01:00.0 > /sys/bus/pci/drivers/xhci_hcd/bind'
What I’d really like is to get SSH access, but that doesn’t work either. ssh -vvv -p 2222 root@localhost
shows me:
...
debug1: Connecting to localhost [127.0.0.1] port 2222.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: Connection established.
...
but then hangs there. In the window running qemu
, every time I attempt SSH I see:
qemu: Slirp: Failed to send packet, ret: -1
Lots of googling but no answers that I can find. Disabling the firewall on the host makes no difference.
Also tried the dtb for the 3b-plus, as well as the ones directly from raspberrypi/firmware, no difference with any of these that I can tell.
Any ideas? Anyone have SSH access working with an emulated aarch64 image?
Maybe it’s just a problem with the -M raspi3b
or the dtb files or something?