Writeprotection handler in CoreController #87

Merged
meierj merged 13 commits from mueller/writeprotect-handler into develop 2021-08-20 11:08:25 +02:00
3 changed files with 101 additions and 71 deletions
Showing only changes of commit e821a9700a - Show all commits

View File

@ -25,7 +25,7 @@ ReturnValue_t Q7STestTask::performOneShotAction() {
//testScratchApi();
//testJsonLibDirect();
//testDummyParams();
testProtHandler();
//testProtHandler();
//FsOpCodes opCode = FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY;
//testFileSystemHandlerDirect(opCode);
return TestTask::performOneShotAction();

View File

@ -946,16 +946,31 @@ ReturnValue_t CoreController::setBootCopyProtection(Chip targetChip, Copy target
}
for(uint8_t arrIdx = 0; arrIdx < protArray.size(); arrIdx++) {
int result = handleBootCopyProtAtIndex(targetChip, targetCopy, protect,
protOperationPerformed, selfChip, selfCopy, allChips, allCopies, arrIdx);
if(result != 0) {
break;
}
}
if(protOperationPerformed and updateProtFile) {
updateProtInfo();
}
return HasReturnvaluesIF::RETURN_OK;
}
int CoreController::handleBootCopyProtAtIndex(Chip targetChip, Copy targetCopy, bool protect,
bool &protOperationPerformed, bool selfChip, bool selfCopy, bool allChips,
bool allCopies, uint8_t arrIdx) {
bool currentProt = protArray[arrIdx];
std::ostringstream oss;
bool performOp = false;
if(protect == currentProt) {
continue;
return 0;
}
if(protOperationPerformed) {
if((selfChip and selfCopy) or (not allCopies and not allChips)) {
// No need to continue, only one operation was requested
break;
return 1;
}
}
Chip currentChip;
@ -1001,11 +1016,26 @@ ReturnValue_t CoreController::setBootCopyProtection(Chip targetChip, Copy target
}
}
else if(selfChip and (currentChip == targetChip)) {
if(selfCopy) {
if(currentCopy == targetCopy) {
performOp = true;
}
else if(selfCopy and (currentCopy == targetCopy)) {
}
else {
performOp = true;
}
}
else if(selfCopy and (currentCopy == targetCopy)) {
if(selfChip) {
if(currentChip == targetChip) {
performOp = true;
}
}
else {
performOp = true;
}
}
else if((targetChip == currentChip) and (targetCopy == currentCopy)) {
performOp = true;
}
@ -1013,16 +1043,13 @@ ReturnValue_t CoreController::setBootCopyProtection(Chip targetChip, Copy target
utility::handleSystemError(result, "CoreController::checkAndSetBootCopyProtection");
}
if(performOp) {
// TODO: Lock operation take a long time. Use command executor?
// TODO: Lock operation take a long time. Use command executor? That would require a
// new state machine..
protOperationPerformed = true;
sif::info << "Executing command: " << oss.str() << std::endl;
result = std::system(oss.str().c_str());
}
}
if(protOperationPerformed and updateProtFile) {
updateProtInfo();
}
return HasReturnvaluesIF::RETURN_OK;
return 0;
}
ReturnValue_t CoreController::updateProtInfo(bool regenerateChipStateFile) {

View File

@ -176,6 +176,9 @@ private:
void performWatchdogControlOperation();
ReturnValue_t handleProtInfoUpdateLine(std::string nextLine);
int handleBootCopyProtAtIndex(Chip targetChip, Copy targetCopy, bool protect,
bool &protOperationPerformed, bool selfChip, bool selfCopy, bool allChips,
bool allCopies, uint8_t arrIdx);
};
#endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */