From 3c746e954b882892e4f6acdac2b373053f2a9e02 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 27 Sep 2022 14:29:39 +0200 Subject: [PATCH] updates on same image are problematic.. --- bsp_q7s/core/CoreController.cpp | 51 +++++++++++++++++++++++++-------- tmtc | 2 +- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index 51ab2bbb..ca63bb90 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -410,6 +410,7 @@ ReturnValue_t CoreController::sdStateMachine() { << std::endl; #endif sdcMan->setActiveSdCard(sdInfo.active); + currMntPrefix = sdcMan->getCurrentMountPrefix(); sdFsmState = SdStates::DETERMINE_OTHER; } else if (sdInfo.activeState == sd::SdState::OFF) { sdCardSetup(sdInfo.active, sd::SdState::ON, sdInfo.activeChar, false); @@ -432,6 +433,7 @@ ReturnValue_t CoreController::sdStateMachine() { } else { if (nonBlockingOpChecking(SdStates::DETERMINE_OTHER, 5, "Mounting SD card")) { sdcMan->setActiveSdCard(sdInfo.active); + currMntPrefix = sdcMan->getCurrentMountPrefix(); sdInfo.activeState = sd::SdState::MOUNTED; currentStateSetter(sdInfo.active, sd::SdState::MOUNTED); } @@ -1869,6 +1871,13 @@ ReturnValue_t CoreController::executeSwUpdate(SwUpdateSources sourceDir, const u } else { sourceStr = "tmp directory"; } + bool sameChipAndCopy = false; + if(chip == CURRENT_CHIP and copy == CURRENT_COPY) { + // This is problematic if the OBSW is running as a systemd service. + // Do not allow for now. + return HasActionsIF::INVALID_PARAMETERS; + //sameChipAndCopy = true; + } sif::info << "Executing SW update for Chip " << static_cast(data[0]) << " Copy " << static_cast(data[1]) << " from " << sourceStr << std::endl; path prefixPath; @@ -1901,17 +1910,35 @@ ReturnValue_t CoreController::executeSwUpdate(SwUpdateSources sourceDir, const u } cmd.str(""); cmd.clear(); - cmd << "xsc_mount_copy " << std::to_string(data[0]) << " " << std::to_string(data[1]); - result = system(cmd.str().c_str()); - if (result != 0) { - std::string contextString = "CoreController::executeAction: SW Update Mounting " + - std::to_string(data[0]) + " " + std::to_string(data[1]); - utility::handleSystemError(result, contextString); + path obswDestPath; + path obswVersionDestPath; + if(not sameChipAndCopy) { + cmd << "xsc_mount_copy " << std::to_string(data[0]) << " " << std::to_string(data[1]); + result = system(cmd.str().c_str()); + if (result != 0) { + std::string contextString = "CoreController::executeAction: SW Update Mounting " + + std::to_string(data[0]) + " " + std::to_string(data[1]); + utility::handleSystemError(result, contextString); + } + cmd.str(""); + cmd.clear(); + path xscMountDest(getXscMountDir(chip, copy)); + obswDestPath = xscMountDest / path(relative(config::OBSW_PATH, "/")); + obswVersionDestPath = xscMountDest / path(relative(config::OBSW_VERSION_FILE_PATH, "/")); + } else { + obswDestPath = path(config::OBSW_PATH); + obswVersionDestPath = path(config::OBSW_VERSION_FILE_PATH); + cmd << "writeprotect " << std::to_string(CURRENT_CHIP) << " " << std::to_string(CURRENT_COPY) + << " 0"; + result = system(cmd.str().c_str()); + if (result != 0) { + std::string contextString = "CoreController::executeAction: Unlocking current chip"; + utility::handleSystemError(result, contextString); + } + cmd.str(""); + cmd.clear(); } - cmd.str(""); - cmd.clear(); - path xscMountDest(getXscMountDir(chip, copy)); - path obswDestPath = xscMountDest / path(relative(config::OBSW_PATH, "/")); + cmd << "cp " << strippedImagePath << " " << obswDestPath; result = system(cmd.str().c_str()); if (result != 0) { @@ -1919,7 +1946,7 @@ ReturnValue_t CoreController::executeSwUpdate(SwUpdateSources sourceDir, const u } cmd.str(""); cmd.clear(); - path obswVersionDestPath = xscMountDest / path(relative(config::OBSW_VERSION_FILE_PATH, "/")); + cmd << "cp " << obswVersionFilePath << " " << obswVersionDestPath; result = system(cmd.str().c_str()); if (result != 0) { @@ -1933,7 +1960,7 @@ ReturnValue_t CoreController::executeSwUpdate(SwUpdateSources sourceDir, const u result = system(cmd.str().c_str()); if (result != 0) { utility::handleSystemError(result, - "CoreController::executeAction: Copying SW permissions 0755"); + "CoreController::executeAction: Setting SW permissions 0755"); } cmd.str(""); cmd.clear(); diff --git a/tmtc b/tmtc index aae1fbdd..a2991988 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit aae1fbddf4f5a208b3407dd11f61e33bb526268f +Subproject commit a2991988f56b631b5bab67e452e9d7c126b49480