summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVipul Rahane <vipul@runtime.io>2016-05-27 19:51:25 -0700
committerVipul Rahane <vipul@runtime.io>2016-06-09 12:31:59 -0700
commit0bc5d6b319a12c1839f75a74a8ef14901c3a5fdf (patch)
tree0340d9012ec7f44b6db4a29c565d0c8381aa2be6 /sys
parente0ed9a2ddd90e97c69bffc469ffd9f2360c85f2b (diff)
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
Diffstat (limited to 'sys')
-rw-r--r--sys/fcb/include/fcb/fcb.h4
-rw-r--r--sys/fcb/src/fcb.c16
-rw-r--r--sys/log/src/log_fcb.c27
-rw-r--r--sys/reboot/src/log_reboot.c3
4 files changed, 34 insertions, 16 deletions
diff --git a/sys/fcb/include/fcb/fcb.h b/sys/fcb/include/fcb/fcb.h
index 3661114c..df19e2bd 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_ */
diff --git a/sys/fcb/src/fcb.c b/sys/fcb/src/fcb.c
index de277bd1..4973be45 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;
}
diff --git a/sys/log/src/log_fcb.c b/sys/log/src/log_fcb.c
index f381c206..0c021a04 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);
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 8a6f3dd8..cdf12706 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++;