Skip to content

Conversation

nashif
Copy link
Member

@nashif nashif commented Jul 18, 2025

Started when I noticed soc code including kernel_internal.h. Then i started finding other oddities and misplaced code.

Cleanup of init.c which was getting overloaded with too many functions used by arch and soc code and remove unrelated declarations from kernel_internal.h which were forcing some non-kernel code to include kernel_internal.h

No functional changes, only code movements and header cleanup`

@dcpleung
Copy link
Member

Maybe time for a boot subsys? :D

zephyr_library_sources(
init.c
)
zephyr_library_sources_ifdef(CONFIG_XIP
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM. Only code style could be improved here:

zephyr_library_sources(init.c)
zephyr_library_sources_ifdef(CONFIG_XIP xip.c)

andyross
andyross previously approved these changes Jul 31, 2025
Copy link
Contributor

@andyross andyross left a comment

Choose a reason for hiding this comment

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

Looks good here. I particularly love the isolation of arch/common code, makes a lot of our memory setup initialization less confusing.

marekmatej
marekmatej previously approved these changes Jul 31, 2025
Copy link

@marekmatej marekmatej left a comment

Choose a reason for hiding this comment

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

besides a small nit looks good

@@ -2,10 +2,10 @@
* Copyright The Zephyr Project contributors
*/

#include <zephyr/sys/util.h>

Choose a reason for hiding this comment

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

just a nit, but maybe you could move this change in the previous commit

wmrsouza
wmrsouza previously approved these changes Jul 31, 2025
dcpleung
dcpleung previously approved these changes Aug 1, 2025
uLipe
uLipe previously approved these changes Aug 1, 2025
cfriedt
cfriedt previously approved these changes Aug 1, 2025
Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

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

LGTM 👍

nashif added 3 commits August 4, 2025 12:36
Not really a kernel feature, more for architecture, which is reflected
in how XIP is enabled and tested. Move it to architecture code to keep
which much of the 'implementation' and usage is.

Signed-off-by: Anas Nashif <[email protected]>
Move under arch, as this is not a kernel feature really. arch also
matches the test idcentifier in place.

Signed-off-by: Anas Nashif <[email protected]>
Move under arch, as this is not a kernel feature really. arch also
matches the test idcentifier in place.

Signed-off-by: Anas Nashif <[email protected]>
nashif added 12 commits August 4, 2025 12:36
Move under arch, as this is not a kernel feature really. arch also
matches the test idcentifier in place.

Signed-off-by: Anas Nashif <[email protected]>
Cleanup init.c code and move early boot code into arch/ and make it
accessible outside of the boot process/kernel.

All of this code is not related to the 'kernel' and is mostly used
within the architecture boot / setup process.

The way it was done, some soc code was including kernel_internal.h
directly, which shouldn't be done.

Signed-off-by: Anas Nashif <[email protected]>
No reason for this to be part of already packed init.c.
Moved to own file and build only when BOOTARGS are enabled.

Signed-off-by: Anas Nashif <[email protected]>
Cleanup kconfig of bootargs and put everything in one menuconfig.

Signed-off-by: Anas Nashif <[email protected]>
Move device model syscalls to device.c and decouple kernel header from
device related routines. Cleanup init to have only what is needed.

Signed-off-by: Anas Nashif <[email protected]>
simplify cmake file and use macros for adding files that are part of the
kernel based on the configuration.

Signed-off-by: Anas Nashif <[email protected]>
Do not use private API prefix and move to architecture interface as
those functions are primarily used across arches and can be defined by
the architecture.

Signed-off-by: Anas Nashif <[email protected]>
Do not use private API prefix and move to architecture interface as
those functions are primarily used across arches and can be defined by
the architecture.

Signed-off-by: Anas Nashif <[email protected]>
Do not use private API prefix and move to architecture interface as
those functions are primarily used across arches and can be defined by
the architecture.

Signed-off-by: Anas Nashif <[email protected]>
Do not use private API prefix and move to architecture interface as
those functions are primarily used across arches and can be defined by
the architecture.

Signed-off-by: Anas Nashif <[email protected]>
Declare z_interrupt_stacks as extern.

Signed-off-by: Anas Nashif <[email protected]>
Declare z_cstart as extern as otherwise we will need to pull in
kernel_internal.h.

Signed-off-by: Anas Nashif <[email protected]>
@nashif nashif force-pushed the topic/kernel/cleanup1 branch from 61932ec to 336804f Compare August 4, 2025 16:36
@nashif
Copy link
Member Author

nashif commented Aug 4, 2025

rebased

Copy link

sonarqubecloud bot commented Aug 4, 2025

@@ -18,6 +18,7 @@

extern void z_prep_c(void);
extern void esp_reset_reason_init(void);
extern FUNC_NORETURN void z_cstart(void);
Copy link
Contributor

Choose a reason for hiding this comment

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

With how things are currently structured, declaring z_cstart() here is not necessary as it is not called within this file. However, z_prep_c() is called, which in turn calls z_cstart(). This also applies to esp32s2 and esp32s3.

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.

9 participants