star tracker flash read

This commit is contained in:
Jakob Meier 2022-02-25 14:24:51 +01:00
parent 3593f5ab8c
commit e082f3973a
8 changed files with 2285 additions and 2291 deletions

View File

@ -1,8 +1,6 @@
#include "ObjectFactory.h" #include "ObjectFactory.h"
#include <devConf.h> #include <devConf.h>
#include <fsfw/src/fsfw/osal/common/TcpTmTcBridge.h>
#include <fsfw/src/fsfw/osal/common/TcpTmTcServer.h>
#include <fsfw_hal/linux/uart/UartComIF.h> #include <fsfw_hal/linux/uart/UartComIF.h>
#include <fsfw_hal/linux/uart/UartCookie.h> #include <fsfw_hal/linux/uart/UartCookie.h>
#include <mission/devices/GPSHyperionHandler.h> #include <mission/devices/GPSHyperionHandler.h>

View File

@ -7,7 +7,7 @@
#include "fsfw/tasks/TaskFactory.h" #include "fsfw/tasks/TaskFactory.h"
/** /**
* @brief This is the main program and entry point for the egse (raspberry pi 4) * @brief This is the main program entry point for the egse (raspberry pi 4)
* @return * @return
*/ */
int main(void) { int main(void) {

2
fsfw

@ -1 +1 @@
Subproject commit 3c06d2dbbb0d79608e003a8a3c89ae90cc71f409 Subproject commit 09c1918c1fe36a07ce611a33ff20799187d8d962

View File

@ -371,7 +371,7 @@ static const DeviceCommandId_t TRACKING = 47;
static const DeviceCommandId_t VALIDATION = 48; static const DeviceCommandId_t VALIDATION = 48;
static const DeviceCommandId_t ALGO = 49; static const DeviceCommandId_t ALGO = 49;
static const DeviceCommandId_t CHECKSUM = 50; static const DeviceCommandId_t CHECKSUM = 50;
static const DeviceCommandId_t READ = 51; static const DeviceCommandId_t FLASH_READ = 51;
static const DeviceCommandId_t DOWNLOAD_MATCHED_STAR = 53; static const DeviceCommandId_t DOWNLOAD_MATCHED_STAR = 53;
static const DeviceCommandId_t STOP_IMAGE_LOADER = 55; static const DeviceCommandId_t STOP_IMAGE_LOADER = 55;
static const DeviceCommandId_t RESET_ERROR = 56; static const DeviceCommandId_t RESET_ERROR = 56;

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,8 @@ class StarTrackerHandler : public DeviceHandlerBase {
void performOperationHook() override; void performOperationHook() override;
Submode_t getInitialSubmode() override;
static const Submode_t SUBMODE_BOOTLOADER = 1; static const Submode_t SUBMODE_BOOTLOADER = 1;
static const Submode_t SUBMODE_FIRMWARE = 2; static const Submode_t SUBMODE_FIRMWARE = 2;
@ -183,11 +185,8 @@ class StarTrackerHandler : public DeviceHandlerBase {
class ReadCmd { class ReadCmd {
public: public:
static const uint8_t ADDRESS_OFFSET = 1; // Minimum length of a read command (region, length and filename)
static const uint8_t LENGTH_OFFSET = 5; static const size_t MIN_LENGTH = 7;
static const uint8_t FILE_OFFSET = 9;
// Minimum length of a read command (region, address, length and filename)
static const size_t MIN_LENGTH = 11;
}; };
class EraseCmd { class EraseCmd {
@ -408,7 +407,7 @@ class StarTrackerHandler : public DeviceHandlerBase {
* *
* @return RETURN_OK if start of execution was successful, otherwise error return value * @return RETURN_OK if start of execution was successful, otherwise error return value
*/ */
ReturnValue_t executeReadCommand(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t executeFlashReadCommand(const uint8_t* commandData, size_t commandDataLen);
/** /**
* @brief Fills command buffer with data to boot image (works only when star tracker is * @brief Fills command buffer with data to boot image (works only when star tracker is

View File

@ -141,7 +141,6 @@ ReturnValue_t StrHelper::startFirmwareUpdate(std::string fullname) {
if (not std::filesystem::exists(flashWrite.fullname)) { if (not std::filesystem::exists(flashWrite.fullname)) {
return FILE_NOT_EXISTS; return FILE_NOT_EXISTS;
} }
flashWrite.address = 0;
flashWrite.firstRegion = static_cast<uint8_t>(startracker::FirmwareRegions::FIRST); flashWrite.firstRegion = static_cast<uint8_t>(startracker::FirmwareRegions::FIRST);
flashWrite.lastRegion = static_cast<uint8_t>(startracker::FirmwareRegions::LAST); flashWrite.lastRegion = static_cast<uint8_t>(startracker::FirmwareRegions::LAST);
internalState = InternalState::FIRMWARE_UPDATE; internalState = InternalState::FIRMWARE_UPDATE;
@ -150,8 +149,7 @@ ReturnValue_t StrHelper::startFirmwareUpdate(std::string fullname) {
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t region, uint32_t address, ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t startRegion, uint32_t length) {
uint32_t length) {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t result = checkPath(path); ReturnValue_t result = checkPath(path);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -162,8 +160,7 @@ ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t region, uint32
if (not std::filesystem::exists(flashRead.path)) { if (not std::filesystem::exists(flashRead.path)) {
return FILE_NOT_EXISTS; return FILE_NOT_EXISTS;
} }
flashRead.address = address; flashRead.startRegion = startRegion;
flashRead.region = region;
flashRead.size = length; flashRead.size = length;
internalState = InternalState::FLASH_READ; internalState = InternalState::FLASH_READ;
semaphore.release(); semaphore.release();
@ -184,8 +181,7 @@ ReturnValue_t StrHelper::performImageDownload() {
struct DownloadActionRequest downloadReq; struct DownloadActionRequest downloadReq;
uint32_t size = 0; uint32_t size = 0;
uint32_t retries = 0; uint32_t retries = 0;
std::string image = makeFilename(); std::string image = makeFullFilename(downloadImage.path, downloadImage.filename);
// std::ofstream file(image, std::ios_base::app | std::ios_base::out);
std::ofstream file(image, std::ios_base::out); std::ofstream file(image, std::ios_base::out);
if (not std::filesystem::exists(image)) { if (not std::filesystem::exists(image)) {
return FILE_CREATION_FAILED; return FILE_CREATION_FAILED;
@ -388,12 +384,13 @@ ReturnValue_t StrHelper::performFlashRead() {
uint32_t size = 0; uint32_t size = 0;
uint32_t retries = 0; uint32_t retries = 0;
Timestamp timestamp; Timestamp timestamp;
std::string fullname = flashRead.path + "/" + timestamp.str() + flashRead.filename; std::string fullname = makeFullFilename(flashRead.path, flashRead.filename);
std::ofstream file(fullname, std::ios_base::app | std::ios_base::out); std::ofstream file(fullname, std::ios_base::app | std::ios_base::out);
if (not std::filesystem::exists(fullname)) { if (not std::filesystem::exists(fullname)) {
return FILE_CREATION_FAILED; return FILE_CREATION_FAILED;
} }
req.region = flashRead.region; req.region = flashRead.startRegion;
req.address = 0;
while (bytesRead < flashRead.size) { while (bytesRead < flashRead.size) {
if (terminate) { if (terminate) {
return RETURN_OK; return RETURN_OK;
@ -403,7 +400,6 @@ ReturnValue_t StrHelper::performFlashRead() {
} else { } else {
req.length = CHUNK_SIZE; req.length = CHUNK_SIZE;
} }
req.address = flashRead.address + bytesRead;
arc_pack_read_action_req(&req, commandBuffer, &size); arc_pack_read_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address); result = sendAndRead(size, req.address);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -425,19 +421,14 @@ ReturnValue_t StrHelper::performFlashRead() {
file.close(); file.close();
return result; return result;
} }
result = checkActionReply();
if (result != RETURN_OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie);
retries++;
continue;
}
file.close();
return result;
}
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + FLASH_READ_DATA_OFFSET), file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + FLASH_READ_DATA_OFFSET),
req.length); req.length);
bytesRead += req.length; bytesRead += req.length;
req.address += req.length;
if (req.address >= FLASH_REGION_SIZE) {
req.address = 0;
req.region++;
}
retries = 0; retries = 0;
} }
file.close(); file.close();
@ -585,14 +576,14 @@ ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
return result; return result;
} }
std::string StrHelper::makeFilename() { std::string StrHelper::makeFullFilename(std::string path, std::string filename) {
std::string image; std::string image;
Timestamp timestamp; Timestamp timestamp;
if (timestamping) { if (timestamping) {
image = downloadImage.path + "/" + timestamp.str() + downloadImage.filename; image = path + "/" + timestamp.str() + filename;
} }
else { else {
image = downloadImage.path + "/" + downloadImage.filename; image = path + "/" + filename;
} }
return image; return image;
} }

View File

@ -118,11 +118,10 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
* @brief Starts the flash read procedure * @brief Starts the flash read procedure
* *
* @param path Path where file with read flash data will be created * @param path Path where file with read flash data will be created
* @param region Region ID of flash region to read from * @param startRegion Region form where to start reading
* @param address Start address of flash section to read
* @param length Number of bytes to read from flash * @param length Number of bytes to read from flash
*/ */
ReturnValue_t startFlashRead(std::string path, uint8_t region, uint32_t address, uint32_t length); ReturnValue_t startFlashRead(std::string path, uint8_t startRegion, uint32_t length);
/** /**
* @brief Can be used to interrupt a running data transfer. * @brief Can be used to interrupt a running data transfer.
@ -191,7 +190,7 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
static const uint8_t ADDRESS_OFFSET = 3; static const uint8_t ADDRESS_OFFSET = 3;
static const uint8_t LENGTH_OFFSET = 7; static const uint8_t LENGTH_OFFSET = 7;
static const size_t CHUNK_SIZE = 1024; static const size_t CHUNK_SIZE = 1024;
static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 2000; static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 3;
static const uint32_t FLASH_ERASE_DELAY = 500; static const uint32_t FLASH_ERASE_DELAY = 500;
enum class InternalState { enum class InternalState {
@ -245,10 +244,7 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
// Default name of file containing the data read from flash, can be changed via command // Default name of file containing the data read from flash, can be changed via command
std::string filename = "flashread.bin"; std::string filename = "flashread.bin";
// Will be set with the flash read command // Will be set with the flash read command
uint8_t region = 0; uint8_t startRegion = 0;
// Will be set with the flash read command and specifies the start address of the flash section
// to read
uint32_t address = 0;
// Number of bytes to read from flash // Number of bytes to read from flash
uint32_t size = 0; uint32_t size = 0;
}; };
@ -372,7 +368,15 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
*/ */
ReturnValue_t unlockAndEraseRegions(uint32_t from, uint32_t to); ReturnValue_t unlockAndEraseRegions(uint32_t from, uint32_t to);
std::string makeFilename(); /**
* @brief Creates full filename either with timestamp or without
*
* @param path Path where to create the file
* @param filename Name fo the file
*
* @return Full filename
*/
std::string makeFullFilename(std::string path, std::string filename);
}; };
#endif /* BSP_Q7S_DEVICES_STRHELPER_H_ */ #endif /* BSP_Q7S_DEVICES_STRHELPER_H_ */