[En-Nut-Discussion] Boot Loader

Ben Hoyt benhoyt at gmail.com
Mon Oct 9 22:45:41 CEST 2006


Hi Tim and Dave,

I've written a couple of bootloaders for the AT91SAM7 now, not ethernet
ones, but I'm sure there's overlap.

To answer Dave's questions:

1) No, you can't access or run from flash while writing it. Been there,
tried that. :-) so your EfcCmd routine must run from RAM (as in NutOS's
At91EfcCmd() -- it's a RAMFUNC). You must also disable interrupts, or an
interrupt may take over and try to execute from flash again -- hence the
Enter/Exit Critical in At91EfcCmd().

2) There's no separate boot page(s) on the SAM7. You have to reserve your
own and keep track of them yourselves. I'm using the SAM7S256 (I'm guessing
the SAM7X256 is the same). It has 256 KB total flash, and I've allocated the
low 16 KB for my bootloader. The lockable sections are also 16 KB in size,
so I always keep that first 16 KB sector locked. I'm sure you can make a
smaller bootloader than this -- my first DataFlash bootloader was something
like 1 KB.

A bootloader obviously needs to be able to pull in the new code from
*somewhere*. You can do this from ethernet/TFTP, but it's more complicated
that way, and you don't have the security of knowing there's a complete
working code image at all times. So I'm a fan of an external DataFlash chip
-- it's simpler, and it seems to me safer. Your application code can pull in
the a new code image from the air or via ethernet or whatever, load it into
the DataFlash, verify the image, then reboot into the bootloader. The
bootloader CRCs the external DataFlash image, if it's okay, sucks it into
the SAM7's internal flash, and you're away.

If something goes wrong during the download or the update, you always have a
valid code image either in the internet or external flash. You can even keep
a redundant copy of code in DataFlash at all times, and CRC the internal
code each reboot, pulling in the external one if it doesn't check out.

That's my two cents worth.

Cheers,
Ben.

On 10/10/06, Dave Warren <dwarren at luescher.com> wrote:
>
> Hi Tim,
>
> I am using the SAM7X256 also. You are right a ethernet bootloader would be
> cool.
>
> I have written a CAN bootloader in the past for the AVR micro (not using
> ethernut). What I think is important is that the bootloader itself can not
> be destroyed, that way you can aways use the bootloader to restore a node
> even after a 'bad' download. The bootloader would have to be a ethernut
> that
> was linked and run at a different address. It should run first at power
> up,
> normally it should switch to the application, another ethernut linked to a
> different address in Flash. However if you want to download then use it
> Flash the application instead.
>
> Questions:-
> 1. Can you access a different Flash page while erasing or programming
> another page? If not the bootloader has to run from RAM, otherwise it
> locks
> up when the ARM tries to read the next program instruction.
>
> 2. Is there a seperate boot page in the Flash ?(Like AVR micros)
>
> I don't know so much about the ARM or ethernut but would be willing to
> help.
>
> regards
>
> Dave Warren
>

-- 
Ben Hoyt
Mobile: +64 21 331 841
http://www.benhoyt.com/



More information about the En-Nut-Discussion mailing list