What does the bootloader boot?

I'm confused. I know what a boot loader does in the context of disk systems. (Loads - perhaps in stages - the operating system from a hard disk). But what does it load when we talk about a microcontroller?
Does it load a program from EEPROM and start executing it?
Does it download programs via a USB link?
Does it participate in in-system debugging?

I have done much reading; I understand about burning a boot loader into a processor, but I can also avoid this and use all the RAM. This is puzzling unless I understand what it loads.

Lou.

When you reset the arduino, it loads some code (the bootloader).

In the case of Arduino, it checks the serial port to see if there is anything trying to contact it. If not, it jumps to a different position in the program memory and runs whatever code was programmed into the flash last.
If the ide contacts the bootloader when it is waiting, then it enters programming mode. This allows the IDE to download your compiled sketch into the flash through USB without the need for a seperate programmer.
The bootloader doesn't take 'RAM' away from your sketch as once it has finished running, it exits and loads your sketch. However it does require some of the program memory (Flash) to store itself. In the case of arduino this is about 2kB, which is space your program cant use, limiting the maximum compiled size.

[quote author=Tom Carpenter link=topic=116316.msg875530#msg875530 date=1343501951]
When you reset the arduino, it loads some code (the bootloader).

In the case of Arduino, it checks the serial port to see if there is anything trying to contact it. If not, it jumps to a different position in the program memory and runs whatever code was programmed into the flash last.
If the ide contacts the bootloader when it is waiting, then it enters programming mode. This allows the IDE to download your compiled sketch into the flash through USB without the need for a seperate programmer.
....
[/quote] Hmmm, OK, but: with a program loaded in flash memory, would a reset not start the program without needing a bootloader?

I assume an ISP device would download the program from the IDE into the flash memory as well? Using such a device appears to be incovenient from what I've read.

would a reset not start the program without needing a bootloader?

Of couse it would. The idea is that the bootloader is there when you are ready to change the flash code during product development.
You just talk to the Arduino board through the USB connector and download a new flash program. Since you are connected to the Arduino, you have opportunity to send debug messages back to the 'IDE'.

They came up with a very small boot loader they call Omniboot. I think that it is less than 1k bytes, maybe smaller.
That doesn't take away a lot of your flash space, unless you are using a very small micro like a Tiny85.

I assume an ISP device would download the program from the IDE into the flash memory as well?

Yes, I have heard that you can use an ISP programmer and download code to the Arduino from the IDE. It probably is incinvenient, mostly because there is no way to talk back to the IDE through such a device. Otherwise, it programs the part just as well asn anything else.

I use an ISP device to program my production versions of the products. There is no need for a boot loader there.
An ISP device is actually not inconvenient at all in this context. It has its place.

So, the bootloader is very convenient for making program changes during a development period and the ISP programmer is best for mass production. The ISP programmer that I use is actually an Arduino Mega1280. It takes care of all of the necessary changes including setting the fuse bits, writing flash and EEProm memory and then locking the part so that no further changes can be made without erasing the entire chip. Works great.

Checkers1811:
Since you are connected to the Arduino, you have opportunity to send debug messages back to the ‘IDE’.

That’s a key point: No bootloader means no debugging via the IDE?

Checkers1811:
So, the bootloader is very convenient for making program changes during a development period and the ISP programmer is best for mass production. The ISP programmer that I use is actually an Arduino Mega1280. It takes care of all of the necessary changes including setting the fuse bits, writing flash and EEProm memory and then locking the part so that no further changes can be made without erasing the entire chip. Works great.

OK. That’s a good answer. Thanks very much.

louarnold:
That’s a key point: No bootloader means no debugging via the IDE?

You can debug without the bootloader as well. The key point of the bootloader here is to remove the need for a seperate programmer, the bootloader is there to do any programming if any is needed.

When you reset the board, if there was no bootloader, it would start your program directly. It sort of looks like this:

No bootloader:

<0x0000> startProgram

<0xwhatever> endOfProgram - stop.


<0x3FFF> endOfFlash

With bootloader:

<0x0000> jump to 0x37FF (The Bootloader)
<0x0002> startProgram


<0xwhatever> endOfProgram - stop.

<0x37FF> startOfBootloader

<0xWhatever> endOfBootloader - jump to <0x0002>

<0x3FFF> endOfFlash

That’s pretty much how it works. The code inside the bootloader can be anything you want (as long as it is small enough).

That makes sense! Thanks again. The debugging part is of interest to me, so I’ll do some research before I start another thread.

With the bootloader you can use the Arduino IDE and change the program many times without having to use any other hardware other than the Arduino and a USB cable. If you were programming without the bootloader you would need an ISP programmer which has some cost, and extra hardware to connect serially to the chip being programmed to do debugging. In most cases the bootloader is small enough, and the sketch is small enough that you never notice the small amount of flash used.

A microcontroller-type "bootloader" usually refers to a program that runs in the on-chip memory, that can load additional programs/data into the on-chip memory using some arbitrary (user-programmable) communications path, instead of whatever (usually complicated) programming protocol and interface is used to program the chip memory.

In the case of Arduino, the (main) bootloader communicates over a serial interface (COM port) (which is usually connected via a separate USB/Serial converter chip), and programs the flash program memory on the chip. So essentially it allows you to load programs into the flash via a USB connection, rather than requiring a special-purpose AVR programmer.

Some bootloader remain active in some role (a sort of baby operating system or library) even after they have performed their "loading" function, but the Arduino bootloader completely removes itself from the picture once it starts the user sketch. Aside from the memory used, a user sketch should never even be aware that a bootloader is present.

Debugging via the IDE is generally just Serial.print statements you put in your code. You can transmit to the board and receive messages back using the IDE Serial Monitor.
That works whether you have a bootloader or not - it only depends on what you have in your sketch.

this looks like the official answer to your questions ...

Checkers1811:
this looks like the official answer to your questions ...

http://www.arduino.cc/en/Hacking/MiniBootloader

I read that article a few days ago. It doesn't answer the questions that I asked. But thanks for trying, anyway. There are good answers from Checkers1811, Posted on: July 28, 2012, 03:36:14 PM in this thread.