-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: flash: sam: fix flash erase last page #80800
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: fix flash erase last page #80800
Conversation
|
|
|
Hardware tests on sam_v71_xult/samv71q21. |
|
The current tests with the samv71 partition cover the last page? If yes, I'm ready to approve. |
|
To erase the last page for that board, change this line
DT_NODELABEL(scratch_partition) and run the suite again :) we are looking for:
the board has a scratch partition at the end of the flash area :) |
I can do that and provide feedback, yes. But in this case, it will be nice if we extend the test to run over these two partitions. I want to avoid regressions here. I'm fine if you want to do on another PR too to not switch your tasks at moment. |
|
Running test using the scratch_partition |
|
well that sucks :) |
|
Hi @bjarki-andreasen , I was wondering if you had time to look on it again. |
|
friendly ping : ) |
|
I'm getting a dev kit in the coming days, then I will fix it properly |
|
I extended the test suite to include board overlays so we can adjust the slot1 partition to extend to the very end of the flash area. With this, and running the test suite both with and without MCU boot on an sam4e_xpro, it runs without error, erasing the last page successfully: I did not need to change the driver, from what I can tell the bug was indeed fixed :) |
|
Hi @bjarki-andreasen , sam4e_xpro, as you mentioned passes sam_v71_xult, as I mentioned, do not passes if you don't mind to include the below patch, it helps to test samv71 +tests/drivers/flash/erase_blocks/boards/sam_v71_xult_samv71q21.overlay
+/*
+ * Copyright (c) 2025 Gerson Fernando Budke <[email protected]>
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+&flash0 {
+ partitions {
+ /delete-node/ storage_partition;
+
+ slot1_partition: partition@100000 {
+ label = "image-1";
+ reg = <0x00100000 0x100000>;
+ };
+ };
+}; |
I will add the overlay, i can't test it however given I don't have that hardware, could it be a dead flash page or something on your board, or is the flash layout maybe different from the sam4? Don't get why its failing... |
|
I'm checking is there is something different on the flash controller that could fail on the test_erase_single_pages_in_part. If I can not find anything that explains we can assume it could be a page problem as you mention : ) |
|
Hi @bjarki-andreasen , I was testing and enabled debug on the driver. I noted this: 1- Given the number is DECon the tests it is harder to detected that something goes wrong. If I understood correctly, the below should erase all the 1MiB but it is not. I saw that this is OK for the test_write_across_page_boundaries_in_part but still not evaluate the last sector! 0x1fa000 + 0x2000 => 1fc000 2- Look the debug here. The device do not even call the Erasing function on the driver. 2072576 is 1fa000. So, I assume there are something wrong in some place and that could be the issue when it tries to write, is this correct? 3- SAM4E erase 4k and SAMV71 erase 8k. 4- There are some restrictions on the erase page size. |
tests/drivers/flash/erase_blocks/boards/sam4e_xpro_sam4e16e.overlay
Outdated
Show resolved
Hide resolved
|
Hi @bjarki-andreasen , As you mentioned in the pvt chat I think I found it, erase-blocks = <&eefc 8 2048>, <&eefc 252 8192>; is incorrect, should be erase-blocks = <&eefc 8 2048>, <&eefc 254 8192>; see samx7xx21.dtsi . I tested and now it passes on SAMV7 too. Please, send the final update : ) |
The implementation for erasing pages in the flash_sam.c driver indicated a successful erase after exceeding the last page to be erased successfully. Since the last page has no proceeding page, the succeeded status was not set. This fix switches around the status to be set as succeeded before erase begins, to have the succeeded status cleared if page unlock or erase fails. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
The flash erase-blocks property was a bit malformed, it has 254 pages of size 8192 after the first 8 pages of size 2048 to reach the total size of 2048K. This caused issues when trying to erase the last pages of the flash, which caused the flash erase_blocks test suite to fail. Adjust the erase-blocks to match the flash layout. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
7c75749 to
ea1b6b9
Compare
The implementation for erasing pages in the flash_sam.c driver indicated a successful erase after exceeding the last page to be erased successfully. Since the last page has no proceeding page, the succeeded status was not set.
This fix switches around the status to be set as succeeded before erase begins, to have the succeeded status cleared if page unlock or erase fails.
fixes: #70344