EmbeddedRelated.com
Forums

How to remap a program to run it in external SDRAM

Started by Kuba Dorzak April 15, 2011
Hi Everybody,

I have Olimex LPC-2478-STK board with 64MB SRAM. Using Uboot I'd like to run
my whole application in the SDRAM. To achieve the goal, I did the following:
1. I modified my linker script- all sections go to the SDRAM, which is
defined as:

MEMORY
{
sdram (rwx) : org = 0xA0000000, len = 64M
}

2. I remaped the program to external memory:

MEMMAP = MEMMAP_MAP_ERAM;

My examplary application is a led blinking effect. After loading the bin to
SDRAM and jumping there, my app does not start.
I have the following questions:
1. should I divide the SDRAM into sections, where i put .text and .data?
Something like:
MEMORY
{
sdram_rom (rx) : org = 0xA0000000, len = 32M
sdram_ram (rwx) : org = 0xA2000000, len = 32M
}
or it does not matter?

2. uboot has it's own init routines. When my program starts it has its
routines, like PLL, MAM, etc. Can those double inits affect the uc proper
work?

3. is there something else I missed to run succesfully my program in SDRAM?

Regards,
Kuba

An Engineer's Guide to the LPC2100 Series

Hi,

2) Your c startup files normally copies the data section from ROM to
RAM. Also the BSS section is being cleared on startup. Assure those
sections are mapped as they should be.

2a) I assume SDRAM is already working in uboot. If not ubot has to init
SDRAM.

3) I would an even smaller application. Just turn on a led.

Marko
On 4/15/2011 10:52 AM, Kuba Dorzak wrote:
>
> Hi Everybody,
>
> I have Olimex LPC-2478-STK board with 64MB SRAM. Using Uboot I'd like
> to run my whole application in the SDRAM. To achieve the goal, I did
> the following:
> 1. I modified my linker script- all sections go to the SDRAM, which is
> defined as:
>
> MEMORY
> {
> sdram (rwx) : org = 0xA0000000, len = 64M
> }
>
> 2. I remaped the program to external memory:
>
> MEMMAP = MEMMAP_MAP_ERAM;
>
> My examplary application is a led blinking effect. After loading the
> bin to SDRAM and jumping there, my app does not start.
> I have the following questions:
> 1. should I divide the SDRAM into sections, where i put .text and
> .data? Something like:
> MEMORY
> {
> sdram_rom (rx) : org = 0xA0000000, len = 32M
> sdram_ram (rwx) : org = 0xA2000000, len = 32M
> }
> or it does not matter?
>
> 2. uboot has it's own init routines. When my program starts it has its
> routines, like PLL, MAM, etc. Can those double inits affect the uc
> proper work?
>
> 3. is there something else I missed to run succesfully my program in
> SDRAM?
>
> Regards,
> Kuba
How are you loading the code to SDRAM? You know that if you don't store the
code in a non-volatile mem it will be lost on reset (or at power off if you
have EMC Reset Disable bit asserted).

I think you'll need to place the code in the Flash and during your startup
code copy it to SDRAM and then jump there.

something like:
MEMORY
{
rom (rx) : org = 0x00000000, len = 512K
sdram (rwx) : org = 0xA0000000, len = 32M
}

SECTIONS {
.text : {
__text_load = LOADADDR (.text);
__text_start = .;
*(.text)
*(everything else)
__text_end = .;
} >SDRAM AT ROM

and then on startup copy from __text_load to __text_start until __text_end.

But I don't know how or what Uboot does... so it might work another way with
Uboot.

This tutorial, amongst other things, shows how to run code from ram, take a
look at it:
http://www.eetimes.com/design/embedded/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started

Regards,
Bernardo Marques.
Marko,

2) Your c startup files normally copies the data section from ROM to RAM.
Also the BSS section is being cleared on startup. Assure those sections are
mapped as they should be.
I checked this out. I even set the sections size the same as my orginal
flash (512kB) and ram (64kB). But no success. I am wondering if this coping
is necessary now- when running the app entirely from SDRAM?

2a) I assume SDRAM is already working in uboot. If not ubot has to init
SDRAM.
Yes it works. I can start uClinux from SDRAM.

3) I would an even smaller application. Just turn on a led.
Ok- no blinking

Bernardo,

2011/4/15 Bernardo

> How are you loading the code to SDRAM? You know that if you don't store the
> code in a non-volatile mem it will be lost on reset (or at power off if you
> have EMC Reset Disable bit asserted).
>
To do this I use uboot- it has an option to load a bin file into external
SDRAM.
>
> I think you'll need to place the code in the Flash and during your startup
> code copy it to SDRAM and then jump there.
>

My application is too big to be placed in Flash.

>
> something like:
> MEMORY
> {
> rom (rx) : org = 0x00000000, len = 512K
> sdram (rwx) : org = 0xA0000000, len = 32M
> }
>
> SECTIONS {
> .text : {
> __text_load = LOADADDR (.text);
> __text_start = .;
> *(.text)
> *(everything else)
> __text_end = .;
> } >SDRAM AT ROM
>
> and then on startup copy from __text_load to __text_start until __text_end.
>

I can do this. My very first application copied functions from a RAM
section, and then put and execute them in SDRAM, however it's limited to
16kB (as the section is in usb RAM of LPC2474). Now it's time for futher
steps:)

>
> But I don't know how or what Uboot does... so it might work another way
> with Uboot.
>

Uboot is a bootloader.

>
> This tutorial, amongst other things, shows how to run code from ram, take a
> look at it:
>
> http://www.eetimes.com/design/embedded/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started
>
> Thanks for this. Before I started to experiment with my SDRAM I used James
Lynch tutor, which also describes how to start an app from RAM- it worked
ok.
> Regards,
> Bernardo Marques.
>

>
>
Hi,

Some additional thoughts.

Uboot might use (for sure) some IRQs. When you jump to the load address
in the SDRAM an IRQ might fire, but at that point you have your
exception vectors set up and remapped. All sorts could happen then.

If you have the opportunity load the code into SDRAM with a JTAG
debugger and check if it works as expected. After this move to the uboot
environment.

Marko

On 4/15/2011 12:15 PM, Kuba Dorzak wrote:
>
> Marko,
>
> 2) Your c startup files normally copies the data section from ROM to
> RAM. Also the BSS section is being cleared on startup. Assure those
> sections are mapped as they should be.
> I checked this out. I even set the sections size the same as my
> orginal flash (512kB) and ram (64kB). But no success. I am wondering
> if this coping is necessary now- when running the app entirely from SDRAM?
>
> 2a) I assume SDRAM is already working in uboot. If not ubot has to
> init SDRAM.
> Yes it works. I can start uClinux from SDRAM.
>
> 3) I would an even smaller application. Just turn on a led.
> Ok- no blinking
>
> Bernardo,
>
> 2011/4/15 Bernardo > > How are you loading the code to SDRAM? You know that if you don't
> store the code in a non-volatile mem it will be lost on reset (or
> at power off if you have EMC Reset Disable bit asserted).
>
> To do this I use uboot- it has an option to load a bin file into
> external SDRAM.
> I think you'll need to place the code in the Flash and during your
> startup code copy it to SDRAM and then jump there.
> My application is too big to be placed in Flash.
> something like:
> MEMORY
> {
> rom (rx) : org = 0x00000000, len = 512K
> sdram (rwx) : org = 0xA0000000, len = 32M
> }
>
> SECTIONS {
> .text : {
> __text_load = LOADADDR (.text);
> __text_start = .;
> *(.text)
> *(everything else)
> __text_end = .;
> } >SDRAM AT ROM
>
> and then on startup copy from __text_load to __text_start until
> __text_end.
> I can do this. My very first application copied functions from a RAM
> section, and then put and execute them in SDRAM, however it's limited
> to 16kB (as the section is in usb RAM of LPC2474). Now it's time for
> futher steps:)
> But I don't know how or what Uboot does... so it might work
> another way with Uboot.
> Uboot is a bootloader.
> This tutorial, amongst other things, shows how to run code from
> ram, take a look at it:
> http://www.eetimes.com/design/embedded/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started
>
> Thanks for this. Before I started to experiment with my SDRAM I used
> James Lynch tutor, which also describes how to start an app from RAM-
> it worked ok.
>
> Regards,
> Bernardo Marques.
Hey Kuba, just one question that as nothing to do with your post,

with Uboot and uClinux can you easily display images in any file
format (jpg, png) on that board LCD (without having to write the code
to decode the files)? how about playing audio files, like mp3? Is
there a 'media player' for uClinux? I don't know anything about
uCLinux, I went to see the uboot web page... thinking about porting it
to my custom made board... but it seems to be a lot of work just to
read the manual (no pdf version available) I'd like to know if uCLinux
is worth all that work for my specific application (display images and
play sounds).

Regards,
Bernardo Marques.
On 4/15/11, Marko Panger wrote:
> Hi,
>
> Some additional thoughts.
>
> Uboot might use (for sure) some IRQs. When you jump to the load address
> in the SDRAM an IRQ might fire, but at that point you have your
> exception vectors set up and remapped. All sorts could happen then.
>
> If you have the opportunity load the code into SDRAM with a JTAG
> debugger and check if it works as expected. After this move to the uboot
> environment.
>
> Marko
>
> On 4/15/2011 12:15 PM, Kuba Dorzak wrote:
>>
>> Marko,
>>
>> 2) Your c startup files normally copies the data section from ROM to
>> RAM. Also the BSS section is being cleared on startup. Assure those
>> sections are mapped as they should be.
>> I checked this out. I even set the sections size the same as my
>> orginal flash (512kB) and ram (64kB). But no success. I am wondering
>> if this coping is necessary now- when running the app entirely from SDRAM?
>>
>> 2a) I assume SDRAM is already working in uboot. If not ubot has to
>> init SDRAM.
>> Yes it works. I can start uClinux from SDRAM.
>>
>> 3) I would an even smaller application. Just turn on a led.
>> Ok- no blinking
>>
>> Bernardo,
>>
>> 2011/4/15 Bernardo >> > How are you loading the code to SDRAM? You know that if you don't
>> store the code in a non-volatile mem it will be lost on reset (or
>> at power off if you have EMC Reset Disable bit asserted).
>>
>> To do this I use uboot- it has an option to load a bin file into
>> external SDRAM.
>> I think you'll need to place the code in the Flash and during your
>> startup code copy it to SDRAM and then jump there.
>> My application is too big to be placed in Flash.
>> something like:
>> MEMORY
>> {
>> rom (rx) : org = 0x00000000, len = 512K
>> sdram (rwx) : org = 0xA0000000, len = 32M
>> }
>>
>> SECTIONS {
>> .text : {
>> __text_load = LOADADDR (.text);
>> __text_start = .;
>> *(.text)
>> *(everything else)
>> __text_end = .;
>> } >SDRAM AT ROM
>>
>> and then on startup copy from __text_load to __text_start until
>> __text_end.
>> I can do this. My very first application copied functions from a RAM
>> section, and then put and execute them in SDRAM, however it's limited
>> to 16kB (as the section is in usb RAM of LPC2474). Now it's time for
>> futher steps:)
>> But I don't know how or what Uboot does... so it might work
>> another way with Uboot.
>> Uboot is a bootloader.
>> This tutorial, amongst other things, shows how to run code from
>> ram, take a look at it:
>>
>> http://www.eetimes.com/design/embedded/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started
>>
>> Thanks for this. Before I started to experiment with my SDRAM I used
>> James Lynch tutor, which also describes how to start an app from RAM-
>> it worked ok.
>>
>> Regards,
>> Bernardo Marques.
Bernardo, the only experience I had with these tools was to flash uboot and
run uClinux plus run some examplary apps which are included to the uClinux
disribution. There is an app which prints some patterns on the LCD.
Please, take a look here:
http://www.olimex.com/dev/pdf/ARM/LPC/lpc2478stk-uclinux-notes.pdf - this is
a short software description for Olimex stuff. I just checked what they got
and it worked.
My output is Bray Terminal, which allows you to communicate both with Uboot
& uClinux.
Regarding your porting, please check their websites as they have ported the
soft for popular platforms.
Regards, Kuba.

2011/4/15 Bernardo

> Hey Kuba, just one question that as nothing to do with your post,
>
> with Uboot and uClinux can you easily display images in any file
> format (jpg, png) on that board LCD (without having to write the code
> to decode the files)? how about playing audio files, like mp3? Is
> there a 'media player' for uClinux? I don't know anything about
> uCLinux, I went to see the uboot web page... thinking about porting it
> to my custom made board... but it seems to be a lot of work just to
> read the manual (no pdf version available) I'd like to know if uCLinux
> is worth all that work for my specific application (display images and
> play sounds).
>
> Regards,
> Bernardo Marques.
> On 4/15/11, Marko Panger wrote:
> > Hi,
> >
> > Some additional thoughts.
> >
> > Uboot might use (for sure) some IRQs. When you jump to the load address
> > in the SDRAM an IRQ might fire, but at that point you have your
> > exception vectors set up and remapped. All sorts could happen then.
> >
> > If you have the opportunity load the code into SDRAM with a JTAG
> > debugger and check if it works as expected. After this move to the uboot
> > environment.
> >
> > Marko
> >
> > On 4/15/2011 12:15 PM, Kuba Dorzak wrote:
> >>
> >> Marko,
> >>
> >> 2) Your c startup files normally copies the data section from ROM to
> >> RAM. Also the BSS section is being cleared on startup. Assure those
> >> sections are mapped as they should be.
> >> I checked this out. I even set the sections size the same as my
> >> orginal flash (512kB) and ram (64kB). But no success. I am wondering
> >> if this coping is necessary now- when running the app entirely from
> SDRAM?
> >>
> >> 2a) I assume SDRAM is already working in uboot. If not ubot has to
> >> init SDRAM.
> >> Yes it works. I can start uClinux from SDRAM.
> >>
> >> 3) I would an even smaller application. Just turn on a led.
> >> Ok- no blinking
> >>
> >> Bernardo,
> >>
> >> 2011/4/15 Bernardo > >> >
> >>
> >> How are you loading the code to SDRAM? You know that if you don't
> >> store the code in a non-volatile mem it will be lost on reset (or
> >> at power off if you have EMC Reset Disable bit asserted).
> >>
> >> To do this I use uboot- it has an option to load a bin file into
> >> external SDRAM.
> >>
> >>
> >> I think you'll need to place the code in the Flash and during your
> >> startup code copy it to SDRAM and then jump there.
> >>
> >>
> >> My application is too big to be placed in Flash.
> >>
> >>
> >> something like:
> >> MEMORY
> >> {
> >> rom (rx) : org = 0x00000000, len = 512K
> >> sdram (rwx) : org = 0xA0000000, len = 32M
> >> }
> >>
> >> SECTIONS {
> >> .text : {
> >> __text_load = LOADADDR (.text);
> >> __text_start = .;
> >> *(.text)
> >> *(everything else)
> >> __text_end = .;
> >> } >SDRAM AT ROM
> >>
> >> and then on startup copy from __text_load to __text_start until
> >> __text_end.
> >>
> >>
> >> I can do this. My very first application copied functions from a RAM
> >> section, and then put and execute them in SDRAM, however it's limited
> >> to 16kB (as the section is in usb RAM of LPC2474). Now it's time for
> >> futher steps:)
> >>
> >>
> >> But I don't know how or what Uboot does... so it might work
> >> another way with Uboot.
> >>
> >>
> >> Uboot is a bootloader.
> >>
> >>
> >> This tutorial, amongst other things, shows how to run code from
> >> ram, take a look at it:
> >>
> >>
> http://www.eetimes.com/design/embedded/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started
> >>
> >> Thanks for this. Before I started to experiment with my SDRAM I used
> >> James Lynch tutor, which also describes how to start an app from RAM-
> >> it worked ok.
> >>
> >> Regards,
> >> Bernardo Marques.
> >>
> >>
> >>
> >>
> >
> >
>
>
Guys, I have another question regarding executing a function in SDRAM with
an attribute __attribute__((section(.sdram))).

Assuming that you have a section in the linker script:
.sdram:
{
. = ALIGN(4);
*(.sdram)

} > xsdram AT > rom

and you copy at startup the code from flash to SDRAM- it still has no
chances to work, because EMC initialization is performed later (somewhere in
main, in my case) and the SDRAM address 0xA0000000 is not visible.
So, I'd need to initialize EMC at startup, before the copying function. Am
I right? Has anyone did this?

Regards, Kuba
2011/4/15 Kuba Dorzak

> Bernardo, the only experience I had with these tools was to flash uboot and
> run uClinux plus run some examplary apps which are included to the uClinux
> disribution. There is an app which prints some patterns on the LCD.
> Please, take a look here:
> http://www.olimex.com/dev/pdf/ARM/LPC/lpc2478stk-uclinux-notes.pdf - this
> is a short software description for Olimex stuff. I just checked what they
> got and it worked.
> My output is Bray Terminal, which allows you to communicate both with Uboot
> & uClinux.
> Regarding your porting, please check their websites as they have ported the
> soft for popular platforms.
> Regards, Kuba.
> 2011/4/15 Bernardo > Hey Kuba, just one question that as nothing to do with your post,
>>
>> with Uboot and uClinux can you easily display images in any file
>> format (jpg, png) on that board LCD (without having to write the code
>> to decode the files)? how about playing audio files, like mp3? Is
>> there a 'media player' for uClinux? I don't know anything about
>> uCLinux, I went to see the uboot web page... thinking about porting it
>> to my custom made board... but it seems to be a lot of work just to
>> read the manual (no pdf version available) I'd like to know if uCLinux
>> is worth all that work for my specific application (display images and
>> play sounds).
>>
>> Regards,
>> Bernardo Marques.
>> On 4/15/11, Marko Panger wrote:
>> > Hi,
>> >
>> > Some additional thoughts.
>> >
>> > Uboot might use (for sure) some IRQs. When you jump to the load address
>> > in the SDRAM an IRQ might fire, but at that point you have your
>> > exception vectors set up and remapped. All sorts could happen then.
>> >
>> > If you have the opportunity load the code into SDRAM with a JTAG
>> > debugger and check if it works as expected. After this move to the uboot
>> > environment.
>> >
>> > Marko
>> >
>> > On 4/15/2011 12:15 PM, Kuba Dorzak wrote:
>> >>
>> >> Marko,
>> >>
>> >> 2) Your c startup files normally copies the data section from ROM to
>> >> RAM. Also the BSS section is being cleared on startup. Assure those
>> >> sections are mapped as they should be.
>> >> I checked this out. I even set the sections size the same as my
>> >> orginal flash (512kB) and ram (64kB). But no success. I am wondering
>> >> if this coping is necessary now- when running the app entirely from
>> SDRAM?
>> >>
>> >> 2a) I assume SDRAM is already working in uboot. If not ubot has to
>> >> init SDRAM.
>> >> Yes it works. I can start uClinux from SDRAM.
>> >>
>> >> 3) I would an even smaller application. Just turn on a led.
>> >> Ok- no blinking
>> >>
>> >> Bernardo,
>> >>
>> >> 2011/4/15 Bernardo >> >> >
>> >>
>> >> How are you loading the code to SDRAM? You know that if you don't
>> >> store the code in a non-volatile mem it will be lost on reset (or
>> >> at power off if you have EMC Reset Disable bit asserted).
>> >>
>> >> To do this I use uboot- it has an option to load a bin file into
>> >> external SDRAM.
>> >>
>> >>
>> >> I think you'll need to place the code in the Flash and during your
>> >> startup code copy it to SDRAM and then jump there.
>> >>
>> >>
>> >> My application is too big to be placed in Flash.
>> >>
>> >>
>> >> something like:
>> >> MEMORY
>> >> {
>> >> rom (rx) : org = 0x00000000, len = 512K
>> >> sdram (rwx) : org = 0xA0000000, len = 32M
>> >> }
>> >>
>> >> SECTIONS {
>> >> .text : {
>> >> __text_load = LOADADDR (.text);
>> >> __text_start = .;
>> >> *(.text)
>> >> *(everything else)
>> >> __text_end = .;
>> >> } >SDRAM AT ROM
>> >>
>> >> and then on startup copy from __text_load to __text_start until
>> >> __text_end.
>> >>
>> >>
>> >> I can do this. My very first application copied functions from a RAM
>> >> section, and then put and execute them in SDRAM, however it's limited
>> >> to 16kB (as the section is in usb RAM of LPC2474). Now it's time for
>> >> futher steps:)
>> >>
>> >>
>> >> But I don't know how or what Uboot does... so it might work
>> >> another way with Uboot.
>> >>
>> >>
>> >> Uboot is a bootloader.
>> >>
>> >>
>> >> This tutorial, amongst other things, shows how to run code from
>> >> ram, take a look at it:
>> >>
>> >>
>> http://www.eetimes.com/design/embedded/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started
>> >>
>> >> Thanks for this. Before I started to experiment with my SDRAM I used
>> >> James Lynch tutor, which also describes how to start an app from RAM-
>> >> it worked ok.
>> >>
>> >> Regards,
>> >> Bernardo Marques.
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>>
>>
hi,

you can copy from ROM to SDRAM in C, after initialization of EMC. Just make
sure not to access SDRAM before. I have not tested that but I think it
should work.

Mario

On Fri, Apr 15, 2011 at 1:57 PM, Kuba Dorzak wrote:

--
Best regards,
Mario.
Or you can initialize the SDRAM first thing in your startup code.
Although if Uboot allows you to load anything to SDRAM then it must be
initialized in Uboot. From what I've seen of Uboot it is able to test
SDRAM, load the application there and start it. I'd bet that it is
better that your code doesn't change any SDRAM registers because most
probably it has been initialized already in Uboot.

Regards,
Bernardo Marques.

On 4/15/11, Mario Ivancic wrote:
> hi,
>
> you can copy from ROM to SDRAM in C, after initialization of EMC. Just make
> sure not to access SDRAM before. I have not tested that but I think it
> should work.
>
> Mario
>
> On Fri, Apr 15, 2011 at 1:57 PM, Kuba Dorzak wrote:
>
> --
> Best regards,
> Mario.
>