Adding second mmcblk device - qemu

I have a arm vexpress-a9 built from buildroot with rootfs on mmcblk0 with command line:
exec qemu-system-arm -M vexpress-a9 -smp 1 -m 256 -kernel zImage -dtb vexpress-v2p-ca9.dtb -drive file=rootfs.ext4,if=sd,format=raw -append "console=ttyAMA0,115200 rootwait root=/dev/mmcblk0" -net nic,model=lan9118 -net user ${EXTRA_ARGS}
I need to add another mmcblk device with 7 partitions.
I created a raw image file and created 7 partitions with disk.
But trying to run:
exec qemu-system-arm -M vexpress-a9 -smp 1 -m 256 -kernel zImage -dtb vexpress-v2p-ca9.dtb -drive file=rootfs.ext4,if=sd,format=raw -drive file=disk2.img,if=sd,format=raw -append "console=ttyAMA0,115200 rootwait root=/dev/mmcblk0" -net nic,model=lan9118 -net user ${EXTRA_ARGS}
"machine type does not support if=sd,bus=0,unit=1"
What am I doing wrong?
Thanks for the help.

The vexpress-a9 machine has only one SD controller, so you can't use more than one SD card. (This is the emulated-machine equivalent to the real world scenario where the board has only one SD card slot -- you physically can't put more than one SD card in at once.)

Related

Start YOCTO Intel x86_64 image on QEMU failure

I create Yocto image for architecture x86_64 and run on the QEMU virtual machine by the below qemu command:
qemu-system-x86_64.exe -m 1024 -hda "rootfs.img" -cpu q35 -kernel "vmlinuz" -initrd "initrd" -append "root=/dev/ram0"
But the booting process was failed. How to indicate the rootfs.img to correct path? What is the problem with QEMU, I tested OK with VirtualBox.
I have to select the correct cpu (i7) and use correct virtual device to mount rootfs.img.
qemu-system-x86_64.exe -m 1024 -drive file=rootfs.img,format=raw,if=virtio -cpu Nehalem -initrd "initrd" -kernel "vmlinuz" -append "root=/dev/vda"
As the result, the image can boot successfully.
(Refer: https://wiki.qemu.org/Documentation/9psetup)

Qemu device loader doesnt load value into memory

Im trying to use the -device,loader option in qemu. Originally, I wanted to load a file into memory, but that was (and still isnt) working. So, I tried to load a constant value into memory. This is my command:
qemu-system-aarch64 \
-machine virt \
-cpu cortex-a57 \
-smp 1 \
-m 3G \
-device loader,addr=0x14680000,data=0xdeadbeef,data-len=0x4\
-machine gic-version=3 \
-machine secure=true \
-machine virtualization=true \
-nographic \
-S -s
I then open gdb, and do:
target remote :1234
x/x 0x14680000
The result is not 0xdeadbeef, as I had expected, but 0xffffffff.
Why is this happening? I cant find much documentation on the loader device in qemu, and have mostly just been following:
https://qemu-project.gitlab.io/qemu/system/generic-loader.html

How to create block devices other than virtio in Qemu virt machine?

I am trying to emulate ARM64 Linux on qemu. The following command works:
qemu-system-aarch64 -M virt-6.2 -cpu cortex-a53 -m 1G -smp 4\
-kernel Image.gz \
-append 'earlycon=pl011,0x9000000 console=ttyAMA0 root=/dev/vda rw' \
-drive file=base.img,format=raw,if=virtio \
-nographic
However, the block device type is virtio. To make it work, the virtio driver should be added to the kernel, which I don't want.
After some googling, I tried following command:
qemu-system-aarch64 -M virt-6.2 -cpu cortex-a53 -m 1G -smp 4\
-kernel Image.gz \
-append 'earlycon=pl011,0x9000000 console=ttyAMA0 root=/dev/vda rw' \
-drive file=base.img,format=raw,if=virtio \
-device sdhci-pci -device sd-card,drive=mydrive -drive id=mydrive,if=none,format=raw,file=base2.img \
-nographic
I was expecting an extra sd-card device, but it does not work. The command lsblk shows nothing new, nor can I find anything new under /dev.
So, how can I emulate a block device in qemu without adding new driver to the kernel?

QEMU snapshot without an image?

I'm working with VxWorks, a Real Time Operating System for embedded systems. They recently added QEMU support, and I've been trying to figure it out. (I'm fairly new to all these technologies.) I would like to checkpoint and restart the virtual machine, ie save the RAM and processor state and reload it later from exactly that point.
QEMU has some support for this called "snapshots." However, everything I've seen and tried requires a disk image in qcow2 format. But my simulation has no disk, the program is loaded directly into RAM and run.
Here's my QEMU command:
qemu-system-aarch64 -m 4096M -smp 4 -machnie xlnx-zcu102 -device loader,file=~/vxworks_21.03/workspace3/QEMU_helloWorld/default/vxWorks,addr=0x00100000 -nographic -monitor telnet:127.0.0.1:35163,server,nowait -serial telnet:127.0.0.1:39251,server -device loader,file=~/vxworks_21.03/workspace3/vip_xlnx_zynqmp_smp_64/default/xlnx-zcu102-rev-1.1.dtb,addr=0x0f000000 -device loader,addr=0x000ffffc,data=0xd2a1e000,data-len=4 -device loader,addr=0x000ffffc,cpu-num=0 -nic user -nic user -nic user -nic user,id=n0,hostfwd=tcp:127.0.0.1:0-:1534,hostfwd=udp:127.0.0.1:0-:17185
Then I log into the monitor and:
$ telnet 127.0.0.1 35163
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
QEMU 5.2.0 monitor - type 'help' for more information
(qemu) savevm
Error: No block device can accept snapshots
I tried a number of things, like creating an empty disk image, or the snapshot_blkdev command, but no luck so far.
The host is RedHat Linux 8.4 running on an x86 desktop, the guest is ARM64.
It turns out that a disk image is required to do snapshots, but you don't have to hook it up to the guest. To do that you pass qemu -drive argument with with if=none. Like this:
-drive if=none,format=qcow2,file=dummy.qcow2
So here is the whole sequence that worked:
$ qemu-img create -f qcow2 dummy.qcow2 32M
$ qemu-system-aarch64 -m 4096M -smp 4 -machnie xlnx-zcu102 -device loader,file=vxWorks,addr=0x00100000 -nographic -monitor telnet:127.0.0.1:35163,server,nowait -serial telnet:127.0.0.1:39251,server -device loader,file=xlnx-zcu102-rev-1.1.dtb,addr=0x0f000000 -device loader,addr=0x000ffffc,data=0xd2a1e000,data-len=4 -device loader,addr=0x000ffffc,cpu-num=0 -nic user -nic user -nic user -nic user,id=n0,hostfwd=tcp:127.0.0.1:0-:1534,hostfwd=udp:127.0.0.1:0-:17185 -snapshot -drive if=none,format=qcow2,file=dummy.qcow2
Then in the monitor terminal savevm and loadvm work:
$ telnet 127.0.0.1 35163
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
QEMU 5.2.0 monitor - type 'help' for more information
(qemu) savevm save1
(qemu) info snapshots
List of snapshots present on all disks:
ID TAG VM SIZE DATE VM CLOCK ICOUNT
-- save1 44.3 MiB 2021-06-28 10:08:28 00:00:05.952
(qemu) loadvm save1
This information came thanks to Peter Maydell and his blog post: https://translatedcode.wordpress.com/2015/07/06/tricks-for-debugging-qemu-savevm-snapshots/

How to save the QEMU console output form Windows Host to a file?

Background:
Host: Win10
Qemu: Qemu 6.0.0
This is my command: qemu-system-arm.exe -D ./log.txt -M sabrelite -smp 4 -m 1G -nographic -serial null -serial mon:stdio -kernel image -dtb sabrelite.dtb
I'm using this command to create a Qemu, in order to run some tests with a lot of output logs on it.
I wanna save the outputs to a file.
Question:
How can I save the console output from windows host QEMU to a file?
It seems that the -D ./log.txt just created an empty file, and did not save the outputs to it.
The -D option is for the log file for the debug info enabled with '-d'. If you don't specify any '-d' options there will be no debug info in the log file.
The output of the serial console is entirely separate. That is controlled by the '-serial' option, which currently you have set up to go to stdio (with a monitor muxed to also use stdio). You can look at the other options for where -serial can be directed; this does include a "send to file", but note that if you just do that then you won't also be able to see it on the console and you won't be able to input anything.
You can use standard windows output redirection. This command line will redirect stdout and stderr to log.txt:
qemu-system-arm.exe -M sabrelite -smp 4 -m 1G -nographic -serial null -serial mon:stdio -kernel image -dtb sabrelite.dtb > 1> ./log.txt 2>&1