Linker file

Discussions related to the firmware code development
VK3KYY
Posts: 7481
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Linker file

Post by VK3KYY » Tue Feb 28, 2023 11:23 am

BTW.

Can you read / understand / modify the MK22 linker files

The firmware now takes 99.9% of the program ROM space in the MK22, making it impossible to make any more changes to the firmware, but I checked the MCU ROM backup and there is 11k of empty space after the codec_bin_section2

I checked the ROM length and it is correct, because the last 4 of ROM can't be used , because there are some hardware lock bytes in that area which the bootloader reads, and if the bytes do not match the unique CPU ID then the bootloader will not load the firmware ever again.

But I don't understand why the linker is not using this area.

possibly there needs to be another linker section added, which starts at after the end of the codec_bin_section2 but I tried adding another text section, but it did not make any difference


However, I don't know anything about linker files, so I'm just guessing about how to make the linker use this section of the ROM

DL4LEX
Posts: 62
Joined: Sat Nov 16, 2019 3:09 pm

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by DL4LEX » Tue Feb 28, 2023 7:24 pm

Roger,
you can use that empty space simply by:

add a section after .codec_bin_section2:

Code: Select all

    .codec_bin_section_2 : ALIGN(4)
    {
        . = ABSOLUTE(0x54000) ;
       *(.codec_bin_section_2)
        KEEP(*(.codec_bin_section_2))
    } > PROGRAM_FLASH
    
    .upper_text : ALIGN(4)
    {
        *(.text*)
        *(.upper_text)
       . = ALIGN(4);
    } > PROGRAM_FLASH
and modify one line at the end of firmware.ld:

Code: Select all

    _image_end = LOADADDR(.codec_bin_section_2) + SIZEOF(.codec_bin_section_2) + SIZEOF(.upper_text);
and then you can move functions to this new section e.g. in main.c:

Code: Select all

...
__attribute__((section(".upper_text"))) void mainTaskFunction(void *data)
...
Alex

VK3KYY
Posts: 7481
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by VK3KYY » Tue Feb 28, 2023 8:16 pm

Alex

Thanks..

I will try using those changes


I did try making similar changes, but I think I made a mistake with the .upper_text block, and I also added 0x2F2F to the _image_end, because I calculated the extra space was 0x2F2F, but using the size of the new block is better

VK3KYY
Posts: 7481
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by VK3KYY » Tue Feb 28, 2023 9:46 pm

Hi Alex

You changes did work, but I have some other questions, becuase the compiler / linker is not automatially using the new text section even if the other sections are full

I'll emial you

EA5JAQ
Posts: 86
Joined: Thu Jul 16, 2020 6:08 am

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by EA5JAQ » Wed Mar 01, 2023 9:09 am

VK3KYY wrote:
Tue Feb 28, 2023 11:23 am
Can you read / understand / modify the MK22 linker files
Hi! Sorry, I haven't checked the forum in a couple days. I wish I could help but I don't know much about linker files, I only changed the ROM start addresses by substracting 0x4000 addresses so the code starts at the beggining of the ROM if I don't flash a bootloader. And I haven't tested anything yet so I don't know if that'll even work. I've just seen someone already helped you.

BTW, when I was writing code for the SPI0 bit-bang to work, i had a strange linker error that wouldn't let me compile saying something like "cannot move location counter backwards". I spent hours on it as I found no errors in the code. In the end, I could solve it by using less functions to do the SPI0 communication. So I assume that was the ROM running out of space, I couldn't even add a simple function. I didn't know the space problem was that bad, I hope you can get those extra addresses.

VK3KYY
Posts: 7481
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by VK3KYY » Wed Mar 01, 2023 9:59 am

OK.

I think I found the problem.

I needed to use

__attribute__((section(".upper_text")))

To force data into this block.

I had expected that the linker would automatically use any new section which is added

DL4LEX
Posts: 62
Joined: Sat Nov 16, 2019 3:09 pm

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by DL4LEX » Wed Mar 01, 2023 10:46 am

Yes, that's the only way I found.

The linker by it's own does not seem to be able to handle multiple .text* section.

VK3KYY
Posts: 7481
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by VK3KYY » Wed Mar 01, 2023 11:05 am

DL4LEX wrote:
Wed Mar 01, 2023 10:46 am
Yes, that's the only way I found.

The linker by it's own does not seem to be able to handle multiple .text* section.
Yes.

Also the percentage of ROM usage which is displayed by the linker is does not seem to be correct

DL4LEX
Posts: 62
Joined: Sat Nov 16, 2019 3:09 pm

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by DL4LEX » Wed Mar 01, 2023 11:19 am

There is another option to move complete *.o files to the .upper_text section:

Code: Select all

    .text_main : ALIGN(4)
    {
       *(EXCLUDE_FILE(*main.o *codec.o).text* )
       *(.rodata .rodata.* .constdata .constdata.*)
       . = ALIGN(4);
       _etext = . ;
    } > PROGRAM_FLASH
and

Code: Select all

    .upper_text : ALIGN(4)
    {
        *codec.o (.text*)
        *main.o (.text*)
        *(.upper_text)
       . = ALIGN(4);
    } > PROGRAM_FLASH
This moves all functions from main.c and codec.c to the upper_text section.

I don't known why the percentage is incorrect. But as long as the linker thinks it fits everything should be ok.

VK3KYY
Posts: 7481
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Porting to the Retevis RT50 (aka TYT MD-680D)

Post by VK3KYY » Wed Mar 01, 2023 8:52 pm

Ale x

What is the reason for using

(.upper_text)

Instead of

*(.rodata .rodata.* .constdata .constdata.*)


I used *(.rodata .rodata.* .constdata .constdata.*) for the upper_text and it seemed to work OK

Re: moving all functions from each file

This is clever, but I think could cause maintenance problmes, if functions were added to those .c files, because there could be space in the main .text block, but no space in upp_text

I tried to move the font data to upper_text but it is too big. I also tried moving the language strings, but they are also too big.

The biggest font will not fit in upper_text on its own, which is surprising

AFIK upper_text should be 11k

Post Reply