cancel
Showing results for 
Search instead for 
Did you mean: 

Question regarding alignment in keil scatter file.

Vmere.1
Senior

I'm quite confused when it comes to alignment.

I opened linker script to make some modifications, so that I can fit two binaries into flash. (Relatively new to embedded, but frankly I learn fast).

I use stm32f091Rx. Which has 256kB of flash memory.

A little about my plan to implement Over the Air update: 

flash schematic:  

1. 4kB- bootloader.

2. 2KB- placeholder (I want to keep a place holder on flash to jump to specific application., so bootloader know where to jump next in the next reboot).

3. 100kB - Application v1.

4. 100kB - Application v2.

Originally bootloader always jump to 0x0800000 which is hardcoded in bootloader.  

And in my project, the bootloader don't do the update, but the application does the OTA and then save the new location in the placeholder (2 in the above flash schematic).

Questions:

1. I want to place the header of the firmware. Where is the best place? (at the beginning, how to manage without vector table) or (at the same place at the end?)

2. What is the purpose of alignment? I had written ALIGN 2048 So that the start address of the header is divisible by 2048 and the beginning of the page.

But why do I want it? What if I do not do it?

0693W00000SuaYcQAJ.png3. *(:gdef:APPheader)

What is the difference between using the above statement vs just using __attribute__((section("MAMBA"))); after the variable definition and then placing mamba in a specific section?

4. ABSOLUTE keyword in the scatter file is the default. So what is FIXED? If I want to do the FOTA update do I need to make some modifications?

7 REPLIES 7
Pavel A.
Evangelist III

Your stm32f091Rx is Cortex-M0, thus its vectors must be at the fixed address 0 (mapped to the flash start address 08000000 in STM32F0, so it works). You can remap the address 0 to internal SRAM, carve a part of the SRAM from the start and copy the vector table there from the app image stored in flash. The start of the SRAM has a good alignment for the vector table. Then, the alignment of vectors in the image is not important at all.

There are empty vectors that can be used safely, I would tend to put a length record in, perhaps a unique or sequenced/advancing number. If you're uncomfortable using within the scope of the vector table, then just beyond it.

Use the length to add a CRC or signature on the far end of the image, the loader can the authenticate it before jumping blindly.

I'd probably go for pointers rather than AT directives, and I'd have the linker provide the application code with the vector table address, and use the symbol in SystemInit()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

But I think it may not be relevant to me as my bootloader which is at 0x0800000 always loads and then using fnc ptr jumps to the application. So I think I don't need to remap to SRAM!

So what you said is when, there are only two applications and no bootcode option.

In my case always the bootloader loads first and then, jumps to specific application, which is having is own vector table.

Is my understanding correct?

Hello @Community member​ ,

There are empty vectors that can be used safely, I would tend to put a length record in, perhaps a unique or sequenced/advancing number. If you're uncomfortable using within the scope of the vector table, then just beyond it.

I didn't get what you were trying to say. I highlighted some new terms u were explaining and couldn't find it on the internet too.

Sorry, just using English words.

Empty/Unused, spaces in the vector table that could be used such that it could be identified as a header, or containing things you put there for the purposes of determining length, and version.

Often there is a requirement that you can't regress to older versions of firmware, such as to exploit bugs/issues that were subsequently fixed. To do so you need some numbering scheme to determine if the current one is newer, older.

A unique number can be used to identify it as a header, and yours, and using some format/structure that you can access or work with via an external signing application, encryptor or whatever

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello @Community member​ ,

That's creative, I see some placeholders as "reserved" in the vector table.

Probably i'll use those.

@Vmere.1​ 

> So I think I don't need to remap to SRAM!

After your bootloader jumps to either of two your apps, they likely will need to handle interrupts. The systick for one. The flash address 08000000 already holds the bootloader's vector table so for the app vectors you have to either remap, or make the bootloader's handlers jump to the app handlers.