Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get networking in Native emulation. #131

Open
Jugulaire opened this issue Jun 5, 2021 · 5 comments
Open

Unable to get networking in Native emulation. #131

Jugulaire opened this issue Jun 5, 2021 · 5 comments

Comments

@Jugulaire
Copy link

Hey !

I have successfully started Raspbian in QEMU with this command :

sudo /usr/local/bin/qemu-system-aarch64 -M raspi3 -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" -dtb '/home/jugu/SSD/home/jugu/VM-HDD/raspbian/qemu-rpi-kernel/native-emulation/dtbs/bcm2710-rpi-3-b-plus.dtb' -sd '/home/jugu/SSD/home/jugu/VM-HDD/raspbian/raspbian.qcow2' -kernel "/home/jugu/SSD/home/jugu/VM-HDD/raspbian/qemu-rpi-kernel/native-emulation/5.4.51 kernels/kernel8.img" -m 1G -smp 4 -serial stdio -usb -device usb-mouse -device usb-kbd

But i'm unable to get networking inside this box. I've followed the QEMU guide, but I cannot figure out.
Did someone have successfully booted a native emulated raspbian with networking enabled ?

Thanks in advance.

@Jugulaire
Copy link
Author

I have some result.

Here is what i did :

  1. Get 2021-01-11-raspios-buster-armhf image (MUST BE THIS ONE)
  2. Extract the dtd and kernel file (follow this part to do this.
  3. Resized the img file qemu-img resize -f raw raspbian.img 8G
  4. Botted using this exact command qemu-system-aarch64_6 -M raspi3 -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootdelay=1" -dtb '/home/jugu/SSD/home/jugu/VM-HDD/raspbian/Emulation_pi3/bcm2710-rpi-3-b-plus.dtb' -sd '/home/jugu/SSD/home/jugu/VM-HDD/raspbian/Emulation_pi3/raspbian.img' -kernel '/home/jugu/SSD/home/jugu/VM-HDD/raspbian/Emulation_pi3/kernel8.img' -m 1G -smp 4 -serial stdio -usb -device usb-mouse -device usb-kbd -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22

Now i'm able to get networking inside the virtual Pi and i'm able to log in ssh. So now i can do port forwarding if required to test stuff thru SSH.

@Jugulaire
Copy link
Author

But now i'm wondering if it's possible to connect my qemu RPI to my local bridge to have full networking since my port frowarding are limited to SSH with this techinque.

@ptrsr
Copy link

ptrsr commented Jun 10, 2021

You should be able to create a network tap using QEMU. Then use bridge-utils to bridge your network and tap interface.

The reason why networking does not work with all distro images is because (native) ethernet emulation is done through a virtual USB ethernet adapter. This adapter requires kernel modules USB_ETH and USB_DWC2, that are installed under /lib/modules in the root partition. I believe that these modules have to match the (external) kernel version, which is why a lot of images are not supported.

@Radoom
Copy link

Radoom commented Jul 5, 2021

I'm trying to get a special raspi image to boot (eblocker-2.6). It won't start with the way Jugulaire shows above (thanks!). So I first repeated what Jugulaire did, with the same raspbian image/version mentioned above - that works fine, i.e. with the image "2021-01-11-raspios-buster-armhf".
I also tried a more recent image "2021-05-07-raspios-buster-armhf", but that one does not start at all.
Same for the "eblocker" image.

I then used the kernel (5.4.83-v8+) and dtb extracted from the "2021-01-11" image in conjunction with the eblocker-2.6 image. THAT combination then boots. But eblocker then misses its network, because it tries to load the respective module from the kernel version folders it was booted with (5.4.83-v8+) - which of course differ from those in the image itself (5.10.17 something).

So, it seems to heavily depend on what kernel version is used with qemu, even though all three images tested are dedicated raspi-3 compatible images. Anyone got a clue what distinguishes the 2021-01-11 / 5.4.83-v8+ kernel from the one in the 2021-05-07 image? (edit: I mean, sure, a ton of things; but what might be relevant for qemu (not) even booting the first few basic steps?) Would like to know what causes the one to work with qemu but not the other.

@markostamcar
Copy link

markostamcar commented Nov 28, 2021

Just to add my experience:

  • On Windows 10 I managed to get it to work using QEMU 5.1.0 (qemu-w64-setup-20200814) - did not work with the latest QEMU - the guest even has internet access 👍
  • Don't be like me and forget to enable ssh using raspi-config or touch /boot/ssh :)
  • It even works with the 64-bit RPi OS (2021-10-30-raspios-bullseye-arm64-lite) - though there was no framebuffer image, but I didn't need it anyway (note: emulation & I/O was very slow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants