-
Notifications
You must be signed in to change notification settings - Fork 8.4k
drivers: flash: flash_hp_ra: perform blank check before reading #88113
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: flash_hp_ra: perform blank check before reading #88113
Conversation
|
Hello @jeremydick, and thank you very much for your first pull request to the Zephyr project! |
|
@KhiemNguyenT re-assigning to you, your IC. |
drivers/flash/Kconfig.renesas_ra
Outdated
|
|
||
| config CHECK_BEFORE_READING | ||
| bool "Verify area before reading it" | ||
| default y |
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 all Renesas RA MCU families with flash hp have undefined value after erasing. Can we add erased-undefined properties in dts and enable this config based on it? like default $(dt_nodelabel_bool_prop,flash1,erased-undefined)
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.
Yes, it looks like the RA4E1, RA4E2, RA4M2, RA4M3, RA6E1, RA6E2, RA6M1, RA6M2, RA6M3, RA6M4, RA6M5, RA8D1, RA8M1, and RA8T1 families have the data flash the will readback an undefined value when erased. Is that all of them, or are there any others I have missed?
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.
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. Since the erase value for the RA4L1 family is 0xff nothing needs to be done for it, only families that have an undefined erase value need to have the erased-undefined property added
drivers/flash/flash_hp_ra.c
Outdated
| LOG_DBG("flash: read 0x%lx, len: %u", (long)(offset + flash_data->area_address), len); | ||
|
|
||
| memcpy(data, (uint8_t *)(offset + flash_data->area_address), len); | ||
| #ifdef CONFIG_CHECK_BEFORE_READING |
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.
Can we move the data flash region check here instead of inside the is_area_readable. Then, with the code flash region, we won't need to call is_area_readable
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.
The flash region check has been moved
67461ac to
a1b4517
Compare
271089f to
52abfff
Compare
|
@KhiemNguyenT , @thaoluonguw , @duynguyenxa , @thenguyenyf, @khoa-nguyen-18 |
khoa-nguyen-18
left a comment
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.
LGTM
52abfff to
64d6ce4
Compare
drivers/flash/flash_hp_ra.c
Outdated
| #ifdef CONFIG_CHECK_BEFORE_READING | ||
| } else if (rc == -ENODATA) { | ||
| /* Erased area, return dummy data as an erased page. */ | ||
| memset(data, 0xFF, len); | ||
| rc = 0; | ||
| #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.
Not in this PR, nevertheless: @jeremydick @khoa-nguyen-18 @thenguyenyf We need to have a discussion on defining -ENODATA return for flash_read API call.
As far as I can see here, your memory has a erasea value (0xff) as a valid write data and erased is separate state.
I think that it may be useful for users to know that, in case of your memory, you can actually detect that the memory has not yet been written at specified location and in such case function should just return without providing bogus data (erase-value filled buffer).
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 @de-nordic, thank you for your feedback.
In my opinion, returning -ENODATA isn’t a typical way for users to check if a flash page has been erased. Most applications, including the flash/common test, simply check for (ret == 0) && (read_buffer_value == 0xFF) to confirm that the page is erased.
The issue we're facing is that the Renesas flash in some SoC series didn't have the 0xFF after erase, which causes compatibility problems with this common check. We’ve considered two options to address this:
- Update the Zephyr's flash test/application condition to accommodate different erased values, and make a broad announcement to inform users of Renesas flash drivers that they need to update their condition checks.
- Provide a configuration option in the Renesas flash driver that allows users to choose whether they want the erased buffer to be
0xFF(as proposed in this PR). If this configuration is not selected, we should return-ENODATA(need to update). We believe this makes sense, especially for users porting applications from other MCU vendors to Renesas MCUs who want to avoid making changes to their existing code.
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 I have stated, we will not be able to resolve this in this PR, but we need a discussion on -ENODATA as valid return from flash_read.
Hi @de-nordic, thank you for your feedback.
In my opinion, returning
-ENODATAisn’t a typical way for users to check if a flash page has been erased. Most applications, including theflash/commontest, simply check for(ret == 0) && (read_buffer_value == 0xFF)to confirm that the page is erased.
It is not for checking whether flash page is erased, it is rather for checking whether user has placed data in specified location.
Note that there is code in Zephyr that reads page and compares it against erase-value to figure out whether page has been erased (looping through buffer), so it can now be written. In case of your device the code will not be able to recognize a difference between erased area and area that has been written with erase-value.
The issue we're facing is that the Renesas flash in some SoC series didn't have the
0xFFafter erase, which causes compatibility problems with this common check. We’ve considered two options to address this:1. Update the Zephyr's flash test/application condition to accommodate different erased values, and make a broad announcement to inform users of Renesas flash drivers that they need to update their condition checks. 2. Provide a configuration option in the Renesas flash driver that allows users to choose whether they want the erased buffer to be `0xFF` (as proposed in this PR). If this configuration is not selected, we should return `-ENODATA` (need to update). We believe this makes sense, especially for users porting applications from other MCU vendors to Renesas MCUs who want to avoid making changes to their existing code.
I agree with what you did; what I mean is that we need to clarify definition of flash_read on the matter of returning -ENODATA, modify in tree code (tests, etc) and announce the change, because it is API breaking change. This will take more effort and I do not think it should happen in this PR.
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.
@de-nordic I agree, longer term it makes the most sense to update the API to allow -ENODATA as a valid return for flash_read, and update all usages of the flash driver within the tree handle that.
thenguyenyf
left a comment
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.
Please rebase to solve conflict
8eee469
64d6ce4 to
8eee469
Compare
|
Rebased to resolve conflicts |
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.
Pull Request Overview
This PR enhances the Renesas RAxxx SoC data flash driver by performing a blank check prior to reading, returning dummy data when an area is erased. Key changes include:
- Adding the new "erased-undefined" property in the DTS binding for configuring blank checks.
- Defining new flash flags (FLASH_FLAG_BLANK and FLASH_FLAG_NOT_BLANK) and updating the flash callback accordingly.
- Implementing a new is_area_readable function and modifying flash_ra_read to utilize blank checks before reading.
Reviewed Changes
Copilot reviewed 3 out of 19 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dts/bindings/mtd/renesas,ra-nv-data-flash.yaml | Added a new boolean property to trigger blank check behavior |
| drivers/flash/soc_flash_renesas_ra_hp.h | Introduced new flash flag macros under a configuration option |
| drivers/flash/soc_flash_renesas_ra_hp.c | Integrated a blank check into the read path via is_area_readable |
Files not reviewed (16)
- drivers/flash/Kconfig.renesas_ra: Language not supported
- dts/arm/renesas/ra/ra4/r7fa4e10d2cfm.dtsi: Language not supported
- dts/arm/renesas/ra/ra4/r7fa4e10d2cne.dtsi: Language not supported
- dts/arm/renesas/ra/ra4/r7fa4e2b93cfm.dtsi: Language not supported
- dts/arm/renesas/ra/ra4/r7fa4m2ad3cfp.dtsi: Language not supported
- dts/arm/renesas/ra/ra4/r7fa4m3af3cfb.dtsi: Language not supported
- dts/arm/renesas/ra/ra6/r7fa6e10f2cfp.dtsi: Language not supported
- dts/arm/renesas/ra/ra6/r7fa6e2bb3cfm.dtsi: Language not supported
- dts/arm/renesas/ra/ra6/r7fa6m1ad3cfp.dtsi: Language not supported
- dts/arm/renesas/ra/ra6/r7fa6m2af3cfb.dtsi: Language not supported
- dts/arm/renesas/ra/ra6/r7fa6m3ah3cfc.dtsi: Language not supported
- dts/arm/renesas/ra/ra6/r7fa6m4af3cfb.dtsi: Language not supported
- dts/arm/renesas/ra/ra6/r7fa6m5bh3cfc.dtsi: Language not supported
- dts/arm/renesas/ra/ra8/r7fa8d1bhecbd.dtsi: Language not supported
- dts/arm/renesas/ra/ra8/r7fa8m1ahecbd.dtsi: Language not supported
- dts/arm/renesas/ra/ra8/r7fa8t1ahecbd.dtsi: Language not supported
Comments suppressed due to low confidence (1)
dts/bindings/mtd/renesas,ra-nv-data-flash.yaml:17
- [nitpick] The property name 'erased-undefined' may be ambiguous given that the feature performs a blank check; consider renaming it to 'blank-check' for clarity and consistency.
erased-undefined:
khoa-nguyen-18
left a comment
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 some minor suggestions regarding your recent update
8eee469 to
7902426
Compare
…flash Add an erased-undefined property for Renesas RA series MCUS data flash that will read back undefined values when erased Signed-off-by: Jeremy Dick <jdick@pivotint.com>
The value read from unwritten areas of Renesas RAxxx SoCs data flash is undefined. To prevent reading unwritten areas a blank check command is performed first. If the area is blank, we return dummy data so it behaves the same as other flash devices. Signed-off-by: Jeremy Dick <jdick@pivotint.com>
7902426 to
f12a693
Compare
|
@KhiemNguyenT could you please review this change to perform a blank check before reading flash with undefined erase values? |
KhiemNguyenT
left a comment
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.
LGTM
The value read from unwritten areas of Renesas RAxxx SoCs data flash is undefined. To prevent reading unwritten areas a blank check command is performed first. If the area is blank, we return dummy data so it behaves the same as other flash devices.