-
Notifications
You must be signed in to change notification settings - Fork 8.2k
linker: aarch32: automatic derivation of region names from devicetree nodes #36365
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
linker: aarch32: automatic derivation of region names from devicetree nodes #36365
Conversation
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.
Just focusing on the main change here.
Have you considered using a string-valued property instead?
You could use the DT_STRING_TOKEN macro being added in #35460 to tokenize a string. That would in turn avoid the fragility of this approach.
include/linker/devicetree_regions.h
Outdated
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 doesn't seem like a good idea to me. It seems quite fragile. Users should be free to add whatever kind of node labels they want to any nodes without modifying things like this.
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.
As long as users use DT_REGION_NAME(node_id) in linker scripts, it is not possible to break this setup AFAICT.
Any changes in the name caused by overlays will automatically propagate through to the linker scripts.
Users are absolutely free to add labels as they wish, its just that the last one applied will be the name generated by the linker.
This was the approach taken in #36196. The downsides listed there were:
Adding a new property is the wrong path forward IMO as by definition no existing nodes will have it.
Quoted vs unquoted strings doesn't actually make a difference for the region names. I am unsure how this affects fragility? |
|
OK, I thought the region names were being used to form variable names and therefore need to be unquoted. If they're always just strings then DT_STRING_TOKEN is not needed and you can just use a string valued property. I still feel pretty strongly that "pick whatever the last node label is" is the wrong approach though, for the reasons I've already given. If you're not comfortable with a string property, can you suggest an alternative? |
Personally I don't mind whether its node label or string property. The node label approach was suggested by @henrikbrixandersen and @erwango and I agreed that their reasons were sound. I don't understand the reasons you have given. Users are free to give whatever node labels they want to nodes. This isn't fragile because you can always get the output region name via At the end of the day it doesn't really matter what that name is, as long as it is derived from the node. Why introduce another property when we already have a human readable, unique, node label to base it on? |
Precisely because node labels are not unique. Picking one arbitrarily feels really wrong to me. Node labels are just arbitrary ways to refer to nodes and I don't think it's sound to just pick one and use it as a name in code. |
#36196 (comment) suggested they were unique, and testing this morning appears to validate that: results in this when compiling:
It doesn't matter which property or label we choose to generate the names from, users don't interact with it in any way apart from seeing the name in the final memory usage summary. All usage in code/linker scripts is via |
OK, we're using 'unique' in different ways. A single node label is unique treewide (your meaning), but a node does not have a single unique node label (my meaning).
If it's not visible to the user at all, why not just use ordinal numbers then? |
They're not visible in code, it is visible in the final memory usage summary: Replacing vs |
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 think the general approach looks sane.
Will let @mbolivar-nordic and @galak drive the naming part / node label as they are the experts here.
Found a couple of minor nits to be fixed.
@mbolivar-nordic maybe you can elaborate ?
which then corresponds to the node label here: zephyr/dts/arm/ti/cc2652r.dtsi Line 24 in f5e5f7d
Now, currently on master, that memory section would be named So already today, the node label The labels in use before and after this PR haven't changed, from what I can see. |
Right, but that is different: that is taking a node label, getting a node identifier from it. DT_NODELABEL takes a node label and returns a node identifier from it. It does not return a node label.
Right, so the linker script author is responsible for naming the memory region using the first argument to DT_REGION_FROM_NODE_STATUS_OKAY, and we can see the list of them in one place.
Right, and that is still what I'm not convinced about. The fact that the memory section names are not predictable and depend on whatever node label the tooling happens to choose feels like the wrong thing to me. I can understand @JordanYates 's objection that having a bunch of ordinal numbers is not good for the |
Fair enough. Question is, is the DT the logical place for controlling the memory section names by adding an additional naming 🤔 ? Imaging on slack, someone posting a problem:
In most cases we can probably deduce that I would really like to see an issue that clearly describes the problem with today's solution, and what use-cases such a change will handle, so that we can also consider if there might be other side-effects we have not considered (like helping users with issues later). |
The goal of this PR is to enable automatically generating regions from devicetree. Which would just automatically create a region for every sram node on the device, instead of the current setup where every new SRAM label on some SoC requires adding SoC specific code to the main linker scripts (sram1 through 4, sdram1 and sdram2, etc). This is required for all automatic integration between devicetree and the linker, not just SRAM. For this to work the name needs to be derived from the node itself, it can't be manually provided. Being able to rename the regions is merely a side effect of the name now coming from the node. |
|
I'm not a huge fan of the node path option. It looks okay for SRAM nodes, These paths also don't contain the information that actually differentiates multiple instances of the same node from each other (beyond the address). Without digging into the .dts, you don't have any idea whether that second path is a In short I think the path is great as a unique identifier, but bad at containing the information you actually want in the memory summary. Whereas the node label is explicitly chosen as a short, human readable string that has some meaning. If the fact that the name can change based on what the user does is a significant problem and not a benefit, then we can just use the first label instead of the last. This will just result in regions always having the label from their original definition. ( |
But this is not what this PR does now.
Now, that sounds like a good use-case. btw. thanks for the extended reasoning. I think some of that info should be copied to the description of this PR. |
|
I think we all agree that node labels are meaningful identifiers. The disagreement seems to be about whether they are the right identifiers to be using in this context. It seems like @tejlmand shares my concerns about making an arbitrary choice. I'm not convinced about the proposal "just pick the first node label" as a workaround. I generally remain unconvinced that any arbitrary choice (first, last, middle, whatever) is going to produce a good result in the case of multiple node labels. And thinking about it a bit more, requiring users to put at least one node label seems like an avoidable requirement also. Using a property like |
|
(Or if a zephyr-specific property won't work, |
|
A summary of my arguments against each option. Each option that requires some value to exist could instead have some sane fallback, be that the path or some new value as proposed by @mbolivar-nordic. I am still of the opinion that the arbitrariness of the name doesn't really matter, as long as it is predictable, consistent and useful. After all, Node Label:
Node Path:
Custom Property:
Label Property:
|
|
Thanks for the summary; very useful.
A reminder that I pointed out uniqueness guarantees for a custom property can be enforced by gen_defines.py. And we could revive #32682 for the label property. So I don't think the points about lack of uniqueness guarantees hold.
I think I already addressed that too above:
|
`UTIL_DECR` was removed in #de8457 with the transition to brute force `FOREACH` macros. This macro is however still useful in the context of converting a `_NUM` define to an index to the last value, which would otherwise require some combination of `NUM_VA_ARGS_LESS_1` and `UTIL_LISTIFY`. The special case of `#define Z_DECR_0 0` was copied from the previous implementation. Signed-off-by: Jordan Yates <[email protected]>
Test the re-introduced `UTIL_DECR` macro. Signed-off-by: Jordan Yates <[email protected]>
Add definitions that allow users to go from a node identifier back to the original node labels. Signed-off-by: Jordan Yates <[email protected]>
Add a comment to separate the children related macros from whats above in the generated `devicetree_unfixed.h` file. Signed-off-by: Jordan Yates <[email protected]>
Adds functions to query the node labels of a node. The awkward naming of `DT_NODE_NUM_NODELABEL` and `DT_NODE_NODELABEL_BY_IDX` is due to `DT_NODELABEL` already being defined to get a node from a nodelabel. Signed-off-by: Jordan Yates <[email protected]>
Test the new node label retrieval API's. Signed-off-by: Jordan Yates <[email protected]>
Generate memory region names from devicetree nodes instead of using
hardcoded values. Region names can be overridden by using an overlay
similar to the following:
```
new_region_name: &sram1 {};
```
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`. Signed-off-by: Jordan Yates <[email protected]>
|
dev-review (Jul 22, 2021):
|
|
Clearing |
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
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.
The next step is to transition to something like:
For SRAM generation, to eliminate SoC specific node labels from the core linker script.