Make Magic

Make Magic

Here's a concise breakdown of make modules_prepare, make modules, and their role in the kernel build process:


1. make modules_prepare

What it does: Prepares the kernel source tree for building loadable kernel modules (LKMs). This includes:

  • Generating headers needed for module compilation (e.g., include/generated/).
  • Creating symbolic links and configuration files (e.g., .config, Module.symvers).
  • Setting up the build environment for external modules (out-of-tree modules).

When to use it:

  • After configuring the kernel (make menuconfig, etc.) but before building modules.
  • If you’re compiling out-of-tree modules (e.g., proprietary drivers) and need the kernel headers/symbols prepped.

Example:

bash

Copy

# Configure the kernel first (e.g., via make menuconfig)
make modules_prepare  # Prepares headers and symbols for modules        

2. make modules

What it does: Compiles in-tree kernel modules (drivers/filesystems/etc. marked as =m in .config).

  • Outputs .ko (Kernel Object) files in their respective subdirectories.
  • Does not build the kernel image (vmlinux, Image, etc.).

When to use it:

  • To rebuild modules after modifying kernel configuration or module code.
  • To avoid rebuilding the entire kernel when only modules need updating.

Example:

bash

Copy

make modules  # Compiles modules (*.ko files)        

3. Full Kernel Build (make or make all)

What it does: Builds both:

  • The kernel image (e.g., vmlinux, Image.gz, or bzImage).
  • All in-tree modules (equivalent to make modules).

When to use it:

  • For a fresh kernel build.
  • After major configuration changes affecting the kernel image.

Example:

bash

Copy

make  # Builds kernel image + modules        



Why They’re Necessary

  1. Efficiency:
  2. Out-of-Tree Modules:
  3. Separation of Concerns:


Typical Workflow

  1. Configure the kernel:
  2. Build the kernel image and modules:
  3. OR, for incremental module work:


Key Takeaways

  • Use make for full kernel builds.
  • Use make modules to save time when only modules need rebuilding.
  • Use make modules_prepare to set up headers for external modules.

This separation streamlines development, especially when working with drivers or embedded systems! ??

要查看或添加评论,请登录

David Zhu的更多文章

社区洞察

其他会员也浏览了