Skip to contentSkip to conversation

runqemu: parse QB_GRAPHICS for nographic flag

PATCH In review [email protected] 2 participants 5 messages Jan 31 – Feb 3

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 runqemu: parse QB_GRAPHICS for nographic flag

From: Charles Dias <[email protected]>

The setup_vga() function was ignoring -nographic in QB_GRAPHICS because it only checked the command-line self.nographic flag. This caused QB_GRAPHICS to be appended after display autodetection, resulting in conflicting options like "-device virtio-vga -display sdl" and "-nographic" in the same command.

Add a check after reading qemuboot.conf to detect -nographic in QB_GRAPHICS and set self.nographic accordingly. This prevents unnecessary display autodetection for BSPs that specify -nographic in their machine configuration, as happens in meta-zephyr layer.

---
 scripts/runqemu | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/runqemu +6 -0
index 32a3d6296a..b791abfda3 100755
@@ -986,6 +986,12 @@ to your build configuration.
                 v = os.path.dirname(self.qemuboot)
             self.set(k_upper, v)
 
+        # Parse QB_GRAPHICS to set internal flags if not already set by command-line
+        if not self.nographic and self.get('QB_GRAPHICS'):
+            if '-nographic' in self.get('QB_GRAPHICS'):
+                logger.debug('Detected -nographic in QB_GRAPHICS, setting nographic mode')
+                self.nographic = True
+
     def validate_paths(self):
         """Ensure all relevant path variables are set"""
         # When we're started with a *.qemuboot.conf arg assume that image
#1 lore raw
Quoted 10 lines · charles.embedded via lists.openembedded.org

The setup_vga() function was ignoring -nographic in QB_GRAPHICS because it only checked the command-line self.nographic flag. This caused QB_GRAPHICS to be appended after display autodetection, resulting in conflicting options like "-device virtio-vga -display sdl" and "-nographic" in the same command.

Add a check after reading qemuboot.conf to detect -nographic in QB_GRAPHICS and set self.nographic accordingly. This prevents unnecessary display autodetection for BSPs that specify -nographic in their machine configuration, as happens in meta-zephyr layer.

I'm not sure specifying -nographic in a BSP layer via QB_GRAPHICS is correct. QB_GRAPHICS is intended for what emulated hardware should be present in the guest machine.

-nographic is a host option that tells qemu what to do with the graphical output (in case of -nographic, discard it). I don't think it's up to the BSP layer to make that decision.

Alex

#2 lore raw
Quoted 8 lines · Alexander Kanavin

I'm not sure specifying -nographic in a BSP layer via QB_GRAPHICS is correct. QB_GRAPHICS is intended for what emulated hardware should be present in the guest machine.

-nographic is a host option that tells qemu what to do with the graphical output (in case of -nographic, discard it). I don't think it's up to the BSP layer to make that decision.

Hi Alex,

Thanks for the feedback.

In meta-zephyr/meta-zephyr-bsp/conf/machine/qemu-x86.conf are defined several QEMU settings that are used to generate the.qemuboot.conf file during the image build (e.g. ${TMPDIR}/deploy/images/qemu-x86/zephyr-helloworld-qemu-x86-20260201174846.elf).

The expectation is that, based on the resulting.qemuboot.conf , running runqemu should be sufficient to boot Zephyr and see the console output in the terminal (no GUI required). However, in this case QB_GRAPHICS="-nographic" is ignored, and the generated QEMU invocation still selects a graphical display device, so the Zephyr output does not appear on the terminal as expected. Please see the QEMU command:

/<path-to>/usr/bin/qemu-system-i386 -nic none -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0    -machine type=q35 -cpu qemu32,+nx,+pae  -m 256 -serial mon:vc -serial null -device virtio-vga  -display sdl,show-cursor=on -nographic -machine acpi=off -kernel <path-to-build> /tmp/deploy/images/qemu-x86/zephyr-helloworld-qemu-x86-20260201174846.elf -append '  mem=256M swiotlb=0 '

So even though -nographic is present, QEMU is still invoked with -device virtio-vga and -display sdl , and the serial is set to mon:vc.

My intent with the patch is to ensure that when QB_GRAPHICS includes -nographic , runqemu does not select a graphical display device and routes the serial console to the terminal (so the Zephyr log is visible as expected).

Please let me know if I'm not on the right track. Thank you!

Charles Dias

#3 lore raw
Quoted 11 lines · charles.embedded via lists.openembedded.org

In meta-zephyr/meta-zephyr-bsp/conf/machine/qemu-x86.conf are defined several QEMU settings that are used to generate the .qemuboot.conf file during the image build (e.g. ${TMPDIR}/deploy/images/qemu-x86/zephyr-helloworld-qemu-x86-20260201174846.elf).

The expectation is that, based on the resulting .qemuboot.conf, running runqemu should be sufficient to boot Zephyr and see the console output in the terminal (no GUI required). However, in this case QB_GRAPHICS="-nographic" is ignored, and the generated QEMU invocation still selects a graphical display device, so the Zephyr output does not appear on the terminal as expected. Please see the QEMU command:

/<path-to>/usr/bin/qemu-system-i386 -nic none -object rng-random,filename=/dev/urandom,id=rng0 -device virtio-rng-pci,rng=rng0 -machine type=q35 -cpu qemu32,+nx,+pae -m 256 -serial mon:vc -serial null -device virtio-vga -display sdl,show-cursor=on -nographic -machine acpi=off -kernel <path-to-build>/tmp/deploy/images/qemu-x86/zephyr-helloworld-qemu-x86-20260201174846.elf -append ' mem=256M swiotlb=0 '

So even though -nographic is present, QEMU is still invoked with -device virtio-vga and -display sdl, and the serial is set to mon:vc.

My intent with the patch is to ensure that when QB_GRAPHICS includes -nographic, runqemu does not select a graphical display device and routes the serial console to the terminal (so the Zephyr log is visible as expected).

Please let me know if I'm not on the right track. Thank you!

nographic is an option that can be passed only as a command line parameter to runqemu. It is also not the default: when you run runqemu with no parameters, it will default to having graphical output if that is detected to be supported (via trying 'qemu-system.. --help' and seeing what is enabled), or no output otherwise:

# If we have no display option, we autodetect based upon what
qemu supports. We

        # need our font setup and show-cusor below so we need to see
what qemu --help says
        # is supported so we can pass our correct config in.
        if not self.nographic and not self.sdl and not self.gtk and
not self.publicvnc and not self.egl_headless == True:
            output = subprocess.check_output([self.qemu_bin,
"--help"], universal_newlines=True, env=self.qemu_environ)
            if "-display gtk" in output:
                self.gtk = True
            elif "-display sdl" in output:
                self.sdl = True
            else:
                self.qemu_opt += ' -display none'

Once again, it is not up to layers to force a decision where qemu output goes. Maybe users want it in a graphical window. Maybe they want it in a vnc server. Maybe they don't want it at all, because they will ssh into the system. We can consider whether the above logic makes sense, and if nographic should be the default (instead of the above if..else block), but taking that choice altogether away from users is not right.

Alex

#4 lore raw
Quoted 23 lines · Alexander Kanavin

nographic is an option that can be passed only as a command line parameter to runqemu. It is also not the default: when you run runqemu with no parameters, it will default to having graphical output if that is detected to be supported (via trying 'qemu-system.. --help' and seeing what is enabled), or no output otherwise:

# If we have no display option, we autodetect based upon what
qemu supports. We

        # need our font setup and show-cusor below so we need to see
what qemu --help says
        # is supported so we can pass our correct config in.
        if not self.nographic and not self.sdl and not self.gtk and
not self.publicvnc and not self.egl_headless == True:
            output = subprocess.check_output([self.qemu_bin,
"--help"], universal_newlines=True, env=self.qemu_environ)
            if "-display gtk" in output:
                self.gtk = True
            elif "-display sdl" in output:
                self.sdl = True
            else:
                self.qemu_opt += ' -display none'
Quoted 8 lines

Once again, it is not up to layers to force a decision where qemu output goes. Maybe users want it in a graphical window. Maybe they want it in a vnc server. Maybe they don't want it at all, because they will ssh into the system. We can consider whether the above logic makes sense, and if nographic should be the default (instead of the above if..else block), but taking that choice altogether away from users is not right.

Hi Alex,

Thanks for the clarification. I’ll drop this patch.

Charles Dias