You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2023/09/25 09:49:53 UTC

[mynewt-core] branch master updated: kernel/os: Update device initialization condition

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 79a45ea33 kernel/os: Update device initialization condition
79a45ea33 is described below

commit 79a45ea33d427c9158107f077da36414217e3765
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Tue Jul 18 11:22:54 2023 +0200

    kernel/os: Update device initialization condition
    
    Function os_dev_init() is called in two places
    First possibility is when device is created in
     os_dev_create() AND g_os_started is not 0
    This apply to devices that are created after main
    function is called (including package defined syscfg
    functions).
    
    Other place that calls os_dev_init is os_dev_initialize_all()
    This function calls all os_dev_init() functions for requested
    stage. When os_dev_initalize_all() is called only devices
    added by bsp (often delegated to mcu) are created.
    Keep in mind that since g_os_started is not set yet condition is
    not checked.
    
    When mcuboot starts with sysinit() enabled it calls os_dev_initalize_all()
    twice then executes sysinit(). Any device created in sysinit() will not
    be initialized since g_os_started is not set.
    
    This change stores device init stage number and uses it when devices are
    initialized. For devices created by BSP initial stage is 0 so dev_init is
    not called during device creation but postponed till os_dev_initialize_all()
    is called (so despite condition change initialization sequence stays the same).
    
    For devices created in sysinit() stage is already set to KERNEL and they are
    initialized during creation even though g_os_started is not checked any more.
    So there should not be any differences in behavior.
    
    For MCUBoot, devices created in sysinit() will have dev_init called when created
    just like it would happen when OS_SCHEDULING is enabled.
    
    Only difference is that when device initialization fails at one stage but is not
    marked as critical initialization will be attempted in next stage.
    
    Signed-off-by: Jerzy Kasenberg <je...@codecoup.pl>
---
 kernel/os/src/os_dev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/os/src/os_dev.c b/kernel/os/src/os_dev.c
index 2e1ea3893..3260d63fd 100644
--- a/kernel/os/src/os_dev.c
+++ b/kernel/os/src/os_dev.c
@@ -22,6 +22,8 @@
 
 static STAILQ_HEAD(, os_dev) g_os_dev_list;
 
+static uint8_t g_os_dev_init_stage;
+
 static int
 os_dev_init(struct os_dev *dev, const char *name, uint8_t stage,
         uint8_t priority, os_dev_init_func_t od_init, void *arg)
@@ -126,7 +128,7 @@ os_dev_create(struct os_dev *dev, const char *name, uint8_t stage,
         goto err;
     }
 
-    if (g_os_started) {
+    if (g_os_dev_init_stage >= stage && (dev->od_flags & OS_DEV_F_STATUS_READY) == 0) {
         rc = os_dev_initialize(dev);
     }
 err:
@@ -139,8 +141,9 @@ os_dev_initialize_all(uint8_t stage)
     struct os_dev *dev;
     int rc = 0;
 
+    g_os_dev_init_stage = stage;
     STAILQ_FOREACH(dev, &g_os_dev_list, od_next) {
-        if (dev->od_stage == stage) {
+        if ((dev->od_flags & OS_DEV_F_STATUS_READY) == 0 && dev->od_stage <= stage) {
             rc = os_dev_initialize(dev);
             if (rc) {
                 break;