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 2019/09/23 16:55:49 UTC
[mynewt-core] branch master updated (cae939f -> c223a3d)
This is an automated email from the ASF dual-hosted git repository.
marko pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.
from cae939f sensors/bma253: Fix uninitialized variable usage
new 70bb26d fs/fcb2; change data pointer to be const with fcb_write().
new c29e06d sys/log; support FCB2 as backing store.
new 43da6d7 fs/fcb2; add fcb_getprev() to walk backwards within FCB.
new 06474c0 sys/log/full; check if log index is > last entry before starting walk of FCB2 area.
new 887b8e9 sys/log; bring in log specific data structures from fs/fcb.
new 22f5f1a sys/log; enable bookmarks with FCB2.
new 1bfeb99 sys/reboot; can run when LOG_FCB2 has been selected.
new 661a2c8 sys/config & sys/log; use different magic numbers when using FCB vs FCB2.
new fba8e26 sys/log; fix incorrect if statement in log_fcb2_copy().
new 40c8f8e sys/log; simplify log_fcb2_copy(), no need to traverse the fcb to start the copy.
new eead0c8 sys/reboot; fix broken build when LOG_FCB is set.
new 87208eb fs/fcb2; do {} while(1) -> while(1) {}
new c223a3d sys/log/full; FCB2 watermarks & storage info. Fix return code from successful call to fcb_set_watermark(). Update incorrect doxygen comments.
The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
fs/fcb/include/fcb/fcb.h | 107 +----
fs/fcb/src/fcb.c | 4 +-
fs/fcb2/include/fcb/fcb.h | 25 +-
fs/fcb2/selftest/src/fcb_test.c | 2 +
fs/fcb2/selftest/src/testcases/fcb_test_getprev.c | 140 +++++++
.../selftest/src/testcases/fcb_test_last_of_n.c | 34 +-
fs/fcb2/src/fcb.c | 27 +-
fs/fcb2/src/fcb_append.c | 2 +-
fs/fcb2/src/fcb_elem_info.c | 2 +-
fs/fcb2/src/fcb_getnext.c | 6 -
fs/fcb2/src/fcb_getprev.c | 102 +++++
fs/fcb2/src/fcb_priv.h | 1 -
sys/config/syscfg.yml | 2 +
sys/log/common/include/log_common/log_common.h | 5 -
sys/log/full/include/log/log.h | 7 +-
sys/log/full/include/log/log_fcb.h | 136 ++++++
sys/log/full/pkg.yml | 5 +
.../full/selftest/{align8 => fcb2_align1}/pkg.yml | 8 +-
.../src/log_test_align1.c | 0
.../selftest/{align1 => fcb2_align1}/syscfg.yml | 2 +-
.../selftest/{align2 => fcb2_bookmarks}/pkg.yml | 9 +-
.../src/log_test_fcb_bookmarks.c | 0
.../src/log_test_fcb_bookmarks.h | 0
.../src/log_test_fcb_bookmarks_util.c | 47 +--
.../src/testcases/s0_l1_b0_p100.c | 0
.../src/testcases/s0_l1_b1_p100.c | 0
.../src/testcases/s100_l500_b10_p2000.c | 0
.../src/testcases/s10_l100_b10_p2000.c | 0
.../src/testcases/s10_l100_b1_p200.c | 0
.../{fcb_bookmarks => fcb2_bookmarks}/syscfg.yml | 3 +-
.../selftest/{align8 => fcb2_watermarks}/pkg.yml | 8 +-
.../src/log_test_fcb_watermarks.c} | 15 +-
.../fcb2_watermarks/src/log_test_fcb_watermarks.h | 24 +-
.../src/log_test_fcb_watermarks_util.c | 199 +++++++++
.../src/testcases/test_s0.c} | 11 +-
.../src/testcases/test_s10.c} | 9 +-
.../src/testcases/test_s100.c} | 11 +-
.../{fcb_bookmarks => fcb2_watermarks}/syscfg.yml | 7 +-
.../src/log_test_fcb_bookmarks_util.c | 6 +-
sys/log/full/selftest/util/src/log_test_util.c | 29 +-
sys/log/full/src/log.c | 6 +-
sys/log/full/src/log_fcb.c | 75 ++--
sys/log/full/src/{log_fcb.c => log_fcb2.c} | 464 ++++++++++++---------
.../log/full/src/log_fcb_bmark.c | 60 +--
sys/log/full/syscfg.yml | 10 +-
sys/reboot/pkg.yml | 5 +-
sys/reboot/src/log_reboot.c | 27 +-
sys/reboot/syscfg.yml | 2 +-
48 files changed, 1112 insertions(+), 532 deletions(-)
create mode 100644 fs/fcb2/selftest/src/testcases/fcb_test_getprev.c
create mode 100644 fs/fcb2/src/fcb_getprev.c
create mode 100644 sys/log/full/include/log/log_fcb.h
copy sys/log/full/selftest/{align8 => fcb2_align1}/pkg.yml (90%)
copy sys/log/full/selftest/{align1_imghash => fcb2_align1}/src/log_test_align1.c (100%)
copy sys/log/full/selftest/{align1 => fcb2_align1}/syscfg.yml (98%)
copy sys/log/full/selftest/{align2 => fcb2_bookmarks}/pkg.yml (87%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/log_test_fcb_bookmarks.c (100%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/log_test_fcb_bookmarks.h (100%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/log_test_fcb_bookmarks_util.c (85%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/testcases/s0_l1_b0_p100.c (100%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/testcases/s0_l1_b1_p100.c (100%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/testcases/s100_l500_b10_p2000.c (100%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/testcases/s10_l100_b10_p2000.c (100%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/src/testcases/s10_l100_b1_p200.c (100%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_bookmarks}/syscfg.yml (96%)
copy sys/log/full/selftest/{align8 => fcb2_watermarks}/pkg.yml (90%)
copy sys/log/full/selftest/{align2/src/log_test_align2.c => fcb2_watermarks/src/log_test_fcb_watermarks.c} (79%)
copy encoding/base64/selftest/src/encoding_test_priv.h => sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks.h (71%)
create mode 100644 sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks_util.c
copy sys/log/full/selftest/{fcb_bookmarks/src/testcases/s0_l1_b0_p100.c => fcb2_watermarks/src/testcases/test_s0.c} (81%)
copy sys/log/full/selftest/{fcb_bookmarks/src/testcases/s10_l100_b10_p2000.c => fcb2_watermarks/src/testcases/test_s10.c} (83%)
copy sys/log/full/selftest/{fcb_bookmarks/src/testcases/s100_l500_b10_p2000.c => fcb2_watermarks/src/testcases/test_s100.c} (81%)
copy sys/log/full/selftest/{fcb_bookmarks => fcb2_watermarks}/syscfg.yml (86%)
copy sys/log/full/src/{log_fcb.c => log_fcb2.c} (57%)
rename fs/fcb/src/fcb_bmark.c => sys/log/full/src/log_fcb_bmark.c (53%)
[mynewt-core] 13/13: sys/log/full;
FCB2 watermarks & storage info. Fix return code from successful
call to fcb_set_watermark(). Update incorrect doxygen comments.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit c223a3dee18c75653cf1c4f9521d87083e13bed3
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Tue Sep 3 13:29:39 2019 +0300
sys/log/full; FCB2 watermarks & storage info.
Fix return code from successful call to fcb_set_watermark().
Update incorrect doxygen comments.
---
sys/log/full/include/log/log_fcb.h | 38 ++--
.../src/log_test_fcb_bookmarks_util.c | 4 +-
sys/log/full/selftest/fcb2_watermarks/pkg.yml | 29 +++
.../fcb2_watermarks/src/log_test_fcb_watermarks.c | 37 ++++
.../fcb2_watermarks/src/log_test_fcb_watermarks.h | 38 ++++
.../src/log_test_fcb_watermarks_util.c | 199 +++++++++++++++++++++
.../fcb2_watermarks/src/testcases/test_s0.c | 31 ++++
.../fcb2_watermarks/src/testcases/test_s10.c | 31 ++++
.../fcb2_watermarks/src/testcases/test_s100.c | 31 ++++
sys/log/full/selftest/fcb2_watermarks/syscfg.yml | 25 +++
.../src/log_test_fcb_bookmarks_util.c | 4 +-
sys/log/full/src/log_fcb.c | 52 ++++--
sys/log/full/src/log_fcb2.c | 190 +++++++++++---------
sys/log/full/src/log_fcb_bmark.c | 54 +++---
14 files changed, 617 insertions(+), 146 deletions(-)
diff --git a/sys/log/full/include/log/log_fcb.h b/sys/log/full/include/log/log_fcb.h
index 9ab23f8..05e52f0 100644
--- a/sys/log/full/include/log/log_fcb.h
+++ b/sys/log/full/include/log/log_fcb.h
@@ -26,27 +26,27 @@ extern "C" {
#include <fcb/fcb.h>
/** An individual fcb log bookmark. */
-struct fcb_log_bmark {
+struct log_fcb_bmark {
/* FCB entry that the bookmark points to. */
- struct fcb_entry flb_entry;
+ struct fcb_entry lfb_entry;
/* The index of the log entry that the FCB entry contains. */
- uint32_t flb_index;
+ uint32_t lfb_index;
};
/** A set of fcb log bookmarks. */
-struct fcb_log_bset {
+struct log_fcb_bset {
/** Array of bookmarks. */
- struct fcb_log_bmark *fls_bmarks;
+ struct log_fcb_bmark *lfs_bmarks;
/** The maximum number of bookmarks. */
- int fls_cap;
+ int lfs_cap;
/** The number of currently usable bookmarks. */
- int fls_size;
+ int lfs_size;
/** The index where the next bookmark will get written. */
- int fls_next;
+ int lfs_next;
};
/**
@@ -57,11 +57,17 @@ struct fcb_log {
uint8_t fl_entries;
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
+#if MYNEWT_VAL(LOG_FCB)
/* Internal - tracking storage use */
uint32_t fl_watermark_off;
#endif
+#if MYNEWT_VAL(LOG_FCB2)
+ uint16_t fl_watermark_sec;
+ uint32_t fl_watermark_off;
+#endif
+#endif
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- struct fcb_log_bset fl_bset;
+ struct log_fcb_bset fl_bset;
#endif
};
@@ -86,18 +92,18 @@ struct fcb_log {
* @brief Configures an fcb_log to use the specified buffer for bookmarks.
*
* @param fcb_log The log to configure.
- * @param bmarks The buffer to use for bookmarks.
+ * @param buf The buffer to use for bookmarks.
* @param bmark_count The bookmark capacity of the supplied buffer.
*/
-void fcb_log_init_bmarks(struct fcb_log *fcb_log,
- struct fcb_log_bmark *buf, int bmark_count);
+void log_fcb_init_bmarks(struct fcb_log *fcb_log,
+ struct log_fcb_bmark *buf, int bmark_count);
/**
* @brief Erases all bookmarks from the supplied fcb_log.
*
* @param fcb_log The fcb_log to clear.
*/
-void fcb_log_clear_bmarks(struct fcb_log *fcb_log);
+void log_fcb_clear_bmarks(struct fcb_log *fcb_log);
/**
* @brief Searches an fcb_log for the closest bookmark that comes before or at
@@ -109,8 +115,8 @@ void fcb_log_clear_bmarks(struct fcb_log *fcb_log);
* @return The closest bookmark on success;
* NULL if the log has no applicable bookmarks.
*/
-const struct fcb_log_bmark *
-fcb_log_closest_bmark(const struct fcb_log *fcb_log, uint32_t index);
+const struct log_fcb_bmark *
+log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index);
/**
* Inserts a bookmark into the provided log.
@@ -119,7 +125,7 @@ fcb_log_closest_bmark(const struct fcb_log *fcb_log, uint32_t index);
* @param entry The entry the bookmark should point to.
* @param index The log entry index of the bookmark.
*/
-void fcb_log_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
+void log_fcb_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
uint32_t index);
#endif
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c
index 76421ba..25d7018 100644
--- a/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c
@@ -38,7 +38,7 @@ static int ltfbu_num_entry_idxs;
static struct fcb_log ltfbu_fcb_log;
static struct log ltfbu_log;
-static struct fcb_log_bmark ltfbu_bmarks[LTFBU_MAX_BMARKS];
+static struct log_fcb_bmark ltfbu_bmarks[LTFBU_MAX_BMARKS];
static struct flash_sector_range ltfbu_fcb_range = {
.fsr_flash_area = {
@@ -220,7 +220,7 @@ ltfbu_init(const struct ltfbu_cfg *cfg)
TEST_ASSERT_FATAL(rc == 0);
if (cfg->bmark_count > 0) {
- fcb_log_init_bmarks(<fbu_fcb_log, ltfbu_bmarks, cfg->bmark_count);
+ log_fcb_init_bmarks(<fbu_fcb_log, ltfbu_bmarks, cfg->bmark_count);
}
log_register("log", <fbu_log, &log_fcb_handler, <fbu_fcb_log,
diff --git a/sys/log/full/selftest/fcb2_watermarks/pkg.yml b/sys/log/full/selftest/fcb2_watermarks/pkg.yml
new file mode 100644
index 0000000..c9acd0a
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/pkg.yml
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+pkg.name: sys/log/full/selftest/fcb2_watermarks
+pkg.type: unittest
+pkg.description: "Log unit tests; FCB2 watermarks."
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "@apache-mynewt-core/sys/console/stub"
+ - "@apache-mynewt-core/sys/log/full"
+ - "@apache-mynewt-core/sys/log/full/selftest/util"
+ - "@apache-mynewt-core/test/testutil"
diff --git a/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks.c b/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks.c
new file mode 100644
index 0000000..03411e1
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks.c
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/mynewt.h"
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_watermarks.h"
+
+TEST_SUITE(log_test_suite_fcb_watermarks)
+{
+ log_test_case_fcb_watermarks_s0();
+ log_test_case_fcb_watermarks_s10();
+ log_test_case_fcb_watermarks_s100();
+}
+
+int
+main(int argc, char **argv)
+{
+ log_test_suite_fcb_watermarks();
+
+ return tu_any_failed;
+}
diff --git a/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks.h b/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks.h
new file mode 100644
index 0000000..62b8471
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks.h
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_LOG_TEST_FCB2_WATERMARKS_
+#define H_LOG_TEST_FCB2_WATERMARKS_
+
+#include "os/mynewt.h"
+#include "testutil/testutil.h"
+
+struct ltfwu_cfg {
+ int skip_mod;
+ int body_len;
+ int pop_count;
+};
+
+void ltfwu_test_once(const struct ltfwu_cfg *cfg);
+
+TEST_CASE_DECL(log_test_case_fcb_watermarks_s0);
+TEST_CASE_DECL(log_test_case_fcb_watermarks_s10);
+TEST_CASE_DECL(log_test_case_fcb_watermarks_s100);
+
+#endif
diff --git a/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks_util.c b/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks_util.c
new file mode 100644
index 0000000..4d74b0c
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/src/log_test_fcb_watermarks_util.c
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_watermarks.h"
+
+#define LTFWU_MAX_ENTRY_IDXS 20480
+#define LTFWU_MAX_BODY_LEN 1024
+
+#define LTFWU_SECTOR_SIZE (2048)
+
+static struct ltfwu_cfg ltfwu_cfg;
+
+static struct fcb_log ltfwu_fcb_log;
+static struct log ltfwu_log;
+
+static struct flash_sector_range ltfwu_fcb_range = {
+ .fsr_flash_area = {
+ .fa_off = 0 * LTFWU_SECTOR_SIZE,
+ .fa_size = 8 * LTFWU_SECTOR_SIZE,
+ },
+ .fsr_sector_count = 8,
+ .fsr_sector_size = LTFWU_SECTOR_SIZE,
+ .fsr_align = MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE)
+};
+
+static int
+ltfwu_skip_amount(void)
+{
+ if (ltfwu_cfg.skip_mod == 0) {
+ return 0;
+ } else {
+ return rand() % ltfwu_cfg.skip_mod;
+ }
+}
+
+static void
+ltfwu_skip(void)
+{
+ g_log_info.li_next_index += ltfwu_skip_amount();
+}
+
+static void
+ltfwu_write_entry(void)
+{
+ uint8_t body[LTFWU_MAX_BODY_LEN];
+ uint32_t idx;
+ int rc;
+
+ ltfwu_skip();
+ idx = g_log_info.li_next_index;
+
+ memset(body, idx, ltfwu_cfg.body_len);
+
+ rc = log_append_body(<fwu_log, 0, 255, LOG_ETYPE_BINARY, body,
+ ltfwu_cfg.body_len);
+ TEST_ASSERT_FATAL(rc == 0);
+}
+
+static void
+ltfwu_populate_log(int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ ltfwu_write_entry();
+ }
+}
+
+struct ltfwu_walk_arg {
+ int start_idx;
+ int amount_before;
+ int amount_total;
+};
+
+static int
+ltfwu_verify_log_walk(struct log *log, struct log_offset *log_offset,
+ const struct log_entry_hdr *hdr, void *dptr,
+ uint16_t len)
+{
+ struct ltfwu_walk_arg *arg;
+ struct log_storage_info info;
+ int rc;
+
+ arg = log_offset->lo_arg;
+ if (arg->start_idx == 0) {
+ arg->start_idx = hdr->ue_index;
+ }
+
+ rc = log_set_watermark(<fwu_log, hdr->ue_index);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ rc = log_storage_info(<fwu_log, &info);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ TEST_ASSERT(info.size - info.used_unread >= arg->amount_before);
+ TEST_ASSERT(info.used_unread < arg->amount_total);
+ TEST_ASSERT(info.used_unread <= info.used);
+ TEST_ASSERT(info.size == arg->amount_total);
+
+ arg->amount_before += len;
+
+ return 0;
+}
+
+static void
+ltfwu_verify_log(void)
+{
+ struct log_offset log_offset;
+ struct log_storage_info info;
+ struct ltfwu_walk_arg arg;
+ int rc;
+
+ memset(&arg, 0, sizeof(arg));
+ log_offset = (struct log_offset) {
+ .lo_arg = &arg,
+ .lo_index = 0,
+ .lo_ts = 0,
+ .lo_data_len = 0,
+ };
+
+ rc = log_storage_info(<fwu_log, &info);
+ TEST_ASSERT_FATAL(rc == 0);
+ TEST_ASSERT(info.size > 0);
+ TEST_ASSERT(info.size == 8 * LTFWU_SECTOR_SIZE);
+ TEST_ASSERT(info.used > 0);
+ TEST_ASSERT(info.used < info.size);
+ arg.amount_total = info.size;
+
+ rc = log_walk_body(<fwu_log, ltfwu_verify_log_walk, &log_offset);
+ TEST_ASSERT_FATAL(rc == 0);
+}
+
+static void
+ltfwu_init(const struct ltfwu_cfg *cfg)
+{
+ int rc;
+
+ /* Ensure tests are repeatable. */
+ srand(0);
+
+ ltfwu_cfg = *cfg;
+
+ ltfwu_fcb_log = (struct fcb_log) {
+ .fl_fcb.f_scratch_cnt = 1,
+ .fl_fcb.f_range_cnt = 1,
+ .fl_fcb.f_sector_cnt = ltfwu_fcb_range.fsr_sector_count,
+ .fl_fcb.f_ranges = <fwu_fcb_range,
+ .fl_fcb.f_magic = 0xBEADBAFA,
+ .fl_fcb.f_version = 0,
+ };
+
+ rc = flash_area_erase(<fwu_fcb_range.fsr_flash_area, 0,
+ ltfwu_fcb_range.fsr_flash_area.fa_size);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ rc = fcb_init(<fwu_fcb_log.fl_fcb);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ log_register("log", <fwu_log, &log_fcb_handler, <fwu_fcb_log,
+ LOG_SYSLEVEL);
+}
+
+void
+ltfwu_test_once(const struct ltfwu_cfg *cfg)
+{
+ int i;
+
+ ltfwu_init(cfg);
+
+ /* Do this three times:
+ * 1. Write a bunch of entries to the log.
+ * 2. Walk the log, watermark spot and check that storage report
+ * gives sane looking values.
+ *
+ * This procedure is repeated three times to ensure that the FCB is rotated
+ * between walks.
+ */
+ for (i = 0; i < 3; i++) {
+ ltfwu_populate_log(cfg->pop_count);
+
+ ltfwu_verify_log();
+ }
+}
diff --git a/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s0.c b/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s0.c
new file mode 100644
index 0000000..ca0d5dc
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s0.c
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_watermarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_watermarks_s0)
+{
+ struct ltfwu_cfg cfg = {
+ .skip_mod = 0,
+ .body_len = 10,
+ .pop_count = 100
+ };
+ ltfwu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s10.c b/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s10.c
new file mode 100644
index 0000000..f2f1a88
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s10.c
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_watermarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_watermarks_s10)
+{
+ struct ltfwu_cfg cfg = {
+ .skip_mod = 10,
+ .body_len = 100,
+ .pop_count = 2000,
+ };
+ ltfwu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s100.c b/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s100.c
new file mode 100644
index 0000000..4797855
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/src/testcases/test_s100.c
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_watermarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_watermarks_s100)
+{
+ struct ltfwu_cfg cfg = {
+ .skip_mod = 100,
+ .body_len = 400,
+ .pop_count = 2000,
+ };
+ ltfwu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_watermarks/syscfg.yml b/sys/log/full/selftest/fcb2_watermarks/syscfg.yml
new file mode 100644
index 0000000..90a22ee
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_watermarks/syscfg.yml
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.vals:
+ LOG_VERSION: 3
+ LOG_FCB2: 1
+ LOG_STORAGE_INFO: 1
+ LOG_STORAGE_WATERMARK: 1
+ MCU_FLASH_STYLE_ST: 0
+ MCU_FLASH_STYLE_NORDIC: 1
diff --git a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c b/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
index dca71d1..0ef66ed 100644
--- a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
+++ b/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
@@ -38,7 +38,7 @@ static int ltfbu_num_entry_idxs;
static struct fcb_log ltfbu_fcb_log;
static struct log ltfbu_log;
-static struct fcb_log_bmark ltfbu_bmarks[LTFBU_MAX_BMARKS];
+static struct log_fcb_bmark ltfbu_bmarks[LTFBU_MAX_BMARKS];
static struct flash_area ltfbu_fcb_areas[] = {
[0] = {
@@ -231,7 +231,7 @@ ltfbu_init(const struct ltfbu_cfg *cfg)
TEST_ASSERT_FATAL(rc == 0);
if (cfg->bmark_count > 0) {
- fcb_log_init_bmarks(<fbu_fcb_log, ltfbu_bmarks, cfg->bmark_count);
+ log_fcb_init_bmarks(<fbu_fcb_log, ltfbu_bmarks, cfg->bmark_count);
}
log_register("log", <fbu_log, &log_fcb_handler, <fbu_fcb_log,
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 376311a..9ee7048 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -30,7 +30,7 @@
/* Assume the flash alignment requirement is no stricter than 8. */
#define LOG_FCB_MAX_ALIGN 8
-static int log_fcb_rtr_erase(struct log *log, void *arg);
+static int log_fcb_rtr_erase(struct log *log);
/**
* Finds the first log entry whose "offset" is >= the one specified. A log
@@ -57,7 +57,7 @@ log_fcb_find_gte(struct log *log, struct log_offset *log_offset,
struct fcb_entry *out_entry)
{
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- const struct fcb_log_bmark *bmark;
+ const struct log_fcb_bmark *bmark;
#endif
struct log_entry_hdr hdr;
struct fcb_log *fcb_log;
@@ -96,9 +96,9 @@ log_fcb_find_gte(struct log *log, struct log_offset *log_offset,
}
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- bmark = fcb_log_closest_bmark(fcb_log, log_offset->lo_index);
+ bmark = log_fcb_closest_bmark(fcb_log, log_offset->lo_index);
if (bmark != NULL) {
- *out_entry = bmark->flb_entry;
+ *out_entry = bmark->lfb_entry;
}
#endif
@@ -142,7 +142,7 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
}
if (fcb_log->fl_entries) {
- rc = log_fcb_rtr_erase(log, fcb_log);
+ rc = log_fcb_rtr_erase(log);
if (rc) {
goto err;
}
@@ -161,7 +161,7 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
/* The FCB needs to be rotated. Invalidate all bookmarks. */
- fcb_log_clear_bmarks(fcb_log);
+ log_fcb_clear_bmarks(fcb_log);
#endif
rc = fcb_rotate(fcb);
@@ -225,7 +225,6 @@ log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
fcb_log = (struct fcb_log *)log->l_arg;
fcb = &fcb_log->fl_fcb;
- hdr_len = 0;
if (fcb->f_align > LOG_FCB_MAX_ALIGN) {
return SYS_ENOTSUP;
@@ -504,14 +503,18 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func,
* last entry), add a bookmark pointing to this walk's start location.
*/
if (log_offset->lo_ts >= 0) {
- fcb_log_add_bmark(fcb_log, &loc, log_offset->lo_index);
+ log_fcb_add_bmark(fcb_log, &loc, log_offset->lo_index);
}
#endif
do {
rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
if (rc != 0) {
- return rc;
+ if (rc < 0) {
+ return rc;
+ } else {
+ return 0;
+ }
}
} while (fcb_getnext(fcb, &loc) == 0);
@@ -528,7 +531,7 @@ log_fcb_flush(struct log *log)
fcb = &fcb_log->fl_fcb;
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- fcb_log_clear_bmarks(fcb_log);
+ log_fcb_clear_bmarks(fcb_log);
#endif
return fcb_clear(fcb);
@@ -657,7 +660,7 @@ log_fcb_new_watermark_index(struct log *log, struct log_offset *log_offset, void
/* Set log watermark to end of this element */
if (ueh.ue_index >= log_offset->lo_index) {
fl->fl_watermark_off = loc->fe_area->fa_off + loc->fe_data_off + loc->fe_data_len;
- return -1;
+ return 1;
} else {
return 0;
}
@@ -698,7 +701,11 @@ done:
/**
* Copies one log entry from source fcb to destination fcb
- * @param src_fcb, dst_fcb
+ *
+ * @param log Log this operation applies to
+ * @param entry FCB2 location for the entry being copied
+ * @param dst_fcb FCB2 area where data is getting copied to.
+ *
* @return 0 on success; non-zero on error
*/
static int
@@ -707,7 +714,7 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
{
struct log_entry_hdr ueh;
char data[LOG_PRINTF_MAX_ENTRY_LEN + LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN];
- uint16_t hdr_len = 0;
+ uint16_t hdr_len;
int dlen;
int rc;
struct fcb *fcb_tmp;
@@ -743,7 +750,12 @@ err:
/**
* Copies log entries from source fcb to destination fcb
- * @param src_fcb, dst_fcb, element offset to start copying
+ *
+ * @param log Log this operation applies to
+ * @param src_fcb FCB area which is the source of data
+ * @param dst_fcb FCB area which is the target
+ * @param offset Flash offset where to start the copy
+ *
* @return 0 on success; non-zero on error
*/
static int
@@ -770,13 +782,15 @@ log_fcb_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
}
/**
- * Flushes the log while restoring specified number of entries
+ * Flushes the log while keeping the specified number of entries
* using image scratch
- * @param src_fcb, dst_fcb
+ *
+ * @param log Log this operation applies to
+ *
* @return 0 on success; non-zero on error
*/
static int
-log_fcb_rtr_erase(struct log *log, void *arg)
+log_fcb_rtr_erase(struct log *log)
{
struct fcb_log *fcb_log;
struct fcb fcb_scratch;
@@ -792,8 +806,8 @@ log_fcb_rtr_erase(struct log *log, void *arg)
goto err;
}
- fcb_log = (struct fcb_log *)arg;
- fcb = (struct fcb *)fcb_log;
+ fcb_log = log->l_arg;
+ fcb = &fcb_log->fl_fcb;
memset(&fcb_scratch, 0, sizeof(fcb_scratch));
diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c
index 535ee36..6528202 100644
--- a/sys/log/full/src/log_fcb2.c
+++ b/sys/log/full/src/log_fcb2.c
@@ -30,7 +30,7 @@
/* Assume the flash alignment requirement is no stricter than 8. */
#define LOG_FCB2_MAX_ALIGN 8
-static int log_fcb2_rtr_erase(struct log *log, void *arg);
+static int log_fcb2_rtr_erase(struct log *log);
/**
* Finds the first log entry whose "offset" is >= the one specified. A log
@@ -57,7 +57,7 @@ log_fcb2_find_gte(struct log *log, struct log_offset *log_offset,
struct fcb_entry *out_entry)
{
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- const struct fcb_log_bmark *bmark;
+ const struct log_fcb_bmark *bmark;
#endif
struct log_entry_hdr hdr;
struct fcb_log *fcb_log;
@@ -103,9 +103,9 @@ log_fcb2_find_gte(struct log *log, struct log_offset *log_offset,
return SYS_EUNKNOWN;
}
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- bmark = fcb_log_closest_bmark(fcb_log, log_offset->lo_index);
+ bmark = log_fcb_closest_bmark(fcb_log, log_offset->lo_index);
if (bmark != NULL) {
- *out_entry = bmark->flb_entry;
+ *out_entry = bmark->lfb_entry;
}
#endif
@@ -130,7 +130,7 @@ log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc)
struct fcb *fcb;
struct fcb_log *fcb_log;
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
- struct flash_area *old_fa;
+ int old_sec;
#endif
int rc = 0;
#if MYNEWT_VAL(LOG_STATS)
@@ -151,7 +151,7 @@ log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc)
}
if (fcb_log->fl_entries) {
- rc = log_fcb2_rtr_erase(log, fcb_log);
+ rc = log_fcb2_rtr_erase(log);
if (rc) {
goto err;
}
@@ -159,17 +159,11 @@ log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc)
}
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
- old_fa = fcb->f_oldest;
- (void)old_fa; /* to avoid #ifdefs everywhere... */
+ old_sec = fcb->f_oldest_sec;
#endif
#if MYNEWT_VAL(LOG_STATS)
-#if MYNEWT_VAL(LOG_FCB)
- rc = fcb_area_info(fcb, NULL, &cnt, NULL);
-#endif
-#if MYNEWT_VAL(LOG_FCB2)
rc = fcb_area_info(fcb, FCB_SECTOR_OLDEST, &cnt, NULL);
-#endif
if (rc == 0) {
LOG_STATS_INCN(log, lost, cnt);
}
@@ -177,7 +171,7 @@ log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc)
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
/* The FCB needs to be rotated. Invalidate all bookmarks. */
- fcb_log_clear_bmarks(fcb_log);
+ log_fcb_clear_bmarks(fcb_log);
#endif
rc = fcb_rotate(fcb);
@@ -191,9 +185,9 @@ log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc)
* oldest flash area which was erased. If yes, then move watermark to
* beginning of current oldest area.
*/
- if ((fcb_log->fl_watermark_off >= old_fa->fa_off) &&
- (fcb_log->fl_watermark_off < old_fa->fa_off + old_fa->fa_size)) {
- fcb_log->fl_watermark_off = fcb->f_oldest->fa_off;
+ if (fcb_log->fl_watermark_sec == old_sec) {
+ fcb_log->fl_watermark_sec = fcb->f_oldest_sec;
+ fcb_log->fl_watermark_off = 0;
}
#endif
}
@@ -236,8 +230,6 @@ log_fcb2_append_body(struct log *log, const struct log_entry_hdr *hdr,
int rc;
uint16_t hdr_len;
- hdr_len = 0;
-
hdr_len = log_hdr_len(hdr);
rc = log_fcb2_start_append(log, hdr_len + body_len, &loc);
@@ -507,14 +499,18 @@ log_fcb2_walk(struct log *log, log_walk_func_t walk_func,
* last entry), add a bookmark pointing to this walk's start location.
*/
if (log_off->lo_ts >= 0) {
- fcb_log_add_bmark(fcb_log, &loc, log_off->lo_index);
+ log_fcb_add_bmark(fcb_log, &loc, log_off->lo_index);
}
#endif
do {
rc = walk_func(log, log_off, &loc, loc.fe_data_len);
if (rc != 0) {
- return rc;
+ if (rc < 0) {
+ return rc;
+ } else {
+ return 0;
+ }
}
} while (fcb_getnext(fcb, &loc) == 0);
@@ -531,7 +527,7 @@ log_fcb2_flush(struct log *log)
fcb = &fcb_log->fl_fcb;
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- fcb_log_clear_bmarks(fcb_log);
+ log_fcb_clear_bmarks(fcb_log);
#endif
return fcb_clear(fcb);
@@ -564,12 +560,15 @@ log_fcb2_registered(struct log *log)
memset(&loc, 0, sizeof(loc));
if (fcb_getnext(fcb, &loc)) {
- fl->fl_watermark_off = loc.fe_area->fa_off + loc.fe_elem_off;
+ fl->fl_watermark_sec = loc.fe_sector;
+ fl->fl_watermark_off = loc.fe_data_off;
} else {
- fl->fl_watermark_off = fcb->f_oldest->fa_off;
+ fl->fl_watermark_sec = fcb->f_oldest_sec;
+ fl->fl_watermark_off = 0;
}
#else
/* Initialize watermark to designated unknown value*/
+ fl->fl_watermark_sec = FCB_SECTOR_OLDEST;
fl->fl_watermark_off = 0xffffffff;
#endif
#endif
@@ -582,13 +581,11 @@ log_fcb2_storage_info(struct log *log, struct log_storage_info *info)
{
struct fcb_log *fl;
struct fcb *fcb;
- struct flash_area *fa;
- uint32_t el_min;
- uint32_t el_max;
- uint32_t fa_min;
- uint32_t fa_max;
- uint32_t fa_size;
- uint32_t fa_used;
+ int i;
+ int j;
+ int sec;
+ uint16_t el_min_sec;
+ uint16_t el_max_sec;
int rc;
fl = (struct fcb_log *)log->l_arg;
@@ -599,45 +596,63 @@ log_fcb2_storage_info(struct log *log, struct log_storage_info *info)
return FCB_ERR_ARGS;
}
- /*
- * Calculate location of 1st entry.
- * We assume 1st log entry starts at beginning of oldest sector in FCB.
- * This is because even if 1st entry is in the middle of sector (is this
- * even possible?) we will never use free space before it thus that space
- * can be also considered used.
- */
- el_min = fcb->f_oldest->fa_off;
+ el_min_sec = fcb->f_oldest_sec;
+ el_max_sec = fcb->f_active.fe_sector;
- /* Calculate end location of last entry */
- el_max = fcb->f_active.fe_area->fa_off + fcb->f_active.fe_elem_off;
-
- /* Sectors assigned to FCB are guaranteed to be contiguous */
- fa = &fcb->f_sectors[0];
- fa_min = fa->fa_off;
- fa = &fcb->f_sectors[fcb->f_sector_cnt - 1];
- fa_max = fa->fa_off + fa->fa_size;
- fa_size = fa_max - fa_min;
+ info->size = 0;
+ info->used = 0;
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
+ info->used_unread = 0;
+#endif
- /* Calculate used size */
- fa_used = el_max - el_min;
- if ((int32_t)fa_used < 0) {
- fa_used += fa_size;
+ sec = 0;
+ for (i = 0; i < fcb->f_range_cnt; i++) {
+ info->size += fcb->f_ranges[i].fsr_flash_area.fa_size;
+ for (j = 0; j < fcb->f_ranges[i].fsr_sector_count; j++, sec++) {
+ if (el_min_sec < el_max_sec) {
+ if (sec >= el_min_sec && sec < el_max_sec) {
+ info->used += fcb->f_ranges[i].fsr_sector_size;
+ }
+ } else if (el_max_sec < el_min_sec) {
+ if (sec < el_max_sec || sec >= el_min_sec) {
+ info->used += fcb->f_ranges[i].fsr_sector_size;
+ }
+ }
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
+ if (fl->fl_watermark_sec < el_max_sec) {
+ if (sec > fl->fl_watermark_sec && sec < el_max_sec) {
+ info->used_unread += fcb->f_ranges[i].fsr_sector_size;
+ }
+ } else if (fl->fl_watermark_sec > el_max_sec) {
+ if (sec < el_max_sec || sec > fl->fl_watermark_sec) {
+ info->used_unread += fcb->f_ranges[i].fsr_sector_size;
+ }
+ }
+#endif
+ if (sec == el_max_sec) {
+ info->used += fcb->f_active.fe_data_off;
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
+ if (sec != fl->fl_watermark_sec) {
+ info->used_unread += fcb->f_active.fe_data_off;
+ } else {
+ info->used_unread += fcb->f_active.fe_data_off -
+ fl->fl_watermark_off;
+ }
+#endif
+ } else {
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
+ if (sec == fl->fl_watermark_sec) {
+ info->used_unread += fcb->f_ranges[i].fsr_sector_size -
+ fl->fl_watermark_off;
+ }
+#endif
+ }
+ }
}
-
- info->size = fa_size;
- info->used = fa_used;
-
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
- /* Calculate used size */
- fa_used = el_max - fl->fl_watermark_off;
-
- if (fl->fl_watermark_off == 0xffffffff){
- fa_used = 0xffffffff;
- } else if ((int32_t)fa_used < 0) {
- fa_used += fa_size;
+ if (fl->fl_watermark_sec == FCB_SECTOR_OLDEST) {
+ info->used_unread = 0xffffffff;
}
-
- info->used_unread = fa_used;
#endif
os_mutex_release(&fcb->f_mtx);
@@ -656,19 +671,20 @@ log_fcb2_new_watermark_index(struct log *log, struct log_offset *log_off,
struct log_entry_hdr ueh;
int rc;
- loc = (struct fcb_entry*)dptr;
+ loc = (struct fcb_entry *)dptr;
fl = (struct fcb_log *)log->l_arg;
- rc = log_fcb_read(log, loc, &ueh, 0, sizeof(ueh));
+ rc = log_fcb2_read(log, loc, &ueh, 0, sizeof(ueh));
if (rc != sizeof(ueh)) {
return -1;
}
+
/* Set log watermark to end of this element */
if (ueh.ue_index >= log_off->lo_index) {
- fl->fl_watermark_off = loc->fe_area->fa_off + loc->fe_data_off +
- loc->fe_data_len;
- return -1;
+ fl->fl_watermark_sec = loc->fe_sector;
+ fl->fl_watermark_off = loc->fe_data_off + loc->fe_data_len;
+ return 1;
} else {
return 0;
}
@@ -698,7 +714,8 @@ log_fcb2_set_watermark(struct log *log, uint32_t index)
/* If there are no entries to read and the watermark has not been set */
if (fl->fl_watermark_off == 0xffffffff) {
- fl->fl_watermark_off = fcb->f_oldest->fa_off;
+ fl->fl_watermark_sec = fcb->f_oldest_sec;
+ fl->fl_watermark_off = 0;
}
return (0);
@@ -709,7 +726,11 @@ done:
/**
* Copies one log entry from source fcb to destination fcb
- * @param src_fcb, dst_fcb
+ *
+ * @param log Log this operation applies to
+ * @param entry FCB2 location for the entry being copied
+ * @param dst_fcb FCB2 area where data is getting copied to.
+ *
* @return 0 on success; non-zero on error
*/
static int
@@ -719,7 +740,7 @@ log_fcb2_copy_entry(struct log *log, struct fcb_entry *entry,
struct log_entry_hdr ueh;
char data[LOG_PRINTF_MAX_ENTRY_LEN + LOG_BASE_ENTRY_HDR_SIZE +
LOG_IMG_HASHLEN];
- uint16_t hdr_len = 0;
+ uint16_t hdr_len;
int dlen;
int rc;
struct fcb *fcb_tmp;
@@ -738,7 +759,9 @@ log_fcb2_copy_entry(struct log *log, struct fcb_entry *entry,
goto err;
}
- /* Changing the fcb to be logged to be dst fcb */
+ /*
+ * Changing the fcb to be logged to be dst fcb.
+ */
fcb_tmp = log->l_arg;
log->l_arg = dst_fcb;
rc = log_fcb2_append(log, data, dlen);
@@ -753,7 +776,12 @@ err:
/**
* Copies log entries from source fcb to destination fcb
- * @param src_fcb, dst_fcb, element to start copying from
+ *
+ * @param log Log this operation applies to
+ * @param src_fcb FCB2 area which is the source of data
+ * @param dst_fcb FCB2 area which is the target
+ * @param from FCB2 location where to start the copy
+ *
* @return 0 on success; non-zero on error
*/
static int
@@ -782,13 +810,15 @@ log_fcb2_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
}
/**
- * Flushes the log while restoring specified number of entries
+ * Flushes the log while keeping the specified number of entries
* using image scratch
- * @param src_fcb, dst_fcb
+ *
+ * @param log Log this operation applies to
+ *
* @return 0 on success; non-zero on error
*/
static int
-log_fcb2_rtr_erase(struct log *log, void *arg)
+log_fcb2_rtr_erase(struct log *log)
{
struct fcb_log *fcb_log;
struct fcb fcb_scratch;
@@ -804,8 +834,8 @@ log_fcb2_rtr_erase(struct log *log, void *arg)
goto err;
}
- fcb_log = (struct fcb_log *)arg;
- fcb = (struct fcb *)fcb_log;
+ fcb_log = log->l_arg;
+ fcb = &fcb_log->fl_fcb;
memset(&fcb_scratch, 0, sizeof(fcb_scratch));
diff --git a/sys/log/full/src/log_fcb_bmark.c b/sys/log/full/src/log_fcb_bmark.c
index 1f8c1a7..92e4791 100644
--- a/sys/log/full/src/log_fcb_bmark.c
+++ b/sys/log/full/src/log_fcb_bmark.c
@@ -26,27 +26,27 @@
#include "log/log_fcb.h"
void
-fcb_log_init_bmarks(struct fcb_log *fcb_log,
- struct fcb_log_bmark *buf, int bmark_count)
+log_fcb_init_bmarks(struct fcb_log *fcb_log,
+ struct log_fcb_bmark *buf, int bmark_count)
{
- fcb_log->fl_bset = (struct fcb_log_bset) {
- .fls_bmarks = buf,
- .fls_cap = bmark_count,
+ fcb_log->fl_bset = (struct log_fcb_bset) {
+ .lfs_bmarks = buf,
+ .lfs_cap = bmark_count,
};
}
void
-fcb_log_clear_bmarks(struct fcb_log *fcb_log)
+log_fcb_clear_bmarks(struct fcb_log *fcb_log)
{
- fcb_log->fl_bset.fls_size = 0;
- fcb_log->fl_bset.fls_next = 0;
+ fcb_log->fl_bset.lfs_size = 0;
+ fcb_log->fl_bset.lfs_next = 0;
}
-const struct fcb_log_bmark *
-fcb_log_closest_bmark(const struct fcb_log *fcb_log, uint32_t index)
+const struct log_fcb_bmark *
+log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index)
{
- const struct fcb_log_bmark *closest;
- const struct fcb_log_bmark *bmark;
+ const struct log_fcb_bmark *closest;
+ const struct log_fcb_bmark *bmark;
uint32_t min_diff;
uint32_t diff;
int i;
@@ -54,10 +54,10 @@ fcb_log_closest_bmark(const struct fcb_log *fcb_log, uint32_t index)
min_diff = UINT32_MAX;
closest = NULL;
- for (i = 0; i < fcb_log->fl_bset.fls_size; i++) {
- bmark = &fcb_log->fl_bset.fls_bmarks[i];
- if (bmark->flb_index <= index) {
- diff = index - bmark->flb_index;
+ for (i = 0; i < fcb_log->fl_bset.lfs_size; i++) {
+ bmark = &fcb_log->fl_bset.lfs_bmarks[i];
+ if (bmark->lfb_index <= index) {
+ diff = index - bmark->lfb_index;
if (diff < min_diff) {
min_diff = diff;
closest = bmark;
@@ -69,29 +69,29 @@ fcb_log_closest_bmark(const struct fcb_log *fcb_log, uint32_t index)
}
void
-fcb_log_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
+log_fcb_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
uint32_t index)
{
- struct fcb_log_bset *bset;
+ struct log_fcb_bset *bset;
bset = &fcb_log->fl_bset;
- if (bset->fls_cap == 0) {
+ if (bset->lfs_cap == 0) {
return;
}
- bset->fls_bmarks[bset->fls_next] = (struct fcb_log_bmark) {
- .flb_entry = *entry,
- .flb_index = index,
+ bset->lfs_bmarks[bset->lfs_next] = (struct log_fcb_bmark) {
+ .lfb_entry = *entry,
+ .lfb_index = index,
};
- if (bset->fls_size < bset->fls_cap) {
- bset->fls_size++;
+ if (bset->lfs_size < bset->lfs_cap) {
+ bset->lfs_size++;
}
- bset->fls_next++;
- if (bset->fls_next >= bset->fls_cap) {
- bset->fls_next = 0;
+ bset->lfs_next++;
+ if (bset->lfs_next >= bset->lfs_cap) {
+ bset->lfs_next = 0;
}
}
[mynewt-core] 10/13: sys/log;
simplify log_fcb2_copy(), no need to traverse the fcb to start the
copy.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 40c8f8eca981190fc135e5f5e0b7c30cd05ba05b
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Fri Aug 30 13:41:45 2019 +0300
sys/log; simplify log_fcb2_copy(), no need to traverse the fcb
to start the copy.
---
sys/log/full/src/log_fcb2.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c
index f59883e..535ee36 100644
--- a/sys/log/full/src/log_fcb2.c
+++ b/sys/log/full/src/log_fcb2.c
@@ -739,8 +739,7 @@ log_fcb2_copy_entry(struct log *log, struct fcb_entry *entry,
}
/* Changing the fcb to be logged to be dst fcb */
- fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
-
+ fcb_tmp = log->l_arg;
log->l_arg = dst_fcb;
rc = log_fcb2_append(log, data, dlen);
log->l_arg = fcb_tmp;
@@ -763,24 +762,21 @@ log_fcb2_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
{
struct fcb_entry entry;
int rc;
- int copy = 0;
rc = 0;
- memset(&entry, 0, sizeof(entry));
- while (!fcb_getnext(src_fcb, &entry)) {
- if (!copy) {
- if (from && (entry.fe_range != from->fe_range ||
- entry.fe_data_off != from->fe_data_off)) {
- continue;
- }
- copy = 1;
- }
+ entry = *from;
+ do {
rc = log_fcb2_copy_entry(log, &entry, dst_fcb);
if (rc) {
break;
}
- }
+ rc = fcb_getnext(src_fcb, &entry);
+ if (rc == FCB_ERR_NOVAR) {
+ rc = 0;
+ break;
+ }
+ } while (rc == 0);
return (rc);
}
@@ -848,8 +844,13 @@ log_fcb2_rtr_erase(struct log *log, void *arg)
goto err;
}
+ memset(&entry, 0, sizeof(entry));
+ rc = fcb_getnext(&fcb_scratch, &entry);
+ if (rc) {
+ goto err;
+ }
/* Copy back from scratch */
- rc = log_fcb2_copy(log, &fcb_scratch, fcb, NULL);
+ rc = log_fcb2_copy(log, &fcb_scratch, fcb, &entry);
err:
return (rc);
[mynewt-core] 05/13: sys/log;
bring in log specific data structures from fs/fcb.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 887b8e908779689e68e6917caa413f7db0ef007a
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Thu Aug 29 12:53:20 2019 +0300
sys/log; bring in log specific data structures from fs/fcb.
---
fs/fcb/include/fcb/fcb.h | 107 +----------------
fs/fcb/src/fcb.c | 4 +-
fs/fcb2/include/fcb/fcb.h | 19 +--
sys/log/full/include/log/log.h | 3 +
.../fcb.h => sys/log/full/include/log/log_fcb.h | 129 +--------------------
.../log/full/src/log_fcb_bmark.c | 6 +-
6 files changed, 22 insertions(+), 246 deletions(-)
diff --git a/fs/fcb/include/fcb/fcb.h b/fs/fcb/include/fcb/fcb.h
index 4d02956..f198e18 100644
--- a/fs/fcb/include/fcb/fcb.h
+++ b/fs/fcb/include/fcb/fcb.h
@@ -30,9 +30,11 @@ extern "C" {
#include <inttypes.h>
#include <limits.h>
+#include <assert.h>
-#include "os/mynewt.h"
-#include "flash_map/flash_map.h"
+#include <syscfg/syscfg.h>
+#include <os/os_mutex.h>
+#include <flash_map/flash_map.h>
#define FCB_MAX_LEN (CHAR_MAX | CHAR_MAX << 7) /* Max length of element */
@@ -78,46 +80,6 @@ struct fcb {
int fcb_init(struct fcb *fcb);
-/** An individual fcb log bookmark. */
-struct fcb_log_bmark {
- /* FCB entry that the bookmark points to. */
- struct fcb_entry flb_entry;
-
- /* The index of the log entry that the FCB entry contains. */
- uint32_t flb_index;
-};
-
-/** A set of fcb log bookmarks. */
-struct fcb_log_bset {
- /** Array of bookmarks. */
- struct fcb_log_bmark *fls_bmarks;
-
- /** The maximum number of bookmarks. */
- int fls_cap;
-
- /** The number of currently usable bookmarks. */
- int fls_size;
-
- /** The index where the next bookmark will get written. */
- int fls_next;
-};
-
-/**
- * fcb_log is needed as the number of entries in a log
- */
-struct fcb_log {
- struct fcb fl_fcb;
- uint8_t fl_entries;
-
-#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
- /* Internal - tracking storage use */
- uint32_t fl_watermark_off;
-#endif
-#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
- struct fcb_log_bset fl_bset;
-#endif
-};
-
/**
* fcb_append() appends an entry to circular buffer. When writing the
* contents for the entry, use loc->fl_area and loc->fl_data_off with
@@ -128,7 +90,7 @@ int fcb_append(struct fcb *, uint16_t len, struct fcb_entry *loc);
int fcb_append_finish(struct fcb *, struct fcb_entry *append_loc);
/**
- * Walk over all log entries in FCB, or entries in a given flash_area.
+ * Walk over all entries in FCB.
* cb gets called for every entry. If cb wants to stop the walk, it should
* return non-zero value.
*
@@ -178,65 +140,6 @@ int fcb_clear(struct fcb *fcb);
int fcb_area_info(struct fcb *fcb, struct flash_area *fa, int *elemsp,
int *bytesp);
-
-#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
-
-/**
- * Bookmarks are an optimization to speed up lookups in FCB-backed logs. The
- * concept is simple: maintain a set of flash area+offset pairs corresponding
- * to recently found log entries. When we perform a log lookup, the walk
- * starts from the bookmark closest to our desired entry rather than from the
- * beginning of the log.
- *
- * Bookmarks are stored in a circular buffer in the fcb_log object. Each time
- * the log is walked, the starting point of the walk is added to the set of
- * bookmarks.
- *
- * FCB rotation invalidates all bookmarks. It is up to the client code to
- * clear a log's bookmarks whenever rotation occurs.
- */
-
-/**
- * @brief Configures an fcb_log to use the specified buffer for bookmarks.
- *
- * @param fcb_log The log to configure.
- * @param bmarks The buffer to use for bookmarks.
- * @param bmark_count The bookmark capacity of the supplied buffer.
- */
-void fcb_log_init_bmarks(struct fcb_log *fcb_log,
- struct fcb_log_bmark *buf, int bmark_count);
-
-/**
- * @brief Erases all bookmarks from the supplied fcb_log.
- *
- * @param fcb_log The fcb_log to clear.
- */
-void fcb_log_clear_bmarks(struct fcb_log *fcb_log);
-
-/**
- * @brief Searches an fcb_log for the closest bookmark that comes before or at
- * the specified index.
- *
- * @param fcb_log The log to search.
- * @param index The index to look for.
- *
- * @return The closest bookmark on success;
- * NULL if the log has no applicable bookmarks.
- */
-const struct fcb_log_bmark *
-fcb_log_closest_bmark(const struct fcb_log *fcb_log, uint32_t index);
-
-/**
- * Inserts a bookmark into the provided log.
- *
- * @param fcb_log The log to insert a bookmark into.
- * @param entry The entry the bookmark should point to.
- * @param index The log entry index of the bookmark.
- */
-void fcb_log_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
- uint32_t index);
-#endif
-
#ifdef __cplusplus
}
diff --git a/fs/fcb/src/fcb.c b/fs/fcb/src/fcb.c
index 59d4054..0fe7e1f 100644
--- a/fs/fcb/src/fcb.c
+++ b/fs/fcb/src/fcb.c
@@ -216,7 +216,7 @@ fcb_sector_hdr_read(struct fcb *fcb, struct flash_area *fap,
* @param0 ptr to fcb
* @param1 n number of fcb entries the user wants to get
* @param2 ptr to the fcb_entry to be returned
- * @return 0 on there are any fcbs aviable; OS_ENOENT otherwise
+ * @return 0 on there are any fcbs aviable; FCB_ERR_NOVAR otherwise
*/
int
fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
@@ -243,7 +243,7 @@ fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
i++;
}
- return (i == 0) ? OS_ENOENT : 0;
+ return (i == 0) ? FCB_ERR_NOVAR : 0;
}
/**
diff --git a/fs/fcb2/include/fcb/fcb.h b/fs/fcb2/include/fcb/fcb.h
index 1b4049d..a0c3772 100644
--- a/fs/fcb2/include/fcb/fcb.h
+++ b/fs/fcb2/include/fcb/fcb.h
@@ -30,9 +30,11 @@ extern "C" {
#include <inttypes.h>
#include <limits.h>
+#include <assert.h>
-#include "os/mynewt.h"
-#include "flash_map/flash_map.h"
+#include <syscfg/syscfg.h>
+#include <os/os_mutex.h>
+#include <flash_map/flash_map.h>
#define FCB_MAX_LEN (CHAR_MAX | CHAR_MAX << 7) /* Max length of element */
@@ -105,19 +107,6 @@ int fcb_init_flash_area(struct fcb *fcb, int flash_area_id, uint32_t magic,
uint8_t version);
/**
- * fcb_log is needed as the number of entries in a log
- */
-struct fcb_log {
- struct fcb fl_fcb;
- uint8_t fl_entries;
-
-#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
- /* Internal - tracking storage use */
- uint32_t fl_watermark_off;
-#endif
-};
-
-/**
* fcb_append() appends an entry to circular buffer. When writing the
* contents for the entry, fcb_write() with fcb_entry filled by.
* fcb_append(). When you're finished, call fcb_append_finish() with
diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index d583473..78adb70 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -25,6 +25,9 @@
#if MYNEWT_VAL(LOG_STATS)
#include "stats/stats.h"
#endif
+#if MYNEWT_VAL(LOG_FCB) || MYNEWT_VAL(LOG_FCB2)
+#include "log/log_fcb.h"
+#endif
#if MYNEWT_VAL(LOG_FLAGS_IMAGE_HASH)
#define LOG_HDR_SIZE 19
diff --git a/fs/fcb/include/fcb/fcb.h b/sys/log/full/include/log/log_fcb.h
similarity index 54%
copy from fs/fcb/include/fcb/fcb.h
copy to sys/log/full/include/log/log_fcb.h
index 4d02956..9ab23f8 100644
--- a/fs/fcb/include/fcb/fcb.h
+++ b/sys/log/full/include/log/log_fcb.h
@@ -16,67 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
-#ifndef __SYS_FCB_H_
-#define __SYS_FCB_H_
+#ifndef __SYS_LOG_FCB_H_
+#define __SYS_LOG_FCB_H_
#ifdef __cplusplus
extern "C" {
#endif
-/**
- * \defgroup FCB Flash circular buffer.
- * @{
- */
-
-#include <inttypes.h>
-#include <limits.h>
-
-#include "os/mynewt.h"
-#include "flash_map/flash_map.h"
-
-#define FCB_MAX_LEN (CHAR_MAX | CHAR_MAX << 7) /* Max length of element */
-
-/**
- * Entry location is pointer to area (within fcb->f_sectors), and offset
- * within that area.
- */
-struct fcb_entry {
- struct flash_area *fe_area; /* ptr to area within fcb->f_sectors */
- uint32_t fe_elem_off; /* start of entry */
- uint32_t fe_data_off; /* start of data */
- uint16_t fe_data_len; /* size of data area */
-};
-
-struct fcb {
- /* Caller of fcb_init fills this in */
- uint32_t f_magic; /* As placed on the disk */
- uint8_t f_version; /* Current version number of the data */
- uint8_t f_sector_cnt; /* Number of elements in sector array */
- uint8_t f_scratch_cnt; /* How many sectors should be kept empty */
- struct flash_area *f_sectors; /* Array of sectors, must be contiguous */
-
- /* Flash circular buffer internal state */
- struct os_mutex f_mtx; /* Locking for accessing the FCB data */
- struct flash_area *f_oldest;
- struct fcb_entry f_active;
- uint16_t f_active_id;
- uint8_t f_align; /* writes to flash have to aligned to this */
-};
-
-/**
- * Error codes.
- */
-#define FCB_OK 0
-#define FCB_ERR_ARGS -1
-#define FCB_ERR_FLASH -2
-#define FCB_ERR_NOVAR -3
-#define FCB_ERR_NOSPACE -4
-#define FCB_ERR_NOMEM -5
-#define FCB_ERR_CRC -6
-#define FCB_ERR_MAGIC -7
-#define FCB_ERR_VERSION -8
-
-int fcb_init(struct fcb *fcb);
+#include <fcb/fcb.h>
/** An individual fcb log bookmark. */
struct fcb_log_bmark {
@@ -118,67 +65,6 @@ struct fcb_log {
#endif
};
-/**
- * fcb_append() appends an entry to circular buffer. When writing the
- * contents for the entry, use loc->fl_area and loc->fl_data_off with
- * flash_area_write(). When you're finished, call fcb_append_finish() with
- * loc as argument.
- */
-int fcb_append(struct fcb *, uint16_t len, struct fcb_entry *loc);
-int fcb_append_finish(struct fcb *, struct fcb_entry *append_loc);
-
-/**
- * Walk over all log entries in FCB, or entries in a given flash_area.
- * cb gets called for every entry. If cb wants to stop the walk, it should
- * return non-zero value.
- *
- * Entry data can be read using flash_area_read(), using
- * loc->fe_area, loc->fe_data_off, and loc->fe_data_len as arguments.
- */
-typedef int (*fcb_walk_cb)(struct fcb_entry *loc, void *arg);
-int fcb_walk(struct fcb *, struct flash_area *, fcb_walk_cb cb, void *cb_arg);
-int fcb_getnext(struct fcb *, struct fcb_entry *loc);
-
-/**
- * Erases the data from oldest sector.
- */
-int fcb_rotate(struct fcb *);
-
-/**
- * Start using the scratch block.
- */
-int fcb_append_to_scratch(struct fcb *);
-
-/**
- * How many sectors are unused.
- */
-int fcb_free_sector_cnt(struct fcb *fcb);
-
-/**
- * Whether FCB has any data.
- */
-int fcb_is_empty(struct fcb *fcb);
-
-/**
- * Element at offset *entries* from last position (backwards).
- */
-int
-fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
- struct fcb_entry *last_n_entry);
-
-/**
- * Clears FCB passed to it
- */
-int fcb_clear(struct fcb *fcb);
-
-/**
- * Usage report for a given FCB area. Returns number of elements and the
- * number of bytes stored in them.
- */
-int fcb_area_info(struct fcb *fcb, struct flash_area *fa, int *elemsp,
- int *bytesp);
-
-
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
/**
@@ -190,7 +76,7 @@ int fcb_area_info(struct fcb *fcb, struct flash_area *fa, int *elemsp,
*
* Bookmarks are stored in a circular buffer in the fcb_log object. Each time
* the log is walked, the starting point of the walk is added to the set of
- * bookmarks.
+ * bookmarks.
*
* FCB rotation invalidates all bookmarks. It is up to the client code to
* clear a log's bookmarks whenever rotation occurs.
@@ -239,11 +125,6 @@ void fcb_log_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
#ifdef __cplusplus
}
-
-/**
- * @} FCB
- */
-
#endif
-#endif /* __SYS_FLASHVAR_H_ */
+#endif /* __SYS_LOG_FCB_H_ */
diff --git a/fs/fcb/src/fcb_bmark.c b/sys/log/full/src/log_fcb_bmark.c
similarity index 97%
rename from fs/fcb/src/fcb_bmark.c
rename to sys/log/full/src/log_fcb_bmark.c
index 8f9b3eb..1f8c1a7 100644
--- a/fs/fcb/src/fcb_bmark.c
+++ b/sys/log/full/src/log_fcb_bmark.c
@@ -17,13 +17,13 @@
* under the License.
*/
+#include <string.h>
+
#include "os/mynewt.h"
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
-#include "fcb/fcb.h"
-#include "fcb_priv.h"
-#include "string.h"
+#include "log/log_fcb.h"
void
fcb_log_init_bmarks(struct fcb_log *fcb_log,
[mynewt-core] 03/13: fs/fcb2;
add fcb_getprev() to walk backwards within FCB.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 43da6d720ba4bfb608c1766f949b8a47dd5253b2
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Wed Aug 28 10:33:03 2019 +0300
fs/fcb2; add fcb_getprev() to walk backwards within FCB.
---
fs/fcb2/include/fcb/fcb.h | 3 +-
fs/fcb2/selftest/src/fcb_test.c | 2 +
fs/fcb2/selftest/src/testcases/fcb_test_getprev.c | 140 +++++++++++++++++++++
.../selftest/src/testcases/fcb_test_last_of_n.c | 34 ++---
fs/fcb2/src/fcb.c | 27 ++--
fs/fcb2/src/fcb_elem_info.c | 2 +-
fs/fcb2/src/fcb_getnext.c | 6 -
fs/fcb2/src/fcb_getprev.c | 102 +++++++++++++++
fs/fcb2/src/fcb_priv.h | 1 -
9 files changed, 276 insertions(+), 41 deletions(-)
diff --git a/fs/fcb2/include/fcb/fcb.h b/fs/fcb2/include/fcb/fcb.h
index 83b99fd..1b4049d 100644
--- a/fs/fcb2/include/fcb/fcb.h
+++ b/fs/fcb2/include/fcb/fcb.h
@@ -138,6 +138,7 @@ int fcb_append_finish(struct fcb_entry *append_loc);
typedef int (*fcb_walk_cb)(struct fcb_entry *loc, void *arg);
int fcb_walk(struct fcb *, int sector, fcb_walk_cb cb, void *cb_arg);
int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc);
+int fcb_getprev(struct fcb *fcb, struct fcb_entry *loc);
int fcb_read(struct fcb_entry *loc, uint16_t off, void *buf, uint16_t len);
/**
@@ -165,7 +166,7 @@ int fcb_is_empty(struct fcb *fcb);
*/
int
fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
- struct fcb_entry *last_n_entry);
+ struct fcb_entry *last_n_entry);
/**
* Erase sector in FCB
diff --git a/fs/fcb2/selftest/src/fcb_test.c b/fs/fcb2/selftest/src/fcb_test.c
index a16e40c..0a29f55 100644
--- a/fs/fcb2/selftest/src/fcb_test.c
+++ b/fs/fcb2/selftest/src/fcb_test.c
@@ -141,6 +141,7 @@ TEST_CASE_DECL(fcb_test_rotate)
TEST_CASE_DECL(fcb_test_multiple_scratch)
TEST_CASE_DECL(fcb_test_last_of_n)
TEST_CASE_DECL(fcb_test_area_info)
+TEST_CASE_DECL(fcb_test_getprev)
TEST_SUITE(fcb_test_all)
{
@@ -154,6 +155,7 @@ TEST_SUITE(fcb_test_all)
fcb_test_multiple_scratch();
fcb_test_last_of_n();
fcb_test_area_info();
+ fcb_test_getprev();
}
int
diff --git a/fs/fcb2/selftest/src/testcases/fcb_test_getprev.c b/fs/fcb2/selftest/src/testcases/fcb_test_getprev.c
new file mode 100644
index 0000000..ec1a255
--- /dev/null
+++ b/fs/fcb2/selftest/src/testcases/fcb_test_getprev.c
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "fcb_test.h"
+
+TEST_CASE_SELF(fcb_test_getprev)
+{
+ struct fcb *fcb = &test_fcb;
+ struct fcb_entry loc;
+ struct fcb_entry prev;
+ int rc;
+ int i, j;
+
+ fcb_tc_pretest(3);
+
+ prev.fe_range = NULL;
+
+ /*
+ * Empty FCB returns error.
+ */
+ rc = fcb_getprev(fcb, &prev);
+ TEST_ASSERT_FATAL(rc == FCB_ERR_NOVAR);
+
+ /*
+ * Add one entry. getprev should find that guy, and then error.
+ */
+ rc = fcb_append(fcb, 8, &loc);
+ TEST_ASSERT(rc == 0);
+ rc = fcb_append_finish(&loc);
+ TEST_ASSERT(rc == 0);
+
+ prev.fe_range = NULL;
+ rc = fcb_getprev(fcb, &prev);
+ TEST_ASSERT_FATAL(rc == 0);
+ TEST_ASSERT(!memcmp(&loc, &prev, sizeof(loc)));
+
+ rc = fcb_getprev(fcb, &prev);
+ TEST_ASSERT(rc == FCB_ERR_NOVAR);
+
+ /*
+ * Add enough entries to go to 2 sectors, should find them all.
+ */
+ fcb_tc_pretest(3);
+ for (i = 0; ; i++) {
+ rc = fcb_append(fcb, i + 1, &loc);
+ TEST_ASSERT(rc == 0);
+ rc = fcb_append_finish(&loc);
+ TEST_ASSERT(rc == 0);
+
+ if (loc.fe_sector == prev.fe_sector + 2) {
+ break;
+ }
+ }
+
+ prev.fe_range = NULL;
+ for (j = i; j >= 0; j--) {
+ rc = fcb_getprev(fcb, &prev);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(prev.fe_data_len == j + 1);
+ }
+ rc = fcb_getprev(fcb, &prev);
+ TEST_ASSERT(rc == FCB_ERR_NOVAR);
+
+ /*
+ * Clean the area. Fill 2 whole sectors with corrupt entries. And one
+ * good one. Should find the one good one, followed by error
+ */
+ fcb_tc_pretest(3);
+
+ for (i = 0; ; i++) {
+ rc = fcb_append(fcb, i + 1, &loc);
+ TEST_ASSERT(rc == 0);
+
+ if (loc.fe_sector == prev.fe_sector + 2) {
+ rc = fcb_append_finish(&loc);
+ TEST_ASSERT(rc == 0);
+ break;
+ }
+ }
+
+ prev.fe_range = NULL;
+ rc = fcb_getprev(fcb, &prev);
+ TEST_ASSERT_FATAL(rc == 0);
+ TEST_ASSERT(!memcmp(&loc, &prev, sizeof(loc)));
+
+ rc = fcb_getprev(fcb, &prev);
+ TEST_ASSERT(rc == FCB_ERR_NOVAR);
+
+ /*
+ * Create new. Rotate one sector, should be able to follow
+ * from end of range to start.
+ */
+
+ fcb_tc_pretest(3);
+
+ for (i = 0; ; i++) {
+ rc = fcb_append(fcb, i + 8, &loc);
+ if (rc == FCB_ERR_NOSPACE) {
+ break;
+ }
+ TEST_ASSERT(rc == 0);
+ rc = fcb_append_finish(&loc);
+ TEST_ASSERT(rc == 0);
+ }
+
+ /*
+ * Full. Rotate, add one more, and then walk backwards.
+ */
+ fcb_rotate(fcb);
+
+ rc = fcb_append(fcb, i + 8, &loc);
+ TEST_ASSERT(rc == 0);
+ rc = fcb_append_finish(&loc);
+ TEST_ASSERT(rc == 0);
+
+ for (j = i; j >= 0; j--) {
+ rc = fcb_getprev(fcb, &prev);
+ if (rc == FCB_ERR_NOVAR) {
+ TEST_ASSERT(i > 0);
+ break;
+ }
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(prev.fe_data_len == j + 8);
+ }
+}
diff --git a/fs/fcb2/selftest/src/testcases/fcb_test_last_of_n.c b/fs/fcb2/selftest/src/testcases/fcb_test_last_of_n.c
index 10ca3d7..2a6c3cd 100644
--- a/fs/fcb2/selftest/src/testcases/fcb_test_last_of_n.c
+++ b/fs/fcb2/selftest/src/testcases/fcb_test_last_of_n.c
@@ -35,7 +35,7 @@ TEST_CASE_SELF(fcb_test_last_of_n)
/* No fcbs available */
rc = fcb_offset_last_n(fcb, 1, &loc);
- assert (rc != 0);
+ TEST_ASSERT(rc != 0);
/*
* Add some fcbs.
@@ -57,29 +57,29 @@ TEST_CASE_SELF(fcb_test_last_of_n)
/* last entry */
rc = fcb_offset_last_n(fcb, 1, &loc);
- assert (rc == 0);
- assert (areas[4].fe_sector == loc.fe_sector);
- assert (areas[4].fe_data_off == loc.fe_data_off);
- assert (areas[4].fe_data_len == loc.fe_data_len);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(areas[4].fe_sector == loc.fe_sector);
+ TEST_ASSERT(areas[4].fe_data_off == loc.fe_data_off);
+ TEST_ASSERT(areas[4].fe_data_len == loc.fe_data_len);
/* somewhere in the middle */
rc = fcb_offset_last_n(fcb, 3, &loc);
- assert (rc == 0);
- assert (areas[2].fe_sector == loc.fe_sector);
- assert (areas[2].fe_data_off == loc.fe_data_off);
- assert (areas[2].fe_data_len == loc.fe_data_len);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(areas[2].fe_sector == loc.fe_sector);
+ TEST_ASSERT(areas[2].fe_data_off == loc.fe_data_off);
+ TEST_ASSERT(areas[2].fe_data_len == loc.fe_data_len);
/* first entry */
rc = fcb_offset_last_n(fcb, 5, &loc);
- assert (rc == 0);
- assert (areas[0].fe_sector == loc.fe_sector);
- assert (areas[0].fe_data_off == loc.fe_data_off);
- assert (areas[0].fe_data_len == loc.fe_data_len);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(areas[0].fe_sector == loc.fe_sector);
+ TEST_ASSERT(areas[0].fe_data_off == loc.fe_data_off);
+ TEST_ASSERT(areas[0].fe_data_len == loc.fe_data_len);
/* after last valid entry, returns the first one like for 5 */
rc = fcb_offset_last_n(fcb, 6, &loc);
- assert (rc == 0);
- assert (areas[0].fe_sector == loc.fe_sector);
- assert (areas[0].fe_data_off == loc.fe_data_off);
- assert (areas[0].fe_data_len == loc.fe_data_len);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(areas[0].fe_sector == loc.fe_sector);
+ TEST_ASSERT(areas[0].fe_data_off == loc.fe_data_off);
+ TEST_ASSERT(areas[0].fe_data_len == loc.fe_data_len);
}
diff --git a/fs/fcb2/src/fcb.c b/fs/fcb2/src/fcb.c
index 3ec9cf2..80451d6 100644
--- a/fs/fcb2/src/fcb.c
+++ b/fs/fcb2/src/fcb.c
@@ -122,7 +122,8 @@ fcb_is_empty(struct fcb *fcb)
{
return (fcb->f_active.fe_sector == fcb->f_oldest_sec &&
fcb->f_active.fe_data_off ==
- fcb_len_in_flash(fcb->f_active.fe_range, sizeof(struct fcb_disk_area)));
+ fcb_len_in_flash(fcb->f_active.fe_range,
+ sizeof(struct fcb_disk_area)));
}
struct flash_sector_range *
@@ -217,10 +218,8 @@ fcb_sector_hdr_read(struct fcb *fcb, struct flash_sector_range *srp,
* @return 0 on there are any fcbs aviable; OS_ENOENT otherwise
*/
int
-fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
- struct fcb_entry *last_n_entry)
+fcb_offset_last_n(struct fcb *fcb, uint8_t entries, struct fcb_entry *loc)
{
- struct fcb_entry loc;
int i;
/* assure a minimum amount of entries */
@@ -229,19 +228,16 @@ fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
}
i = 0;
- memset(&loc, 0, sizeof(loc));
- while (!fcb_getnext(fcb, &loc)) {
- if (i == 0) {
- /* Start from the beginning of fcb entries */
- *last_n_entry = loc;
- } else if (i > (entries - 1)) {
- /* Update last_n_entry after n entries and keep updating */
- fcb_getnext(fcb, last_n_entry);
- }
+ memset(loc, 0, sizeof(*loc));
+ while (!fcb_getprev(fcb, loc)) {
+ --entries;
i++;
+ if (entries == 0) {
+ break;
+ }
}
- return (i == 0) ? OS_ENOENT : 0;
+ return (i == 0) ? FCB_ERR_NOVAR : 0;
}
/**
@@ -285,7 +281,8 @@ fcb_init_flash_area(struct fcb *fcb, int flash_area_id, uint32_t magic,
assert(rc == 0 && sector_range_cnt > 0);
sector_ranges = malloc(sizeof(struct flash_sector_range) * sector_range_cnt);
assert(sector_ranges);
- rc = flash_area_to_sector_ranges(flash_area_id, §or_range_cnt, sector_ranges);
+ rc = flash_area_to_sector_ranges(flash_area_id, §or_range_cnt,
+ sector_ranges);
assert(rc == 0 && sector_range_cnt > 0);
fcb->f_ranges = sector_ranges;
diff --git a/fs/fcb2/src/fcb_elem_info.c b/fs/fcb2/src/fcb_elem_info.c
index 413eea2..a222f36 100644
--- a/fs/fcb2/src/fcb_elem_info.c
+++ b/fs/fcb2/src/fcb_elem_info.c
@@ -57,7 +57,7 @@ fcb_elem_crc16(struct fcb_entry *loc, uint16_t *c16p)
return 0;
}
-int
+static int
fcb_read_entry(struct fcb_entry *loc)
{
uint8_t buf[FCB_ENTRY_SIZE];
diff --git a/fs/fcb2/src/fcb_getnext.c b/fs/fcb2/src/fcb_getnext.c
index 4284afe..f90e26d 100644
--- a/fs/fcb2/src/fcb_getnext.c
+++ b/fs/fcb2/src/fcb_getnext.c
@@ -59,9 +59,6 @@ fcb_getnext_nolock(struct fcb *fcb, struct fcb_entry *loc)
* If offset is zero, we serve the first entry from the area.
*/
loc->fe_entry_num = 1;
- loc->fe_data_off =
- fcb_len_in_flash(loc->fe_range, sizeof(struct fcb_disk_area));
- loc->fe_data_len = 0;
rc = fcb_elem_info(loc);
} else {
rc = fcb_getnext_in_area(fcb, loc);
@@ -91,9 +88,6 @@ next_sector:
loc->fe_sector = fcb_getnext_sector(fcb, loc->fe_sector);
loc->fe_range = fcb_get_sector_range(fcb, loc->fe_sector);
loc->fe_entry_num = 1;
- loc->fe_data_off =
- fcb_len_in_flash(loc->fe_range, sizeof(struct fcb_disk_area));
- loc->fe_data_len = 0;
rc = fcb_elem_info(loc);
switch (rc) {
case 0:
diff --git a/fs/fcb2/src/fcb_getprev.c b/fs/fcb2/src/fcb_getprev.c
new file mode 100644
index 0000000..6cdbe33
--- /dev/null
+++ b/fs/fcb2/src/fcb_getprev.c
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <stddef.h>
+
+#include "fcb/fcb.h"
+#include "fcb_priv.h"
+
+static int
+fcb_sector_find_last(struct fcb *fcb, struct fcb_entry *loc)
+{
+ int rc;
+ int last_valid = 0;
+
+ loc->fe_entry_num = 1;
+
+ do {
+ rc = fcb_elem_info(loc);
+ if (rc == 0) {
+ last_valid = loc->fe_entry_num;
+ }
+ if (rc == FCB_ERR_NOVAR) {
+ /*
+ * Out entries in this sector
+ */
+ if (last_valid == 0) {
+ loc->fe_entry_num = 1;
+ /*
+ * No valid entries in this sector.
+ */
+ return FCB_ERR_NOVAR;
+ } else {
+ loc->fe_entry_num = last_valid;
+ rc = fcb_elem_info(loc);
+ assert(rc == 0); /* must be; just succeeded a bit earlier */
+ return rc;
+ }
+ }
+ loc->fe_entry_num++;
+ } while (1);
+ return rc;
+}
+
+int
+fcb_getprev(struct fcb *fcb, struct fcb_entry *loc)
+{
+ int rc;
+
+ rc = os_mutex_pend(&fcb->f_mtx, OS_WAIT_FOREVER);
+ if (rc && rc != OS_NOT_STARTED) {
+ return FCB_ERR_ARGS;
+ }
+ if (loc->fe_range == NULL) {
+ /*
+ * Find the last element.
+ */
+ *loc = fcb->f_active;
+ }
+ do {
+ loc->fe_entry_num--;
+ if (loc->fe_entry_num < 1) {
+ /*
+ * Need to get from previous sector.
+ */
+ if (loc->fe_sector == fcb->f_oldest_sec) {
+ return FCB_ERR_NOVAR;
+ }
+ if (loc->fe_sector == 0) {
+ loc->fe_sector = fcb->f_sector_cnt - 1;
+ } else {
+ loc->fe_sector--;
+ }
+ loc->fe_range = fcb_get_sector_range(fcb, loc->fe_sector);
+ rc = fcb_sector_find_last(fcb, loc);
+ if (rc == 0) {
+ break;
+ }
+ } else {
+ rc = fcb_elem_info(loc);
+ if (rc == 0) {
+ break;
+ }
+ }
+ } while (1);
+ os_mutex_release(&fcb->f_mtx);
+ return rc;
+}
diff --git a/fs/fcb2/src/fcb_priv.h b/fs/fcb2/src/fcb_priv.h
index 63f18e3..a1ec9d5 100644
--- a/fs/fcb2/src/fcb_priv.h
+++ b/fs/fcb2/src/fcb_priv.h
@@ -67,7 +67,6 @@ int fcb_elem_crc16(struct fcb_entry *loc, uint16_t *c16p);
int fcb_sector_hdr_init(struct fcb *fcb, int sector, uint16_t id);
int fcb_entry_location_in_range(const struct fcb_entry *loc);
-
struct flash_sector_range *fcb_get_sector_range(const struct fcb *fcb,
int sector);
[mynewt-core] 09/13: sys/log;
fix incorrect if statement in log_fcb2_copy().
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit fba8e26809e399f09c23b449a0074f4a7cba0f76
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Fri Aug 30 11:23:44 2019 +0300
sys/log; fix incorrect if statement in log_fcb2_copy().
---
sys/log/full/src/log_fcb2.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c
index 7a141cf..f59883e 100644
--- a/sys/log/full/src/log_fcb2.c
+++ b/sys/log/full/src/log_fcb2.c
@@ -770,8 +770,8 @@ log_fcb2_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
memset(&entry, 0, sizeof(entry));
while (!fcb_getnext(src_fcb, &entry)) {
if (!copy) {
- if (from && entry.fe_range != from->fe_range &&
- entry.fe_data_off != from->fe_data_off) {
+ if (from && (entry.fe_range != from->fe_range ||
+ entry.fe_data_off != from->fe_data_off)) {
continue;
}
copy = 1;
[mynewt-core] 07/13: sys/reboot;
can run when LOG_FCB2 has been selected.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 1bfeb992234e0f935dc591a22516be5995d438d3
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Fri Aug 30 10:45:15 2019 +0300
sys/reboot; can run when LOG_FCB2 has been selected.
---
sys/reboot/pkg.yml | 5 ++++-
sys/reboot/src/log_reboot.c | 25 +++++++++++++++++++++----
sys/reboot/syscfg.yml | 2 +-
3 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/sys/reboot/pkg.yml b/sys/reboot/pkg.yml
index 3b70a01..8d7378d 100644
--- a/sys/reboot/pkg.yml
+++ b/sys/reboot/pkg.yml
@@ -32,8 +32,11 @@ pkg.deps:
- "@apache-mynewt-core/sys/flash_map"
- "@apache-mynewt-core/sys/log/modlog"
-pkg.deps.REBOOT_LOG_FCB:
+pkg.deps.(REBOOT_LOG_FCB && LOG_FCB):
- "@apache-mynewt-core/fs/fcb"
+pkg.deps.(REBOOT_LOG_FCB && LOG_FCB2):
+ - "@apache-mynewt-core/fs/fcb2"
+
pkg.init:
log_reboot_pkg_init: 'MYNEWT_VAL(REBOOT_SYSINIT_STAGE)'
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index f4c320c..c9c3780 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -55,7 +55,12 @@ struct conf_handler reboot_conf_handler = {
#if MYNEWT_VAL(REBOOT_LOG_FCB)
static struct fcb_log reboot_log_fcb;
static struct log reboot_log;
-static struct flash_area sector;
+#if MYNEWT_VAL(LOG_FCB)
+static struct flash_area reboot_sector;
+#endif
+#if MYNEWT_VAL(LOG_FCB2)
+static struct flash_sector_range reboot_sector;
+#endif
#endif
@@ -88,12 +93,24 @@ log_reboot_init_fcb(void)
return SYS_EUNKNOWN;
}
fcbp = &reboot_log_fcb.fl_fcb;
+#if MYNEWT_VAL(LOG_FCB)
sector = *ptr;
- fcbp->f_sectors = §or;
- fcbp->f_sector_cnt = 1;
fcbp->f_magic = 0x7EADBADF;
fcbp->f_version = g_log_info.li_version;
-
+ fcbp->f_sector_cnt = 1;
+ fcbp->f_sectors = &reboot_sector;
+#endif
+#if MYNEWT_VAL(LOG_FCB2)
+ fcbp->f_magic = 0x8EADBAE0;
+ fcbp->f_version = g_log_info.li_version;
+ fcbp->f_sector_cnt = 1;
+ fcbp->f_range_cnt = 1;
+ fcbp->f_ranges = &reboot_sector;
+ reboot_sector.fsr_flash_area = *ptr;
+ reboot_sector.fsr_sector_count = 1;
+ reboot_sector.fsr_sector_size = ptr->fa_size;
+ reboot_sector.fsr_align = flash_area_align(ptr);
+#endif
reboot_log_fcb.fl_entries = MYNEWT_VAL(REBOOT_LOG_ENTRY_COUNT);
rc = fcb_init(fcbp);
diff --git a/sys/reboot/syscfg.yml b/sys/reboot/syscfg.yml
index f08cecf..c8bd647 100644
--- a/sys/reboot/syscfg.yml
+++ b/sys/reboot/syscfg.yml
@@ -21,7 +21,7 @@ syscfg.defs:
description: 'Set reboot log target to be FCB.'
value: 0
restrictions:
- - LOG_FCB
+ - (LOG_FCB || LOG_FCB2)
- REBOOT_LOG_FLASH_AREA
REBOOT_LOG_CONSOLE:
[mynewt-core] 12/13: fs/fcb2; do {} while(1) -> while(1) {}
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 87208eb3955fb3713ecc295b90f7adf884439253
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Mon Sep 2 12:25:04 2019 +0300
fs/fcb2; do {} while(1) -> while(1) {}
---
fs/fcb2/src/fcb_getprev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/fcb2/src/fcb_getprev.c b/fs/fcb2/src/fcb_getprev.c
index 6cdbe33..e98c86c 100644
--- a/fs/fcb2/src/fcb_getprev.c
+++ b/fs/fcb2/src/fcb_getprev.c
@@ -71,7 +71,7 @@ fcb_getprev(struct fcb *fcb, struct fcb_entry *loc)
*/
*loc = fcb->f_active;
}
- do {
+ while (1) {
loc->fe_entry_num--;
if (loc->fe_entry_num < 1) {
/*
@@ -96,7 +96,7 @@ fcb_getprev(struct fcb *fcb, struct fcb_entry *loc)
break;
}
}
- } while (1);
+ }
os_mutex_release(&fcb->f_mtx);
return rc;
}
[mynewt-core] 04/13: sys/log/full;
check if log index is > last entry before starting walk of FCB2
area.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 06474c065f84d56b29c67998421fe717f7f80fb8
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Wed Aug 28 10:34:11 2019 +0300
sys/log/full; check if log index is > last entry before starting
walk of FCB2 area.
---
sys/log/full/src/log_fcb2.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c
index 590424c..9e5c4d1 100644
--- a/sys/log/full/src/log_fcb2.c
+++ b/sys/log/full/src/log_fcb2.c
@@ -67,9 +67,9 @@ log_fcb2_find_gte(struct log *log, struct log_offset *log_offset,
fcb_log = log->l_arg;
fcb = &fcb_log->fl_fcb;
- /* Attempt to read the first entry. If this fails, the FCB is empty. */
- memset(out_entry, 0, sizeof *out_entry);
- rc = fcb_getnext(fcb, out_entry);
+ /* Attempt to read the last entry. If this fails, the FCB is empty. */
+ memset(out_entry, 0, sizeof(*out_entry));
+ rc = fcb_getprev(fcb, out_entry);
if (rc == FCB_ERR_NOVAR) {
return SYS_ENOENT;
} else if (rc != 0) {
@@ -77,25 +77,31 @@ log_fcb2_find_gte(struct log *log, struct log_offset *log_offset,
}
/*
- * if timestamp for request is < 0, return last log entry
+ * if timestamp for request is < 0, return last log entry (already read).
*/
if (log_offset->lo_ts < 0) {
- *out_entry = fcb->f_active;
return 0;
}
-#if 0 /* XXXX */
/* If the requested index is beyond the end of the log, there is nothing to
* retrieve.
*/
- rc = log_read_hdr(log, &fcb->f_active, &hdr);
+ rc = log_read_hdr(log, out_entry, &hdr);
if (rc != 0) {
return rc;
}
if (log_offset->lo_index > hdr.ue_index) {
return SYS_ENOENT;
}
-#endif
+
+ /*
+ * Start from beginning.
+ */
+ memset(out_entry, 0, sizeof(*out_entry));
+ rc = fcb_getnext(fcb, out_entry);
+ if (rc != 0) {
+ return SYS_EUNKNOWN;
+ }
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
bmark = fcb_log_closest_bmark(fcb_log, log_offset->lo_index);
if (bmark != NULL) {
[mynewt-core] 01/13: fs/fcb2;
change data pointer to be const with fcb_write().
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 70bb26d70be18929459c4b9df65bbdd8220cfe70
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Mon Aug 26 15:52:44 2019 +0300
fs/fcb2; change data pointer to be const with fcb_write().
---
fs/fcb2/include/fcb/fcb.h | 3 ++-
fs/fcb2/src/fcb_append.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/fcb2/include/fcb/fcb.h b/fs/fcb2/include/fcb/fcb.h
index d481297..83b99fd 100644
--- a/fs/fcb2/include/fcb/fcb.h
+++ b/fs/fcb2/include/fcb/fcb.h
@@ -124,7 +124,8 @@ struct fcb_log {
* loc as argument.
*/
int fcb_append(struct fcb *fcb, uint16_t len, struct fcb_entry *loc);
-int fcb_write(struct fcb_entry *loc, uint16_t off, void *buf, uint16_t len);
+int fcb_write(struct fcb_entry *loc, uint16_t off, const void *buf,
+ uint16_t len);
int fcb_append_finish(struct fcb_entry *append_loc);
/**
diff --git a/fs/fcb2/src/fcb_append.c b/fs/fcb2/src/fcb_append.c
index 04cb340..a039ece 100644
--- a/fs/fcb2/src/fcb_append.c
+++ b/fs/fcb2/src/fcb_append.c
@@ -128,7 +128,7 @@ fcb_active_sector_free_space(const struct fcb *fcb)
}
int
-fcb_write(struct fcb_entry *loc, uint16_t off, void *buf, uint16_t len)
+fcb_write(struct fcb_entry *loc, uint16_t off, const void *buf, uint16_t len)
{
int pos = loc->fe_data_off + off;
/* Make sure tha write does not exceed lenght declared in fcb_append */
[mynewt-core] 02/13: sys/log; support FCB2 as backing store.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit c29e06dee45baf0d3ea8efdd692f8434f4b6ff8e
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Mon Aug 26 16:30:51 2019 +0300
sys/log; support FCB2 as backing store.
---
sys/log/common/include/log_common/log_common.h | 5 -
sys/log/full/include/log/log.h | 4 +-
sys/log/full/pkg.yml | 2 +
sys/log/full/{ => selftest/fcb2_align1}/pkg.yml | 44 +---
.../selftest/fcb2_align1/src/log_test_align1.c | 33 +++
sys/log/full/selftest/fcb2_align1/syscfg.yml | 25 ++
sys/log/full/selftest/util/src/log_test_util.c | 29 ++-
sys/log/full/src/log.c | 6 +-
sys/log/full/src/log_fcb.c | 23 +-
sys/log/full/src/{log_fcb.c => log_fcb2.c} | 260 +++++++++++----------
sys/log/full/syscfg.yml | 8 +
11 files changed, 254 insertions(+), 185 deletions(-)
diff --git a/sys/log/common/include/log_common/log_common.h b/sys/log/common/include/log_common/log_common.h
index a9ee6a1..6aa4d89 100644
--- a/sys/log/common/include/log_common/log_common.h
+++ b/sys/log/common/include/log_common/log_common.h
@@ -76,11 +76,6 @@ struct log;
#define LOG_ETYPE_BINARY (2)
#endif
-/* Logging medium */
-#define LOG_STORE_CONSOLE 1
-#define LOG_STORE_CBMEM 2
-#define LOG_STORE_FCB 3
-
/* UTC Timestamp for Jan 2016 00:00:00 */
#define UTC01_01_2016 1451606400
diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index 1ed90c0..d583473 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -704,8 +704,10 @@ log_fill_current_img_hash(struct log_entry_hdr *hdr);
extern const struct log_handler log_console_handler;
#endif
extern const struct log_handler log_cbmem_handler;
-#if MYNEWT_VAL(LOG_FCB)
+#if MYNEWT_VAL(LOG_FCB) || MYNEWT_VAL(LOG_FCB2)
extern const struct log_handler log_fcb_handler;
+#endif
+#if MYNEWT_VAL(LOG_FCB)
extern const struct log_handler log_fcb_slot1_handler;
#endif
diff --git a/sys/log/full/pkg.yml b/sys/log/full/pkg.yml
index 06c6b96..5c4ecde 100644
--- a/sys/log/full/pkg.yml
+++ b/sys/log/full/pkg.yml
@@ -32,6 +32,8 @@ pkg.deps:
pkg.deps.LOG_FCB:
- "@apache-mynewt-core/hw/hal"
- "@apache-mynewt-core/fs/fcb"
+pkg.deps.LOG_FCB2:
+ - "@apache-mynewt-core/fs/fcb2"
pkg.deps.LOG_CLI:
- "@apache-mynewt-core/sys/shell"
- "@apache-mynewt-core/encoding/base64"
diff --git a/sys/log/full/pkg.yml b/sys/log/full/selftest/fcb2_align1/pkg.yml
similarity index 50%
copy from sys/log/full/pkg.yml
copy to sys/log/full/selftest/fcb2_align1/pkg.yml
index 06c6b96..9600a41 100644
--- a/sys/log/full/pkg.yml
+++ b/sys/log/full/selftest/fcb2_align1/pkg.yml
@@ -1,4 +1,3 @@
-#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
@@ -6,7 +5,7 @@
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
@@ -16,42 +15,15 @@
# specific language governing permissions and limitations
# under the License.
#
-
-pkg.name: sys/log/full
-pkg.description: Logging utilities for embedded systems.
+pkg.name: sys/log/full/selftest/fcb2_align1
+pkg.type: unittest
+pkg.description: "Log unit tests; FCB2 flash-alignment=1."
pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- - logging
pkg.deps:
- - "@apache-mynewt-core/kernel/os"
- - "@apache-mynewt-core/sys/flash_map"
- - "@apache-mynewt-core/sys/log/common"
- - "@apache-mynewt-core/util/cbmem"
-pkg.deps.LOG_FCB:
- - "@apache-mynewt-core/hw/hal"
- - "@apache-mynewt-core/fs/fcb"
-pkg.deps.LOG_CLI:
- - "@apache-mynewt-core/sys/shell"
- - "@apache-mynewt-core/encoding/base64"
-
-pkg.deps.LOG_NEWTMGR:
- - "@apache-mynewt-core/mgmt/mgmt"
- - "@apache-mynewt-core/encoding/cborattr"
- - "@apache-mynewt-core/encoding/tinycbor"
-
-pkg.deps.LOG_FLAGS_IMAGE_HASH:
- - "@apache-mynewt-core/mgmt/imgmgr"
-
-pkg.deps.LOG_STORAGE_WATERMARK:
- - sys/config
-
-pkg.apis:
- - log
-
-pkg.init:
- log_init: 'MYNEWT_VAL(LOG_SYSINIT_STAGE_MAIN)'
-
-pkg.init.LOG_FCB_SLOT1:
- log_init_slot1: 'MYNEWT_VAL(LOG_SYSINIT_STAGE_SLOT1)'
+ - "@apache-mynewt-core/sys/console/stub"
+ - "@apache-mynewt-core/sys/log/full"
+ - "@apache-mynewt-core/sys/log/full/selftest/util"
+ - "@apache-mynewt-core/test/testutil"
diff --git a/sys/log/full/selftest/fcb2_align1/src/log_test_align1.c b/sys/log/full/selftest/fcb2_align1/src/log_test_align1.c
new file mode 100644
index 0000000..6fb73ff
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_align1/src/log_test_align1.c
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/mynewt.h"
+#include "log_test_util/log_test_util.h"
+
+int
+main(int argc, char **argv)
+{
+ log_test_suite_cbmem_flat();
+ log_test_suite_cbmem_mbuf();
+ log_test_suite_fcb_flat();
+ log_test_suite_fcb_mbuf();
+ log_test_suite_misc();
+
+ return tu_any_failed;
+}
diff --git a/sys/log/full/selftest/fcb2_align1/syscfg.yml b/sys/log/full/selftest/fcb2_align1/syscfg.yml
new file mode 100644
index 0000000..6dd29ba
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_align1/syscfg.yml
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.vals:
+ LOG_FCB2: 1
+ LOG_VERSION: 3
+ MCU_FLASH_MIN_WRITE_SIZE: 1
+
+ # The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
+ MSYS_1_BLOCK_COUNT: 1000
diff --git a/sys/log/full/selftest/util/src/log_test_util.c b/sys/log/full/selftest/util/src/log_test_util.c
index fab5dd8..1682e04 100644
--- a/sys/log/full/selftest/util/src/log_test_util.c
+++ b/sys/log/full/selftest/util/src/log_test_util.c
@@ -19,6 +19,7 @@
#include "log_test_util/log_test_util.h"
+#if MYNEWT_VAL(LOG_FCB)
static struct flash_area fcb_areas[] = {
[0] = {
.fa_off = 0x00000000,
@@ -29,6 +30,18 @@ static struct flash_area fcb_areas[] = {
.fa_size = 16 * 1024
}
};
+#endif
+#if MYNEWT_VAL(LOG_FCB2)
+static struct flash_sector_range fcb_range = {
+ .fsr_flash_area = {
+ .fa_off = 0,
+ .fa_size = 32 * 1024
+ },
+ .fsr_sector_count = 2,
+ .fsr_sector_size = 16 * 1024,
+ .fsr_align = MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE)
+};
+#endif
static int ltu_str_idx = 0;
static int ltu_str_max_idx = 0;
@@ -99,15 +112,25 @@ ltu_setup_fcb(struct fcb_log *fcb_log, struct log *log)
*fcb_log = (struct fcb_log) { 0 };
- fcb_log->fl_fcb.f_sectors = fcb_areas;
- fcb_log->fl_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
fcb_log->fl_fcb.f_magic = 0x7EADBADF;
fcb_log->fl_fcb.f_version = 0;
-
+#if MYNEWT_VAL(LOG_FCB)
+ fcb_log->fl_fcb.f_sectors = fcb_areas;
+ fcb_log->fl_fcb.f_sector_cnt = sizeof(fcb_areas) / sizeof(fcb_areas[0]);
for (i = 0; i < fcb_log->fl_fcb.f_sector_cnt; i++) {
rc = flash_area_erase(&fcb_areas[i], 0, fcb_areas[i].fa_size);
TEST_ASSERT(rc == 0);
}
+#endif
+#if MYNEWT_VAL(LOG_FCB2)
+ (void)i;
+ fcb_log->fl_fcb.f_range_cnt = 1;
+ fcb_log->fl_fcb.f_sector_cnt = fcb_range.fsr_sector_count;
+ fcb_log->fl_fcb.f_ranges = &fcb_range;
+ rc = flash_area_erase(&fcb_range.fsr_flash_area, 0,
+ fcb_range.fsr_flash_area.fa_size);
+#endif
+
rc = fcb_init(&fcb_log->fl_fcb);
TEST_ASSERT(rc == 0);
diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index ec3ec82..3dc40ff 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -408,7 +408,11 @@ log_register(char *name, struct log *log, const struct log_handler *lh,
/* Call registered handler now - log structure is set and put on list */
if (log->l_log->log_registered) {
- log->l_log->log_registered(log);
+ rc = log->l_log->log_registered(log);
+ if (rc) {
+ STAILQ_REMOVE(&g_log_list, log, log, l_next);
+ return rc;
+ }
}
/* If this is a persisted log, read the index from its most recent entry.
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 2eb96ea..376311a 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -30,8 +30,6 @@
/* Assume the flash alignment requirement is no stricter than 8. */
#define LOG_FCB_MAX_ALIGN 8
-static struct flash_area sector;
-
static int log_fcb_rtr_erase(struct log *log, void *arg);
/**
@@ -202,7 +200,7 @@ log_fcb_hdr_body_bytes(uint8_t align, uint8_t hdr_len)
/* Assume power-of-two alignment for faster modulo calculation. */
assert((align & (align - 1)) == 0);
-
+
mod = hdr_len & (align - 1);
if (mod == 0) {
return 0;
@@ -352,7 +350,7 @@ log_fcb_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
return rc;
}
loc.fe_data_off += LOG_BASE_ENTRY_HDR_SIZE;
-
+
if (hdr->ue_flags & LOG_FLAGS_IMG_HASH) {
/* Write LOG_IMG_HASHLEN bytes of image hash */
rc = flash_area_write(loc.fe_area, loc.fe_data_off, hdr->ue_imghash, LOG_IMG_HASHLEN);
@@ -392,24 +390,24 @@ log_fcb_append_mbuf(struct log *log, struct os_mbuf *om)
* We do a pull up twice, once so that the base header is
* contiguous, so that we read the flags correctly, second
* time is so that we account for the image hash as well.
- */
+ */
om = os_mbuf_pullup(om, LOG_BASE_ENTRY_HDR_SIZE);
-
- /*
+
+ /*
* We can just pass the om->om_data ptr as the log_entry_hdr
* because the log_entry_hdr is a packed struct and does not
* cause any alignment or padding issues
- */
+ */
hdr_len = log_hdr_len((struct log_entry_hdr *)om->om_data);
-
+
om = os_mbuf_pullup(om, hdr_len);
-
+
memcpy(&hdr, om->om_data, hdr_len);
os_mbuf_adj(om, hdr_len);
rc = log_fcb_append_mbuf_body(log, &hdr, om);
-
+
os_mbuf_prepend(om, hdr_len);
memcpy(om->om_data, &hdr, hdr_len);
@@ -723,7 +721,7 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
dlen = min(entry->fe_data_len, LOG_PRINTF_MAX_ENTRY_LEN +
hdr_len);
-
+
rc = log_fcb_read(log, entry, data, 0, dlen);
if (rc < 0) {
goto err;
@@ -786,6 +784,7 @@ log_fcb_rtr_erase(struct log *log, void *arg)
const struct flash_area *ptr;
struct fcb_entry entry;
int rc;
+ struct flash_area sector;
rc = 0;
if (!log) {
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb2.c
similarity index 75%
copy from sys/log/full/src/log_fcb.c
copy to sys/log/full/src/log_fcb2.c
index 2eb96ea..590424c 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb2.c
@@ -19,7 +19,7 @@
#include "os/mynewt.h"
-#if MYNEWT_VAL(LOG_FCB)
+#if MYNEWT_VAL(LOG_FCB2)
#include <string.h>
@@ -28,11 +28,9 @@
#include "log/log.h"
/* Assume the flash alignment requirement is no stricter than 8. */
-#define LOG_FCB_MAX_ALIGN 8
+#define LOG_FCB2_MAX_ALIGN 8
-static struct flash_area sector;
-
-static int log_fcb_rtr_erase(struct log *log, void *arg);
+static int log_fcb2_rtr_erase(struct log *log, void *arg);
/**
* Finds the first log entry whose "offset" is >= the one specified. A log
@@ -55,8 +53,8 @@ static int log_fcb_rtr_erase(struct log *log, void *arg);
* Other error on failure.
*/
static int
-log_fcb_find_gte(struct log *log, struct log_offset *log_offset,
- struct fcb_entry *out_entry)
+log_fcb2_find_gte(struct log *log, struct log_offset *log_offset,
+ struct fcb_entry *out_entry)
{
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
const struct fcb_log_bmark *bmark;
@@ -86,6 +84,7 @@ log_fcb_find_gte(struct log *log, struct log_offset *log_offset,
return 0;
}
+#if 0 /* XXXX */
/* If the requested index is beyond the end of the log, there is nothing to
* retrieve.
*/
@@ -96,7 +95,7 @@ log_fcb_find_gte(struct log *log, struct log_offset *log_offset,
if (log_offset->lo_index > hdr.ue_index) {
return SYS_ENOENT;
}
-
+#endif
#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
bmark = fcb_log_closest_bmark(fcb_log, log_offset->lo_index);
if (bmark != NULL) {
@@ -120,11 +119,13 @@ log_fcb_find_gte(struct log *log, struct log_offset *log_offset,
}
static int
-log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
+log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc)
{
struct fcb *fcb;
struct fcb_log *fcb_log;
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
struct flash_area *old_fa;
+#endif
int rc = 0;
#if MYNEWT_VAL(LOG_STATS)
int cnt;
@@ -144,15 +145,17 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
}
if (fcb_log->fl_entries) {
- rc = log_fcb_rtr_erase(log, fcb_log);
+ rc = log_fcb2_rtr_erase(log, fcb_log);
if (rc) {
goto err;
}
continue;
}
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
old_fa = fcb->f_oldest;
(void)old_fa; /* to avoid #ifdefs everywhere... */
+#endif
#if MYNEWT_VAL(LOG_STATS)
rc = fcb_area_info(fcb, NULL, &cnt, NULL);
@@ -182,8 +185,6 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
fcb_log->fl_watermark_off = fcb->f_oldest->fa_off;
}
#endif
-
-
}
err:
@@ -196,13 +197,13 @@ err:
* to satisfy the flash hardware's write alignment restrictions.
*/
static int
-log_fcb_hdr_body_bytes(uint8_t align, uint8_t hdr_len)
+log_fcb2_hdr_body_bytes(uint8_t align, uint8_t hdr_len)
{
uint8_t mod;
/* Assume power-of-two alignment for faster modulo calculation. */
assert((align & (align - 1)) == 0);
-
+
mod = hdr_len & (align - 1);
if (mod == 0) {
return 0;
@@ -212,30 +213,23 @@ log_fcb_hdr_body_bytes(uint8_t align, uint8_t hdr_len)
}
static int
-log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
- const void *body, int body_len)
+log_fcb2_append_body(struct log *log, const struct log_entry_hdr *hdr,
+ const void *body, int body_len)
{
- uint8_t buf[LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN + LOG_FCB_MAX_ALIGN - 1];
- struct fcb *fcb;
+ uint8_t buf[LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN +
+ LOG_FCB2_MAX_ALIGN - 1];
struct fcb_entry loc;
- struct fcb_log *fcb_log;
const uint8_t *u8p;
int hdr_alignment;
int chunk_sz;
int rc;
uint16_t hdr_len;
- fcb_log = (struct fcb_log *)log->l_arg;
- fcb = &fcb_log->fl_fcb;
hdr_len = 0;
- if (fcb->f_align > LOG_FCB_MAX_ALIGN) {
- return SYS_ENOTSUP;
- }
-
hdr_len = log_hdr_len(hdr);
- rc = log_fcb_start_append(log, hdr_len + body_len, &loc);
+ rc = log_fcb2_start_append(log, hdr_len + body_len, &loc);
if (rc != 0) {
return rc;
}
@@ -245,7 +239,7 @@ log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
* the flash alignment). If the hash flag is set, we have to account for
* appending the hash right after the header.
*/
- hdr_alignment = log_fcb_hdr_body_bytes(fcb->f_align, hdr_len);
+ hdr_alignment = log_fcb2_hdr_body_bytes(loc.fe_range->fsr_align, hdr_len);
if (hdr_alignment > body_len) {
chunk_sz = hdr_len + body_len;
} else {
@@ -265,7 +259,7 @@ log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
}
memcpy(buf + hdr_len, u8p, hdr_alignment);
- rc = flash_area_write(loc.fe_area, loc.fe_data_off, buf, chunk_sz);
+ rc = fcb_write(&loc, 0, buf, chunk_sz);
if (rc != 0) {
return rc;
}
@@ -276,14 +270,13 @@ log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
body_len -= hdr_alignment;
if (body_len > 0) {
- rc = flash_area_write(loc.fe_area, loc.fe_data_off + chunk_sz, u8p,
- body_len);
+ rc = fcb_write(&loc, chunk_sz, u8p, body_len);
if (rc != 0) {
return rc;
}
}
- rc = fcb_append_finish(fcb, &loc);
+ rc = fcb_append_finish(&loc);
if (rc != 0) {
return rc;
}
@@ -292,29 +285,28 @@ log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
}
static int
-log_fcb_append(struct log *log, void *buf, int len)
+log_fcb2_append(struct log *log, void *buf, int len)
{
int hdr_len;
hdr_len = log_hdr_len(buf);
- return log_fcb_append_body(log, buf, (uint8_t *)buf + hdr_len,
- len - hdr_len);
+ return log_fcb2_append_body(log, buf, (uint8_t *)buf + hdr_len,
+ len - hdr_len);
}
static int
-log_fcb_write_mbuf(struct fcb_entry *loc, struct os_mbuf *om)
+log_fcb2_write_mbuf(struct fcb_entry *loc, struct os_mbuf *om, int off)
{
int rc;
while (om) {
- rc = flash_area_write(loc->fe_area, loc->fe_data_off, om->om_data,
- om->om_len);
+ rc = fcb_write(loc, off, om->om_data, om->om_len);
if (rc != 0) {
return SYS_EIO;
}
- loc->fe_data_off += om->om_len;
+ off += om->om_len;
om = SLIST_NEXT(om, om_next);
}
@@ -322,15 +314,14 @@ log_fcb_write_mbuf(struct fcb_entry *loc, struct os_mbuf *om)
}
static int
-log_fcb_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
- struct os_mbuf *om)
+log_fcb2_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
+ struct os_mbuf *om)
{
- struct fcb *fcb;
struct fcb_entry loc;
- struct fcb_log *fcb_log;
int len;
int rc;
+#if 0 /* XXXX */
fcb_log = (struct fcb_log *)log->l_arg;
fcb = &fcb_log->fl_fcb;
@@ -340,34 +331,35 @@ log_fcb_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
if (fcb->f_align != 1) {
return SYS_ENOTSUP;
}
+#endif
len = log_hdr_len(hdr) + os_mbuf_len(om);
- rc = log_fcb_start_append(log, len, &loc);
+ rc = log_fcb2_start_append(log, len, &loc);
if (rc != 0) {
return rc;
}
- rc = flash_area_write(loc.fe_area, loc.fe_data_off, hdr, LOG_BASE_ENTRY_HDR_SIZE);
+ rc = fcb_write(&loc, 0, hdr, LOG_BASE_ENTRY_HDR_SIZE);
if (rc != 0) {
return rc;
}
- loc.fe_data_off += LOG_BASE_ENTRY_HDR_SIZE;
-
+ len = LOG_BASE_ENTRY_HDR_SIZE;
+
if (hdr->ue_flags & LOG_FLAGS_IMG_HASH) {
/* Write LOG_IMG_HASHLEN bytes of image hash */
- rc = flash_area_write(loc.fe_area, loc.fe_data_off, hdr->ue_imghash, LOG_IMG_HASHLEN);
+ rc = fcb_write(&loc, len, hdr->ue_imghash, LOG_IMG_HASHLEN);
if (rc != 0) {
return rc;
}
- loc.fe_data_off += LOG_IMG_HASHLEN;
+ len += LOG_IMG_HASHLEN;
}
- rc = log_fcb_write_mbuf(&loc, om);
+ rc = log_fcb2_write_mbuf(&loc, om, len);
if (rc != 0) {
return rc;
}
- rc = fcb_append_finish(fcb, &loc);
+ rc = fcb_append_finish(&loc);
if (rc != 0) {
return rc;
}
@@ -376,7 +368,7 @@ log_fcb_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
}
static int
-log_fcb_append_mbuf(struct log *log, struct os_mbuf *om)
+log_fcb2_append_mbuf(struct log *log, struct os_mbuf *om)
{
int rc;
uint16_t mlen;
@@ -392,24 +384,24 @@ log_fcb_append_mbuf(struct log *log, struct os_mbuf *om)
* We do a pull up twice, once so that the base header is
* contiguous, so that we read the flags correctly, second
* time is so that we account for the image hash as well.
- */
+ */
om = os_mbuf_pullup(om, LOG_BASE_ENTRY_HDR_SIZE);
-
- /*
+
+ /*
* We can just pass the om->om_data ptr as the log_entry_hdr
* because the log_entry_hdr is a packed struct and does not
* cause any alignment or padding issues
- */
+ */
hdr_len = log_hdr_len((struct log_entry_hdr *)om->om_data);
-
+
om = os_mbuf_pullup(om, hdr_len);
-
+
memcpy(&hdr, om->om_data, hdr_len);
os_mbuf_adj(om, hdr_len);
- rc = log_fcb_append_mbuf_body(log, &hdr, om);
-
+ rc = log_fcb2_append_mbuf_body(log, &hdr, om);
+
os_mbuf_prepend(om, hdr_len);
memcpy(om->om_data, &hdr, hdr_len);
@@ -418,18 +410,17 @@ log_fcb_append_mbuf(struct log *log, struct os_mbuf *om)
}
static int
-log_fcb_read(struct log *log, void *dptr, void *buf, uint16_t offset,
- uint16_t len)
+log_fcb2_read(struct log *log, void *dptr, void *buf, uint16_t off, uint16_t len)
{
struct fcb_entry *loc;
int rc;
loc = (struct fcb_entry *)dptr;
- if (offset + len > loc->fe_data_len) {
- len = loc->fe_data_len - offset;
+ if (off + len > loc->fe_data_len) {
+ len = loc->fe_data_len - off;
}
- rc = flash_area_read(loc->fe_area, loc->fe_data_off + offset, buf, len);
+ rc = fcb_read(loc, off, buf, len);
if (rc == 0) {
return len;
} else {
@@ -438,8 +429,8 @@ log_fcb_read(struct log *log, void *dptr, void *buf, uint16_t offset,
}
static int
-log_fcb_read_mbuf(struct log *log, void *dptr, struct os_mbuf *om,
- uint16_t offset, uint16_t len)
+log_fcb2_read_mbuf(struct log *log, void *dptr, struct os_mbuf *om,
+ uint16_t off, uint16_t len)
{
struct fcb_entry *loc;
uint8_t data[128];
@@ -449,16 +440,15 @@ log_fcb_read_mbuf(struct log *log, void *dptr, struct os_mbuf *om,
loc = (struct fcb_entry *)dptr;
- if (offset + len > loc->fe_data_len) {
- len = loc->fe_data_len - offset;
+ if (off + len > loc->fe_data_len) {
+ len = loc->fe_data_len - off;
}
rem_len = len;
while (rem_len > 0) {
read_len = min(rem_len, sizeof(data));
- rc = flash_area_read(loc->fe_area, loc->fe_data_off + offset, data,
- read_len);
+ rc = fcb_read(loc, off, data, read_len);
if (rc) {
goto done;
}
@@ -469,7 +459,7 @@ log_fcb_read_mbuf(struct log *log, void *dptr, struct os_mbuf *om,
}
rem_len -= read_len;
- offset += read_len;
+ off += read_len;
}
done:
@@ -477,8 +467,8 @@ done:
}
static int
-log_fcb_walk(struct log *log, log_walk_func_t walk_func,
- struct log_offset *log_offset)
+log_fcb2_walk(struct log *log, log_walk_func_t walk_func,
+ struct log_offset *log_off)
{
struct fcb *fcb;
struct fcb_log *fcb_log;
@@ -489,7 +479,7 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func,
fcb = &fcb_log->fl_fcb;
/* Locate the starting point of the walk. */
- rc = log_fcb_find_gte(log, log_offset, &loc);
+ rc = log_fcb2_find_gte(log, log_off, &loc);
switch (rc) {
case 0:
/* Found a starting point. */
@@ -505,13 +495,13 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func,
/* If a minimum index was specified (i.e., we are not just retrieving the
* last entry), add a bookmark pointing to this walk's start location.
*/
- if (log_offset->lo_ts >= 0) {
- fcb_log_add_bmark(fcb_log, &loc, log_offset->lo_index);
+ if (log_off->lo_ts >= 0) {
+ fcb_log_add_bmark(fcb_log, &loc, log_off->lo_index);
}
#endif
do {
- rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
+ rc = walk_func(log, log_off, &loc, loc.fe_data_len);
if (rc != 0) {
return rc;
}
@@ -521,7 +511,7 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func,
}
static int
-log_fcb_flush(struct log *log)
+log_fcb2_flush(struct log *log)
{
struct fcb_log *fcb_log;
struct fcb *fcb;
@@ -537,20 +527,28 @@ log_fcb_flush(struct log *log)
}
static int
-log_fcb_registered(struct log *log)
+log_fcb2_registered(struct log *log)
{
-#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
+ struct fcb *fcb;
+ int i;
struct fcb_log *fl;
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
#if MYNEWT_VAL(LOG_PERSIST_WATERMARK)
- struct fcb *fcb;
struct fcb_entry loc;
#endif
+#endif
fl = (struct fcb_log *)log->l_arg;
-
-#if MYNEWT_VAL(LOG_PERSIST_WATERMARK)
fcb = &fl->fl_fcb;
+ for (i = 0; i < fcb->f_range_cnt; i++) {
+ if (fcb->f_ranges[i].fsr_align > LOG_FCB2_MAX_ALIGN) {
+ return SYS_ENOTSUP;
+ }
+ }
+
+#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
+#if MYNEWT_VAL(LOG_PERSIST_WATERMARK)
/* Set watermark to first element */
memset(&loc, 0, sizeof(loc));
@@ -569,7 +567,7 @@ log_fcb_registered(struct log *log)
#if MYNEWT_VAL(LOG_STORAGE_INFO)
static int
-log_fcb_storage_info(struct log *log, struct log_storage_info *info)
+log_fcb2_storage_info(struct log *log, struct log_storage_info *info)
{
struct fcb_log *fl;
struct fcb *fcb;
@@ -624,8 +622,7 @@ log_fcb_storage_info(struct log *log, struct log_storage_info *info)
if (fl->fl_watermark_off == 0xffffffff){
fa_used = 0xffffffff;
- }
- else if ((int32_t)fa_used < 0) {
+ } else if ((int32_t)fa_used < 0) {
fa_used += fa_size;
}
@@ -640,8 +637,8 @@ log_fcb_storage_info(struct log *log, struct log_storage_info *info)
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
static int
-log_fcb_new_watermark_index(struct log *log, struct log_offset *log_offset, void *dptr,
- uint16_t len)
+log_fcb2_new_watermark_index(struct log *log, struct log_offset *log_off,
+ void *dptr, uint16_t len)
{
struct fcb_entry *loc;
struct fcb_log *fl;
@@ -657,8 +654,9 @@ log_fcb_new_watermark_index(struct log *log, struct log_offset *log_offset, void
return -1;
}
/* Set log watermark to end of this element */
- if (ueh.ue_index >= log_offset->lo_index) {
- fl->fl_watermark_off = loc->fe_area->fa_off + loc->fe_data_off + loc->fe_data_len;
+ if (ueh.ue_index >= log_off->lo_index) {
+ fl->fl_watermark_off = loc->fe_area->fa_off + loc->fe_data_off +
+ loc->fe_data_len;
return -1;
} else {
return 0;
@@ -666,7 +664,7 @@ log_fcb_new_watermark_index(struct log *log, struct log_offset *log_offset, void
}
static int
-log_fcb_set_watermark(struct log *log, uint32_t index)
+log_fcb2_set_watermark(struct log *log, uint32_t index)
{
int rc;
struct log_offset log_offset;
@@ -682,7 +680,7 @@ log_fcb_set_watermark(struct log *log, uint32_t index)
log_offset.lo_data_len = 0;
/* Find where to start the walk, and set watermark accordingly */
- rc = log_fcb_walk(log, log_fcb_new_watermark_index, &log_offset);
+ rc = log_fcb2_walk(log, log_fcb2_new_watermark_index, &log_offset);
if (rc != 0) {
goto done;
}
@@ -704,27 +702,27 @@ done:
* @return 0 on success; non-zero on error
*/
static int
-log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
- struct fcb *dst_fcb)
+log_fcb2_copy_entry(struct log *log, struct fcb_entry *entry,
+ struct fcb *dst_fcb)
{
struct log_entry_hdr ueh;
- char data[LOG_PRINTF_MAX_ENTRY_LEN + LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN];
+ char data[LOG_PRINTF_MAX_ENTRY_LEN + LOG_BASE_ENTRY_HDR_SIZE +
+ LOG_IMG_HASHLEN];
uint16_t hdr_len = 0;
int dlen;
int rc;
struct fcb *fcb_tmp;
- rc = log_fcb_read(log, entry, &ueh, 0, LOG_BASE_ENTRY_HDR_SIZE);
+ rc = log_fcb2_read(log, entry, &ueh, 0, LOG_BASE_ENTRY_HDR_SIZE);
if (rc != LOG_BASE_ENTRY_HDR_SIZE) {
goto err;
}
hdr_len = log_hdr_len(&ueh);
- dlen = min(entry->fe_data_len, LOG_PRINTF_MAX_ENTRY_LEN +
- hdr_len);
-
- rc = log_fcb_read(log, entry, data, 0, dlen);
+ dlen = min(entry->fe_data_len, LOG_PRINTF_MAX_ENTRY_LEN + hdr_len);
+
+ rc = log_fcb2_read(log, entry, data, 0, dlen);
if (rc < 0) {
goto err;
}
@@ -733,7 +731,7 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
log->l_arg = dst_fcb;
- rc = log_fcb_append(log, data, dlen);
+ rc = log_fcb2_append(log, data, dlen);
log->l_arg = fcb_tmp;
if (rc) {
goto err;
@@ -745,24 +743,29 @@ err:
/**
* Copies log entries from source fcb to destination fcb
- * @param src_fcb, dst_fcb, element offset to start copying
+ * @param src_fcb, dst_fcb, element to start copying from
* @return 0 on success; non-zero on error
*/
static int
-log_fcb_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
- uint32_t offset)
+log_fcb2_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
+ struct fcb_entry *from)
{
struct fcb_entry entry;
int rc;
+ int copy = 0;
rc = 0;
memset(&entry, 0, sizeof(entry));
while (!fcb_getnext(src_fcb, &entry)) {
- if (entry.fe_elem_off < offset) {
- continue;
+ if (!copy) {
+ if (from && entry.fe_range != from->fe_range &&
+ entry.fe_data_off != from->fe_data_off) {
+ continue;
+ }
+ copy = 1;
}
- rc = log_fcb_copy_entry(log, &entry, dst_fcb);
+ rc = log_fcb2_copy_entry(log, &entry, dst_fcb);
if (rc) {
break;
}
@@ -778,14 +781,15 @@ log_fcb_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
* @return 0 on success; non-zero on error
*/
static int
-log_fcb_rtr_erase(struct log *log, void *arg)
+log_fcb2_rtr_erase(struct log *log, void *arg)
{
struct fcb_log *fcb_log;
struct fcb fcb_scratch;
struct fcb *fcb;
- const struct flash_area *ptr;
struct fcb_entry entry;
int rc;
+ struct flash_sector_range range;
+ int range_cnt;
rc = 0;
if (!log) {
@@ -798,16 +802,18 @@ log_fcb_rtr_erase(struct log *log, void *arg)
memset(&fcb_scratch, 0, sizeof(fcb_scratch));
- if (flash_area_open(FLASH_AREA_IMAGE_SCRATCH, &ptr)) {
+ range_cnt = 1;
+ if (flash_area_to_sector_ranges(FLASH_AREA_IMAGE_SCRATCH, &range_cnt,
+ &range)) {
goto err;
}
- sector = *ptr;
- fcb_scratch.f_sectors = §or;
+ fcb_scratch.f_ranges = ⦥
fcb_scratch.f_sector_cnt = 1;
+ fcb_scratch.f_range_cnt = 1;
fcb_scratch.f_magic = 0x7EADBADF;
fcb_scratch.f_version = g_log_info.li_version;
- flash_area_erase(§or, 0, sector.fa_size);
+ flash_area_erase(&range.fsr_flash_area, 0, range.fsr_flash_area.fa_size);
rc = fcb_init(&fcb_scratch);
if (rc) {
goto err;
@@ -820,19 +826,19 @@ log_fcb_rtr_erase(struct log *log, void *arg)
}
/* Copy to scratch */
- rc = log_fcb_copy(log, fcb, &fcb_scratch, entry.fe_elem_off);
+ rc = log_fcb2_copy(log, fcb, &fcb_scratch, &entry);
if (rc) {
goto err;
}
/* Flush log */
- rc = log_fcb_flush(log);
+ rc = log_fcb2_flush(log);
if (rc) {
goto err;
}
/* Copy back from scratch */
- rc = log_fcb_copy(log, &fcb_scratch, fcb, 0);
+ rc = log_fcb2_copy(log, &fcb_scratch, fcb, NULL);
err:
return (rc);
@@ -840,21 +846,21 @@ err:
const struct log_handler log_fcb_handler = {
.log_type = LOG_TYPE_STORAGE,
- .log_read = log_fcb_read,
- .log_read_mbuf = log_fcb_read_mbuf,
- .log_append = log_fcb_append,
- .log_append_body = log_fcb_append_body,
- .log_append_mbuf = log_fcb_append_mbuf,
- .log_append_mbuf_body = log_fcb_append_mbuf_body,
- .log_walk = log_fcb_walk,
- .log_flush = log_fcb_flush,
+ .log_read = log_fcb2_read,
+ .log_read_mbuf = log_fcb2_read_mbuf,
+ .log_append = log_fcb2_append,
+ .log_append_body = log_fcb2_append_body,
+ .log_append_mbuf = log_fcb2_append_mbuf,
+ .log_append_mbuf_body = log_fcb2_append_mbuf_body,
+ .log_walk = log_fcb2_walk,
+ .log_flush = log_fcb2_flush,
#if MYNEWT_VAL(LOG_STORAGE_INFO)
- .log_storage_info = log_fcb_storage_info,
+ .log_storage_info = log_fcb2_storage_info,
#endif
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
- .log_set_watermark = log_fcb_set_watermark,
+ .log_set_watermark = log_fcb2_set_watermark,
#endif
- .log_registered = log_fcb_registered,
+ .log_registered = log_fcb2_registered,
};
#endif
diff --git a/sys/log/full/syscfg.yml b/sys/log/full/syscfg.yml
index 3218c8f..b49ccd8 100644
--- a/sys/log/full/syscfg.yml
+++ b/sys/log/full/syscfg.yml
@@ -41,6 +41,14 @@ syscfg.defs:
LOG_FCB:
description: 'Support logging to FCB.'
value: 0
+ restrictions:
+ - "!LOG_FCB2"
+
+ LOG_FCB2:
+ description: 'Support logging to FCB2.'
+ value: 0
+ restrictions:
+ - "!LOG_FCB"
LOG_FCB_SLOT1:
description: >
[mynewt-core] 06/13: sys/log; enable bookmarks with FCB2.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 22f5f1a6ffa3f0f1a02da218d25ab532a69b01c3
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Thu Aug 29 12:55:02 2019 +0300
sys/log; enable bookmarks with FCB2.
---
sys/log/full/pkg.yml | 3 ++
sys/log/full/selftest/fcb2_bookmarks/pkg.yml | 30 +++++++++++++++
.../fcb2_bookmarks/src/log_test_fcb_bookmarks.c | 39 +++++++++++++++++++
.../fcb2_bookmarks/src/log_test_fcb_bookmarks.h | 44 ++++++++++++++++++++++
.../src/log_test_fcb_bookmarks_util.c | 43 ++++++++-------------
.../fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c | 32 ++++++++++++++++
.../fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c | 32 ++++++++++++++++
.../src/testcases/s100_l500_b10_p2000.c | 32 ++++++++++++++++
.../src/testcases/s10_l100_b10_p2000.c | 32 ++++++++++++++++
.../src/testcases/s10_l100_b1_p200.c | 32 ++++++++++++++++
sys/log/full/selftest/fcb2_bookmarks/syscfg.yml | 23 +++++++++++
.../src/log_test_fcb_bookmarks_util.c | 2 +-
sys/log/full/src/log_fcb2.c | 7 +++-
sys/log/full/syscfg.yml | 2 +-
14 files changed, 323 insertions(+), 30 deletions(-)
diff --git a/sys/log/full/pkg.yml b/sys/log/full/pkg.yml
index 5c4ecde..4e618cb 100644
--- a/sys/log/full/pkg.yml
+++ b/sys/log/full/pkg.yml
@@ -52,6 +52,9 @@ pkg.deps.LOG_STORAGE_WATERMARK:
pkg.apis:
- log
+pkg.req_apis.LOG_STATS:
+ - stats
+
pkg.init:
log_init: 'MYNEWT_VAL(LOG_SYSINIT_STAGE_MAIN)'
diff --git a/sys/log/full/selftest/fcb2_bookmarks/pkg.yml b/sys/log/full/selftest/fcb2_bookmarks/pkg.yml
new file mode 100644
index 0000000..7b9a2f0
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/pkg.yml
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+pkg.name: sys/log/full/selftest/fcb2_bookmarks
+pkg.type: unittest
+pkg.description: "Log unit tests; bookmarks with FCB2."
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+
+pkg.deps:
+ - "@apache-mynewt-core/sys/console/stub"
+ - "@apache-mynewt-core/sys/log/full"
+ - "@apache-mynewt-core/sys/log/full/selftest/util"
+ - "@apache-mynewt-core/sys/stats/full"
+ - "@apache-mynewt-core/test/testutil"
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.c b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.c
new file mode 100644
index 0000000..85b8391
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.c
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/mynewt.h"
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_bookmarks.h"
+
+TEST_SUITE(log_test_suite_fcb_bookmarks)
+{
+ log_test_case_fcb_bookmarks_s0_l1_b0_p100();
+ log_test_case_fcb_bookmarks_s0_l1_b1_p100();
+ log_test_case_fcb_bookmarks_s10_l100_b1_p200();
+ log_test_case_fcb_bookmarks_s10_l100_b10_p2000();
+ log_test_case_fcb_bookmarks_s100_l500_b10_p2000();
+}
+
+int
+main(int argc, char **argv)
+{
+ log_test_suite_fcb_bookmarks();
+
+ return tu_any_failed;
+}
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.h b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.h
new file mode 100644
index 0000000..e7d58f5
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.h
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_LOG_TEST_FCB_BOOKMARKS_
+#define H_LOG_TEST_FCB_BOOKMARKS_
+
+#include "os/mynewt.h"
+#include "testutil/testutil.h"
+
+struct ltfbu_cfg {
+ int skip_mod;
+ int body_len;
+ int bmark_count;
+ int pop_count;
+};
+
+void ltfbu_populate_log(int count);
+void ltfbu_verify_log(uint32_t start_idx);
+void ltfbu_init(const struct ltfbu_cfg *cfg);
+void ltfbu_test_once(const struct ltfbu_cfg *cfg);
+
+TEST_CASE_DECL(log_test_case_fcb_bookmarks_s0_l1_b0_p100);
+TEST_CASE_DECL(log_test_case_fcb_bookmarks_s0_l1_b1_p100);
+TEST_CASE_DECL(log_test_case_fcb_bookmarks_s10_l100_b1_p200);
+TEST_CASE_DECL(log_test_case_fcb_bookmarks_s10_l100_b10_p2000);
+TEST_CASE_DECL(log_test_case_fcb_bookmarks_s100_l500_b10_p2000);
+
+#endif
diff --git a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c
similarity index 87%
copy from sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
copy to sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c
index 25a8b36..76421ba 100644
--- a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c
@@ -40,15 +40,14 @@ static struct log ltfbu_log;
static struct fcb_log_bmark ltfbu_bmarks[LTFBU_MAX_BMARKS];
-static struct flash_area ltfbu_fcb_areas[] = {
- [0] = {
+static struct flash_sector_range ltfbu_fcb_range = {
+ .fsr_flash_area = {
.fa_off = 0 * LTFBU_SECTOR_SIZE,
- .fa_size = LTFBU_SECTOR_SIZE,
+ .fa_size = 2 * LTFBU_SECTOR_SIZE
},
- [1] = {
- .fa_off = 1 * LTFBU_SECTOR_SIZE,
- .fa_size = LTFBU_SECTOR_SIZE,
- }
+ .fsr_sector_count = 2,
+ .fsr_sector_size = LTFBU_SECTOR_SIZE,
+ .fsr_align = MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE)
};
static int
@@ -56,19 +55,10 @@ ltfbu_max_entries(void)
{
int entry_space;
int entry_size;
- int len_size;
- int crc_size;
- if (ltfbu_cfg.body_len > 127) {
- len_size = 2;
- } else {
- len_size = 1;
- }
- crc_size = 1;
-
- /* "+ 1" for CRC. */
+ /* "+ 2" for CRC. */
entry_size = LOG_BASE_ENTRY_HDR_SIZE + ltfbu_cfg.body_len +
- len_size + crc_size;
+ FCB_ENTRY_SIZE + 2;
entry_space = LTFBU_SECTOR_SIZE - 8;
return entry_space / entry_size;
@@ -99,7 +89,7 @@ ltfbu_expected_idxs(uint32_t start_idx)
first++;
count--;
}
-
+
return (struct ltfbu_slice) {
.idxs = <fbu_entry_idxs[first],
.count = count,
@@ -206,7 +196,6 @@ void
ltfbu_init(const struct ltfbu_cfg *cfg)
{
int rc;
- int i;
/* Ensure tests are repeatable. */
srand(0);
@@ -216,17 +205,17 @@ ltfbu_init(const struct ltfbu_cfg *cfg)
ltfbu_fcb_log = (struct fcb_log) {
.fl_fcb.f_scratch_cnt = 1,
- .fl_fcb.f_sectors = ltfbu_fcb_areas,
- .fl_fcb.f_sector_cnt = sizeof(ltfbu_fcb_areas) / sizeof(ltfbu_fcb_areas[0]),
+ .fl_fcb.f_range_cnt = 1,
+ .fl_fcb.f_sector_cnt = ltfbu_fcb_range.fsr_sector_count,
+ .fl_fcb.f_ranges = <fbu_fcb_range,
.fl_fcb.f_magic = 0x7EADBADF,
.fl_fcb.f_version = 0,
};
- for (i = 0; i < ltfbu_fcb_log.fl_fcb.f_sector_cnt; i++) {
- rc = flash_area_erase(<fbu_fcb_areas[i], 0,
- ltfbu_fcb_areas[i].fa_size);
- TEST_ASSERT_FATAL(rc == 0);
- }
+ rc = flash_area_erase(<fbu_fcb_range.fsr_flash_area, 0,
+ ltfbu_fcb_range.fsr_flash_area.fa_size);
+ TEST_ASSERT_FATAL(rc == 0);
+
rc = fcb_init(<fbu_fcb_log.fl_fcb);
TEST_ASSERT_FATAL(rc == 0);
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c
new file mode 100644
index 0000000..d211264
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_bookmarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_bookmarks_s0_l1_b0_p100)
+{
+ struct ltfbu_cfg cfg = {
+ .skip_mod = 0,
+ .body_len = 10,
+ .bmark_count = 0,
+ .pop_count = 100,
+ };
+ ltfbu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c
new file mode 100644
index 0000000..ee7718b
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_bookmarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_bookmarks_s0_l1_b1_p100)
+{
+ struct ltfbu_cfg cfg = {
+ .skip_mod = 0,
+ .body_len = 10,
+ .bmark_count = 1,
+ .pop_count = 100,
+ };
+ ltfbu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s100_l500_b10_p2000.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s100_l500_b10_p2000.c
new file mode 100644
index 0000000..e86964c
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s100_l500_b10_p2000.c
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_bookmarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_bookmarks_s100_l500_b10_p2000)
+{
+ struct ltfbu_cfg cfg = {
+ .skip_mod = 100,
+ .body_len = 500,
+ .bmark_count = 10,
+ .pop_count = 2000,
+ };
+ ltfbu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b10_p2000.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b10_p2000.c
new file mode 100644
index 0000000..ac48042
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b10_p2000.c
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_bookmarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_bookmarks_s10_l100_b10_p2000)
+{
+ struct ltfbu_cfg cfg = {
+ .skip_mod = 10,
+ .body_len = 100,
+ .bmark_count = 10,
+ .pop_count = 2000,
+ };
+ ltfbu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b1_p200.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b1_p200.c
new file mode 100644
index 0000000..ac81aef
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b1_p200.c
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "log_test_util/log_test_util.h"
+#include "log_test_fcb_bookmarks.h"
+
+TEST_CASE_SELF(log_test_case_fcb_bookmarks_s10_l100_b1_p200)
+{
+ struct ltfbu_cfg cfg = {
+ .skip_mod = 10,
+ .body_len = 100,
+ .bmark_count = 1,
+ .pop_count = 200,
+ };
+ ltfbu_test_once(&cfg);
+}
diff --git a/sys/log/full/selftest/fcb2_bookmarks/syscfg.yml b/sys/log/full/selftest/fcb2_bookmarks/syscfg.yml
new file mode 100644
index 0000000..fda1a78
--- /dev/null
+++ b/sys/log/full/selftest/fcb2_bookmarks/syscfg.yml
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.vals:
+ LOG_VERSION: 3
+ LOG_FCB2: 1
+ LOG_FCB_BOOKMARKS: 1
+ LOG_STATS: 1
diff --git a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c b/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
index 25a8b36..dca71d1 100644
--- a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
+++ b/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c
@@ -99,7 +99,7 @@ ltfbu_expected_idxs(uint32_t start_idx)
first++;
count--;
}
-
+
return (struct ltfbu_slice) {
.idxs = <fbu_entry_idxs[first],
.count = count,
diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c
index 9e5c4d1..38b0619 100644
--- a/sys/log/full/src/log_fcb2.c
+++ b/sys/log/full/src/log_fcb2.c
@@ -24,8 +24,8 @@
#include <string.h>
#include "flash_map/flash_map.h"
-#include "fcb/fcb.h"
#include "log/log.h"
+#include "fcb/fcb.h"
/* Assume the flash alignment requirement is no stricter than 8. */
#define LOG_FCB2_MAX_ALIGN 8
@@ -164,7 +164,12 @@ log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc)
#endif
#if MYNEWT_VAL(LOG_STATS)
+#if MYNEWT_VAL(LOG_FCB)
rc = fcb_area_info(fcb, NULL, &cnt, NULL);
+#endif
+#if MYNEWT_VAL(LOG_FCB2)
+ rc = fcb_area_info(fcb, FCB_SECTOR_OLDEST, &cnt, NULL);
+#endif
if (rc == 0) {
LOG_STATS_INCN(log, lost, cnt);
}
diff --git a/sys/log/full/syscfg.yml b/sys/log/full/syscfg.yml
index b49ccd8..5e8982b 100644
--- a/sys/log/full/syscfg.yml
+++ b/sys/log/full/syscfg.yml
@@ -68,7 +68,7 @@ syscfg.defs:
bookmark storage at runtime.
value: 0
restrictions:
- - LOG_FCB
+ - (LOG_FCB || LOG_FCB2)
LOG_CONSOLE:
description: 'Support logging to console.'
[mynewt-core] 11/13: sys/reboot;
fix broken build when LOG_FCB is set.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit eead0c8d2cf9b9e696a0aa9a86426d52e66b8409
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Fri Aug 30 13:54:08 2019 +0300
sys/reboot; fix broken build when LOG_FCB is set.
---
sys/reboot/src/log_reboot.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index c9c3780..24e335f 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -94,7 +94,7 @@ log_reboot_init_fcb(void)
}
fcbp = &reboot_log_fcb.fl_fcb;
#if MYNEWT_VAL(LOG_FCB)
- sector = *ptr;
+ reboot_sector = *ptr;
fcbp->f_magic = 0x7EADBADF;
fcbp->f_version = g_log_info.li_version;
fcbp->f_sector_cnt = 1;
[mynewt-core] 08/13: sys/config & sys/log;
use different magic numbers when using FCB vs FCB2.
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 661a2c82090ebe89cc7dee042fe83e98236847c1
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Fri Aug 30 10:46:07 2019 +0300
sys/config & sys/log; use different magic numbers when using FCB vs FCB2.
---
sys/config/syscfg.yml | 2 ++
sys/log/full/src/log_fcb2.c | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/sys/config/syscfg.yml b/sys/config/syscfg.yml
index 684f962..ee9695d 100644
--- a/sys/config/syscfg.yml
+++ b/sys/config/syscfg.yml
@@ -97,3 +97,5 @@ syscfg.defs.CONFIG_NFFS:
description: 'Limit how many items stored in file before compressing'
value: 32
+syscfg.vals.CONFIG_FCB2:
+ CONFIG_FCB_MAGIC: 0xd0b1d0b1
diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c
index 38b0619..7a141cf 100644
--- a/sys/log/full/src/log_fcb2.c
+++ b/sys/log/full/src/log_fcb2.c
@@ -821,7 +821,7 @@ log_fcb2_rtr_erase(struct log *log, void *arg)
fcb_scratch.f_ranges = ⦥
fcb_scratch.f_sector_cnt = 1;
fcb_scratch.f_range_cnt = 1;
- fcb_scratch.f_magic = 0x7EADBADF;
+ fcb_scratch.f_magic = 0x7EADBAE0;
fcb_scratch.f_version = g_log_info.li_version;
flash_area_erase(&range.fsr_flash_area, 0, range.fsr_flash_area.fa_size);