K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
Image scrub

Data Structures

struct  kfsw_scrub_result
 
struct  kfsw_scrub_status
 

Macros

#define KFSW_SCRUB_PARAM_TABLE_ID   39U
 
#define KFSW_SCRUB_PARAM_TABLE_NAME   "scrub"
 
#define KFSW_SCRUB_NAME_SIZE   8U
 

Types

typedef bool(* kfsw_scrub_visitor_t) (const struct kfsw_scrub_result *result, void *context)
 

Enumerations

enum  kfsw_scrub_region { KFSW_SCRUB_SLOT0 = 0 , KFSW_SCRUB_SLOT1 = 1 , KFSW_SCRUB_GOLDEN = 2 , KFSW_SCRUB_REGIONS = 3 }
 
enum  kfsw_scrub_state {
  KFSW_SCRUB_EMPTY = 0 , KFSW_SCRUB_UNKNOWN = 1 , KFSW_SCRUB_OK = 2 , KFSW_SCRUB_MISMATCH = 3 ,
  KFSW_SCRUB_UNREADABLE = 4 , KFSW_SCRUB_ABSENT = 5
}
 
enum  kfsw_scrub_event { KFSW_EVENT_SCRUB_MISMATCH = 1 }
 

Functions

int kfsw_scrub_start (void)
 
int kfsw_scrub_stop (void)
 
int kfsw_scrub_sweep (void)
 
int kfsw_scrub_sweep_region (enum kfsw_scrub_region region)
 
int kfsw_scrub_learn (enum kfsw_scrub_region region)
 
void kfsw_scrub_get_status (struct kfsw_scrub_status *status)
 
int kfsw_scrub_get_result (enum kfsw_scrub_region region, struct kfsw_scrub_result *result)
 
void kfsw_scrub_visit_regions (kfsw_scrub_visitor_t visitor, void *context)
 

Variables

const struct kfsw_param_definition_set kfsw_scrub_param_definitions
 

Description

Re-reads the resident images and compares a CRC32 against a reference kept across resets.

FWU checks an image as it arrives and the bootloader checks the slot it boots; without this, the slot that is not running and the recovery image are never read again, so a bit flip in either is found when the image is needed and not before.

The reference is learned on command, never silently: a region whose reference is unknown reports KFSW_SCRUB_UNKNOWN and never KFSW_SCRUB_OK.

The storage partition is deliberately not a region. It is a mutable filesystem holding the parameter snapshots, the journal and the procedure files, so a checksum over it would differ after every ordinary write.

Macro Documentation

◆ KFSW_SCRUB_NAME_SIZE

#define KFSW_SCRUB_NAME_SIZE   8U

#include <scrub.h>

Longest region name kept, including the terminator.

◆ KFSW_SCRUB_PARAM_TABLE_ID

#define KFSW_SCRUB_PARAM_TABLE_ID   39U

#include <scrub.h>

Table 39: what the last sweep found in each region.

◆ KFSW_SCRUB_PARAM_TABLE_NAME

#define KFSW_SCRUB_PARAM_TABLE_NAME   "scrub"

#include <scrub.h>

Parameter table name.

Type Documentation

◆ kfsw_scrub_visitor_t

typedef bool(* kfsw_scrub_visitor_t) (const struct kfsw_scrub_result *result, void *context)

#include <scrub.h>

A visitor over the regions.

Returning false stops the walk.

Enumeration Documentation

◆ kfsw_scrub_event

#include <scrub.h>

Event IDs of this service.

Enumerator
KFSW_EVENT_SCRUB_MISMATCH 

A region's image no longer matches its reference.

Payload: the region id, then the measured CRC32 as a big-endian u32.

◆ kfsw_scrub_region

#include <scrub.h>

The regions this build can sweep.

Enumerator
KFSW_SCRUB_SLOT0 

The primary slot, where the running image came from.

KFSW_SCRUB_SLOT1 

The secondary slot, where an update waits for its swap.

KFSW_SCRUB_GOLDEN 

The recovery image.

KFSW_SCRUB_REGIONS 

Regions defined, present or not.

◆ kfsw_scrub_state

#include <scrub.h>

What a sweep concluded about one region.

Enumerator
KFSW_SCRUB_EMPTY 

No image header, so there is nothing to check.

An erased secondary slot reads this way and it is the normal case.

KFSW_SCRUB_UNKNOWN 

An image is there and no reference has been learned for it.

KFSW_SCRUB_OK 

The measured CRC32 matches the reference.

KFSW_SCRUB_MISMATCH 

It does not.

The image on flash is not the one that was learned.

KFSW_SCRUB_UNREADABLE 

The region could not be read.

KFSW_SCRUB_ABSENT 

The region does not exist in this build.

Function Documentation

◆ kfsw_scrub_get_result()

int kfsw_scrub_get_result ( enum kfsw_scrub_region  region,
struct kfsw_scrub_result *  result 
)

#include <scrub.h>

Read one region's last result.

Returns -EINVAL for an unknown region.

◆ kfsw_scrub_get_status()

void kfsw_scrub_get_status ( struct kfsw_scrub_status *  status)

#include <scrub.h>

Copy the counters.

◆ kfsw_scrub_learn()

int kfsw_scrub_learn ( enum kfsw_scrub_region  region)

#include <scrub.h>

Take the last measurement of a region as its reference.

Sweeps the region first, so what is learned is what is on flash now. The reference is persisted, because a reference held only in RAM would be relearned at every boot and could never report a mismatch.

Return values
0Learned and persisted.
-ENODEVThe region does not exist in this build.
-ENOENTThe region holds no image.
-EIOThe region could not be read, or the snapshot not written.

◆ kfsw_scrub_start()

int kfsw_scrub_start ( void  )

#include <scrub.h>

Start sweeping on the configured period.

◆ kfsw_scrub_stop()

int kfsw_scrub_stop ( void  )

#include <scrub.h>

Stop sweeping.

The recorded numbers stay readable.

◆ kfsw_scrub_sweep()

int kfsw_scrub_sweep ( void  )

#include <scrub.h>

Sweep every present region once.

Returns
Regions swept, or a negative errno.

◆ kfsw_scrub_sweep_region()

int kfsw_scrub_sweep_region ( enum kfsw_scrub_region  region)

#include <scrub.h>

Sweep one region.

Return values
0Swept; read the result to see what it concluded.
-ENODEVThe region does not exist in this build.
-EINVALNo such region.

◆ kfsw_scrub_visit_regions()

void kfsw_scrub_visit_regions ( kfsw_scrub_visitor_t  visitor,
void *  context 
)

#include <scrub.h>

Walk every region, present or not, in id order.

Variable Documentation

◆ kfsw_scrub_param_definitions

const struct kfsw_param_definition_set kfsw_scrub_param_definitions
extern

#include <scrub.h>

Parameter table 39.