Android A/B system - bootctrl

Android A/B system系列

Achitecture

Android A/B System概述中有讲到A升B的一个例子。下面这张图是想说明两个问题:

  • 启动的时候是如何知道要从A启动还是B启动?
  • 升级的时候是如何要更新A还是B?

图中有两个流程,和涉及的一些模块:
模块:

  • bootloader:启动的早期阶段,叫preloader/lk都行
  • misc:单独的一块分区,存放启动的信息,也是今天研究的重点
  • update_verifier:当前slot启动成功,会将当前的slot设置为successful,表示这个slot是可以成功启动的
  • update_engine:Android负责升级流程的守护进程
  • bootctrl HAL:google规定的HAL,各个IC厂商有自己的底层实现,是获取misc信息的软件接口

流程:

  • boot flow
    • get active slot:读misc的信息,从而知道当前要从slot A启动还是slot B启动
    • mark slot successful:启动成功的时候,标记当前slot为successful
  • update flow
    • trigger update and read update package
    • get current slot:获取当前slot,假设当前slot为A,那么要更新slot B;当前为B,那么要更新slot A
    • write data to another slot:更新
    • set active slot:更新完成以后,切换slot,则下次启动从更新的slot启动
      在这里插入图片描述

misc

关于misc分区的内容,各个IC厂商各自有不同的结构,但核心思想是类似的,所以这里拿google的结构来分析。
重要的部分为红色标记的:

  • active_slot:当前正在运行的slot
  • slot_info:每个slot的信息(实际的产品实现不会这么简单)
    在这里插入图片描述

/system/extras/boot_control_copy/bootinfo.h

typedef struct BrilloSlotInfo {
   
  uint8_t bootable : 1;
  uint8_t reserved[3];
} BrilloSlotInfo;

typedef struct BrilloBootInfo {
   
  // Used by fs_mgr. Must be NUL terminated.
  char bootctrl_suffix[4];

  // Magic for identification - must be 'B', 'C', 'c' (short for
  // "boot_control copy" implementation).
  uint8_t magic[3];

  // Version of BrilloBootInfo struct, must be 0 or larger.
  uint8_t version;

  // Currently active slot.
  uint8_t active_slot;

  // Information about each slot.
  BrilloSlotInfo slot_info[2];

  uint8_t reserved[15];
} BrilloBootInfo;

根据这个结构,bootinfo.cpp实现了对BrilloBootInfo进行存取操作的接口,这里的操作比较简单,这里就不去研究了。

/system/extras/boot_control_copy/bootinfo.cpp

  • 存取操作
    • bool boot_info_load(BrilloBootInfo *out_info)
    • b
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值