自定义Yocto镜像中RAUC因fw_printenv/fw_setenv故障无法运行
问题
为自定义开发板搭建Yocto发行版,配置了boot/root的A/B分区并部署RAUC。当前分区状态正常、RAUC已启动,但fw_printenv与fw_setenv功能异常,导致RAUC执行受阻。
当前配置信息
/etc/fw_env.config内容:
cat /etc/fw_env.config # MTD device name Device offset Env. size Flash sector size Number of sectors /dev/mmcblk0boot0 0x1ff000 0x1000
U-Boot eMMC相关配置参数:
CONFIG_ENV_SIZE=0x1000 CONFIG_ENV_OFFSET=0x1FF000 CONFIG_ENV_IS_IN_MMC=y CONFIG_SYS_MMC_ENV_PART=1 CONFIG_SUPPORT_EMMC_BOOT=y
设备信息:
root@qsmp-1570:~# ls -l /dev/mmcblk0boot0 brw-rw---- 1 root disk 179, 16 Jan 1 01:41 /dev/mmcblk0boot0 root@qsmp-1570:~# fdisk -l Found valid GPT with protective MBR; using GPT Disk /dev/mmcblk0: 7733248 sectors, 3776M Logical sector size: 512 Disk identifier (GUID): 4d27c97e-fde1-451e-b80f-48e3c3aa58b4 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 7733214 Number Start (sector) End (sector) Size Name 1 2048 6143 2048K fip 2 6144 137215 64.0M boot_a 3 137216 268287 64.0M boot_b 4 268288 2365439 1024M rootfs_a 5 2365440 4462591 1024M rootfs_b 6 4462592 7732223 1596M data Disk /dev/mmcblk0boot0: 2 MB, 2097152 bytes, 4096 sectors 64 cylinders, 4 heads, 16 sectors/track Units: sectors of 1 * 512 = 512 bytes Disk /dev/mmcblk0boot0 doesn't contain a valid partition table Disk /dev/mmcblk0boot1: 2 MB, 2097152 bytes, 4096 sectors 64 cylinders, 4 heads, 16 sectors/track Units: sectors of 1 * 512 = 512 bytes Disk /dev/mmcblk0boot1 doesn't contain a valid partition table
内核启动日志中RAUC相关报错:
Starting kernel ... # 省略无关日志... (rauc:401): rauc-WARNING **: 01:41:57.617: Failed getting primary slot: uboot backend: fw_printenv failed with exit code: 243 rauc mark: Failed marking slot rootfs.0 as good: uboot backend: Failed to run fw_setenv: Child process exited with code 243
调试与修复步骤
1. 手动测试fw_printenv基础功能
执行fw_printenv -v查看详细错误输出,定位是配置错误、设备权限问题还是环境数据损坏。
2. 补全fw_env.config缺失字段
当前配置缺少Flash sector size和Number of sectors两个必要参数,根据eMMC boot0分区信息补全:
- Flash sector size:eMMC扇区大小为512字节,即
0x200 - Number of sectors:环境大小
0x1000÷ 扇区大小0x200= 8,即8
修改后的/etc/fw_env.config:
# MTD device name Device offset Env. size Flash sector size Number of sectors /dev/mmcblk0boot0 0x1ff000 0x1000 0x200 8
3. 验证eMMC boot分区可访问性
- 执行
dd if=/dev/mmcblk0boot0 of=/tmp/env_test bs=1 count=4096 skip=$((0x1ff000)),尝试读取环境分区数据,确认设备可正常读写。 - 若读取失败,检查设备权限:确保
/dev/mmcblk0boot0所属组为disk,必要时执行chmod 660 /dev/mmcblk0boot0开放读写权限。
4. 核对U-Boot配置与用户空间工具一致性
- 确认U-Boot编译时的
CONFIG_ENV_OFFSET、CONFIG_ENV_SIZE与fw_env.config数值完全一致(十六进制大小写不影响,但需确保无计算错误)。 - 检查
CONFIG_SYS_MMC_ENV_PART=1是否对应/dev/mmcblk0boot0,确认内核对eMMC boot分区的映射正确。
5. 测试fw_setenv基础功能
在fw_printenv可正常读取后,执行以下命令验证写入功能:
fw_setenv test_var "hello" fw_printenv test_var
若执行成功,说明工具功能恢复,RAUC的依赖问题即可解决。
6. 修复RAUC依赖的U-Boot环境变量
RAUC需要U-Boot中存在bootcount、bootlimit等变量管理A/B分区切换,若变量缺失,需通过U-Boot命令行手动添加,或在U-Boot编译阶段配置默认环境变量。
内容的提问来源于stack exchange,提问作者Humusk
相关产品推荐
相关产品推荐

