crc for ploc update

This commit is contained in:
Jakob.Meier 2021-08-18 08:26:31 +02:00
parent be6056aadb
commit 124abf0213
4 changed files with 31 additions and 8 deletions

View File

@ -926,7 +926,7 @@ candump can0
## Dump content of file in hex
````
cat file.bin | hexdump
cat file.bin | hexdump -C
````
## Preparation of a fresh rootfs and SD card

View File

@ -292,7 +292,7 @@ void PlocUpdater::commandUpdateAvailable() {
remainingPackets = numOfUpdatePackets;
packetsSent = 0;
uint32_t imageCrc = makeCrc();
calcImageCrc();
PLOC_SPV::UpdateInfo packet(PLOC_SPV::APID_UPDATE_AVAILABLE, static_cast<uint8_t>(updateMemory),
static_cast<uint8_t>(updatePartition), imageSize, imageCrc, numOfUpdatePackets);
@ -338,7 +338,7 @@ void PlocUpdater::commandUpdatePacket() {
file.close();
// sequence count of first packet is 1
packet.setPacketSequenceCount((packetsSent + 1) & PLOC_SPV::SEQUENCE_COUNT_MASK);
if (numOfUpdatePackets > 0) {
if (numOfUpdatePackets > 1) {
adjustSequenceFlags(packet);
}
packet.makeCrc();
@ -383,9 +383,27 @@ void PlocUpdater::commandUpdateVerify() {
return;
}
ReturnValue_t PlocUpdater::makeCrc() {
//TODO: Waiting on input from TAS about the CRC to use
return 0;
void PlocUpdater::calcImageCrc() {
std::ifstream file(updateFile, std::ifstream::binary);
file.seekg(0, file.end);
uint32_t count;
uint32_t bit;
uint32_t remainder = INITIAL_REMAINDER_32;
char input;
for (count = 0; count < imageSize; count++) {
file.seekg(count, file.beg);
file.read(&input, 1);
remainder ^= (input << 16);
for (bit = 8; bit > 0; --bit) {
if (remainder & TOPBIT_32) {
remainder = (remainder << 1) ^ POLYNOMIAL_32;
} else {
remainder = (remainder << 1);
}
}
}
file.close();
imageCrc = (remainder ^ FINAL_XOR_VALUE_32);
}
void PlocUpdater::adjustSequenceFlags(PLOC_SPV::UpdatePacket& packet) {

View File

@ -92,6 +92,11 @@ private:
// Maximum size of update payload data per space packet (max size of space packet is 1024 bytes)
static const size_t MAX_SP_DATA = 1016;
static const uint32_t TOPBIT_32 = (1 << 31);
static const uint32_t POLYNOMIAL_32 = 0x04C11DB7;
static const uint32_t INITIAL_REMAINDER_32 = 0xFFFFFFFF;
static const uint32_t FINAL_XOR_VALUE_32 = 0xFFFFFFFF;
MessageQueueIF* commandQueue = nullptr;
#if BOARD_TE0720 == 0
@ -168,7 +173,7 @@ private:
bool isSdCardMounted(sd::SdCard sdCard);
#endif
ReturnValue_t makeCrc();
void calcImageCrc();
void adjustSequenceFlags(PLOC_SPV::UpdatePacket& packet);
};

View File

@ -1453,7 +1453,7 @@ public:
UpdateInfo(uint16_t apid, uint8_t memory, uint8_t partition, uint32_t imageSize,
uint32_t imageCrc, uint32_t numPackets) :
SupvTcSpacePacket(PAYLOAD_LENGTH, apid), memory(memory), partition(partition), imageSize(
imageSize), numPackets(numPackets) {
imageSize), imageCrc(imageCrc), numPackets(numPackets) {
initPacket();
makeCrc();
}