rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
fw_ota.c File Reference

The application slots over esp_ota_ops. More...

#include "fw_ota.h"
#include <stdio.h>
#include <string.h>
#include "esp_app_desc.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_partition.h"
#include "esp_system.h"

Data Structures

struct  ota_ctx_t
 One write into the slot that is not running. More...
struct  restart_note_t
 The note fw_ota_note_restart() leaves for the next start. More...

Macros

#define NOTE_MAGIC   0x52435550u
 A note that holds a version: "RCUP".

Functions

uint32_t fw_ota_slot_bytes (void)
 The slot an update writes.
bool fw_ota_running (fw_image_info_t *out)
 The running build: version and ELF (executable and linkable format) SHA-256, as fw_offer() compares them.
static bool ota_begin (void *ctx, uint32_t bytes)
 Open the slot that is not running for bytes.
static bool ota_write (void *ctx, uint32_t off, const uint8_t *src, uint32_t len)
 Write the next piece, at the offset the last one ended.
static bool ota_finish (void *ctx)
 Check the written slot and name it in otadata.
static void ota_abort (void *ctx)
 Drop a write under way.
const fw_flash_t * fw_ota_flash (void)
 The slot that is not running, for fw_install_begin().
static uint32_t note_check (const restart_note_t *n)
 FNV-1a (Fowler-Noll-Vo) over the note's version text.
void fw_ota_note_restart (const char *version)
 Before the restart into a written slot: what the next start reports when that build does not stay. Kept in memory a software restart keeps and a power cut clears.
static bool boot_pending (void *ctx)
 Whether the running build is pending verify.
static void boot_mark_invalid (void *ctx)
 Mark the running build invalid and restart into the one before.
static bool boot_mark_valid (void *ctx)
 Keep the running build: otadata says valid.
static void boot_restart (void *ctx)
 Restart.
static bool boot_last_invalid (void *ctx)
 Whether a slot is marked invalid by a start that went back.
bool fw_ota_trial_pending (void)
 Whether the running build is on its first start after an update (pending verify), and fw_ota_boot_check() still settles it.
fw_boot_t fw_ota_boot_check (bool ui_up, char *other, uint32_t other_cap)
 Once per start: with ui_up false at the display or touch failing, or with ui_up true once the start is known to work (fw_trial.h).

Variables

static const char * TAG = "fw_ota"
 The console tag.
static ota_ctx_t s_ctx
 The write under way; one at a time.
static const fw_flash_t k_flash
 The writer fw_install_begin() drives.
static RTC_NOINIT_ATTR restart_note_t s_note
 Kept across esp_restart() and a panic; a power cut clears it.
static const fw_boot_ops_t k_boot
 The calls fw_boot_decide() makes.

Detailed Description

The application slots over esp_ota_ops.

SPDX-License-Identifier: MIT

Function Documentation

◆ boot_last_invalid()

bool boot_last_invalid ( void * ctx)
static

Whether a slot is marked invalid by a start that went back.

Parameters
ctxUnused.
Returns
True when one is.

◆ boot_mark_invalid()

void boot_mark_invalid ( void * ctx)
static

Mark the running build invalid and restart into the one before.

Parameters
ctxUnused.

◆ boot_mark_valid()

bool boot_mark_valid ( void * ctx)
static

Keep the running build: otadata says valid.

Parameters
ctxUnused.
Returns
False when otadata could not be written.

◆ boot_pending()

bool boot_pending ( void * ctx)
static

Whether the running build is pending verify.

Parameters
ctxUnused.
Returns
True on a trial start.

◆ boot_restart()

void boot_restart ( void * ctx)
static

Restart.

Parameters
ctxUnused.

◆ fw_ota_boot_check()

fw_boot_t fw_ota_boot_check ( bool ui_up,
char * other,
uint32_t other_cap )

Once per start: with ui_up false at the display or touch failing, or with ui_up true once the start is known to work (fw_trial.h).

On a build's first start after an update: ui_up keeps it (FW_BOOT_UPDATED, or FW_BOOT_UNCONFIRMED when otadata could not be written), otherwise the panel restarts into the build before it and this does not return (fw_boot_decide()). After a start that went back: FW_BOOT_ROLLED_BACK with the written build's version in other, when fw_ota_note_restart() was called before it and no power cut came between.

Parameters
ui_upWhether the start is kept (true) or goes back (false).
otherWhere the written build's version goes; may be NULL with other_cap 0.
other_capBytes at other.
Returns
What the check found.

◆ fw_ota_flash()

const fw_flash_t * fw_ota_flash ( void )

The slot that is not running, for fw_install_begin().

Returns
Its writer.

◆ fw_ota_note_restart()

void fw_ota_note_restart ( const char * version)

Before the restart into a written slot: what the next start reports when that build does not stay. Kept in memory a software restart keeps and a power cut clears.

Parameters
versionThe written build's version.

◆ fw_ota_running()

bool fw_ota_running ( fw_image_info_t * out)

The running build: version and ELF (executable and linkable format) SHA-256, as fw_offer() compares them.

Parameters
outWhere they go.
Returns
False when its version does not parse.

◆ fw_ota_slot_bytes()

uint32_t fw_ota_slot_bytes ( void )

The slot an update writes.

Returns
Its bytes; 0 when the table has no second slot.

◆ fw_ota_trial_pending()

bool fw_ota_trial_pending ( void )

Whether the running build is on its first start after an update (pending verify), and fw_ota_boot_check() still settles it.

Returns
True on a trial start.

◆ note_check()

uint32_t note_check ( const restart_note_t * n)
static

FNV-1a (Fowler-Noll-Vo) over the note's version text.

Parameters
nThe note.
Returns
The hash.

◆ ota_abort()

void ota_abort ( void * ctx)
static

Drop a write under way.

Parameters
ctxThe ota_ctx_t.

◆ ota_begin()

bool ota_begin ( void * ctx,
uint32_t bytes )
static

Open the slot that is not running for bytes.

Parameters
ctxThe ota_ctx_t.
bytesThe image's size.
Returns
False when the slot is missing, too small or will not open.

◆ ota_finish()

bool ota_finish ( void * ctx)
static

Check the written slot and name it in otadata.

Parameters
ctxThe ota_ctx_t.
Returns
False when the check or the otadata write fails.

◆ ota_write()

bool ota_write ( void * ctx,
uint32_t off,
const uint8_t * src,
uint32_t len )
static

Write the next piece, at the offset the last one ended.

Parameters
ctxThe ota_ctx_t.
offThe piece's offset in the image.
srcThe bytes.
lenBytes at src.
Returns
False when the write is not open, out of order or fails.

Variable Documentation

◆ k_boot

const fw_boot_ops_t k_boot
static
Initial value:
= {
}
static bool boot_mark_valid(void *ctx)
Keep the running build: otadata says valid.
Definition fw_ota.c:220
static bool boot_last_invalid(void *ctx)
Whether a slot is marked invalid by a start that went back.
Definition fw_ota.c:247
static void boot_mark_invalid(void *ctx)
Mark the running build invalid and restart into the one before.
Definition fw_ota.c:205
static void boot_restart(void *ctx)
Restart.
Definition fw_ota.c:236
static bool boot_pending(void *ctx)
Whether the running build is pending verify.
Definition fw_ota.c:192

The calls fw_boot_decide() makes.

◆ k_flash

const fw_flash_t k_flash
static
Initial value:
= {
}
static bool ota_write(void *ctx, uint32_t off, const uint8_t *src, uint32_t len)
Write the next piece, at the offset the last one ended.
Definition fw_ota.c:87
static bool ota_finish(void *ctx)
Check the written slot and name it in otadata.
Definition fw_ota.c:109
static ota_ctx_t s_ctx
The write under way; one at a time.
Definition fw_ota.c:51
static void ota_abort(void *ctx)
Drop a write under way.
Definition fw_ota.c:133
static bool ota_begin(void *ctx, uint32_t bytes)
Open the slot that is not running for bytes.
Definition fw_ota.c:59

The writer fw_install_begin() drives.