Skip to content

Commit 0ae0c3d

Browse files
dewitt-garminnashif
authored andcommittedMar 19, 2025·
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>
1 parent da867db commit 0ae0c3d

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed
 

‎cmake/modules/extensions.cmake

+7-2
Original file line numberDiff line numberDiff line change
@@ -5240,8 +5240,8 @@ endfunction()
52405240
# This is useful content such as struct devices.
52415241
#
52425242
# For example: zephyr_linker_section_obj_level(SECTION init LEVEL PRE_KERNEL_1)
5243-
# will create an input section matching `.z_init_PRE_KERNEL_1_?_` and
5244-
# `.z_init_PRE_KERNEL_1_??_`.
5243+
# will create an input section matching `.z_init_PRE_KERNEL_1_?_`,
5244+
# `.z_init_PRE_KERNEL_1_??_`, and `.z_init_PRE_KERNEL_1_???_`.
52455245
#
52465246
# SECTION <section>: Section in which the objects shall be placed
52475247
# LEVEL <level> : Priority level, all input sections matching the level
@@ -5274,6 +5274,11 @@ function(zephyr_linker_section_obj_level)
52745274
INPUT ".z_${OBJ_SECTION}_${OBJ_LEVEL}_??_*"
52755275
KEEP SORT NAME
52765276
)
5277+
zephyr_linker_section_configure(
5278+
SECTION ${OBJ_SECTION}
5279+
INPUT ".z_${OBJ_SECTION}_${OBJ_LEVEL}_???_*"
5280+
KEEP SORT NAME
5281+
)
52775282
endfunction()
52785283

52795284
# Usage:

‎doc/kernel/drivers/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ initialization levels:
366366

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

‎include/zephyr/init.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern "C" {
4141
* - `SMP`: Only available if @kconfig{CONFIG_SMP} is enabled, specific for
4242
* SMP.
4343
*
44-
* Initialization priority can take a value in the range of 0 to 99.
44+
* Initialization priority can take a value in the range of 0 to 999.
4545
*
4646
* @note The same infrastructure is used by devices.
4747
* @{

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
#define CREATE_OBJ_LEVEL(object, level) \
4949
__##object##_##level##_start = .; \
5050
KEEP(*(SORT(.z_##object##_##level##_?_*))); \
51-
KEEP(*(SORT(.z_##object##_##level##_??_*)));
51+
KEEP(*(SORT(.z_##object##_##level##_??_*))); \
52+
KEEP(*(SORT(.z_##object##_##level##_???_*)));
5253
/* clang-format on */
5354

5455
/*

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,11 @@ SYS_INIT_NAMED(init1, init_fn, APPLICATION, 1);
271271
SYS_INIT_NAMED(init2, init_fn, APPLICATION, 2);
272272
SYS_INIT_NAMED(init3, init_fn, APPLICATION, 2);
273273
SYS_INIT_NAMED(init4, init_fn, APPLICATION, 99);
274+
SYS_INIT_NAMED(init5, init_fn, APPLICATION, 999);
274275

275276
ZTEST(device, test_sys_init_multiple)
276277
{
277-
zassert_equal(sys_init_counter, 5, "");
278+
zassert_equal(sys_init_counter, 6, "");
278279
}
279280

280281
/* this is for storing sequence during initialization */

0 commit comments

Comments
 (0)
Please sign in to comment.