BSB Developer Docs
Loading...
Searching...
No Matches
updater.h File Reference

Firmware update system interface. More...

#include "settings/settings.h"
#include <furi.h>
#include <toolbox/update_lib/update_manifest.h>

Go to the source code of this file.

Data Structures

struct  UpdaterUpdateState
 Update state information accessible via FuriState. More...
 
struct  UpdaterCheckState
 Update check state information accessible via FuriState. More...
 
struct  UpdateCheckInfo
 

Macros

#define RECORD_UPDATER   "updater"
 
#define UPDATER_UPDATE_STATE_DETAIL_MAX_LENGTH   128
 

Typedefs

typedef struct Updater Updater
 

Enumerations

enum  UpdaterStatus {
  UpdaterStatusOk , UpdaterStatusBatteryLow , UpdaterStatusBusy , UpdaterStatusDownloadFailure ,
  UpdaterStatusDownloadAbort , UpdaterStatusShaMismatch , UpdaterStatusUnpackCreateStagingDirectoryFailure , UpdaterStatusUnpackArchiveOpenFailure ,
  UpdaterStatusUnpackArchiveUnpackFailure , UpdaterStatusInstallationPrepareManifestNotFound , UpdaterStatusInstallationPrepareManifestInvalid , UpdaterStatusInstallationPrepareSecurityMismatch ,
  UpdaterStatusInstallationPrepareSessionConfigSetupFailure , UpdaterStatusInstallationPreparePointerSetupFailure , UpdaterStatusUnknownFailure , UpdaterStatusesCount
}
 
enum  UpdaterUpdateAction {
  UpdaterUpdateActionDownload , UpdaterUpdateActionShaVerification , UpdaterUpdateActionUnpack , UpdaterUpdateActionInstallationPrepare ,
  UpdaterUpdateActionInstallationApply , UpdaterUpdateActionNone , UpdaterUpdateActionsCount
}
 
enum  UpdaterUpdateEvent {
  UpdaterUpdateEventSessionStart , UpdaterUpdateEventSessionStop , UpdaterUpdateEventActionBegin , UpdaterUpdateEventActionDone ,
  UpdaterUpdateEventDetailChange , UpdaterUpdateEventActionProgress , UpdaterUpdateEventNone , UpdaterUpdateEventsCount
}
 
enum  UpdaterCheckResult {
  UpdaterCheckResultAvailable , UpdaterCheckResultNotAvailable , UpdaterCheckResultFailure , UpdaterCheckResultNone ,
  UpdaterCheckResultsCount
}
 
enum  UpdaterCheckEvent { UpdaterCheckEventStart , UpdaterCheckEventStop , UpdaterCheckEventNone , UpdaterCheckEventsCount }
 

Functions

const char * updater_get_status_string (UpdaterStatus status)
 Get human-readable string for a status code.
 
FuriState * updater_get_update_state (Updater *instance)
 Get update state object for monitoring progress.
 
FuriState * updater_get_check_state (Updater *instance)
 Get update check state object for monitoring update availability.
 
void updater_get_check_info (Updater *instance, UpdateCheckInfo *info)
 Get update information.
 
UpdaterStatus updater_get_allowance_status (Updater *instance)
 Check if update is allowed to start.
 
UpdaterStatus updater_session_start (Updater *instance)
 Start update process.
 
void updater_session_stop (Updater *instance)
 Stop update process.
 
UpdaterStatus updater_download (Updater *instance, const char *url, const char *path, bool do_wait)
 Download update bundle from URL.
 
void updater_abort_download (Updater *instance)
 Abort ongoing download operation.
 
UpdaterStatus updater_verify_bundle_sha (Updater *instance, const char *tar_path, const char *sha, bool do_wait)
 Verify SHA256 checksum of update bundle.
 
UpdaterStatus updater_unpack (Updater *instance, const char *tar_path, const char *staging_path, FuriString *manifest_path, bool do_wait)
 Unpack update bundle .tar archive.
 
UpdaterStatus updater_installation_prepare (Updater *instance, const char *manifest_path, bool do_wait)
 Prepare update for installation.
 
void updater_installation_apply (Updater *instance, bool do_wait)
 Apply prepared installation.
 
void updater_install_from_url (Updater *instance, const char *url, const char *sha256)
 Install firmware from URL.
 
UpdaterStatus updater_check_for_update (Updater *instance)
 Check for available firmware updates.
 
void updater_pause_autoupdates (Updater *instance)
 Pause automatic updates.
 
void updater_resume_autoupdates (Updater *instance)
 Resume automatic updates.
 
const char * updater_get_active_version (void)
 Get currently active firmware version string.
 
bool updater_get_active_security_flags (uint32_t *flags)
 Get the device's active firmware protection flags.
 
void updater_get_settings (const Updater *instance, UpdaterSettings *settings)
 Get the current updater settings.
 
bool updater_set_settings (Updater *instance, const UpdaterSettings *settings)
 Set new updater settings.
 
FuriState * updater_get_settings_state (Updater *instance)
 Get settings state object for change notifications.
 

Detailed Description

Firmware update system interface.

Enumeration Type Documentation

◆ UpdaterCheckEvent

Enumerator
UpdaterCheckEventStart 

Update check started.

UpdaterCheckEventStop 

Update check stopped.

UpdaterCheckEventNone 

No event (initial/idle state)

◆ UpdaterCheckResult

Enumerator
UpdaterCheckResultAvailable 

Update is available.

UpdaterCheckResultNotAvailable 

No update available.

UpdaterCheckResultFailure 

Failed to check for update.

UpdaterCheckResultNone 

No check performed (initial/idle state)

◆ UpdaterStatus

Enumerator
UpdaterStatusOk 

Operation completed successfully.

UpdaterStatusBatteryLow 

Battery level too low.

UpdaterStatusBusy 

Update already in progress.

UpdaterStatusDownloadFailure 

Failed to download update bundle from URL.

UpdaterStatusDownloadAbort 

Download was aborted by user.

UpdaterStatusShaMismatch 

Update bundle SHA256 checksum verification failed.

UpdaterStatusUnpackCreateStagingDirectoryFailure 

Failed to create staging directory.

UpdaterStatusUnpackArchiveOpenFailure 

Failed to open .tar archive file.

UpdaterStatusUnpackArchiveUnpackFailure 

Failed to extract .tar archive contents.

UpdaterStatusInstallationPrepareManifestNotFound 

Update manifest file not found.

UpdaterStatusInstallationPrepareManifestInvalid 

Manifest file validation failed.

UpdaterStatusInstallationPrepareSecurityMismatch 

Bundle security flags don't match device.

UpdaterStatusInstallationPrepareSessionConfigSetupFailure 

Failed to save session configuration.

UpdaterStatusInstallationPreparePointerSetupFailure 

Failed to write pointer file.

UpdaterStatusUnknownFailure 

Unknown error occurred.

◆ UpdaterUpdateAction

Enumerator
UpdaterUpdateActionDownload 

Downloading update bundle from URL.

UpdaterUpdateActionShaVerification 

Downloading update bundle from URL.

UpdaterUpdateActionUnpack 

Unpacking .tar archive to staging directory.

UpdaterUpdateActionInstallationPrepare 

Preparing update for installation (manifest validation, session setup)

UpdaterUpdateActionInstallationApply 

Rebooting device to install prepared update.

UpdaterUpdateActionNone 

No action (initial/idle state)

◆ UpdaterUpdateEvent

Enumerator
UpdaterUpdateEventSessionStart 

Update process started (lock acquired)

UpdaterUpdateEventSessionStop 

Update process stopped (lock released)

UpdaterUpdateEventActionBegin 

Action started (download/unpack/prepare/reboot)

UpdaterUpdateEventActionDone 

Action completed with result status.

UpdaterUpdateEventDetailChange 

Status detail string changed (e.g., download state message)

UpdaterUpdateEventActionProgress 

Progress update (e.g., download bytes received)

UpdaterUpdateEventNone 

No event (initial/idle state)

Function Documentation

◆ updater_abort_download()

void updater_abort_download ( Updater * instance)

Abort ongoing download operation.

Signals download to abort. Download will complete with UpdaterStatusDownloadAbort. Must be called from inside of updater's session.

Parameters
[in]instanceUpdater instance

◆ updater_check_for_update()

UpdaterStatus updater_check_for_update ( Updater * instance)

Check for available firmware updates.

Queries remote server for available updates and populates check state.

Parameters
[in]instanceUpdater instance
Returns
UpdaterStatusOk on success, UpdaterStatusBusy if check is already in progress,

◆ updater_download()

UpdaterStatus updater_download ( Updater * instance,
const char * url,
const char * path,
bool do_wait )

Download update bundle from URL.

Must be called from inside of updater's session.

Parameters
[in]instanceUpdater instance
[in]urlURL to download from
[in]pathLocal file path to save to (NULL for default)
[in]do_waittrue to block until complete, false for async operation
Returns
UpdaterStatusOk on success, UpdaterStatusDownloadFailure on network/file error, UpdaterStatusDownloadAbort if aborted

◆ updater_get_active_security_flags()

bool updater_get_active_security_flags ( uint32_t * flags)

Get the device's active firmware protection flags.

Computes a bitmask of active UpdateManifestSecurityFlag bits from the wireless co-processor (Si917) NWP/M4 signature and encryption state.

Parameters
[out]flagsPointer to receive the security flags bitmask (see UpdateManifestSecurityFlag in update_manifest.h)
Returns
true if the info source is ready and the flags are valid, false if it is not ready yet (*flags is set to 0)

◆ updater_get_active_version()

const char * updater_get_active_version ( void )

Get currently active firmware version string.

Returns
Version string

◆ updater_get_allowance_status()

UpdaterStatus updater_get_allowance_status ( Updater * instance)

Check if update is allowed to start.

Parameters
[in]instanceUpdater instance
Returns
UpdaterStatusOk if allowed, UpdaterStatusBatteryLow if battery too low

◆ updater_get_check_info()

void updater_get_check_info ( Updater * instance,
UpdateCheckInfo * info )

Get update information.

The info parameter should point to an initialized struct:

  • if a member is NULL, it will not be changed.
  • if a member is not NULL, the string it points to will be set. Example usage: FuriString* check_version = furi_string_alloc(); FuriString* check_changelog = furi_string_alloc(); updater_get_check_info( updater, &(UpdateCheckInfo){ .version = check_version, .url = NULL, .id = NULL, .sha256 = NULL, .changelog = check_changelog, });
Parameters
[in]instanceUpdater instance
[out]infoPointer to UpdateCheckInfo struct.

◆ updater_get_check_state()

FuriState * updater_get_check_state ( Updater * instance)

Get update check state object for monitoring update availability.

Parameters
[in]instanceUpdater instance
Returns
FuriState pointer (acquire/release to access UpdaterCheckState)

◆ updater_get_settings()

void updater_get_settings ( const Updater * instance,
UpdaterSettings * settings )

Get the current updater settings.

Retrieves the current configuration of the updater service including check URL, channel ID, sync intervals, and autoupdate settings.

Parameters
[in]instanceUpdater instance
[out]settingsPointer to a structure to be filled with current settings

◆ updater_get_settings_state()

FuriState * updater_get_settings_state ( Updater * instance)

Get settings state object for change notifications.

Parameters
[in]instanceUpdater instance
Returns
FuriState pointer (subscribe to receive UpdaterSettings snapshots)

◆ updater_get_status_string()

const char * updater_get_status_string ( UpdaterStatus status)

Get human-readable string for a status code.

Parameters
[in]statusThe status code
Returns
Status string or "Unknown error code" for invalid status

◆ updater_get_update_state()

FuriState * updater_get_update_state ( Updater * instance)

Get update state object for monitoring progress.

Parameters
[in]instanceUpdater instance
Returns
FuriState pointer (acquire/release to access UpdaterUpdateState)

◆ updater_install_from_url()

void updater_install_from_url ( Updater * instance,
const char * url,
const char * sha256 )

Install firmware from URL.

Downloads, verifies, unpacks, prepares, and installs firmware from a remote URL. Runs asynchronously in a background thread and reboots the device upon completion. The update session is automatically started and stopped by this function. Requires update session to be started, will close it on completion.

Parameters
[in]instanceUpdater instance
[in]urlURL to download update bundle from
[in]sha256Expected SHA256 checksum (NULL to skip verification)

◆ updater_installation_apply()

void updater_installation_apply ( Updater * instance,
bool do_wait )

Apply prepared installation.

This will reboot the device. Requires update session to be started.

Parameters
[in]instanceUpdater instance
[in]do_waittrue to block and reboot, false for async reboot

◆ updater_installation_prepare()

UpdaterStatus updater_installation_prepare ( Updater * instance,
const char * manifest_path,
bool do_wait )

Prepare update for installation.

Must be called from inside of updater's session.

Parameters
[in]instanceUpdater instance
[in]manifest_pathPath to update manifest file (NULL for default: /ext/update/staging/update.fuf)
[in]do_waittrue to block until complete, false for async operation
Returns
UpdaterStatusOk on success, UpdaterStatusInstallationPrepareManifestNotFound if manifest missing, UpdaterStatusInstallationPrepareManifestInvalid if validation fails, UpdaterStatusInstallationPrepareSessionConfigSetupFailure if session config save fails, UpdaterStatusInstallationPreparePointerSetupFailure if pointer file write fails

◆ updater_pause_autoupdates()

void updater_pause_autoupdates ( Updater * instance)

Pause automatic updates.

Parameters
[in]instanceUpdater instance

◆ updater_resume_autoupdates()

void updater_resume_autoupdates ( Updater * instance)

Resume automatic updates.

Parameters
[in]instanceUpdater instance

◆ updater_session_start()

UpdaterStatus updater_session_start ( Updater * instance)

Start update process.

Checks allowance status, acquires update lock, and emits UpdaterUpdateEventSessionStart event. Must be called before any update operations.

Parameters
[in]instanceUpdater instance
Returns
UpdaterStatusOk on success, UpdaterStatusBatteryLow if battery too low, UpdaterStatusBusy if update already in progress

◆ updater_session_stop()

void updater_session_stop ( Updater * instance)

Stop update process.

Emits UpdaterUpdateEventSessionStop event and releases update lock. Must be called after all update operations complete.

Parameters
[in]instanceUpdater instance

◆ updater_set_settings()

bool updater_set_settings ( Updater * instance,
const UpdaterSettings * settings )

Set new updater settings.

Updates the updater service configuration. Changes take effect immediately and will trigger a reconfiguration of the background update task if the service is enabled.

Parameters
[in,out]instanceUpdater instance
[in]settingsPointer to a structure containing the new settings
Returns
true if settings were successfully applied, false otherwise

◆ updater_unpack()

UpdaterStatus updater_unpack ( Updater * instance,
const char * tar_path,
const char * staging_path,
FuriString * manifest_path,
bool do_wait )

Unpack update bundle .tar archive.

Must be called from inside of updater's session.

Parameters
[in]instanceUpdater instance
[in]tar_pathPath to .tar archive (NULL for default)
[in]staging_pathDirectory to extract to (NULL for default)
[out]manifest_pathFuriString to receive manifest path (or NULL if not needed)
[in]do_waittrue to block until complete, false for async operation
Returns
UpdaterStatusOk on success, UpdaterStatusUnpackCreateStagingDirectoryFailure if mkdir fails, UpdaterStatusUnpackArchiveOpenFailure if .tar open fails, UpdaterStatusUnpackArchiveUnpackFailure if extraction fails

◆ updater_verify_bundle_sha()

UpdaterStatus updater_verify_bundle_sha ( Updater * instance,
const char * tar_path,
const char * sha,
bool do_wait )

Verify SHA256 checksum of update bundle.

Must be called from inside of updater's session.

Parameters
[in]instanceUpdater instance
[in]tar_pathPath to .tar archive (NULL for default)
[in]shaExpected SHA256 checksum string
[in]do_waittrue to block until complete, false for async operation
Returns
UpdaterStatusOk if checksum matches and file is accessible, UpdaterStatusShaMismatch if checksum verification failed