6 nRF51 DFU 初始化包

来源:互联网 发布:java base64 编码 编辑:程序博客网 时间:2024/06/06 07:43

当升级数据包时,在应用程序映像传输之前,在DFU中需要初始化包来执行映像的安全检测。这个初始化包作为升级流程的一部分提供了安全检测机制,因此被升级的设备只能接收兼容的应用程序。

初始化包包括以下信息可用于安全检测(参见dfu_init_packet_t)

/**@brief Structure contained in an init packet. Contains information on device type, revision, *and supported SoftDevices. */typedef struct{    uint16_t device_type;       uint16_t device_rev;                                                                       uint32_t app_version;                                                                     uint16_t softdevice_len;                                                                   uint16_t softdevice[1];                                                               } dfu_init_packet_t;
l  Device type:一个2个字节的值,可由开发者定义,以指示设备的类型,如Heart Rate Belt。
/**< Device type (2 bytes), for example Heart Rate. This number must be defined by the customer before production.It can be located in UICR or FICR. */ 

l  Device revision:一个2个字节的值,用于限制一个设备只能使用一个定义的版本号进行升级。

/**< Device revision (2 bytes), for example major revision 1, minor revision 0. This number must be  defined by the customer before production.It can be located in UICR or FICR. */

l  Application version:一个4字节的值,用来标识用于传输的应用程序的版本,这个值用来只允许软件升级而不能降级。没有示例代码使用这个值。

  /**< Application version for the image software. This field allows for additional checking,for example ensuring that a downgrade is not allowed. */ 

l  Supported SoftDevices:一个2个字节的列表标识与应用程序兼容的SoftDevices,如S110 v7.0 和 S110 v7.1。

  /**< Variable length array of SoftDevices compatible with this application. The length of the array is specified in the length field.SoftDevice firmware id 0xFFFE indicates any SoftDevice. */

l  Checksum:2个字节的循环校验码,用于校验映像。

 SDK提供一个模板dfu_init_template.c用于执行初始化包的安全检测。这个模板是为了增强DFU的安全性而增加的。

 1 设备和版本类型

   设备和版本类型在nRF51芯片的UICR(0x10001080)寄存器的用户保留区中保存,如果这个区域用于其他目的,更新dfu_init.h中的偏移:UICR_CUSTOMER_DEVICE_INFO_OFFSET。

#defin  UICR_CUSTOMER_DEVICE_INFO_OFFSET 0x0  /**< Variable length array of SoftDevices compatible with this application. The length of the array is specified in the length field.SoftDevice firmware id 0xFFFE indicates any SoftDevice. */

2 应用程序版本在UICR中默认值为0xFFFF,这个值意味着初始化数据包中任何设备和版本信息的DFU数据都会被接收。

/* In order to support application versioning this check should be updated. This template allows for any application to be installed however customer could place a revision number at bottom of application to be verified by bootloader. This could be done  at a relative location to this papplication for example Application start address + 0x0100.*/

3 SoftDevice列表

  应用程序以特定的SoftDevice为目标专为某一nRF51芯片而编译,例如S110 v7.1.0。如果API向后兼容,一些应用程序可能运行在多种SoftDevice版本上,例如,一个应用程序专为SoftDevice S110 v7.1.0而编译,但也可以运行在SoftDevice S110 v7.0.0 上。可以在DFU初始化包中提供一个支持应用程序的SoftDevice列表。DFU检测该列表,看看是否与当前SoftDevice版本相对应,如果对应才继续升级。 如果值为0xFFFE,那意味着任何应用程序都可以安装而不管SoftDevice的版本,这个特性在开发中非常有用,但不要用在产品中。 当前SoftDevice的FWID值如下:

   SoftDevice S110icS1

  FWID

S110 v7.0.0

0x004F

S110 v7.1.0

0x005A

Development/any

0xFFFE

4  DFU初始化包生成方法

       Tan-v提供了DFU初始化包生成工具:make_dfu_initpacket.bat,生成的DFU init packet可直接用于手机APP升级,使用方法:

1. 把编译生成的hex文件“nrf51422_xxac.hex”(官方示例默认生成的hex文件名)放到 make initpacket 文件夹路径之下。注意:此hex文件名不可改变。

2. 点击 make_dfu_initpacket.bat ,则生成 bin 文件:nrf51422_xxac.bin 和DFU Init packet 文件:bootloader_initpacket.dat。

3. 把 bootloader_initpacket.dat 和nrf51422_xxac.hex保存到手机中,可直接用手机 DFU APP 进行升级。

注意:生成的DFU Init packet文件默认配置是支持任何设备类型、支持任何设备版本、支持S110 V7.0.0 和S110 V7.1.0,若要更改,更改config.dat文件中对应字段。

DFU 初始化包生成工具下载链接:http://pan.baidu.com/s/1dDgZQMX


摘自:http://www.cnblogs.com/tan-v/p/4291509.html

0 0