-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Switch flash_map to resolve devices at compile-time instead of using device_get_binding #33346
Switch flash_map to resolve devices at compile-time instead of using device_get_binding #33346
Conversation
@@ -21,6 +21,19 @@ config FLASH_MAP_SHELL | |||
help | |||
This enables shell commands to list and test flash maps. | |||
|
|||
|
|||
config FLASH_MAP_DEV_NAME_IN_FLASH_AREA |
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.
Maybe for backward compatibility this option should enforce device binding behavior in the code?
#if defined(CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA) && defined(FLASH_MAP_DEV_NAME_IN_FLASH_AREA)
if (fa->fa_dev == NULL) {
flash_dev = device_get_binding(fa->fa_dev_name);
if (flash_dev == NULL) {
return -ENODEV;
}
}
#endif
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 have such variant of the PR if desired. I have thought about the options and I now think, since that we allow custom flash_map to be developed, that user may fail to deliver device bindings so the option to use the new compile time resolution should be default for non custom maps.
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 agree with you.
I was about to write comment with suggestion to make he new compile time resolution should be default.
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 defined(CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA) && defined(FLASH_MAP_DEV_NAME_IN_FLASH_AREA)
if (fa->fa_dev == NULL) {
flash_dev = device_get_binding(fa->fa_dev_name);
if (flash_dev == NULL) {
return -ENODEV;
}
}
#endif
3de5c86
to
ecf557c
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.
FLASH_MAP_DEV_IN_FLASH_AREA=y
FLASH_MAP_USE_DEV_IN_FLASH_AREA=n
makes fa_dev
field meaningless. This doesn't make sense.
That is in case when user wants to use fa_dev for something other than flash map API. |
Is there any user case? I understand that user might want either I feel that so simple subsystem have to much option with this patch. |
I don't know. I will default the one choice: if
I am not sure I want to add such option: the selection should go either way, if use the
Will reduce the |
ecf557c
to
5a8cdc1
Compare
@de-nordic Looks ok to me now. Need to align a few flash_area structure usage from the codebase, |
5a8cdc1
to
bc8f3a7
Compare
bc8f3a7
to
592bfa4
Compare
We will probably dump the |
@de-nordic, @nvlsianpu, can't we get rid of flash_map? Since all information can be received from the dts, I would expect this to be replaced by a |
Cannot yet. The msuboot and mcumgr use integer IDs for figuring which partition to operate on. Within Zephyr, internally we probably could do that. |
If required by mcuboot/mcumgr, these things should move into mcuboot/mcumgr code. |
322275b
to
c14d616
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.
-1 for now because I'm not comfortable with this at first blush and want to take a longer look at this today
subsys/storage/flash_map/Kconfig
Outdated
The option is selected for default flash map (FLASH_MAP_CUSTOM=n); if your custom map | ||
populates the flash_area.fa_dev, with pointers to devices that are tied to proper flash | ||
areas, you may want to unselect this option. |
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 understand this.
The option is selected
Nothing I can see select
s this option if FLASH_MAP_CUSTOM=n, it's just default y
in that case. That is not the same thing.
if your custom map [...] you may want to unselect this option.
I don't understand what this is trying to say, either.
First, I think using the word "unselect" in this context is unclear because Kconfig has a select
keyword that you cannot undo.
Second, it seems to me that the only way to both have a custom map (CONFIG_FLASH_MAP_CUSTOM=y
) and populate fa_dev
pointers is if the user manually sets them up, so why would they want to make sure CONFIG_FLASH_MAP_DEV_IN_FLASH_AREA=n
?
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 will fix the comments.
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.
Seems that I have merged comments from two different options.
@de-nordic @nvlsianpu I'm confused about why this is being done this way. I feel like we've been carrying a bunch of legacy stuff from the mynewt operating system in Zephyr's mcuboot port that I don't understand the need for and this seems to be adding on top of it instead of fixing the underlying issue. From what I recall, Grepping a bit more, I only see
Those are write-only, just putting the value into the So it seems to me we could do this in a couple of different ways that would have lower footprint. Option 1 Stick with the mynewt HAL names, but change struct flash_area {
uintptr_t fa_device_id;
off_t fa_off;
size_t fa_size;
uint8_t fa_id;
}; Then set Zephyr is already using differently sized types for the fa_size and fa_off members (we use Option 2 Take this to upstream MCUboot and change it so this bootloader doesn't force design decisions made by the mynewt RTOS onto other operating systems. From what I can tell, that would basically mean changing the struct boot_rsp {
const struct image_header *br_hdr;
flash_dev_id_t br_flash_dev_id;
uint32_t br_image_off;
}; which Zephyr's flash map backend could handle like this: typedef const struct device* flash_dev_id_t; Then our flash_area structure can use a device pointer here too, with nicer results since there will be less casting to and from struct flash_area {
flash_dev_id_t fa_device_id;
off_t fa_off;
size_t fa_size;
uint8_t fa_id;
}; Am I missing something here? Why do we need to bloat this structure even more? |
To head off a potential objection, yes, I know that what I am proposing is an API change and that Flash map is stable. But I think we all agree that the current situation is just technical debt we inherited from another RTOS. We have a process for changing stable APIs and I think a change like this in particular is long overdue, especially now that we can avoid using device_get_binding() at all. |
@mbolivar This PR objective is to use compile time device binding instead of runtime binding. Legacy fa_dev_name field is kept optional only for backward compatibility. And yes, we should improve this code as you elaborated (I found both options usefully) and change the API. We want to limit this PR to already small change. API change we would do in very next PR. |
I guess I don't understand why this PR should be merged if it's adding a new Kconfig option that will be removed in the next PR. If the path forward to using compile-time struct devices is agreed upon -- it seems like you agree, would be good to know @de-nordic's thoughts too -- then why not pursue it? |
The mcuboot should not directly peek into flash_area, I have thought that we are giving it flash_map header and it blindly uses We could probably get rid of the The ifdefery and Kconfig options are provided because we let users to link custom flash maps, which means that we have let them adapt what they generate and actually give them option whether they want to adapt at all (at least for now).
I do not think that the Kconfig will be removed in next PR. The |
No, that's not correct. It needs the structure definition provided by a platform port. This is covered in https:/mcu-tools/mcuboot/blob/master/docs/PORTING.md. You can see in flash_map.h for Zephyr that It's not just documentation either. The mcuboot code looks directly into the
I wish! But since mcuboot is getting this definition from here, we can't do that without breaking mcuboot for the reason explained above. Try it and see; if you comment it out in Zephyr and build mcuboot, you will get this:
|
Yes, it also states that you may need to implement counters to protect flash area from closing it when it has been opened more than one time.
Then we should change mcuboot code to access the structure via API/macros only and make it take our flash area definition when compiled with Zephry
That was my wishful thinking.
So again that is not a job for simple PR that does switch from one API to other. There is more rework needed for both the mcuboot and the flash map API. |
The commit adds Kconfig option FLASH_MAP_DEV_IN_FLASH_AREA that enables addition of const struct device * type fa_dev field to the flash_area structure. Enabling this option will also populate fa_dev of each entry of the default flash map with a pointer to a device object that flash area described by the entry is tied to. The option switches flash map API to use the flash_area.fa_dev instead of obtaining device object by name, flash_area.fa_dev_name, by default. Signed-off-by: Dominik Ermel <[email protected]>
The flash subsystem API is switching from using fa_dev_name to fa_dev, of flash_area structure, making the fa_dev_name optional filed, controlled by Kconfig option CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA. Using fa_dev_name for logging makes it required field, so this commit removed the usage from log to remove dependency on the Kconfig option. Signed-off-by: Dominik Ermel <[email protected]>
The flash subsystem API is switching from using fa_dev_name to fa_dev, of flash_area structure, making the fa_dev_name optional filed, controlled by Kconfig option CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA. Using fa_dev_name for logging makes it required field, so this commit removed the usage from log to remove dependency on the Kconfig option. Signed-off-by: Dominik Ermel <[email protected]>
The flash subsystem API is switching from using fa_dev_name to fa_dev, of flash_area structure, making the fa_dev_name optional filed, controlled by Kconfig option CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA. Using fa_dev_name for device binding makes it required field, so this commit introduce binding using flash_area_get_device() which removes dependency on the Kconfig option. Signed-off-by: Andrzej Puzdrowski <[email protected]>
The flash subsystem API is switching from using fa_dev_name to fa_dev, of flash_area structure, making the fa_dev_name optional filed, controlled by Kconfig option CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA. Using fa_dev_name for device binding makes it required field, so this commit introduce binding using flash_area_get_device() which removes dependency on the Kconfig option. Signed-off-by: Andrzej Puzdrowski <[email protected]>
With switch to compile time resolved device object and usage of flash_area.fa_dev, the filed flash_area.fa_dev_name becomes optional as there are no more device_get_binding calls within flash_map that rely on that filed, or any other references to that field. The added Kconfig option, FLASH_MAP_DEV_NAME_IN_FLASH_AREA, allows to remove the flash_area.fa_dev_name field, when disabled. The option is set to y by default to support external code that may relay on the existence of flash_area.fa_dev_name. Configurations for samples and tests that require the fa_dev_name have been altered to have proper Kconfig options enabled. Signed-off-by: Dominik Ermel <[email protected]>
c14d616
to
5b8d8eb
Compare
I think this is not a good idea for a stable API. I made a pretty detailed proposal above and it seemed like we agreed on at least one of the options; can we figure out the right thing to do instead of just merging this? We seem to all agree that the inclusion of |
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. |
The PR contains series of commits that switch flash_map from using device_get_binding on flash_area.fa_dev_name
to using new filed flash_area.fa_dev, that is filled at compile time with a pointer to the flash device the flash_area is tied to.
This PR also contains commit that makes the filed flash_area.fa_dev_name optional, as it is no longer used within flash map API, but is left available for external code that relies on existence of this field.
Set to DNM due to ongoing tests.