Minimizing bootloader time

I am using an Arduino Mega, and wish to make the bootloader-caused initial startup delay to be as little as possible, at most 0.5 seconds = 500 milliseconds. That is, so that my sketch runs as soon as possible (whether when first powered on, or when reset).

Could someone get me started on how I would go about approaching this, assuming this is doable?

Get an AVR ISP, such as Atmel AVR ISP MKii
Then use File:Upload Using Programmer to down your sketch with no bootloader. Sketch starts immediately after reset.

NickGammon has great web page on using arduino as a programmer also.

But I really prefer to maintain the bootloader so that I can upload sketches via USB.

Is there some modification of the delay time variable that can be done to the bootloader itself?

Need someone knowlegdable in making the bootloader to answer that.

But really, when you come up with the means to install a revised bootloader, then you have the means to use File:Upload Using Programmer, so why not use it?

giantsfan3:
But I really prefer to maintain the bootloader so that I can upload sketches via USB.

You can easily put the bootloader back again if you need to...

But honestly, once you start using an ISP you'll wonder why anybody bothers with serial. It's difficult to go back.

giantsfan3:
Is there some modification of the delay time variable that can be done to the bootloader itself?

It has to wait in case some serial data arrives from the IDE, so...not really.

I'm sure there is - the current delay is in there, yes? So likely it can be shortened.
Someone like westfw has the knowledge of what goes into it.

CrossRoads:
I'm sure there is - the current delay is in there, yes? So likely it can be shortened.
Someone like westfw has the knowledge of what goes into it.

I guess 0.5 seconds is possible, yes.

(I concur with the ease of the ISP-based upload, and have used it in the past, but I'm much more curious how the bootloader itself can be modified to solve the problem. And if I could set a 0.5-second wait time, that should be enough for waiting for the serial data, no?)

I just took a look at the bootloader source ( Google Code Archive - Long-term storage for Google Code Project Hosting. ). But it comments out "MAX_TIME_COUNT" and states this:

/* set the waiting time for the bootloader */
/* get this from the Makefile instead */
/* #define MAX_TIME_COUNT (F_CPU>>4) */

The Makefile, in turn, states this:

mega: MCU_TARGET = atmega1280
mega: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' -DBAUD_RATE=57600

I'm unsure how this corresponds to the wait-time exactly, but am investigating...

Make sure you look at the correct bootloader. Stk500v2 for the arduino mega...