Silicon Labs Gecko Bootloader 是适用于所有较新 EFM32 和 EFR32 MCU 与无线 MCU 的通用 Bootloader。自 GSDK 4.0 起,Gecko Bootloader 重构为基于组件的架构,可在 Simplicity Studio 5 的 Project Configurator 中直观地安装和配置各个组件,生成适配不同协议栈和升级场景的 Bootloader 映像。Documentation Index
Fetch the complete documentation index at: https://mintlify.com/dsyx/docs.silabs.com_zh/llms.txt
Use this file to discover all available pages before exploring further.
概述与架构
Gecko Bootloader 的主要特性:通用性
适用于 Silicon Labs Gecko 系列 MCU 和无线 MCU,支持 EFM32 和 EFR32 Series 1 及 Series 2 设备。
可现场升级
Bootloader 自身可现场更新,支持添加新功能、更改通信协议和修复安全漏洞。
安全特性
内置 Secure Boot(每次引导验证签名)、已签名升级映像文件和已加密升级映像文件支持。
GBL 文件格式
使用专有 GBL(Gecko Bootloader)文件格式,扩展名
.gbl,支持 Application、Bootloader 和 SE 升级内容的组合打包。Series 1 vs Series 2 架构差异
在 Series 1 设备上,Gecko Bootloader 采用两阶段(Two-Stage)设计,包含 First Stage Bootloader 和 Main Stage Bootloader。First Stage 通过 CRC32 校验和验证 Main Bootloader 更新映像的完整性,完成 Main Bootloader 的现场升级。 在 Series 2 设备上,Gecko Bootloader 仅包含 Main Stage Bootloader,First Stage Bootloader 的角色由 Secure Engine(SE)承担。SE 可以是硬件实现(HSE)或虚拟实现(VSE)。GBL 文件格式
GBL 文件是 Gecko Bootloader 专用的升级映像格式,由多个带标签(Tag)的数据块组成。明文 GBL 标签结构
一个典型的 GBL 文件 Tag 序列如下所示:加密 GBL 标签结构
启用加密后,内容被包裹在加密 Tag 中:可以使用 Simplicity Commander 将多种内容组合为单个升级映像:
Bootloader 运行模式
Standalone Bootloader 操作流程
Application Bootloader 操作流程
在 Simplicity Studio 5 中创建 Bootloader 项目
创建新项目
在 Simplicity Studio 5 的 Launcher 视图中,选择目标设备,点击 Create New Project,在项目向导中选择 Bootloader 类别的示例项目。
选择示例配置
根据使用场景选择预置的示例 Bootloader,例如:
- UART XMODEM Bootloader(Standalone,UART 接口)
- SPI Flash Storage Bootloader(Application,外部 SPI 闪存)
- Internal Storage Bootloader(Application,内部闪存)
- Bluetooth AppLoader OTA DFU Bootloader(OTA 升级)
插件/组件系统
Gecko Bootloader 通过组件系统实现高度可配置性,组件分为以下几大类:- Communication(通信)
- Storage(存储)
- Security(安全)
- 其他组件
提供 Bootloader 与主机设备通信的接口:
| 组件 | 协议 | 适用场景 |
|---|---|---|
| UART: XMODEM | UART + XMODEM 协议 | EmberZNet NCP |
| UART: BGAPI | UART + BGAPI 协议 | Bluetooth NCP |
| SPI: EZSP | SPI + EZSP 协议 | Zigbee NCP |
| Bluetooth: AppLoader | BLE OTA | Bluetooth SoC |
存储配置示例
SPI Flash Storage 配置:存储区基地址在 Common Storage 组件配置,存储槽在 Bootloader Storage Slot Setup 中设置,SPI GPIO 引脚在 Bootloader SPI Controller Driver 中配置。 Internal Storage 配置参考:| 设备型号 | Storage Offset | Storage Size |
|---|---|---|
| 512 kB 设备(flash base 0x00) | 0x44000 | 196608 bytes |
| 1 MB 设备(flash base 0x00) | 0x84000 | 458752 bytes |
| 2 MB 设备(flash base 0x00) | 0x10000 | 1011712 bytes |
Application Interface(btl_interface.h)
Bootloader 通过内部函数表向应用程序暴露 API,通过api/btl_interface.h 头文件访问。
如果未使用 Silicon Labs 的协议栈,可直接使用
btl_interface.h 中的 API;如果使用了 Silicon Labs 协议栈,建议使用各协议栈推荐的 Bootloader 接口 API。api/btl_interface.c:通用接口实现api/btl_interface_storage.c:存储功能接口实现
核心 API 模块
Common Application Interface(通用接口)
Common Application Interface(通用接口)
适用于所有版本的 Bootloader,与已安装的组件无关,包括初始化、重启等基础功能:
Storage Interface(存储接口)
Storage Interface(存储接口)
仅在支持存储的 Application Bootloader 上可用,用于读写升级映像到存储槽:
Parser Interface(解析器接口)
Parser Interface(解析器接口)
用于解析 GBL 文件内容,在不执行升级的情况下提取元数据:
典型使用示例
以下示例展示了如何在应用程序中使用btl_interface.h 完成存储升级映像并触发升级的完整流程:
错误码分组
大多数 Gecko Bootloader API 返回错误码,主要分组如下:| 错误码 | 说明 |
|---|---|
0x0 | OK(成功) |
0x01xx | 初始化错误 |
0x02xx | 映像验证错误 |
0x04xx | 存储错误 |
0x05xx | 引导加载错误(Bootload error) |
0x06xx | 安全错误 |
0x07xx | 通信错误 |
0x09xx | XMODEM 解析器错误 |
0x10xx | GBL 文件解析器错误 |
0x11xx | SPI 从设备驱动错误 |
0x12xx | UART 驱动错误 |
0x13xx | 压缩错误 |
platform/bootloader/api/btl_errorcode.h 中找到。
Application Properties 结构
Application 映像应包含ApplicationProperties_t 结构,声明版本、功能和其他元数据。安装 bootloader_interface 组件后,该结构会自动添加到项目中。
安装 bootloader_interface 组件
在 Simplicity Studio 5 Project Configurator 中,搜索并安装 bootloader_interface 组件,它会自动安装 bootloader_app_properties 子组件。
配置 App Properties
在 Platform > Bootloader > App Properties 组件中点击 Configure,设置 Application 版本号。版本号也可通过宏
APP_PROPERTIES_VERSION 在 Additional Macros 中定义。