dfu: mcuboot: add boot_read_bank_header()
This is an accessor function for the MCUboot image header of an image bank. The interface may seem a little cumbersome, but it is future-proof against MCUboot feature and incompatible header version changes. Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
This commit is contained in:
parent
01aa12bffd
commit
e2c9be1a18
2 changed files with 195 additions and 4 deletions
|
@ -9,6 +9,88 @@
|
|||
#define __MCUBOOT_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <zephyr/types.h>
|
||||
|
||||
/**
|
||||
* @brief MCUboot image header representation for image version
|
||||
*
|
||||
* The header for an MCUboot firmware image contains an embedded
|
||||
* version number, in semantic versioning format. This structure
|
||||
* represents the information it contains.
|
||||
*/
|
||||
struct mcuboot_img_sem_ver {
|
||||
u8_t major;
|
||||
u8_t minor;
|
||||
u16_t revision;
|
||||
u32_t build_num;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Model for the MCUboot image header as of version 1
|
||||
*
|
||||
* This represents the data present in the image header, in version 1
|
||||
* of the header format.
|
||||
*
|
||||
* Some information present in the header but not currently relevant
|
||||
* to applications is omitted.
|
||||
*/
|
||||
struct mcuboot_img_header_v1 {
|
||||
/** The size of the image, in bytes. */
|
||||
u32_t image_size;
|
||||
/** The image version. */
|
||||
struct mcuboot_img_sem_ver sem_ver;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Model for the MCUBoot image header
|
||||
*
|
||||
* This contains the decoded image header, along with the major
|
||||
* version of MCUboot that the header was built for.
|
||||
*
|
||||
* (The MCUboot project guarantees that incompatible changes to the
|
||||
* image header will result in major version changes to the bootloader
|
||||
* itself, and will be detectable in the persistent representation of
|
||||
* the header.)
|
||||
*/
|
||||
struct mcuboot_img_header {
|
||||
/**
|
||||
* The version of MCUboot the header is built for.
|
||||
*
|
||||
* The value 1 corresponds to MCUboot versions 1.x.y.
|
||||
*/
|
||||
u32_t mcuboot_version;
|
||||
/**
|
||||
* The header information. It is only valid to access fields
|
||||
* in the union member corresponding to the mcuboot_version
|
||||
* field above.
|
||||
*/
|
||||
union {
|
||||
/** Header information for MCUboot version 1. */
|
||||
struct mcuboot_img_header_v1 v1;
|
||||
} h;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Read the MCUboot image header information from an image bank.
|
||||
*
|
||||
* This attempts to parse the image header, which must begin at offset
|
||||
* @a bank_offset from the beginning of the flash device used by
|
||||
* MCUboot.
|
||||
*
|
||||
* @param bank_offset Offset of the image header from the start of the
|
||||
* flash device used by MCUboot to store firmware.
|
||||
* @param header On success, the returned header information is available
|
||||
* in this structure.
|
||||
* @param header_size Size of the header structure passed by the caller.
|
||||
* If this is not large enough to contain all of the
|
||||
* necessary information, an error is returned.
|
||||
* @return Zero on success, a negative value on error.
|
||||
*/
|
||||
int boot_read_bank_header(u32_t bank_offset,
|
||||
struct mcuboot_img_header *header,
|
||||
size_t header_size);
|
||||
|
||||
/**
|
||||
* @brief Check if the currently running image is confirmed as OK.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue