Linker problem with Kinetis demos

ChibiOS public support forum for topics related to the Freescale Kinetis family of micro-controllers.

Moderator: utzig

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Linker problem with Kinetis demos

Postby Giovanni » Sun Jan 03, 2016 12:38 pm

Hi,

I noticed that the .ld files do not use the common rules.ld, because of this there are errors caused by the updated startup files. The .ld files should be updated to export the required symbols for the extra RAM sections, please see rules.ld.

Giovanni

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Linker problem with Kinetis demos

Postby utzig » Sun Jan 03, 2016 1:37 pm

Why are all those ramX sections needed?

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Linker problem with Kinetis demos

Postby utzig » Sun Jan 03, 2016 2:08 pm

Well,

I changed locally the linker script and added -DCRT1_AREAS_NUMBER=1 to the makefile. That fixes the first problem. Now linking fails with error:

Code: Select all

arm-none-eabi/bin/ld: build/ch.elf section `.isr' will not fit in region `flash0'
arm-none-eabi/bin/ld: region `flash0' overflowed by 64 bytes


Although flash0 is 0xc0 sized and there are 32 vectors, which gives 0xc0 - 0x80 = 64 bytes free. Unless somehow the compiler is thinking vectors are 8 bytes... does that make sense?

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Linker problem with Kinetis demos

Postby utzig » Sun Jan 03, 2016 2:43 pm

Ok, fixing myself, the correct calculation for number of used vectors is 15+32 which gives 0xc0 space required! Which also must be the explanation for I using that for flash0 size in the linker script.

To fix the build I removed the aligned(128) in os/common/ports/ARMCMx/compilers/GCC/vectors.c line 438. Not sure why that's necessary. Either fix that way or change flash0 to be 0x100 sized. I will try both in the board and see if they work...

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Linker problem with Kinetis demos

Postby utzig » Sun Jan 03, 2016 2:52 pm

Ok, both solutions worked! So aligned(128) just means the it the vectors section must be a multiple of 0x80, correct? Not sure yet what's the reasoning...

Anyway I'll commit the changes I had to make (for the KL25Z demo only for now) and look into merging with the standard rules.ld script later because I'm hungry now and this thread is turning into a personal diary already...

Cheers

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Linker problem with Kinetis demos

Postby Giovanni » Sun Jan 03, 2016 3:37 pm

Hi,

The vectors address must be aligned to 128, the size not necessarily. It is a restriction of the base register.

Giovanni

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Linker problem with Kinetis demos

Postby utzig » Sun Jan 03, 2016 10:41 pm

I updated the linker scripts using rules.ld as reference. The problem of not being able to reuse rules.ld like the STM32 ports do, is that in Kinetis there's one small flash section at the beginning (flash0), then the flash protection segment, than the remaining of the flash. So I have to use 3 sections. When including rules.ld either before or after my custom declaration of the flash0 + protection, those sections or the default sections in rules.ld will not be allocated in the correct position. I would need something like ram0, ram1, ram2 equivalents for flash to make that work. Do you know of any other workaround?

Cheers,
Fabio Utzig

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Linker problem with Kinetis demos

Postby Giovanni » Sun Jan 03, 2016 10:47 pm

Hi,

Good point I think it is a good idea. Do you think we should delay the release for this or can it go in next one?

Giovanni

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Linker problem with Kinetis demos

Postby utzig » Sun Jan 03, 2016 10:56 pm

I think it is ok as it is right now. It has a lot of duplication which could be fixed later. Also there are only two linker scripts (very similar btw!) so these changes can be postponed.

utzig
Posts: 359
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 20 times
Contact:

Re: Linker problem with Kinetis demos

Postby utzig » Sun Jan 03, 2016 11:12 pm

Btw, I commited the fixes only to trunk, is that enough?


Return to “Kinetis Support”

Who is online

Users browsing this forum: No registered users and 17 guests