Fix MSP flash read so it returns the actual bytes read from the flash,

and not the amount of bytes requested, which may be different depending
on the constraints of the flash chip used.
This commit is contained in:
Dominic Clifton 2018-12-06 12:14:57 +01:00
parent 25e1607292
commit 2627826cb7
1 changed files with 7 additions and 0 deletions

View File

@ -375,6 +375,8 @@ static void serializeDataflashReadReply(sbuf_t *dst, uint32_t address, const uin
#endif
if (compressionMethod == NO_COMPRESSION) {
uint16_t *readLenPtr = (uint16_t *)sbufPtr(dst);
if (!useLegacyFormat) {
// new format supports variable read lengths
sbufWriteU16(dst, readLen);
@ -383,6 +385,11 @@ static void serializeDataflashReadReply(sbuf_t *dst, uint32_t address, const uin
const int bytesRead = flashfsReadAbs(address, sbufPtr(dst), readLen);
if (!useLegacyFormat) {
// update the 'read length' with the actual amount read from flash.
*readLenPtr = (uint16_t)bytesRead;
}
sbufAdvance(dst, bytesRead);
if (useLegacyFormat) {