Pull Request #254: DRAFT: Binmode dude readfix

New Pull Request: DRAFT: Binmode dude readfix
mbrugman67/BusPirate5-firmwareDangerousPrototypes/BusPirate5-firmware

DO NOT MERGE UNTIL FURTHER TESTING

This PR fixes the issue with legacy binmode with AVRdude preventing reads on parts with flash > 64Kbytes.

The AVR command to read flash uses a 16-byte address pointer; for parts greater than 64K flash, there is a separate ISP command for AVR_LOAD_ADDRESS_EXTENDED_HIGH_BYTE_COMMAND. There could be issues on older AVR parts with <= 64Kbytes of flash generating errors if they receive this command.

To manage this, it’s necessary to know flash memory size before starting read flash memory operations. We’ll use the part’s signature to determine flash size. AVR parts have a 3-byte signature:

  • byte 0 - always 0x1e
  • byte 1 - flash size
  • byte 2 - specific part within the flash size family

One of the first things that happens with AVRdude is that the part is commanded to go into ISP program mode, then the signature is read. This PR adds some hacky code to watch for that and set a flag if signature byte 1 indicates this part has > 64Kbytes.

Here is a table of signatures and parts supported by AVRdude:

Signature Flash size Parts Extended High Byte Required?
0x1e 0x8f 0x– 512 bytes ATtiny4/5 No
0x1e 0x90 0x– 1 Kbyte ATtiny9/1*, AT90S1200 No
0x1e 0x91 0x– 2 Kbyte ATtiny2, AT90S23 No
0x1e 0x92 0x– 4 Kbyte ATtiny4, ATmega4, AT90S4* No
0x1e 0x93 0x– 8 Kbyte ATtiny8, ATmega8, ATxmega8, AT90S8 No
0x1e 0x94 0x– 16 Kbyte ATtiny16, ATmega16, ATxmega16* No
0x1e 0x95 0x– 32 Kbyte ATtiny32, ATmega32, ATxmega32, AVR32, AT90CAN32 No
0x1e 0x96 0x– 48, 64 Kbyte ATmega480, ATmega64, ATxmega64, AVR64, AT90CAN64, AT90USB64* No
0x1e 0x97 0x– 128, 192 Kbyte ATmega103, ATmega128, AVR128, ATxmega128, ATxmega192, AT90CAN128, AT90USB128 Yes
0x1e 0x98 0x– 256, 384 Kbyte ATmega256, ATxmega256, ATxmega384* Yes
0x1e 0xa6 0x– 64 Kbyte ATmega64RF* No
0x1e 0xa7 0x– 128 Kbyte ATmega128RF* Yes
0x1e 0xa8 0x– 256 Kbyte ATmega256RF* Yes
0x1e 0xc0 0x– 512 Kbyte AT32UC3A0512 Yes

Created by: mbrugman67

Thanks @henrygab ! Honestly, I ported the code all at once and just fixed things as I went along, so it’s all a bit of a mess.

Comment by: therealdreg

Thanks @henrygab ! Honestly, I ported the code all at once (+ugly hacks) and just fixed things as I went along, so it’s all a bit of a mess.

working, ulgy, hacked code >> not having working code

After all, solving problems to reach the objective is key. Until you ported the code, it wasn’t working for anyone. Now, it works for most, and is getting even better. Thus, it is you who deserve my thanks!

Comment by: henrygab

You can go ahead and merge it as far as I’m concerned @mbrugman67 @DangerousPrototypes

all tested!

Comment by: therealdreg