Hello Tristan,

Tristan Williams writes:

> Is it possible to build the current AVR AmForth so that it can
> co-exist with a bootloader?
> There is a reference in the documentation to changes that would be
> required 
> http://amforth.sourceforge.net/TG/AVR8.html?highlight=bootloader
> and some older discussions in the mailing list 
> https://sourceforge.net/p/amforth/mailman/message/32235234/
> but nothing since. I was wondering whether this might be a way to use
> AmForth with the ATmega32u4 and USB.

Someone else asked me the same question more recently ... odd.

Well. As far as I understand (anything I wrote below might be
only partially correct or even outright wrong):

The function, which stores a new value in flash, must reside in
the NRWW section of the flash. At least on larger Atmega
controllers the size of this section can be changed.

section 27 Bootloader Support
Size can be 512, 1024, 2048 to 4096 words (word == 16 Bit,
iirc). The size is set with the BOOTSZ[01] fuses in HIGH Fuse

A bootloader needs to reside in NRWW. Then it can read Bytes
from /somewhere/ (e.g. serial connection) and write them to
flash outside the NRWW section.

Writing Flash outside of NRWW needs to account for erasing in
blocks, saving and rewriting blocks accordingly, unless writing
the new value involves changes from 1 to 0 only (for any
individual bit). This makes i! somewhat /interesting/.

Currently "i!" lives in the NRWW section together with a number
of "core" words, thus overwriting any bootloader that existed on
the board.

So to make AmForth (or any Forth) coexist with the bootloader,
there are at least these options:

1. Forth compiles to RAM only --- normally not what you want.

2. The bootloader living in NRWW exports its "write-to-flash"
function as an interface to any interested party outside the
bootloader. Most probably such an interface would use a call
frame and not the Forth data stack. I have not checked whether
there is such a bootloader, which offers this. From the point of
view of the bootloader: "you (the user) want to load an
application which is rewriting itself? Are you nuts?"

I had looked at this many years ago (arduino bootloader) and
decided that this was over my head.

3. You could of course write your own bootloader. I have met a
person who has done just that. He wrote a small machine monitor,
but I'm not aware that he did publish it.

Hope this helps,

> Tristan 

May the Forth be with you ...

Amforth-devel mailing list for http://amforth.sf.net/

Reply via email to