Bootloader requirements

Is there a reference for an Arduino bootloader?

If I wanted to write a bootloader for a new target (non-AVR) where would I get the requirements?

The Atmega328P datasheet has a sample bootloader code.
Does your non AVR processor datasheet have similar, or an application note?

Thanks for the reply.

I checked out the datasheet you reference. The code I found was an assembly example for writing a single page.

I have written three bootloaders for the AT90CAN128 and six for a family of TI Tiva chips. Knowing how to write a page is one thing, the envelope of handshaking between the bootloader and the service tool or Arduino IDE is a different thing.

I found another posting that says basically "set this setting in the IDE and watch the data stream, then figure it out." This will give me an idea of a successful download, but will not expose all the fault situations.

So I am looking for how the service tool and bootloader:

  • Agree on where the data is being flashed
  • How many bytes (I assume for AVR it is assumed 256.
  • Error conditions and the appropriate response
  • Which player erases the page about to be programmed, bootloader or service tool?

If there is no bootloader requirement doc, is there code for the Arduino Uno's bootloader available?
Or does choosing a target in the Arduino IDE drag in an overloaded "upload" function, such that each Arduino target can have a different method?

Is the bootloader only used for reflashing the app, or does is provide other functions? Such as memory dump, or I/O testing, or writing factory data to non-volatile memory?

I appreciate your time.

The bootloaders use the protocol defined by the upload.protocol parameter in boards.txt (the protocols to which they refer are baked into avrdude - or whatever tool is being used for uploading). Most of the Arduino bootloaders (all maybe?) use a variant on the STK500 protocol from Atmel.

I am only a user of the tools, so I can only partially answer:

  1. "Agree on where the data is being flashed" I believe this is defined in the .hex file to be loaded.
    For example, looking at the first few lines of the Optiboot .hex file for 328:

:10 7E0 00 11 24 84 B7 14 BE 81 FF F0 D0 85 E0 80 93 81 00F7

:107E100082E08093C00088E18093C10086E0809377

:107E2000C20080E18093C4008EE0C9D0259A86E02C

:107E300020E33CEF91E0309385002093840096BBD3
This would be read as something like:
10 says 16 bytes
7E0 is the start address
16 bytes of data follow
2 byte checksum ends the line

  1. Datasheet for 328 says 256 pages of 64 words (128 bytes), is that what you mean?
  2. See 28.8.1, 28.8.2, looks like a Chip Erase command is sent.

See the bootloaders folder in your IDE download, check boot.h and optiboot.c for example:

optiboot.c (21.8 KB)

boot.h (33.2 KB)

osenjw:
Is there a reference for an Arduino bootloader?

If I wanted to write a bootloader for a new target (non-AVR) where would I get the requirements?

Research the STK500-2 protocol, and the Motorola format, Search for OptiBoot, @WESTFw's GitHub is the current version.

Chuck.

I have been slowly adding documentation to the wiki associated with the Optiboot repository.

Optiboot (used by Uno) is an implementation of Atmel STK500v1 Communications protocol (Application Note AVR061)
Arduino MEGA uses STK500v2, and the native USB chips use something else again.

Given the latest IDE program structure, the only "requirement" is that bootloader is able to communicate with a host program to upload a binary, and that the host program run on Windows, Linux, and MacOS. Usually the host program is "avrdude", which only supports a couple dozen comm protocols, but various third party boards (teensy, for example) have used other programs. Even the binary format need not be fixed.