Add initial stubs for LFS filesystem support

parent 00e849c2
......@@ -27,6 +27,7 @@ target_sources(app PRIVATE
${KESTREL_SOURCE_DIR}/src/zephyr.c
${KESTREL_SOURCE_DIR}/src/shell.c
${KESTREL_SOURCE_DIR}/src/opencores_i2c.c
${KESTREL_SOURCE_DIR}/src/flash_filesystem.c
${KESTREL_SOURCE_DIR}/src/fsi.c
${KESTREL_SOURCE_DIR}/src/kestrel.c
${KESTREL_SOURCE_DIR}/src/webservice.c
......
......@@ -28,7 +28,7 @@ How to build:
export SOURCE_ROOT_DIR=$(pwd)
cd zephyr
mkdir build
ZEPHYR_BASE=${SOURCE_ROOT_DIR}/zephyr ZEPHYR_TOOLCHAIN_VARIANT=host cmake -DZEPHYR_MODULES=${SOURCE_ROOT_DIR}/mbedtls -DZEPHYR_MODULES=${SOURCE_ROOT_DIR}/civetweb -DBOARD=litex_kestrel ${SOURCE_ROOT_DIR}/zephyr-firmware
ZEPHYR_BASE=${SOURCE_ROOT_DIR}/zephyr ZEPHYR_TOOLCHAIN_VARIANT=host cmake -DZEPHYR_MODULES="${SOURCE_ROOT_DIR}/littlefs;${SOURCE_ROOT_DIR}/mbedtls;${SOURCE_ROOT_DIR}/civetweb" -DBOARD=litex_kestrel ${SOURCE_ROOT_DIR}/zephyr-firmware
cp -Rp ../libsoft-fp.a zephyr/
make -j144
......
// Copyright (c) 2019 Peter Bigot Consulting, LLC
// Copyright (c) 2021 Raptor Engineering, LLC
//
// Released under the terms of the GPL v3
// See the LICENSE file for full details
#include <logging/log.h>
LOG_MODULE_REGISTER(flash_filesystem, LOG_LEVEL_DBG);
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <zephyr.h>
#include <device.h>
#include <fs/fs.h>
#include <fs/littlefs.h>
#include <storage/flash_map.h>
#define WITH_ZEPHYR 1
#include "kestrel.h"
// Matches LFS_NAME_MAX */
#define MAX_PATH_LEN 255
#define PARTITION_NODE DT_NODELABEL(lfs1)
#if DT_NODE_EXISTS(PARTITION_NODE)
FS_FSTAB_DECLARE_ENTRY(PARTITION_NODE);
#else /* PARTITION_NODE */
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(storage);
static struct fs_mount_t lfs_storage_mnt = {
.type = FS_LITTLEFS,
.fs_data = &storage,
.storage_dev = (void *)FLASH_AREA_ID(storage),
.mnt_point = "/lfs",
};
#endif
int initialize_flash_filesystem(void)
{
struct fs_mount_t *mp =
#if DT_NODE_EXISTS(PARTITION_NODE)
&FS_FSTAB_ENTRY(PARTITION_NODE)
#else
&lfs_storage_mnt
#endif
;
unsigned int id = (uintptr_t)mp->storage_dev;
char fname[MAX_PATH_LEN];
struct fs_statvfs sbuf;
const struct flash_area *pfa;
int rc;
snprintf(fname, sizeof(fname), "%s/boot_count", mp->mnt_point);
rc = flash_area_open(id, &pfa);
if (rc < 0) {
printk("FAIL: unable to find flash area %u: %d\n",
id, rc);
return;
}
printk("Area %u at 0x%x on %s for %u bytes\n",
id, (unsigned int)pfa->fa_off, pfa->fa_dev_name,
(unsigned int)pfa->fa_size);
/* Optional wipe flash contents */
if (IS_ENABLED(CONFIG_APP_WIPE_STORAGE)) {
printk("Erasing flash area ... ");
rc = flash_area_erase(pfa, 0, pfa->fa_size);
printk("%d\n", rc);
}
flash_area_close(pfa);
rc = fs_mount(mp);
if (rc < 0) {
printk("FAIL: mount id %u at %s: %d\n",
(unsigned int)mp->storage_dev, mp->mnt_point,
rc);
return;
}
printk("%s mount: %d\n", mp->mnt_point, rc);
rc = fs_statvfs(mp->mnt_point, &sbuf);
if (rc < 0) {
printk("FAIL: statvfs: %d\n", rc);
goto fail;
}
printk("%s: bsize = %lu ; frsize = %lu ;"
" blocks = %lu ; bfree = %lu\n",
mp->mnt_point,
sbuf.f_bsize, sbuf.f_frsize,
sbuf.f_blocks, sbuf.f_bfree);
return 0;
fail:
rc = fs_unmount(mp);
printk("%s unmount: %d\n", mp->mnt_point, rc);
return -1;
}
\ No newline at end of file
// © 2021 Raptor Engineering, LLC
//
// Released under the terms of the GPL v3
// See the LICENSE file for full details
#ifndef _FLASH_FILESYSTEM_H
#define _FLASH_FILESYSTEM_H
int initialize_flash_filesystem(void);
#endif // _FLASH_FILESYSTEM_H
\ No newline at end of file
......@@ -64,6 +64,9 @@ void main(void)
k_sem_init(&kestrel_init_thread_lock, 0, UINT_MAX);
// Run early setup
initialize_flash_filesystem();
// Kick off Kestrel initialization thread
kestrel_init_thread_id = k_thread_create(&kestrel_init_thread_data, kestrel_init_thread_stack,
K_THREAD_STACK_SIZEOF(kestrel_init_thread_stack),
......
......@@ -18,6 +18,14 @@ CONFIG_SHELL_BACKEND_TELNET=y
CONFIG_THREAD_RUNTIME_STATS=y
CONFIG_THREAD_RUNTIME_STATS_USE_TIMING_FUNCTIONS=y
# Flash configuration
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
# Kestrel specific configuration
CONFIG_NET_TC_THREAD_PREEMPTIVE=n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment