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>
This commit is contained in:
Josh DeWitt 2025-03-12 11:29:01 -05:00 committed by Anas Nashif
commit 0ae0c3dc44
5 changed files with 13 additions and 6 deletions

View file

@ -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)
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:

View file

@ -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.

View file

@ -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.
* @{

View file

@ -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 */
/*

View file

@ -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 */