I'm trying to create an spi Linux module. When I try to see function definition of built-in functions in the path referred in Bootlin Elixir Cross Referencer in my system, I'm unable to find the C source code file.

Can somebody tell me how to find the C source files in Ubuntu?

  • If I'm not mistaken, the source file is not included on your system because it's already compiled from the source.
    – mchid
    Mar 24 '19 at 5:11
  • "The C source" of what?
    – waltinator
    Mar 24 '19 at 5:26
  • Kernel module C source file that should have been present in drivers/spi directory
    – Vijay
    Mar 24 '19 at 6:53

To get a list of all built-in kernel modules, run the following command.

cat /lib/modules/$(uname -r)/modules.builtin 

To get a list of all built-in kernel modules containing the string spi, run the following command.

cat /lib/modules/$(uname -r)/modules.builtin | grep spi

You should expect to see some positive results from the second command showing that built-in spi kernel module(s) are installed on your system. Searching for files that end in spi.ko in Ubuntu 18.04 gives the following results, many of which are drivers, for example ethernet and touchscreen.

There are also many spi.ko files in /lib/modules/. You can use dpkg -S <path> to find out what package installed the selected spi.ko file. For example:

dpkg -S '/lib/modules/4.15.0-45-generic/kernel/drivers/iio/common/st_sensors/st_sensors_spi.ko' 

I don't type the path, instead I drag the file's icon from the file manager into the terminal and the path prints after the cursor position automatically. Results:

linux-modules-extra-4.15.0-45-generic: /lib/modules/4.15.0-45-generic/kernel/drivers/iio/common/st_sensors/st_sensors_spi.ko   

To download the source code of a package that contains a driver run the following command:

apt --download-only source <package_name>
  • I don't think you understood my question. What i want to find are the C files as mentioned in the above link rather than the .ko files.
    – Vijay
    Mar 24 '19 at 6:59
  • The Linux kernel is a monolithic Unix-like computer operating system kernel. The basic Linux Kernel is written in C and the Assembly language. Virtually all of the Linux kernel (the source of which you can find at torvalds/linux) is written in C. There are small bits of code here and there that are written in assembly language, which you can find in that source tree by looking for files whose names end in .S instead of .c. Most of these bits deal with manipulating the state of the processor in ways that the C language simply has no way to specify.
    – karel
    Mar 24 '19 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.