Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions subsys/fs/zms/zms.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ static int zms_init(struct zms_fs *fs)
uint32_t i;
uint32_t closed_sectors = 0;
bool zms_magic_exist = false;
bool ebw_required =
flash_params_get_erase_cap(fs->flash_parameters) & FLASH_ERASE_C_EXPLICIT;

k_mutex_lock(&fs->zms_lock, K_FOREVER);

Expand Down Expand Up @@ -1279,9 +1281,30 @@ static int zms_init(struct zms_fs *fs)
if (rc) {
goto end;
}
if (!zms_ate_valid(fs, &last_ate)) {
/* found empty location */
break;

/* Verify that the next location is empty.
* For devices that do not need erase this should be a non valid ATE.
* For devices that needs erase this should be filled with erase_value.
*/
if (ebw_required) {
size_t byte;

for (byte = 0; byte < sizeof(last_ate); byte++) {
if (((uint8_t *)&last_ate)[byte] !=
(uint8_t)fs->flash_parameters->erase_value) {
break; /* break from the comparison loop */
}
}

if (byte == sizeof(last_ate)) {
/* found ff empty location */
break;
}
} else {
if (!zms_ate_valid(fs, &last_ate)) {
/* found empty location */
break;
}
}

/* ate on the last position within the sector is
Expand Down