sync
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#include <zephyr/fs/littlefs.h>
|
||||
#include <zephyr/drivers/flash.h>
|
||||
#include <zephyr/dfu/flash_img.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
#include <fs.h>
|
||||
LOG_MODULE_REGISTER(buzz_fs, LOG_LEVEL_DBG);
|
||||
LOG_MODULE_REGISTER(buzz_fs, LOG_LEVEL_INF);
|
||||
|
||||
#define STORAGE_PARTITION_ID FIXED_PARTITION_ID(littlefs_storage)
|
||||
#define SLOT1_ID FIXED_PARTITION_ID(slot1_partition)
|
||||
|
||||
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(fs_storage_data);
|
||||
|
||||
#define QSPI_FLASH_NODE DT_ALIAS(qspi_flash)
|
||||
@@ -13,8 +16,11 @@ FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(fs_storage_data);
|
||||
#endif
|
||||
|
||||
static const struct device *flash_dev = DEVICE_DT_GET(QSPI_FLASH_NODE);
|
||||
|
||||
static volatile uint32_t open_count = 0;
|
||||
static struct k_mutex flash_pm_lock;
|
||||
static struct slot_info_t slot1_info;
|
||||
static struct flash_img_context flash_ctx;
|
||||
|
||||
static struct fs_mount_t fs_storage_mnt = {
|
||||
.type = FS_LITTLEFS,
|
||||
@@ -30,6 +36,17 @@ int fs_init(void) {
|
||||
return rc;
|
||||
}
|
||||
k_mutex_init(&flash_pm_lock);
|
||||
|
||||
const struct flash_area *fa;
|
||||
rc = flash_area_open(SLOT1_ID, &fa);
|
||||
if (rc < 0) {
|
||||
LOG_ERR("Error opening flash area for slot 1: %d", rc);
|
||||
return rc;
|
||||
}
|
||||
slot1_info.start_addr = fa->fa_off;
|
||||
slot1_info.size = fa->fa_size;
|
||||
flash_area_close(fa);
|
||||
|
||||
LOG_DBG("Filesystem mounted successfully");
|
||||
return 0;
|
||||
}
|
||||
@@ -128,10 +145,7 @@ int fs_pm_unlink(const char *path)
|
||||
LOG_DBG("PM Unlinking file '%s'", path);
|
||||
fs_pm_flash_resume();
|
||||
int rc = fs_unlink(path);
|
||||
if (rc < 0)
|
||||
{
|
||||
fs_pm_flash_suspend();
|
||||
}
|
||||
fs_pm_flash_suspend();
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -142,4 +156,42 @@ int fs_pm_statvfs(const char *path, struct fs_statvfs *stat)
|
||||
int rc = fs_statvfs(path, stat);
|
||||
fs_pm_flash_suspend();
|
||||
return rc;
|
||||
}
|
||||
|
||||
int fs_pm_mkdir(const char *path)
|
||||
{
|
||||
LOG_DBG("PM Creating directory '%s'", path);
|
||||
fs_pm_flash_resume();
|
||||
int rc = fs_mkdir(path);
|
||||
fs_pm_flash_suspend();
|
||||
return rc;
|
||||
}
|
||||
int flash_get_slot_info(slot_info_t *info) {
|
||||
if (slot1_info.size != 0) {
|
||||
*info = slot1_info;
|
||||
return 0;
|
||||
}
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
int flash_init_firmware_upload(void) {
|
||||
int rc;
|
||||
|
||||
rc = flash_img_init_id(&flash_ctx, SLOT1_ID);
|
||||
if (rc != 0) {
|
||||
printk("Error initializing flash image: %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flash_write_firmware_block(const uint8_t *buffer, size_t length, bool is_last_block) {
|
||||
int rc;
|
||||
rc = flash_img_buffered_write(&flash_ctx, buffer, length, is_last_block);
|
||||
|
||||
if (rc != 0) {
|
||||
printk("Error writing flash image: %d\n", rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user