使用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 externalkernel-qemuwith the kernel image from your Yocto deploy directory, likezImageorImage(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 alwaysp2for RPi images, but double-check to be sure. - The
consoleparameters 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 arm1176to-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 1if 4-core causes issues. - Debug with serial output: Replace
-nographicwith-serial stdioto ensure you’re capturing all boot logs—sometimes-nographiccan 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/initexists—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
相关产品推荐
相关产品推荐

