Qemu device loader doesnt load value into memory - qemu

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

Related

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?

how to log into cloud image using qemu

I am following this guide https://powersj.io/posts/ubuntu-qemu-cli/ but i seem to get stuck in the login prompt at when i run
qemu-system-x86_64 \
-machine accel=kvm,type=q35 \
-cpu host \
-m 2G \
-nographic \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
-drive if=virtio,format=qcow2,file=focal-server-cloudimg-amd64.img \
-drive if=virtio,format=raw,file=seed.img
I dont know what the user and password would be. I also am unable to exit this screen so I have to open another terminal and kill it.
Do I need to leave an `&` to leave it running in background?

Qemu Native to Libvirt XML

I have created a macos virtual machine using qemu cli everything seems to work great so far. My challenge is to convert it to an libvirt xml now.
I'm trying using this command: virsh domxml-from-native qemu-argv but I get the following error with no other info error: this function is not supported by the connection driver: virConnectDomainXMLFromNative
This is my cli command, I'm using Fedora 31
qemu-system-x86_64 -enable-kvm -m 16G \
-cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+aes,+xsave,+avx,+xsaveopt,avx2,+smep \
-boot order=c \
-machine pc-q35-2.9 \
-smp 16,sockets=1,cores=8,threads=2 \
-usb -device usb-kbd -device usb-tablet \
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" \
-drive if=pflash,format=raw,readonly,file=OVMF_CODE.fd \
-drive if=pflash,format=raw,file=OVMF_VARS-3440x1440.fd \
-smbios type=2 \
-device ich9-intel-hda -device hda-duplex \
-device ide-drive,bus=ide.0,drive=Clover \
-drive id=Clover,if=none,snapshot=on,format=qcow2,file=./'HighSierra/Clover.qcow2' \
-device ide-drive,bus=ide.1,drive=MacHDD \
-drive id=MacHDD,if=none,file=/dev/disk/by-id/ata-SanDisk_SDSSDA120G_163757447010,format=raw \
-nic user,model=e1000-82545em \
-device vfio-pci,host=08:00.0,multifunction=on \
-device vfio-pci,host=08:00.1 \
-rtc clock=host,base=localtime \
-vga none \
-nographic \
-serial none \
-parallel none \
-usb \
-device usb-host,hostbus=5,hostport=4 \
-device usb-host,hostbus=5,hostport=4.1 \
-device usb-host,hostbus=5,hostport=4.2 \
-device usb-host,hostbus=5,hostport=4.3 \
-device usb-host,hostbus=5,hostport=4.4
I have no clue where to start, the documentation for this function is almost nonexistent
Unfortunately support for the domxml-from-native command has been removed from recentish libvirt, because we found that in practice it was too unreliable and incomplete to be useful.
Your best bet for importing a pre-existing disk image to libvirt is to use the "virt-install" command with its "--import" flag. You can use the various other args to define the disks, NICs, etc.
The only thing I think you'll have trouble with is the "isa-applesmc" device as I don't think libvirt supports that. For that you will need to edit the XML virt-intsall has created, and then add a passthrough option as illustrated here https://libvirt.org/drvqemu.html#qemucommand

How to run qemu with -nographic and -monitor but still be able to send Ctrl+C to the guest and quit with Ctrl+A X?

I have just found out that if you run QEMU with -monitor telnet::45454,server,nowait -nographic, then Ctrl-C kills the QEMU VM instead of generating SIGINT on the guest: How to pass Ctrl-C to the guest when running qemu with -nographic? | Unix & Linux Stack Exchange
However, I don't want to remove -monitor because it is convenient to automate monitor commands, e.g. it allows me to create a helper script that does:
echo 'savevm my_snap_id' | telnet localhost 45454
Is there a way to both keep my Ctrl-C and -monitor working with -nographic?
Full QEMU command:
qemu-system-x86_64 -append 'root=/dev/vda console=ttyS0' -kernel 'bzImage' -drive file='rootfs.ext2.qcow2,if=virtio,format=qcow2' -nographic -monitor telnet::45454,server,nowait
On QEMU 2.10.1, Ubuntu 17.10, full QEMU command:
./x86_64-softmmu/qemu-system-x86_64 \
-append "root=/dev/sda console=ttyS0 nokaslr printk.time=y" \
-drive file="${dir}/out/x86_64/buildroot/images/rootfs.ext2.qcow2,format=qcow2" \
-kernel "${dir}/out/x86_64/buildroot/images/bzImage" \
-nographic \
If I add:
-chardev stdio,id=s1,signal=off \
-serial none -device isa-serial,chardev=s1
then Ctrl+C starts working as desired, but Ctrl+A X does not work to quit QEMU, which is annoying sometimes: I can use telnet to quit, but it requires more typing / automation.
http://lists.nongnu.org/archive/html/qemu-discuss/2018-04/msg00006.html
Add -serial mon:stdio and remove other -serial options
The following satisfies all my requirements:
./x86_64-softmmu/qemu-system-x86_64 \
-append 'root=/dev/vda nopat nokaslr norandmaps printk.devkmsg=on printk.time=y console=ttyS0' \
-drive file="${dir}/out/x86_64/buildroot/images/rootfs.ext2.qcow2,if=virtio,format=qcow2" \
-kernel "${dir}/out/x86_64/buildroot/images/bzImage" \
-nographic \
-monitor telnet::45454,server,nowait \
-serial mon:stdio
Or for aarch64:
./aarch64-softmmu/qemu-system-aarch64 \
-M virt \
-append 'root=/dev/vda nokaslr norandmaps printk.devkmsg=on printk.time=y' \
-cpu cortex-a57 \
-drive file="${dir}/out/aarch64/buildroot/images/rootfs.ext2.qcow2,if=virtio,format=qcow2" \
-kernel "${dir}/out/aarch64/buildroot/images/Image" \
-monitor telnet::45454,server,nowait \
-nographic \
-serial mon:stdio \
Tested on QEMU 9d2a09063922757ec3640d93f6b35921ab95b1c2
(post v2.12.0-rc2).

Suppress Specific IP Warnings in Modelsim

A Vivado IP is generating an inordinate amount of Modelsim warnings which are making it difficult to assess the simulation for warnings I actually care about.
I see from the Modelsim command documentation that in order to suppress a warning I need to include the parameter -suppress and then the warning numbers. My current implementation is as follows...
vsim -voptargs=+acc \
-L work \
-L xil_defaultlib \
-L secureip \
-L simprims_ver \
-L unifast_ver \
-L unimacro_ver \
-L unisims_ver \
-L xpm \
-L fifo_generator_v13_1_1 \
-L blk_mem_gen_v8_3_3 \
work.blr_tb xil_defaultlib.glbl -l sv_sim.log -suppress 3015,3017,3722
This code snippet works but I am afraid that this will suppress warnings that are created by problems with my own rtl. Is there a way of suppressing specific warnings of an IP?
For reference the warnings are all from the Vivado MIG IP and look something like this...
# ** Warning: (vsim-3017) ../../ip/xc7k160t2ffg676-2/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/phy/mig_7series_v4_0_ddr_mc_phy_wrapper.v(1260): [TFMPC] - Too few port connections. Expected 9, found 8.
# Time: 0 fs Iteration: 0 Instance: /blr_tb/blr_sbk_top_i/ddr3_balor_i/u_mig_ddr3_64bit_32G/u_mig_ddr3_64bit_32G_mig/u_memc_ui_top_std/mem_intfc0/ddr_phy_top0/u_ddr_mc_phy_wrapper/gen_dqs_iobuf_HP/gen_dqs_iobuf[0]/gen_dqs_diff/u_iobuf_dqs File: C:/Xilinx/Vivado/2016.2/data/verilog/src/unisims/IOBUFDS_DIFF_OUT_DCIEN.v
The MIG is compiled with the following command...
vlog -work xil_defaultlib -incr \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/mig_ddr3_64bit_32G.v" \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/mig_ddr3_64bit_32G_mig_sim.v" \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/clocking/*.v" \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/controller/*.v" \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/ecc/*.v" \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/ip_top/*.v" \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/phy/*.v" \
"$SBK_IP_DIR/mig_ddr3_64bit_32G/mig_ddr3_64bit_32G/user_design/rtl/ui/*.v"