Skip to content

Allow for selective deferment of device initialization (aka manual init) #39896

@palchak-google

Description

@palchak-google

Is your enhancement proposal related to a problem? Please describe.
Zephyr currently assumes that all devices available in the system should be automatically initialized at boot. This assumption does not account for the the following common embedded scenarios:

  • Multiple devices share a common resource, such as a set of GPIO pins, and only one device is ever enabled/active at a time depending on some runtime state. A example of this would be having a SPI master controller and a SPI slave controller configured to the use the same pins, and the system dynamically changes which controller to activate based on a separate control signal.
  • The power source for the system may not always be capable of supporting the entire system load. The system needs to boot first with a minimal set of devices enabled, determine the current power state, and then selectively enable additional devices as appropriate.

Describe the solution you'd like
Add an optional parameter to the Devicetree bindings for device nodes that allows application developers to specify whether initialization for that device should be deferred. This information should be stored in the init_entry struct for each device and checked in the z_sys_init_runlevel function before calling the init function for the device.

Devices with deferred initialization would then need to be manually initialized by the application code prior to use; Zephyr would provide a system call for manually invoking a device's initialization function (after checking that the device was not already initialized).

Describe alternatives you've considered
An alternative solution would be to add a "deferred" status enumeration for devices, alongside "okay" and "disabled". This status indication would serve the same purpose as described above, namely inhibiting automatic boot-time execution of the device's initialization function. At compile time the build system could also check if any "okay" nodes appear to depend on other nodes marked as "deferred". This would help catch potential initialization defects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions