在没有用户干预的情况下执行裸机程序后如何干净地退出 QEMU? [英] How to cleanly exit QEMU after executing bare metal program without user intervention?

查看:18
本文介绍了在没有用户干预的情况下执行裸机程序后如何干净地退出 QEMU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 ARM 系统组装一个交叉编译单元测试平台,并使用 qemu-system-arm 在主机上运行测试.具体来说,我使用 qemu 来模拟 Stellaris LM3S6965 评估板,因为它包含一个 Cortex M3 处理器,就像我的目标环境一样.在 qemu 中运行的二进制文件是使用 GNU Tools for ARM 构建的.

I am assembling a cross compiling unit testing rig for an ARM system and running the tests on a host machine with qemu-system-arm. Specifically, I'm using qemu to emulate the Stellaris LM3S6965 eval board as it contains a Cortex M3 processor like my target environment. The binary run in qemu is built with GNU Tools for ARM.

不涉及操作系统.测试套件作为裸机应用程序在 -nographic 模式下使用 qemu 运行.工具链和测试台本身工作正常.并且测试成功运行到完成并在 qemu 中产生测试结果也很好.

There is no OS involved. The test suite is run as a bare metal application with qemu in -nographic mode. The toolchain and the test rig itself are working fine. And the tests successfully run to completion and produce test results within qemu just fine as well.

问题在于将 qemu 包装在自动构建工具中(在本例中为 Rake).除了键盘命令之外,我还没有找到一种在测试套件运行并吐出结果后让 qemu 退出的好方法.这会导致构建环境挂起/依赖用户干预.

The problem is in wrapping up qemu in an automated build tool (Rake in this case). Other than keyboard commands I have not yet found a good way to cause qemu to exit after the test suite runs and spits out its results. This causes the build environment to hang / rely on user intervention.

我看了很多,也没有找到关于如何在程序终止后完成简单退出的好资料.我确实找到了一些使用 -no-reboot 选项运行 qemu 的建议,然后从模拟器中运行的程序触发系统重置.我试过这个.它有效……有点.在 main() 执行后,我将适当的值写入模拟处理器的复位向量,这确实会触发复位.运行测试套件后,qemu 报告捕获系统重置.但是,它将此报告为硬件错误,转储寄存器内容,然后生气地退出(下面的错误消息).虽然这确实在测试套件运行后完成了退出,但由于 qemu 退出并出现错误情况,它会破坏自动构建脚本.

I have looked high and low and have found no good sources on how to accomplish a simple exit after program termination. I did find a couple suggestions of running qemu with the -no-reboot option and then triggering a system reset from the program running in the emulator. I have tried this. It works… kinda. I write the appropriate values to the emulated processor's reset vector after main() executes, and this does trigger a reset. After running the test suite qemu reports catching a system reset. However, it reports this as a hardware error, dumps register contents, and then exits angry (error message below). While this does accomplish exiting after the test suite runs, it then breaks the automated build script due to qemu exiting with an error condition.

qemu: hardware error: System reset

我想避免将键盘命令插入构建以模拟用户干预.我还想避免依赖 qemu 以错误状态退出.

I'd like to avoid hacking the insertion of keyboard commands into the build to simulate user intervention. I'd also like to avoid relying on qemu exiting in an error state.

似乎我已经接近一个干净的出口,但并不完全在那里.搜索 qemu 错误消息(上图)除了相关的错误报告之外没有产生任何相关文档.

It seems I'm close to a clean exit but not quite there. Searching for the qemu error message (above) has produced no relevant documentation other than tangentially related bug reports.

在我缺少的裸机程序中返回 main() 后,是否存在导致 qemu 退出的机制?这个 -no-reboot + 系统重置策略会起作用吗?如果是这样,还需要什么才能让 qemu 干净地退出?

Is there a mechanism for causing qemu to exit after main() returns in a bare metal program that I'm missing? Will this -no-reboot + system reset strategy work? If so, what else is necessary to allow qemu to exit cleanly?

推荐答案

对我来说,最干净的选择是获取接近我们已经使用的稳定版本 Qemu 的源代码.以下是指1.1.2版本的Qemu源码.

The cleanest option for me was to grab the source for a stable version of Qemu close to the one we were already using. The following refers to version 1.1.2 of the Qemu source.

我在 armv7m_nvic.c 中修改了 Cortex M3 + Stellaris LM3S6965 评估板的复位向量处理仿真.我将 hw_error() 调用替换为对 qemu_system_reset_request() 的调用.此内部系统调用将重置虚拟机,但也会响应 -no-reboot 命令行选项以实现干净关闭,如我原来的问题中所述.

I modified the emulation of the reset vector handling for the Cortex M3 + Stellaris LM3S6965 eval board in armv7m_nvic.c. I replaced the hw_error() call with a call to qemu_system_reset_request(). This internal system call will reset a virtual machine but also responds to the -no-reboot command line option for a clean shutdown as discussed in my original question.

这些 在获取 快照后,构建说明对我有用Qemu 1.1.2.我遇到了几个构建错误,但网络搜索很快解决了每个问题.

These build instructions worked for me after grabbing a snapshot of Qemu 1.1.2. I encountered several build errors, but web searches quickly resolved each issue.

这篇关于在没有用户干预的情况下执行裸机程序后如何干净地退出 QEMU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆