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/11/30 23:54:23 UTC
[1/2] incubator-mynewt-core git commit: MYNEWT-491 Prevent repeated
package initialization
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 13fd07eff -> 265f67019
MYNEWT-491 Prevent repeated package initialization
A function can ensure it only gets called during system initialization
by invoking the SYSINIT_ASSERT_ACTIVE() macro. If the function gets
called outside of sysinit, a failed assert is triggered.
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/259c6704
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/259c6704
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/259c6704
Branch: refs/heads/develop
Commit: 259c670486422dd9beb891d403e700af08189eb6
Parents: 13fd07e
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Nov 30 14:44:34 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Nov 30 15:45:06 2016 -0800
----------------------------------------------------------------------
boot/split/src/split.c | 4 +++
fs/fatfs/src/mynewt_glue.c | 4 +++
fs/nffs/src/nffs.c | 3 ++
kernel/os/src/os.c | 3 ++
mgmt/imgmgr/src/imgmgr.c | 3 ++
mgmt/newtmgr/src/newtmgr.c | 3 ++
mgmt/newtmgr/transport/ble/src/newtmgr_ble.c | 3 ++
.../transport/nmgr_shell/src/nmgr_shell.c | 4 +++
.../newtmgr/transport/nmgr_uart/src/nmgr_uart.c | 4 +++
mgmt/oicmgr/src/oicmgr.c | 3 ++
net/ip/native_sockets/src/native_sock.c | 4 +++
net/nimble/controller/src/ble_ll.c | 3 ++
net/nimble/host/services/ans/src/ble_svc_ans.c | 3 ++
net/nimble/host/services/bleuart/src/bleuart.c | 3 ++
net/nimble/host/services/gap/src/ble_svc_gap.c | 3 ++
.../host/services/gatt/src/ble_svc_gatt.c | 3 ++
net/nimble/host/services/ias/src/ble_svc_ias.c | 3 ++
net/nimble/host/services/tps/src/ble_svc_tps.c | 3 ++
net/nimble/host/src/ble_hs.c | 3 ++
net/nimble/host/store/ram/src/ble_store_ram.c | 4 +++
net/nimble/transport/ram/src/ble_hci_ram.c | 3 ++
net/nimble/transport/uart/src/ble_hci_uart.c | 6 +++-
sys/config/src/config_init.c | 3 ++
sys/console/full/src/cons_tty.c | 3 ++
sys/flash_map/src/flash_map.c | 3 ++
sys/id/src/id.c | 3 ++
sys/log/src/log.c | 3 ++
sys/mfg/src/mfg.c | 4 +++
sys/reboot/src/log_reboot.c | 3 ++
sys/shell/src/shell.c | 3 ++
sys/stats/src/stats.c | 3 ++
sys/sysinit/include/sysinit/sysinit.h | 33 ++++++++++++++++++--
test/crash_test/src/crash_test.c | 4 +++
test/runtest/src/runtest.c | 4 +++
34 files changed, 140 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/boot/split/src/split.c
----------------------------------------------------------------------
diff --git a/boot/split/src/split.c b/boot/split/src/split.c
index c7aae93..b29a627 100644
--- a/boot/split/src/split.c
+++ b/boot/split/src/split.c
@@ -18,6 +18,7 @@
*/
#include <assert.h>
+#include "sysinit/sysinit.h"
#include "defs/error.h"
#include "bootutil/bootutil.h"
#include "bootutil/image.h"
@@ -37,6 +38,9 @@ split_app_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = split_conf_init();
assert(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/fs/fatfs/src/mynewt_glue.c
----------------------------------------------------------------------
diff --git a/fs/fatfs/src/mynewt_glue.c b/fs/fatfs/src/mynewt_glue.c
index 06db816..c1dde99 100644
--- a/fs/fatfs/src/mynewt_glue.c
+++ b/fs/fatfs/src/mynewt_glue.c
@@ -1,4 +1,5 @@
#include <assert.h>
+#include <sysinit/sysinit.h>
#include <hal/hal_flash.h>
#include <flash_map/flash_map.h>
#include <stdio.h>
@@ -400,5 +401,8 @@ get_fattime(void)
void
fatfs_pkg_init(void)
{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
fs_register(&fatfs_ops);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/fs/nffs/src/nffs.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs.c b/fs/nffs/src/nffs.c
index 4386416..8f25cb5 100644
--- a/fs/nffs/src/nffs.c
+++ b/fs/nffs/src/nffs.c
@@ -747,6 +747,9 @@ nffs_pkg_init(void)
int cnt;
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
/* Initialize nffs's internal state. */
rc = nffs_init();
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/kernel/os/src/os.c
----------------------------------------------------------------------
diff --git a/kernel/os/src/os.c b/kernel/os/src/os.c
index a6b7748..c313a26 100644
--- a/kernel/os/src/os.c
+++ b/kernel/os/src/os.c
@@ -194,6 +194,9 @@ os_start(void)
void
os_pkg_init(void)
{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
os_msys_init();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/mgmt/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr.c b/mgmt/imgmgr/src/imgmgr.c
index 2a64bc1..1ca37a0 100644
--- a/mgmt/imgmgr/src/imgmgr.c
+++ b/mgmt/imgmgr/src/imgmgr.c
@@ -397,6 +397,9 @@ imgmgr_module_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = mgmt_group_register(&imgr_nmgr_group);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/mgmt/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/src/newtmgr.c b/mgmt/newtmgr/src/newtmgr.c
index 465751a..b57d0a3 100644
--- a/mgmt/newtmgr/src/newtmgr.c
+++ b/mgmt/newtmgr/src/newtmgr.c
@@ -370,6 +370,9 @@ nmgr_pkg_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = nmgr_task_init();
SYSINIT_PANIC_ASSERT(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c b/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
index 7e8e749..72c8a24 100644
--- a/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
+++ b/mgmt/newtmgr/transport/ble/src/newtmgr_ble.c
@@ -234,6 +234,9 @@ newtmgr_ble_pkg_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = nmgr_ble_gatt_svr_init();
SYSINIT_PANIC_ASSERT(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/mgmt/newtmgr/transport/nmgr_shell/src/nmgr_shell.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/transport/nmgr_shell/src/nmgr_shell.c b/mgmt/newtmgr/transport/nmgr_shell/src/nmgr_shell.c
index 2615d53..3ae170b 100644
--- a/mgmt/newtmgr/transport/nmgr_shell/src/nmgr_shell.c
+++ b/mgmt/newtmgr/transport/nmgr_shell/src/nmgr_shell.c
@@ -19,6 +19,7 @@
#include <inttypes.h>
#include <assert.h>
+#include <sysinit/sysinit.h>
#include <shell/shell.h>
#include <mgmt/mgmt.h>
#include <newtmgr/newtmgr.h>
@@ -57,6 +58,9 @@ nmgr_shell_pkg_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = nmgr_transport_init(&nmgr_shell_transport, nmgr_shell_out,
nmgr_shell_get_mtu);
assert(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
index 17c7b8e..adb7e37 100644
--- a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
+++ b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c
@@ -20,6 +20,7 @@
#include <assert.h>
#include <syscfg/syscfg.h>
+#include <sysinit/sysinit.h>
#include <bsp/bsp.h>
#include <os/os.h>
@@ -358,6 +359,9 @@ nmgr_uart_pkg_init(void)
.uc_cb_arg = nus
};
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = nmgr_transport_init(&nus->nus_transport, nmgr_uart_out, nmgr_uart_mtu);
assert(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index e084caf..e66c4ed 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -232,6 +232,9 @@ oicmgr_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = nmgr_os_groups_register();
if (rc != 0) {
goto err;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/ip/native_sockets/src/native_sock.c
----------------------------------------------------------------------
diff --git a/net/ip/native_sockets/src/native_sock.c b/net/ip/native_sockets/src/native_sock.c
index a4049f4..9e2d3d6 100644
--- a/net/ip/native_sockets/src/native_sock.c
+++ b/net/ip/native_sockets/src/native_sock.c
@@ -27,6 +27,7 @@
#include <sys/ioctl.h>
#include <stdio.h>
+#include <sysinit/sysinit.h>
#include <os/os.h>
#include <os/os_mbuf.h>
#include "mn_socket/mn_socket.h"
@@ -729,6 +730,9 @@ native_sock_init(void)
int i;
os_stack_t *sp;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
for (i = 0; i < NATIVE_SOCK_MAX; i++) {
native_socks[i].ns_fd = -1;
STAILQ_INIT(&native_socks[i].ns_rx);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index b65aba4..63b3cac 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -1217,6 +1217,9 @@ ble_ll_init(void)
uint8_t features;
struct ble_ll_obj *lldata;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
/* Get pointer to global data object */
lldata = &g_ble_ll_data;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/host/services/ans/src/ble_svc_ans.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ans/src/ble_svc_ans.c b/net/nimble/host/services/ans/src/ble_svc_ans.c
index 249e2f5..ca4ee8a 100644
--- a/net/nimble/host/services/ans/src/ble_svc_ans.c
+++ b/net/nimble/host/services/ans/src/ble_svc_ans.c
@@ -445,6 +445,9 @@ ble_svc_ans_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = ble_gatts_count_cfg(ble_svc_ans_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/host/services/bleuart/src/bleuart.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/bleuart/src/bleuart.c b/net/nimble/host/services/bleuart/src/bleuart.c
index 826f282..3c26ffc 100644
--- a/net/nimble/host/services/bleuart/src/bleuart.c
+++ b/net/nimble/host/services/bleuart/src/bleuart.c
@@ -193,6 +193,9 @@ bleuart_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = console_init(bleuart_uart_read);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/host/services/gap/src/ble_svc_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gap/src/ble_svc_gap.c b/net/nimble/host/services/gap/src/ble_svc_gap.c
index 92f3c32..e0ccd7c 100644
--- a/net/nimble/host/services/gap/src/ble_svc_gap.c
+++ b/net/nimble/host/services/gap/src/ble_svc_gap.c
@@ -155,6 +155,9 @@ ble_svc_gap_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = ble_gatts_count_cfg(ble_svc_gap_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/host/services/gatt/src/ble_svc_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/gatt/src/ble_svc_gatt.c b/net/nimble/host/services/gatt/src/ble_svc_gatt.c
index d0e2f12..340e7cc 100644
--- a/net/nimble/host/services/gatt/src/ble_svc_gatt.c
+++ b/net/nimble/host/services/gatt/src/ble_svc_gatt.c
@@ -77,6 +77,9 @@ ble_svc_gatt_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = ble_gatts_count_cfg(ble_svc_gatt_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/host/services/ias/src/ble_svc_ias.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/ias/src/ble_svc_ias.c b/net/nimble/host/services/ias/src/ble_svc_ias.c
index 4af6936..5644ccd 100644
--- a/net/nimble/host/services/ias/src/ble_svc_ias.c
+++ b/net/nimble/host/services/ias/src/ble_svc_ias.c
@@ -136,6 +136,9 @@ ble_svc_ias_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = ble_gatts_count_cfg(ble_svc_ias_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/host/services/tps/src/ble_svc_tps.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/tps/src/ble_svc_tps.c b/net/nimble/host/services/tps/src/ble_svc_tps.c
index 6987a5d..74c2df4 100644
--- a/net/nimble/host/services/tps/src/ble_svc_tps.c
+++ b/net/nimble/host/services/tps/src/ble_svc_tps.c
@@ -96,6 +96,9 @@ ble_svc_tps_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = ble_gatts_count_cfg(ble_svc_tps_defs);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/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 9754a6d..b55dc2c 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -539,6 +539,9 @@ ble_hs_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
log_init();
/* Create memory pool of OS events */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/host/store/ram/src/ble_store_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/store/ram/src/ble_store_ram.c b/net/nimble/host/store/ram/src/ble_store_ram.c
index b346f14..e899a46 100644
--- a/net/nimble/host/store/ram/src/ble_store_ram.c
+++ b/net/nimble/host/store/ram/src/ble_store_ram.c
@@ -26,6 +26,7 @@
#include <inttypes.h>
#include <string.h>
+#include "sysinit/sysinit.h"
#include "host/ble_hs.h"
#include "store/ram/ble_store_ram.h"
@@ -375,6 +376,9 @@ ble_store_ram_write(int obj_type, union ble_store_value *val)
void
ble_store_ram_init(void)
{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
ble_hs_cfg.store_read_cb = ble_store_ram_read;
ble_hs_cfg.store_write_cb = ble_store_ram_write;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/transport/ram/src/ble_hci_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/src/ble_hci_ram.c b/net/nimble/transport/ram/src/ble_hci_ram.c
index 6c34a52..1c0cc6a 100644
--- a/net/nimble/transport/ram/src/ble_hci_ram.c
+++ b/net/nimble/transport/ram/src/ble_hci_ram.c
@@ -245,6 +245,9 @@ ble_hci_ram_pkg_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = ble_hci_ram_init();
SYSINIT_PANIC_ASSERT(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/net/nimble/transport/uart/src/ble_hci_uart.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/src/ble_hci_uart.c b/net/nimble/transport/uart/src/ble_hci_uart.c
index 87da7b5..1ace2b0 100755
--- a/net/nimble/transport/uart/src/ble_hci_uart.c
+++ b/net/nimble/transport/uart/src/ble_hci_uart.c
@@ -22,8 +22,9 @@
#include <stdio.h>
#include <errno.h>
#include <stdint.h>
-#include "os/os_cputime.h"
+#include "sysinit/sysinit.h"
#include "syscfg/syscfg.h"
+#include "os/os_cputime.h"
#include "bsp/bsp.h"
#include "os/os.h"
#include "mem/mem.h"
@@ -965,6 +966,9 @@ ble_hci_uart_init(void)
int acl_block_size;
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
ble_hci_uart_free_mem();
/*
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/config/src/config_init.c
----------------------------------------------------------------------
diff --git a/sys/config/src/config_init.c b/sys/config/src/config_init.c
index d8f4298..53a5f25 100644
--- a/sys/config/src/config_init.c
+++ b/sys/config/src/config_init.c
@@ -94,6 +94,9 @@ config_init_fcb(void)
void
config_pkg_init(void)
{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
conf_init();
#if MYNEWT_VAL(CONFIG_NFFS)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/sys/console/full/src/cons_tty.c b/sys/console/full/src/cons_tty.c
index 3563c89..50870f1 100644
--- a/sys/console/full/src/cons_tty.c
+++ b/sys/console/full/src/cons_tty.c
@@ -566,6 +566,9 @@ console_pkg_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = console_init(NULL);
SYSINIT_PANIC_ASSERT(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/flash_map/src/flash_map.c
----------------------------------------------------------------------
diff --git a/sys/flash_map/src/flash_map.c b/sys/flash_map/src/flash_map.c
index 77a617b..b652de0 100644
--- a/sys/flash_map/src/flash_map.c
+++ b/sys/flash_map/src/flash_map.c
@@ -242,6 +242,9 @@ flash_map_init(void)
int num_areas;
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = hal_flash_init();
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/id/src/id.c
----------------------------------------------------------------------
diff --git a/sys/id/src/id.c b/sys/id/src/id.c
index 7625d29..7a964ad 100644
--- a/sys/id/src/id.c
+++ b/sys/id/src/id.c
@@ -149,6 +149,9 @@ id_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
rc = conf_register(&id_conf);
SYSINIT_PANIC_ASSERT(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/log/src/log.c
----------------------------------------------------------------------
diff --git a/sys/log/src/log.c b/sys/log/src/log.c
index 99bf704..89f2741 100644
--- a/sys/log/src/log.c
+++ b/sys/log/src/log.c
@@ -50,6 +50,9 @@ log_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
(void)rc;
if (log_inited) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/mfg/src/mfg.c
----------------------------------------------------------------------
diff --git a/sys/mfg/src/mfg.c b/sys/mfg/src/mfg.c
index 6a3fe99..4105984 100644
--- a/sys/mfg/src/mfg.c
+++ b/sys/mfg/src/mfg.c
@@ -19,6 +19,7 @@
#include <string.h>
+#include "sysinit/sysinit.h"
#include "sysflash/sysflash.h"
#include "os/os.h"
@@ -307,6 +308,9 @@ mfg_init(void)
uint16_t off;
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
if (mfg_state.valid) {
/* Already initialized. */
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/reboot/src/log_reboot.c
----------------------------------------------------------------------
diff --git a/sys/reboot/src/log_reboot.c b/sys/reboot/src/log_reboot.c
index b1869b5..0015157 100644
--- a/sys/reboot/src/log_reboot.c
+++ b/sys/reboot/src/log_reboot.c
@@ -235,6 +235,9 @@ log_reboot_pkg_init(void)
int type;
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
(void)rc;
(void)type;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/sys/shell/src/shell.c b/sys/shell/src/shell.c
index 2b11efc..166eda6 100644
--- a/sys/shell/src/shell.c
+++ b/sys/shell/src/shell.c
@@ -537,6 +537,9 @@ shell_help_cmd(int argc, char **argv)
void
shell_init(void)
{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
#if !MYNEWT_VAL(SHELL_TASK)
return;
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/stats/src/stats.c
----------------------------------------------------------------------
diff --git a/sys/stats/src/stats.c b/sys/stats/src/stats.c
index c01d037..b2009f6 100644
--- a/sys/stats/src/stats.c
+++ b/sys/stats/src/stats.c
@@ -172,6 +172,9 @@ stats_module_init(void)
{
int rc;
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
STAILQ_INIT(&g_stats_registry);
#if MYNEWT_VAL(STATS_CLI)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/sys/sysinit/include/sysinit/sysinit.h
----------------------------------------------------------------------
diff --git a/sys/sysinit/include/sysinit/sysinit.h b/sys/sysinit/include/sysinit/sysinit.h
index e7a5d11..5eb915b 100644
--- a/sys/sysinit/include/sysinit/sysinit.h
+++ b/sys/sysinit/include/sysinit/sysinit.h
@@ -31,8 +31,17 @@
extern "C" {
#endif
+extern uint8_t sysinit_active;
+
+void sysinit_start(void);
+void sysinit_end(void);
+
typedef void sysinit_panic_fn(const char *file, int line);
+/* By default, a panic triggers an assertion failure. If the project overrides
+ * the sysinit panic function setting, the specified function gets called
+ * instead.
+ */
#ifndef MYNEWT_VAL_SYSINIT_PANIC_FN
#include <assert.h>
#define SYSINIT_PANIC() assert(0)
@@ -48,12 +57,23 @@ void MYNEWT_VAL(SYSINIT_PANIC_FN)(const char *file, int line);
} \
} while (0)
+/**
+ * Asserts that system initialization is in progress. This macro is used to
+ * ensure packages don't get initialized a second time after system
+ * initialization has completed.
+ */
+#define SYSINIT_ASSERT_ACTIVE() assert(sysinit_active)
#if MYNEWT_VAL(SPLIT_LOADER)
/*** System initialization for loader (first stage of split image). */
void sysinit_loader(void);
-#define sysinit() sysinit_loader()
+#define sysinit() do \
+{ \
+ sysinit_start(); \
+ sysinit_loader(); \
+ sysinit_end(); \
+} while (0)
#elif MYNEWT_VAL(SPLIT_APPLICATION)
@@ -62,15 +82,22 @@ void sysinit_app(void);
#define sysinit() do \
{ \
/* Record that a split app is running; imgmgt needs to know this. */ \
- split_app_active_set(1); \
+ split_app_active_set(1); \
+ sysinit_start(); \
sysinit_app(); \
+ sysinit_end(); \
} while (0)
#else
/*** System initialization for a unified image (no split). */
void sysinit_app(void);
-#define sysinit() sysinit_app()
+#define sysinit() do \
+{ \
+ sysinit_start(); \
+ sysinit_app(); \
+ sysinit_end(); \
+} while (0)
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/test/crash_test/src/crash_test.c
----------------------------------------------------------------------
diff --git a/test/crash_test/src/crash_test.c b/test/crash_test/src/crash_test.c
index fa5cd8c..3b469b0 100644
--- a/test/crash_test/src/crash_test.c
+++ b/test/crash_test/src/crash_test.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <assert.h>
+#include "sysinit/sysinit.h"
#include "syscfg/syscfg.h"
#include "os/os.h"
#include "console/console.h"
@@ -65,6 +66,9 @@ crash_device(char *how)
void
crash_test_init(void)
{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
#if MYNEWT_VAL(CRASH_TEST_CLI)
shell_cmd_register(&crash_cmd_struct);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259c6704/test/runtest/src/runtest.c
----------------------------------------------------------------------
diff --git a/test/runtest/src/runtest.c b/test/runtest/src/runtest.c
index 87aaa5d..28657d0 100644
--- a/test/runtest/src/runtest.c
+++ b/test/runtest/src/runtest.c
@@ -21,6 +21,7 @@
#include <string.h>
#include <assert.h>
+#include "sysinit/sysinit.h"
#include "syscfg/syscfg.h"
#include "os/os.h"
#include "console/console.h"
@@ -49,6 +50,9 @@ runtest()
void
runtest_init(void)
{
+ /* Ensure this function only gets called by sysinit. */
+ SYSINIT_ASSERT_ACTIVE();
+
runtest_start = 1;
#if MYNEWT_VAL(RUNTEST_CLI)
[2/2] incubator-mynewt-core git commit: sys/log/test - Remove extra
log_init() call.
Posted by cc...@apache.org.
sys/log/test - Remove extra log_init() call.
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/265f6701
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/265f6701
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/265f6701
Branch: refs/heads/develop
Commit: 265f67019fa7c06e09a455572eb7045510013a01
Parents: 259c670
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Nov 30 15:37:29 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Nov 30 15:47:43 2016 -0800
----------------------------------------------------------------------
sys/log/test/src/log_test.c | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/265f6701/sys/log/test/src/log_test.c
----------------------------------------------------------------------
diff --git a/sys/log/test/src/log_test.c b/sys/log/test/src/log_test.c
index 1ff5069..63fa032 100644
--- a/sys/log/test/src/log_test.c
+++ b/sys/log/test/src/log_test.c
@@ -101,7 +101,6 @@ main(int argc, char **argv)
ts_config.ts_print_results = 1;
tu_init();
- log_init();
log_test_all();
return tu_any_failed;