Skip to main content
Vmere.1
Associate III
September 6, 2022
Question

Question regarding alignment in keil scatter file.

  • September 6, 2022
  • 2 replies
  • 3207 views

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?

This topic has been closed for replies.

2 replies

Pavel A.
Super User
September 6, 2022

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.

Vmere.1
Vmere.1Author
Associate III
September 7, 2022

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?

Pavel A.
Super User
September 8, 2022

@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.

Tesla DeLorean
Guru
September 6, 2022

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 VenmoUp vote any posts that you find helpful, it shows what's working..
Vmere.1
Vmere.1Author
Associate III
September 7, 2022

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.