SOLVED mega2560 compiling stk500 bootloader on windows

I have compiled optiboot for the atmega328p after changing the watchdog timer to 8 seconds. I uploaded it and everything worked. I then compiled a version for the atmega2560 and burned the bootloader everything went okay but i cannot upload any sketches. i read that optiboot v8 is stk500v2 compatible and im using avrdude 6.3. do the fuses look right? any ideas whats wrong?

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:D8, L:FF)

i should have also said the programmer error messages are timeouts and sometimes sync errors. im trying to upload over usb. the arduino board is a atmega2560 promini v1.1

Juraj:
the baud rate is different
create your own Mega definition like this GitHub - jandrassy/my_boards: My Arduino boards custom variants. You can use it as starting point for your boards specialities.

im going to go a bit off topic here but now im trying to compile the stk500 bootloader but i keep getting this error

Compiling: stk500boot.c
avr-gcc -c -mmcu=atmega1280 -I. -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -mno-tablejump -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.lst  -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.o.d stk500boot.c -o stk500boot.o
stk500boot.c: In function 'PrintFromPROGMEM':
stk500boot.c:1309: warning: cast from pointer to integer of different size
stk500boot.c: In function 'DumpHex':
stk500boot.c:1526: warning: cast to pointer from integer of different size
stk500boot.c: In function 'EEPROMtest':
stk500boot.c:1570: warning: cast from pointer to integer of different size
stk500boot.c:1595: warning: cast from pointer to integer of different size
stk500boot.c: At top level:
stk500boot.c:2132: fatal error: opening dependency file .dep/stk500boot.o.d: No such file or directory
compilation terminated.
make: *** [stk500boot.o] Error 1

btw my ultimate goal is to increase the watchdog timer so i can have more time to send my hex's over my network through esplink.

i got past that part now im getting

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>make
      0 [main] sh 17876 sync_with_child: child 22884(0x1EC) died before initialization with status code 0xC0000142
    207 [main] sh 17876 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (GCC) 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.


Size before:
      0 [main] sh 20812 sync_with_child: child 6988(0x1EC) died before initialization with status code 0xC0000142
    167 [main] sh 20812 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
make: *** [sizebefore] Error 128

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>

i read that optiboot v8 is stk500v2 compatible

No, it's not. Optiboot uses STK500v1, and since it doesn't implement all of it, you need to use the "-carduino" variant (otherwise, avrdude will use a lot of "generic SPI command" commands to do things that have other ways to do them in STK500v1.

(It's not clear that STK500v1 and/or -carduino work across a network connection...)

stk500boot.c:2132: fatal error: opening dependency file .dep/stk500boot.o.d: No such file or directory

What are you using for your avr toolchain, make, and etc?

westfw:
(It's not clear that STK500v1 and/or -carduino work across a network connection...)What are you using for your avr toolchain, make, and etc?

I'm using WinAVR 4.3.3 and im trying to compile stk500boot.c from C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\stk500v2 when i type make this is my output

C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\stk500v2>make
      0 [main] sh 23360 sync_with_child: child 9032(0x1E8) died before initialization with status code 0xC0000142
    147 [main] sh 23360 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
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.


Size before:
      0 [main] sh 20020 sync_with_child: child 23816(0x1A0) died before initialization with status code 0xC0000142
    117 [main] sh 20020 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
make: *** [sizebefore] Error 128

C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\stk500v2>make
      0 [main] sh 19264 sync_with_child: child 24624(0x1E8) died before initialization with status code 0xC0000142
    136 [main] sh 19264 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
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.


Size before:
      0 [main] sh 20492 sync_with_child: child 24808(0x1E4) died before initialization with status code 0xC0000142
    146 [main] sh 20492 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
make: *** [sizebefore] Error 128

C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\stk500v2>

all i want to do is increase the watchdog time since iv'e abandoned hope with optiboot on the mega2560. Before iv'e even begin to modify stk500boot.c i am going to try to successfully compile it in my windows 10 environment. I'm not sure what the error message status code means either what am i doing wrong?

how can i compile the stk500v2 bootloader on windows? i really need some hints please

The latest WinAVR is from 2010, back when WXP was all the rage.
You probably need something newer, like the cli toolchain from microchip GCC Compilers for AVR® and ARM® | Microchip Technology
Unfortunately, these tend to be just the compiler, and don't have the various utilities (make, bash, etc) that were included in WinAVR. :frowning:
(OTOH, the stk500v2 code is from the same timeframe as WinAVR.)

Also, stk500v2 doesn't do it's timeout using the WDT...

westfw:
The latest WinAVR is from 2010, back when WXP was all the rage.
You probably need something newer, like the cli toolchain from microchip GCC Compilers for AVR® and ARM® | Microchip Technology
Unfortunately, these tend to be just the compiler, and don't have the various utilities (make, bash, etc) that were included in WinAVR. :frowning:
(OTOH, the stk500v2 code is from the same timeframe as WinAVR.)

Also, stk500v2 doesn't do it's timeout using the WDT...

funny you mention that i just read you post here and i did exactly what you instructed to do. im going to download the cli toolchain from atmel winavr is using a pretty old version of avr gcc. does the stk500v2 folder included with arduino ide include all the files required to compile the stk500v2 bootloader?

avr toolchain downloaded and my make version says GNU Make 3.81. will this work? how to i point it to the new toolchain?

i reaplaced the files in the winavr folder with the ones in the toolchain i downloaded now when i type make mega2560 i get

C:\Users\User\Desktop\arduino-1.8.9\hardware\arduino\avr\bootloaders\stk500v2>make mega2560
      0 [main] sh 23164 sync_with_child: child 25420(0x1EC) died before initialization with status code 0xC0000142
    147 [main] sh 23164 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 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.


Compiling: stk500boot.c
avr-gcc -c -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.lst  -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.o.d stk500boot.c -o stk500boot.o
stk500boot.c:2119:1: fatal error: opening dependency file .dep/stk500boot.o.d: No such file or directory
 }
 ^
compilation terminated.
make: *** [stk500boot.o] Error 1

C:\Users\User\Desktop\arduino-1.8.9\hardware\arduino\avr\bootloaders\stk500v2>

the directory infact does not exist. ive yet to find it anywhere? and it looks like the compiler reports a toolchain version higher than version 3.5 i downloaded.

how can i compile the stk500v2 bootloader on windows?

Try “make mega2560”, with your current setup…
You can install Atmel Studio 7, open an “AS7 Command Prompt” window, and use “make mega2560”
(but I also got weird errors with just “make”)

(You really OUGHT not to need all of AS7 to do this. But it will take me a while to see what’s needed on an otherwise “virgin” windows 10…)

Um:

C:\Users\User\Desktop\arduino-1.8.9\hardware\arduino\avr\bootloaders\stk500v2>

try making a copy outside of the Arduino install, where you’re certain that you have all of the needed file and directory write permissions…

C:\Users\billw\Documents\stk500v2>dir
Volume in drive C has no label.
Volume Serial Number is 76D1-5C84

Directory of C:\Users\billw\Documents\stk500v2

06/05/2019 03:07 PM .
06/05/2019 03:07 PM …
06/05/2019 02:59 PM .dep
10/16/2017 04:20 AM 27,394 avrinterruptnames.h
10/16/2017 04:20 AM 7,044 avr_cpunames.h
10/16/2017 04:20 AM 4,591 command.h
10/16/2017 04:20 AM 15,424 License.txt
10/16/2017 04:20 AM 17,482 Makefile
10/16/2017 04:20 AM 53,331 stk500boot.c
10/16/2017 04:20 AM 83 stk500boot.ppg
06/05/2019 02:59 PM 4,652 stk500boot.sym
10/16/2017 04:20 AM 190 STK500V2.pnproj
10/16/2017 04:20 AM 61 STK500V2.pnps
10 File(s) 130,252 bytes
3 Dir(s) 14,260,985,856 bytes free

C:\Users\billw\Documents\stk500v2>make mega2560

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_1750) 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.

Compiling: stk500boot.c
avr-gcc -c -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.lst -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.o.d stk500boot.c -o stk500boot.o

Linking: stk500boot.elf
avr-gcc -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.o -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.elf.d stk500boot.o --output stk500boot.elf -Wl,-Map=stk500boot.map,–cref -lm -Wl,–section-start=.text=3E000

Creating load file for Flash: stk500boot.hex
avr-objcopy -O ihex -R .eeprom stk500boot.elf stk500boot.hex

Creating load file for EEPROM: stk500boot.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom=“alloc,load”
–change-section-lma .eeprom=0 -O ihex stk500boot.elf stk500boot.eep
C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe: --change-section-lma .eeprom=0x00000000 never used

Creating Extended Listing: stk500boot.lss
avr-objdump -h -S stk500boot.elf > stk500boot.lss

Creating Symbol Table: stk500boot.sym
avr-nm -n stk500boot.elf > stk500boot.sym

Size after:
AVR Memory Usage

Device: atmega2560

Program: 5928 bytes (2.3% Full)
(.text + .data + .bootloader)

Data: 18 bytes (0.2% Full)
(.data + .bss + .noinit)

-------- end --------

mv stk500boot.hex stk500boot_v2_mega2560.hex

i have done everything you just said including atmel studio 7 install. im compiling from my desktop and permissions not an issue. the output is in my previous post how ever i do not have the .dep directory like you do?

i found a .dep directory in another directory that i might have actually put there myself i found the stk500boot.o.d file in someone elses repository. when i run make mega2560 with the .dep directory of unknown origin avr-objcopy.exe pops up with an application error saying unable to start correctly error 0xc0000142. i get a similar error when i type make clean too? here is a link to the stk500boot.o.d file i copied

it appears even with the error im still getting a hex file it is complaining about the .lss and .eep file

C:\Users\User\Desktop\arduino-1.8.9\hardware\arduino\avr\bootloaders\stk500v2\New folder>make mega2560
      0 [main] sh 24996 sync_with_child: child 18956(0x1E8) died before initialization with status code 0xC0000142
    133 [main] sh 24996 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 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.


Compiling: stk500boot.c
avr-gcc -c -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.lst  -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.o.d stk500boot.c -o stk500boot.o

Linking: stk500boot.elf
avr-gcc -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.o  -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.elf.d stk500boot.o --output stk500boot.elf -Wl,-Map=stk500boot.map,--cref    -lm -Wl,--section-start=.text=3E000

Creating load file for Flash: stk500boot.hex
avr-objcopy -O ihex -R .eeprom stk500boot.elf stk500boot.hex

Creating load file for EEPROM: stk500boot.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
        --change-section-lma .eeprom=0 -O ihex stk500boot.elf stk500boot.eep
make: [stk500boot.eep] Error -1073741502 (ignored)

Creating Extended Listing: stk500boot.lss
avr-objdump -h -S stk500boot.elf > stk500boot.lss
      0 [main] sh 7540 sync_with_child: child 10024(0x1E4) died before initialization with status code 0xC0000142
    118 [main] sh 7540 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
make: *** [stk500boot.lss] Error 128

i could try the output file i guess. also after i run compile it wont let me run it again the output in the console is

C:\Users\User\Desktop\arduino-1.8.9\hardware\arduino\avr\bootloaders\stk500v2\New folder>make mega2560
      0 [main] sh 5988 sync_with_child: child 27340(0x1E8) died before initialization with status code 0xC0000142
    160 [main] sh 5988 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 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.


Size before:
      0 [main] sh 23852 sync_with_child: child 19576(0x1E4) died before initialization with status code 0xC0000142
    160 [main] sh 23852 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
make: *** [sizebefore] Error 128

im compiling from my desktop and permissions not an issue.

Are you sure? There are permission issues beyond network shares/etc. (I got a very clear “no write permission” message when I first tried to compile within the “installed” arduino dir.)

Sorry; my windows10VM is now “updating” to the latest version. 1% done. Sigh.
I thought that .dep would be created as needed (one of the reasons that permissions are important.)
(that’s how it works on my Mac…)

WWHackintosh<10019> rm -Rf .dep/
WWHackintosh<10020> 
WWHackintosh<10020> ls -a
./                      STK500V2.pnproj         command.h
../                     STK500V2.pnps           stk500boot.c
License.txt             avr_cpunames.h          stk500boot.ppg
Makefile                avrinterruptnames.h
WWHackintosh<10021> make

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_495) 5.4.0

it looks like the compiler reports a toolchain version higher than version 3.5

The "Atmel Toolchain version" (3.6.1 is what I have on the Mac) does not match the "gnu compiler version" (5.4.0 or later) (sigh.)

westfw:
Are you sure? There are permission issues beyond network shares/etc. (I got a very clear “no write permission” message when I first tried to compile within the “installed” arduino dir.)

Sorry; my windows10VM is now “updating” to the latest version. 1% done. Sigh.
I thought that .dep would be created as needed (one of the reasons that permissions are important.)
(that’s how it works on my Mac…)

WWHackintosh<10019> rm -Rf .dep/

WWHackintosh<10020>
WWHackintosh<10020> ls -a
./                      STK500V2.pnproj        command.h
…/                    STK500V2.pnps          stk500boot.c
License.txt            avr_cpunames.h          stk500boot.ppg
Makefile                avrinterruptnames.h
WWHackintosh<10021> make

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.1_495) 5.4.0

atleast i dont think it is. runing cmd as admin dont output any different result remember optiboot giving me a similar error in the end it only outputted the .hex file. your compiler creates the .dep directory when you compile? what about the errors from objcopy. maybe it a permission error when objcopy is located i will check

the solution i found on thispage worked. now the dep folder is created automatically and i can compile more than once. make clean and objcopy is working too.

heres the output from the successful attempt,

C:\Users\User\Desktop\arduino-1.8.9\hardware\arduino\avr\bootloaders\stk500v2\New folder (2)\New folder (2)\New folder (2)\New folder>make mega2560

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.6.2_1759) 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.


Compiling: stk500boot.c
avr-gcc -c -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.lst  -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.o.d stk500boot.c -o stk500boot.o

Linking: stk500boot.elf
avr-gcc -mmcu=atmega2560 -I. -gdwarf-2 -DF_CPU=16000000UL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-jump-tables -Wall -Wstrict-prototypes -Wa,-adhlns=stk500boot.o  -std=gnu99 -D_MEGA_BOARD_ -MD -MP -MF .dep/stk500boot.elf.d stk500boot.o --output stk500boot.elf -Wl,-Map=stk500boot.map,--cref    -lm -Wl,--section-start=.text=3E000

Creating load file for Flash: stk500boot.hex
avr-objcopy -O ihex -R .eeprom stk500boot.elf stk500boot.hex

Creating load file for EEPROM: stk500boot.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
        --change-section-lma .eeprom=0 -O ihex stk500boot.elf stk500boot.eep
c:\WinAVR-20100110\bin\avr-objcopy.exe: --change-section-lma .eeprom=0x00000000 never used

Creating Extended Listing: stk500boot.lss
avr-objdump -h -S stk500boot.elf > stk500boot.lss

Creating Symbol Table: stk500boot.sym
avr-nm -n stk500boot.elf > stk500boot.sym

Size after:
AVR Memory Usage
----------------
Device: atmega2560

Program:    5928 bytes (2.3% Full)
(.text + .data + .bootloader)

Data:         18 bytes (0.2% Full)
(.data + .bss + .noinit)



-------- end --------

mv stk500boot.hex stk500boot_v2_mega2560.hex

C:\Users\User\Desktop\arduino-1.8.9\hardware\arduino\avr\bootloaders\stk500v2\New folder (2)\New folder (2)\New folder (2)\New folder>

is this where i want to change the delay before booting application? aka delay startup

void delay_ms(unsigned int timedelay)
{
	unsigned int i;
	for (i=0;i<timedelay;i++)
	{
		_delay_ms(0.5);
	}
}