If you need urgent consulting help click here

Flash Image

The flash image API as part of the Device Firmware Upgrade (DFU) subsystem provides an abstraction on top of Flash Stream to simplify writing firmware image chunks to flash.

API Reference

group flash_img_api

Abstraction layer to write firmware images to flash.

Functions

int flash_img_init_id(struct flash_img_context *ctx, uint8_t area_id)

Initialize context needed for writing the image to the flash.

Parameters
  • ctx – context to be initialized

  • area_id – flash area id of partition where the image should be written

Returns

0 on success, negative errno code on fail

int flash_img_init(struct flash_img_context *ctx)

Initialize context needed for writing the image to the flash.

Parameters
  • ctx – context to be initialized

Returns

0 on success, negative errno code on fail

size_t flash_img_bytes_written(struct flash_img_context *ctx)

Read number of bytes of the image written to the flash.

Parameters
  • ctx – context

Returns

Number of bytes written to the image flash.

int flash_img_buffered_write(struct flash_img_context *ctx, const uint8_t *data, size_t len, bool flush)

Process input buffers to be written to the image slot 1. flash memory in single blocks. Will store remainder between calls.

A final call to this function with flush set to true will write out the remaining block buffer to flash. Since flash is written to in blocks, the contents of flash from the last byte written up to the next multiple of CONFIG_IMG_BLOCK_BUF_SIZE is padded with 0xff.

Parameters
  • ctx – context

  • data – data to write

  • len – Number of bytes to write

  • flush – when true this forces any buffered data to be written to flash

Returns

0 on success, negative errno code on fail

int flash_img_check(struct flash_img_context *ctx, const struct flash_img_check *fic, uint8_t area_id)

Verify flash memory length bytes integrity from a flash area. The start point is indicated by an offset value.

The function is enabled via CONFIG_IMG_ENABLE_IMAGE_CHECK Kconfig options.

Parameters
  • ctx[in] context.

  • fic[in] flash img check data.

  • area_id[in] flash area id of partition where the image should be verified.

Returns

0 on success, negative errno code on fail

struct flash_img_context
#include <flash_img.h>
struct flash_img_check
#include <flash_img.h>

Structure for verify flash region integrity.

Match vector length is fixed and depends on size from hash algorithm used to verify flash integrity. The current available algorithm is SHA-256.

Public Members

size_t clen

Match vector data