Skip to content

Introduce auto-listing of FlashArea Partitions #16874

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

Merged
merged 2 commits into from
May 2, 2025

Conversation

VynDragon
Copy link
Contributor

@VynDragon VynDragon commented Mar 7, 2025

Summary

This enables listing all flash area partitions automagically instead of just sotrage_partitions. It uses the label, and the ID when not present.

Testing

Tested on nrf52840

@VynDragon VynDragon force-pushed the FlashArea_automatic branch from 00b7051 to 80e44de Compare March 7, 2025 16:38
@ThinkTransit
Copy link
Contributor

This is a great addition and really helps with identifying partitions.

Tested on the nrf5340DK (8MB qpsi external flash)

External flash added as 'my_flash'

&mx25r64 {
    partitions {
        compatible = "fixed-partitions";
        #address-cells = <1>;
        #size-cells = <1>;

        external_partition: partition@0 {
            reg = <0x00000000 0x800000>;
            label = "my_flash";
        };
    };
};

In micropython the partition is now visible by label.

>>> from zephyr import FlashArea
>>> FlashArea.__dict__
{'readblocks': <function>, 'writeblocks': <function>, 'ioctl': <function>, 'my_flash': 9, 'mcuboot': 0, 'image_0': 1, 'image_0_nonsecure': 2, 'image_1': 3, 'image_1_nonsecure': 4, 'tfm_ps': 5, 'tfm_its': 6, 'tfm_otp': 7, 'storage': 8}
>>> 

and can be mounted with

>>> import vfs
>>> from zephyr import FlashArea
>>> block_dev = FlashArea(FlashArea.my_flash, 4096)
>>> vfs.VfsLfs2.mkfs(block_dev)
>>> vfs.mount(block_dev, '/my_flash')

Copy link
Contributor

@laodzu laodzu left a comment

Choose a reason for hiding this comment

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

This looks pretty cool. Will test this later on a frdm_mcxn947

#define FLASH_AREA_DEFINE(part) COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_MTD_FROM_FIXED_PARTITION(part)), \
(FLASH_AREA_DEFINE_DEFINE(part)), ())

#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_DEFINE)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can do without DT_DRV_COMPAT pretty easily. Just change this to

#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_INST(n, fixed_partitions), FLASH_AREA_DEFINE)

and remove DT_DRV_COMPAT. I think this makes things actually easier to understand.

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 looks better yea, will look into it

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 does not work, but i figured another slightly different solution

Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

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

This looks very useful!

What do you think about adding something brief about it in the "Flash Area" section of docs/zephyr/quickref.rst?

@VynDragon VynDragon force-pushed the FlashArea_automatic branch from 64840be to 09f12c2 Compare April 9, 2025 18:23
@projectgus projectgus added this to the release-1.26.0 milestone Apr 15, 2025
@dpgeorge
Copy link
Member

What do you think about adding something brief about it in the "Flash Area" section of docs/zephyr/quickref.rst?

Yes, I think this is a good idea.

@VynDragon
Copy link
Contributor Author

Is this ok?

@VynDragon VynDragon force-pushed the FlashArea_automatic branch from 6a063c0 to c59bcdc Compare April 30, 2025 13:41
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

Yes, thanks, that addition to the quickref is good.

VynDragon added 2 commits May 2, 2025 12:37
This enables listing all flash area partitions automagically instead of
just sotrage_partitions.  It uses the label, and the ID when not present.

Signed-off-by: Vdragon <mail@massdriver.space>
Signed-off-by: Vdragon <mail@massdriver.space>
@dpgeorge dpgeorge force-pushed the FlashArea_automatic branch from c59bcdc to ced7ebb Compare May 2, 2025 02:38
@dpgeorge dpgeorge merged commit ced7ebb into micropython:master May 2, 2025
8 checks passed
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.

6 participants