You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/05/26 00:37:41 UTC

incubator-mynewt-core git commit: slinky, bootloader; make trying out config storage in NFFS vs FCB easier. If NFFS is included in build, use that. If that's not there, then expect FCB. Need to figure out a final answer on where and how this decision is

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop b63403ea0 -> 5fe4de767


slinky, bootloader; make trying out config storage in NFFS vs FCB easier.
If NFFS is included in build, use that. If that's not there, then
expect FCB. Need to figure out a final answer on where and how this
decision is made. Punting for now.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5fe4de76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5fe4de76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5fe4de76

Branch: refs/heads/develop
Commit: 5fe4de767bdeb241281d28e6742cd97e7df3cef0
Parents: b63403e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed May 25 17:34:37 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Wed May 25 17:34:37 2016 -0700

----------------------------------------------------------------------
 apps/boot/pkg.yml      |   6 +++
 apps/boot/src/boot.c   | 103 ++++++++++++++++++++++++++++++------------
 apps/slinky/pkg.yml    |   6 +++
 apps/slinky/src/main.c | 107 ++++++++++++++++++++++++++++++++------------
 4 files changed, 165 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/boot/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/boot/pkg.yml b/apps/boot/pkg.yml
index 3564ace..07d12a0 100644
--- a/apps/boot/pkg.yml
+++ b/apps/boot/pkg.yml
@@ -35,3 +35,9 @@ pkg.deps:
     - libs/os
     - libs/util
 pkg.cflags: -DLOG_LEVEL=255
+
+pkg.cflags.NFFS:
+    - "-DNFFS_PRESENT"
+
+pkg.cflags.FCB:
+    - "-DFCB_PRESENT"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/boot/src/boot.c
----------------------------------------------------------------------
diff --git a/apps/boot/src/boot.c b/apps/boot/src/boot.c
index d0bdb1c..14408b5 100755
--- a/apps/boot/src/boot.c
+++ b/apps/boot/src/boot.c
@@ -25,11 +25,17 @@
 #include <bsp/bsp.h>
 #include <hal/hal_system.h>
 #include <hal/hal_flash.h>
-#include <log/log.h>
 #include <config/config.h>
 #include <config/config_file.h>
-#include "fs/fs.h"
-#include "nffs/nffs.h"
+#ifdef NFFS_PRESENT
+#include <fs/fs.h>
+#include <nffs/nffs.h>
+#elif FCB_PRESENT
+#include <fcb/fcb.h>
+#include <config/config_fcb.h>
+#else
+#error "Need NFFS or FCB for config storage"
+#endif
 #include "bootutil/image.h"
 #include "bootutil/loader.h"
 #include "bootutil/bootutil_misc.h"
@@ -39,16 +45,75 @@
 #define BOOT_AREA_DESC_MAX  (256)
 #define AREA_DESC_MAX       (BOOT_AREA_DESC_MAX)
 
+#ifdef NFFS_PRESENT
 #define MY_CONFIG_FILE "/cfg/run"
 
 static struct conf_file my_conf = {
     .cf_name = MY_CONFIG_FILE
 };
 
+static void
+setup_for_nffs(void)
+{
+    struct nffs_area_desc nffs_descs[NFFS_AREA_MAX + 1];
+
+    /*
+     * Make sure we have enough left to initialize the NFFS with the
+     * right number of maximum areas otherwise the file-system will not
+     * be readable.
+     */
+    cnt = NFFS_AREA_MAX;
+    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, nffs_descs);
+    assert(rc == 0);
+
+    /*
+     * Initializes the flash driver and file system for use by the boot loader.
+     */
+    rc = nffs_init();
+    if (rc == 0) {
+        /* Look for an nffs file system in internal flash.  If no file
+         * system gets detected, all subsequent file operations will fail,
+         * but the boot loader should proceed anyway.
+         */
+        nffs_detect(nffs_descs);
+    }
+
+    rc = conf_file_src(&my_conf);
+    assert(rc == 0);
+    rc = conf_file_dst(&my_conf);
+    assert(rc == 0);
+}
+#else
+struct flash_area conf_fcb_area[NFFS_AREA_MAX + 1];
+
+static struct conf_fcb my_conf = {
+    .cf_fcb.f_magic = 0xc09f6e5e,
+    .cf_fcb.f_sectors = conf_fcb_area
+};
+
+static void
+setup_for_fcb(void)
+{
+    int cnt;
+    int rc;
+
+    rc = flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, NULL);
+    assert(rc == 0);
+    assert(cnt <= sizeof(conf_fcb_area) / sizeof(conf_fcb_area[0]));
+    flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, conf_fcb_area);
+
+    my_conf.cf_fcb.f_sector_cnt = cnt;
+
+    rc = conf_fcb_src(&my_conf);
+    assert(rc == 0);
+    rc = conf_fcb_dst(&my_conf);
+    assert(rc == 0);
+}
+#endif
+
 int
 main(void)
 {
-    struct nffs_area_desc nffs_descs[NFFS_AREA_MAX + 1];
     struct flash_area descs[AREA_DESC_MAX];
     /** Areas representing the beginning of image slots. */
     uint8_t img_starts[2];
@@ -87,33 +152,13 @@ main(void)
 
     req.br_num_image_areas = total;
 
-    /*
-     * Make sure we have enough left to initialize the NFFS with the
-     * right number of maximum areas otherwise the file-system will not
-     * be readable.
-     */
-    cnt = NFFS_AREA_MAX;
-    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, nffs_descs);
-    assert(rc == 0);
-
-    /*
-     * Initializes the flash driver and file system for use by the boot loader.
-     */
-    rc = nffs_init();
-    if (rc == 0) {
-        /* Look for an nffs file system in internal flash.  If no file
-         * system gets detected, all subsequent file operations will fail,
-         * but the boot loader should proceed anyway.
-         */
-        nffs_detect(nffs_descs);
-    }
-
     conf_init();
 
-    rc = conf_file_src(&my_conf);
-    assert(rc == 0);
-    rc = conf_file_dst(&my_conf);
-    assert(rc == 0);
+#ifdef NFFS_PRESENT
+    setup_for_nffs();
+#elif FCB_PRESENT
+    setup_for_fcb();
+#endif
     bootutil_cfg_register();
 
     rc = boot_go(&req, &rsp);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/slinky/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/slinky/pkg.yml b/apps/slinky/pkg.yml
index 1d3165a..add0c27 100644
--- a/apps/slinky/pkg.yml
+++ b/apps/slinky/pkg.yml
@@ -39,3 +39,9 @@ pkg.deps:
 
 pkg.cflags:
     - "-DSTATS_NAME_ENABLE=1"
+
+pkg.cflags.NFFS:
+    - "-DNFFS_PRESENT"
+
+pkg.cflags.FCB:
+    - "-DFCB_PRESENT"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index f505cf2..3c6d8d5 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -25,10 +25,18 @@
 #include <log/log.h>
 #include <stats/stats.h>
 #include <config/config.h>
-#include <config/config_file.h>
 #include <hal/flash_map.h>
+#include <hal/hal_system.h>
+#ifdef NFFS_PRESENT
 #include <fs/fs.h>
 #include <nffs/nffs.h>
+#include <config/config_file.h>
+#elif FCB_PRESENT
+#include <fcb/fcb.h>
+#include <config/config_fcb.h>
+#else
+#error "Need NFFS or FCB for config storage"
+#endif
 #include <newtmgr/newtmgr.h>
 #include <bootutil/image.h>
 #include <bootutil/bootutil_misc.h>
@@ -90,6 +98,7 @@ STATS_NAME_START(gpio_stats)
 STATS_NAME(gpio_stats, toggles)
 STATS_NAME_END(gpio_stats)
 
+#ifdef NFFS_PRESENT
 /* configuration file */
 #define MY_CONFIG_DIR  "/cfg"
 #define MY_CONFIG_FILE "/cfg/run"
@@ -97,6 +106,14 @@ STATS_NAME_END(gpio_stats)
 static struct conf_file my_conf = {
     .cf_name = MY_CONFIG_FILE
 };
+#elif FCB_PRESENT
+struct flash_area conf_fcb_area[NFFS_AREA_MAX + 1];
+
+static struct conf_fcb my_conf = {
+    .cf_fcb.f_magic = 0xc09f6e5e,
+    .cf_fcb.f_sectors = conf_fcb_area
+};
+#endif
 
 #define DEFAULT_MBUF_MPOOL_BUF_LEN (256)
 #define DEFAULT_MBUF_MPOOL_NBUFS (10)
@@ -246,6 +263,62 @@ init_tasks(void)
     return 0;
 }
 
+#ifdef NFFS_PRESENT
+static void
+setup_for_nffs(void)
+{
+    /* NFFS_AREA_MAX is defined in the BSP-specified bsp.h header file. */
+    struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
+    int cnt;
+    int rc;
+
+    /* Initialize nffs's internal state. */
+    rc = nffs_init();
+    assert(rc == 0);
+
+    /* Convert the set of flash blocks we intend to use for nffs into an array
+     * of nffs area descriptors.
+     */
+    cnt = NFFS_AREA_MAX;
+    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
+    assert(rc == 0);
+
+    /* Attempt to restore an existing nffs file system from flash. */
+    if (nffs_detect(descs) == FS_ECORRUPT) {
+        /* No valid nffs instance detected; format a new one. */
+        rc = nffs_format(descs);
+        assert(rc == 0);
+    }
+
+    fs_mkdir(MY_CONFIG_DIR);
+    rc = conf_file_src(&my_conf);
+    assert(rc == 0);
+    rc = conf_file_dst(&my_conf);
+    assert(rc == 0);
+}
+
+#elif FCB_PRESENT
+
+static void
+setup_for_fcb(void)
+{
+    int cnt;
+    int rc;
+
+    rc = flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, NULL);
+    assert(rc == 0);
+    assert(cnt <= sizeof(conf_fcb_area) / sizeof(conf_fcb_area[0]));
+    flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, conf_fcb_area);
+
+    my_conf.cf_fcb.f_sector_cnt = cnt;
+
+    rc = conf_fcb_src(&my_conf);
+    assert(rc == 0);
+    rc = conf_fcb_dst(&my_conf);
+    assert(rc == 0);
+}
+
+#endif
 
 /**
  * main
@@ -260,12 +333,8 @@ int
 main(int argc, char **argv)
 {
     int rc;
-    int cnt;
     struct image_version ver;
 
-    /* NFFS_AREA_MAX is defined in the BSP-specified bsp.h header file. */
-    struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
-
 #ifdef ARCH_sim
     mcu_sim_parse_args(argc, argv);
 #endif
@@ -296,29 +365,11 @@ main(int argc, char **argv)
     rc = hal_flash_init();
     assert(rc == 0);
 
-    /* Initialize nffs's internal state. */
-    rc = nffs_init();
-    assert(rc == 0);
-
-    /* Convert the set of flash blocks we intend to use for nffs into an array
-     * of nffs area descriptors.
-     */
-    cnt = NFFS_AREA_MAX;
-    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
-    assert(rc == 0);
-
-    /* Attempt to restore an existing nffs file system from flash. */
-    if (nffs_detect(descs) == FS_ECORRUPT) {
-        /* No valid nffs instance detected; format a new one. */
-        rc = nffs_format(descs);
-        assert(rc == 0);
-    }
-
-    fs_mkdir(MY_CONFIG_DIR);
-    rc = conf_file_src(&my_conf);
-    assert(rc == 0);
-    rc = conf_file_dst(&my_conf);
-    assert(rc == 0);
+#ifdef NFFS_PRESENT
+    setup_for_nffs();
+#elif FCB_PRESENT
+    setup_for_fcb();
+#endif
 
     shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
                     SHELL_MAX_INPUT_LEN);


Fwd: incubator-mynewt-core git commit: slinky, bootloader; make trying out config storage in NFFS vs FCB easier. If NFFS is included in build, use that. If that's not there, then expect FCB. Need to figure out a final answer on where and how this decision is

Posted by marko kiiskila <ma...@runtime.io>.
Hi,

this is a continuation of the plan to make building apps which don’t need/want NFFS
easier. Now you can build slinky and matching bootloader which use FCB instead of
NFFS. This has been possible even before, but I thought I’d make it easier for ppl to try
this out.

What you would do is change the package dependency for apps/boot/pkg.yml and
apps/slinky/pkg.yml to depend on sys/fcb, instead of fs/nffs.
As you can see from the commit, it sets up FCB config area over the area in flash
where NFFS would be.

Why use FCB instead of NFFS? NFFS has a bigger footprint in RAM and in flash,
and not all use cases need a filesystem.
Why bootloader and slinky do go together? Image management uses config variables to
communicate which image to boot next. So both the app and bootloader have to agree
on where this data is located.

Hope this helps,
M

> Begin forwarded message:
> 
> From: marko@apache.org
> Subject: incubator-mynewt-core git commit: slinky, bootloader; make trying out config storage in NFFS vs FCB easier. If NFFS is included in build, use that. If that's not there, then expect FCB. Need to figure out a final answer on where and how this decision is 
> Date: May 25, 2016 at 5:37:41 PM PDT
> To: commits@mynewt.incubator.apache.org
> Reply-To: dev@mynewt.incubator.apache.org
> 
> Repository: incubator-mynewt-core
> Updated Branches:
>  refs/heads/develop b63403ea0 -> 5fe4de767
> 
> 
> slinky, bootloader; make trying out config storage in NFFS vs FCB easier.
> If NFFS is included in build, use that. If that's not there, then
> expect FCB. Need to figure out a final answer on where and how this
> decision is made. Punting for now.
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
> Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5fe4de76
> Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5fe4de76
> Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5fe4de76
> 
> Branch: refs/heads/develop
> Commit: 5fe4de767bdeb241281d28e6742cd97e7df3cef0
> Parents: b63403e
> Author: Marko Kiiskila <ma...@runtime.io>
> Authored: Wed May 25 17:34:37 2016 -0700
> Committer: Marko Kiiskila <ma...@runtime.io>
> Committed: Wed May 25 17:34:37 2016 -0700
> 
> ----------------------------------------------------------------------
> apps/boot/pkg.yml      |   6 +++
> apps/boot/src/boot.c   | 103 ++++++++++++++++++++++++++++++------------
> apps/slinky/pkg.yml    |   6 +++
> apps/slinky/src/main.c | 107 ++++++++++++++++++++++++++++++++------------
> 4 files changed, 165 insertions(+), 57 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/boot/pkg.yml
> ----------------------------------------------------------------------
> diff --git a/apps/boot/pkg.yml b/apps/boot/pkg.yml
> index 3564ace..07d12a0 100644
> --- a/apps/boot/pkg.yml
> +++ b/apps/boot/pkg.yml
> @@ -35,3 +35,9 @@ pkg.deps:
>     - libs/os
>     - libs/util
> pkg.cflags: -DLOG_LEVEL=255
> +
> +pkg.cflags.NFFS:
> +    - "-DNFFS_PRESENT"
> +
> +pkg.cflags.FCB:
> +    - "-DFCB_PRESENT"
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/boot/src/boot.c
> ----------------------------------------------------------------------
> diff --git a/apps/boot/src/boot.c b/apps/boot/src/boot.c
> index d0bdb1c..14408b5 100755
> --- a/apps/boot/src/boot.c
> +++ b/apps/boot/src/boot.c
> @@ -25,11 +25,17 @@
> #include <bsp/bsp.h>
> #include <hal/hal_system.h>
> #include <hal/hal_flash.h>
> -#include <log/log.h>
> #include <config/config.h>
> #include <config/config_file.h>
> -#include "fs/fs.h"
> -#include "nffs/nffs.h"
> +#ifdef NFFS_PRESENT
> +#include <fs/fs.h>
> +#include <nffs/nffs.h>
> +#elif FCB_PRESENT
> +#include <fcb/fcb.h>
> +#include <config/config_fcb.h>
> +#else
> +#error "Need NFFS or FCB for config storage"
> +#endif
> #include "bootutil/image.h"
> #include "bootutil/loader.h"
> #include "bootutil/bootutil_misc.h"
> @@ -39,16 +45,75 @@
> #define BOOT_AREA_DESC_MAX  (256)
> #define AREA_DESC_MAX       (BOOT_AREA_DESC_MAX)
> 
> +#ifdef NFFS_PRESENT
> #define MY_CONFIG_FILE "/cfg/run"
> 
> static struct conf_file my_conf = {
>     .cf_name = MY_CONFIG_FILE
> };
> 
> +static void
> +setup_for_nffs(void)
> +{
> +    struct nffs_area_desc nffs_descs[NFFS_AREA_MAX + 1];
> +
> +    /*
> +     * Make sure we have enough left to initialize the NFFS with the
> +     * right number of maximum areas otherwise the file-system will not
> +     * be readable.
> +     */
> +    cnt = NFFS_AREA_MAX;
> +    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, nffs_descs);
> +    assert(rc == 0);
> +
> +    /*
> +     * Initializes the flash driver and file system for use by the boot loader.
> +     */
> +    rc = nffs_init();
> +    if (rc == 0) {
> +        /* Look for an nffs file system in internal flash.  If no file
> +         * system gets detected, all subsequent file operations will fail,
> +         * but the boot loader should proceed anyway.
> +         */
> +        nffs_detect(nffs_descs);
> +    }
> +
> +    rc = conf_file_src(&my_conf);
> +    assert(rc == 0);
> +    rc = conf_file_dst(&my_conf);
> +    assert(rc == 0);
> +}
> +#else
> +struct flash_area conf_fcb_area[NFFS_AREA_MAX + 1];
> +
> +static struct conf_fcb my_conf = {
> +    .cf_fcb.f_magic = 0xc09f6e5e,
> +    .cf_fcb.f_sectors = conf_fcb_area
> +};
> +
> +static void
> +setup_for_fcb(void)
> +{
> +    int cnt;
> +    int rc;
> +
> +    rc = flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, NULL);
> +    assert(rc == 0);
> +    assert(cnt <= sizeof(conf_fcb_area) / sizeof(conf_fcb_area[0]));
> +    flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, conf_fcb_area);
> +
> +    my_conf.cf_fcb.f_sector_cnt = cnt;
> +
> +    rc = conf_fcb_src(&my_conf);
> +    assert(rc == 0);
> +    rc = conf_fcb_dst(&my_conf);
> +    assert(rc == 0);
> +}
> +#endif
> +
> int
> main(void)
> {
> -    struct nffs_area_desc nffs_descs[NFFS_AREA_MAX + 1];
>     struct flash_area descs[AREA_DESC_MAX];
>     /** Areas representing the beginning of image slots. */
>     uint8_t img_starts[2];
> @@ -87,33 +152,13 @@ main(void)
> 
>     req.br_num_image_areas = total;
> 
> -    /*
> -     * Make sure we have enough left to initialize the NFFS with the
> -     * right number of maximum areas otherwise the file-system will not
> -     * be readable.
> -     */
> -    cnt = NFFS_AREA_MAX;
> -    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, nffs_descs);
> -    assert(rc == 0);
> -
> -    /*
> -     * Initializes the flash driver and file system for use by the boot loader.
> -     */
> -    rc = nffs_init();
> -    if (rc == 0) {
> -        /* Look for an nffs file system in internal flash.  If no file
> -         * system gets detected, all subsequent file operations will fail,
> -         * but the boot loader should proceed anyway.
> -         */
> -        nffs_detect(nffs_descs);
> -    }
> -
>     conf_init();
> 
> -    rc = conf_file_src(&my_conf);
> -    assert(rc == 0);
> -    rc = conf_file_dst(&my_conf);
> -    assert(rc == 0);
> +#ifdef NFFS_PRESENT
> +    setup_for_nffs();
> +#elif FCB_PRESENT
> +    setup_for_fcb();
> +#endif
>     bootutil_cfg_register();
> 
>     rc = boot_go(&req, &rsp);
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/slinky/pkg.yml
> ----------------------------------------------------------------------
> diff --git a/apps/slinky/pkg.yml b/apps/slinky/pkg.yml
> index 1d3165a..add0c27 100644
> --- a/apps/slinky/pkg.yml
> +++ b/apps/slinky/pkg.yml
> @@ -39,3 +39,9 @@ pkg.deps:
> 
> pkg.cflags:
>     - "-DSTATS_NAME_ENABLE=1"
> +
> +pkg.cflags.NFFS:
> +    - "-DNFFS_PRESENT"
> +
> +pkg.cflags.FCB:
> +    - "-DFCB_PRESENT"
> 
> http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5fe4de76/apps/slinky/src/main.c
> ----------------------------------------------------------------------
> diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
> index f505cf2..3c6d8d5 100755
> --- a/apps/slinky/src/main.c
> +++ b/apps/slinky/src/main.c
> @@ -25,10 +25,18 @@
> #include <log/log.h>
> #include <stats/stats.h>
> #include <config/config.h>
> -#include <config/config_file.h>
> #include <hal/flash_map.h>
> +#include <hal/hal_system.h>
> +#ifdef NFFS_PRESENT
> #include <fs/fs.h>
> #include <nffs/nffs.h>
> +#include <config/config_file.h>
> +#elif FCB_PRESENT
> +#include <fcb/fcb.h>
> +#include <config/config_fcb.h>
> +#else
> +#error "Need NFFS or FCB for config storage"
> +#endif
> #include <newtmgr/newtmgr.h>
> #include <bootutil/image.h>
> #include <bootutil/bootutil_misc.h>
> @@ -90,6 +98,7 @@ STATS_NAME_START(gpio_stats)
> STATS_NAME(gpio_stats, toggles)
> STATS_NAME_END(gpio_stats)
> 
> +#ifdef NFFS_PRESENT
> /* configuration file */
> #define MY_CONFIG_DIR  "/cfg"
> #define MY_CONFIG_FILE "/cfg/run"
> @@ -97,6 +106,14 @@ STATS_NAME_END(gpio_stats)
> static struct conf_file my_conf = {
>     .cf_name = MY_CONFIG_FILE
> };
> +#elif FCB_PRESENT
> +struct flash_area conf_fcb_area[NFFS_AREA_MAX + 1];
> +
> +static struct conf_fcb my_conf = {
> +    .cf_fcb.f_magic = 0xc09f6e5e,
> +    .cf_fcb.f_sectors = conf_fcb_area
> +};
> +#endif
> 
> #define DEFAULT_MBUF_MPOOL_BUF_LEN (256)
> #define DEFAULT_MBUF_MPOOL_NBUFS (10)
> @@ -246,6 +263,62 @@ init_tasks(void)
>     return 0;
> }
> 
> +#ifdef NFFS_PRESENT
> +static void
> +setup_for_nffs(void)
> +{
> +    /* NFFS_AREA_MAX is defined in the BSP-specified bsp.h header file. */
> +    struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
> +    int cnt;
> +    int rc;
> +
> +    /* Initialize nffs's internal state. */
> +    rc = nffs_init();
> +    assert(rc == 0);
> +
> +    /* Convert the set of flash blocks we intend to use for nffs into an array
> +     * of nffs area descriptors.
> +     */
> +    cnt = NFFS_AREA_MAX;
> +    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
> +    assert(rc == 0);
> +
> +    /* Attempt to restore an existing nffs file system from flash. */
> +    if (nffs_detect(descs) == FS_ECORRUPT) {
> +        /* No valid nffs instance detected; format a new one. */
> +        rc = nffs_format(descs);
> +        assert(rc == 0);
> +    }
> +
> +    fs_mkdir(MY_CONFIG_DIR);
> +    rc = conf_file_src(&my_conf);
> +    assert(rc == 0);
> +    rc = conf_file_dst(&my_conf);
> +    assert(rc == 0);
> +}
> +
> +#elif FCB_PRESENT
> +
> +static void
> +setup_for_fcb(void)
> +{
> +    int cnt;
> +    int rc;
> +
> +    rc = flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, NULL);
> +    assert(rc == 0);
> +    assert(cnt <= sizeof(conf_fcb_area) / sizeof(conf_fcb_area[0]));
> +    flash_area_to_sectors(FLASH_AREA_NFFS, &cnt, conf_fcb_area);
> +
> +    my_conf.cf_fcb.f_sector_cnt = cnt;
> +
> +    rc = conf_fcb_src(&my_conf);
> +    assert(rc == 0);
> +    rc = conf_fcb_dst(&my_conf);
> +    assert(rc == 0);
> +}
> +
> +#endif
> 
> /**
>  * main
> @@ -260,12 +333,8 @@ int
> main(int argc, char **argv)
> {
>     int rc;
> -    int cnt;
>     struct image_version ver;
> 
> -    /* NFFS_AREA_MAX is defined in the BSP-specified bsp.h header file. */
> -    struct nffs_area_desc descs[NFFS_AREA_MAX + 1];
> -
> #ifdef ARCH_sim
>     mcu_sim_parse_args(argc, argv);
> #endif
> @@ -296,29 +365,11 @@ main(int argc, char **argv)
>     rc = hal_flash_init();
>     assert(rc == 0);
> 
> -    /* Initialize nffs's internal state. */
> -    rc = nffs_init();
> -    assert(rc == 0);
> -
> -    /* Convert the set of flash blocks we intend to use for nffs into an array
> -     * of nffs area descriptors.
> -     */
> -    cnt = NFFS_AREA_MAX;
> -    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
> -    assert(rc == 0);
> -
> -    /* Attempt to restore an existing nffs file system from flash. */
> -    if (nffs_detect(descs) == FS_ECORRUPT) {
> -        /* No valid nffs instance detected; format a new one. */
> -        rc = nffs_format(descs);
> -        assert(rc == 0);
> -    }
> -
> -    fs_mkdir(MY_CONFIG_DIR);
> -    rc = conf_file_src(&my_conf);
> -    assert(rc == 0);
> -    rc = conf_file_dst(&my_conf);
> -    assert(rc == 0);
> +#ifdef NFFS_PRESENT
> +    setup_for_nffs();
> +#elif FCB_PRESENT
> +    setup_for_fcb();
> +#endif
> 
>     shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
>                     SHELL_MAX_INPUT_LEN);
>