WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] drivers: how to find kernel built-ins?  (Read 6551 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
[Solved] drivers: how to find kernel built-ins?
« on: August 10, 2020, 11:42:29 AM »
I'm running  lshw  and looking at the  driver=  field for my various hardware components. Several of the drivers seem to be loadable kernel modules because they show up in the output of  lsmod  (e.g., snd_hda_intel, ath9k, xhci_hcd). Other drivers do not show up in the output of  lsmod  so I'm assuming they are kernel built-ins (e.g., ahci, pcieport, uhci_hcd).

Is there direct way--i.e., not process of exclusion--to find out which drivers are kernel built-ins (on a running TCL11 64bit system in case it matters)?

P.S. I found this: https://superuser.com/questions/577307/how-to-get-a-list-of-active-drivers-that-are-statically-built-into-the-linux-ker but I cannot find any file named "modules.builtin" on my system. Maybe looking at the config file used to build the kernel (where "=Y" means built-in) is the only place where I'm going to find a list of built-ins?
« Last Edit: August 11, 2020, 09:03:41 AM by Rich »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: drivers: how to find kernel built-ins?
« Reply #1 on: August 10, 2020, 12:36:40 PM »
The kernel config file may be easiest.
The only barriers that can stop you are the ones you create yourself.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: drivers: how to find kernel built-ins?
« Reply #2 on: August 10, 2020, 01:03:39 PM »
Hi, curaga. I was beginning to suspect that. Thanks for confirming.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: drivers: how to find kernel built-ins?
« Reply #3 on: August 10, 2020, 01:59:27 PM »
Hi GNUser
I think that file is created when  make modules  is run. Unfortunately it does not get included in the initrd. To the best of my knowledge,
the only way to recreate it is to fetch the source and config files and run  make modules.  That will create the following files:


modules.builtin:  These modules are already built into the kernel.
modules.order:    This is the list of external modules built for this kernel. It includes their path so you know where to find them.
modules.dep:      Module dependencies. Each line contains  ModuleName:  followed by its dependencies, if any.
modules.alias:    This file can help you track down the correct driver if you know the hardwares  Vendor ID  and Product ID.
modules.symbols:  If you get  symbol not found  messages in dmesg, search for it here. It may point to a missing module.


Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: drivers: how to find kernel built-ins?
« Reply #4 on: August 10, 2020, 09:39:09 PM »
I think that file is created when  make modules  is run.
Thanks for the tip, Rich. It took a few hours on my rickety hardware, but I ran  make modules  on the kernel source (using tinycore's patches and config for TCL11 64bit) just to get my hands on those files. The resulting  modules.builtin  and  modules.order  are attached, in case anyone else wants them.

modules.dep, modules.alias, and modules.symbols didn't get created for some reason. Oh, well.
Code: [Select]
bruno@x200:~/Downloads/linux-5.4.3$ find . -name 'modules.dep'
bruno@x200:~/Downloads/linux-5.4.3$ find . -name 'modules.alias'
bruno@x200:~/Downloads/linux-5.4.3$ find . -name 'modules.symbols'
bruno@x200:~/Downloads/linux-5.4.3$

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: drivers: how to find kernel built-ins?
« Reply #5 on: August 10, 2020, 10:40:57 PM »
Hmmm, this is not what I expected: Some drivers are not found in either list (i.e., they are neither a built-in nor an external module). Here are two examples:

Code: [Select]
bruno@x200:~/Downloads/goodies$ ls
modules.builtin  modules.order
bruno@x200:~/Downloads/goodies$ grep pcieport *
bruno@x200:~/Downloads/goodies$ grep uhci_hcd *
bruno@x200:~/Downloads/goodies$
I'm confused because I thought every driver was either a "built-in" or an external module. What am I missing?
« Last Edit: August 10, 2020, 10:47:41 PM by GNUser »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: drivers: how to find kernel built-ins?
« Reply #6 on: August 10, 2020, 11:23:43 PM »
I think I understand it. It seems there are two kinds of hardware drivers on linux:

1. Drivers that are provided by the kernel itself
2. Drivers that are provided by kernel modules. When kernel is being compiled, the user can choose whether each given module is a
  2a. Built-in module (i.e., always loaded because it is statically linked to the kernel) or an
  2b. External module (i.e., only loaded when needed)

Tools such as  lsmod  and  modprobe  only deal with external modules, but /sys/module/ shows both built-in and external modules.

Does the above seem correct?

P.S. It seems that the above narrative still doesn't explain everything. If the built-in modules (i.e., those listed in the  modules.builtin  file) are always loaded, how come I only see some of them in the  /sys/module  directory?
« Last Edit: August 10, 2020, 11:47:50 PM by GNUser »

TinyCoreLinux

  • Guest
Re: drivers: how to find kernel built-ins?
« Reply #7 on: August 11, 2020, 12:37:42 AM »
In fact, I am confused about this question, but thank you for asking me this question.
I've heard that Linux kernel comes with many common basic drivers (usually these drivers may be universal), and some drivers are provided through platform software packages or library files. As for the storage location of drivers, it seems that they are not always stored in /sys/xxx.
I don't know the specific reason, maybe ask some Linux system developers, they should be the most clear.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: drivers: how to find kernel built-ins?
« Reply #8 on: August 11, 2020, 12:57:33 AM »
Hi GNUser
... modules.dep, modules.alias, and modules.symbols didn't get created for some reason. Oh, well. ...
Try this:
Code: [Select]
mkdir -p /home/tc/Downloads/modules/usr/local
make INSTALL_MOD_PATH=/home/tc/Downloads/modules/usr/local modules_install

If you execute this, you should see all 5 modules files:
Code: [Select]
ls -l /home/tc/Downloads/modules/usr/local/lib/modules/KERNEL/modules.*

Offline nick65go

  • Hero Member
  • *****
  • Posts: 839
Re: drivers: how to find kernel built-ins?
« Reply #9 on: August 11, 2020, 02:40:28 AM »
It will be very kind if the developers would provide the two list of the modules (in kernel, or external) directly on their web-site.http://tinycorelinux.net/11.x/x86_64/release/src/kernel/
I see no point to compile (run for few minutes, maybe hours on slow CPU) the module again; cost/benefit anyone?
A better solution could be (by using ash, sed, awk) to script something from /proc, /sys.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: drivers: how to find kernel built-ins?
« Reply #10 on: August 11, 2020, 03:41:12 AM »
The file has little use, it's mainly for curiosity's sake. This is the first time someone's asked for them in all this time.
The only barriers that can stop you are the ones you create yourself.

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: drivers: how to find kernel built-ins?
« Reply #11 on: August 11, 2020, 08:28:15 AM »
@Rich - That didn't work, but the main file I wanted was  modules.builtin  so it's all good.
Code: [Select]
bruno@x200:~/Downloads/linux-5.4.3$ mkdir -p /home/tc/Downloads/modules/usr/local
bruno@x200:~/Downloads/linux-5.4.3$ make INSTALL_MOD_PATH=/home/tc/Downloads/modules/usr/local modules_install
cp: can't stat './modules.builtin.modinfo': No such file or directory
make: *** [Makefile:1319: _modinst_] Error 1
Rich, what bothers me more is not understanding why many of the builtin modules (e.g., nfsv2 and nfsv3) are not loaded (i.e., I don't see them in /sys/modules). Aren't builtin modules always loaded by definition because they are statically linked into the kernel?

@TinyCoreLinux - /sys and /proc are virtual filesystems that show you what the kernel is doing at any given time. Nothing is stored there. The external modules are stored in  /lib/modules  and  /usr/local/lib/modules. The built-in modules are embedded in the kernel image, which is stored in /boot/vmlinuz[64].

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: drivers: how to find kernel built-ins?
« Reply #12 on: August 11, 2020, 08:48:19 AM »
I think I get it now. /sys/module lists all the modules that are currently loaded and active. Built-in modules are always loaded but are not always active--they spring into action only when they are actually needed (see the hypothetical built-in webcam module discussion here: https://thelastmaimou.wordpress.com/2013/07/11/listing-built-in-modules).

Good enough. Thank you all for your help and input. Thread is solved :)
« Last Edit: August 11, 2020, 08:52:03 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: [Solved] drivers: how to find kernel built-ins?
« Reply #13 on: August 11, 2020, 09:02:58 AM »
Hi GNUser
Sorry, I presumed you would be in the build directory. Did you:
Code: [Select]
cd ~/Downloads/linux-5.4.3before you ran:
Code: [Select]
make INSTALL_MOD_PATH=/home/tc/Downloads/modules/usr/local modules_installAlso, you didn't remove any files from the build directory, did you?
« Last Edit: August 11, 2020, 09:13:19 AM by Rich »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1530
Re: [Solved] drivers: how to find kernel built-ins?
« Reply #14 on: August 11, 2020, 09:10:08 AM »
Yes, I was in the build directory and I had not deleted any files.
It's too late now because after my last post I deleted everything :-\ I'm a neat freak and only kept my payload (modules.builtin and modules.order). Not a big deal.