Skip to content

Conversation

@JordanYates
Copy link
Contributor

Update the aarch32 linker file to automatically derive the name of memory regions from devicetree nodes instead of providing hardcoded values. This is required for automatic generation of regions based on compatibles, and also allows chosen and alias nodes to be used to control variable placement (as desired in #36152).

This PR is the first step to enable automatically generating regions from devicetree.

This is a rework of #36365 to address feedback.

@JordanYates
Copy link
Contributor Author

Copy link
Contributor

@galak galak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Need to move DT_NODE_LINKER_REGION to different header
  • Need to update docs for zephyr,linker-region

@mbolivar-nordic
Copy link
Contributor

Need to update docs for zephyr,linker-region

I wonder if it would be enough just to add this property to the specific compatibles that are expected to use it, with a nice multi-line description in the YAML. That would show up in the DT bindings index.

@JordanYates
Copy link
Contributor Author

Bindings have been moved to only mmio-sram and fixed-partition, with additional documentation added.

Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a naming nitpick. For which I apologize in advance...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you would probably want to consider removing attr at all (that at least for the GNU linker is optional). The problem is that when the MPU is present the actual attribute of the region (in terms of RWX) is defined by the MPU and by the attributes that we are using to mark the region and not by the linker.

If you think to introduce the mpu-attr we could think of obtaining this attr from the mpu-attr but that is hard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can be done in future PR's if needed. This is purely about updating where the names are coming from, I don't want to potentially introduce other problems here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is large enough as it it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm only concerned that all the future needed changes (mpu-attr, the FOR_EACH_.. macro, this fix on the _REGION_DECLARE, etc...) will require deep changes to the current state of this PR.

I have no objections on this PR if this is considered a first step.

@carlocaione
Copy link
Contributor

@JordanYates can you rebase and trigger the CI again?

@carlocaione
Copy link
Contributor

carlocaione commented Nov 22, 2021

Opened #40569 for the failing test

@carlocaione
Copy link
Contributor

On the other hand @JordanYates can you review #40422? I think a lot of the issues are already solved in my PoC so it could be worthwhile taking that into account.

@erwango
Copy link
Member

erwango commented Nov 25, 2021

@galak Would you mind reviewing again ?
@JordanYates Maybe you could have a try to rebase on latest master to see if the reported error is fixed now ?

@JordanYates
Copy link
Contributor Author

@JordanYates Maybe you could have a try to rebase on latest master to see if the reported error is fixed now ?

Done, I don't think it will make much difference though as the linked issue is still open

Copy link
Contributor

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

Please remember to add same support for the CMake based linker script generator.

And then a minor suggestion on naming,
Implementation wise, things looks good.

Comment on lines 35 to 36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have same behavior here, so that region names are picked up from devicetree if defined regardless of how the linker script is generated.

# TI CCFG Registers
zephyr_linker_dts_memory(NAME FLASH_CCFG FLAGS rwx NODELABEL ti_ccfg_partition)
# Data & Instruction Tightly Coupled Memory
zephyr_linker_dts_memory(NAME ITCM FLAGS rw CHOSEN "zephyr,itcm")
zephyr_linker_dts_memory(NAME DTCM FLAGS rw CHOSEN "zephyr,dtcm")
zephyr_linker_dts_memory(NAME SRAM1 FLAGS rw NODELABEL sram1)
zephyr_linker_dts_memory(NAME SRAM2 FLAGS rw NODELABEL sram2)
zephyr_linker_dts_memory(NAME SRAM3 FLAGS rw NODELABEL sram3)
zephyr_linker_dts_memory(NAME SRAM4 FLAGS rw NODELABEL sram4)
zephyr_linker_dts_memory(NAME SDRAM1 FLAGS rw NODELABEL sdram1)
zephyr_linker_dts_memory(NAME SDRAM2 FLAGS rw NODELABEL sdram2)
zephyr_linker_dts_memory(NAME BACKUP_SRAM FLAGS rw NODELABEL backup_sram)

which would be in this function where name from region property used, otherwise fallback on node path.

function(zephyr_linker_dts_memory)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@carlocaione carlocaione closed this Dec 9, 2021
@carlocaione carlocaione reopened this Dec 9, 2021
Jordan Yates added 5 commits December 9, 2021 20:34
Introduce optional `zephyr,linker-region` property which signifies that
the node should result in a linker memory region and what the name of
that region should be. Property added to compatibles likely to result
in a linker memory region; 'mmio-sram', 'arm,itcm`, `arm,dtcm`,
`nxp,imx-itcm`, `nxp,imx-dtcm` and `fixed-partitions`.

Signed-off-by: Jordan Yates <[email protected]>
Add checks to ensure that `zephyr,linker-region` property values are
always globally unique.

Signed-off-by: Jordan Yates <[email protected]>
Adds a macro to convert a devicetree node to the name of a linker memory
region.

Signed-off-by: Jordan Yates <[email protected]>
Add a new application for testing non-core devicetree functionality.
Add tests for the default and fallback case of
`LINKER_DT_NODE_REGION_NAME`.

Signed-off-by: Jordan Yates <[email protected]>
As memory region names are now derived purely from devicetree, remove
the `name` parameter from `DT_REGION_FROM_NODE_STATUS_OKAY`. Name is
`zephyr,linker-region` if it exists, otherwise the node path.

Signed-off-by: Jordan Yates <[email protected]>
Update the linker script generator to automatically derive memory
region names from the devicetree node according to the same logic in
`devicetree_regions.h`.

Signed-off-by: Jordan Yates <[email protected]>
Jordan Yates added 3 commits December 9, 2021 21:53
Remove the `NAME` function argument from `zephyr_linker_dts_memory` as
the name is now automatically derived from the devicetree node.

Signed-off-by: Jordan Yates <[email protected]>
Add `zephyr,linker-region` properties to all nodes sram1, sram2, sram3,
sram4, sdram1, sdram2, backup_sram, ti_ccfg, dtcm and itcm.

Signed-off-by: Jordan Yates <[email protected]>
Link variables into derived section names instead of hardcoded names.

Signed-off-by: Jordan Yates <[email protected]>
Copy link
Contributor

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes looks good.

# Common fields for devices resulting in linker memory regions

properties:
zephyr,memory-region:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing wrong on this line but with the latest update you are now using memory-region
👍 to that :)

But the commit message still says e06bc25:

dts: bindings: zephyr,linker-region property

Introduce optional zephyr,linker-region property

Note: same goes for some other commit messages.

Comment on lines +3381 to +3384
if (NOT DEFINED name)
# Fallback to the node path
set(name ${DTS_MEMORY_PATH})
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit, it's possible to do:

Suggested change
if (NOT DEFINED name)
# Fallback to the node path
set(name ${DTS_MEMORY_PATH})
endif()
set_ifndef(name ${DTS_MEMORY_PATH})

function(set_ifndef variable value)

Copy link
Contributor

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider cleanup the commit message before merging to avoid later confusion if later doing a bisect.

Approving as code looks good.

@carlescufi carlescufi merged commit f408f42 into zephyrproject-rtos:main Dec 9, 2021
@JordanYates JordanYates deleted the 210728_linker_name_prop branch August 15, 2022 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.