Skip to content

Commit

Permalink
nn_ccr/sys: Add fw update functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Apr 5, 2024
1 parent 682f8eb commit 3242650
Showing 1 changed file with 157 additions and 6 deletions.
163 changes: 157 additions & 6 deletions include/nn/ccr/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@
extern "C" {
#endif

typedef struct CCRSysUpdateState CCRSysUpdateState;

typedef enum CCRSysPairingState
{
//! Pairing is complete / hasn't started yet
CCR_SYS_PAIRING_FINISHED = 0,
//! Pairing is in progress
CCR_SYS_PAIRING_IN_PROGRESS = 1,
//! Pairing timed out
CCR_SYS_PAIRING_TIMED_OUT = 2,
//! Pairing is complete / hasn't started yet
CCR_SYS_PAIRING_FINISHED = 0,
//! Pairing is in progress
CCR_SYS_PAIRING_IN_PROGRESS = 1,
//! Pairing timed out
CCR_SYS_PAIRING_TIMED_OUT = 2,
} CCRSysPairingState;

struct CCRSysUpdateState
{
uint32_t state;
//! Progress from 0-100
uint32_t progress;
};

void
CCRSysInit(void);

Expand Down Expand Up @@ -118,6 +127,148 @@ CCRSysGetPincode(uint32_t *pin);
int32_t
CCRSysSetSystemTime(OSTime time);

/**
* Check if a DRC firmware update is needed.
* This function additionally verifies the DRC area compared to \link __CCRSysNeedsDRCFWUpdate \endlink.
*
* \param drcSlot
* Slot from 0 to 1.
*
* \param outNeedsUpdate
* Pointer to store the result to.
*
* \return
* 0 on success.
*/
int32_t
CCRSysNeedsDRCFWUpdate(uint32_t drcSlot,
BOOL *outNeedsUpdate);

/**
* Check if a DRC firmware update is needed.
*
* \param drcSlot
* Slot from 0 to 1.
*
* \param outNeedsUpdate
* Pointer to store the result to.
*
* \param allowDowngrade
* Only check if the installed version doesn't match the running version,
* instead of checking that it's greater.
*
* \return
* 0 on success.
*/
int32_t
__CCRSysNeedsDRCFWUpdate(uint32_t drcSlot,
BOOL *outNeedsUpdate,
BOOL allowDowngrade);

/**
* Starts a DRC firmware update if necessary and region matches.
*
* \note
* This function will wait for \link CCRSysDRCFWUpdateForward \endlink to be called once done.
* See \link CCRSysGetUpdateState \endlink for status and progress.
*
* \param drcSlot
* Slot from 0 to 1.
*
* \return
* 0 on success.
*/
int32_t
CCRSysDRCFWUpdate(uint32_t drcSlot);

/**
* Starts a DRC firmware update if necessary.
*
* \note
* This function will wait for \link CCRSysDRCFWUpdateForward \endlink to be called once done.
* See \link CCRSysGetUpdateState \endlink for status and progress.
*
* \param drcSlot
* Slot from 0 to 1.
*
* \param allowDowngrade
* Only check if the installed version doesn't match the running version,
* instead of checking that it's greater.
* There are additional checks on the IOS side and this doesn't actually allow downgrading the firmware.
*
* \return
* 0 on success.
*/
int32_t
__CCRSysDRCFWUpdate(uint32_t drcSlot,
BOOL allowDowngrade);


/**
* Finish a pending DRC firmware update.
*/
void
CCRSysDRCFWUpdateForward(void);

/**
* Get the update state during a pending DRC firmware update.
*
* \param outUpdateState
* Pointer to store the state to.
*/
void
CCRSysGetUpdateState(CCRSysUpdateState *outUpdateState);

/**
* Initialize a DRC reattach.
*
* \param drcSlot
* Slot from 0 to 1.
*/
void
__CCRSysInitReattach(uint32_t drcSlot);

/**
* Wait for the DRC to reattach.
* This returns once the DRC disconnects and reconnects or a timeout is reached.
*
* \param drcSlot
* Slot from 0 to 1.
*
* \return
* 0 on success.
*/
int32_t
__CCRSysWaitReattach(uint32_t drcSlot,
BOOL unknown);

/**
* Get the version check flag.
*
* \param outFlag
* Pointer to write the flag to.
*
* \return
* 0 on success.
*/
int32_t
CCRSysGetVersionCheckFlag(uint32_t *outFlag);

/**
* Set the version check flag.
*
* \param outFlag
* The flag to set.
*
* \return
* 0 on success.
*/
int32_t
CCRSysSetVersionCheckFlag(uint32_t flag);

int32_t
CCRSysCaffeineSetCaffeineSlot(uint32_t slot);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 3242650

Please sign in to comment.