OTA A/B Partitions and U-Boot Environment Variables¶
How A/B update flows use U-Boot environment state to select and recover system slots.
This English edition keeps the original illustrations and reproducible command or configuration examples.
Commands and configuration¶
┌─────────────────────────────────────────┐
│ 应用层(Linux 用户空间) │ ← 触发更新、确认启动
│ - OTA 更新程序 │
│ - 启动确认服务 │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ 引导层(U-Boot) │ ← 切换分区、自动回滚
│ - 环境变量管理 │
│ - bootcmd 启动脚本 │
└─────────────────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ 存储层(eMMC 分区) │ ← 物理存储
│ - boot_a / boot_b │
│ - rootfs_a / rootfs_b │
│ - data(共享数据) │
└─────────────────────────────────────────┘
启动 U-Boot
↓
检查 slot_updated 标志
↓
是否为 1?
├─→ 是:切换 slot_active,设置 boot_count=3,清除 slot_updated
└─→ 否:继续
↓
检查 boot_count 是否存在
↓
是否存在?
├─→ 是:减 1 并保存
│ ├─→ boot_count > 0:继续启动
│ └─→ boot_count = 0:回滚到另一个 slot,重启
└─→ 否:正常启动(没有重试机制)
↓
根据 slot_active 加载对应分区的内核和设备树
↓
启动内核
#include <stdlib.h>
void confirm_boot_successful() {
// 检查系统是否稳定,例如网络、核心服务是否正常
if (is_system_stable()) {
// 系统稳定,清除 boot_count,锁定当前分区
system("fw_setenv boot_count");
printf("Boot successful, boot_count cleared.\n");
} else {
// 如果检查失败,可以直接执行 reboot
// U-Boot 会因为 boot_count 递减而最终触发回滚
printf("System unstable, rebooting for rollback...\n");
system("reboot");
}
}
Practical notes¶
Test each change on a recoverable target, keep logs from the boot or failure path, and record the exact kernel and userspace versions used in the result.