1

I have a GNU linker script for my firmware with the following section defined:

  .endc :
  {
    KEEP(*(.endc));
    . = ALIGN(4);
    _end_code_mark = .;
  } >FLASH

This is the last time I'm assigning a section to the FLASH region. The purpose of this section is to put an "end of code" marker so that I can know in my application what's the actual size of my binary (I do the difference with the start and end address).

In my C code, when I look for the _end_code_mark symbol, it indeed is referencing the last byte of my binary. So, that's fine.

However, I would like to have a magic bytecode value as a marker to define the end of my binary rather than a symbol. Therefore, I have a file where I defined a 4 bytes buffer:

const uint8_t end_of_code[] __attribute__((section(".endc.end_of_code"))) = {0x01, 0x02, 0x03, 0x04};

And I changed the .endc section in my linker script above with the following:

  .endc :
  {
    KEEP(*(.endc));
    . = ALIGN(4);
    .end_of_code = .;
  } >FLASH

Yet, when I build my firmware binary this way, the end_of_code buffer is not located at the end of my binary image anymore.

Am I doing something wrong, or is there an other way to write those 4 bytes at the end of my binary image with the linker script?

2
  • 1
    You're using section .endc.end_of_code in the C code, but .endc in the linker script. Commented Sep 25, 2023 at 12:28
  • @pmacfarlane Yup, indeed, that was the issue. I thought this was the way it was meant to be done. Thank's a lot! Commented Sep 25, 2023 at 12:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.