Skip to content

Commit

Permalink
emds: Fix size calculation required by emds entries on RRAM
Browse files Browse the repository at this point in the history
The total size required by emds entries calculated more than what is
actually being used. For RRAM, we don't need to align the data with
write block size. We can write as many bytes as we want up to the size
of write block size, thus we don't need to align writes with write
block size.

Signed-off-by: alperen sener <[email protected]>
  • Loading branch information
m-alperen-sener committed Jan 6, 2025
1 parent cac49ac commit b340f24
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions subsys/emds/emds.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,35 @@ static int emds_fs_init(void)

static int emds_entries_size(uint32_t *size)
{
size_t block_size = emds_flash.flash_params->write_block_size;
int entries = 0;

*size = 0;

STRUCT_SECTION_FOREACH(emds_entry, ch) {
#if defined CONFIG_SOC_FLASH_NRF_RRAM
/* Data is not required to be alinged with block_size for RRAM */
*size += ch->len;
*size += emds_flash.ate_size;
#else
size_t block_size = emds_flash.flash_params->write_block_size;
*size += DIV_ROUND_UP(ch->len, block_size) * block_size;
*size += DIV_ROUND_UP(emds_flash.ate_size, block_size) * block_size;
#endif
entries++;
}

struct emds_dynamic_entry *ch;

SYS_SLIST_FOR_EACH_CONTAINER(&emds_dynamic_entries, ch, node) {
#if defined CONFIG_SOC_FLASH_NRF_RRAM
/* Data is not required to be alinged with block_size for RRAM */
*size += ch->entry.len;
*size += emds_flash.ate_size;
#else
size_t block_size = emds_flash.flash_params->write_block_size;
*size += DIV_ROUND_UP(ch->entry.len, block_size) * block_size;
*size += DIV_ROUND_UP(emds_flash.ate_size, block_size) * block_size;
#endif
entries++;
}

Expand Down Expand Up @@ -251,7 +264,6 @@ int emds_prepare(void)
}

(void)emds_entries_size(&size);

rc = emds_flash_prepare(&emds_flash, size);
if (rc) {
return rc;
Expand Down

0 comments on commit b340f24

Please sign in to comment.