Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I have a theory that it's impossible to prove anything, but I can't prove it.


devel / comp.arch.embedded / Re: gcc ld and bss sections on SDRAM

SubjectAuthor
* gcc ld and bss sections on SDRAMpozz
+* Re: gcc ld and bss sections on SDRAMDavid Brown
|`- Re: gcc ld and bss sections on SDRAMpozz
`* Re: gcc ld and bss sections on SDRAMStefan Reuther
 `- Re: gcc ld and bss sections on SDRAMpozz

1
gcc ld and bss sections on SDRAM

<t11duu$b0l$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=832&group=comp.arch.embedded#832

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: gcc ld and bss sections on SDRAM
Date: Fri, 18 Mar 2022 08:56:14 +0100
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <t11duu$b0l$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 18 Mar 2022 07:56:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cb0d4c49140875aecd7840ebe641088d";
logging-data="11285"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192zAwP6p3RLsBTjoCOTolGr24LruMF32E="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:yq6zpB+OwXcPKcrM4oUZ3xdXnvg=
 by: pozz - Fri, 18 Mar 2022 07:56 UTC

My platform is LPC546xx, Cortex-M4 by NXP, and the build environment is
based on GCC ARM toolchain (MCUXpresso IDE). However the question is
generic.

The default linker script instructs linker to put bss sections (zero
initialized data) in internal RAM. During startup, before main, bss
sections, described in a table on Flash, are reset to zero:

__attribute__ ((section(".after_vectors.init_bss")))
void bss_init(unsigned int start, unsigned int len) {
unsigned int *pulDest = (unsigned int*) start;
unsigned int loop;
for (loop = 0; loop < len; loop = loop + 4)
*pulDest++ = 0;
}

extern unsigned int __bss_section_table;
extern unsigned int __bss_section_table_end;

void ResetISR(void) {
...
// At this point, SectionTableAddr = &__bss_section_table;
// Zero fill the bss segment
while (SectionTableAddr < &__bss_section_table_end) {
ExeAddr = *SectionTableAddr++;
SectionLen = *SectionTableAddr++;
bss_init(ExeAddr, SectionLen);
}

...
main();
...
}

This works well until I add a new RAM memory section on external bus (it
is a SDRAM). Suppose I want to allocate a big variable on SDRAM. This
can be done in different ways (I use some facilities of MCUXpresso IDE).

Now the startup code is broken, because SDRAM memory can be accessed
only after it is configured (during main), but the bss initialization is
done before main.

I know I can rewrite ResetISR() or bss_init() to avoid accessing
external bus addresses or I can configure SDRAM during ResetISR() before
calling bss_init().

I suspect there's a better and more cleaner way. Noinit sections?

Re: gcc ld and bss sections on SDRAM

<t11m3g$ect$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=833&group=comp.arch.embedded#833

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.arch.embedded
Subject: Re: gcc ld and bss sections on SDRAM
Date: Fri, 18 Mar 2022 11:15:11 +0100
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <t11m3g$ect$1@dont-email.me>
References: <t11duu$b0l$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 18 Mar 2022 10:15:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4a9effb4475105aabb157253ff114ab7";
logging-data="14749"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184ihOu5Rj9hIMbsmC9k8b/vlayCl0sdSY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:bDiQTc5Js+dIcSTqoAqn9dZzY3k=
In-Reply-To: <t11duu$b0l$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 18 Mar 2022 10:15 UTC

On 18/03/2022 08:56, pozz wrote:
> My platform is LPC546xx, Cortex-M4 by NXP, and the build environment is
> based on GCC ARM toolchain (MCUXpresso IDE). However the question is
> generic.
>
> The default linker script instructs linker to put bss sections (zero
> initialized data) in internal RAM. During startup, before main, bss
> sections, described in a table on Flash, are reset to zero:
>
>
> __attribute__ ((section(".after_vectors.init_bss")))
> void bss_init(unsigned int start, unsigned int len) {
>     unsigned int *pulDest = (unsigned int*) start;
>     unsigned int loop;
>     for (loop = 0; loop < len; loop = loop + 4)
>         *pulDest++ = 0;
> }
>
> extern unsigned int __bss_section_table;
> extern unsigned int __bss_section_table_end;
>
> void ResetISR(void) {
>     ...
>     // At this point, SectionTableAddr = &__bss_section_table;
>     // Zero fill the bss segment
>     while (SectionTableAddr < &__bss_section_table_end) {
>         ExeAddr = *SectionTableAddr++;
>         SectionLen = *SectionTableAddr++;
>         bss_init(ExeAddr, SectionLen);
>     }
>
>     ...
>     main();
>     ...
> }
>
>
> This works well until I add a new RAM memory section on external bus (it
> is a SDRAM). Suppose I want to allocate a big variable on SDRAM. This
> can be done in different ways (I use some facilities of MCUXpresso IDE).
>
> Now the startup code is broken, because SDRAM memory can be accessed
> only after it is configured (during main), but the bss initialization is
> done before main.
>
> I know I can rewrite ResetISR() or bss_init() to avoid accessing
> external bus addresses or I can configure SDRAM during ResetISR() before
> calling bss_init().
>
> I suspect there's a better and more cleaner way. Noinit sections?

There are several ways to handle this. You can set up the sdram before
clearing the bss - I think you'll find a weak function called
SytemInitHook or similar, that you can override with your own version.
If you are putting a lot of different stuff into the sdram, this is
probably the best.

You can fiddle with either the linker script or the ResetISR function to
avoid clearing the sdram bss (and copying the sdram initialised data)
during ResetISR, and do it manually after initialising the ram.

Often, however, it is a good idea /not/ to use sdram for bss or data.
Use the internal ram (DTC ram if possible, or OCRAM - depending on the
particular chip) for that. Put your heap in sdram, along with other big
buffers such as network buffers, FreeRTOS heap, etc. These can all be
initialised later once the ram is configured. And you can mark any
large statically allocated arrays or structures with a section attribute
for a "noinit" section of the sdram.

Re: gcc ld and bss sections on SDRAM

<t11o4m$js4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=834&group=comp.arch.embedded#834

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Re: gcc ld and bss sections on SDRAM
Date: Fri, 18 Mar 2022 11:49:58 +0100
Organization: A noiseless patient Spider
Lines: 148
Message-ID: <t11o4m$js4$1@dont-email.me>
References: <t11duu$b0l$1@dont-email.me> <t11m3g$ect$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 18 Mar 2022 10:49:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cb0d4c49140875aecd7840ebe641088d";
logging-data="20356"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Fi0rXj865aUWKLzQfU1OlPs59wWp2nyI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:oQsxBVT1ktxUj+RyqTs0uCxClP4=
In-Reply-To: <t11m3g$ect$1@dont-email.me>
 by: pozz - Fri, 18 Mar 2022 10:49 UTC

Il 18/03/2022 11:15, David Brown ha scritto:
> On 18/03/2022 08:56, pozz wrote:
>> My platform is LPC546xx, Cortex-M4 by NXP, and the build environment is
>> based on GCC ARM toolchain (MCUXpresso IDE). However the question is
>> generic.
>>
>> The default linker script instructs linker to put bss sections (zero
>> initialized data) in internal RAM. During startup, before main, bss
>> sections, described in a table on Flash, are reset to zero:
>>
>>
>> __attribute__ ((section(".after_vectors.init_bss")))
>> void bss_init(unsigned int start, unsigned int len) {
>>     unsigned int *pulDest = (unsigned int*) start;
>>     unsigned int loop;
>>     for (loop = 0; loop < len; loop = loop + 4)
>>         *pulDest++ = 0;
>> }
>>
>> extern unsigned int __bss_section_table;
>> extern unsigned int __bss_section_table_end;
>>
>> void ResetISR(void) {
>>     ...
>>     // At this point, SectionTableAddr = &__bss_section_table;
>>     // Zero fill the bss segment
>>     while (SectionTableAddr < &__bss_section_table_end) {
>>         ExeAddr = *SectionTableAddr++;
>>         SectionLen = *SectionTableAddr++;
>>         bss_init(ExeAddr, SectionLen);
>>     }
>>
>>     ...
>>     main();
>>     ...
>> }
>>
>>
>> This works well until I add a new RAM memory section on external bus (it
>> is a SDRAM). Suppose I want to allocate a big variable on SDRAM. This
>> can be done in different ways (I use some facilities of MCUXpresso IDE).
>>
>> Now the startup code is broken, because SDRAM memory can be accessed
>> only after it is configured (during main), but the bss initialization is
>> done before main.
>>
>> I know I can rewrite ResetISR() or bss_init() to avoid accessing
>> external bus addresses or I can configure SDRAM during ResetISR() before
>> calling bss_init().
>>
>> I suspect there's a better and more cleaner way. Noinit sections?
>
> There are several ways to handle this. You can set up the sdram before
> clearing the bss - I think you'll find a weak function called
> SytemInitHook or similar, that you can override with your own version.
> If you are putting a lot of different stuff into the sdram, this is
> probably the best.

ResetISR() is the first call after a reset.

__attribute__ ((section(".after_vectors")))
void
ResetISR(void) {

//
// Copy the data sections from flash to SRAM.
//
unsigned int LoadAddr, ExeAddr, SectionLen;
unsigned int *SectionTableAddr;

// Load base address of Global Section Table
SectionTableAddr = &__data_section_table;

// Copy the data sections from flash to SRAM.
while (SectionTableAddr < &__data_section_table_end) {
LoadAddr = *SectionTableAddr++;
ExeAddr = *SectionTableAddr++;
SectionLen = *SectionTableAddr++;
data_init(LoadAddr, ExeAddr, SectionLen);
}
// At this point, SectionTableAddr = &__bss_section_table;
// Zero fill the bss segment
while (SectionTableAddr < &__bss_section_table_end) {
ExeAddr = *SectionTableAddr++;
SectionLen = *SectionTableAddr++;
bss_init(ExeAddr, SectionLen);
}

#if defined (__USE_CMSIS) || defined (__USE_LPCOPEN)
SystemInit();
#endif

#if defined (__cplusplus)
//
// Call C++ library initialisation
//
__libc_init_array();
#endif

#if defined (__REDLIB__)
// Call the Redlib library, which in turn calls main()
__main() ;
#else
main();
#endif

//
// main() shouldn't return, but if it does, we'll just enter an
infinite loop
//
while (1) {
;
}
}

There isn't any weak function call, anyway I can add my own.

> You can fiddle with either the linker script or the ResetISR function to
> avoid clearing the sdram bss (and copying the sdram initialised data)
> during ResetISR, and do it manually after initialising the ram.

Yes, this is another possibility.

You didn't mention NOLOAD (noinit). It seems to me another good approach
for my problem.

> Often, however, it is a good idea /not/ to use sdram for bss or data.
> Use the internal ram (DTC ram if possible, or OCRAM - depending on the
> particular chip) for that. Put your heap in sdram, along with other big
> buffers such as network buffers, FreeRTOS heap, etc. These can all be
> initialised later once the ram is configured. And you can mark any
> large statically allocated arrays or structures with a section attribute
> for a "noinit" section of the sdram.

I have some images saved in a SDCard and I have to show them on the
display in some cases. I have plenty of SDRAM for other purposes
(framebuffer, for example) so I thought, why read images from SDCard
every time I have to show them?

At startup, I copy images from SDCard to SDRAM and later I can access
images directly from SDRAM.
The maximum size of all images is 2MB and I have this free space on SDRAM.

Re: gcc ld and bss sections on SDRAM

<t12h67.4tc.1@stefan.msgid.phost.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=835&group=comp.arch.embedded#835

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: stefan.n...@arcor.de (Stefan Reuther)
Newsgroups: comp.arch.embedded
Subject: Re: gcc ld and bss sections on SDRAM
Date: Fri, 18 Mar 2022 17:57:26 +0100
Lines: 17
Message-ID: <t12h67.4tc.1@stefan.msgid.phost.de>
References: <t11duu$b0l$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net r93qGVUwtCH54QxHuZgmOw/RcSKBXNjd1Ag/IKoe7Or7wXp4DY
Cancel-Lock: sha1:y6xWMiZ+FGHfzy0U7FBoIlhvbps=
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101
Thunderbird/68.12.1 Hamster/2.1.0.1538
In-Reply-To: <t11duu$b0l$1@dont-email.me>
 by: Stefan Reuther - Fri, 18 Mar 2022 16:57 UTC

Am 18.03.2022 um 08:56 schrieb pozz:
> I know I can rewrite ResetISR() or bss_init() to avoid accessing
> external bus addresses or I can configure SDRAM during ResetISR() before
> calling bss_init().
>
> I suspect there's a better and more cleaner way. Noinit sections?

When I did bootloaders, I did the SDRAM initialisation there, before the
application starts. This also means there's a nice place to deal with
board varieties, i.e. if I have a board variant with a different SDRAM
chip, I only have to change the bootloader. And it allows loading parts
of the application code into SDRAM, if that is relevant for you.

Otherwise, I'd probably use a noinit section.

Stefan

Re: gcc ld and bss sections on SDRAM

<t14rfu$6i6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=839&group=comp.arch.embedded#839

  copy link   Newsgroups: comp.arch.embedded
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: pozzu...@gmail.com (pozz)
Newsgroups: comp.arch.embedded
Subject: Re: gcc ld and bss sections on SDRAM
Date: Sat, 19 Mar 2022 16:05:35 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <t14rfu$6i6$1@dont-email.me>
References: <t11duu$b0l$1@dont-email.me> <t12h67.4tc.1@stefan.msgid.phost.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 19 Mar 2022 15:05:34 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="45f8288871b0e996764f1cb87d2d5718";
logging-data="6726"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jAyZ6GUyhOwOAi7b78J1G6QBryHMmPbw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.7.0
Cancel-Lock: sha1:6iOH70F7MvI149qeJdiEOkAO2oY=
In-Reply-To: <t12h67.4tc.1@stefan.msgid.phost.de>
 by: pozz - Sat, 19 Mar 2022 15:05 UTC

Il 18/03/2022 17:57, Stefan Reuther ha scritto:
> Am 18.03.2022 um 08:56 schrieb pozz:
>> I know I can rewrite ResetISR() or bss_init() to avoid accessing
>> external bus addresses or I can configure SDRAM during ResetISR() before
>> calling bss_init().
>>
>> I suspect there's a better and more cleaner way. Noinit sections?
>
> When I did bootloaders, I did the SDRAM initialisation there, before the
> application starts. This also means there's a nice place to deal with
> board varieties, i.e. if I have a board variant with a different SDRAM
> chip, I only have to change the bootloader. And it allows loading parts
> of the application code into SDRAM, if that is relevant for you.
>
> Otherwise, I'd probably use a noinit section.

Yes, you're right, bootloader is another good place to configure hw and
next launch application.

Thank you for your suggestion.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor