From dbb530e27bfa9dfbc25bf172cfa88bd167680412 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 17:16:08 +0100 Subject: [PATCH 1/8] Unlock STR second firmware slot --- bsp_q7s/objectFactory.cpp | 2 +- linux/acs/StrComHandler.cpp | 42 +++++---- linux/acs/StrComHandler.h | 5 +- mission/acs/str/StarTrackerHandler.cpp | 124 +++++++++++++++++++------ mission/acs/str/StarTrackerHandler.h | 18 ++-- mission/acs/str/strHelpers.h | 21 ++++- tmtc | 2 +- 7 files changed, 158 insertions(+), 56 deletions(-) diff --git a/bsp_q7s/objectFactory.cpp b/bsp_q7s/objectFactory.cpp index 313c880d..c0dc489a 100644 --- a/bsp_q7s/objectFactory.cpp +++ b/bsp_q7s/objectFactory.cpp @@ -951,7 +951,7 @@ void ObjectFactory::createStrComponents(PowerSwitchIF* pwrSwitcher, SdCardManage auto cfgGetter = new StrConfigPathGetter(sdcMan); auto starTracker = new StarTrackerHandler(objects::STAR_TRACKER, objects::STR_COM_IF, starTrackerCookie, - strComIF, power::PDU1_CH2_STAR_TRACKER_5V, *cfgGetter); + strComIF, power::PDU1_CH2_STAR_TRACKER_5V, *cfgGetter, sdcMan); starTracker->setPowerSwitcher(pwrSwitcher); starTracker->connectModeTreeParent(*strAssy); starTracker->setCustomFdir(strFdir); diff --git a/linux/acs/StrComHandler.cpp b/linux/acs/StrComHandler.cpp index 0bb4d749..a02d47d1 100644 --- a/linux/acs/StrComHandler.cpp +++ b/linux/acs/StrComHandler.cpp @@ -175,7 +175,8 @@ void StrComHandler::setDownloadImageName(std::string filename) { void StrComHandler::setFlashReadFilename(std::string filename) { flashRead.filename = filename; } -ReturnValue_t StrComHandler::startFirmwareUpdate(std::string fullname) { +ReturnValue_t StrComHandler::startFirmwareUpdate(std::string fullname, + startracker::FirmwareTarget target) { { MutexGuard mg(lock); if (state != InternalState::SLEEPING) { @@ -192,8 +193,13 @@ ReturnValue_t StrComHandler::startFirmwareUpdate(std::string fullname) { if (not std::filesystem::exists(flashWrite.fullname)) { return FILE_NOT_EXISTS; } - flashWrite.firstRegion = static_cast(startracker::FirmwareRegions::FIRST); - flashWrite.lastRegion = static_cast(startracker::FirmwareRegions::LAST); + if (target == startracker::FirmwareTarget::MAIN) { + flashWrite.firstRegion = static_cast(startracker::FirmwareRegions::FIRST_MAIN); + flashWrite.lastRegion = static_cast(startracker::FirmwareRegions::LAST_MAIN); + } else if (target == startracker::FirmwareTarget::BACKUP) { + flashWrite.firstRegion = static_cast(startracker::FirmwareRegions::FIRST_BACKUP); + flashWrite.lastRegion = static_cast(startracker::FirmwareRegions::LAST_BACKUP); + } { MutexGuard mg(lock); replyWasReceived = false; @@ -275,7 +281,7 @@ ReturnValue_t StrComHandler::performImageDownload() { file.close(); return result; } - result = checkActionReply(replySize); + result = checkActionReply(replySize, "downloading image"); if (result != returnvalue::OK) { if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { serial::flushRxBuf(serialPort); @@ -348,7 +354,7 @@ ReturnValue_t StrComHandler::performImageUpload() { if (result != returnvalue::OK) { return returnvalue::FAILED; } - result = checkActionReply(replyLen); + result = checkActionReply(replyLen, "sky image upload"); if (result != returnvalue::OK) { return result; } @@ -374,7 +380,7 @@ ReturnValue_t StrComHandler::performImageUpload() { if (result != returnvalue::OK) { return returnvalue::FAILED; } - result = checkActionReply(replyLen); + result = checkActionReply(replyLen, "sky image upload"); if (result != returnvalue::OK) { return result; } @@ -388,8 +394,7 @@ ReturnValue_t StrComHandler::performImageUpload() { ReturnValue_t StrComHandler::performFirmwareUpdate() { using namespace startracker; ReturnValue_t result = returnvalue::OK; - result = unlockAndEraseRegions(static_cast(startracker::FirmwareRegions::FIRST), - static_cast(startracker::FirmwareRegions::LAST)); + result = unlockAndEraseRegions(flashWrite.firstRegion, flashWrite.lastRegion); if (result != returnvalue::OK) { return result; } @@ -421,6 +426,8 @@ ReturnValue_t StrComHandler::performFlashWrite() { file.seekg(0, file.end); fileSize = file.tellg(); if (fileSize > FLASH_REGION_SIZE * (flashWrite.lastRegion - flashWrite.firstRegion)) { + sif::debug << "Last region: " << (int)flashWrite.lastRegion + << " first region: " << (int)flashWrite.firstRegion << std::endl; sif::warning << "StrHelper::performFlashWrite: Invalid file" << std::endl; return returnvalue::FAILED; } @@ -445,7 +452,7 @@ ReturnValue_t StrComHandler::performFlashWrite() { if (result != returnvalue::OK) { return result; } - result = checkActionReply(replyLen); + result = checkActionReply(replyLen, "firmware image upload"); if (result != returnvalue::OK) { return result; } @@ -488,7 +495,7 @@ ReturnValue_t StrComHandler::performFlashWrite() { if (result != returnvalue::OK) { return result; } - result = checkActionReply(replyLen); + result = checkActionReply(replyLen, "flash write"); if (result != returnvalue::OK) { return result; } @@ -542,7 +549,7 @@ ReturnValue_t StrComHandler::performFlashRead() { file.close(); return result; } - result = checkActionReply(replyLen); + result = checkActionReply(replyLen, "flash read"); if (result != returnvalue::OK) { if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { serial::flushRxBuf(serialPort); @@ -584,7 +591,7 @@ ReturnValue_t StrComHandler::sendAndRead(size_t size, uint32_t failParameter) { return readOneReply(failParameter); } -ReturnValue_t StrComHandler::checkActionReply(size_t replySize) { +ReturnValue_t StrComHandler::checkActionReply(size_t replySize, const char* context) { uint8_t type = startracker::getReplyFrameType(replyPtr); if (type != TMTC_ACTIONREPLY) { sif::warning << "StrHelper::checkActionReply: Received reply with invalid type ID" << std::endl; @@ -592,7 +599,7 @@ ReturnValue_t StrComHandler::checkActionReply(size_t replySize) { } uint8_t status = startracker::getStatusField(replyPtr); if (status != ArcsecDatalinkLayer::STATUS_OK) { - sif::warning << "StrHelper::checkActionReply: Status failure: " + sif::warning << "StrHelper::checkActionReply: Status failure for " << context << ": " << static_cast(status) << std::endl; return STATUS_ERROR; } @@ -744,15 +751,15 @@ ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) { struct UnlockActionRequest unlockReq; struct EraseActionRequest eraseReq; uint32_t size = 0; - for (uint32_t idx = from; idx <= to; idx++) { + for (uint32_t idx = from; idx < to; idx++) { unlockReq.region = idx; - unlockReq.code = startracker::region_secrets::secret[idx]; + unlockReq.code = startracker::region_secrets::SECRETS[idx]; arc_pack_unlock_action_req(&unlockReq, cmdBuf.data(), &size); result = sendAndRead(size, unlockReq.region); if (result != returnvalue::OK) { return result; } - result = checkActionReply(replyLen); + result = checkActionReply(replyLen, "unlocking region"); if (result != returnvalue::OK) { sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id " << static_cast(unlockReq.region) << std::endl; @@ -761,6 +768,9 @@ ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) { eraseReq.region = idx; arc_pack_erase_action_req(&eraseReq, cmdBuf.data(), &size); result = sendAndRead(size, eraseReq.region); + if (result != returnvalue::OK) { + } + result = checkActionReply(replyLen, "erasing region"); if (result != returnvalue::OK) { sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id " << static_cast(eraseReq.region) << std::endl; diff --git a/linux/acs/StrComHandler.h b/linux/acs/StrComHandler.h index 252b2466..0fc11629 100644 --- a/linux/acs/StrComHandler.h +++ b/linux/acs/StrComHandler.h @@ -6,6 +6,7 @@ #include #include "OBSWConfig.h" +#include "mission/acs/str/strHelpers.h" #ifdef XIPHOS_Q7S #include "bsp_q7s/fs/SdCardManager.h" @@ -127,7 +128,7 @@ class StrComHandler : public SystemObject, public DeviceCommunicationIF, public * @param fullname Full name including absolute path of file containing firmware * update. */ - ReturnValue_t startFirmwareUpdate(std::string fullname); + ReturnValue_t startFirmwareUpdate(std::string fullname, startracker::FirmwareTarget target); /** * @brief Starts the flash read procedure @@ -334,7 +335,7 @@ class StrComHandler : public SystemObject, public DeviceCommunicationIF, public * * @return returnvalue::OK if reply confirms success of packet transfer, otherwise REUTRN_FAILED */ - ReturnValue_t checkActionReply(size_t replySize); + ReturnValue_t checkActionReply(size_t replySize, const char *context); /** * @brief Checks the position field in a star tracker upload/download reply. diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 7999519c..36fb78b0 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -5,7 +5,11 @@ #include #include +#include + #include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/returnvalues/returnvalue.h" +#include "mission/memory/SdCardMountedIF.h" extern "C" { #include @@ -16,7 +20,6 @@ extern "C" { } #include -#include #include #include "OBSWConfig.h" @@ -27,7 +30,8 @@ std::atomic_bool JCFG_DONE(false); StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, StrComHandler* strHelper, power::Switch_t powerSwitch, - startracker::SdCardConfigPathGetter& cfgPathGetter) + startracker::SdCardConfigPathGetter& cfgPathGetter, + SdCardMountedIF& sdCardIF) : DeviceHandlerBase(objectId, comIF, comCookie), temperatureSet(this), versionSet(this), @@ -60,6 +64,7 @@ StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, contrastSet(this), strHelper(strHelper), powerSwitch(powerSwitch), + sdCardIF(sdCardIF), cfgPathGetter(cfgPathGetter) { if (comCookie == nullptr) { sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl; @@ -138,6 +143,9 @@ ReturnValue_t StarTrackerHandler::initialize() { // delay whole satellite boot process. reloadJsonCfgFile(); + // Default firmware target is always initialized from persistent file. + loadTargetFirmwareFromPersistentCfg(); + EventManagerIF* manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); if (manager == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -165,6 +173,19 @@ ReturnValue_t StarTrackerHandler::initialize() { return returnvalue::OK; } +void StarTrackerHandler::loadTargetFirmwareFromPersistentCfg() { + const char* prefix = sdCardIF.getCurrentMountPrefix(); + std::filesystem::path path = std::filesystem::path(prefix) / startracker::FW_TARGET_CFG_PATH; + std::ifstream ifile(path); + if (ifile.is_open()) { + std::string targetStr; + std::getline(ifile, targetStr); + if (targetStr == "backup\n") { + firmwareTargetRaw = static_cast(startracker::FirmwareTarget::BACKUP); + } + } +} + bool StarTrackerHandler::reloadJsonCfgFile() { jcfgCountdown.resetTimer(); auto strCfgPath = cfgPathGetter.getCfgPath(); @@ -307,21 +328,11 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu strHelper->setFlashReadFilename(std::string(reinterpret_cast(data), size)); return EXECUTION_FINISHED; } - case (startracker::FIRMWARE_UPDATE): { - result = DeviceHandlerBase::acceptExternalDeviceCommands(); - if (result != returnvalue::OK) { - return result; - } - if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) { - return FILE_PATH_TOO_LONG; - } - result = - strHelper->startFirmwareUpdate(std::string(reinterpret_cast(data), size)); - if (result != returnvalue::OK) { - return result; - } - strHelperHandlingSpecialRequest = true; - return EXECUTION_FINISHED; + case (startracker::FIRMWARE_UPDATE_MAIN): { + return handleFirmwareUpdateCommand(data, size, startracker::FirmwareTarget::MAIN); + } + case (startracker::FIRMWARE_UPDATE_BACKUP): { + return handleFirmwareUpdateCommand(data, size, startracker::FirmwareTarget::BACKUP); } default: break; @@ -330,6 +341,23 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu reinitNextSetParam = true; return DeviceHandlerBase::executeAction(actionId, commandedBy, data, size); } +ReturnValue_t StarTrackerHandler::handleFirmwareUpdateCommand(const uint8_t* data, size_t size, + startracker::FirmwareTarget target) { + ReturnValue_t result = DeviceHandlerBase::acceptExternalDeviceCommands(); + if (result != returnvalue::OK) { + return result; + } + if (size > config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE) { + return FILE_PATH_TOO_LONG; + } + result = strHelper->startFirmwareUpdate(std::string(reinterpret_cast(data), size), + target); + if (result != returnvalue::OK) { + return result; + } + strHelperHandlingSpecialRequest = true; + return EXECUTION_FINISHED; +} void StarTrackerHandler::performOperationHook() { EventMessage event; @@ -569,7 +597,7 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi return returnvalue::OK; } case (startracker::BOOT): { - prepareBootCommand(); + prepareBootCommand(static_cast(firmwareTargetRaw)); return returnvalue::OK; } case (startracker::REQ_VERSION): { @@ -1659,7 +1687,8 @@ ReturnValue_t StarTrackerHandler::checkMode(ActionId_t actionId) { case startracker::UPLOAD_IMAGE: case startracker::DOWNLOAD_IMAGE: case startracker::FLASH_READ: - case startracker::FIRMWARE_UPDATE: { + case startracker::FIRMWARE_UPDATE_BACKUP: + case startracker::FIRMWARE_UPDATE_MAIN: { return DeviceHandlerBase::acceptExternalDeviceCommands(); default: break; @@ -1956,9 +1985,9 @@ ReturnValue_t StarTrackerHandler::executeFlashReadCommand(const uint8_t* command return result; } -void StarTrackerHandler::prepareBootCommand() { +void StarTrackerHandler::prepareBootCommand(startracker::FirmwareTarget target) { uint32_t length = 0; - struct BootActionRequest bootRequest = {BOOT_REGION_ID}; + struct BootActionRequest bootRequest = {static_cast(target)}; arc_pack_boot_action_req(&bootRequest, commandBuffer, &length); rawPacket = commandBuffer; rawPacketLen = length; @@ -2389,7 +2418,8 @@ ReturnValue_t StarTrackerHandler::checkProgram() { internalState = InternalState::DONE; } break; - case startracker::Program::FIRMWARE: + case startracker::Program::FIRMWARE_BACKUP: + case startracker::Program::FIRMWARE_MAIN: { if (startupState == StartupState::WAIT_CHECK_PROGRAM) { startupState = StartupState::BOOT_BOOTLOADER; } @@ -2400,9 +2430,10 @@ ReturnValue_t StarTrackerHandler::checkProgram() { internalState = InternalState::FAILED_BOOTLOADER_BOOT; } break; + } default: - sif::warning << "StarTrackerHandler::checkProgram: Version set has invalid program ID" - << std::endl; + sif::warning << "StarTrackerHandler::checkProgram: Version set has invalid program ID " + << (int)versionSet.program.value << std::endl; return INVALID_PROGRAM; } return returnvalue::OK; @@ -2865,12 +2896,13 @@ ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) { case startracker::REQ_CENTROID: case startracker::REQ_CENTROIDS: case startracker::REQ_CONTRAST: { - if (getMode() == MODE_ON and getSubmode() != startracker::Program::FIRMWARE) { + if (getMode() == MODE_ON and getSubmode() != startracker::Program::FIRMWARE_MAIN) { return STARTRACKER_NOT_RUNNING_FIRMWARE; } break; } - case startracker::FIRMWARE_UPDATE: + case startracker::FIRMWARE_UPDATE_MAIN: + case startracker::FIRMWARE_UPDATE_BACKUP: case startracker::FLASH_READ: if (getMode() != MODE_ON or getSubmode() != startracker::Program::BOOTLOADER) { return STARTRACKER_NOT_RUNNING_BOOTLOADER; @@ -2883,3 +2915,43 @@ ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) { } ReturnValue_t StarTrackerHandler::acceptExternalDeviceCommands() { return returnvalue::OK; } + +ReturnValue_t StarTrackerHandler::getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues, + uint16_t startAtIndex) { + auto firmwareTargetUpdate = [&](bool persistent) { + uint8_t value = 0; + newValues->getElement(&value); + if (value != static_cast(startracker::FirmwareTarget::MAIN) && + value != static_cast(startracker::FirmwareTarget::BACKUP)) { + return HasParametersIF::INVALID_VALUE; + } + parameterWrapper->set(firmwareTargetRaw); + if (persistent) { + if (sdCardIF.isSdCardUsable(std::nullopt)) { + const char* prefix = sdCardIF.getCurrentMountPrefix(); + std::filesystem::path path = + std::filesystem::path(prefix) / startracker::FW_TARGET_CFG_PATH; + std::ofstream of(path, std::ofstream::out | std::ofstream::trunc); + if (value == static_cast(startracker::FirmwareTarget::MAIN)) { + of << "main\n"; + } else { + of << "backup\n"; + } + } else { + sif::warning << "SD card not usable" << std::endl; + return returnvalue::FAILED; + } + }; + return returnvalue::OK; + }; + if (uniqueId == startracker::ParamId::FIRMWARE_TARGET) { + return firmwareTargetUpdate(false); + } + if (uniqueId == startracker::ParamId::FIRMWARE_TARGET_PERSISTENT) { + return firmwareTargetUpdate(true); + } + return DeviceHandlerBase::getParameter(domainId, uniqueId, parameterWrapper, newValues, + startAtIndex); +} diff --git a/mission/acs/str/StarTrackerHandler.h b/mission/acs/str/StarTrackerHandler.h index 91651e04..f6611ed6 100644 --- a/mission/acs/str/StarTrackerHandler.h +++ b/mission/acs/str/StarTrackerHandler.h @@ -11,10 +11,7 @@ #include #include -#include "OBSWConfig.h" -#include "devices/powerSwitcherList.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h" -#include "fsfw/src/fsfw/serialize/SerializeAdapter.h" #include "fsfw/timemanager/Countdown.h" extern "C" { @@ -45,7 +42,7 @@ class StarTrackerHandler : public DeviceHandlerBase { */ StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, StrComHandler* strHelper, power::Switch_t powerSwitch, - startracker::SdCardConfigPathGetter& cfgPathGetter); + startracker::SdCardConfigPathGetter& cfgPathGetter, SdCardMountedIF& sdCardIF); virtual ~StarTrackerHandler(); ReturnValue_t initialize() override; @@ -61,6 +58,9 @@ class StarTrackerHandler : public DeviceHandlerBase { Submode_t getInitialSubmode() override; + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, + const ParameterWrapper* newValues, uint16_t startAtIndex) override; + protected: void doStartUp() override; void doShutDown() override; @@ -161,7 +161,8 @@ class StarTrackerHandler : public DeviceHandlerBase { // Ping request will reply ping with this ID (data field) static const uint32_t PING_ID = 0x55; - static const uint32_t BOOT_REGION_ID = 1; + uint8_t firmwareTargetRaw = static_cast(startracker::FirmwareTarget::MAIN); + static const MutexIF::TimeoutType TIMEOUT_TYPE = MutexIF::TimeoutType::WAITING; static const uint32_t MUTEX_TIMEOUT = 20; static const uint32_t BOOT_TIMEOUT = 1000; @@ -314,12 +315,14 @@ class StarTrackerHandler : public DeviceHandlerBase { std::set additionalRequestedTm{}; std::set::iterator currentSecondaryTmIter; + SdCardMountedIF& sdCardIF; startracker::SdCardConfigPathGetter& cfgPathGetter; /** * @brief Handles internal state */ void handleInternalState(); + void loadTargetFirmwareFromPersistentCfg(); /** * @brief Checks mode for commands requiring MODE_ON of MODE_NORMAL for execution. @@ -380,7 +383,7 @@ class StarTrackerHandler : public DeviceHandlerBase { * @brief Fills command buffer with data to boot image (works only when star tracker is * in bootloader mode). */ - void prepareBootCommand(); + void prepareBootCommand(startracker::FirmwareTarget target); /** * @brief Fills command buffer with command to get the checksum of a flash part @@ -550,6 +553,9 @@ class StarTrackerHandler : public DeviceHandlerBase { void bootBootloader(); bool reloadJsonCfgFile(); ReturnValue_t acceptExternalDeviceCommands() override; + + ReturnValue_t handleFirmwareUpdateCommand(const uint8_t* data, size_t size, + startracker::FirmwareTarget target); }; #endif /* MISSION_DEVICES_STARTRACKERHANDLER_H_ */ diff --git a/mission/acs/str/strHelpers.h b/mission/acs/str/strHelpers.h index 9f284725..e73a58af 100644 --- a/mission/acs/str/strHelpers.h +++ b/mission/acs/str/strHelpers.h @@ -14,6 +14,12 @@ namespace startracker { static const Submode_t SUBMODE_BOOTLOADER = 1; static const Submode_t SUBMODE_FIRMWARE = 2; +enum class FirmwareTarget : uint8_t { MAIN = 1, BACKUP = 10 }; + +static constexpr char FW_TARGET_CFG_PATH[] = "startracker/fw-target.txt"; + +enum ParamId : uint32_t { FIRMWARE_TARGET = 1, FIRMWARE_TARGET_PERSISTENT = 2 }; + class SdCardConfigPathGetter { public: virtual ~SdCardConfigPathGetter() = default; @@ -373,7 +379,7 @@ static const DeviceCommandId_t REQ_DEBUG_CAMERA = 80; static const DeviceCommandId_t LOGLEVEL = 81; static const DeviceCommandId_t LOGSUBSCRIPTION = 82; static const DeviceCommandId_t DEBUG_CAMERA = 83; -static const DeviceCommandId_t FIRMWARE_UPDATE = 84; +static const DeviceCommandId_t FIRMWARE_UPDATE_MAIN = 84; static const DeviceCommandId_t DISABLE_TIMESTAMP_GENERATION = 85; static const DeviceCommandId_t ENABLE_TIMESTAMP_GENERATION = 86; static constexpr DeviceCommandId_t SET_TIME_FROM_SYS_TIME = 87; @@ -388,6 +394,7 @@ static constexpr DeviceCommandId_t ADD_SECONDARY_TM_TO_NORMAL_MODE = 95; static constexpr DeviceCommandId_t RESET_SECONDARY_TM_SET = 96; static constexpr DeviceCommandId_t READ_SECONDARY_TM_SET = 97; static constexpr DeviceCommandId_t RELOAD_JSON_CFG_FILE = 100; +static const DeviceCommandId_t FIRMWARE_UPDATE_BACKUP = 101; static const DeviceCommandId_t NONE = 0xFFFFFFFF; static const uint32_t VERSION_SET_ID = REQ_VERSION; @@ -489,7 +496,8 @@ static constexpr uint8_t MATCHED_CENTROIDS = 40; namespace Program { static const uint8_t BOOTLOADER = 1; -static const uint8_t FIRMWARE = 2; +static const uint8_t FIRMWARE_MAIN = 2; +static const uint8_t FIRMWARE_BACKUP = 3; } // namespace Program namespace region_secrets { @@ -509,7 +517,7 @@ static const uint32_t REGION_12_SECRET = 0x42fedef6; static const uint32_t REGION_13_SECRET = 0xe53cf10d; static const uint32_t REGION_14_SECRET = 0xe862b70b; static const uint32_t REGION_15_SECRET = 0x79b537ca; -static const uint32_t secret[16]{ +static const uint32_t SECRETS[16]{ REGION_0_SECRET, REGION_1_SECRET, REGION_2_SECRET, REGION_3_SECRET, REGION_4_SECRET, REGION_5_SECRET, REGION_6_SECRET, REGION_7_SECRET, REGION_8_SECRET, REGION_9_SECRET, REGION_10_SECRET, REGION_11_SECRET, @@ -538,7 +546,12 @@ enum class FlashSections : uint8_t { }; // Flash region IDs of firmware partition -enum class FirmwareRegions : uint32_t { FIRST = 1, LAST = 8 }; +enum class FirmwareRegions : uint32_t { + FIRST_MAIN = 1, + LAST_MAIN = 8, + FIRST_BACKUP = 10, + LAST_BACKUP = 16 +}; static const uint32_t FLASH_REGION_SIZE = 0x20000; diff --git a/tmtc b/tmtc index a5ebac62..85fc106a 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit a5ebac626682e86b45f991c919a3ce9a9b7fcfcc +Subproject commit 85fc106a9b0e6d4256e6243200b9c0a3b910f67c -- 2.43.0 From 9a1d91c26133218a6504bc5064b5b74c2264ffba Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 17:16:56 +0100 Subject: [PATCH 2/8] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index baccb4cb..e3e311f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,10 @@ will consitute of a breaking change warranting a new major release: - The `PTG_CTRL_NO_ATTITUDE_INFORMATION` will now actually trigger a fallback into safe mode and is triggered by the `AcsController` now. +## Added + +- Updated STR handler to unlock and allow using the secondary firmware slot. + # [v7.6.1] 2024-02-05 ## Changed -- 2.43.0 From 2d9236824009fc3a721c3b9c9e98a2be160f96b0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Feb 2024 17:23:02 +0100 Subject: [PATCH 3/8] small bugfix --- mission/acs/str/StarTrackerHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 36fb78b0..0858b48d 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -180,7 +180,7 @@ void StarTrackerHandler::loadTargetFirmwareFromPersistentCfg() { if (ifile.is_open()) { std::string targetStr; std::getline(ifile, targetStr); - if (targetStr == "backup\n") { + if (targetStr == "backup") { firmwareTargetRaw = static_cast(startracker::FirmwareTarget::BACKUP); } } -- 2.43.0 From ab71014f672850e0b53a6bc81457b0b729c8d5fc Mon Sep 17 00:00:00 2001 From: meggert Date: Mon, 26 Feb 2024 14:06:23 +0100 Subject: [PATCH 4/8] bumped tmtc --- tmtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc b/tmtc index 85fc106a..588d7a80 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 85fc106a9b0e6d4256e6243200b9c0a3b910f67c +Subproject commit 588d7a8079194c6c51d6ecafd4c940cb1bf0554c -- 2.43.0 From 386430b9f2b0b47ffd86090d5405772fc2cc89bc Mon Sep 17 00:00:00 2001 From: meggert Date: Mon, 26 Feb 2024 14:06:59 +0100 Subject: [PATCH 5/8] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 150a79e0..6acf41d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ will consitute of a breaking change warranting a new major release: # [unreleased] +- Bumped `eive-tmtc` to - Bumped `eive-fsfw` ## Fixed -- 2.43.0 From c434882e3727f8497c14cd246884451eaf629205 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Feb 2024 10:54:26 +0100 Subject: [PATCH 6/8] code review --- mission/acs/str/StarTrackerHandler.cpp | 10 +++++----- mission/genericFactory.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 0858b48d..2a07def5 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -7,6 +7,7 @@ #include +#include "fsfw/filesystem/HasFileSystemIF.h" #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/returnvalues/returnvalue.h" #include "mission/memory/SdCardMountedIF.h" @@ -177,7 +178,7 @@ void StarTrackerHandler::loadTargetFirmwareFromPersistentCfg() { const char* prefix = sdCardIF.getCurrentMountPrefix(); std::filesystem::path path = std::filesystem::path(prefix) / startracker::FW_TARGET_CFG_PATH; std::ifstream ifile(path); - if (ifile.is_open()) { + if (ifile.is_open() and !ifile.bad()) { std::string targetStr; std::getline(ifile, targetStr); if (targetStr == "backup") { @@ -2896,7 +2897,7 @@ ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) { case startracker::REQ_CENTROID: case startracker::REQ_CENTROIDS: case startracker::REQ_CONTRAST: { - if (getMode() == MODE_ON and getSubmode() != startracker::Program::FIRMWARE_MAIN) { + if (getMode() == MODE_ON and getSubmode() != startracker::SUBMODE_FIRMWARE) { return STARTRACKER_NOT_RUNNING_FIRMWARE; } break; @@ -2904,7 +2905,7 @@ ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) { case startracker::FIRMWARE_UPDATE_MAIN: case startracker::FIRMWARE_UPDATE_BACKUP: case startracker::FLASH_READ: - if (getMode() != MODE_ON or getSubmode() != startracker::Program::BOOTLOADER) { + if (getMode() != MODE_ON or getSubmode() != startracker::SUBMODE_BOOTLOADER) { return STARTRACKER_NOT_RUNNING_BOOTLOADER; } break; @@ -2940,8 +2941,7 @@ ReturnValue_t StarTrackerHandler::getParameter(uint8_t domainId, uint8_t uniqueI of << "backup\n"; } } else { - sif::warning << "SD card not usable" << std::endl; - return returnvalue::FAILED; + return HasFileSystemIF::FILESYSTEM_INACTIVE; } }; return returnvalue::OK; diff --git a/mission/genericFactory.cpp b/mission/genericFactory.cpp index daaf59cc..c5a69b26 100644 --- a/mission/genericFactory.cpp +++ b/mission/genericFactory.cpp @@ -253,7 +253,7 @@ void ObjectFactory::produceGenericObjects(HealthTableIF** healthTable_, PusTmFun auto psbParamsService5 = PsbParams(objects::PUS_SERVICE_5_EVENT_REPORTING, config::EIVE_PUS_APID, pus::PUS_SERVICE_5); - psbParamsService5.requestQueueDepth = 50; + psbParamsService5.requestQueueDepth = 50; psbParamsService5.maxPacketsPerCycle = 50; new Service5EventReporting(psbParamsService5, 80, 160); new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, config::EIVE_PUS_APID, -- 2.43.0 From 69f4b6de06096f299458f17e8b219dbd7019fd57 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Feb 2024 10:55:53 +0100 Subject: [PATCH 7/8] I LOVE STATIC_CAST. I LOVE TYPING A LOT --- mission/acs/str/StarTrackerHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mission/acs/str/StarTrackerHandler.cpp b/mission/acs/str/StarTrackerHandler.cpp index 2a07def5..a88014ab 100644 --- a/mission/acs/str/StarTrackerHandler.cpp +++ b/mission/acs/str/StarTrackerHandler.cpp @@ -2434,7 +2434,7 @@ ReturnValue_t StarTrackerHandler::checkProgram() { } default: sif::warning << "StarTrackerHandler::checkProgram: Version set has invalid program ID " - << (int)versionSet.program.value << std::endl; + << static_cast(versionSet.program.value) << std::endl; return INVALID_PROGRAM; } return returnvalue::OK; -- 2.43.0 From 2ac9f972da6c113e1f2ca4e6a7be7316269262fb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Feb 2024 10:58:23 +0100 Subject: [PATCH 8/8] remove debug printout --- linux/acs/StrComHandler.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/linux/acs/StrComHandler.cpp b/linux/acs/StrComHandler.cpp index a02d47d1..9c5e045f 100644 --- a/linux/acs/StrComHandler.cpp +++ b/linux/acs/StrComHandler.cpp @@ -426,8 +426,6 @@ ReturnValue_t StrComHandler::performFlashWrite() { file.seekg(0, file.end); fileSize = file.tellg(); if (fileSize > FLASH_REGION_SIZE * (flashWrite.lastRegion - flashWrite.firstRegion)) { - sif::debug << "Last region: " << (int)flashWrite.lastRegion - << " first region: " << (int)flashWrite.firstRegion << std::endl; sif::warning << "StrHelper::performFlashWrite: Invalid file" << std::endl; return returnvalue::FAILED; } -- 2.43.0