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 2016/09/08 02:52:46 UTC

[1/4] incubator-mynewt-core git commit: Change logging format to use 16-bit log index.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 260a90ebb -> 7f28def42


Change logging format to use 16-bit log index.

Change log struct (log_entry_hdr) from using an 8-bit to 16-bit index (ue_index) and reducing the log module number (ue_module) from 16-bit to 8-bit preserving the size of the structure. Also removed code which reset the index
every 1ms.

Added a version id in the global log_info structure so the log record format can be differentiated OTW or from non-volatile storage.

Partial checkin for MYNEWT-368 - remaining work to store record format in FCB.


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/2d7ed71e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2d7ed71e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2d7ed71e

Branch: refs/heads/develop
Commit: 2d7ed71e48fdbc65034e514238455cd7893de9cb
Parents: 260a90e
Author: Peter Snyder <gi...@peterfs.com>
Authored: Thu Sep 1 17:20:18 2016 -0700
Committer: Peter Snyder <gi...@peterfs.com>
Committed: Wed Sep 7 19:47:24 2016 -0700

----------------------------------------------------------------------
 sys/log/include/log/log.h | 7 +++++--
 sys/log/src/log.c         | 6 +-----
 2 files changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2d7ed71e/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/sys/log/include/log/log.h b/sys/log/include/log/log.h
index 1e974ff..2785bf6 100644
--- a/sys/log/include/log/log.h
+++ b/sys/log/include/log/log.h
@@ -28,7 +28,10 @@
 struct log_info {
     int64_t li_timestamp;
     uint8_t li_index;
+    uint8_t li_version;
 };
+#define LOG_VERSION_V2  2
+#define LOG_VERSION_V1  1
 
 extern struct log_info g_log_info;
 
@@ -65,8 +68,8 @@ struct log_handler {
 
 struct log_entry_hdr {
     int64_t ue_ts;
-    uint16_t ue_module;
-    uint8_t ue_index;
+    uint16_t ue_index;
+    uint8_t ue_module;
     uint8_t ue_level;
 }__attribute__((__packed__));
 #define LOG_ENTRY_HDR_SIZE (sizeof(struct log_entry_hdr))

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2d7ed71e/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index 6547d5a..23bb83a 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -113,6 +113,7 @@ log_append(struct log *log, uint16_t module, uint16_t level, void *data,
 
     ue = (struct log_entry_hdr *) data;
 
+    /* Could check for li_index wraparound here */
     g_log_info.li_index++;
 
     /* Try to get UTC Time */
@@ -134,11 +135,6 @@ log_append(struct log *log, uint16_t module, uint16_t level, void *data,
         goto err;
     }
 
-    /* Resetting index every millisecond */
-    if (g_log_info.li_timestamp > 1000 + prev_ts) {
-        g_log_info.li_index = 0;
-    }
-
     return (0);
 err:
     return (rc);


[3/4] incubator-mynewt-core git commit: Logging format and initialization

Posted by cc...@apache.org.
Logging format and initialization

MYNEWT-368: Complete logging format changes including saving log format version in fcb struct in flash

MYNEWT-262: Move initialization of logging resources to application. Logging handler is chosen by application and uses standard log_handlers rather than having each app call the handler_init function. Per-instance log structure are declared and initialized in each app and are associated with the log calls by log_register. Separate notion of log "type" for newtmgr (i.e, stream, memory,storage), and how log records are handled (e.g, cbmem, fcb).

Also - fix console_print_prompt() warning, nffs logging


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/1fd3fbfe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1fd3fbfe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1fd3fbfe

Branch: refs/heads/develop
Commit: 1fd3fbfe068ed496b92523185a093ecee7c52164
Parents: 42048f4
Author: Peter Snyder <gi...@peterfs.com>
Authored: Wed Sep 7 18:46:59 2016 -0700
Committer: Peter Snyder <gi...@peterfs.com>
Committed: Wed Sep 7 19:47:51 2016 -0700

----------------------------------------------------------------------
 apps/blecent/src/main.c                |  4 +--
 apps/bleprph/src/main.c                |  4 +--
 apps/bletiny/src/main.c                |  4 +--
 apps/ffs2native/src/main.c             |  4 +--
 apps/slinky/src/main.c                 | 12 ++++---
 apps/splitty/src/main.c                |  4 +--
 fs/nffs/src/nffs.c                     |  7 ++--
 fs/nffs/src/nffs_priv.h                |  4 +--
 libs/console/full/src/prompt.c         |  2 +-
 net/nimble/host/src/ble_hs.c           |  5 +--
 sys/fcb/include/fcb/fcb.h              | 10 ++++++
 sys/log/include/log/log.h              | 22 +++++++------
 sys/log/src/log.c                      | 16 +++++----
 sys/log/src/log_cbmem.c                | 33 +++++++------------
 sys/log/src/log_console.c              | 26 +++++----------
 sys/log/src/log_fcb.c                  | 50 ++++++++++-------------------
 sys/log/src/test/log_test.c            |  5 +--
 sys/reboot/include/reboot/log_reboot.h |  2 +-
 sys/reboot/src/log_reboot.c            | 37 +++++++++++----------
 19 files changed, 111 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 7056cc6..c5cd2bc 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -55,7 +55,6 @@ struct os_mbuf_pool blecent_mbuf_pool;
 struct os_mempool blecent_mbuf_mpool;
 
 /** Log data. */
-static struct log_handler blecent_log_console_handler;
 struct log blecent_log;
 
 /** Priority of the nimble host and controller tasks. */
@@ -557,8 +556,7 @@ main(void)
 
     /* Initialize the logging system. */
     log_init();
-    log_console_handler_init(&blecent_log_console_handler);
-    log_register("blecent", &blecent_log, &blecent_log_console_handler);
+    log_register("blecent", &blecent_log, &log_console_handler, NULL);
 
     /* Initialize the eventq for the application task. */
     os_eventq_init(&blecent_evq);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 0233bc1..1121703 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -69,7 +69,6 @@ struct os_mbuf_pool bleprph_mbuf_pool;
 struct os_mempool bleprph_mbuf_mpool;
 
 /** Log data. */
-static struct log_handler bleprph_log_console_handler;
 struct log bleprph_log;
 
 /** Priority of the nimble host and controller tasks. */
@@ -381,8 +380,7 @@ main(void)
 
     /* Initialize the logging system. */
     log_init();
-    log_console_handler_init(&bleprph_log_console_handler);
-    log_register("bleprph", &bleprph_log, &bleprph_log_console_handler);
+    log_register("bleprph", &bleprph_log, &log_console_handler, NULL);
 
     /* Initialize eventq */
     os_eventq_init(&bleprph_evq);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index dfd0aee..faaf8ab 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -112,7 +112,6 @@ struct os_eventq bletiny_evq;
 struct os_task bletiny_task;
 bssnz_t os_stack_t bletiny_stack[BLETINY_STACK_SIZE];
 
-static struct log_handler bletiny_log_console_handler;
 struct log bletiny_log;
 
 bssnz_t struct bletiny_conn bletiny_conns[NIMBLE_OPT(MAX_CONNECTIONS)];
@@ -1685,8 +1684,7 @@ main(void)
 
     /* Initialize the logging system. */
     log_init();
-    log_console_handler_init(&bletiny_log_console_handler);
-    log_register("bletiny", &bletiny_log, &bletiny_log_console_handler);
+    log_register("bletiny", &bletiny_log, &log_console_handler, NULL);
 
     /* Initialize eventq for the application task. */
     os_eventq_init(&bletiny_evq);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/apps/ffs2native/src/main.c
----------------------------------------------------------------------
diff --git a/apps/ffs2native/src/main.c b/apps/ffs2native/src/main.c
index 19a5330..6558f0d 100644
--- a/apps/ffs2native/src/main.c
+++ b/apps/ffs2native/src/main.c
@@ -40,7 +40,6 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 
-static struct log_handler nffs_log_console_handler;
 struct log nffs_log;
 static const char *copy_in_dir;
 static const char *progname;
@@ -684,8 +683,7 @@ main(int argc, char **argv)
     assert(rc == 0);
 
     log_init();
-    log_console_handler_init(&nffs_log_console_handler);
-    log_register("nffs-log", &nffs_log, &nffs_log_console_handler);
+    log_register("nffs-log", &nffs_log, &log_console_handler, NULL);
 
     file_scratch_idx = MAX_AREAS + 1;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 9c0a03b..5d607cf 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -79,8 +79,8 @@ static struct os_task task2;
 #define NEWTMGR_TASK_PRIO (4)
 #define NEWTMGR_TASK_STACK_SIZE (OS_STACK_ALIGN(896))
 
-static struct log_handler log_cbmem_handler;
 static struct log my_log;
+extern struct log nffs_log; /* defined in the OS module */
 
 static volatile int g_task2_loops;
 
@@ -148,6 +148,9 @@ static char test_str[32];
 static uint32_t cbmem_buf[MAX_CBMEM_BUF];
 static struct cbmem cbmem;
 
+static uint32_t nffs_cbmem_buf[MAX_CBMEM_BUF];
+static struct cbmem nffs_cbmem;
+
 static char *
 test_conf_get(int argc, char **argv, char *buf, int max_len)
 {
@@ -372,8 +375,9 @@ main(int argc, char **argv)
 
     log_init();
     cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
-    log_cbmem_handler_init(&log_cbmem_handler, &cbmem);
-    log_register("log", &my_log, &log_cbmem_handler);
+    cbmem_init(&nffs_cbmem, nffs_cbmem_buf, MAX_CBMEM_BUF);
+    log_register("log", &my_log, &log_cbmem_handler, &cbmem);
+    log_register("nffs", &nffs_log, &log_cbmem_handler, &nffs_cbmem);
 
     os_init();
 
@@ -422,7 +426,7 @@ main(int argc, char **argv)
 
     flash_test_init();
 
-    reboot_init_handler(LOG_TYPE_STORAGE, 10);
+    reboot_init_handler(LOG_STORE_FCB, 11);
 
 #if defined SPLIT_LOADER || defined SPLIT_APPLICATION
     split_app_init();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/apps/splitty/src/main.c
----------------------------------------------------------------------
diff --git a/apps/splitty/src/main.c b/apps/splitty/src/main.c
index 682acfe..acdc750 100755
--- a/apps/splitty/src/main.c
+++ b/apps/splitty/src/main.c
@@ -78,7 +78,6 @@ static struct os_task task2;
 #define NEWTMGR_TASK_PRIO (4)
 #define NEWTMGR_TASK_STACK_SIZE (OS_STACK_ALIGN(896))
 
-static struct log_handler log_cbmem_handler;
 static struct log my_log;
 
 static volatile int g_task2_loops;
@@ -307,8 +306,7 @@ main(int argc, char **argv)
 
     log_init();
     cbmem_init(&cbmem, cbmem_buf, MAX_CBMEM_BUF);
-    log_cbmem_handler_init(&log_cbmem_handler, &cbmem);
-    log_register("log", &my_log, &log_cbmem_handler);
+    log_register("log", &my_log, &log_cbmem_handler, &cbmem);
 
     os_init();
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/fs/nffs/src/nffs.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs.c b/fs/nffs/src/nffs.c
index a503df3..f6e1add 100644
--- a/fs/nffs/src/nffs.c
+++ b/fs/nffs/src/nffs.c
@@ -55,7 +55,6 @@ struct nffs_inode_entry *nffs_lost_found_dir;
 
 static struct os_mutex nffs_mutex;
 
-static struct log_handler nffs_log_console_handler;
 struct log nffs_log;
 
 static int nffs_open(const char *path, uint8_t access_flags,
@@ -725,15 +724,13 @@ nffs_init(void)
         return FS_ENOMEM;
     }
 
-    log_init();
-    log_console_handler_init(&nffs_log_console_handler);
-    log_register("nffs", &nffs_log, &nffs_log_console_handler);
-
     rc = nffs_misc_reset();
     if (rc != 0) {
         return rc;
     }
 
+    NFFS_LOG(DEBUG, "nffs_init");
+
     fs_register(&nffs_ops);
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/fs/nffs/src/nffs_priv.h
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_priv.h b/fs/nffs/src/nffs_priv.h
index 1985da5..a91161d 100644
--- a/fs/nffs/src/nffs_priv.h
+++ b/fs/nffs/src/nffs_priv.h
@@ -504,10 +504,10 @@ int nffs_write_to_file(struct nffs_file *file, const void *data, int len);
 
 #define NFFS_FLASH_LOC_NONE  nffs_flash_loc(NFFS_AREA_ID_NONE, 0)
 
-#ifdef NFFS_DEBUG
+#ifdef ARCH_sim
 #include <stdio.h>
 #define NFFS_LOG(lvl, ...) \
-      printf(__VA_ARGS__)
+    printf(__VA_ARGS__)
 #else
 #define NFFS_LOG(lvl, ...) \
     LOG_ ## lvl(&nffs_log, LOG_MODULE_NFFS, __VA_ARGS__)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/libs/console/full/src/prompt.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/prompt.c b/libs/console/full/src/prompt.c
index ac0dc81..5a811bf 100644
--- a/libs/console/full/src/prompt.c
+++ b/libs/console/full/src/prompt.c
@@ -36,5 +36,5 @@ console_set_prompt(char p)
 void
 console_print_prompt(void)
 {
-    console_printf(console_prompt);
+    console_printf("%s", console_prompt);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 8d4b047..1899a74 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -32,8 +32,6 @@
  */
 #define BLE_HS_MAX_EVS_IN_A_ROW 2
 
-static struct log_handler ble_hs_log_console_handler;
-
 struct os_mempool ble_hs_hci_ev_pool;
 static void *ble_hs_hci_os_event_buf;
 
@@ -561,8 +559,7 @@ ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
     ble_hs_cfg_init(cfg);
 
     log_init();
-    log_console_handler_init(&ble_hs_log_console_handler);
-    log_register("ble_hs", &ble_hs_log, &ble_hs_log_console_handler);
+    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL);
 
     ble_hs_hci_os_event_buf = malloc(
         OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs, sizeof (struct os_event)));

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/fcb/include/fcb/fcb.h
----------------------------------------------------------------------
diff --git a/sys/fcb/include/fcb/fcb.h b/sys/fcb/include/fcb/fcb.h
index 953074f..290303f 100644
--- a/sys/fcb/include/fcb/fcb.h
+++ b/sys/fcb/include/fcb/fcb.h
@@ -73,6 +73,16 @@ struct fcb {
 int fcb_init(struct fcb *fcb);
 
 /*
+ * fcb_log is needed as the number of entries in a log
+ */
+struct fcb_log {
+    struct fcb fl_fcb;
+    uint8_t fl_entries;
+} fcb_log;
+
+int log_fcb_init(struct fcb_log *fcblog, struct fcb *fcb, uint16_t entries);
+
+/*
  * 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

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/log/include/log/log.h
----------------------------------------------------------------------
diff --git a/sys/log/include/log/log.h b/sys/log/include/log/log.h
index 2785bf6..a27ad6c 100644
--- a/sys/log/include/log/log.h
+++ b/sys/log/include/log/log.h
@@ -63,7 +63,6 @@ struct log_handler {
     lh_walk_func_t log_walk;
     lh_flush_func_t log_flush;
     lh_rtr_erase_func_t log_rtr_erase;
-    void *log_arg;
 };
 
 struct log_entry_hdr {
@@ -111,6 +110,13 @@ struct log_entry_hdr {
     (LOG_MODULE_REBOOT      == module ? "REBOOT"      :\
      "UNKNOWN")))))))
 
+/*
+ * Logging Implementations
+ */
+#define LOG_STORE_CONSOLE    1
+#define LOG_STORE_CBMEM      2
+#define LOG_STORE_FCB        3
+
 /* UTC Timestamnp for Jan 2016 00:00:00 */
 #define UTC01_01_2016    1451606400
 
@@ -159,6 +165,7 @@ struct log_entry_hdr {
 struct log {
     char *l_name;
     struct log_handler *l_log;
+    void *l_arg;
     STAILQ_ENTRY(log) l_next;
 };
 
@@ -175,7 +182,8 @@ int log_init(void);
 struct log *log_list_get_next(struct log *);
 
 /* Log functions, manipulate a single log */
-int log_register(char *name, struct log *log, struct log_handler *);
+int log_register(char *name, struct log *log, const struct log_handler *,
+                 void *arg);
 int log_append(struct log *, uint16_t, uint16_t, void *, uint16_t);
 
 #define LOG_PRINTF_MAX_ENTRY_LEN (128)
@@ -187,14 +195,10 @@ int log_walk(struct log *log, log_walk_func_t walk_func,
 int log_flush(struct log *log);
 int log_rtr_erase(struct log *log, void *arg);
 
-
-
 /* Handler exports */
-int log_cbmem_handler_init(struct log_handler *, struct cbmem *);
-int log_console_handler_init(struct log_handler *);
-struct fcb;
-int log_fcb_handler_init(struct log_handler *, struct fcb *,
-                         uint8_t entries);
+extern const struct log_handler log_console_handler;
+extern const struct log_handler log_cbmem_handler;
+extern const struct log_handler log_fcb_handler;
 
 /* Private */
 #ifdef NEWTMGR_PRESENT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index c2c9ee5..7bdc0fc 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -46,6 +46,8 @@ struct shell_cmd g_shell_log_cmd = {
 };
 #endif
 
+char *log_modules[LOG_MODULE_MAX];
+
 int
 log_init(void)
 {
@@ -90,11 +92,16 @@ log_list_get_next(struct log *log)
     return (next);
 }
 
+/*
+ * Associate an instantiation of a log with the logging infrastructure
+ */
 int
-log_register(char *name, struct log *log, struct log_handler *lh)
+log_register(char *name, struct log *log, const struct log_handler *lh,
+             void *arg)
 {
     log->l_name = name;
-    log->l_log = lh;
+    log->l_log = (struct log_handler *)lh;
+    log->l_arg = arg;
 
     STAILQ_INSERT_TAIL(&g_log_list, log, l_next);
 
@@ -108,7 +115,6 @@ log_append(struct log *log, uint16_t module, uint16_t level, void *data,
     struct log_entry_hdr *ue;
     int rc;
     struct os_timeval tv;
-    int64_t prev_ts;
 
     if (log->l_name == NULL || log->l_log == NULL) {
         rc = -1;
@@ -128,7 +134,6 @@ log_append(struct log *log, uint16_t module, uint16_t level, void *data,
         ue->ue_ts = tv.tv_sec * 1000000 + tv.tv_usec;
     }
 
-    prev_ts = g_log_info.li_timestamp;
     g_log_info.li_timestamp = ue->ue_ts;
     ue->ue_level = level;
     ue->ue_module = module;
@@ -145,8 +150,7 @@ err:
 }
 
 void
-log_printf(struct log *log, uint16_t module, uint16_t level, char *msg,
-        ...)
+log_printf(struct log *log, uint16_t module, uint16_t level, char *msg, ...)
 {
     va_list args;
     char buf[LOG_ENTRY_HDR_SIZE + LOG_PRINTF_MAX_ENTRY_LEN];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/log/src/log_cbmem.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_cbmem.c b/sys/log/src/log_cbmem.c
index aa66d16..0caa17b 100644
--- a/sys/log/src/log_cbmem.c
+++ b/sys/log/src/log_cbmem.c
@@ -16,21 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #include <os/os.h>
-
 #include <util/cbmem.h>
-
 #include "log/log.h"
 
-
 static int
 log_cbmem_append(struct log *log, void *buf, int len)
 {
     struct cbmem *cbmem;
     int rc;
 
-    cbmem = (struct cbmem *) log->l_log->log_arg;
+    cbmem = (struct cbmem *) log->l_arg;
 
     rc = cbmem_append(cbmem, buf, len);
     if (rc != 0) {
@@ -50,7 +46,7 @@ log_cbmem_read(struct log *log, void *dptr, void *buf, uint16_t offset,
     struct cbmem_entry_hdr *hdr;
     int rc;
 
-    cbmem = (struct cbmem *) log->l_log->log_arg;
+    cbmem = (struct cbmem *) log->l_arg;
     hdr = (struct cbmem_entry_hdr *) dptr;
 
     rc = cbmem_read(cbmem, hdr, buf, offset, len);
@@ -66,7 +62,7 @@ log_cbmem_walk(struct log *log, log_walk_func_t walk_func, void *arg)
     struct cbmem_iter iter;
     int rc;
 
-    cbmem = (struct cbmem *) log->l_log->log_arg;
+    cbmem = (struct cbmem *) log->l_arg;
 
     rc = cbmem_lock_acquire(cbmem);
     if (rc != 0) {
@@ -102,7 +98,7 @@ log_cbmem_flush(struct log *log)
     struct cbmem *cbmem;
     int rc;
 
-    cbmem = (struct cbmem *) log->l_log->log_arg;
+    cbmem = (struct cbmem *) log->l_arg;
 
     rc = cbmem_flush(cbmem);
     if (rc != 0) {
@@ -114,16 +110,11 @@ err:
     return (rc);
 }
 
-int
-log_cbmem_handler_init(struct log_handler *handler, struct cbmem *cbmem)
-{
-    handler->log_type = LOG_TYPE_MEMORY;
-    handler->log_read = log_cbmem_read;
-    handler->log_append = log_cbmem_append;
-    handler->log_walk = log_cbmem_walk;
-    handler->log_flush = log_cbmem_flush;
-    handler->log_arg = (void *) cbmem;
-    handler->log_rtr_erase = NULL;
-
-    return (0);
-}
+const struct log_handler log_cbmem_handler = {
+    .log_type = LOG_TYPE_MEMORY,
+    .log_read = log_cbmem_read,
+    .log_append = log_cbmem_append,
+    .log_walk = log_cbmem_walk,
+    .log_flush = log_cbmem_flush,
+    .log_rtr_erase = NULL,
+};

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/log/src/log_console.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_console.c b/sys/log/src/log_console.c
index 20e1183..73814da 100644
--- a/sys/log/src/log_console.c
+++ b/sys/log/src/log_console.c
@@ -18,14 +18,10 @@
  */
 
 #include <os/os.h>
-
 #include <util/cbmem.h>
-
 #include <console/console.h>
-
 #include "log/log.h"
 
-
 static int
 log_console_append(struct log *log, void *buf, int len)
 {
@@ -69,17 +65,11 @@ log_console_flush(struct log *log)
     return (OS_EINVAL);
 }
 
-int
-log_console_handler_init(struct log_handler *handler)
-{
-    handler->log_type = LOG_TYPE_STREAM;
-    handler->log_read = log_console_read;
-    handler->log_append = log_console_append;
-    handler->log_walk = log_console_walk;
-    handler->log_flush = log_console_flush;
-    handler->log_arg = NULL;
-    handler->log_rtr_erase = NULL;
-
-    return (0);
-}
-
+const struct log_handler log_console_handler = {
+    .log_type = LOG_TYPE_STREAM,
+    .log_read = log_console_read,
+    .log_append = log_console_append,
+    .log_walk = log_console_walk,
+    .log_flush = log_console_flush,
+    .log_rtr_erase = NULL,
+};

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/log/src/log_fcb.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log_fcb.c b/sys/log/src/log_fcb.c
index 3bfde04..a878189 100644
--- a/sys/log/src/log_fcb.c
+++ b/sys/log/src/log_fcb.c
@@ -27,10 +27,6 @@
 #include "log/log.h"
 
 static struct flash_area sector;
-struct fcb_log {
-    uint8_t fl_entries;
-    struct fcb *fl_fcb;
-} fcb_log;
 
 static int
 log_fcb_append(struct log *log, void *buf, int len)
@@ -40,8 +36,8 @@ log_fcb_append(struct log *log, void *buf, int len)
     struct fcb_log *fcb_log;
     int rc;
 
-    fcb_log = (struct fcb_log *)log->l_log->log_arg;
-    fcb = fcb_log->fl_fcb;
+    fcb_log = (struct fcb_log *)log->l_arg;
+    fcb = &fcb_log->fl_fcb;
 
     while (1) {
         rc = fcb_append(fcb, len, &loc);
@@ -106,7 +102,7 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func, void *arg)
     int rc;
 
     rc = 0;
-    fcb = ((struct fcb_log *)log->l_log->log_arg)->fl_fcb;
+    fcb = &((struct fcb_log *)log->l_arg)->fl_fcb;
 
     memset(&loc, 0, sizeof(loc));
 
@@ -122,9 +118,7 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func, void *arg)
 static int
 log_fcb_flush(struct log *log)
 {
-
-    return fcb_clear(((struct fcb_log *)log->l_log->log_arg)->fl_fcb);
-
+    return fcb_clear(&((struct fcb_log *)log->l_arg)->fl_fcb);
 }
 
 /**
@@ -141,7 +135,6 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
     int dlen;
     int rc;
     struct fcb *fcb_tmp;
-    uint8_t entries_tmp;
 
     rc = log_fcb_read(log, entry, &ueh, 0, sizeof(ueh));
     if (rc != sizeof(ueh)) {
@@ -157,11 +150,9 @@ 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;
+    fcb_tmp = &((struct fcb_log *)log->l_arg)->fl_fcb;
 
-    rc = log_fcb_handler_init(log->l_log, dst_fcb, 0);
+    rc = log_register(log->l_name, log, &log_fcb_handler, dst_fcb);
     if (rc) {
         goto err;
     }
@@ -171,7 +162,7 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
         goto err;
     }
 
-    rc = log_fcb_handler_init(log->l_log, fcb_tmp, entries_tmp);
+    rc = log_register(log->l_name, log, &log_fcb_handler, fcb_tmp);
     if (rc) {
         goto err;
     }
@@ -232,7 +223,7 @@ log_fcb_rtr_erase(struct log *log, void *arg)
     }
 
     fcb_log = (struct fcb_log *)arg;
-    fcb = fcb_log->fl_fcb;
+    fcb = (struct fcb *)fcb_log;
 
     memset(&fcb_scratch, 0, sizeof(fcb_scratch));
 
@@ -243,7 +234,7 @@ log_fcb_rtr_erase(struct log *log, void *arg)
     fcb_scratch.f_sectors = &sector;
     fcb_scratch.f_sector_cnt = 1;
     fcb_scratch.f_magic = 0x7EADBADF;
-    fcb_scratch.f_version = 0;
+    fcb_scratch.f_version = g_log_info.li_version;
 
     flash_area_erase(&sector, 0, sector.fa_size);
     rc = fcb_init(&fcb_scratch);
@@ -276,20 +267,13 @@ err:
     return (rc);
 }
 
-int
-log_fcb_handler_init(struct log_handler *handler, struct fcb *fcb, uint8_t entries)
-{
-    handler->log_type = LOG_TYPE_STORAGE;
-    handler->log_read = log_fcb_read;
-    handler->log_append = log_fcb_append;
-    handler->log_walk = log_fcb_walk;
-    handler->log_flush = log_fcb_flush;
-    handler->log_rtr_erase = log_fcb_rtr_erase;
-    fcb_log.fl_entries = entries;
-    fcb_log.fl_fcb = fcb;
-    handler->log_arg = &fcb_log;
-
-    return 0;
-}
+const struct log_handler log_fcb_handler = {
+    .log_type = LOG_TYPE_STORAGE,
+    .log_read = log_fcb_read,
+    .log_append = log_fcb_append,
+    .log_walk = log_fcb_walk,
+    .log_flush = log_fcb_flush,
+    .log_rtr_erase = log_fcb_rtr_erase,
+};
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/log/src/test/log_test.c
----------------------------------------------------------------------
diff --git a/sys/log/src/test/log_test.c b/sys/log/src/test/log_test.c
index 7230686..14c1b8b 100644
--- a/sys/log/src/test/log_test.c
+++ b/sys/log/src/test/log_test.c
@@ -33,7 +33,6 @@ static struct flash_area fcb_areas[] = {
         .fa_size = 16 * 1024
     }
 };
-static struct log_handler log_fcb_handler;
 static struct fcb log_fcb;
 static struct log my_log;
 
@@ -61,10 +60,8 @@ TEST_CASE(log_setup_fcb)
     }
     rc = fcb_init(&log_fcb);
     TEST_ASSERT(rc == 0);
-    rc = log_fcb_handler_init(&log_fcb_handler, &log_fcb, 0);
-    TEST_ASSERT(rc == 0);
 
-    log_register("log", &my_log, &log_fcb_handler);
+    log_register("log", &my_log, &log_fcb_handler, &log_fcb);
 }
 
 TEST_CASE(log_append_fcb)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/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 a59c772..f3d84a4 100644
--- a/sys/reboot/include/reboot/log_reboot.h
+++ b/sys/reboot/include/reboot/log_reboot.h
@@ -29,7 +29,7 @@
     (GEN_CORE     == reason ? "GEN_CORE" :\
      "UNKNOWN")))
 
-int reboot_init_handler(int log_type, uint8_t entries);
+int reboot_init_handler(int log_store_type, uint8_t entries);
 int log_reboot(int reason);
 
 #endif /* _LOG_REBOOT_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd3fbfe/sys/reboot/src/log_reboot.c
----------------------------------------------------------------------
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index 470d300..8eff1e3 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -35,8 +35,7 @@
 #include <shell/shell.h>
 #endif
 
-static struct log_handler reboot_log_handler;
-static struct fcb fcb;
+static struct log_handler *reboot_log_handler;
 static struct log reboot_log;
 static uint16_t reboot_cnt;
 static uint16_t soft_reboot;
@@ -46,6 +45,8 @@ 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 struct flash_area sector;
 
+static struct fcb_log reboot_log_fcb;
+
 struct conf_handler reboot_conf_handler = {
     .ch_name = "reboot",
     .ch_get = reboot_cnt_get,
@@ -60,44 +61,46 @@ struct conf_handler reboot_conf_handler = {
  * @return 0 on success; non-zero on failure
  */
 int
-reboot_init_handler(int log_type, uint8_t entries)
+reboot_init_handler(int log_store_type, uint8_t entries)
 {
     int rc;
     const struct flash_area *ptr;
+    struct fcb *fcbp = &reboot_log_fcb.fl_fcb;
 
     rc = conf_register(&reboot_conf_handler);
 
-    switch (log_type) {
-        case LOG_TYPE_STORAGE:
+    switch (log_store_type) {
+        case LOG_STORE_FCB:
             if (flash_area_open(FLASH_AREA_REBOOT_LOG, &ptr)) {
                 goto err;
             }
             sector = *ptr;
-            fcb.f_sectors = &sector;
-            fcb.f_sector_cnt = 1;
-            fcb.f_magic = 0x7EADBADF;
-            fcb.f_version = 0;
+            fcbp->f_sectors = &sector;
+            fcbp->f_sector_cnt = 1;
+            fcbp->f_magic = 0x7EADBADF;
+            fcbp->f_version = g_log_info.li_version;
+
+            reboot_log_fcb.fl_entries = entries;
 
-            rc = fcb_init(&fcb);
+            rc = fcb_init(fcbp);
             if (rc) {
                 goto err;
             }
-            rc = log_fcb_handler_init(&reboot_log_handler, &fcb, entries);
+            reboot_log_handler = (struct log_handler *)&log_fcb_handler;
             if (rc) {
                 goto err;
             }
             break;
-       case LOG_TYPE_STREAM:
-            rc = log_console_handler_init(&reboot_log_handler);
-            if (rc) {
-                goto err;
-            }
+       case LOG_STORE_CONSOLE:
+            reboot_log_handler = (struct log_handler *)&log_console_handler;
             break;
        default:
             assert(0);
     }
 
-    rc = log_register("reboot_log", &reboot_log, &reboot_log_handler);
+    rc = log_register("reboot_log", &reboot_log,
+                      (struct log_handler *)reboot_log_handler,
+                      &reboot_log_fcb);
 err:
     return (rc);
 }


[2/4] incubator-mynewt-core git commit: Change logging format to use 16-bit index.

Posted by cc...@apache.org.
Change logging format to use 16-bit index.

Initialize g_log_info struct with current version.

For MYNEWT-368


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/42048f48
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/42048f48
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/42048f48

Branch: refs/heads/develop
Commit: 42048f4887e4b5cdb062e5dab8405f9e31e5bc9f
Parents: 2d7ed71
Author: Peter Snyder <gi...@peterfs.com>
Authored: Thu Sep 1 17:45:02 2016 -0700
Committer: Peter Snyder <gi...@peterfs.com>
Committed: Wed Sep 7 19:47:36 2016 -0700

----------------------------------------------------------------------
 sys/log/src/log.c | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/42048f48/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index 23bb83a..c2c9ee5 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -58,6 +58,10 @@ log_init(void)
     }
     log_inited = 1;
 
+    g_log_info.li_version = LOG_VERSION_V2;
+    g_log_info.li_index = 0;
+    g_log_info.li_timestamp = 0;
+
 #ifdef SHELL_PRESENT
     shell_cmd_register(&g_shell_log_cmd);
 #endif


[4/4] incubator-mynewt-core git commit: This closes #104 Merge remote-tracking branch 'peterfs/logfix' into develop

Posted by cc...@apache.org.
This closes #104
Merge remote-tracking branch 'peterfs/logfix' into develop

* peterfs/logfix:
  Logging format and initialization
  Change logging format to use 16-bit index.
  Change logging format to use 16-bit log index.


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/7f28def4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7f28def4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7f28def4

Branch: refs/heads/develop
Commit: 7f28def4249f896ee8d71ba997cedf8430117797
Parents: 260a90e 1fd3fbf
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Sep 7 19:52:24 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Sep 7 19:52:24 2016 -0700

----------------------------------------------------------------------
 apps/blecent/src/main.c                |  4 +--
 apps/bleprph/src/main.c                |  4 +--
 apps/bletiny/src/main.c                |  4 +--
 apps/ffs2native/src/main.c             |  4 +--
 apps/slinky/src/main.c                 | 12 ++++---
 apps/splitty/src/main.c                |  4 +--
 fs/nffs/src/nffs.c                     |  7 ++--
 fs/nffs/src/nffs_priv.h                |  4 +--
 libs/console/full/src/prompt.c         |  2 +-
 net/nimble/host/src/ble_hs.c           |  5 +--
 sys/fcb/include/fcb/fcb.h              | 10 ++++++
 sys/log/include/log/log.h              | 29 ++++++++++-------
 sys/log/src/log.c                      | 26 ++++++++-------
 sys/log/src/log_cbmem.c                | 33 +++++++------------
 sys/log/src/log_console.c              | 26 +++++----------
 sys/log/src/log_fcb.c                  | 50 ++++++++++-------------------
 sys/log/src/test/log_test.c            |  5 +--
 sys/reboot/include/reboot/log_reboot.h |  2 +-
 sys/reboot/src/log_reboot.c            | 37 +++++++++++----------
 19 files changed, 121 insertions(+), 147 deletions(-)
----------------------------------------------------------------------