-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ld: refactor sam0 ldscripts #7739
Conversation
696a9c0
to
ada52bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
@@ -17,7 +17,7 @@ ifeq ($(PROGRAMMER),jlink) | |||
else | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this to be unconditionally assigned or do we want ?=
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree it's better with the conditional ?=
. Will change.
boards/opencm904/Makefile.include
Outdated
@@ -19,5 +16,7 @@ export DEBUGGER_FLAGS = | |||
PORT_LINUX ?= /dev/ttyACM0 | |||
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) | |||
|
|||
export ROM_OFFSET = 0x3000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto ?=
cpu/cortexm_common/Makefile.include
Outdated
@@ -5,3 +5,14 @@ INCLUDES += -I$(RIOTCPU)/cortexm_common/include/vendor | |||
USEMODULE += cortexm_common_periph | |||
|
|||
export IMAGE_HDR_SIZE ?= 512 | |||
|
|||
ifneq (,$(ROM_OFFSET)) | |||
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=rom_offset=$(ROM_OFFSET) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
cpu/sam0_common/Makefile.include
Outdated
export RAM_LEN = 0x8000 | ||
endif | ||
|
||
ROM_START_ADDR ?= 0x00000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, I agree, it's generalized enough in this place.
cpu/sam0_common/Makefile.include
Outdated
@@ -1,11 +1,20 @@ | |||
# Define the CPU family so we can differentiate between them in the code | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. All SAMXxxY18 model have 256KB of flash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, like I wrote above, this is fine here now. This can be refactored later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW SAML21J18B is missing from the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we support such mcu?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't find it in the current base code, however it is in the vendor headers. I'll add it.
cpu/sam0_common/Makefile.include
Outdated
endif | ||
|
||
ROM_START_ADDR ?= 0x00000000 | ||
RAM_START_ADDR ?= 0x20000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good default for any cortex m
* @{ | ||
* | ||
* @file | ||
* @brief Memory definitions for the cortexm family |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Cortex-M family"
boards/spark-core/Makefile.include
Outdated
@@ -21,5 +18,7 @@ export FFLAGS = -d 1d50:607f -a 0 -s 0x08005000:leave -D "$(HEXFILE)" | |||
|
|||
export INCLUDES += -I$(RIOTCPU)/$(CPU)/include/ -I$(RIOTBOARD)/$(BOARD)/include/ | |||
|
|||
export ROM_OFFSET = 0x5000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?=
?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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..
@@ -17,7 +17,7 @@ ifeq ($(PROGRAMMER),jlink) | |||
else | |||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is necessary to export this, could you try without export
?
cpu/sam0_common/Makefile.include
Outdated
@@ -1,11 +1,20 @@ | |||
# Define the CPU family so we can differentiate between them in the code | |||
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))) | |||
export ROM_LEN = 0x40000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you try this without export
?
@gebart fixed. Murdock agrees so without export it works well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fine now 👍
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment needs updating
cpu/sam0_common/Makefile.include
Outdated
# this CPU implementation doesn't use CMSIS initialization | ||
export CFLAGS += -DDONT_USE_CMSIS_INIT | ||
|
||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reword: "use shared Cortex-M linker script"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe common
@@ -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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and below: comment needs updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, BOSSA is the default flash tool (for these boards).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK.
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: