|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The IOmcu's half of the firmware update. More...
#include "link_update_dev.h"#include <stddef.h>#include <string.h>#include "link_crc.h"#include "link_msg.h"Functions | |
| void | link_update_dev_init (link_update_dev_t *u, const link_update_io_t *io, const uint8_t *running, const uint8_t *target, uint32_t slot_bytes, uint16_t slot) |
Start idle. slot is LINK_UPD_SLOT as the boot ROM reports it: the running slot, LINK_UPD_SLOT_NONE without a partition table this build writes, and LINK_UPD_SLOT_TRIAL for an image that waits for its BUY. running and target may be NULL with LINK_UPD_SLOT_NONE. | |
| static bool | in_session (uint8_t state) |
| Test whether a state is inside an update session. | |
| static bool | gate_open (const link_update_dev_t *u) |
| Ask the callback whether flash may be written. | |
| static uint8_t | refuse (link_update_dev_t *u, uint8_t err, uint8_t nack) |
| A refusal: the reason kept for LINK_UPD_ERROR, the code for the NACK. | |
| static uint8_t | fail (link_update_dev_t *u, uint8_t err) |
| A failure that ends the session. | |
| static uint32_t | arg32 (const uint16_t *a) |
| Read a 32-bit argument held in two registers, low word first. | |
| static uint8_t | cmd_hash_running (link_update_dev_t *u, const uint16_t *a) |
| Handle HASH_RUNNING: start hashing the running slot's image. | |
| static uint8_t | cmd_begin (link_update_dev_t *u, const uint16_t *a) |
| Handle BEGIN: erase the first sector and open a receive session. | |
| static void | staged_bytes (const link_update_dev_t *u, uint8_t *out) |
| The block staged in UPDATE_DATA as bytes, low byte of each register first. | |
| static uint8_t | cmd_commit (link_update_dev_t *u, const uint16_t *a) |
| Handle COMMIT: check one staged block and place it. | |
| static uint8_t | cmd_finish (link_update_dev_t *u) |
| Handle FINISH: start hashing the bytes as written. | |
| static uint8_t | cmd_activate (link_update_dev_t *u) |
| Handle ACTIVATE: write the first sector and owe a restart. | |
| static uint8_t | cmd_abort (link_update_dev_t *u) |
| Handle ABORT: return to idle. | |
| static uint8_t | cmd_buy (link_update_dev_t *u) |
| Handle BUY: buy the image on trial and owe the other slot's erase. | |
| void | link_update_dev_read_ctl (link_update_dev_t *u, uint8_t offset, uint8_t count, uint16_t *out) |
| The two pages' handlers, for the caller's link_page_t table. | |
| uint8_t | link_update_dev_write_ctl (link_update_dev_t *u, uint8_t offset, uint8_t count, const uint16_t *in) |
| Write registers of the UPDATE_CTL page: one command and its arguments. | |
| void | link_update_dev_read_data (link_update_dev_t *u, uint8_t offset, uint8_t count, uint16_t *out) |
| Read registers of the UPDATE_DATA page. | |
| uint8_t | link_update_dev_write_data (link_update_dev_t *u, uint8_t offset, uint8_t count, const uint16_t *in) |
| Write registers of the UPDATE_DATA page: stage part of a block. | |
| static const uint8_t * | verify_src (const link_update_dev_t *u, uint32_t pos) |
Where the byte at pos of the image being checked is read from: the first sector from RAM, which ACTIVATE has not written yet. | |
| static void | sweep (link_update_dev_t *u, uint32_t now_ms) |
| The owed erase of the other slot's first sector: outside a session and a trial, with the gate open, once every LINK_UPD_SWEEP_MS. | |
| void | link_update_dev_poll (link_update_dev_t *u, uint32_t now_ms) |
| The work that does not fit a reply: LINK_UPD_HASH_STEP bytes of a hash, the restart LINK_UPD_RESTART_MS after ACTIVATE, an owed erase of the other slot's first sector, and the end of a session that has had no request to either update page for LINK_UPD_SILENCE_MS. | |
| bool | link_update_dev_holds_arm (const link_update_dev_t *u) |
| True while ARM is refused: a session runs or an image waits for BUY. | |
| bool | link_update_dev_refuses_arm (const link_update_dev_t *u, uint8_t off, uint8_t n, const uint16_t *in) |
Whether a write of n CONTROL registers from off is refused for the update: it asks for a non-zero ARM while link_update_dev_holds_arm(). | |
The IOmcu's half of the firmware update.
See link_update_dev.h and the update section of link_pages.h.
SPDX-License-Identifier: MIT
|
static |
Read a 32-bit argument held in two registers, low word first.
| a | The command registers; the argument is a[1] and a[2]. |
|
static |
Handle ABORT: return to idle.
| u | The update state; refused once ACTIVATED. |
|
static |
Handle ACTIVATE: write the first sector and owe a restart.
| u | The update state; it must be VERIFIED. |
|
static |
Handle BEGIN: erase the first sector and open a receive session.
| u | The update state. |
| a | The command registers; the image size is arg32(a). |
|
static |
Handle BUY: buy the image on trial and owe the other slot's erase.
| u | The update state. |
|
static |
Handle COMMIT: check one staged block and place it.
| u | The update state. |
| a | The command registers: a[1] is the block, a[2] its CRC. |
|
static |
Handle FINISH: start hashing the bytes as written.
| u | The update state; it must be RECEIVED. |
|
static |
Handle HASH_RUNNING: start hashing the running slot's image.
| u | The update state. |
| a | The command registers; the length is arg32(a). |
|
static |
A failure that ends the session.
| u | The update state. |
| err | The reason, a link_upd_err_t. |
|
static |
Ask the callback whether flash may be written.
| u | The update state; u->io must be set. |
|
static |
Test whether a state is inside an update session.
| state | A link_upd_state_t value. |
| bool link_update_dev_holds_arm | ( | const link_update_dev_t * | u | ) |
True while ARM is refused: a session runs or an image waits for BUY.
| u | The update state; NULL gives false. |
| void link_update_dev_init | ( | link_update_dev_t * | u, |
| const link_update_io_t * | io, | ||
| const uint8_t * | running, | ||
| const uint8_t * | target, | ||
| uint32_t | slot_bytes, | ||
| uint16_t | slot ) |
Start idle. slot is LINK_UPD_SLOT as the boot ROM reports it: the running slot, LINK_UPD_SLOT_NONE without a partition table this build writes, and LINK_UPD_SLOT_TRIAL for an image that waits for its BUY. running and target may be NULL with LINK_UPD_SLOT_NONE.
A bought image that finds the other slot's first sector written owes its erase.
| u | The update state to set up. |
| io | The callbacks; kept, not copied. |
| running | The running slot's bytes. |
| target | The other slot's bytes. |
| slot_bytes | Bytes in one slot, a multiple of the 4KiB sector. |
| slot | LINK_UPD_SLOT as the boot ROM reports it. |
| void link_update_dev_poll | ( | link_update_dev_t * | u, |
| uint32_t | now_ms ) |
The work that does not fit a reply: LINK_UPD_HASH_STEP bytes of a hash, the restart LINK_UPD_RESTART_MS after ACTIVATE, an owed erase of the other slot's first sector, and the end of a session that has had no request to either update page for LINK_UPD_SILENCE_MS.
Once per pass of the caller's loop.
| u | The update state. |
| now_ms | The current time, in ms. |
| void link_update_dev_read_ctl | ( | link_update_dev_t * | u, |
| uint8_t | offset, | ||
| uint8_t | count, | ||
| uint16_t * | out ) |
The two pages' handlers, for the caller's link_page_t table.
| u | The update state. |
| offset | First register, 0 to LINK_UPD_COUNT - 1. |
| count | Number of registers to read. |
| out | Receives the registers. |
| void link_update_dev_read_data | ( | link_update_dev_t * | u, |
| uint8_t | offset, | ||
| uint8_t | count, | ||
| uint16_t * | out ) |
Read registers of the UPDATE_DATA page.
| u | The update state. |
| offset | First register of the staged block. |
| count | Number of registers to read. |
| out | Receives the registers. |
| bool link_update_dev_refuses_arm | ( | const link_update_dev_t * | u, |
| uint8_t | off, | ||
| uint8_t | n, | ||
| const uint16_t * | in ) |
Whether a write of n CONTROL registers from off is refused for the update: it asks for a non-zero ARM while link_update_dev_holds_arm().
The caller answers it with LINK_NACK_NOT_ARMED before the page's own rules run, so nothing of the frame is stored. A disarm is always taken.
| u | The update state. |
| off | First CONTROL register of the write. |
| n | Number of registers in the write. |
| in | The registers written. |
| uint8_t link_update_dev_write_ctl | ( | link_update_dev_t * | u, |
| uint8_t | offset, | ||
| uint8_t | count, | ||
| const uint16_t * | in ) |
Write registers of the UPDATE_CTL page: one command and its arguments.
| u | The update state. |
| offset | First register; must be LINK_UPD_CMD. |
| count | Number of registers, 1 to 4. |
| in | The registers written. |
| uint8_t link_update_dev_write_data | ( | link_update_dev_t * | u, |
| uint8_t | offset, | ||
| uint8_t | count, | ||
| const uint16_t * | in ) |
Write registers of the UPDATE_DATA page: stage part of a block.
| u | The update state. |
| offset | First register of the block, 0 to LINK_UPD_DATA_COUNT - 1. |
| count | Number of registers written. |
| in | The registers written. |
|
static |
A refusal: the reason kept for LINK_UPD_ERROR, the code for the NACK.
| u | The update state. |
| err | The reason, a link_upd_err_t, kept in u->error. |
| nack | The NACK code returned to the caller. |
|
static |
The block staged in UPDATE_DATA as bytes, low byte of each register first.
| u | The update state; its data registers are read. |
| out | Receives 2 * LINK_UPD_DATA_COUNT bytes. |
|
static |
The owed erase of the other slot's first sector: outside a session and a trial, with the gate open, once every LINK_UPD_SWEEP_MS.
| u | The update state. |
| now_ms | The current time, in ms. |
|
static |
Where the byte at pos of the image being checked is read from: the first sector from RAM, which ACTIVATE has not written yet.
| u | The update state. |
| pos | Byte offset within the image. |