SimpleOTA client v1.2.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_trial.h File Reference

What a boot means for a saved trial record. More...

Go to the source code of this file.

Data Structures

struct  sota_boot_facts_t
 The trial record and the boot's facts that sota_classify_boot() reads. More...
 

Enumerations

enum  sota_boot_outcome_t {
  SOTA_BOOT_NONE = 0 , SOTA_BOOT_TRIAL , SOTA_BOOT_ROLLED_BACK , SOTA_BOOT_REPORT_PENDING ,
  SOTA_BOOT_WAITING , SOTA_BOOT_ABANDONED , SOTA_BOOT_INCOMPLETE , SOTA_BOOT_TRIAL_RESET ,
  SOTA_BOOT_ROLLBACK_CUT
}
 What a boot means for the saved trial record, and what to do about it. More...
 
enum  { SOTA_TRIAL_STAGED = 1 , SOTA_TRIAL_ROLLED_BACK = 2 , SOTA_TRIAL_BOOTED = 3 }
 sota_trial values. More...
 
enum  { SOTA_STAGED_STARTED = 1 , SOTA_STAGED_SNAPSHOT = 2 }
 sota_staged values. More...
 
enum  {
  SOTA_RST_POWERON = 1 , SOTA_RST_SW = 3 , SOTA_RST_PANIC = 4 , SOTA_RST_INT_WDT = 5 ,
  SOTA_RST_TASK_WDT = 6 , SOTA_RST_WDT = 7 , SOTA_RST_DEEPSLEEP = 8 , SOTA_RST_BROWNOUT = 9
}
 esp_reset_reason_t values used for rollback reasons.
 

Functions

static bool sota_on_new_image (const sota_boot_facts_t *f)
 Whether the running image is the update's, from sota_new_part or else sota_prev_part.
 
static sota_boot_outcome_t sota_classify_boot (const sota_boot_facts_t *f)
 Classify this boot against the trial record.
 
static bool sota_abandon_restores_identity (uint8_t staged)
 An abandoned record puts the previous identity back only when it was saved in full.
 
static bool sota_hold_pending_image (bool image_pending, sota_boot_outcome_t outcome)
 Arduino's verifyRollbackLater(): keep an image the bootloader still has on probation (pending verify) only when it is a SimpleOTA trial.
 
static bool sota_reset_is_crash (int reset_reason)
 The reset was a crash or a watchdog.
 
static const char * sota_rollback_reason (int reset_reason)
 Reason sent with rolled_back, from the reset that ended the trial.
 

Detailed Description

What a boot means for a saved trial record.

The trial record uses NVS keys that every release of both clients reads and writes: sota_trial (1 = trial, 3 = a trial whose image has booted, 2 = a rollback happened), sota_new_part (where the update went) and sota_prev_part (the partition the update replaced). Arduino releases up to 0.6.0 write only sota_prev_part; ESP-IDF releases write both. The classifier uses sota_new_part when it is there and falls back to sota_prev_part, so a record from any earlier release of either client reads the way that release meant it.

The apply path also writes sota_staged before the boot slot switches and removes it straight after, so a record whose slot switch never happened can be told apart from a rollback. A release that does not know sota_staged ignores it, and a record written without it reads like any other, so updates in either direction between releases read the same way.

Any trial value other than 0 and 2 is a trial, so a release that does not know 3 reads it as one.

No platform types, so the host tests can include this header.

Enumeration Type Documentation

◆ sota_boot_outcome_t

What a boot means for the saved trial record, and what to do about it.

Enumerator
SOTA_BOOT_NONE 

No trial record.

SOTA_BOOT_TRIAL 

Running the new image: supervise it.

SOTA_BOOT_ROLLED_BACK 

Not on the new image: restore identity, report.

SOTA_BOOT_REPORT_PENDING 

A previous boot recorded a rollback: report it.

SOTA_BOOT_WAITING 

Flashed, not booted yet (deep-sleep wake).

SOTA_BOOT_ABANDONED 

The slot switch never happened: drop quietly.

SOTA_BOOT_INCOMPLETE 

The record cannot be checked: drop it.

SOTA_BOOT_TRIAL_RESET 

The new image reset before it was confirmed: roll back.

SOTA_BOOT_ROLLBACK_CUT 

A rollback was saved but its slot switch never happened.

◆ anonymous enum

anonymous enum

sota_trial values.

Enumerator
SOTA_TRIAL_STAGED 

The new image has not booted yet.

SOTA_TRIAL_ROLLED_BACK 

A rollback was decided and saved.

SOTA_TRIAL_BOOTED 

The new image booted once; any reset ends the trial.

◆ anonymous enum

anonymous enum

sota_staged values.

The apply path writes STARTED first, then the previous image's identity, then SNAPSHOT, and only then overwrites the live identity with the new build's.

Enumerator
SOTA_STAGED_STARTED 

The record is being written.

SOTA_STAGED_SNAPSHOT 

The previous image's identity is saved.

Function Documentation

◆ sota_on_new_image()

static bool sota_on_new_image ( const sota_boot_facts_t *  f)
inlinestatic

Whether the running image is the update's, from sota_new_part or else sota_prev_part.

False when neither is known.

◆ sota_classify_boot()

static sota_boot_outcome_t sota_classify_boot ( const sota_boot_facts_t *  f)
inlinestatic

Classify this boot against the trial record.

Pure, so the host tests cover every power-cut point.

◆ sota_abandon_restores_identity()

static bool sota_abandon_restores_identity ( uint8_t  staged)
inlinestatic

An abandoned record puts the previous identity back only when it was saved in full.

Before that, the live identity was not touched.

◆ sota_hold_pending_image()

static bool sota_hold_pending_image ( bool  image_pending,
sota_boot_outcome_t  outcome 
)
inlinestatic

Arduino's verifyRollbackLater(): keep an image the bootloader still has on probation (pending verify) only when it is a SimpleOTA trial.

Any other pending image, such as one written by ArduinoOTA, is left for the Arduino core to accept.

◆ sota_reset_is_crash()

static bool sota_reset_is_crash ( int  reset_reason)
inlinestatic

The reset was a crash or a watchdog.

A trial that crashed before it could save its first boot (SOTA_TRIAL_BOOTED), such as in a global constructor, has failed it too. Other resets cannot be told apart from the restart into the update.