Controlling Driver Load Order in ByteDance BSP Interviews

Introduction

  1. All the following content is a brief overview; those interested can research based on the prompts.
  2. 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.
  3. Personal email: [email protected]
  4. WeChat public account: Feng Zhenghao

Main Content

Controlling Driver Load Order in Linux

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

  1. Interviews should have depth; during the interview, we can discuss how loading macros like subsys_initcall and module_init are implemented.
  2. 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.
  3. 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.

Leave a Comment