Optiboot compiling

Hello, good afternoon.

I'm trying to make use of the optiboot timeout, 8 seconds, and I can't identify the changes that need to be made to compile the new bootloader.

I am working with an arduino nano and I want to perform OTA with an HC 05, I manage to generate the DTR signal but I estimate that the waiting time for the data of the new program is very short.

Can someone give me a hand, thank you very much in advance!

Please study the documentation provided by the Optiboot project:

If you still have questions or problems after you compile by following those, come back with specific questions and detailed information about what you tried and what happened when you tried it, the forum members will help you out.

1 Like

With current optiboot source, use:
make atmega328 TIMEOUT=8

Edit: I've updated the "Compiling Optiboot" instructions at The Optiboot Wiki
(previously, it didn't mention "TIMEOUT" :frowning: )

2 Likes

Hello, your comments have been very helpful, I have made some progress and learned, but I have the following error when compiling, I can't find information on the web. Can you give me a hand please.

avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 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=3 -c -o optiboot.o optiboot.c
optiboot.c:429:2: warning: #warning BAUD_RATE off by greater than 2%
optiboot.c:498: warning: 'leaf' attribute directive ignored
optiboot.c:499: warning: 'leaf' attribute directive ignored
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L -DBAUD_RATE=115200 -DLED_START_FLASHES=3 -Wl,-Tlink_optiboot.ld -Wl,--relax -nostartfiles -o optiboot_atmega328.elf optiboot.o
link_optiboot.ld:31: nonconstant expression for origin
make: *** [optiboot_atmega328.elf] Error 1
rm optiboot.o

You need a newer avr-gcc than WinAVR (which is over 12y old.)
The version packaged with Arduino is fine. You'll still need "Make" from winAVR or a separate download, though :frowning:

(ah, the things one had to do before Arduino!)

1 Like

Hello, thank you very much everyone, it seems that thanks to your help I have managed to advance a little, I have a different error.

make atmega328 LED_START_FLASHES=0 TIMEOUT=8
avr-gcc (GCC) 11.1.0
Copyright (C) 2021 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 -DWDTTIME=8 -Wl,-Tlink_optiboot.ld -Wl,--relax -nostartfiles -o optiboot_atmega328.elf optiboot.o
c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: optiboot_atmega328.elf section .text' will not fit in region text'
c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: section .version LMA [0000000000007ffe,0000000000007fff] overlaps section .text LMA [0000000000007e00,0000000000008001]
c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: region text' overflowed by 0 bytes c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/avr5\libgcc.a(_copy_data.o): in function __do_copy_data':
/root/gcc-11.1.0/obj-avr/avr/avr5/libgcc/../../../../libgcc/config/avr/lib1funcs.S:2405: undefined reference to __data_end' c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: /root/gcc-11.1.0/obj-avr/avr/avr5/libgcc/../../../../libgcc/config/avr/lib1funcs.S:2406: undefined reference to __data_start'
c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: /root/gcc-11.1.0/obj-avr/avr/avr5/libgcc/../../../../libgcc/config/avr/lib1funcs.S:2407: undefined reference to __data_start' c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: /root/gcc-11.1.0/obj-avr/avr/avr5/libgcc/../../../../libgcc/config/avr/lib1funcs.S:2408: undefined reference to __data_load_start'
c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: /root/gcc-11.1.0/obj-avr/avr/avr5/libgcc/../../../../libgcc/config/avr/lib1funcs.S:2409: undefined reference to __data_load_start' c:/avr-gcc/bin/../lib/gcc/avr/11.1.0/../../../../avr/bin/ld.exe: /root/gcc-11.1.0/obj-avr/avr/avr5/libgcc/../../../../libgcc/config/avr/lib1funcs.S:2420: undefined reference to __data_end'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:694: optiboot_atmega328.elf] Error 1

Hello, thank you very much everyone, it seems that thanks to your help I have managed to advance a little, I have a different error.

I entered Makefile and found this, it doesn't help me at all, since I don't understand it.

I appreciate any kind of help to solve this new problem, thank you very much!

Sigh. Not THAT new!

WinAVR is v4.3.3, the latest "toolchain" from Microchip is v5.4.0, and Arduino ships with 7.3.0

section .text' will not fit in region text

Part of what makes Optiboot maintenance so exciting is that since it's a dozen or so instructions from "not fitting in 512 bytes", it's subject to "minor" changes in the compiler causing it to get too big. One has to go and look for new optimization settings, or minor re-arrangements of code, to try to fix things.

There were "major" changes in gcc between v10 and v11, almost resulting in the loss of avr support entirely. :frowning:
And I haven't looked at versions beyond v7 at all.

in function __do_copy_data': ... undefined reference to `__data_start'

That's particularly troubling, since using "-nostartfiles" is supposed to cause __do_copy_data/etc to be omitted. Sigh.
I'll have to take a look...

1 Like

Well. THIS is "interesting."
I used the windows avr-gcc 11.1 from AVR-GCC 12.1.0 for Windows 32 and 64 bit | Zak’s Electronics Blog ~*

>make atmega328 LED_START_FLASHES=0 TIMEOUT=8
avr-gcc (GCC) 11.1.0
   :
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=0           -DWDTTIME=8      -c -o optiboot.o optiboot.c
optiboot.c:425:2: warning: #warning BAUD_RATE off by greater than 2% [-Wcpp]
  425 | #warning BAUD_RATE off by greater than 2%
      |  ^~~~~~~
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L  -DBAUD_RATE=115200 -DLED_START_FLASHES=0           -DWDTTIME=8    -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe -Wl,--relax -nostartfiles -o optiboot_atmega328.elf optiboot.o
avr-size optiboot_atmega328.elf
   text    data     bss     dec     hex filename
    448       0       0     448     1c0 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
avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
rm optiboot.o

What exactly was your build environment and where did you get your 11.1 avr-gcc?

I wouldn't be the first time that some linux package manager distributed an "avr-gcc" that wasn't working. More investigation needed!

Hello westfw

I downloaded it from the same page as you! It's weird, I'm going to investigate what's going on.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.