You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/06/09 21:38:51 UTC
[6/9] incubator-mynewt-core git commit: Clean reboot log and fix a
few issues
Clean reboot log and fix a few issues
- Cleaning up last_n_offset function
- initializing new log before it gets written to
- Storing number of entries and fcb to temp and retreiving them after
moving to the scratch
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/0bc5d6b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0bc5d6b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0bc5d6b3
Branch: refs/heads/develop
Commit: 0bc5d6b319a12c1839f75a74a8ef14901c3a5fdf
Parents: e0ed9a2
Author: Vipul Rahane <vi...@runtime.io>
Authored: Fri May 27 19:51:25 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Thu Jun 9 12:31:59 2016 -0700
----------------------------------------------------------------------
apps/slinky/src/main.c | 2 +-
sys/fcb/include/fcb/fcb.h | 4 ++--
sys/fcb/src/fcb.c | 16 +++++++++-------
sys/log/src/log_fcb.c | 27 +++++++++++++++++++++------
sys/reboot/src/log_reboot.c | 3 ++-
5 files changed, 35 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0bc5d6b3/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 74d1e5e..da401e2 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -391,7 +391,7 @@ main(int argc, char **argv)
stats_register("gpio_toggle", STATS_HDR(g_stats_gpio_toggle));
flash_test_init();
-
+
reboot_init_handler(LOG_TYPE_STORAGE, 10);
conf_load();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0bc5d6b3/sys/fcb/include/fcb/fcb.h
----------------------------------------------------------------------
diff --git a/sys/fcb/include/fcb/fcb.h b/sys/fcb/include/fcb/fcb.h
index 3661114..df19e2b 100644
--- a/sys/fcb/include/fcb/fcb.h
+++ b/sys/fcb/include/fcb/fcb.h
@@ -113,7 +113,7 @@ int fcb_free_sector_cnt(struct fcb *fcb);
*/
int fcb_is_empty(struct fcb *fcb);
-uint32_t
-fcb_offset_last_n(struct fcb *fcb, uint8_t entries);
+int
+fcb_offset_last_n(struct fcb *fcb, uint8_t entries, uint32_t *offset);
#endif /* __SYS_FLASHVAR_H_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0bc5d6b3/sys/fcb/src/fcb.c
----------------------------------------------------------------------
diff --git a/sys/fcb/src/fcb.c b/sys/fcb/src/fcb.c
index de277bd..4973be4 100644
--- a/sys/fcb/src/fcb.c
+++ b/sys/fcb/src/fcb.c
@@ -21,6 +21,7 @@
#include "fcb/fcb.h"
#include "fcb_priv.h"
+#include "string.h"
int
fcb_init(struct fcb *fcb)
@@ -199,30 +200,31 @@ fcb_sector_hdr_read(struct fcb *fcb, struct flash_area *fap,
return 1;
}
-uint32_t
-fcb_offset_last_n(struct fcb *fcb, uint8_t entries)
+int
+fcb_offset_last_n(struct fcb *fcb, uint8_t entries, uint32_t *last_n_off)
{
struct fcb_entry loc;
uint32_t curr_off;
- uint32_t last_n_off;
int i;
i = 0;
+ memset(&loc, 0, sizeof(loc));
while (fcb_getnext(fcb, &loc) == 0) {
if (i == 0) {
/* Start from the beginning of fcb entries */
curr_off = loc.fe_elem_off;
- last_n_off = curr_off;
+ *last_n_off = curr_off;
}
/* length + crc length in flash + data length in flash */
- curr_off += fcb_len_in_flash(fcb, sizeof(loc.fe_data_len)) + fcb_len_in_flash(fcb, 1) +
+ curr_off += fcb_len_in_flash(fcb, sizeof(loc.fe_data_len)) +
+ fcb_len_in_flash(fcb, FCB_CRC_SZ) +
fcb_len_in_flash(fcb, loc.fe_data_len);
/* Update last_n_off after n entries and keep updating */
if (i >= entries) {
- last_n_off = curr_off;
+ *last_n_off = curr_off;
}
i++;
}
- return last_n_off;
+ return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0bc5d6b3/sys/log/src/log_fcb.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_fcb.c b/sys/log/src/log_fcb.c
index f381c20..0c021a0 100644
--- a/sys/log/src/log_fcb.c
+++ b/sys/log/src/log_fcb.c
@@ -146,8 +146,8 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
char data[LOG_PRINTF_MAX_ENTRY_LEN + sizeof(ueh)];
int dlen;
int rc;
-
- dst_fcb = ((struct fcb_log *)log->l_log->log_arg)->fl_fcb;
+ struct fcb *fcb_tmp;
+ uint8_t entries_tmp;
rc = log_fcb_read(log, entry, &ueh, 0, sizeof(ueh));
if (rc != sizeof(ueh)) {
@@ -162,11 +162,26 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
}
data[rc] = 0;
+ /* Changing the fcb to be logged to be dst fcb */
+ fcb_tmp = ((struct fcb_log *)log->l_log->log_arg)->fl_fcb;
+
+ entries_tmp = ((struct fcb_log *)log->l_log->log_arg)->fl_entries;
+
+ rc = log_fcb_handler_init(log->l_log, dst_fcb, 0);
+ if (rc) {
+ goto err;
+ }
+
rc = log_fcb_append(log, data, dlen);
if (rc) {
goto err;
}
+ rc = log_fcb_handler_init(log->l_log, fcb_tmp, entries_tmp);
+ if (rc) {
+ goto err;
+ }
+
err:
return (rc);
}
@@ -217,6 +232,7 @@ log_fcb_rtr_erase(struct log *log, void *arg)
int rc;
rc = 0;
+ offset = 0;;
if (!log) {
rc = -1;
goto err;
@@ -242,10 +258,8 @@ log_fcb_rtr_erase(struct log *log, void *arg)
}
/* Calculate offset of n-th last entry */
- offset = fcb_offset_last_n(fcb, fcb_log->fl_entries);
-
- rc = log_fcb_handler_init(log->l_log, &fcb_scratch, 0);
- if (rc) {
+ rc = fcb_offset_last_n(fcb, fcb_log->fl_entries, &offset);
+ if (rc){
goto err;
}
@@ -259,6 +273,7 @@ log_fcb_rtr_erase(struct log *log, void *arg)
if (rc) {
goto err;
}
+
/* Copy back from scratch */
rc = log_fcb_copy(log, &fcb_scratch, fcb, 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0bc5d6b3/sys/reboot/src/log_reboot.c
----------------------------------------------------------------------
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 8a6f3dd..cdf1270 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -65,7 +65,7 @@ reboot_init_handler(int log_type, uint8_t entries)
int rc;
const struct flash_area *ptr;
- conf_register(&reboot_conf_handler);
+ rc = conf_register(&reboot_conf_handler);
switch (log_type) {
case LOG_TYPE_STORAGE:
@@ -137,6 +137,7 @@ log_reboot(int reason)
goto err;
}
if (soft_reboot) {
+ /* No need to log as it's not a hard reboot */
goto err;
} else {
reboot_cnt++;