1 /*
2 * Copyright (c) 2019 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "settings_test.h"
8 #include <zephyr/device.h>
9 #include <zephyr/fs/fs.h>
10 #include <zephyr/fs/littlefs.h>
11
12 #define LITTLEFS_PARTITION settings_file_partition
13 #define LITTLEFS_PARTITION_ID FIXED_PARTITION_ID(LITTLEFS_PARTITION)
14
15 /* LittleFS work area struct */
16 FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
17 static struct fs_mount_t littlefs_mnt = {
18 .type = FS_LITTLEFS,
19 .fs_data = &cstorage,
20 .storage_dev = (void *)LITTLEFS_PARTITION_ID,
21 .mnt_point = TEST_FS_MPTR,
22 };
23
config_setup_fs(void)24 void *config_setup_fs(void)
25 {
26 int rc;
27 const struct flash_area *fap;
28
29 rc = flash_area_open(LITTLEFS_PARTITION_ID, &fap);
30 zassume_true(rc == 0, "opening flash area for erase [%d]\n", rc);
31
32 rc = flash_area_erase(fap, 0, fap->fa_size);
33 zassume_true(rc == 0, "erasing flash area [%d]\n", rc);
34
35 rc = fs_mount(&littlefs_mnt);
36 zassume_true(rc == 0, "mounting littlefs [%d]\n", rc);
37 settings_config_setup();
38 return NULL;
39 }
40