firmware update wip
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Jakob Meier 2022-02-04 13:06:56 +01:00
parent 4edbbf223c
commit 18d018b7d7
6 changed files with 624 additions and 542 deletions

View File

@ -9,7 +9,7 @@
#include "objects/systemObjectList.h"
namespace StarTracker {
namespace startracker {
/** This is the address of the star tracker */
static const uint8_t ADDRESS = 33;
@ -373,6 +373,56 @@ static const uint8_t BOOTLOADER = 1;
static const uint8_t FIRMWARE = 2;
} // namespace Program
namespace region_secrets {
static const uint32_t REGION_0_SECRET = 0xd1a220d3;
static const uint32_t REGION_1_SECRET = 0xdc770fa8;
static const uint32_t REGION_2_SECRET = 0xdf9066b0;
static const uint32_t REGION_3_SECRET = 0x5f6a0423;
static const uint32_t REGION_4_SECRET = 0xbbaad5d8;
static const uint32_t REGION_5_SECRET = 0xa81c3678;
static const uint32_t REGION_6_SECRET = 0xe10f76f8;
static const uint32_t REGION_7_SECRET = 0x83220919;
static const uint32_t REGION_8_SECRET = 0xec37289d;
static const uint32_t REGION_9_SECRET = 0x27ac0ef8;
static const uint32_t REGION_10_SECRET = 0xf017e43d;
static const uint32_t REGION_11_SECRET = 0xbc7f7f49;
static const uint32_t REGION_12_SECRET = 0x42fedef6;
static const uint32_t REGION_13_SECRET = 0xe53cf10d;
static const uint32_t REGION_14_SECRET = 0xe862b70b;
static const uint32_t REGION_15_SECRET = 0x79b537ca;
uint32_t secret[16] {
REGION_0_SECRET,
REGION_1_SECRET,
REGION_2_SECRET,
REGION_3_SECRET,
REGION_4_SECRET,
REGION_5_SECRET,
REGION_6_SECRET,
REGION_7_SECRET,
REGION_8_SECRET,
REGION_9_SECRET,
REGION_10_SECRET,
REGION_11_SECRET,
REGION_12_SECRET,
REGION_13_SECRET,
REGION_14_SECRET,
REGION_15_SECRET
};
}
enum class FlashSections: uint8_t {
BOOTLOADER_SECTION = 0,
MAIN_FIRMWARE_SECTION = 1,
ARC_CONFIG_SECTION = 2
};
enum class FirmwareRegions: uint32_t {
START = 1,
END = 8
};
static const uint32_t FLASH_REGION_SIZE = 0x20000;
/**
* @brief This dataset can be used to store the temperature of a reaction wheel.
*/

File diff suppressed because it is too large Load Diff

View File

@ -245,26 +245,26 @@ class StarTrackerHandler : public DeviceHandlerBase {
ArcsecDatalinkLayer dataLinkLayer;
StarTracker::TemperatureSet temperatureSet;
StarTracker::VersionSet versionSet;
StarTracker::PowerSet powerSet;
StarTracker::InterfaceSet interfaceSet;
StarTracker::TimeSet timeSet;
StarTracker::SolutionSet solutionSet;
StarTracker::HistogramSet histogramSet;
StarTracker::ContrastSet contrastSet;
StarTracker::ChecksumSet checksumSet;
StarTracker::DownloadCentroidSet downloadCentroidSet;
StarTracker::DownloadMatchedStar downloadMatchedStar;
StarTracker::DownloadDBImage downloadDbImage;
StarTracker::DownloadBlobPixel downloadBlobPixel;
StarTracker::CameraSet cameraSet;
StarTracker::LimitsSet limitsSet;
startracker::TemperatureSet temperatureSet;
startracker::VersionSet versionSet;
startracker::PowerSet powerSet;
startracker::InterfaceSet interfaceSet;
startracker::TimeSet timeSet;
startracker::SolutionSet solutionSet;
startracker::HistogramSet histogramSet;
startracker::ContrastSet contrastSet;
startracker::ChecksumSet checksumSet;
startracker::DownloadCentroidSet downloadCentroidSet;
startracker::DownloadMatchedStar downloadMatchedStar;
startracker::DownloadDBImage downloadDbImage;
startracker::DownloadBlobPixel downloadBlobPixel;
startracker::CameraSet cameraSet;
startracker::LimitsSet limitsSet;
// Pointer to object responsible for uploading and downloading images to/from the star tracker
StrHelper* strHelper = nullptr;
uint8_t commandBuffer[StarTracker::MAX_FRAME_SIZE];
uint8_t commandBuffer[startracker::MAX_FRAME_SIZE];
// Countdown to insert delay for star tracker to switch from bootloader to firmware program
Countdown bootCountdown;

View File

@ -154,7 +154,7 @@ ReturnValue_t StrHelper::startFirmwareUpdate(std::string fullname) {
return FILE_NOT_EXISTS;
}
flashWrite.address = 0;
flashWrite.region = static_cast<uint8_t>(RegionId::MAIN_FIRMWARE_SECTION);
flashWrite.section = static_cast<uint8_t>(RegionId::MAIN_FIRMWARE_SECTION);
internalState = InternalState::FIRMWARE_UPDATE;
semaphore.release();
terminate = false;
@ -317,12 +317,10 @@ ReturnValue_t StrHelper::performImageUpload() {
}
ReturnValue_t StrHelper::performFirmwareUpdate() {
using namespace startracker;
ReturnValue_t result = RETURN_OK;
result = unlock(flashWrite.region);
if (result != RETURN_OK) {
return result;
}
eraseF(flashWrite.region);
result = unlockAndEraseRegions(static_cast<uint32_t>(FirmwareRegions::START),
static_cast<uint32_t>(FirmwareRegions::END));
if (result != RETURN_OK) {
return result;
}
@ -345,7 +343,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
file.seekg(0, file.end);
fileSize = file.tellg();
remainingBytes = fileSize;
req.region = flashWrite.region;
req.region = flashWrite.section;
req.address = flashWrite.address;
req.length = MAX_FLASH_DATA;
while (remainingBytes >= MAX_FLASH_DATA) {
@ -357,7 +355,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
arc_pack_write_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address);
if (result != RETURN_OK) {
return RETURN_FAILED;
return result;
}
result = checkFlashActionReply(req.region, req.address, req.length);
if (result != RETURN_OK) {
@ -371,7 +369,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
arc_pack_write_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address);
if (result != RETURN_OK) {
return RETURN_FAILED;
return result;
}
result = checkFlashActionReply(req.region, req.address, req.length);
if (result != RETURN_OK) {
@ -551,7 +549,7 @@ ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter) {
}
decResult = ArcsecDatalinkLayer::DEC_IN_PROGRESS;
while (decResult == ArcsecDatalinkLayer::DEC_IN_PROGRESS) {
result = uartComIF->requestReceiveMessage(comCookie, StarTracker::MAX_FRAME_SIZE * 2 + 2);
result = uartComIF->requestReceiveMessage(comCookie, startracker::MAX_FRAME_SIZE * 2 + 2);
if (result != RETURN_OK) {
sif::warning << "StrHelper::sendAndRead: Failed to request reply" << std::endl;
triggerEvent(STR_HELPER_REQUESTING_MSG_FAILED, result, parameter);
@ -706,3 +704,31 @@ void StrHelper::printProgress(uint32_t itemsTransferred, uint32_t fullNumItems)
nextProgressPrint = 0;
}
}
ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
using namespace startracker::region_secrets;
struct UnlockActionRequest unlockReq;
struct EraseActionRequest eraseReq;
uint32_t size = 0;
for (uint8_t idx = from; idx <= to; idx++) {
unlockReq.region = idx;
unlockReq.code = secret[idx];
arc_pack_unlock_action_req(&req, commandBuffer, &size);
sendAndRead(size, req.region);
result = checkActionReply();
if (result != RETURN_OK) {
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id "
<< static_cast<unsigned int>(unlockReq.region) << std::endl;
return result;
}
eraseReq.region = idx;
arc_pack_erase_action_req(&eraseReq, commandBuffer, &size);
result = sendAndRead(size, eraseReq.region);
if (result != RETURN_OK) {
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id "
<< static_cast<unsigned int>(eraseReq.region) << std::endl;
return result;
}
}
return result;
}

View File

@ -21,6 +21,9 @@ extern "C" {
* @brief Helper class for the star tracker handler to accelerate large data transfers.
*/
class StrHelper : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF {
using namespace startracker;
public:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_HELPER;
@ -267,8 +270,8 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
public:
// File which contains data to write when executing the flash write command
std::string fullname;
// Will be set with the flash write command
uint8_t region = 0;
// Section where to write to
uint8_t section = 0;
// Will be set with the flash write command and specifies the start address where to write the
// flash data to
uint32_t address = 0;
@ -291,15 +294,9 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
};
FlashRead flashRead;
enum class RegionId : uint8_t {
BOOTLOADER_SECTION = 0,
MAIN_FIRMWARE_SECTION = 1,
ARC_CONFIG_SECTION = 2,
};
SdCardManager* sdcMan = nullptr;
uint8_t commandBuffer[StarTracker::MAX_FRAME_SIZE];
uint8_t commandBuffer[startracker::MAX_FRAME_SIZE];
bool terminate = false;
@ -413,6 +410,15 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
* @param fullNumItems Full number of items to transfer
*/
void printProgress(uint32_t itemsTransferred, uint32_t fullNumItems);
/**
* @brief Unlocks a range of flash regions
*
* @param from First region in range to unlock
* @param to Last region in range to unlock
*
*/
ReturnValue_t unlockRegions(uint32_t from, uint32_t to);
};
#endif /* BSP_Q7S_DEVICES_STRHELPER_H_ */

2
fsfw

@ -1 +1 @@
Subproject commit faf7da2743dcd30d83c3ab2f7b4d85277878e636
Subproject commit f08d291e3e22950e729c327c101d22a943910e9b