nffs init
This commit is contained in:
1 parent
079c02cdef
commit
9e73ff6bdb
4 files changed
+44
-25
No files matched your search
@@ -36,16 +36,51 @@
|
||||
|
||||
#include "NewtNffs.h"
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "hal/hal_flash.h"
|
||||
|
||||
#define NFFS_AREA_MAX (7)
|
||||
|
||||
NewtNffs Nffs;
|
||||
|
||||
NewtNffs::NewtNffs(void)
|
||||
{
|
||||
errnum = FS_EOK;
|
||||
errnum = FS_EOK;
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
void NewtNffs::begin(void)
|
||||
bool NewtNffs::begin(void)
|
||||
{
|
||||
nffs_pkg_init();
|
||||
// Follow code in nffs_pkg_init()
|
||||
if (_initialized) return true;
|
||||
|
||||
// Init flash
|
||||
hal_flash_init();
|
||||
|
||||
/* Initialize nffs's internal state. */
|
||||
errnum = nffs_init();
|
||||
VERIFY_STATUS( errnum, false );
|
||||
|
||||
/* Convert the set of flash blocks we intend to use for nffs into an array
|
||||
* of nffs area descriptors.
|
||||
*/
|
||||
struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
|
||||
int cnt = NFFS_AREA_MAX;
|
||||
|
||||
errnum = nffs_misc_desc_from_flash_area( MYNEWT_VAL(NFFS_FLASH_AREA), &cnt, descs);
|
||||
VERIFY_STATUS( errnum, false );
|
||||
|
||||
/* Attempt to restore an existing nffs file system from flash. */
|
||||
errnum = nffs_detect(descs);
|
||||
|
||||
// If not formatted, format it
|
||||
if (FS_ECORRUPT == errnum)
|
||||
{
|
||||
errnum = nffs_format(descs);
|
||||
VERIFY_STATUS( errnum, false );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NewtNffs::format(void)
|
||||
|
||||
@@ -47,12 +47,15 @@
|
||||
|
||||
class NewtNffs
|
||||
{
|
||||
private:
|
||||
bool _initialized;
|
||||
|
||||
public:
|
||||
int errnum;
|
||||
|
||||
NewtNffs(void);
|
||||
|
||||
void begin(void);
|
||||
bool begin(void);
|
||||
|
||||
// Format the flash
|
||||
bool format(void);
|
||||
|
||||
@@ -65,8 +65,6 @@ int nffs_format(const struct nffs_area_desc *area_descs);
|
||||
|
||||
int nffs_misc_desc_from_flash_area(int idx, int *cnt, struct nffs_area_desc *nad);
|
||||
|
||||
void nffs_pkg_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -22,18 +22,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define NFFS_AREA_MAX 8
|
||||
|
||||
#define SYSINIT_ASSERT_ACTIVE()
|
||||
#define SYSINIT_PANIC_ASSERT(rc) do \
|
||||
{ \
|
||||
if (!(rc)) { \
|
||||
SYSINIT_PANIC(); \
|
||||
} \
|
||||
} while (0)
|
||||
#define SYSINIT_PANIC() return // assert(0)
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
//#include "sysinit/sysinit.h"
|
||||
//#include "sysflash/sysflash.h"
|
||||
//#include "bsp/bsp.h"
|
||||
@@ -756,23 +744,17 @@ nffs_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
nffs_pkg_init(void)
|
||||
{
|
||||
static bool already_init = false;
|
||||
|
||||
struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
|
||||
int cnt;
|
||||
int rc;
|
||||
|
||||
if (already_init) return;
|
||||
already_init = true;
|
||||
|
||||
/* Ensure this function only gets called by sysinit. */
|
||||
SYSINIT_ASSERT_ACTIVE();
|
||||
|
||||
hal_flash_init();
|
||||
|
||||
/* Initialize nffs's internal state. */
|
||||
rc = nffs_init();
|
||||
SYSINIT_PANIC_ASSERT(rc == 0);
|
||||
@@ -815,3 +797,4 @@ nffs_pkg_init(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user