-
Notifications
You must be signed in to change notification settings - Fork 93
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
feat(spi_nand_flash): Add Kconfig option to verify write operations #436
base: master
Are you sure you want to change the base?
feat(spi_nand_flash): Add Kconfig option to verify write operations #436
Conversation
f4d2a95
to
0ac8c3c
Compare
be53084
to
01fe332
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.
Thanks for the PR @RathiSonika.
I left a few minor comments. The major one is whether we should indeed verify writes above Dhara layer, like you did, or below it, in nand.c dhara_glue.c.
To me it seems that verifying writes at lower layer achieves the goal of making sure our Flash operations work correctly, while verifying at upper layer doesn't.
We do writes to Flash in dhara_nand_prog, dhara_nand_copy, dhara_nand_mark_bad. If we fail to perform the write in dhara_nand_mark_bad correctly, we might not get the verification error in spi_nand_flash_write_sector
. Dhara will consider the page as "bad" until next reset, but after reset we will mistakenly detect the page as not "bad" because the bad block marker wasn't written correctly.
I had the same thought to add it in below Dhara layer. Currently added it to nand.c. I wasn’t entirely sure if it should go in dhara_glue.c, given its tight coupling with the Dhara library. However, you’re right; we should verify the write operation below Dhara layer. So, for the current structure, it makes sense to add this in dhara_glue.c. We could consider refactoring this in the future. |
a7220f2
to
33f6ef4
Compare
ret = s_verify_write(dev, data, 0, dev->page_size); | ||
if (ret != ESP_OK) { | ||
ESP_LOGE(TAG, "%s: prog page=%"PRIu32" write verification failed", __func__, p); | ||
} |
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.
Technically we also have to verify the used marker 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.
Oh, I see. So you mean it should return -1/failure if the write verification fails, correct?
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 mean that a few lines above, we write two parts:
ESP_GOTO_ON_ERROR(spi_nand_program_load(dev->config.device_handle, data, 0, dev->page_size),
fail, TAG, "");
ESP_GOTO_ON_ERROR(spi_nand_program_load(dev->config.device_handle, (uint8_t *)&used_marker,
dev->page_size + 2, 2),
This s_verify_write
call checks that the first part (from 0 to page_size) is written correctly. We should call s_verify_write second time to check that the used page marker (page_size ... page_size + 2) is also written correctly.
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.
Oh, my mistake—I misunderstood. Yes, it should verify the markers. I’ll update it. Thank you!
33f6ef4
to
4e8026d
Compare
{ | ||
dhara_error_t err; | ||
esp_err_t ret = ESP_OK; | ||
|
Check warning
Code scanning / clang-tidy
Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] Warning
4e8026d
to
794a352
Compare
Change description
spi_nand_flash_copy_sector()
API in nand.c and test case for the same.