Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Unified Diff: lib/bio/debug.c

Issue 1410223011: [spiflash][bio][stm32f7] Fixed (sub)sector erase on spiflash device. (Closed) Base URL: git@github.com:travisg/lk.git@master
Patch Set: Subsector Address Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | platform/stm32f7xx/qspi.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/bio/debug.c
diff --git a/lib/bio/debug.c b/lib/bio/debug.c
index b4898320832d319882aff6cbbc4a149b9e42817e..072a9c4b8fad6036eacf3f7eb208b7a0c152d9bc 100644
--- a/lib/bio/debug.c
+++ b/lib/bio/debug.c
@@ -36,6 +36,8 @@
#endif
#define DMA_ALIGNMENT (CACHE_LINE)
+#define THREE_BYTE_ADDR_BOUNDARY (16777216)
+#define SUB_ERASE_TEST_SAMPLES (32)
#if defined(WITH_LIB_CONSOLE)
@@ -333,6 +335,52 @@ static ssize_t erase_test(bdev_t *device)
return num_invalid_blocks;
}
+static bool test_erase_block(bdev_t* device, uint32_t block_addr)
+{
+ bool success = false;
+ uint8_t valid_byte[1];
+
+ uint8_t *block_contents = memalign(DMA_ALIGNMENT, device->block_size);
+ memset(block_contents, ~(device->erase_byte), device->block_size);
+
+ ssize_t err = bio_write_block(device, block_contents, block_addr, 1);
+ if (err != (ssize_t)device->block_size) {
+ goto finish;
+ }
+
+ valid_byte[0] = ~(device->erase_byte);
+ if (!is_valid_block(device, block_addr, valid_byte, 1)) {
+ goto finish;
+ }
+
+ err = bio_erase(device, block_addr * device->block_size, 1);
+ if (err <= 0) {
+ goto finish;
+ }
+
+ valid_byte[0] = device->erase_byte;
+ if (is_valid_block(device, block_addr, valid_byte, 1)) {
+ success = true;
+ }
+
+finish:
+ free(block_contents);
+ return success;
+}
+
+// Ensure that (sub)sector erase work.
+static bool sub_erase_test(bdev_t* device, uint32_t n_samples)
+{
+ printf("Sampling the device %d times.\n", n_samples);
+ for (uint32_t i = 0; i < n_samples; i++) {
+ bnum_t block_addr = rand() % device->block_count;
+ if (!test_erase_block(device, block_addr)) {
+ return false;
+ }
+ }
+ return true;
+}
+
static uint8_t get_signature(uint32_t word)
{
uint8_t* sigptr = (uint8_t*)(&word);
@@ -387,5 +435,14 @@ static int bio_test_device(bdev_t* device)
return -1;
}
+ printf ("Testing sub-erase...\n");
+ bool success = sub_erase_test(device, SUB_ERASE_TEST_SAMPLES);
+ if (!success) {
+ printf("Discovered errors while testing sub-erase.\n");
+ return -1;
+ } else {
+ printf("No errors while testing sub-erase.\n");
+ }
+
return 0;
}
« no previous file with comments | « no previous file | platform/stm32f7xx/qspi.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698