|
K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
|
Data Structures | |
| struct | kfsw_fwu_owner |
| struct | kfsw_fwu_image |
| struct | kfsw_fwu_handle |
| struct | kfsw_fwu_status |
Macros | |
| #define | KFSW_FWU_SHA256_SIZE 32U |
Enumerations | |
| enum | kfsw_fwu_state { KFSW_FWU_IDLE = 0 , KFSW_FWU_RECEIVING = 1 , KFSW_FWU_READY = 2 , KFSW_FWU_FAILED = 3 , KFSW_FWU_VERIFIED = 4 } |
| enum | kfsw_fwu_owner_kind { KFSW_FWU_OWNER_LOCAL = 0 , KFSW_FWU_OWNER_FTP = 1 , KFSW_FWU_OWNER_LITE = 2 } |
Functions | |
| int | kfsw_fwu_session_begin (const struct kfsw_fwu_owner *owner, const struct kfsw_fwu_image *image, uint32_t transfer_id, struct kfsw_fwu_handle *handle, struct kfsw_fwu_status *status) |
| int | kfsw_fwu_session_write (const struct kfsw_fwu_handle *handle, uint32_t offset, const void *data, size_t size, struct kfsw_fwu_status *status) |
| int | kfsw_fwu_session_verify (const struct kfsw_fwu_handle *handle, struct kfsw_fwu_status *status) |
| int | kfsw_fwu_session_activate (const struct kfsw_fwu_handle *handle, struct kfsw_fwu_status *status) |
| int | kfsw_fwu_session_abort (const struct kfsw_fwu_handle *handle, struct kfsw_fwu_status *status) |
| int | kfsw_fwu_session_lookup (const struct kfsw_fwu_owner *owner, struct kfsw_fwu_status *status) |
| int | kfsw_fwu_session_status (const struct kfsw_fwu_handle *handle, struct kfsw_fwu_status *status) |
| uint32_t | kfsw_fwu_max_image_size (void) |
| uint32_t | kfsw_fwu_slot_write_offset (void) |
| int | kfsw_fwu_begin (uint32_t total_size, uint32_t expected_crc32) |
| int | kfsw_fwu_write (uint32_t offset, const void *data, size_t size) |
| int | kfsw_fwu_verify (void) |
| int | kfsw_fwu_files_mount (void) |
| int | kfsw_fwu_finish (void) |
| int | kfsw_fwu_abort (void) |
| int | kfsw_fwu_get_status (struct kfsw_fwu_status *status) |
| const char * | kfsw_fwu_state_name (enum kfsw_fwu_state state) |
Receives a firmware image into the secondary image slot and asks the bootloader to try it on the next boot.
Images are written directly to flash. With KFSW_FWU_FILES, both slots are also available as read-only files, without using data filesystem space. The service handles the MCUboot write offset and checks upgrade scheduling.
With KFSW_FWU_RECOVERY, permanent Golden replaces primary A directly. The whole partition is available, READY schedules no swap, and finish never resets the board. Begin destroys previous A; there is no previous-A rollback. MCUboot must reject invalid A and execute Golden after an interrupted upload.
The CRC32 catches corruption in transit, not tampering. Authenticity is the bootloader's signature check.
| #define KFSW_FWU_SHA256_SIZE 32U |
#include <fwu.h>
Whole-artifact SHA-256 length in bytes.
| enum kfsw_fwu_owner_kind |
#include <fwu.h>
Backend transfer principal.
Peer identity is supplied by the transport.
| enum kfsw_fwu_state |
#include <fwu.h>
Transfer state.
| int kfsw_fwu_abort | ( | void | ) |
#include <fwu.h>
Abandon a transfer and return to idle.
On success the secondary slot is erased. If cleanup fails, the service retains its transfer details in the failed state; call again to retry. Erasing the rollback image during a trial boot is refused.
| 0 | Cleanup completed, or no target partition is bound. |
| -EBUSY | A secondary-slot reader is open. |
| int kfsw_fwu_begin | ( | uint32_t | total_size, |
| uint32_t | expected_crc32 | ||
| ) |
#include <fwu.h>
Begin a CRC-only local transfer, erasing the available slot.
Local mutation APIs refuse remote ownership (-EACCES). Begin returns -EBUSY for a conflicting session.
| total_size | Image size in bytes. |
| expected_crc32 | CRC32 (IEEE, as produced by Zephyr's crc32_ieee) over the whole image. |
| 0 | The slot is ready to receive. |
| -ENODEV | No target partition is bound. |
| -EINVAL | total_size is zero. |
| -EFBIG | total_size exceeds kfsw_fwu_max_image_size. |
| -EBUSY | An unfinished session or another owner holds the slot, a secondary reader is open, or MCUboot needs trial rollback. |
| int kfsw_fwu_files_mount | ( | void | ) |
#include <fwu.h>
Mount read-only MCUboot images at /kfsw/boot.
firmware_1.bin reads slot0; firmware_2.bin reads slot1. Files contain the image header, payload, and TLVs, excluding slot padding and swap metadata. A secondary reader blocks erase and upgrade requests until it closes. Image visibility checks structure, not the bootloader's signature policy. Call once during service startup, before exposing file transfers.
| int kfsw_fwu_finish | ( | void | ) |
#include <fwu.h>
Verify the received image and offer it to the bootloader.
Repeated finish of a ready transfer succeeds without another boot request or counter increment. On success the image is marked to be tried once. It becomes permanent only if it confirms itself after booting; otherwise the bootloader restores the previous image.
Recovery instead leaves A ready for signature verification on an explicitly commanded reset. It neither schedules a swap nor resets the board.
| 0 | The image was accepted; swap_scheduled reports swap integration. |
| -EINVAL | No transfer is receiving or verified. |
| -EBUSY | A secondary-slot reader is open. |
| -EAGAIN | Fewer bytes were received than declared. |
| -EILSEQ | The CRC32 does not match what the sender declared. |
| -EIO | The bootloader did not schedule a swap despite being asked. |
| int kfsw_fwu_get_status | ( | struct kfsw_fwu_status * | status | ) |
#include <fwu.h>
Read a consistent snapshot of the update state.
| [out] | status | Destination snapshot. |
| 0 | The snapshot was written. |
| -EINVAL | status is NULL. |
| uint32_t kfsw_fwu_max_image_size | ( | void | ) |
#include <fwu.h>
Largest image the target slot can hold, in bytes.
Smaller than the partition: the swap offset costs one sector at the start, and the bootloader needs its trailer at the end. Recovery uses the full partition.
| int kfsw_fwu_session_abort | ( | const struct kfsw_fwu_handle * | handle, |
| struct kfsw_fwu_status * | status | ||
| ) |
#include <fwu.h>
Erase this owned transfer; retain identity on failure and a tombstone on success.
| int kfsw_fwu_session_activate | ( | const struct kfsw_fwu_handle * | handle, |
| struct kfsw_fwu_status * | status | ||
| ) |
#include <fwu.h>
Offer an explicitly VERIFIED image; READY replay does not schedule again.
| int kfsw_fwu_session_begin | ( | const struct kfsw_fwu_owner * | owner, |
| const struct kfsw_fwu_image * | image, | ||
| uint32_t | transfer_id, | ||
| struct kfsw_fwu_handle * | handle, | ||
| struct kfsw_fwu_status * | status | ||
| ) |
#include <fwu.h>
Acquire or resume the canonical writer, returning an atomic snapshot.
Only digest-bearing lite descriptors may resume an identical owner, descriptor and transfer ID without erasing. CRC-only begin is non-resumable. Transfer ID zero requests a backend ID for CRC-only callers; digest sessions require a nonzero ID and block size. Generation never wraps during this boot. A completed CRC-only session may be replaced by the same owner, preserving ordinary FWU upload behavior. Failed sessions require owned abort. Successful abort retains one tombstone.
All session operations validate and act under the same lock, and fill status even on operational errors. Once acquisition starts, handle is returned even if flash preparation fails, allowing owner-scoped cleanup. Refused acquisition leaves the output handle unchanged. Arguments and output pointers must be non-NULL. Owner mismatch returns -EACCES; superseded identity returns -ESTALE; conflicting begin returns -EBUSY. Handles are RAM-only and do not survive receiver reset. Digest verification establishes content integrity, not authentication.
| int kfsw_fwu_session_lookup | ( | const struct kfsw_fwu_owner * | owner, |
| struct kfsw_fwu_status * | status | ||
| ) |
#include <fwu.h>
Resolve the current transfer owned by this principal, without mutating it.
Returns -ENOENT for no active identity, -EACCES for another owner. Bind subsequent operations to the returned handle; never resolve again on retry.
| int kfsw_fwu_session_status | ( | const struct kfsw_fwu_handle * | handle, |
| struct kfsw_fwu_status * | status | ||
| ) |
#include <fwu.h>
Query this handle with the same ownership and generation checks as mutations.
| int kfsw_fwu_session_verify | ( | const struct kfsw_fwu_handle * | handle, |
| struct kfsw_fwu_status * | status | ||
| ) |
#include <fwu.h>
Flush and check exactly the stored image bytes against CRC and optional SHA-256.
| int kfsw_fwu_session_write | ( | const struct kfsw_fwu_handle * | handle, |
| uint32_t | offset, | ||
| const void * | data, | ||
| size_t | size, | ||
| struct kfsw_fwu_status * | status | ||
| ) |
#include <fwu.h>
Accept the next ordered span and return its atomic snapshot.
Digest-bearing lite sessions replay only the exact last block, including a short tail, without another write. Changed duplicates and older offsets fail.
| uint32_t kfsw_fwu_slot_write_offset | ( | void | ) |
#include <fwu.h>
Byte offset within the target partition where an image is written.
Non-zero because of the bootloader's swap mode; zero in recovery mode.
| const char * kfsw_fwu_state_name | ( | enum kfsw_fwu_state | state | ) |
#include <fwu.h>
Human-readable name for a state, for shells and logs.
| state | One of kfsw_fwu_state. |
| int kfsw_fwu_verify | ( | void | ) |
#include <fwu.h>
Flush received bytes and independently check the stored image CRC.
Reads exactly the declared image bytes, excluding flash padding. Does not schedule a boot. Repeated verification of a verified or ready transfer succeeds. Further writes are rejected until a new transfer begins.
| 0 | The complete image is available in flash. |
| -EINVAL | No transfer is receiving or verified. |
| -EAGAIN | The transfer is incomplete. |
| -EILSEQ | The transfer CRC does not match. |
| int kfsw_fwu_write | ( | uint32_t | offset, |
| const void * | data, | ||
| size_t | size | ||
| ) |
#include <fwu.h>
Accept the next span of image bytes.
Spans must arrive in order and without gaps.
| offset | Offset of this span within the image, from zero. |
| data | Bytes to write. |
| size | Number of bytes. |
| 0 | The span was accepted. |
| -EINVAL | data is NULL, size is zero, or no transfer is running. |
| -ESPIPE | offset is not where the transfer had reached. |
| -EFBIG | The span would run past the declared image size. |