BootMap

概述

BootMap 为 SDK 启动过程提供 boot map image 配置相关功能。

底层存储

bootmap 通过调用 bootmap 相关 API 来获取已经更新 bootmap 中的 image 信息。bootmap 中存储了所有 image 的起始位置,长度,类型等信息

备注

bootmap 本身采用乒乓算法的存储方式,所以有掉电保护的功能,对于固定大小的 flash,bootmap 本身的存储位置是固定的,存储大小目前固定使用 8K, 两个 flash sector, 一般在 flash 倒数第二,第三个 sector

存储结构

当前,我们假设 flash 扇区大小为 4096 字节,

bootmap 结构如下图所示,括号内数字表示该部分的大小(以字节为单位)。

+----------------------+--------------+--------------+-------------+
|       index (4)      | image. no.(1)| boot type(1) |  Unused (2) |   页头部 (8)
+----------+-----------+-------+--------+---------+----------------+
| type (1) | Unused (3)| lma(4)| vma(4) |  len(4) | area len(4)    |   image0 信息 (20)
+------------------------------------------------------------------+
| type (1) | Unused (3)| lma(4)| vma(4) |  len(4) | area len(4)    |   image1 信息 (20)
+------------------------------------------------------------------+
| type (1) | Unused (3)| lma(4)| vma(4) |  len(4) | area len(4)    |   image2 信息 (20)
|+-----------------------------------------------------------------+
/                                                                  /
/                                                                  /
+------------------------------------------------------------------+
|                       image* information (20)                    |   image n 信息 (20)
+------------------------------------------------------------------+
|                       CRC32(4)                                   |   bootmap 校验 (4)
+------------------------------------------------------------------+

该结构存储在 bootmap 区域,每次更新后 index 减小 1,存入乒乓的另一个区域,每次取 index 小的值为最新的信息

API 介绍

This section introduces the BOOTMAP module's enum, structure, functions and how to use this component.

Defines

BOOTMAP_MAGIC

BOOTMAP header MAIGC, string WqBM.

WQ_IMAGE_MAGIC

Image header MAIGC.

BOOT_SECTION_OTA

Boot from OTA section, reserved.

BOOT_SECTION_TRY

Test boot from default section, reserved.

BOOT_SECTION_SBL

Boot from SBL section, reserved.

BOOT_SECTION_STANDARD

Boot from STANDARD section, reserved.

Enums

enum WQ_IMAGE_TYPE

Values:

enumerator IMAGE_TYPE_ROM

Image ROM type, don't need use now

enumerator IMAGE_TYPE_PBL

Image PBL type, deprecatped

enumerator IMAGE_TYPE_SYSDATA

Image SYSDATA type

enumerator IMAGE_TYPE_OTA

Image OTA type, used for upgrade firmware

enumerator IMAGE_TYPE_KV

Image KV type,for saving key-value information

enumerator IMAGE_TYPE_BOOTMAP

Image bootmap type itself,flash partion information

enumerator IMAGE_TYPE_CALDATA

Image caculate type, storage calibration information

enumerator IMAGE_TYPE_SBL0

Image SBL type, second bootloader

enumerator IMAGE_TYPE_SBL1

deprecatped

enumerator IMAGE_TYPE_RECOVER

Image recover type, used for recover firmware

enumerator IMAGE_TYPE_MAX
enum [anonymous]

Values:

enumerator WQ_BOOT_MODE_NORMAL

Normal boot mode

enumerator WQ_BOOT_MODE_OTA

OTA boot mode, will decompress ota firmware to running partion

enumerator WQ_BOOT_MODE_UNKONWN

Functions

WQ_RET bootmap_get_valid_map(bootmap_t *boot_map)

This function is to get bootmap's vaildity.

参数:

boot_map -- is boot map

返回:

  • WQ_RET_OK success.

  • WQ_RET_INVALID param error.

  • WQ_RET_NOT_EXIST no valid bootmap found.

WQ_RET bootmap_get_image(bootmap_image_t *image, uint8_t id)

This function is to get boot map's image.

参数:
  • image -- is bootmap's image

  • id -- is image id

返回:

  • WQ_RET_OK success.

  • WQ_RET_INVALID param error.

  • WQ_RET_NOT_EXIST no valid bootmap or image found.

WQ_RET bootmap_get_boot_type(uint8_t *boot_type)

This function is to get boot map's type.

返回:

  • WQ_RET_OK success.

  • WQ_RET_NOT_EXIST no valid bootmap found.

WQ_RET bootmap_set_boot_type(uint8_t boot_type)

This function is to set boot map's boot type.

参数:

boot_type -- is boot map's bppt type

返回:

  • WQ_RET_OK success.

  • WQ_RET_FAIL bootmap write fail.

  • WQ_RET_NOSUPP unsupport boot type

  • WQ_RET_NOT_EXIST no valid bootmap found.

struct bootmap_image_t
#include <bootmap.h>

Boot map image information.

Public Members

uint8_t image_type

Image ID

uint8_t reserved[3]

reserved

uint32_t code_lma

Flash offset start from 0

uint32_t code_vma

Image '_start' address

uint32_t code_length

Image true size

uint32_t code_area_size

Image Flash section size

struct bootmap_t
#include <bootmap.h>

Boot map main header.

Public Members

uint32_t index

index for header using

uint8_t image_num

total images number

uint8_t boot_type

boot type

uint8_t reserved[2]

reserved

struct wq_image_header_t
#include <bootmap.h>

Flash image header.

Public Members

uint32_t guard

Magic for image header check

uint32_t length

Image size except this header

uint32_t version

Image version

uint32_t start

Image '_start' address

uint32_t crc

Image crc except header

uint8_t tlv_count

Number of image tlv

uint8_t reserved0[3]

reserved

uint32_t stack

main stack address of th image

uint8_t reserved1[4]

reserved