Browse Source

linker: Allow for 999 priority levels in init levels

Some projects may have needs for more than 99 priority levels, so add
a third linker input section for each obj level.

Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
pull/87385/head
Josh DeWitt 4 months ago committed by Anas Nashif
parent
commit
0ae0c3dc44
  1. 9
      cmake/modules/extensions.cmake
  2. 2
      doc/kernel/drivers/index.rst
  3. 2
      include/zephyr/init.h
  4. 3
      include/zephyr/linker/linker-defs.h
  5. 3
      tests/kernel/device/src/main.c

9
cmake/modules/extensions.cmake

@ -5240,8 +5240,8 @@ endfunction() @@ -5240,8 +5240,8 @@ endfunction()
# This is useful content such as struct devices.
#
# For example: zephyr_linker_section_obj_level(SECTION init LEVEL PRE_KERNEL_1)
# will create an input section matching `.z_init_PRE_KERNEL_1_?_` and
# `.z_init_PRE_KERNEL_1_??_`.
# will create an input section matching `.z_init_PRE_KERNEL_1_?_`,
# `.z_init_PRE_KERNEL_1_??_`, and `.z_init_PRE_KERNEL_1_???_`.
#
# SECTION <section>: Section in which the objects shall be placed
# LEVEL <level> : Priority level, all input sections matching the level
@ -5274,6 +5274,11 @@ function(zephyr_linker_section_obj_level) @@ -5274,6 +5274,11 @@ function(zephyr_linker_section_obj_level)
INPUT ".z_${OBJ_SECTION}_${OBJ_LEVEL}_??_*"
KEEP SORT NAME
)
zephyr_linker_section_configure(
SECTION ${OBJ_SECTION}
INPUT ".z_${OBJ_SECTION}_${OBJ_LEVEL}_???_*"
KEEP SORT NAME
)
endfunction()
# Usage:

2
doc/kernel/drivers/index.rst

@ -366,7 +366,7 @@ initialization levels: @@ -366,7 +366,7 @@ initialization levels:
Within each initialization level you may specify a priority level, relative to
other devices in the same initialization level. The priority level is specified
as an integer value in the range 0 to 99; lower values indicate earlier
as an integer value in the range 0 to 999; lower values indicate earlier
initialization. The priority level must be a decimal integer literal without
leading zeroes or sign (e.g. 32), or an equivalent symbolic name (e.g.
``\#define MY_INIT_PRIO 32``); symbolic expressions are *not* permitted (e.g.

2
include/zephyr/init.h

@ -41,7 +41,7 @@ extern "C" { @@ -41,7 +41,7 @@ extern "C" {
* - `SMP`: Only available if @kconfig{CONFIG_SMP} is enabled, specific for
* SMP.
*
* Initialization priority can take a value in the range of 0 to 99.
* Initialization priority can take a value in the range of 0 to 999.
*
* @note The same infrastructure is used by devices.
* @{

3
include/zephyr/linker/linker-defs.h

@ -48,7 +48,8 @@ @@ -48,7 +48,8 @@
#define CREATE_OBJ_LEVEL(object, level) \
__##object##_##level##_start = .; \
KEEP(*(SORT(.z_##object##_##level##_?_*))); \
KEEP(*(SORT(.z_##object##_##level##_??_*)));
KEEP(*(SORT(.z_##object##_##level##_??_*))); \
KEEP(*(SORT(.z_##object##_##level##_???_*)));
/* clang-format on */
/*

3
tests/kernel/device/src/main.c

@ -271,10 +271,11 @@ SYS_INIT_NAMED(init1, init_fn, APPLICATION, 1); @@ -271,10 +271,11 @@ SYS_INIT_NAMED(init1, init_fn, APPLICATION, 1);
SYS_INIT_NAMED(init2, init_fn, APPLICATION, 2);
SYS_INIT_NAMED(init3, init_fn, APPLICATION, 2);
SYS_INIT_NAMED(init4, init_fn, APPLICATION, 99);
SYS_INIT_NAMED(init5, init_fn, APPLICATION, 999);
ZTEST(device, test_sys_init_multiple)
{
zassert_equal(sys_init_counter, 5, "");
zassert_equal(sys_init_counter, 6, "");
}
/* this is for storing sequence during initialization */

Loading…
Cancel
Save