Found by building with a printf format attribute on PrintAndLogEx.
User visible:
- hw version: GENERIC device/firmware name was passed as an unused arg
and never printed
- hf saflok selftest: PRIx32 lacked '%', printed a literal 'x'
- hf mfp: key index value was never printed
- hf waveshare: output filename was never printed
Also: size_t/int64_t/uint64_t specifiers (%zu, PRId64, PRIX64), int
macros printed with %zu, ' ' flag on %u, unused arg in flash_prepare,
and non-literal strings passed as the format.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since cd5906674 the flash animation runs whatever stdout is, and a
redirected flash of fullimage.elf wrote a 7 MB log.
flash_pm3() replaced a flash error with the result of
flash_stop_flashing(), always PM3_SUCCESS, so a failed flash ended with
"All done". main() exited 0 after --flash, --dumpmem and
--reboot-to-bootloader whatever happened. dumpmem printed its negative
error code with %u.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The main loop cleared the whole PacketCommandNG payload before every call to
receive_ng(), so a device sitting idle memset PM3_CMD_DATA_SIZE bytes on each
pass of the loop whether anything was arriving or not. The zeroing belongs
inside receive_ng_internal(), once the preamble has been read and a packet is
known to be coming in, and that is where it is now.
It has to be before either branch fills the payload, because neither fills all
of it: an NG command writes only its own length, and an old style one only
PM3_CMD_DATA_SIZE_OLD. Whatever is not written has to start at zero.
Moving it also covers two callers that never had it. appmain.c has a second
receive_ng() that drains the buffer on a mode switch, and iclass.c has one that
picks up EML_MEMSET commands while waiting for RF. Both declare their
PacketCommandNG without initialising it, and the iclass one then reads a struct
out of the payload -- so a command shorter than that struct was reading stack
garbage beyond its length. That is fixed as a side effect.
Builds for RDV4 and PM5.
Thanks to @Msprg et al
The OLD frame size was tied to the NG one, but the bootloader only speaks
OLD - growing PM3_CMD_DATA_SIZE would silently change sizeof(PacketCommandOLD)
and break flashing against every deployed bootrom in both directions.
Pin the OLD structs to their own constant and use it on every OLD path:
reply_old and the OLD receive branch on both sides, the bootrom, and the
flasher's write_block/send_finish_write_cmd, which memcpy into a
PacketCommandOLD using the NG size.
No behaviour change - both constants are 512 and armsrc .text is
byte-identical before and after.
When updating from a old version on Windows, the `pm3-flash-all` always
fails even after updating the bootloader. This is because it detects
the hardware by the serial number "ICEMAN", which only appears after
flashing the fullimage.