You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用qemu-system-arm运行Yocto树莓派2镜像时出现挂起问题

Troubleshooting Hanging QEMU Setup for Yocto-Built Raspberry Pi 2 Image

Hey there, let's figure out why your QEMU instance is hanging when trying to run your Yocto-built Raspberry Pi 2 image. I’ve dealt with similar compatibility issues before, so here are actionable steps to fix this:

1. Fix Kernel & Component Compatibility

  • Stop using the standalone kernel-qemu: Yocto builds a kernel specifically tailored for your root filesystem and target hardware. Replace the external kernel-qemu with the kernel image from your Yocto deploy directory, like zImage or Image (located at ./tmp/deploy/images/raspberrypi2/).
  • Ensure matching components: Make sure your kernel, DTB (bcm2709-rpi-2-b.dtb), and root filesystem (berrynux-image-raspberrypi2.rootfs.rpi-sdimg) all come from the same Yocto build. Mixing components from different sources is a common cause of hangs.

2. Complete & Correct the Kernel append Arguments

Your append parameter was truncated—here’s a full, working example that specifies critical boot details:

-append "rw root=/dev/mmcblk0p2 rootfstype=ext4 console=ttyAMA0,115200 console=tty1"
  • Verify the root partition with fdisk -l ./tmp/deploy/images/raspberrypi2/berrynux-image-raspberrypi2.rootfs.rpi-sdimg—it’s almost always p2 for RPi images, but double-check to be sure.
  • The console parameters ensure you get output to your terminal, which helps diagnose if the hang is before or after init starts.

3. Tune QEMU Parameters for Stability

  • Upgrade QEMU (if possible): Your version (2.10.1) is quite old, and later releases (5.x+) have much better support for the Raspberry Pi 2 board. If you can update, it’ll likely resolve low-level compatibility bugs.
  • Adjust CPU & SMP settings: The Raspberry Pi 2 uses a Cortex-A7 CPU, not arm1176 (that’s for RPi 1). Change -cpu arm1176 to -cpu cortex-a7. You can also try setting -smp 4 (matching the RPi 2’s 4 cores), though older QEMU versions might work better with -smp 1 if 4-core causes issues.
  • Debug with serial output: Replace -nographic with -serial stdio to ensure you’re capturing all boot logs—sometimes -nographic can suppress critical error messages that explain the hang.

4. Verify Root Filesystem Integrity

  • Check for filesystem corruption with e2fsck:
    # First, calculate the offset for the root partition (usually p2)
    OFFSET=$(($(fdisk -l ./tmp/deploy/images/raspberrypi2/berrynux-image-raspberrypi2.rootfs.rpi-sdimg | grep p2 | awk '{print $2}') * 512))
    e2fsck -f -o offset=$OFFSET ./tmp/deploy/images/raspberrypi2/berrynux-image-raspberrypi2.rootfs.rpi-sdimg
    
  • Confirm the root filesystem has a valid init process: Mount the image and check if /sbin/init exists—Yocto builds should include this, but a corrupted image might be missing it.

Example Working Command

Putting it all together, here’s a revised command you can test:

qemu-system-arm \
 -M raspi2 \
 -cpu cortex-a7 \
 -dtb ./tmp/deploy/images/raspberrypi2/bcm2709-rpi-2-b.dtb \
 -sd ./tmp/deploy/images/raspberrypi2/berrynux-image-raspberrypi2.rootfs.rpi-sdimg \
 -m 1G \
 -smp 4 \
 -serial stdio \
 -kernel ./tmp/deploy/images/raspberrypi2/zImage \
 -append "rw root=/dev/mmcblk0p2 rootfstype=ext4 console=ttyAMA0,115200"

内容的提问来源于stack exchange,提问作者evilSnobu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:07:08