OBSW Update Commands #302

Merged
meierj merged 42 commits from mueller/obsw-update-cmds into develop 2022-09-29 13:24:17 +02:00
4 changed files with 90 additions and 34 deletions
Showing only changes of commit 8161d1cd88 - Show all commits

View File

@ -201,38 +201,10 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
return HasActionsIF::EXECUTION_FINISHED;
}
case (OBSW_UPDATE_FROM_SD_0): {
using namespace std;
using namespace std::filesystem;
// At the very least, chip and copy ID need to be included in the command
if (size < 2) {
return HasActionsIF::INVALID_PARAMETERS;
return executeSwUpdate(SwUpdateSources::SD_0, data, size);
}
if (data[0] > 1 or data[1] > 1) {
return HasActionsIF::INVALID_PARAMETERS;
}
auto chip = static_cast<xsc::Chip>(data[0]);
auto copy = static_cast<xsc::Copy>(data[1]);
path archivePath =
path(config::SD_0_MOUNT_POINT) / path(config::OBSW_UPDATE_ARCHIVE_FILE_NAME);
if (not exists(archivePath)) {
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
}
ostringstream cmd("tar -xJvf");
cmd << " " << archivePath;
int result = system(cmd.str().c_str());
if (result != 0) {
utility::handleSystemError(result,
"CoreController::executeAction: SW Update Decompression");
}
cmd.clear();
cmd << "xsc_mount_copy " << data[0] << " " << data[1];
result = system(cmd.str().c_str());
if (result != 0) {
std::string ctxString =
"CoreController::executeAction: SW Update Mounting " + data[0] + " " + data[1];
utility::handleSystemError(result, ctxString);
}
return HasActionsIF::EXECUTION_FINISHED;
case (OBSW_UPDATE_FROM_SD_1): {
return executeSwUpdate(SwUpdateSources::SD_1, data, size);
}
case (SWITCH_IMG_LOCK): {
if (size != 3) {
@ -1899,6 +1871,83 @@ const char *CoreController::getXscMountDir(xsc::Chip chip, xsc::Copy copy) {
return CHIP_0_COPY_0_MOUNT_DIR;
}
ReturnValue_t CoreController::executeSwUpdate(SwUpdateSources sourceDir, const uint8_t *data,
size_t size) {
using namespace std;
using namespace std::filesystem;
// At the very least, chip and copy ID need to be included in the command
if (size < 2) {
return HasActionsIF::INVALID_PARAMETERS;
}
if (data[0] > 1 or data[1] > 1) {
return HasActionsIF::INVALID_PARAMETERS;
}
auto chip = static_cast<xsc::Chip>(data[0]);
auto copy = static_cast<xsc::Copy>(data[1]);
path prefixPath;
if (sourceDir == SwUpdateSources::SD_0) {
prefixPath = path(config::SD_0_MOUNT_POINT);
} else if (sourceDir == SwUpdateSources::SD_1) {
prefixPath = path(config::SD_1_MOUNT_POINT);
} else if (sourceDir == SwUpdateSources::TMP_DIR) {
prefixPath = path("/tmp");
}
path archivePath = prefixPath / path(config::OBSW_UPDATE_ARCHIVE_FILE_NAME);
if (not exists(archivePath)) {
return HasFileSystemIF::FILE_DOES_NOT_EXIST;
}
ostringstream cmd("tar -xJvf");
cmd << " " << archivePath;
int result = system(cmd.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "CoreController::executeAction: SW Update Decompression");
}
path strippedImagePath = prefixPath / path(config::STRIPPED_OBSW_BINARY_FILE_NAME);
if (!exists(strippedImagePath)) {
// TODO: Custom returnvalue?
return returnvalue::FAILED;
}
path obswVersionFilePath = prefixPath / path(config::OBSW_VERSION_FILE_NAME);
if (!exists(obswVersionFilePath)) {
// TODO: Custom returnvalue?
return returnvalue::FAILED;
}
cmd.clear();
cmd << "xsc_mount_copy " << data[0] << " " << 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.clear();
std::string xscMountDest = std::string(getXscMountDir(chip, copy));
path obswDestPath = xscMountDest / config::OBSW_PATH;
cmd << "cp " << strippedImagePath << " " << obswDestPath;
result = system(cmd.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "CoreController::executeAction: Copying SW update");
}
cmd.clear();
path obswVersionDestPath = xscMountDest / config::OBSW_VERSION_FILE_PATH;
cmd << "cp " << obswVersionFilePath << " " << obswVersionDestPath;
result = system(cmd.str().c_str());
if (result != 0) {
utility::handleSystemError(result, "CoreController::executeAction: Copying SW version file");
}
cmd.clear();
// TODO: This takes a long time and will block the core controller.. Maybe use command executor?
// For now dont care..
cmd << "writeprotect " << data[0] << " " << data[1] << " 1";
result = system(cmd.str().c_str());
if (result != 0) {
std::string contextString = "CoreController::executeAction: Writeprotecting " +
std::to_string(data[0]) + " " + std::to_string(data[1]);
utility::handleSystemError(result, contextString);
}
return HasActionsIF::EXECUTION_FINISHED;
}
bool CoreController::isNumber(const std::string &s) {
return !s.empty() && std::find_if(s.begin(), s.end(),
[](unsigned char c) { return !std::isdigit(c); }) == s.end();

View File

@ -168,6 +168,9 @@ class CoreController : public ExtendedControllerBase {
// Used if SD switches or mount commands are issued via telecommand
SET_STATE_FROM_COMMAND,
};
enum class SwUpdateSources { SD_0, SD_1, TMP_DIR };
static constexpr bool BLOCKING_SD_INIT = false;
SdCardManager* sdcMan = nullptr;
@ -230,6 +233,7 @@ class CoreController : public ExtendedControllerBase {
void updateSdInfoOther();
ReturnValue_t sdCardSetup(sd::SdCard sdCard, sd::SdState targetState, std::string sdChar,
bool printOutput = true);
ReturnValue_t executeSwUpdate(SwUpdateSources sourceDir, const uint8_t* data, size_t size);
ReturnValue_t sdColdRedundantBlockingInit();
void currentStateSetter(sd::SdCard sdCard, sd::SdState newState);

View File

@ -12,6 +12,9 @@ static constexpr char OBSW_UPDATE_ARCHIVE_FILE_NAME[] = "eive-sw-update.tar.xz";
static constexpr char STRIPPED_OBSW_BINARY_FILE_NAME[] = "eive-obsw-stripped";
static constexpr char OBSW_VERSION_FILE_NAME[] = "obsw_version.txt";
static constexpr char OBSW_PATH[] = "/usr/bin/eive-obsw";
static constexpr char OBSW_VERSION_FILE_PATH[] = "/usr/share/eive-obsw/obsw_version.txt";
static constexpr uint16_t EIVE_PUS_APID = 0x65;
static constexpr uint16_t EIVE_CFDP_APID = 0x66;
static constexpr uint16_t EIVE_LOCAL_CFDP_ENTITY_ID = EIVE_CFDP_APID;

View File

@ -8,9 +8,9 @@
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/Clock.h"
void utility::handleSystemError(int retcode, std::string function) {
void utility::handleSystemError(int retcode, std::string context) {
#if OBSW_VERBOSE_LEVEL >= 1
sif::warning << function << ": System call failed with code " << retcode << ": "
sif::warning << context << ": System call failed with code " << retcode << ": "
<< strerror(retcode) << std::endl;
#endif
}