Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nn_ccr/sys: Add fw update functions #355

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading