Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avrdude has EEPROM bug #235

Open
WestfW opened this issue Jul 24, 2018 · 11 comments
Open

avrdude has EEPROM bug #235

WestfW opened this issue Jul 24, 2018 · 11 comments
Assignees
Labels
Not-our-issue Turns out to be a bug in some other component. (compiler, make, etc) Permanent This issue shouldn't be closed, because it documents something "permanent" Type-Other

Comments

@WestfW
Copy link
Member

WestfW commented Jul 24, 2018

Optiboot is about to be tuned enough to include EEPROM support in a 512byte image.
That's swell, but it turns out that AVRDUDE is somewhat inconsistent WRT reading and writing EEPROM - some parts (ATmega328x, for example) use a word-based address in the STK_LOAD_ADDRESS command, and other parts (notably ATmega8) ) used a byte-based address.
This is documented here: https://savannah.nongnu.org/bugs/?48131

There's probably an avrdude.conf based patch, but the short-term issue is that an ATmega8 with optiboot will not interact properly with AVRDUDE. (It doesn't work with ArduinoISP, either!)

Documented here for the sake of completeness.

@WestfW WestfW added Type-Other Not-our-issue Turns out to be a bug in some other component. (compiler, make, etc) labels Jul 24, 2018
@WestfW WestfW self-assigned this Jul 24, 2018
@MCUdude
Copy link

MCUdude commented Aug 7, 2018

So, about getting EEPROM support in a 512B image; how can this be done? I just compared "my" repo to yours in terms of compiled size. Both are compiled with avr-gcc 5.4.0.

make atmega328 LED=B5 LED_START_FLASHES=2 UART=0 AVR_FREQ=20000000L BAUD_RATE=500000 BIGBOOT=1

"My optiboot_flash repo":

  avr-size atmega328/20000000L/optiboot_flash_atmega328_UART0_500000_20000000L.elf
   text	   data	    bss	    dec	    hex	filename
    560	      0	      0	    560	    230	atmega328/20000000L/optiboot_flash_atmega328_UART0_500000_20000000L.elf

Official Optiboot repo:

avr-size optiboot_atmega328.elf
   text	   data	    bss	    dec	    hex	filename
    570	    156	      0	    726	    2d6	optiboot_atmega328.elf

If i've understood it correctly the text field is the actual size of the image in bytes. How can this be reduced to 512 or less?

@MCUdude
Copy link

MCUdude commented Aug 7, 2018

ON TOPIC:
I'm no avrdude.conf guru, so maybe you know where the EEPROM related bug for ATmega8 (or other devices with byte-based addresses) is located? My Arduino cores includes a separate copy of avrdude.conf, so a patch should be easy to roll out to affected users if we can figure how we can fix the bug.

@WestfW
Copy link
Member Author

WestfW commented Oct 27, 2021

The trick to getting EEPROM support is that you don't get DOSPM support at the same time :-(
(tough decision! Sigh.)

 make atmega328 LED_START_FLASHES=0 NO_APP_SPM=1 SUPPORT_EEPROM=1 LED_START_ON=1
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_495) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

BAUD RATE CHECK: Desired: 115200, Real: 117647, UBRRL = 16, Difference=2.1%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=0      -DSUPPORT_EEPROM -DLED_START_ON=1 -DAPP_NOSPM=1         -c -o optiboot.o optiboot.c
optiboot.c:425:2: warning: #warning BAUD_RATE off by greater than 2% [-Wcpp]
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=0      -DSUPPORT_EEPROM -DLED_START_ON=1 -DAPP_NOSPM=1       -Wl,-Tlinkscript.ld -Wl,--relax -nostartfiles -o optiboot_atmega328.elf optiboot.o 
avr-size optiboot_atmega328.elf
   text    data     bss     dec     hex filename
    510       0       0     510     1fe optiboot_atmega328.elf
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex

@MCUdude
Copy link

MCUdude commented Oct 27, 2021

I favored so_spm because EEPROM upload is not currently supported in Arduino IDE, and you can do cool and useful things with do_spm.

I created a high-ish level Flash library to make the internal flash memory more accessible to the end-user:
https://github.com/MCUdude/MiniCore/tree/master/avr/libraries/Optiboot_flasher

@WestfW
Copy link
Member Author

WestfW commented Jul 18, 2022

See the conclusion at avrdudes/avrdude#967 (comment) and related discussion.
TLDR: a bug was introduced in AVRDUDE back in 2006, and since then other code (like optiboot and Arduino as ISP) has compensated, assuming that the buggy code was intentional.)

@WestfW WestfW added the Permanent This issue shouldn't be closed, because it documents something "permanent" label Jul 18, 2022
@mcuee
Copy link

mcuee commented Oct 15, 2022

For classic AVRs, this has been fixed in avrdude git main by the following PR.

It does introduce regression for optiboot_x and optoboot_dx. This will be fixed in the following PR.

@mcuee
Copy link

mcuee commented Oct 22, 2022

There may still be some issues with four chips (ATmega161 ATmega163 ATmega8515 ATmega8535) and there is a potential fix here.

@mcuee
Copy link

mcuee commented Dec 19, 2022

From avrdude side, this issue has been fixed in avrdude git main, which will lead to avrdude 7.1 release soon.

@mcuee
Copy link

mcuee commented Dec 20, 2022

From Optiboot side, #357 is a real issue related to EEPROM.

@mcuee
Copy link

mcuee commented Dec 20, 2022

urboot (which is indeed inspired by Optiboot) does achieve this goal within 512B.
https://github.com/stefanrueger/urboot

Tight code: most bootloaders fit into

  • 256 bytes albeit without EEPROM read/write support
  • 384 bytes with EEPROM read/write support
  • 512 bytes with dual-boot, EEPROM read/write support and Chip Erase capability

@mirh
Copy link

mirh commented May 14, 2023

Didn't the guy at #227 (most updated version here I think?) already handle EEPROM+SPM?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not-our-issue Turns out to be a bug in some other component. (compiler, make, etc) Permanent This issue shouldn't be closed, because it documents something "permanent" Type-Other
Projects
None yet
Development

No branches or pull requests

4 participants