hdr.h File Reference

RIOT "partition" header and tools. More...

Detailed Description

RIOT "partition" header and tools.

Author
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e
Francisco Acosta franc.nosp@m.isco.nosp@m..acos.nosp@m.ta@i.nosp@m.nria..nosp@m.fr

Definition in file hdr.h.

#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
+ Include dependency graph for hdr.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  riotboot_hdr_v1
 Structure to store image header - All members are little endian. More...
 
struct  riotboot_hdr_v2
 Structure to store image header v2 - All members are little endian. More...
 
union  riotboot_hdr
 Union to store riotboot headers in different versions. More...
 

Macros

#define RIOTBOOT_MAGIC_V1   0x544f4952 /* "RIOT" */
 Magic number for riotboot_hdr version 1.
 
#define RIOTBOOT_MAGIC_V2   0x54304952 /* "RI0T" */
 Magic number for riotboot_hdr version 2.
 
#define RIOTBOOT_HDR_IMAGE_BOOT_COUNT_SHIFT   0u
 Bit shift position of tentative boot counter.
 
#define RIOTBOOT_HDR_IMAGE_BOOT_COUNT_MASK   (0x0000000f << RIOTBOOT_HDR_IMAGE_BOOT_COUNT_SHIFT)
 4-bit mask of tentative boot counter
 
#define RIOTBOOT_HDR_IMAGE_STATE_SHIFT   4u
 Bit shift position of image boot state.
 
#define RIOTBOOT_HDR_IMAGE_STATE_MASK   (0x0000000f << RIOTBOOT_HDR_IMAGE_STATE_SHIFT)
 4-bit mask of image boot state
 
#define CONFIG_RIOTBOOT_MAX_ATTEMPTS   3u
 Maximum number of attempts to boot a tentative image before reverting to the previous one.
 

Typedefs

typedef enum riotboot_hdr_img_state riotboot_hdr_img_state_t
 Image state enumeration.
 
typedef union riotboot_hdr riotboot_hdr_t
 Union to store riotboot headers in different versions.
 

Enumerations

enum  riotboot_hdr_img_state {
  RIOTBOOT_HDR_IMG_STATE_INSTALLED = 0x0f , RIOTBOOT_HDR_IMG_STATE_DEACTIVATED = 0x0e , RIOTBOOT_HDR_IMG_STATE_ACTIVATED = 0x0c , RIOTBOOT_HDR_IMG_STATE_CONFIRMED = 0x08 ,
  RIOTBOOT_HDR_IMG_STATE_DISMISSED = 0x00
}
 Image state enumeration. More...
 

Functions

uint32_t riotboot_hdr_get_magic_number (const riotboot_hdr_t *riotboot_hdr)
 Getter for riotboot magic number. More...
 
uint32_t riotboot_hdr_get_version (const riotboot_hdr_t *riotboot_hdr)
 Getter for riotboot version. More...
 
uint32_t riotboot_hdr_get_start_addr (const riotboot_hdr_t *riotboot_hdr)
 Getter for riotboot start address. More...
 
uint32_t riotboot_hdr_get_flags (const riotboot_hdr_t *riotboot_hdr)
 Getter for riotboot flags. More...
 
uint32_t riotboot_hdr_get_checksum (const riotboot_hdr_t *riotboot_hdr)
 Getter for the header checksum. More...
 
void riotboot_hdr_print (const riotboot_hdr_t *riotboot_hdr)
 Print formatted riotboot_hdr_t to STDIO. More...
 
int riotboot_hdr_validate (const riotboot_hdr_t *riotboot_hdr)
 Validate image header. More...
 
uint32_t riotboot_hdr_checksum (const riotboot_hdr_t *riotboot_hdr)
 Calculate header checksum. More...
 
bool riotboot_hdr_is_v2 (const riotboot_hdr_t *riotboot_hdr)
 Check if the header is version 2. More...
 
unsigned riotboot_hdr_get_boot_count (const riotboot_hdr_t *riotboot_hdr)
 Get current image boot count. More...
 
void riotboot_hdr_set_boot_count (riotboot_hdr_t *riotboot_hdr, unsigned boot_count)
 Set image boot count. More...
 
int riotboot_hdr_set_img_state (riotboot_hdr_t *riotboot_hdr, riotboot_hdr_img_state_t state)
 Set image state. More...
 
int riotboot_hdr_get_img_state (const riotboot_hdr_t *riotboot_hdr)
 Get image state. More...
 

Enumeration Type Documentation

◆ riotboot_hdr_img_state

Image state enumeration.

Enumerator
RIOTBOOT_HDR_IMG_STATE_INSTALLED 

Image is installed (1111)

RIOTBOOT_HDR_IMG_STATE_DEACTIVATED 

Image is deactivated (1110)

RIOTBOOT_HDR_IMG_STATE_ACTIVATED 

Image is activated (1100)

RIOTBOOT_HDR_IMG_STATE_CONFIRMED 

Image is confirmed (1000)

RIOTBOOT_HDR_IMG_STATE_DISMISSED 

Image is dismissed (0000)

Definition at line 92 of file hdr.h.

Function Documentation

◆ riotboot_hdr_checksum()

uint32_t riotboot_hdr_checksum ( const riotboot_hdr_t riotboot_hdr)

Calculate header checksum.

Parameters
[in]riotboot_hdrptr to image header
Returns
the checksum of the given riotboot_hdr

◆ riotboot_hdr_get_boot_count()

unsigned riotboot_hdr_get_boot_count ( const riotboot_hdr_t riotboot_hdr)

Get current image boot count.

Parameters
[in]riotboot_hdrptr to image header
Returns
boot counter

◆ riotboot_hdr_get_checksum()

uint32_t riotboot_hdr_get_checksum ( const riotboot_hdr_t riotboot_hdr)

Getter for the header checksum.

Parameters
[in]riotboot_hdrptr to image header
Returns
Checksum of the given riotboot_hdr

◆ riotboot_hdr_get_flags()

uint32_t riotboot_hdr_get_flags ( const riotboot_hdr_t riotboot_hdr)

Getter for riotboot flags.

Parameters
[in]riotboot_hdrptr to image header
Returns
Flags

◆ riotboot_hdr_get_img_state()

int riotboot_hdr_get_img_state ( const riotboot_hdr_t riotboot_hdr)

Get image state.

Parameters
[in]riotboot_hdrptr to image header
Returns
image state

◆ riotboot_hdr_get_magic_number()

uint32_t riotboot_hdr_get_magic_number ( const riotboot_hdr_t riotboot_hdr)

Getter for riotboot magic number.

Parameters
[in]riotboot_hdrptr to image header
Returns
Magic number

◆ riotboot_hdr_get_start_addr()

uint32_t riotboot_hdr_get_start_addr ( const riotboot_hdr_t riotboot_hdr)

Getter for riotboot start address.

Parameters
[in]riotboot_hdrptr to image header
Returns
Start address

◆ riotboot_hdr_get_version()

uint32_t riotboot_hdr_get_version ( const riotboot_hdr_t riotboot_hdr)

Getter for riotboot version.

Parameters
[in]riotboot_hdrptr to image header
Returns
Version number

◆ riotboot_hdr_is_v2()

bool riotboot_hdr_is_v2 ( const riotboot_hdr_t riotboot_hdr)

Check if the header is version 2.

Parameters
[in]riotboot_hdrptr to image header
Returns
true if version is 2, false otherwise

◆ riotboot_hdr_print()

void riotboot_hdr_print ( const riotboot_hdr_t riotboot_hdr)

Print formatted riotboot_hdr_t to STDIO.

Parameters
[in]riotboot_hdrptr to image header

◆ riotboot_hdr_set_boot_count()

void riotboot_hdr_set_boot_count ( riotboot_hdr_t riotboot_hdr,
unsigned  boot_count 
)

Set image boot count.

Parameters
[in]riotboot_hdrptr to image header
[in]boot_countnew boot count

◆ riotboot_hdr_set_img_state()

int riotboot_hdr_set_img_state ( riotboot_hdr_t riotboot_hdr,
riotboot_hdr_img_state_t  state 
)

Set image state.

Parameters
[in]riotboot_hdrptr to image header
[in]statenew image state
Returns
0 on success, -1 on failure

◆ riotboot_hdr_validate()

int riotboot_hdr_validate ( const riotboot_hdr_t riotboot_hdr)

Validate image header.

Parameters
[in]riotboot_hdrptr to image header
Returns
0 if OK
-1 if not OK