EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Making a custom "firmware update" of my application lpc2468

Started by Daniel Cobo May 7, 2009
Hi all,

I want to make possible a "firmware update" on a lpc2468 application and I
don't know if is possible the way I'm thinking.
First of all, I am using Keil uvision3 v3.63 with armcc, armlink, armasm,
etc v3.1.0.939. I tell you how my application works:
-I have part of code in the internal flash and another part on a external
nor flash.
-With a scatter file i move the code of the external nor flash to be in
execution on external ram. RW and ZI execution regions are on internal and
external ram.

Lpc2468's memory map:
0x00000000 Start of internal flash
0x40000000 Start of internal ram
0x80000000 Start of external nor flash
0xA0000000 Start of external ram

My scatter file is something like this:

LR_IROM1 0x00000000 0x00080000 { ; load region size_region
;Internal flash
ER_IROM1 0x00000000 0x00080000 { ; load address = execution address
*.o (RESET, +First) ;startup code must be on
root section
*(InRoot$$Sections)
file1.o ;I will have
some code files in the internal flash that will not vary with the update
file2.o
}
RW_RAM2 0xA0000000 0x00012000 { ; RW and ZI data on part of external RAM

.ANY (+RW +ZI)
}
RW_IRAM1 0x40000000 0x0000FFFF {
.ANY (+RW +ZI) ;RW and ZI on
internal RAM
}
}

LR_IROM2 0x80001000 0x00FFF000 { ;Load region of the external nor
flash. 0x80000000 to 0x80001000 part is used for other stuff
ER_IROM2 0xA0012000 0x16E000 { ;it executes on external ram
.ANY (+RO)
}
}

I want to update only the code that is at load region of the external nor
flash. The idea is this:

-With new code i will program de lpc2468 in the normal way, so the new code
will be place at nor flash. Then i will dump the nor flash to a file in a SD
and i will use it as the update.
-To update it, i will do just the contrary, i would dump the file to the nor
flash.
-In the house of the sweets at candy street in a perfect world the next time
the arm starts will take the new code and work fine. But...
Note: All the code that makes the update is on the internal flash so if
something go wrong during the process it could be retried.

The question is, if i do this, the scatter process will take the function's
new addresses or they are predefined the first time? I dont know how
scatter process works.
Anyone has made something like this in a similar or different way? How do
people do updates on embedded systems?
I know you cant give me a solution in a couple of lines with something like
this, but any idea, will help me a lot.

Thank you all


An Engineer's Guide to the LPC2100 Series

Hi again,

I have wrote some code to copy the nor flash to a sd file and another one to
put the sd file data to the nor flash.
So I erase the nor flash, rewrite it with the sd file data, and it works.

I have a part of the nor where i have a function that will be exactly at the
same place and with the same function calls in all the updates, so i thougth
that this function would have the new pointers to the rest of functions of
the update so it would work. But it doesnt.

I think that the function positions in the memory are prefixed at
compilation time. So now I think in two possible solutions:

1. If the functions positions are prefixed it have to be something like a
memory map. Someone knows where it is in memory?
2. Instead of only rewrite the nor flash i would have to rewrite also the
internal flash. I would have to execute everything on ram and modify the
internal flash. Can I rewrite it with a pointer?

Thank you all.


Hola Daniel:

By default, all code is fixed at the memory address you select in the scatter file.

In Keil uVision, Options for Target, Linker tab, you can make RAM/ROM sections position independent. However, I don't know how to work with that.
In the Options for Target, Listing tab, check the Linker Listing and the Memory Map checkboxes to generate a complete memory map file, that shows you where all the functions and data are located in memory (plus other useful information, like code size and others).

In our application, we have developed a "custom" bootloader that receives the new upgrade file, writes it to memory (at a fixed memory address) and then executes the code from that address.

In your case, it seems that you have two sections in your NOR memory; one that would be updated, and one that not. I would suggest create two load sections in your scatter file, and place each block of code in each section. Note that the sections need to be aligned with memory pages. This way you can erase one section (by erasing the respective pages) without having to erase the other section.

Then your "custom" bootloader would have to be smart enough to only update the one section you need to update.

Regards,

Alex.
--- In l..., Daniel Cobo wrote:
>
> Hi again,
>
> I have wrote some code to copy the nor flash to a sd file and another one to
> put the sd file data to the nor flash.
> So I erase the nor flash, rewrite it with the sd file data, and it works.
>
> I have a part of the nor where i have a function that will be exactly at the
> same place and with the same function calls in all the updates, so i thougth
> that this function would have the new pointers to the rest of functions of
> the update so it would work. But it doesnt.
>
> I think that the function positions in the memory are prefixed at
> compilation time. So now I think in two possible solutions:
>
> 1. If the functions positions are prefixed it have to be something like a
> memory map. Someone knows where it is in memory?
> 2. Instead of only rewrite the nor flash i would have to rewrite also the
> internal flash. I would have to execute everything on ram and modify the
> internal flash. Can I rewrite it with a pointer?
>
> Thank you all.
>
>
>
>

Hola Alex,

Thank you for your advices. I already tried RW and RO position independent
but I had not luck. I also have checked all the tabs for memory map details.
You are right, I have one part to be updated and other part that I do not
want to update. The part that I do not update have the code that makes the
update, this way if there is any problem while the update is working it is
possible to retry the update. But I think that this is the problem.
I have three load regions:
1. The first is at internal flash and this wont be modified anyway(this is
where I have startup code, initial chip's configuration and update code).
This will not be update.
2. At NOR memory, is a small code that only calls the real application(at
third load section). This will be update, but the code will be always the
same and call the function where the application starts. I thought that
doing this i would not have problems when the application functions change
size or if i have new functions in the third load section because updating
it the directions of the application functions would be correct.
3. At NOR memory, this is what i really want to update.

The update code works fine, it only change the second and third load
section, in fact when i update it, it works until the program want to jump
to a function that have change its direction after the update. Is like that
the functions directions are saved somewhere in the first load section.
One question, your bootloader upgrades all your load sections? I think the
problem is trying to upgrade only a part.

Thank you all

Dani
2009/5/14 Alex Ribero

> Hola Daniel:
>
> By default, all code is fixed at the memory address you select in the
> scatter file.
>
> In Keil uVision, Options for Target, Linker tab, you can make RAM/ROM
> sections position independent. However, I don't know how to work with that.
>
> In the Options for Target, Listing tab, check the Linker Listing and the
> Memory Map checkboxes to generate a complete memory map file, that shows you
> where all the functions and data are located in memory (plus other useful
> information, like code size and others).
>
> In our application, we have developed a "custom" bootloader that receives
> the new upgrade file, writes it to memory (at a fixed memory address) and
> then executes the code from that address.
>
> In your case, it seems that you have two sections in your NOR memory; one
> that would be updated, and one that not. I would suggest create two load
> sections in your scatter file, and place each block of code in each section.
> Note that the sections need to be aligned with memory pages. This way you
> can erase one section (by erasing the respective pages) without having to
> erase the other section.
>
> Then your "custom" bootloader would have to be smart enough to only update
> the one section you need to update.
>
> Regards,
>
> Alex.
> --- In l... , Daniel Cobo
> wrote:
> >
> > Hi again,
> >
> > I have wrote some code to copy the nor flash to a sd file and another one
> to
> > put the sd file data to the nor flash.
> > So I erase the nor flash, rewrite it with the sd file data, and it works.
> >
> > I have a part of the nor where i have a function that will be exactly at
> the
> > same place and with the same function calls in all the updates, so i
> thougth
> > that this function would have the new pointers to the rest of functions
> of
> > the update so it would work. But it doesnt.
> >
> > I think that the function positions in the memory are prefixed at
> > compilation time. So now I think in two possible solutions:
> >
> > 1. If the functions positions are prefixed it have to be something like a
> > memory map. Someone knows where it is in memory?
> > 2. Instead of only rewrite the nor flash i would have to rewrite also the
> > internal flash. I would have to execute everything on ram and modify the
> > internal flash. Can I rewrite it with a pointer?
> >
> > Thank you all.
> >
> >
> >
> >
>


Solved. I had a function in the nor memory that was being called from
internal flash. The direction of that function changes with the update so
when the program counter jumped where the function was supposed to be it
wasnt.

Thank you all,

Dani

2009/5/18 Daniel Cobo

> Hola Alex,
>
> Thank you for your advices. I already tried RW and RO position independent
> but I had not luck. I also have checked all the tabs for memory map details.
> You are right, I have one part to be updated and other part that I do not
> want to update. The part that I do not update have the code that makes the
> update, this way if there is any problem while the update is working it is
> possible to retry the update. But I think that this is the problem.
> I have three load regions:
> 1. The first is at internal flash and this wont be modified anyway(this is
> where I have startup code, initial chip's configuration and update code).
> This will not be update.
> 2. At NOR memory, is a small code that only calls the real application(at
> third load section). This will be update, but the code will be always the
> same and call the function where the application starts. I thought that
> doing this i would not have problems when the application functions change
> size or if i have new functions in the third load section because updating
> it the directions of the application functions would be correct.
> 3. At NOR memory, this is what i really want to update.
>
> The update code works fine, it only change the second and third load
> section, in fact when i update it, it works until the program want to jump
> to a function that have change its direction after the update. Is like that
> the functions directions are saved somewhere in the first load section.
> One question, your bootloader upgrades all your load sections? I think the
> problem is trying to upgrade only a part.
>
> Thank you all
>
> Dani
> 2009/5/14 Alex Ribero
>>
>> Hola Daniel:
>>
>> By default, all code is fixed at the memory address you select in the
>> scatter file.
>>
>> In Keil uVision, Options for Target, Linker tab, you can make RAM/ROM
>> sections position independent. However, I don't know how to work with that.
>>
>> In the Options for Target, Listing tab, check the Linker Listing and the
>> Memory Map checkboxes to generate a complete memory map file, that shows you
>> where all the functions and data are located in memory (plus other useful
>> information, like code size and others).
>>
>> In our application, we have developed a "custom" bootloader that receives
>> the new upgrade file, writes it to memory (at a fixed memory address) and
>> then executes the code from that address.
>>
>> In your case, it seems that you have two sections in your NOR memory; one
>> that would be updated, and one that not. I would suggest create two load
>> sections in your scatter file, and place each block of code in each section.
>> Note that the sections need to be aligned with memory pages. This way you
>> can erase one section (by erasing the respective pages) without having to
>> erase the other section.
>>
>> Then your "custom" bootloader would have to be smart enough to only update
>> the one section you need to update.
>>
>> Regards,
>>
>> Alex.
>> --- In l... , Daniel Cobo
>> wrote:
>> >
>> > Hi again,
>> >
>> > I have wrote some code to copy the nor flash to a sd file and another
>> one to
>> > put the sd file data to the nor flash.
>> > So I erase the nor flash, rewrite it with the sd file data, and it
>> works.
>> >
>> > I have a part of the nor where i have a function that will be exactly at
>> the
>> > same place and with the same function calls in all the updates, so i
>> thougth
>> > that this function would have the new pointers to the rest of functions
>> of
>> > the update so it would work. But it doesnt.
>> >
>> > I think that the function positions in the memory are prefixed at
>> > compilation time. So now I think in two possible solutions:
>> >
>> > 1. If the functions positions are prefixed it have to be something like
>> a
>> > memory map. Someone knows where it is in memory?
>> > 2. Instead of only rewrite the nor flash i would have to rewrite also
>> the
>> > internal flash. I would have to execute everything on ram and modify the
>> > internal flash. Can I rewrite it with a pointer?
>> >
>> > Thank you all.
>> >
>> >
>> >
>> >
>>
>>
>>



Memfault Beyond the Launch