Skip to content
Introduction
- All the following content is a brief overview; those interested can research based on the prompts.
- Personal note: After starting work, I have become more mellow (laughs). Some things that would have made me very angry in the past now just make me drink some water, eat a cookie, and write something while listening to music at midnight.
- Personal email: [email protected]
- WeChat public account: Feng Zhenghao
Main Content
Controlling Driver Load Order in Linux
- In Linux driver development, there are several methods to control driver loading:
- Using loading macros such as subsys_initcall and module_init.
- Device tree dependency relationships.
- Declaring driver dependencies with MODULE_SOFTDEP.
- If the driver is built as a module (.ko), you can control the load order using startup scripts.
Implementation Principles of Loading Macros
- Interviews should have depth; during the interview, we can discuss how loading macros like subsys_initcall and module_init are implemented.
- The principle is quite simple, utilizing compiler extension syntax. If we take a closer look at the internal implementation of loading macros like subsys_initcall and module_init, they are essentially implemented by the same macro.
- This extension syntax can store specified functions in designated locations, and there are two control methods:
- Using a linker script to specify a region, and then using the extension syntax macro to store functions in that region.
- If no region is specified in the linker script, the ARM compiler has a dictionary order rule that sorts functions based on dictionary order. Those interested can refer to the map file for analysis.