# Forum: ARM programming with GCC/GNU tools AT91SAM7S: bootloader

 Author: Roman Mashak (romez777) Posted on: 2008-03-03 12:14

Rate this post
 0 ▲ useful ▼ not useful
Hello,

I have a few queries on bootlloader for AT91SAM7x controllers. Now I'm
reading corresponding documents from
http://www.atmel.com/dyn/products/app_notes.asp?fa...

What I understand: memory is split, bootloader is put into the very
beginning of flash area, followed by the firmware's working copy (which
is right above the bootloader) and a buffer area, where the code is
first downloaded to, verified and recopied to the first region if valid.

So, every time the MCU resets, first instruction to execute will be
bootloader's instruction. Am I right?

1) What I can't understand so far is the way my firmware (which is
supposed to be placed right after bootloader) should be compiled. Does
it have to be linked with C-startup code?
2) What addresses has my firmware be loaded at?
3) Can I simply leave my firmware unmodified (just change loading
addresses), get bootloader burnt in flash and enjoy or I need
significant changes in my firmware too?

Thanks in advance for helping me to clarify my doubts.

 Author: Martin Thomas (mthomas) (Moderator) Posted on: 2008-03-03 22:43

Rate this post
 0 ▲ useful ▼ not useful
Roman Mashak wrote:
> Hello,
>
> I have a few queries on bootlloader for AT91SAM7x controllers. Now I'm
> reading corresponding documents from
>
http://www.atmel.com/dyn/products/app_notes.asp?fa...
>
> What I understand: memory is split, bootloader is put into the very
> beginning of flash area, followed by the firmware's working copy (which
> is right above the bootloader) and a buffer area, where the code is
> first downloaded to, verified and recopied to the first region if valid.

I expect you are asking about a "secondary" bootloader not the "SAM-BA"
preinstalled in the hardware.

> So, every time the MCU resets, first instruction to execute will be
> bootloader's instruction. Am I right?
If the bootloader is located at 0x0 which is usual, yes. Well, the first
"user defined" instruction. (But AFIAK the SAM7X offers settings to
start from a different address - not sure, have not used SAM7X yet.)

> 1) What I can't understand so far is the way my firmware (which is
> supposed to be placed right after bootloader) should be compiled. Does
> it have to be linked with C-startup code?
If the bootloader does simply jump to the application's start-address:
Yes a startup-code for the application is needed, esp. to copy
initialized data into RAM and clear bss. Usually also to set the
interrupt-vectors (see remapping in user's manual).

> 2) What addresses has my firmware be loaded at?
This should be a "define" or constant in the bootloader's source-code.

> 3) Can I simply leave my firmware unmodified (just change loading
> addresses), get bootloader burnt in flash and enjoy
For very simple user-code without interrupts this should be enough, yes.

> or I need
> significant changes in my firmware too?
If you are going to use interrupts you have to "remap" the
interrupt-vectors of your user-application so they get used. See user's
manual and Atmels application-notes on startup.

> Thanks in advance for helping me to clarify my doubts.
I hope this clarifies at least a little bit.

 Author: Roman Mashak (romez777) Posted on: 2008-03-05 14:56

Rate this post
 0 ▲ useful ▼ not useful
Martin Thomas wrote:
>
> I expect you are asking about a "secondary" bootloader not the "SAM-BA"
> preinstalled in the hardware.

Correct.

>> 1) What I can't understand so far is the way my firmware (which is
>> supposed to be placed right after bootloader) should be compiled. Does
>> it have to be linked with C-startup code?
> If the bootloader does simply jump to the application's start-address:
> Yes a startup-code for the application is needed, esp. to copy
> initialized data into RAM and clear bss. Usually also to set the
> interrupt-vectors (see remapping in user's manual).

I need bootloader to upgrade my firmware, located right after
"secondary" bootloader. This is what the Atmel's docs are about (I
mentioned them in the first post).

Those documents are accompanied with IAR reference code. Are you aware
of GCC port for this? I googled, but without luck yet.

Thanks. Keep on studying.

 Author: Martin Thomas (mthomas) (Moderator) Posted on: 2008-03-05 16:15

Rate this post
 0 ▲ useful ▼ not useful
>Are you aware of GCC port for this?
No.

 Author: Jonathan Dumaresq (dumarjo) Posted on: 2008-03-05 19:24

Rate this post
 0 ▲ useful ▼ not useful
Roman Mashak wrote:
> Martin Thomas wrote:
>>
>> I expect you are asking about a "secondary" bootloader not the "SAM-BA"
>> preinstalled in the hardware.
>
> Correct.
>
>>> 1) What I can't understand so far is the way my firmware (which is
>>> supposed to be placed right after bootloader) should be compiled. Does
>>> it have to be linked with C-startup code?
>> If the bootloader does simply jump to the application's start-address:
>> Yes a startup-code for the application is needed, esp. to copy
>> initialized data into RAM and clear bss. Usually also to set the
>> interrupt-vectors (see remapping in user's manual).
>
> I need bootloader to upgrade my firmware, located right after
> "secondary" bootloader. This is what the Atmel's docs are about (I
> mentioned them in the first post).
>
> Those documents are accompanied with IAR reference code. Are you aware
> of GCC port for this? I googled, but without luck yet.
>
> Thanks. Keep on studying.

If you look on the at91.com you should find something like that. I think
we start from a example from there to build our bootloader for the
sam7s.

if you can't find anything there, I will post the original code as
reference.

Jonathan

 Author: Roman Mashak (romez777) Posted on: 2008-03-06 14:15

Rate this post
 0 ▲ useful ▼ not useful
Jonathan Dumaresq wrote:
> If you look on the at91.com you should find something like that. I think
> we start from a example from there to build our bootloader for the
> sam7s.
>
> if you can't find anything there, I will post the original code as
> reference.
>

Hello,

I was seeking for it on at91.com, but without luck so far. Will
appreciate very much if you post the sources.

Thanks.

 Author: Jonathan Dumaresq (dumarjo) Posted on: 2008-03-07 15:31

Rate this post
 0 ▲ useful ▼ not useful
Roman Mashak wrote:
> Jonathan Dumaresq wrote:
>> If you look on the at91.com you should find something like that. I think
>> we start from a example from there to build our bootloader for the
>> sam7s.
>>
>> if you can't find anything there, I will post the original code as
>> reference.
>>
>
> Hello,
>
> I was seeking for it on at91.com, but without luck so far. Will
> appreciate very much if you post the sources.
>
> Thanks.
Hi,

I have told youo this is not my work. So I don't any credit on this.

But i'm pretty sure that will help you to understand how to do it.

It is very long time i have not played with this source code. So i'm not
sure it's working correctly. But the principle is the same.

The attachement is to large for the forum. I put it on my webserver a
coupple of days

www.cimeq.qc.ca/AT91SAM7SERIALBOOT_s256.zip

Jonathan

### Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

### Rules — please read before posting

• Post long source code as attachment, not in the text
• Posting advertisements is forbidden.

### Formatting options

• [c]C code[/c]
• [avrasm]AVR assembler code[/avrasm]
• [code]code in other languages, ASCII drawings[/code]
• $formula (LaTeX syntax)$
 Name: E-mail address (not visible): Subject: Searching for similar topics... Attachment: Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one. Text: