-
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
[WIP] Factorise stm32 and sam0 linker scripts #7729
Conversation
2b1b89c
to
ffdd8d5
Compare
Well I pushed the removal of all linker scripts and let Murdock take a look. He agrees so there's no harm on removing them. Thus, only testing is left. |
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 like the idea of reducing the number of scripts, but I am a bit sceptical to extending the board makefiles on every board like this. This complicates the makefile creation for new board ports. The boot loader offset is fine in a board makefile but the cpu properties for rom and ram length should be more centralized. Is there any way to deduce the rom and ram sizes from the model number?
I started working on a similar thing for kinetis but I have not had time to finish it. Those CPUs have the rom size as part of the model number.
|
||
MEMORY | ||
{ | ||
rom (rx) : ORIGIN = 0x08000000 + boot_offset, LENGTH = rom_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.
If you subtract boot offset from the length you will have one less source of mistakes in the makefiles.
MEMORY | ||
{ | ||
rom (rx) : ORIGIN = 0x00002000, LENGTH = 256K-0x2000 | ||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 32K | ||
rom (rx) : ORIGIN = 0x00000000 + boot_offset, LENGTH = rom_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.
If you subtract boot offset from the length you will have one less source of mistakes in the makefiles.
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 thought about it but wanted to make it explicit... maye is not necessary so I'll change with your suggestion.
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.
Very nice effort, I like it! But please do it in a clean way -> use the logical CPU structure that is there instead of starting with ugly else-if blocks!
makefiles/arch/cortexm.inc.mk
Outdated
@@ -16,7 +16,16 @@ export CFLAGS += $(CFLAGS_CPU) $(CFLAGS_LINK) $(CFLAGS_DBG) $(CFLAGS_OPT) | |||
|
|||
export ASFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) | |||
export LINKFLAGS += -L$(RIOTCPU)/$(CPU)/ldscripts -L$(RIOTCPU)/cortexm_common/ldscripts | |||
export LINKER_SCRIPT ?= $(CPU_MODEL).ld | |||
|
|||
ifneq (,$(filter stm32%,$(CPU_FAM))) |
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 seems wrong. There should be no multiplexing for different families in the shared cortex code tree. Instead, this should be handled by the families makefiles!
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.
To be more precise: leave export LINKER_SCRIPT ?= $(CPU_MODEL).ld
in this file. But move the other two options to the corresponding cpu family makefile.includes. As we use ?=
for assignment here, and the family makefiles are passed before this one, the more specific values prevail.
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 prefer your suggestion, I was looking where to put it but didn't think about ?=
(it always happen...). Will fix.
@@ -17,7 +21,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 LINKER_SCRIPT ?= $(RIOTCPU)/sam0_common/ldscripts/$(CPU_MODEL)_arduino_bootloader.ld |
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.
what is this about? Just commenting out seems not the right way to proceed here?!
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.
Oops, sorry, I commented it out first to test and forgot to remove it, since actually the file doesn't exist anymore in this PR.
Two more comments: |
done, see #7731 |
Unfortunately not, for some models the trailing letters mean the memory sizes but for some other models the letters are completely different. I agree it's a bit of overhead setting so many variables (two, after #7731 gets merged), and indeed maybe not in the right place, except for the offset. What I suggest is maybe still use 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.
Found some remaining commented lines that could be removed.
Just one remark: would it be possible to just introduce news variables like RAM_LENGTH, ROM_LENGTH, ROM_OFFSET etc in the board Makefile and use them in makefiles/arch/cortexm.inc.mk ?
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=offset=$(ROM_OFFSET)
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=rom_length=$(ROM_LENGTH)
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=ram_length=$(RAM_LENGTH)
boards/opencm904/Makefile.include
Outdated
@@ -3,7 +3,7 @@ export CPU = stm32f1 | |||
export CPU_MODEL = stm32f103cb | |||
|
|||
# custom linkerscript | |||
export LINKER_SCRIPT = stm32f103cb_opencm904.ld | |||
#export LINKER_SCRIPT = stm32f103cb_opencm904.ld |
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 needs to be removed as well
boards/spark-core/Makefile.include
Outdated
@@ -3,7 +3,7 @@ export CPU = stm32f1 | |||
export CPU_MODEL = stm32f103cb | |||
|
|||
# the spark-core uses its own custom linkerscript... | |||
export LINKER_SCRIPT = stm32f103cb_sparkcore.ld | |||
#export LINKER_SCRIPT = stm32f103cb_sparkcore.ld |
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.
remove
@aabadie I was thinking the same thing. Also RAM and ROM base addresses could be configurable. This would let us eliminate both the Kinetis and the stm32 ldscripts. |
I like that too. I will do it and let's see how it looks like. However I still have the question of where to define those variables, if at the board level or split them up at both board and cpu level with some |
960dc26
to
820d665
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.
Nice changes!
And nearly done, except the remaining commented out lines and @gebart comment about subtracting offset from rom size.
cpu/sam0_common/Makefile.include
Outdated
@@ -7,6 +7,14 @@ 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 | |||
|
|||
ifdef ROM_OFFSET | |||
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=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.
you need 2 spaces indent here
cpu/stm32_common/Makefile.include
Outdated
@@ -8,5 +8,14 @@ USEMODULE += periph_common | |||
# include stm32 common functions and stm32 common periph drivers | |||
USEMODULE += stm32_common stm32_common_periph | |||
|
|||
ifdef ROM_OFFSET | |||
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=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.
2 spaces indent
@@ -6,6 +6,10 @@ export CPU_MODEL = samd21g18a | |||
export PORT_LINUX ?= /dev/ttyACM0 | |||
export PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*))) | |||
|
|||
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.
This should only be defined when using bossa programmer, with jlink programmer the bootloader is overwritten.
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 yes! I forgot, will change.
It's ongoing, I'm pushing just to see if Murdock complains, since I need to be sure all boards still compile without issues. I'll say explicitly when it's ready again. Thanks for the feedback @aabadie ! |
I addressed most of the comments, it remains to move all the defines for ROM and RAM size at the cpu level. |
Thinking of it, there's also a README in cpu//sam0_common/ldscripts/ that could be removed by this PR |
It's removed. |
Well I think it's done, can I squash to start a new clean review? @gebart @haukepetersen @aabadie ? |
3e3736e
to
5a31d9c
Compare
I'd like to close it when #7799 gets merged. Is it OK for you? |
More or less, we want to do some clean up in opened PRs, then no. |
No, I don't think this would be merged one day, I just wanted to leave it open for reference, but I have no problems closing it. Thus, let it be! |
Thanks @kYc0o ! |
This PR aims to remove all linker scripts for the stm32 and sam0 CPU families, by replacing them by a common linker script which accept ROM and RAM size variables. It also sets the CPU_ID and ccmram (but not used in main cortex_common.ld) for the stm32 family.
Besides removing all redundant linker scripts, this PR also allows to set an offset length at the beginning of the ROM, which is needed for some boards with embedded bootloaders. It also allows to skip a given ROM area for custom bootloaders.
I did some tests for some boards, but I think a wide testing might be required for the affected boards, which are quite a few.
Here there is a list which should be completed if possible before merging this PR.
Once all or most of the boards are tested, I'll add a last commit which removes all the unnecessary linker scripts. Any help is very much appreciated!
I'd like to merge first this one before #7727 and #7725, and rather ask the authors to adapt for this PR.