Skip to content

sys/log, fs/fcb2: FCB2 support for bookmarks #3386

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions fs/fcb2/include/fcb/fcb2.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ int fcb2_walk(struct fcb2 *fcb, int sector, fcb2_walk_cb cb, void *cb_arg);
*/
int fcb2_getnext(struct fcb2 *fcb, struct fcb2_entry *loc);

/**
* Get first entry in the provided flash area
*
* @param fcb Pointer to FCB
* @param range Optional range in flash sector
* @param loc Pointer to first FCB entry in the provided flash area
*
* @return 0 on success, non-zero on failure
*/
int
fcb2_getnext_in_area(struct fcb2 *fcb, struct flash_sector_range *range,
struct fcb2_entry *loc);

/**
* Walk through entries within FCB from newest to oldest.
* fcb_getprev() finds the previous valid entry backwards from loc, and fills in
Expand Down Expand Up @@ -304,6 +317,17 @@ int fcb2_clear(struct fcb2 *fcb);
*/
int fcb2_area_info(struct fcb2 *fcb, int sector, int *elemsp, int *bytesp);

/**
* Returns the next sector flash range, given current entry
*
* @param fcb Pointer to the FCB
* @param loc Pointer to the location
*
* @return Flash sector range of the next sector
*/
struct flash_sector_range *
fcb2_getnext_range(struct fcb2 *fcb, struct fcb2_entry *loc);

#ifdef __cplusplus
}

Expand Down
2 changes: 1 addition & 1 deletion fs/fcb2/src/fcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fcb2_init(struct fcb2 *fcb)
fcb->f_active_id = newest;

while (1) {
rc = fcb2_getnext_in_area(fcb, &fcb->f_active);
rc = fcb2_getnext_in_area(fcb, NULL, &fcb->f_active);
if (rc == FCB2_ERR_NOVAR) {
rc = FCB2_OK;
break;
Expand Down
27 changes: 24 additions & 3 deletions fs/fcb2/src/fcb_getnext.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@
#include "fcb_priv.h"

int
fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc)
fcb2_getnext_in_area(struct fcb2 *fcb, struct flash_sector_range *range,
struct fcb2_entry *loc)
{
int rc = FCB2_ERR_CRC;
int len;
int next_data_offset;
int next_entry_offset;

/* If a flash range is specified, find first entry in that area */
if (range) {
loc->fe_range = range;
loc->fe_data_off = fcb2_len_in_flash(range, sizeof(struct fcb2_disk_area));
loc->fe_entry_num = 0;
loc->fe_data_len = 0;
loc->fe_sector = 0;
}

while (rc == FCB2_ERR_CRC) {
len = loc->fe_data_len;
/* Next data offset in sector */
Expand All @@ -52,6 +62,17 @@ fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc)
return rc;
}

struct flash_sector_range *
fcb2_getnext_range(struct fcb2 *fcb, struct fcb2_entry *loc)
{
loc->fe_entry_num = 0;
loc->fe_data_len = 0;
loc->fe_sector = fcb2_getnext_sector(fcb, loc->fe_sector);
loc->fe_range = fcb2_get_sector_range(fcb, loc->fe_sector);

return loc->fe_range;
}

int
fcb2_getnext_nolock(struct fcb2 *fcb, struct fcb2_entry *loc)
{
Expand All @@ -71,7 +92,7 @@ fcb2_getnext_nolock(struct fcb2 *fcb, struct fcb2_entry *loc)
loc->fe_entry_num = 1;
rc = fcb2_elem_info(loc);
} else {
rc = fcb2_getnext_in_area(fcb, loc);
rc = fcb2_getnext_in_area(fcb, NULL, loc);
}
switch (rc) {
case 0:
Expand All @@ -82,7 +103,7 @@ fcb2_getnext_nolock(struct fcb2 *fcb, struct fcb2_entry *loc)
goto next_sector;
}
while (rc == FCB2_ERR_CRC) {
rc = fcb2_getnext_in_area(fcb, loc);
rc = fcb2_getnext_in_area(fcb, NULL, loc);
if (rc == 0) {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions fs/fcb2/src/fcb_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ fcb2_len_in_flash(const struct flash_sector_range *range, uint16_t len)
return (len + (range->fsr_align - 1)) & ~(range->fsr_align - 1);
}

int fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc);

static inline int
fcb2_getnext_sector(struct fcb2 *fcb, int sector)
{
Expand Down
14 changes: 13 additions & 1 deletion sys/log/full/src/log_fcb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ log_fcb2_start_append(struct log *log, int len, struct fcb2_entry *loc)
}
#endif

#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS) && !MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
/* The FCB needs to be rotated. */
log_fcb_rotate_bmarks(fcb_log);
#endif
Expand All @@ -183,6 +183,18 @@ log_fcb2_start_append(struct log *log, int len, struct fcb2_entry *loc)
goto err;
}

#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
/* The FCB needs to be rotated, reinit previously allocated
* bookmarks
*/
rc = log_fcb_init_bmarks(fcb_log, fcb_log->fl_bset.lfs_bmarks,
fcb_log->fl_bset.lfs_cap,
fcb_log->fl_bset.lfs_en_sect_bmarks);
if (rc) {
goto err;
}
#endif

#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
/*
* FCB was rotated successfully so let's check if watermark was within
Expand Down
15 changes: 13 additions & 2 deletions sys/log/full/src/log_fcb_bmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index,
fcb_log->fl_bset.lfs_next_sect < (fcb_log->fl_bset.lfs_sect_cap - 1)) {
start_idx = fcb_log->fl_bset.lfs_next_sect + 1;
}
#elif MYNEWT_VAL(LOG_FCB2)
if (!fcb_log->fl_bset.lfs_bmarks[i].lfb_entry.fe_range &&
fcb_log->fl_bset.lfs_next_sect < (fcb_log->fl_bset.lfs_sect_cap - 1)) {
start_idx = fcb_log->fl_bset.lfs_next_sect + 1;
}
#endif
#endif

Expand Down Expand Up @@ -298,9 +303,15 @@ log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index,
}

#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
#if MYNEWT_VAL(LOG_FCB)
static int
log_fcb_insert_sect_bmark(struct fcb_log *fcb_log, struct fcb_entry *entry,
uint32_t index)
#elif MYNEWT_VAL(LOG_FCB2)
static int
log_fcb_insert_sect_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
uint32_t index)
#endif
{
struct log_fcb_bset *bset;

Expand Down Expand Up @@ -336,7 +347,7 @@ log_fcb_replace_non_sect_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry
int i = 0;
struct log_fcb_bset *bset = &fcb_log->fl_bset;

#if MYNEWT_VAL(LOG_FCB) && MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
if (bset->lfs_en_sect_bmarks) {
for (i = bset->lfs_sect_cap;
i < (bset->lfs_non_sect_size + bset->lfs_sect_cap);
Expand Down Expand Up @@ -382,7 +393,7 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, struct fcb2_entry *entry,
return SYS_ENOMEM;
}

#if MYNEWT_VAL(LOG_FCB) && MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
if (sect_bmark & bset->lfs_en_sect_bmarks) {
rc = log_fcb_insert_sect_bmark(fcb_log, entry, index);
if (rc) {
Expand Down
1 change: 0 additions & 1 deletion sys/log/full/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ syscfg.defs:
value: 0
restrictions:
- LOG_FCB_BOOKMARKS
- LOG_FCB

syscfg.vals.CONSOLE_TICKS:
LOG_CONSOLE_PRETTY_WITH_TIMESTAMP: 0
Expand Down