You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2017/03/17 19:22:14 UTC
incubator-mynewt-core git commit: MYNEWT-676 Reboot counter value
inconsistent
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 0d659e876 -> d1f00e95a
MYNEWT-676 Reboot counter value inconsistent
The value that gets logged to the reboot log is one greater than the
actual reboot counter (the value retrieved via "newtmgr config
reboot/reboot_cnt").
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/d1f00e95
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d1f00e95
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d1f00e95
Branch: refs/heads/develop
Commit: d1f00e95a6d4187d4227782fd97b055473137a0e
Parents: 0d659e8
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Mar 17 12:04:40 2017 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Mar 17 12:20:11 2017 -0700
----------------------------------------------------------------------
apps/sensors_test/src/main.c | 4 +-
apps/slinky/src/main.c | 4 +-
apps/slinky_oic/src/main.c | 4 +-
apps/splitty/src/main.c | 4 +-
apps/testbench/src/testbench.c | 4 +-
apps/testbench/src/testbench.h | 2 +-
sys/reboot/include/reboot/log_reboot.h | 1 +
sys/reboot/src/log_reboot.c | 119 +++++++++++++---------------
8 files changed, 67 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index 45d25a2..8ecbccd 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -46,7 +46,7 @@
#include <assert.h>
#include <string.h>
#include <flash_test/flash_test.h>
-#include <reboot/log_reboot.h>
+#include <reboot/reboot_start.h>
#include <os/os_time.h>
#include <id/id.h>
@@ -425,7 +425,7 @@ main(int argc, char **argv)
conf_load();
- log_reboot(hal_reset_cause());
+ reboot_start(hal_reset_cause());
init_tasks();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 7ab13d6..2e74801 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -41,7 +41,7 @@
#include <assert.h>
#include <string.h>
#include <flash_test/flash_test.h>
-#include <reboot/log_reboot.h>
+#include <reboot/reboot_start.h>
#include <os/os_time.h>
#include <id/id.h>
@@ -269,7 +269,7 @@ main(int argc, char **argv)
conf_load();
- log_reboot(hal_reset_cause());
+ reboot_start(hal_reset_cause());
init_tasks();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/apps/slinky_oic/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky_oic/src/main.c b/apps/slinky_oic/src/main.c
index 2f8df31..115fa33 100755
--- a/apps/slinky_oic/src/main.c
+++ b/apps/slinky_oic/src/main.c
@@ -37,7 +37,7 @@
#include <oic/oc_api.h>
#include <assert.h>
#include <string.h>
-#include <reboot/log_reboot.h>
+#include <reboot/reboot_start.h>
#include <os/os_time.h>
#ifdef ARCH_sim
@@ -283,7 +283,7 @@ main(int argc, char **argv)
conf_load();
- log_reboot(hal_reset_cause());
+ reboot_start(hal_reset_cause());
#if MYNEWT_VAL(SPLIT_LOADER)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/apps/splitty/src/main.c
----------------------------------------------------------------------
diff --git a/apps/splitty/src/main.c b/apps/splitty/src/main.c
index 267b4bc..6362187 100755
--- a/apps/splitty/src/main.c
+++ b/apps/splitty/src/main.c
@@ -34,7 +34,7 @@
#include <imgmgr/imgmgr.h>
#include <assert.h>
#include <string.h>
-#include <reboot/log_reboot.h>
+#include <reboot/reboot_start.h>
#include <os/os_time.h>
#include <id/id.h>
@@ -196,7 +196,7 @@ main(int argc, char **argv)
conf_load();
- log_reboot(hal_reset_cause());
+ reboot_start(hal_reset_cause());
init_tasks();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/apps/testbench/src/testbench.c
----------------------------------------------------------------------
diff --git a/apps/testbench/src/testbench.c b/apps/testbench/src/testbench.c
index b8fe034..5345d6f 100644
--- a/apps/testbench/src/testbench.c
+++ b/apps/testbench/src/testbench.c
@@ -43,7 +43,7 @@
#include <assert.h>
#include <string.h>
#include <json/json.h>
-#include <reboot/log_reboot.h>
+#include <reboot/reboot_start.h>
#include <os/os_time.h>
#include <id/id.h>
#include <os/os_eventq.h>
@@ -353,7 +353,7 @@ main(int argc, char **argv)
cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
log_register("testlog", &testlog, &log_cbmem_handler, &cbmem, LOG_SYSLEVEL);
- log_reboot(hal_reset_cause());
+ reboot_start(hal_reset_cause());
conf_load();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/apps/testbench/src/testbench.h
----------------------------------------------------------------------
diff --git a/apps/testbench/src/testbench.h b/apps/testbench/src/testbench.h
index a94ee1c..8b39310 100644
--- a/apps/testbench/src/testbench.h
+++ b/apps/testbench/src/testbench.h
@@ -46,7 +46,7 @@
#include <assert.h>
#include <string.h>
#include <json/json.h>
-#include <reboot/log_reboot.h>
+#include <reboot/reboot_start.h>
#include <os/os_time.h>
#include <id/id.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/sys/reboot/include/reboot/log_reboot.h
----------------------------------------------------------------------
diff --git a/sys/reboot/include/reboot/log_reboot.h b/sys/reboot/include/reboot/log_reboot.h
index e3ff093..fbc1f24 100644
--- a/sys/reboot/include/reboot/log_reboot.h
+++ b/sys/reboot/include/reboot/log_reboot.h
@@ -35,6 +35,7 @@ extern "C" {
int reboot_init_handler(int log_store_type, uint8_t entries);
int log_reboot(enum hal_reset_reason);
+void reboot_start(enum hal_reset_reason reason);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d1f00e95/sys/reboot/src/log_reboot.c
----------------------------------------------------------------------
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 9bfe04c..b795e1c 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -43,17 +43,17 @@ static uint16_t reboot_cnt;
static uint16_t soft_reboot;
static char reboot_cnt_str[12];
static char soft_reboot_str[12];
-static char *reboot_cnt_get(int argc, char **argv, char *buf, int max_len);
-static int reboot_cnt_set(int argc, char **argv, char *val);
-static int reboot_cnt_export(void (*export_func)(char *name, char *val),
+static char *reboot_conf_get(int argc, char **argv, char *buf, int max_len);
+static int reboot_conf_set(int argc, char **argv, char *val);
+static int reboot_conf_export(void (*export_func)(char *name, char *val),
enum conf_export_tgt tgt);
struct conf_handler reboot_conf_handler = {
.ch_name = "reboot",
- .ch_get = reboot_cnt_get,
- .ch_set = reboot_cnt_set,
+ .ch_get = reboot_conf_get,
+ .ch_set = reboot_conf_set,
.ch_commit = NULL,
- .ch_export = reboot_cnt_export
+ .ch_export = reboot_conf_export
};
#if MYNEWT_VAL(REBOOT_LOG_FCB)
@@ -127,6 +127,19 @@ reboot_init_handler(int log_store_type, uint8_t entries)
return 0;
}
+static int
+reboot_cnt_inc(void)
+{
+ char str[12];
+ int rc;
+
+ reboot_cnt++;
+ rc = conf_save_one("reboot/reboot_cnt",
+ conf_str_from_value(CONF_INT16, &reboot_cnt,
+ str, sizeof(str)));
+ return rc;
+}
+
/**
* Logs reboot with the specified reason
* @param reason for reboot
@@ -135,105 +148,83 @@ reboot_init_handler(int log_store_type, uint8_t entries)
int
log_reboot(enum hal_reset_reason reason)
{
- int rc;
- char str[12] = {0};
struct image_version ver;
- int16_t reboot_tmp_cnt;
- rc = 0;
#if MYNEWT_VAL(REBOOT_LOG_FCB)
{
const struct flash_area *ptr;
if (flash_area_open(MYNEWT_VAL(REBOOT_LOG_FLASH_AREA), &ptr)) {
- goto err;
+ return 0;
}
}
#endif
- reboot_tmp_cnt = reboot_cnt;
-
if (reason == HAL_RESET_REQUESTED) {
- /*
- * Save soft_reboot as 1 if user is requesting restart.
- */
- reboot_tmp_cnt = 1;
- conf_save_one("reboot/soft_reboot",
- conf_str_from_value(CONF_INT16, &reboot_tmp_cnt,
- str, sizeof(str)));
- reboot_tmp_cnt = reboot_cnt + 1;
+ conf_save_one("reboot/soft_reboot", "1");
} else {
conf_save_one("reboot/soft_reboot", "0");
- if (soft_reboot && reason == HAL_RESET_SOFT) {
- /* No need to log as it's not a hard reboot */
- goto err;
- } else {
- reboot_cnt++;
- reboot_tmp_cnt = reboot_cnt;
- }
}
- /*
- * Only care for this return code as it will tell whether the config is
- * full, the caller of the function might not care about the return code
- * Saving the reboot cnt
- */
- rc = conf_save_one("reboot/reboot_cnt",
- conf_str_from_value(CONF_INT16, &reboot_tmp_cnt,
- str, sizeof(str)));
+ if (!soft_reboot || reason != HAL_RESET_SOFT) {
+ imgr_my_version(&ver);
+
+ /* Log a reboot */
+ LOG_CRITICAL(&reboot_log, LOG_MODULE_REBOOT, "rsn:%s, cnt:%u,"
+ " img:%u.%u.%u.%u", REBOOT_REASON_STR(reason),
+ reboot_cnt, ver.iv_major, ver.iv_minor,
+ ver.iv_revision, (unsigned int)ver.iv_build_num);
+ }
- imgr_my_version(&ver);
+ return 0;
+}
- /* Log a reboot */
- LOG_CRITICAL(&reboot_log, LOG_MODULE_REBOOT, "rsn:%s, cnt:%u,"
- " img:%u.%u.%u.%u", REBOOT_REASON_STR(reason), reboot_tmp_cnt,
- ver.iv_major, ver.iv_minor, ver.iv_revision,
- (unsigned int)ver.iv_build_num);
-err:
- return (rc);
+/**
+ * Increments the reboot counter and writes an entry to the reboot log, if
+ * necessary. This function should be called from main() after config
+ * settings have been loaded via conf_load().
+ *
+ * @param reason The cause of the reboot.
+ */
+void
+reboot_start(enum hal_reset_reason reason)
+{
+ reboot_cnt_inc();
+ log_reboot(reason);
}
static char *
-reboot_cnt_get(int argc, char **argv, char *buf, int max_len)
+reboot_conf_get(int argc, char **argv, char *buf, int max_len)
{
if (argc == 1) {
if (!strcmp(argv[0], "reboot_cnt")) {
- return reboot_cnt_str;
+ return conf_str_from_value(CONF_INT16, &reboot_cnt,
+ reboot_cnt_str, sizeof reboot_cnt_str);
} else if (!strcmp(argv[0], "soft_reboot")) {
- return soft_reboot_str;
+ return conf_str_from_value(CONF_INT16, &soft_reboot,
+ soft_reboot_str,
+ sizeof soft_reboot_str);
}
}
return NULL;
}
static int
-reboot_cnt_set(int argc, char **argv, char *val)
+reboot_conf_set(int argc, char **argv, char *val)
{
- int rc;
-
if (argc == 1) {
if (!strcmp(argv[0], "reboot_cnt")) {
- rc = CONF_VALUE_SET(val, CONF_STRING, reboot_cnt_str);
- if (rc) {
- goto err;
- }
-
- return CONF_VALUE_SET(reboot_cnt_str, CONF_INT16, reboot_cnt);
+ return CONF_VALUE_SET(val, CONF_INT16, reboot_cnt);
} else if (!strcmp(argv[0], "soft_reboot")) {
- rc = CONF_VALUE_SET(val, CONF_STRING, soft_reboot_str);
- if (rc) {
- goto err;
- }
-
- return CONF_VALUE_SET(soft_reboot_str, CONF_INT16, soft_reboot);
+ return CONF_VALUE_SET(val, CONF_INT16, soft_reboot);
}
}
-err:
return OS_ENOENT;
}
static int
-reboot_cnt_export(void (*func)(char *name, char *val), enum conf_export_tgt tgt)
+reboot_conf_export(void (*func)(char *name, char *val),
+ enum conf_export_tgt tgt)
{
if (tgt == CONF_EXPORT_SHOW) {
func("reboot/reboot_cnt", reboot_cnt_str);