Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel/os: Update device initialization condition #3043

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

kasjer
Copy link
Contributor

@kasjer kasjer commented Jul 18, 2023

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.

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 <jerzy.kasenberg@codecoup.pl>
Copy link
Contributor

@sjanc sjanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks OK to me but it would be good to maybe put some of information from commit message into code comment around g_os_dev_init_stage

@kasjer kasjer merged commit 79a45ea into apache:master Sep 25, 2023
9 checks passed
@kasjer kasjer deleted the kasjer/os_dev_init-for-mcuboot branch September 25, 2023 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants