diff --git a/fs/fcb2/include/fcb/fcb2.h b/fs/fcb2/include/fcb/fcb2.h index e089fccbce..7fca09bb77 100644 --- a/fs/fcb2/include/fcb/fcb2.h +++ b/fs/fcb2/include/fcb/fcb2.h @@ -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 @@ -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 } diff --git a/fs/fcb2/src/fcb.c b/fs/fcb2/src/fcb.c index e8a65ff123..c568d1667a 100644 --- a/fs/fcb2/src/fcb.c +++ b/fs/fcb2/src/fcb.c @@ -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; diff --git a/fs/fcb2/src/fcb_getnext.c b/fs/fcb2/src/fcb_getnext.c index 8a4f8f3051..8528fc34a7 100644 --- a/fs/fcb2/src/fcb_getnext.c +++ b/fs/fcb2/src/fcb_getnext.c @@ -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 */ @@ -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) { @@ -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: @@ -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; } diff --git a/fs/fcb2/src/fcb_priv.h b/fs/fcb2/src/fcb_priv.h index d02784fab5..ce83646f7d 100644 --- a/fs/fcb2/src/fcb_priv.h +++ b/fs/fcb2/src/fcb_priv.h @@ -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) { diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c index 2bb2e604e8..5e1aa87014 100644 --- a/sys/log/full/src/log_fcb2.c +++ b/sys/log/full/src/log_fcb2.c @@ -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 @@ -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 diff --git a/sys/log/full/src/log_fcb_bmark.c b/sys/log/full/src/log_fcb_bmark.c index 2a210aa941..aec0af2c8e 100644 --- a/sys/log/full/src/log_fcb_bmark.c +++ b/sys/log/full/src/log_fcb_bmark.c @@ -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 @@ -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; @@ -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); @@ -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) { diff --git a/sys/log/full/syscfg.yml b/sys/log/full/syscfg.yml index 7170e91ed8..65c29b5358 100644 --- a/sys/log/full/syscfg.yml +++ b/sys/log/full/syscfg.yml @@ -190,7 +190,6 @@ syscfg.defs: value: 0 restrictions: - LOG_FCB_BOOKMARKS - - LOG_FCB syscfg.vals.CONSOLE_TICKS: LOG_CONSOLE_PRETTY_WITH_TIMESTAMP: 0