How can I force make to build without graphic support? - makefile

On redox-os I have to run make qemu to run redox-os.
But I need to run it without graphic support, make qemu -nographic or make qemu -curses is not supported.
nasm -f bin -o build/harddrive.bin -D ARCH_x86_64 -ibootloader/x86_64/ bootloader/x86_64/harddrive.asm
SDL_VIDEO_X11_DGAMOUSE=0 qemu-system-x86_64 -serial mon:stdio -d cpu_reset -d guest_errors -smp 4 -m 1024 -machine q35 -net nic,model=e1000 -net user -net dump,file=build/network.pcap -device nec-usb-xhci,id=xhci -device usb-tablet,bus=xhci.0 -drive file=build/harddrive.bin,format=raw
Unable to init server: Could not connect: Connection refused
gtk initialization failed
make: *** [mk/qemu.mk:32: qemu] Error 1

Launch using QEMU without using KVM (Kernel Virtual Machine) nor Graphics
make qemu kvm=no vga=no
Just added at Redox-os by me

Related

qemu-system-x86_64 No bootable device. ARM M2 processor. mit6.858

I'm learning the mit6.858. In Lab1, I need to set up the lab environment on my M2 Mac using qemu (version 7.2.0 installed by homebrew).
I follow the instruction of the lab hints and run the course VM Image with this shell scripts:
#!/bin/bash
if ! command -v qemu-system-x86_64 > /dev/null; then
echo "You do not have QEMU installed."
echo "If you are on a Linux system, install QEMU and try again."
echo "Otherwise, follow the lab instructions for your OS instead of using this script."
exit
fi
# can we use the -nic option?
version=$(qemu-system-x86_64 --version \
| grep 'QEMU emulator version' \
| sed 's/QEMU emulator version \([0-9]\)\.\([0-9]\).*/\1.\2/')
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
net=()
if (( major > 2 || major == 2 && minor >= 12 )); then
net=("-nic" "user,ipv6=off,model=virtio,hostfwd=tcp:127.0.0.1:2222-:2222,hostfwd=tcp:127.0.0.1:8080-:8080,hostfwd=tcp:127.0.0.1:8888-:8888")
else
net=("-netdev" "user,id=n1,ipv6=off,hostfwd=tcp:127.0.0.1:2222-:2222,hostfwd=tcp:127.0.0.1:8080-:8080,hostfwd=tcp:127.0.0.1:8888-:8888" "-device" "virtio-net,netdev=n1")
fi
qemu-system-x86_64 \
-m 2048 \
-nographic -serial mon:stdio \
"$#" \
# -enable-kvm \
"${net[#]}" \
6.858-x86_64-v22.vmdk
But I got this output:
SeaBIOS (version rel-1.16.1-0-g3208b098f51a-prebuilt.qemu.org)
iPXE (http://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+7EFD11A0+7EF311A0 CA00
Booting from Hard Disk...
Boot failed: could not read the boot disk
Booting from Floppy...
Boot failed: could not read the boot disk
Booting from DVD/CD...
Boot failed: Could not read from CDROM (code 0003)
Booting from ROM...
iPXE (PCI 00:03.0) starting execution...ok
iPXE initialising devices...ok
iPXE 1.20.1+ (g4bd0) -- Open Source Network Boot Firmware -- http://ipxe.org
Features: DNS HTTP iSCSI TFTP AoE ELF MBOOT PXE bzImage Menu PXEXT
net0: 52:54:00:12:34:56 using 82540em on 0000:00:03.0 (open)
[Link:up, TX:0 TXE:0 RX:0 RXE:0]
Configuring (net0 52:54:00:12:34:56)...... ok
net0: 10.0.2.15/255.255.255.0 gw 10.0.2.2
Nothing to boot: No such file or directory (http://ipxe.org/2d03e13b)
No more network devices
No bootable device.
When I type ctrlA+X to quit, I got another lines of output.
QEMU: Terminated
./6.858-x86_64-v22.sh: line 30: -nic: command not found
My homebrew installation is correct.
I'd like to know how to start the course VM correctly on M2 mac.
So, at first glance this looked off-topic as not a programming question as such (running Qemu is more of a superuser.com or serverfault.com question, or perhaps apple.stackexchange.com as we're talking about running Qemu on macOS), but looking more closely, your problem appears to be a bash scripting one, which makes it on topic again!
The clues
One thing you don't explicitly mention in your question is that you modified the script, attempting to comment out this line:
# -enable-kvm \
(The reason to remove that flag is because kvm is not available on macOS hosts, and the alternative, hvf, is not available when using binary translation to run an x86-64 VM on an arm64 host CPU.)
Another clue to the problem is this error:
./6.858-x86_64-v22.sh: line 30: -nic: command not found
What's happened here is that the backslashes (\) at the end of each of these lines in the original script turn the multi-line block into a single line:
qemu-system-x86_64 \
-m 2048 \
-nographic -serial mon:stdio \
"$#" \
-enable-kvm \
"${net[#]}" \
6.858-x86_64-v22.vmdk
Unfortunately, when commenting a line with #, bash ignores any backslash at the end of the line - this interrupts and splits the multi-line command.
This means that your networking and disk image command line options are not making it into the qemu command line, which in turn is why it can't find the virtual disk image. The -nic error comes from treating the following as a new command:
"${net[#]}" \
6.858-x86_64-v22.vmdk
Solution:
Don't comment out the flag -enable-kvm \ in place: either remove the line entirely, or move it out of the command and comment it out there.

Running u-boot hello_world on an image partition with qemu

I'm developing on an ubuntu x86 machine, trying to run the u-boot hello_world standalone application which resides on an image sd.img which contains a partition.
I've compiled u-boot (v2022.10) with qemu-x86_64_defconfig
I run qemu with qemu-system-x86_64 -m 1024 -nographic -bios u-boot.rom -drive format=raw,file=sd.img
u-boot starts up, doesn't find a script, doesn't detect tftp, and awaits a command. If I type ext4ls ide 0:1, I can clearly see hello_world.bin (3932704 hello_world.bin).
When I do a ext4load ide 0:1 0x40000 hello_world.bin (in preparation for go 40000 This is another test), qemu/u-boot restarts.
0x40000 is the CONFIG_STANDALONE_LOAD_ADDR for x86.
I have even tried making an image of hello_world mkimage -n "Hello stand alone" -A x86_64 -O u-boot -T standalone -C none -a 0x40000 -d hello_world.bin -v hello_world.img and tried to load the image into 0x40000 with the intention of using bootm in case of cache issues - qemu/u-boot still resets.
Could anyone possibly point out the basic mistake I'm making.
Cheers
The memory area 0xa0000-0xffffff is reserved and you are overwriting it when loading your 4 MiB file to 040000 due to the excessive size of the file.
If you build hello_world.bin correctly, it will be a few kilobytes.

Docker on Windows: how to do tftp with Linux container?

I have:
Windows 10
Docker for Windows with WSL2 integration (using Ubuntu 20.04)
I created a simple tftpd server to run in a Linux (Ubuntu 16.04) container and exposed port 69. Here is the Dockerfile:
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install --no-install-recommends -y \
tftpd-hpa \
nfs-kernel-server && \
# Clean rootfs
apt-get clean all && \
apt-get autoremove -y && \
apt-get purge && \
rm -rf /var/lib/{apt,dpkg,cache,log}
# Export the TFTP server port
EXPOSE 69/udp
WORKDIR /
VOLUME ["/var/lib/tftpboot"]
VOLUME ["/nfs"]
VOLUME ["/etc/dhcp"]
VOLUME ["/etc/default"]
COPY entrypoint.sh /entrypoint.sh
# Set correct entrypoint permission
RUN chmod u+x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
The script extrypoint.sh just start the tftd-hpa service on start-up and then waits until C+C is pressed:
service tftpd-hpa start
echo "Started..."
while true; do sleep 1; done
I spin up a container using a Powershell script this:
docker run --rm -ti --privileged `
-p 69:69/udp `
-v ${PWD}/tftp:/var/lib/tftpboot `
-v ${PWD}/nfs:/nfs `
-v ${PWD}/etc/exports:/etc/exports `
-v ${PWD}/etc/default/nfs-kernel-server:/etc/default/nfs-kernel-server `
-v ${PWD}/etc/network/interfaces:/etc/network/interfaces `
nfs_tftp_server:latest;
As you can see, I am mapping port 69 in the container to 69 on the host. When I do netstat -an | find "UDP" in a command window, I do see entries for port 69. This seems to indicate the port is okay. I checked the status of the tftpd-hpa service in the container, and it is running.
I changed the Firewall settings to allow inbound and outbound traffic on port 69. I also updated the firewall to allow the Trivial File Transfer Protocol App (TFTP.EXE) to communicate through it.
The problem is when I try to do tftp:
tftp 0.0.0.0 GET test.txt
it just hangs and times out. The file does exist.
Why doesn't it work? When I try the same in my Ubuntu Virtual Machine, it works. So this must be related to Docker on Windows.

How to connect and use the camera in a docker container on MacOS with Docker Desktop [duplicate]

I'm not sure that this is even possible, but is there a way to access my camera inside docker container? I'm not using external camera but built-in in my mac.
I'm not sure that the flag volume (-v) is the best practice to do so.
According to the github of jfrazelle, docker engineer who wrote many Dockerfile and docker run for many graphical app such as chromium, skype, spotify, and so on, the flag and argument you should use is --device /dev/video0.
For quick test(tested on ubuntu), below code should give supported frame resolution of cameras:-
docker run --rm -it --entrypoint /bin/bash --device /dev/video0 jrottenberg/ffmpeg
ffmpeg -f video4linux2 -list_formats all -i /dev/video0
You can try to forward your webcam device using -v flag
Something like
sudo docker run -d -p 55555:22 --privileged -v /dev/video0:/dev/video0 testimage
To list all devices attached to USB use lsusb ; to list all devices attached to PCI use lspci
On MacOS, it can be a bit tricky:
Install legacy docker virtualization engine for Docker Desktop on Mac (which uses Oracle Virtual Box)
Install Virtual Box
Install Virtual Box Extension pack
Install Docker Toolbox (reading this is strongly recommended & backuping your /usr/local/bin/docker* before is also recommended)
Ensure that /usr/local/bin/docker and /usr/local/bin/docker-compose link to Docker Desktop binaries (/Applications/Docker.app/Contents/Resources), and not Docker Toolbox
Test everything is still working: docker ps -a and docker images should display what you already had in Docker Desktop, docker-machine ls should not raise an error
brew install socat
brew install xquartz
Setting: XQuartz Preferences > Security > check allow all (Allow connections from network clients)
defaults write org.macosforge.xquartz.X11 enable_iglx -bool true
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $IP
docker-machine create -d virtualbox --virtualbox-cpu-count=4 --virtualbox-memory=4096 --virtualbox-disk-size=1000000 --virtualbox-boot2docker-url https://github.com/gzupark/boot2docker-webcam-mac/releases/download/18.06.1-ce-usb/boot2docker.iso default
docker-machine stop default
Open Virtual Box app & configure the VirtualBox VM that has just been created with docker-machine
Display > Video memory (max)
Display > Acceleration > Enable 3D acceleration (check)
Ports > USB > Enable USB controller (check) > USB 2.0 (select)
Shared folders > Add > Folder Path = / & Folder name = host-root
Reboot macOS
Open a terminal (T1), and type
open -a XQuartz
If it does not open another terminal, focus XQuartz app, and Applications > Terminal
Now a new terminal is opened (T2)
On T2: socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
if it complains about "Address already in use", check with lsof -i tcp:6000 that owning process is X11.bin, otherwise kill owning process and try running socat again (always on T2)
On T1 again
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $IP
docker-machine start default
eval $(docker-machine env default)
vboxmanage list webcams
Identify in the list your webcam (eg mine was .1)
vboxmanage controlvm default webcam attach .1
(You may need to open VirtualBox again, double click on your VM, which will open a view of your system, and then Devices > Webcam > <select your camera>)
You should now be able to access your camera in a container.
Test XQuartz with
docker run --rm -it -e DISPLAY=$IP:0 gns3/xeyes
Test camera with
docker run --rm -it -e DISPLAY=$IP:0 --device=/dev/video0:/dev/video0 -v /tmp/.X11-unix:/tmp/.X11-unix ubuntu
apt update && apt install -y streamer
streamer -f jpeg -o image.jpeg
Tip
Shutdown your greedy VM process with: VBoxManage controlvm thevm acpipowerbutton
Big thanks to:
https://github.com/GzuPark/boot2docker-webcam-mac
https://medium.com/#jijupax/connect-the-webcam-to-docker-on-mac-or-windows-51d894c44468
https://askubuntu.com/a/106773
https://apple.stackexchange.com/a/277029
Additional notes:
https://apple.stackexchange.com/a/277029
https://docs.docker.com/docker-for-mac/docker-toolbox/#docker-toolbox-and-docker-desktop-coexistence
https://docs.docker.com/docker-for-mac/docker-toolbox/

QEMU kernel for raspberry pi 3 with networking and virtio support [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 months ago.
Improve this question
I used the QEMU(qemu-system-aarch64 -M raspi3) for emulating the Raspberry pi3 with the kernel from the working image. Everything was working but there was no networking.
qemu-system-aarch64 \
-kernel ./bootpart/kernel8.img \
-initrd ./bootpart/initrd.img-4.14.0-3-arm64 \
-dtb ./debian_bootpart/bcm2837-rpi-3-b.dtb \
-M raspi3 -m 1024 \
-nographic \
-serial mon:stdio \
-append "rw earlycon=pl011,0x3f201000 console=ttyAMA0 loglevel=8 root=/dev/mmcblk0p3 fsck.repair=yes net.ifnames=0 rootwait memtest=1" \
-drive file=./genpi64lite.img,format=raw,if=sd,id=hd-root \
-no-reboot
I tried to add this option
-device virtio-blk-device,drive=hd-root \
-netdev user,id=net0,hostfwd=tcp::5555-:22 \
-device virtio-net-device,netdev=net0 \
But there would be an error
qemu-system-aarch64: -device virtio-blk-device,drive=hd-root: No 'virtio-bus' bus found for device 'virtio-blk-device'
I have referenced some forum, and used the "virt" machine instead of raspi3 in order of emulating virtio-network
qemu-system-aarch64 \
-kernel ./bootpart/kernel8.img \
-initrd ./bootpart/initrd.img-4.14.0-3-arm64 \
-m 2048 \
-M virt \
-cpu cortex-a53 \
-smp 8 \
-nographic \
-serial mon:stdio \
-append "rw root=/dev/vda3 console=ttyAMA0 loglevel=8 rootwait fsck.repair=yes memtest=1" \
-drive file=./genpi64lite.img,format=raw,if=sd,id=hd-root \
-device virtio-blk-device,drive=hd-root \
-netdev user,id=net0,net=192.168.1.1/24,dhcpstart=192.168.1.234 \
-device virtio-net-device,netdev=net0 \
-no-reboot
There is nothing printed and the terminal was suspended. It means the kernel does not work with virt machine.
I decided to build for my own custom kernel. Could anyone give me advice for options to build the kernel that works with both the QEMU and the virtio?
Thanks in advance!
The latest versions of QEMU (5.1.0 and 5.0.1) have USB emulation for the raspi3 machine (qemu-system-aarch64 -M raspi3).
You can emulate networking and access to SSH if you use: -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22 in QEMU
I tested this configuration, and I got this:
The USB network device in QEMU raspi3
Ethernet interface in QEMU raspi3
Here the full command and options that I used:
qemu-system-aarch64 -m 1024 -M raspi3 -kernel kernel8.img -dtb bcm2710-rpi-3-b-plus.dtb -sd 2020-08-20-raspios-buster-armhf.img -append "console=ttyAMA0 root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4" -nographic -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22
The QEMU version used was 5.1.0.
I have had the same problems as user #peterbabic, in that while I could see the gadget with lsusb, I could not see any net device.
So I tried manually inserting the appropriate module g_ether -- and it said that it could not find the driver.
It was then that I realized that the kernelv8.img file I had downloaded and the Raspbian OS image that I was booting were different versions, so the kernel could not find its modules because it looked for them in the wrong directory.
On the other hand, the Raspbian OS image had the correct kernel in its first partition (I could see it in /boot). The only problem was getting it out and use it to replace the wrong kernelv8.img (I could not find the correct one online -- and anyway, the kernel of the Raspbian image is by definition more correct).
So, I copied the Raspbian OS image on my Linux box, and mounted it with loop:
# fdisk raspbian.img
- command "p" lists partitions and tells me that P#1 starts at sector 2048
- command "q" exits without changes
# losetup -o $[ 2048 * 512 ] /dev/loop9 raspbian.img # because sectors are 512 bytes
# mkdir /mnt/raspi
# mount /dev/loop9 /mnt/raspi
- now "ls -la /mnt/raspi" shows the content of image partition 1, with kernels
# cp /mnt/raspi/kernel8.img .
# umount /mnt/raspi
# losetup -d /dev/loop9 # destroy loop device
# rmdir /mnt/raspi # remove temporary mount point
# rm raspbian.img
- I no longer need the raspbian.img copy so I delete it.
- now current directory holds "kernel8.img". I can just copy it back.
To be sure, I also modified /boot/cmdline.txt on the Raspberry image (before rebooting with the new kernel) so that it now added the dwc and g_ether modules:
On boot, the gadget is now automatically recognized:
Your raspi3 command line has no networking because on a raspi3 the networking is via USB, and QEMU doesn't have a model of the USB controller for that board yet. Adding virtio-related options won't work, because the raspi3 has no PCI and so there's no way to plug in a pci virtio device.
Your command line option with virt looks basically right (at least enough so to boot; you probably want "if=none" rather than "if=sd" and I'm not sure if the network options are quite right, but if those parts are wrong they will result in errors from the guest kernel later rather than total lack of output). So your problem is likely that the kernel config is missing some important items.
You can boot a stock Debian kernel on the virt board (instructions here: https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/) so one approach you could take to finding the error in your kernel config is to compare your config with the one the Debian kernel has. The upstream kernel source 'defconfig' also should work. I find that starting with a configm that works and cutting it down is faster than building one up from nothing by trying to find all the obscure options that need to be present.
I've updated the steps needed to get this working with April 4th Raspios
# wget https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2022-04-07/2022-04-04-raspios-bullseye-arm64-lite.img.xz
# unxz 2022-04-04-raspios-bullseye-arm64-lite.img.xz
# mkdir boot
# mount -o loop,offset=4194304 2022-04-04-raspios-bullseye-arm64-lite.img boot
# cp boot/bcm2710-rpi-3-b-plus.dtb kernel8.img .
# echo 'pi:$6$6jHfJHU59JxxUfOS$k9natRNnu0AaeS/S9/IeVgSkwkYAjwJfGuYfnwsUoBxlNocOn.5yIdLRdSeHRiw8EWbbfwNSgx9/vUhu0NqF50' > boot/userconf
# umount boot
# qemu-img convert -f raw -O qcow2 2022-04-04-raspios-bullseye-arm64-lite.img 2022-04-04-raspios-bullseye-arm64-lite.qcow2
# qemu-img resize 2022-04-04-raspios-bullseye-arm64-lite.qcow2 4g
Then run Qemu 7.1.0 this way:
# qemu-system-aarch64 -m 1024 -M raspi3b -kernel kernel8.img \
-dtb bcm2710-rpi-3-b-plus.dtb -sd 2022-04-04-raspios-bullseye-arm64-lite.qcow2 \
-append "console=ttyAMA0 root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4" \
-nographic -device usb-net,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22
Edit your /boot/cmdline.txt file to add modules-load=dwc2,g_ether to /boot/cmdline.txt after rootwait.

Resources