|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
return executeSwUpdate(SwUpdateSources::SD_0, data, size);
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|