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
drivers: flash: sam: Redesign controller to fully utilize flash page layout #64215
drivers: flash: sam: Redesign controller to fully utilize flash page layout #64215
Conversation
ec32c8d
to
550e9dd
Compare
Hi @bjarki-trackunit, in other flash drivers this is done by creating the correct page_layout array. For the atmel sam flash there would be two entries: one entry for the smaller pages and one for the larger pages. |
That is what the redesigned driver is doing internally :) zephyr/drivers/flash/flash_sam.c Lines 319 to 333 in 550e9dd
Its using the new cells in the devicetree to create the proper page_layout array :) For the ATSAM4E, the struct flash_pages_layout array expands to:
|
@bjarki-trackunit, is the proposal to move the definition of flash layout from the driver to the dts ? It would be needed to change "flash-pages" to "erase-blocks". What is the meaning of "&eefc" ? |
Correct, just like
I agree with
Its the node label of the flash-controller, it defines the cell properties of the |
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.
Hi @bjarki-trackunit ,
Nice!
It will took time from my side to do a proper review and test the flash_sam.c
.
|
||
"#flash-page-cells": | ||
type: int | ||
const: 2 |
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 will be necessary the documentation with examples. Remember that devicetree should be self explanatory and readers should not go to the datasheet to have a full understanding.
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.
Agreed
@@ -0,0 +1,18 @@ | |||
description: Atmel SAM flash area | |||
|
|||
compatible: "atmel,sam-flash" |
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.
provide full documentation with examples
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.
Agreed, wanted to get some feedback first :)
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.
550e9dd
to
1c48594
Compare
Could it not just be part of the device yaml? |
Well, the device is a flash controller, right? |
@bjarki-trackunit, maybe a future addition could be to fall back to an |
Unfortunately. |
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.
Some nits, but generally OK.
if ((offset >= 0) && ((offset + len) <= config->area_size)) { | ||
return true; |
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.
with significantly large offset
and len
the (offset + len)
may rollover to something that is <= area_size
.
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.
Added a check to validate the addition of offset and len are safe
zephyr/drivers/flash/flash_sam.c
Lines 54 to 67 in a06dfce
static bool sam_flash_validate_offset_len(off_t offset, size_t len) | |
{ | |
if (offset < 0) { | |
return false; | |
} | |
if ((offset + len) < len) { | |
return false; | |
} | |
return true; | |
} | |
drivers/flash/flash_sam.c
Outdated
if (((offset % config->parameters.write_block_size) == 0) && | ||
((len % config->parameters.write_block_size) == 0)) { |
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.
'%' is division, so probably takes more cycles than binary operations that could be used 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.
Changed to use binary operations as the value will always be aligned with an exponent of base 2
zephyr/drivers/flash/flash_sam.c
Lines 67 to 72 in a06dfce
static bool sam_flash_aligned(size_t value, size_t alignment) | |
{ | |
return (value & (alignment - 1)) == 0; | |
} | |
be18b9d
be18b9d
to
84b6ed9
Compare
This commit updates the driver to use the flash layout pages, rewriting it to utilize the flash_page_layout.c driver to avoid duplicate code. Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
Add log messages to help diagnose and understand flash driver behavior. Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
Use interrupt to wait for flash controller to finish its command and become ready. Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
84b6ed9
to
a06dfce
Compare
UpdateI have addressed the issues brought up by @pdgendt and @de-nordic :) |
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.
Thanks! Tested on sam4s.
@bjarki-trackunit, I have some annoying remark. The PR adds a test Could the test be renamed into something else so that can leave the name |
sure, I have no strong feeling on the name, I could name it erase_write_boundary or just erase_write_validate, or maybe you have a good name? |
What about |
Add test suite which tests writing to and erasing all pages, of any size defined by the page layout. If the test is built with MCUBOOT, the test will jump into the application, then run write/erase/boundary tests on the bootload partition. If MCUBOOT is not selected, the test will target the slot1 partition instead, performing the same tests. Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
a06dfce
to
86b8b55
Compare
renamed |
Maybe in the long run we should move all present flash tests under |
This PR redesigns the atmel sam flash controller to fully utilize the flash page layout and capabilities of each individual soc.
An example is the ATSAM4E series socs, they have a flash layout like:
This PR adds a new
flash-pages
cell property which is used to describe this layout fully:Comparing this to the ATSAME70 series
It is described as
The redesigned driver is based on the
flash_page_layout.c
driver to avoid duplicate code. The redesigned flash driver is still a bit naive, it will be expanded with logging and error handling.