Writeprotection handler in CoreController #87
@ -25,7 +25,7 @@ ReturnValue_t Q7STestTask::performOneShotAction() {
|
|||||||
//testScratchApi();
|
//testScratchApi();
|
||||||
//testJsonLibDirect();
|
//testJsonLibDirect();
|
||||||
//testDummyParams();
|
//testDummyParams();
|
||||||
testProtHandler();
|
//testProtHandler();
|
||||||
//FsOpCodes opCode = FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY;
|
//FsOpCodes opCode = FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY;
|
||||||
//testFileSystemHandlerDirect(opCode);
|
//testFileSystemHandlerDirect(opCode);
|
||||||
return TestTask::performOneShotAction();
|
return TestTask::performOneShotAction();
|
||||||
|
@ -946,77 +946,10 @@ ReturnValue_t CoreController::setBootCopyProtection(Chip targetChip, Copy target
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(uint8_t arrIdx = 0; arrIdx < protArray.size(); arrIdx++) {
|
for(uint8_t arrIdx = 0; arrIdx < protArray.size(); arrIdx++) {
|
||||||
bool currentProt = protArray[arrIdx];
|
int result = handleBootCopyProtAtIndex(targetChip, targetCopy, protect,
|
||||||
std::ostringstream oss;
|
protOperationPerformed, selfChip, selfCopy, allChips, allCopies, arrIdx);
|
||||||
bool performOp = false;
|
|
||||||
if(protect == currentProt) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(protOperationPerformed) {
|
|
||||||
if((selfChip and selfCopy) or (not allCopies and not allChips)) {
|
|
||||||
// No need to continue, only one operation was requested
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Chip currentChip;
|
|
||||||
Copy currentCopy;
|
|
||||||
oss << "writeprotect ";
|
|
||||||
if(arrIdx == 0 or arrIdx == 1) {
|
|
||||||
oss << "0 ";
|
|
||||||
currentChip = Chip::CHIP_0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
oss << "1 ";
|
|
||||||
currentChip = Chip::CHIP_1;
|
|
||||||
}
|
|
||||||
if(arrIdx == 0 or arrIdx == 2) {
|
|
||||||
oss << "0 ";
|
|
||||||
currentCopy = Copy::COPY_0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
oss << "1 ";
|
|
||||||
currentCopy = Copy::COPY_1;
|
|
||||||
}
|
|
||||||
if(protect) {
|
|
||||||
oss << "1";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
oss << "0";
|
|
||||||
}
|
|
||||||
|
|
||||||
int result = 0;
|
|
||||||
if(allChips and allCopies) {
|
|
||||||
performOp = true;
|
|
||||||
}
|
|
||||||
else if(allChips) {
|
|
||||||
if((selfCopy and CURRENT_COPY == targetCopy) or
|
|
||||||
(currentCopy == targetCopy)) {
|
|
||||||
performOp = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(allCopies) {
|
|
||||||
if((selfChip and CURRENT_COPY == targetCopy) or
|
|
||||||
(currentChip == targetChip)) {
|
|
||||||
performOp = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(selfChip and (currentChip == targetChip)) {
|
|
||||||
performOp = true;
|
|
||||||
}
|
|
||||||
else if(selfCopy and (currentCopy == targetCopy)) {
|
|
||||||
performOp = true;
|
|
||||||
}
|
|
||||||
else if((targetChip == currentChip) and (targetCopy == currentCopy)) {
|
|
||||||
performOp = true;
|
|
||||||
}
|
|
||||||
if(result != 0) {
|
if(result != 0) {
|
||||||
utility::handleSystemError(result, "CoreController::checkAndSetBootCopyProtection");
|
break;
|
||||||
}
|
|
||||||
if(performOp) {
|
|
||||||
// TODO: Lock operation take a long time. Use command executor?
|
|
||||||
protOperationPerformed = true;
|
|
||||||
sif::info << "Executing command: " << oss.str() << std::endl;
|
|
||||||
result = std::system(oss.str().c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(protOperationPerformed and updateProtFile) {
|
if(protOperationPerformed and updateProtFile) {
|
||||||
@ -1025,6 +958,100 @@ ReturnValue_t CoreController::setBootCopyProtection(Chip targetChip, Copy target
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
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) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(protOperationPerformed) {
|
||||||
|
if((selfChip and selfCopy) or (not allCopies and not allChips)) {
|
||||||
|
// No need to continue, only one operation was requested
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Chip currentChip;
|
||||||
|
Copy currentCopy;
|
||||||
|
oss << "writeprotect ";
|
||||||
|
if(arrIdx == 0 or arrIdx == 1) {
|
||||||
|
oss << "0 ";
|
||||||
|
currentChip = Chip::CHIP_0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
oss << "1 ";
|
||||||
|
currentChip = Chip::CHIP_1;
|
||||||
|
}
|
||||||
|
if(arrIdx == 0 or arrIdx == 2) {
|
||||||
|
oss << "0 ";
|
||||||
|
currentCopy = Copy::COPY_0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
oss << "1 ";
|
||||||
|
currentCopy = Copy::COPY_1;
|
||||||
|
}
|
||||||
|
if(protect) {
|
||||||
|
oss << "1";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
oss << "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = 0;
|
||||||
|
if(allChips and allCopies) {
|
||||||
|
performOp = true;
|
||||||
|
}
|
||||||
|
else if(allChips) {
|
||||||
|
if((selfCopy and CURRENT_COPY == targetCopy) or
|
||||||
|
(currentCopy == targetCopy)) {
|
||||||
|
performOp = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(allCopies) {
|
||||||
|
if((selfChip and CURRENT_COPY == targetCopy) or
|
||||||
|
(currentChip == targetChip)) {
|
||||||
|
performOp = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(selfChip and (currentChip == targetChip)) {
|
||||||
|
if(selfCopy) {
|
||||||
|
if(currentCopy == targetCopy) {
|
||||||
|
performOp = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if(result != 0) {
|
||||||
|
utility::handleSystemError(result, "CoreController::checkAndSetBootCopyProtection");
|
||||||
|
}
|
||||||
|
if(performOp) {
|
||||||
|
// 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());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t CoreController::updateProtInfo(bool regenerateChipStateFile) {
|
ReturnValue_t CoreController::updateProtInfo(bool regenerateChipStateFile) {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||||
|
@ -176,6 +176,9 @@ private:
|
|||||||
void performWatchdogControlOperation();
|
void performWatchdogControlOperation();
|
||||||
|
|
||||||
ReturnValue_t handleProtInfoUpdateLine(std::string nextLine);
|
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_ */
|
#endif /* BSP_Q7S_CORE_CORECONTROLLER_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user