Skip to content
Closed
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
8 changes: 4 additions & 4 deletions include/zephyr/fs/fcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern "C" {
* within that area.
*/
struct fcb_entry {
struct flash_sector *fe_sector;
const struct flash_sector *fe_sector;
/**< Pointer to info about sector where data are placed */

uint32_t fe_elem_off;
Expand Down Expand Up @@ -109,14 +109,14 @@ struct fcb {
* to have scratch space for garbage collecting when FCB fills up.
*/

struct flash_sector *f_sectors;
const struct flash_sector *f_sectors;
/**< Array of sectors, must be contiguous */

/* Flash circular buffer internal state */
struct k_mutex f_mtx;
/**< Locking for accessing the FCB data, internal state */

struct flash_sector *f_oldest;
const struct flash_sector *f_oldest;
/**< Pointer to flash sector containing the oldest data,
* internal state
*/
Expand Down Expand Up @@ -223,7 +223,7 @@ typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg);
* @return 0 on success, negative on failure (or transferred form callback
* return-value), positive transferred form callback return-value
*/
int fcb_walk(struct fcb *fcbp, struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg);
int fcb_walk(struct fcb *fcbp, const struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg);

/**
* Get next fcb entry location.
Expand Down
12 changes: 7 additions & 5 deletions subsys/fs/fcb/fcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ int fcb_erase_sector(const struct fcb *fcbp, const struct flash_sector *sector)

int fcb_init(int f_area_id, struct fcb *fcbp)
{
struct flash_sector *sector;
const struct flash_sector *sector;
int rc;
int i;
uint8_t align;
int oldest = -1, newest = -1;
struct flash_sector *oldest_sector = NULL, *newest_sector = NULL;
const struct flash_sector *oldest_sector = NULL;
const struct flash_sector *newest_sector = NULL;
struct fcb_disk_area fda;
const struct flash_parameters *fparam;

Expand Down Expand Up @@ -174,7 +175,7 @@ int fcb_init(int f_area_id, struct fcb *fcbp)
int fcb_free_sector_cnt(struct fcb *fcbp)
{
int i;
struct flash_sector *fa;
const struct flash_sector *fa;

fa = fcbp->f_active.fe_sector;
for (i = 0; i < fcbp->f_sector_cnt; i++) {
Expand Down Expand Up @@ -252,7 +253,7 @@ int fcb_get_len(const struct fcb *fcbp, uint8_t *buf, uint16_t *len)
/**
* Initialize erased sector for use.
*/
int fcb_sector_hdr_init(struct fcb *fcbp, struct flash_sector *sector, uint16_t id)
int fcb_sector_hdr_init(struct fcb *fcbp, const struct flash_sector *sector, uint16_t id)
{
struct fcb_disk_area fda;
int rc;
Expand All @@ -275,7 +276,8 @@ int fcb_sector_hdr_init(struct fcb *fcbp, struct flash_sector *sector, uint16_t
* Returns 0 if sector is unused;
* Returns 1 if sector has data.
*/
int fcb_sector_hdr_read(struct fcb *fcbp, struct flash_sector *sector, struct fcb_disk_area *fdap)
int fcb_sector_hdr_read(struct fcb *fcbp, const struct flash_sector *sector,
struct fcb_disk_area *fdap)
{
struct fcb_disk_area fda;
int rc;
Expand Down
11 changes: 5 additions & 6 deletions subsys/fs/fcb/fcb_append.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
#include <zephyr/fs/fcb.h>
#include "fcb_priv.h"

static struct flash_sector *
fcb_new_sector(struct fcb *fcb, int cnt)
static const struct flash_sector *fcb_new_sector(struct fcb *fcb, int cnt)
{
struct flash_sector *prev;
struct flash_sector *cur;
const struct flash_sector *prev;
const struct flash_sector *cur;
int i;

prev = NULL;
Expand All @@ -39,7 +38,7 @@ fcb_new_sector(struct fcb *fcb, int cnt)
int
fcb_append_to_scratch(struct fcb *fcb)
{
struct flash_sector *sector;
const struct flash_sector *sector;
int rc;

sector = fcb_new_sector(fcb, 0);
Expand All @@ -59,7 +58,7 @@ fcb_append_to_scratch(struct fcb *fcb)
int
fcb_append(struct fcb *fcb, uint16_t len, struct fcb_entry *append_loc)
{
struct flash_sector *sector;
const struct flash_sector *sector;
struct fcb_entry *active;
int cnt;
int rc;
Expand Down
3 changes: 1 addition & 2 deletions subsys/fs/fcb/fcb_getnext.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ fcb_getnext_in_sector(struct fcb *fcb, struct fcb_entry *loc)
return rc;
}

struct flash_sector *
fcb_getnext_sector(struct fcb *fcb, struct flash_sector *sector)
const struct flash_sector *fcb_getnext_sector(struct fcb *fcb, const struct flash_sector *sector)
{
sector++;
if (sector >= &fcb->f_sectors[fcb->f_sector_cnt]) {
Expand Down
7 changes: 4 additions & 3 deletions subsys/fs/fcb/fcb_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ uint8_t fcb_get_align(const struct fcb *fcbp);
int fcb_erase_sector(const struct fcb *fcbp, const struct flash_sector *sector);

int fcb_getnext_in_sector(struct fcb *fcbp, struct fcb_entry *loc);
struct flash_sector *fcb_getnext_sector(struct fcb *fcbp, struct flash_sector *sector);
const struct flash_sector *fcb_getnext_sector(struct fcb *fcbp, const struct flash_sector *sector);
int fcb_getnext_nolock(struct fcb *fcbp, struct fcb_entry *loc);

int fcb_elem_info(struct fcb *fcbp, struct fcb_entry *loc);
int fcb_elem_endmarker(struct fcb *fcbp, struct fcb_entry *loc, uint8_t *crc8p);

int fcb_sector_hdr_init(struct fcb *fcbp, struct flash_sector *sector, uint16_t id);
int fcb_sector_hdr_read(struct fcb *fcbp, struct flash_sector *sector, struct fcb_disk_area *fdap);
int fcb_sector_hdr_init(struct fcb *fcbp, const struct flash_sector *sector, uint16_t id);
int fcb_sector_hdr_read(struct fcb *fcbp, const struct flash_sector *sector,
struct fcb_disk_area *fdap);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion subsys/fs/fcb/fcb_rotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
int
fcb_rotate(struct fcb *fcb)
{
struct flash_sector *sector;
const struct flash_sector *sector;
int rc = 0;

rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
Expand Down
4 changes: 1 addition & 3 deletions subsys/fs/fcb/fcb_walk.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
* Call 'cb' for every element in flash circular buffer. If sector is specified,
* only elements with that flash_sector are reported.
*/
int
fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
void *cb_arg)
int fcb_walk(struct fcb *fcb, const struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg)
{
struct fcb_entry_ctx entry_ctx;
int rc;
Expand Down
2 changes: 1 addition & 1 deletion tests/subsys/fs/fcb/src/fcb_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern struct fcb test_fcb;
extern struct fcb test_fcb_crc_disabled;
#endif

extern struct flash_sector test_fcb_sector[];
extern const struct flash_sector test_fcb_sector[];

extern uint8_t fcb_test_erase_value;

Expand Down
24 changes: 5 additions & 19 deletions tests/subsys/fs/fcb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,11 @@ uint8_t fcb_test_erase_value;
* area. This test suite is the non bootable application so 1. image slot is
* suitable for it.
*/
struct flash_sector test_fcb_sector[] = {
[0] = {
.fs_off = 0,
.fs_size = SECTOR_SIZE
},
[1] = {
.fs_off = SECTOR_SIZE,
.fs_size = SECTOR_SIZE
},
[2] = {
.fs_off = 2 * SECTOR_SIZE,
.fs_size = SECTOR_SIZE
},
[3] = {
.fs_off = 3 * SECTOR_SIZE,
.fs_size = SECTOR_SIZE
}
};

const struct flash_sector test_fcb_sector[] = {
[0] = {.fs_off = 0, .fs_size = SECTOR_SIZE},
[1] = {.fs_off = SECTOR_SIZE, .fs_size = SECTOR_SIZE},
[2] = {.fs_off = 2 * SECTOR_SIZE, .fs_size = SECTOR_SIZE},
[3] = {.fs_off = 3 * SECTOR_SIZE, .fs_size = SECTOR_SIZE}};
Comment on lines -33 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change? same in another couple of files, PRs should nto change unrelated code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JPHutchins If you did run clang format on the code, please do not do that. At least not with other changes.


void test_fcb_wipe(void)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/subsys/settings/fcb/src/settings_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern int test_export_block;

extern int c2_var_count;

extern struct flash_sector fcb_sectors[SETTINGS_TEST_FCB_FLASH_CNT];
extern const struct flash_sector fcb_sectors[SETTINGS_TEST_FCB_FLASH_CNT];

extern char val_string[SETTINGS_TEST_FCB_VAL_STR_CNT][SETTINGS_MAX_VAL_LEN];
extern char test_ref_value[SETTINGS_TEST_FCB_VAL_STR_CNT][SETTINGS_MAX_VAL_LEN];
Expand All @@ -46,7 +46,7 @@ void ctest_clear_call_state(void);
int ctest_get_call_state(void);

void config_wipe_srcs(void);
void config_wipe_fcb(struct flash_sector *fs, int cnt);
void config_wipe_fcb(const struct flash_sector *fs, int cnt);

void test_config_fill_area(
char test_value[SETTINGS_TEST_FCB_VAL_STR_CNT][SETTINGS_MAX_VAL_LEN],
Expand Down
13 changes: 3 additions & 10 deletions tests/subsys/settings/fcb/src/settings_test_compress_deleted.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@

#define NAME_DELETABLE "4/deletable"

struct flash_sector fcb_small_sectors[2] = {
[0] = {
.fs_off = 0x00000000,
.fs_size = 4 * 1024
},
[1] = {
.fs_off = 0x00001000,
.fs_size = 4 * 1024
}
};
const struct flash_sector fcb_small_sectors[2] = {
[0] = {.fs_off = 0x00000000, .fs_size = 4 * 1024},
[1] = {.fs_off = 0x00001000, .fs_size = 4 * 1024}};

struct deletable_s {
bool valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ZTEST(settings_config_fcb, test_config_compress_reset)
{
int rc;
struct settings_fcb cf;
struct flash_sector *fa;
const struct flash_sector *fa;
int elems[4];
int i;

Expand Down
25 changes: 6 additions & 19 deletions tests/subsys/settings/fcb/src/settings_test_fcb.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,13 @@ void config_wipe_srcs(void)
settings_save_dst = NULL;
}

struct flash_sector fcb_sectors[SETTINGS_TEST_FCB_FLASH_CNT] = {
[0] = {
.fs_off = 0x00000000,
.fs_size = 16 * 1024
},
[1] = {
.fs_off = 0x00004000,
.fs_size = 16 * 1024
},
[2] = {
.fs_off = 0x00008000,
.fs_size = 16 * 1024
},
[3] = {
.fs_off = 0x0000c000,
.fs_size = 16 * 1024
}
};
const struct flash_sector fcb_sectors[SETTINGS_TEST_FCB_FLASH_CNT] = {
[0] = {.fs_off = 0x00000000, .fs_size = 16 * 1024},
[1] = {.fs_off = 0x00004000, .fs_size = 16 * 1024},
[2] = {.fs_off = 0x00008000, .fs_size = 16 * 1024},
[3] = {.fs_off = 0x0000c000, .fs_size = 16 * 1024}};

void config_wipe_fcb(struct flash_sector *fs, int cnt)
void config_wipe_fcb(struct flash_sector const *fs, int cnt)
{
const struct flash_area *fap;
int rc;
Expand Down
Loading