-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Add persistent partition to RPi Pico Flash #87918
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
Conversation
Hello @Snap-A, and thank you very much for your first pull request to the Zephyr project! |
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.
Functionally this looks good. It looks like you've got a merge commit that probably doesn't want to be here, however.
|
||
code_partition: partition@100 { | ||
label = "code-partition"; | ||
reg = <0x100 (DT_SIZE_M(2)-0x100-DT_SIZE_K(64))>; |
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.
reg = <0x100 (DT_SIZE_M(2)-0x100-DT_SIZE_K(64))>; | |
reg = <0x100 (DT_SIZE_M(2) - 0x100 - DT_SIZE_K(64))>; |
Is there a reason not to use single whitespace either side of binary operators 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.
I will add the whitespaces. Did not even notice I "compacted" the text like that.
|
||
storage_partition: storage_partition@1f0000 { | ||
label = "storage-partition"; | ||
reg = <(DT_SIZE_M(2)-DT_SIZE_K(64)) (DT_SIZE_K(64))>; |
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.
reg = <(DT_SIZE_M(2)-DT_SIZE_K(64)) (DT_SIZE_K(64))>; | |
reg = <(DT_SIZE_M(2) - DT_SIZE_K(64)) (DT_SIZE_K(64))>; |
Same comment as above. Is there a reason not to use single whitespace either side of binary operators 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.
Same here.
Regarding the merge commit, I had re-merged the branch before the PR creation. Did not realize this would be visible, here.
In the Contribution Guidelines, it says to use --rebase <commit>^
, and then a push --force
to update this PR. I will try this out, it may clean up things...
Additionally, I missed the "copyright / license" comment lines at the start of these files. Will fix that, too.
478212e
to
fa56658
Compare
/delete-node/ &code_partition; | ||
|
||
&flash0 { | ||
partitions { |
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.
dts indent is tab, and don't see why this should be an overlay when it can go in the board file itself (which would also make it usable for many other samples needing a storage partition)
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.
Will fix the tabs.
Not sure if the change is welcomed in the board file, but I'm open to adjust the PR to place it in there if people agree.
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.
Not sure if the change is welcomed in the board file,
I think it's a good idea.
I think my questions would be (sharing my train of thought):
- What's the idiomatic thing in the Zephyr codebase? A very crude search suggests, yes, a lot of boards have a storage partition defined for a good "out-of-the-box" experience.
- What is motivating the choice of size? > 1 flash sector seems like a minimum. Has something motivated the choice of 64kB in particular?
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.
Regarding (2):
The choice of 64 kB gave the FS 16 blocks to work with. That seemed sufficient for the root dir and another few files (15 if each is smaller than a couple of kB in size).
Space for only two files are needed in this specific example and so it could be reduced to 16 kB (4 blocks), but the Pico has 2MB flash, so the 64 kB seem seemed to be more realistic to me.
/delete-node/ &code_partition; | ||
|
||
&flash0 { | ||
partitions { |
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.
Not sure if the change is welcomed in the board file,
I think it's a good idea.
I think my questions would be (sharing my train of thought):
- What's the idiomatic thing in the Zephyr codebase? A very crude search suggests, yes, a lot of boards have a storage partition defined for a good "out-of-the-box" experience.
- What is motivating the choice of size? > 1 flash sector seems like a minimum. Has something motivated the choice of 64kB in particular?
storage_partition: storage_partition@1f0000 { | ||
label = "storage-partition"; |
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.
storage_partition: storage_partition@1f0000 { | |
label = "storage-partition"; | |
storage_partition: partition@1f0000 { | |
label = "storage"; |
Seems to be a more common idiom in the codebase: I think partitions labelled <foo>-partition
is perhaps a bit redundant.
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.
That name could be addressed if this is made a change to the Pico board dts. As an overlay, it probably should stick with the base naming scheme...
@@ -0,0 +1,7 @@ | |||
/* | |||
* Copyright (c) 2025 Andreas Wolf <awolf002@gmai.com> |
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.
* Copyright (c) 2025 Andreas Wolf <awolf002@gmai.com> | |
* Copyright (c) 2025 Andreas Wolf <awolf002@gmail.com> |
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.
Fixing that.
d1a027f
to
92df7d2
Compare
|
9e8bfd5
to
4dd9df1
Compare
4dd9df1
to
43eff44
Compare
I adjusted the PR to a change of the DTS include file I documented the tests that were run with this change in an update to the initial description. Please give feedback if this would be acceptable as a PR. |
The twister build found a problem in the sample code for USB mass storage: It also defines a "storage_partition". This will fail with this proposed change, unless it is "deleted" and re-defined in the overlay file. I will add this change to this PR, so that the twister is "happy". |
43eff44
to
49ef52e
Compare
storage_partition: partition@1fc000 { | ||
label = "storage-partition"; | ||
reg = <(DT_SIZE_M(2) - DT_SIZE_K(16)) (DT_SIZE_K(16))>; |
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 is fine, but the @xxxxxxxx at the end of the node path and the value at the beginning of reg must match. So, represent in the calculations make bit hard to understand.
IMO, If you want to make it easier to read, you might want to introduce
#define STORAGE_PARTITION_SIZE DT_SIZE_K(16)
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 take a look at that. This should improved readability, I agree.
Re-assigning to RPI maintainer. |
49ef52e
to
c79397f
Compare
#define FLASH_SIZE DT_SIZE_M(2) | ||
#define STORAGE_PARTITION_SIZE DT_SIZE_K(16) |
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.
Having a #define
s in the middle of a .dtsi file doesn't seem very idiomatic. Have you come across this elsewhere in the codebase?
I appreciate what you're trying to do here, however, but I think for reasons I don't understand, this is frowned upon in the codebase.
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.
Alright, I will remove the #define ...
lines and update this PR.
Add a 16 KB 'storage' partition at the end of the Pico flash. That size is sufficient to hold the two test files created by the 'littlefs' sample. The sample 'subsys/USB/mass' uses an overlay to add the same partition and it was changed to delete the one defined by this DTSI file before doing that. Signed-off-by: Andreas Wolf <awolf002@gmail.com>
c79397f
to
8221ed6
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.
It seems that #90411 has now added a partition to a set of DTSI files, and #90758 adds this layout to the "standard" Probably, the fix of the overlay file in |
@Snap-A |
I tested compiling the USB "mass storage" sample with the changes in #90758 and no further changes to the sample code.
I am closing this PR. |
Updated Summary
The added partition
storage_partition
can be used for the littelfs sample application. It is sized to have enough capacity for the created files in this sample code.Details
The changed file
rpi_pico-common.dtsi
now contains a third partition, that describes "storage" are for a file system. The "code" partition was reduced in size to make room for this area. The new partition has a capacity of 16 kB, which is enough for the littelfs sample to store two files.Tests
Compilation
The compile step for each platform succeeds:
Test Run
The test were run in a Pico-W device.
First Run On Device
Log after flashing the littlefs sample:
After performing a power cycle:
Old Text
The below text is kept to document previous changes to make the littlefs sample work.
IGNORE TEXT BELOW
Summary
The added overlay files support the compilation for the Pico and Pico_w of the sample for the littlefs filesystem.
Details
The file
rpi_pico.overlay
reduces the size of the "code" partition and adds another partition at the end.This partition has a capacity of 64 kB.
Tests
Compilation
The compile step for each platform succeeds:
Test Run
The code was run on the Pico_w test platform