/**************************************************************************** NAME usbSetBootMode DESCRIPTION Set the boot mode to default or low power RETURNS void */ void usbSetBootMode(uint8 bootmode) { /* Don't change anything if battery charging disabled */ if(!USB_CLASS_ENABLED(USB_DEVICE_CLASS_TYPE_BATTERY_CHARGING)) return; if(BootGetMode() != bootmode) { USB_DEBUG(("USB: Set Mode %d\n", bootmode)); BootSetMode(bootmode); } }
/* We end up here after reboot */ bool HandleCommitHostContinue(MessageId id, Message message) { switch(id) { case UPGRADE_HOST_IN_PROGRESS_RES: { UPGRADE_HOST_IN_PROGRESS_RES_T *msg = (UPGRADE_HOST_IN_PROGRESS_RES_T *)message; MessageCancelFirst(UpgradeGetUpgradeTask(), UPGRADE_INTERNAL_RECONNECTION_TIMEOUT); if(msg->action == 0) { MoveToState(UPGRADE_STATE_COMMIT_VERIFICATION); } else { MoveToState(UPGRADE_STATE_SYNC); } } break; case UPGRADE_INTERNAL_RECONNECTION_TIMEOUT: { bool dfu = UpgradePartitionDataIsDfuUpdate(); uint16 err = LoaderErrorCheck(); if(dfu && !err) { /* Carry on */ CommitConfirmYes(); } else { /* Revert */ UpgradeRevertUpgrades(); UpgradeCtxGetPSKeys()->upgrade_in_progress_key = UPGRADE_RESUME_POINT_ERROR; UpgradeSavePSKeys(); PRINT(("P&R: UPGRADE_RESUME_POINT_ERROR saved\n")); SetState(UPGRADE_STATE_SYNC); BootSetMode(BootGetMode()); } } break; default: return FALSE; } return TRUE; }
/**************************************************************************** NAME configManagerDefragCheck DESCRIPTION Defrag PS if required. RETURNS void */ void configManagerDefragCheck(void) { CONF_DEBUG(("CONF: Defrag Check ")) ; if(theSink.rundata->defrag.key_size) { uint16 count = PsFreeCount(theSink.rundata->defrag.key_size); CONF_DEBUG(("Enabled [%d] ", count)) ; if(count <= theSink.rundata->defrag.key_minimum) { CONF_DEBUG(("Flooding PS")) ; PsFlood(); /* try to set the same boot mode; this triggers the target to reboot.*/ BootSetMode(BootGetMode()); } } CONF_DEBUG(("\n")) ; }
bool HandleCommitConfirm(MessageId id, Message message) { switch(id) { case UPGRADE_HOST_COMMIT_CFM: { UPGRADE_HOST_COMMIT_CFM_T *cfm = (UPGRADE_HOST_COMMIT_CFM_T *)message; switch (cfm->action) { case UPGRADE_HOSTACTION_YES: CommitConfirmYes(); break; case UPGRADE_HOSTACTION_NO: /** @todo Call to UpgradeRevertUpgrades here */ UpgradeRevertUpgrades(); UpgradeCtxGetPSKeys()->upgrade_in_progress_key = UPGRADE_RESUME_POINT_PRE_REBOOT; UpgradeSavePSKeys(); PRINT(("P&R: UPGRADE_RESUME_POINT_PRE_REBOOT saved\n")); SetState(UPGRADE_STATE_SYNC); BootSetMode(BootGetMode()); break; /** default: @todo: Error case. Should we handle ? Who cancels timeout */ } } break; case UPGRADE_INTERNAL_CONTINUE: CommitConfirmYes(); break; default: /** @todo We don't handle unexpected messages in most cases, error messages are dealt with in the default handler. BUT how do we deal with timeout ? It *should* be in the state machine */ return FALSE; } return TRUE; }
/* NAME CallLoaderOrReboot DESCRIPTION Process the required actions from HandleValidated. Depending on the type of upgrade being performed either call the loader to execute a DFU from SQIF, or warm reboot to change the partitions in SQIF that are mounted. Called either immediately or once we receive permission from the VM application. */ static void CallLoaderOrReboot() { if (UpgradePartitionDataIsDfuUpdate()) { uint16 partition = UpgradePartitionDataGetDfuPartition(); /* This will reboot into the loader to apply the dfu */ LoaderPerformDfuFromSqif(partition); /* If we get here then the dfu file failed the initial validation checks and the device was not rebooted by the firmware. We still need to reboot to reconnect to the host though. */ UpgradeCtxGetPSKeys()->loader_msg = UPGRADE_LOADER_MSG_INVALID; UpgradeSavePSKeys(); } BootSetMode(BootGetMode()); }
/* NAME PsFloodAndReboot DESCRIPTION Process the required actions from HandleRebootToResume. Flood PS to force a defrag on next boot, then do a warm reboot. Called either immediately or once we receive permission from the VM application. */ static void PsFloodAndReboot() { PsFlood(); BootSetMode(BootGetMode()); }