ld: refactor sam0 ldscripts#7739
Conversation
696a9c0 to
ada52bc
Compare
jnohlgard
left a comment
There was a problem hiding this comment.
This is a good initiative for reducing the maintenance burden.
Some questions about the implementation:
- Symbol names, should we use a prefix to avoid name clashes with c code? Sometimes linker scripts use single or double underscores to avoid collisions with variables and functions.
- Special segment types. How do we specify special segments, like the CCM ram in stm32, without polluting the generic linker script?
| # by default, we use BOSSA to flash this board and take into account the | ||
| # preinstalled Arduino bootloader. | ||
| export LINKER_SCRIPT ?= $(RIOTCPU)/sam0_common/ldscripts/$(CPU_MODEL)_arduino_bootloader.ld | ||
| export ROM_OFFSET = 0x2000 |
There was a problem hiding this comment.
Do we want this to be unconditionally assigned or do we want ?= instead?
There was a problem hiding this comment.
Yes, I agree it's better with the conditional ?=. Will change.
boards/opencm904/Makefile.include
Outdated
| PORT_LINUX ?= /dev/ttyACM0 | ||
| PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) | ||
|
|
||
| export ROM_OFFSET = 0x3000 |
cpu/cortexm_common/Makefile.include
Outdated
| export IMAGE_HDR_SIZE ?= 512 | ||
|
|
||
| ifneq (,$(ROM_OFFSET)) | ||
| LINKFLAGS += $(LINKFLAGPREFIX)--defsym=rom_offset=$(ROM_OFFSET) |
There was a problem hiding this comment.
I would actually prefer to just assign this to 0 by default and always pass the linker symbol on the command line.
Fewer conditionals in the makefiles make them easier to read IMO.
| { | ||
| rom (rx) : ORIGIN = rom_start_addr + boot_offset, LENGTH = rom_length - boot_offset | ||
| ram (rwx) : ORIGIN = ram_start_addr, LENGTH = ram_length | ||
| ccmram (rwx): ORIGIN = ccmram_start_addr, LENGTH = ccmram_length |
There was a problem hiding this comment.
This is an stm32 specific kind of memory. Is there not another way to get this segment into the linker?
There was a problem hiding this comment.
Actually this segment is not used at all in our current cortexm_base.ld
Maybe we can discuss this when we figure out how to use this RAM? I mean to remove it from the MEMORY section but still define it to know which CPUs implement it, and then when we use this segment add it either in this linker script or somewhere else.
| export RAM_LEN = 0x8000 | ||
| endif | ||
|
|
||
| ROM_START_ADDR ?= 0x00000000 |
There was a problem hiding this comment.
This could actually go in the cortex m makefile. These addresses are sensible defaults for any cortex m CPU and can be overridden in the CPU specific makefiles where they differ instead.
There was a problem hiding this comment.
Hmmm... As far as I understand the memory spaces are not defined by ARM in an explicit way, but it's up to the silicon vendors to allocate their ROM and RAM to any address.
In RIOT we have, for ROM, at least 3 examples:
- cc2538 at 0x00200000
- stm32 family at 0x08000000
- kinetis, nordic and sam at 0x00000000
For RAM is even more varied:
- cc2538 generally at 0x20000000, but for some models at 0x20004000
- kinetis, stm32 and sam0 at 0x20000000
- NXP at 0x10000000, some at 0x40000000
- sam3x8e at 0x20070000
Thus, in my opinion use standard values seem dangerous.
There was a problem hiding this comment.
alright, I agree, it's generalized enough in this place.
cpu/sam0_common/Makefile.include
Outdated
| CFLAGS += -DCPU_FAM_$(shell echo $(CPU_FAM) | tr 'a-z-' 'A-Z_') | ||
|
|
||
| # Set ROM and RAM lengths according to CPU model | ||
| ifneq (,$(filter samd21g18a samd21j18a saml21j18a samr21g18a,$(CPU_MODEL))) |
There was a problem hiding this comment.
This is fine here for now, but you could also try to use a wildcard or parse the size from the model number if you're feeling experimental. I'm guessing the 18 in the model is the rom size? (2**18 = 0x40000 = 256 KB)
There was a problem hiding this comment.
You're right. All SAMXxxY18 model have 256KB of flash.
There was a problem hiding this comment.
I thought about this but my skills in make made me feel insecure. Besides the fact that I think is better to explicitly state which are the memory capabilities of a given CPU model.
If you really want this I'll ask my "make guru" colleagues how to do it.
There was a problem hiding this comment.
no, like I wrote above, this is fine here now. This can be refactored later.
There was a problem hiding this comment.
BTW SAML21J18B is missing from the line.
There was a problem hiding this comment.
Do we support such mcu?
There was a problem hiding this comment.
Yes, SAML21-XPRO board can be equipped with SAML21J18A or SAML21J18B. I also heard Rev C is on the way.
SAML21J18A were only early engineering sample, Atmel does NOT sell them. Only SAML21J18B are sold.
There was a problem hiding this comment.
Oh, I didn't find it in the current base code, however it is in the vendor headers. I'll add it.
| endif | ||
|
|
||
| ROM_START_ADDR ?= 0x00000000 | ||
| RAM_START_ADDR ?= 0x20000000 |
There was a problem hiding this comment.
Good default for any cortex m
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Memory definitions for the cortexm family |
boards/spark-core/Makefile.include
Outdated
|
|
||
| export INCLUDES += -I$(RIOTCPU)/$(CPU)/include/ -I$(RIOTBOARD)/$(BOARD)/include/ | ||
|
|
||
| export ROM_OFFSET = 0x5000 |
|
SAML21 has a low-power embedded SRAM in addition to the standard SRAM. |
I think a |
504239e to
4f6352b
Compare
I don't have a strong opinion on this, but it seems legit to me. Which one you prefer the most?
I removed this special segment on the generic script. I think it make sense to put the specific regions in a specific linker script for each family (I didn't see a specific CPU implementing weird regions on RAM or ROM, but rather a whole CPU family), as I propose in my last fixup at #7799. |
|
@kYc0o I suggest single underscore prefixes since we already have some symbols with that prefix in the cortexm_common ldscript |
|
Added underscores to variables. |
jnohlgard
left a comment
There was a problem hiding this comment.
Looks fine, could you just see if it still works without the export? (see comments)
I realized we are exporting a lot of stuff that we don't need to when we had that problem with Makefile.dep last week..
| # by default, we use BOSSA to flash this board and take into account the | ||
| # preinstalled Arduino bootloader. | ||
| export LINKER_SCRIPT ?= $(RIOTCPU)/sam0_common/ldscripts/$(CPU_MODEL)_arduino_bootloader.ld | ||
| export ROM_OFFSET ?= 0x2000 |
There was a problem hiding this comment.
I don't think it is necessary to export this, could you try without export?
cpu/sam0_common/Makefile.include
Outdated
|
|
||
| # Set ROM and RAM lengths according to CPU model | ||
| ifneq (,$(filter samd21g18a samd21j18a saml21j18a samr21g18a,$(CPU_MODEL))) | ||
| export ROM_LEN = 0x40000 |
There was a problem hiding this comment.
could you try this without export?
|
@gebart fixed. Murdock agrees so without export it works well. |
|
please squash |
|
@kYc0o ping please squash |
|
oops, almost forgot. |
236178b to
a889df3
Compare
|
squashed. |
|
Need to fix feather-m0. |
|
Oh it got merged before this one... Will fix. |
a889df3 to
0815de0
Compare
kaspar030
left a comment
There was a problem hiding this comment.
sorry, some more change requests
| @@ -17,7 +17,7 @@ ifeq ($(PROGRAMMER),jlink) | |||
| else | |||
| # by default, we use BOSSA to flash this board to take into account the | |||
There was a problem hiding this comment.
the comment needs updating
cpu/sam0_common/Makefile.include
Outdated
|
|
||
| # for the sam[drl] CPUs we hold all linkerscripts in the sam0 common folder | ||
| export LINKFLAGS += -L$(RIOTCPU)/sam0_common/ldscripts | ||
| # For Cortex-M cpu we use the cortexm.ld linker script |
There was a problem hiding this comment.
reword: "use shared Cortex-M linker script"
| @@ -17,7 +17,7 @@ ifeq ($(PROGRAMMER),jlink) | |||
| else | |||
| # by default, we use BOSSA to flash this board and take into account the | |||
There was a problem hiding this comment.
here and below: comment needs updating
There was a problem hiding this comment.
I don't think so, BOSSA is the default flash tool (for these boards).
There was a problem hiding this comment.
I updated it accordingly.
There was a problem hiding this comment.
Ok, I was looking at fixed version but the initial comment is still there ;)
|
@kaspar030 I addressed your comments, I suppose I could have squashed directly but forgot it... |
5a5ec37 to
ec9897f
Compare
|
So I guess @kaspar030 just has to ACK and we go |
|
@kaspar030, can you ACK this one ? |
|
pinging again @kaspar030, just in case :) |
|
@kaspar030 can we dismiss your review and merge this one ? |
|
Thanks! the story continues in #7799 ... |
This PR is a subset of #7729, I split it to ease review and understand better the concept.
The goal is to get rid of every specific linker script associated to a specific CPU model, and factorise it to allow CPU specific definitions like start address and boot offset.
This would give us flexibility to:
Boards to be tested: