diff --git a/armsrc/appmain.c b/armsrc/appmain.c index ee9909615..4ffebcff4 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -3221,8 +3221,10 @@ static void PacketReceived(PacketCommandNG *packet) { } if (isok) { - for (size_t pos = 0; pos < count; pos += PM3_CMD_DATA_SIZE) { - size_t len = MIN((count - pos), PM3_CMD_DATA_SIZE); + // CMD_READ_MEM_DOWNLOADED is an OLD frame, also served by bootrom.c. + // Chunk by what reply_old can carry, not by the NG payload size. + for (size_t pos = 0; pos < count; pos += PM3_CMD_DATA_SIZE_OLD) { + size_t len = MIN((count - pos), PM3_CMD_DATA_SIZE_OLD); isok = (reply_old(CMD_READ_MEM_DOWNLOADED, pos, len, 0, &base[offset + pos], len) == PM3_SUCCESS); if (isok == false) { Dbprintf("transfer to client failed :: | pos %u len %u", pos, len); diff --git a/client/src/comms.c b/client/src/comms.c index 33cf760ff..a40f8fdc1 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -1289,6 +1289,9 @@ static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, siz offset = response->oldarg[0]; copy_bytes = response->oldarg[1]; src = response->data.asBytes; + // an OLD frame carries at most PM3_CMD_DATA_SIZE_OLD valid bytes, + // whatever oldarg[1] claims + copy_bytes = MIN(copy_bytes, (uint32_t)PM3_CMD_DATA_SIZE_OLD); } copy_bytes = MIN(bytes - bytes_completed, copy_bytes);