How to build kernel module from source?

I have the 5.6.2 kernel (from the official Fedora repository) and even though it’s been reported it should contain a new CPU driver (cpu-idle-cooling) it does not have it, in binary or source. I downloaded the 5.6.2 source from Kernel.org and it does have it, I want to build that module and add it to my current Fedora setup.

When I go to the root of the extracted source archive and run:
When I go to the root of the extracted source archive and run:

make oldconfig

make prepare

make scripts

These don’t print any warning or errors. The cpu idle cooling driver is in ./drivers/thermal. Then:

make M=drivers/thermal

I get:

AR drivers/thermal/broadcom/built-in.a
AR drivers/thermal/samsung/built-in.a
CC [M] drivers/thermal/intel/int340x_thermal/int3400_thermal.o
CC [M] drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.o
CC [M] drivers/thermal/intel/int340x_thermal/int3402_thermal.o
CC [M] drivers/thermal/intel/int340x_thermal/int3403_thermal.o
CC [M] drivers/thermal/intel/int340x_thermal/processor_thermal_device.o
CC [M] drivers/thermal/intel/int340x_thermal/int3406_thermal.o
CC [M] drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.o
AR drivers/thermal/intel/built-in.a
CC [M] drivers/thermal/intel/intel_powerclamp.o
CC [M] drivers/thermal/intel/x86_pkg_temp_thermal.o
CC [M] drivers/thermal/intel/intel_soc_dts_iosf.o
CC [M] drivers/thermal/intel/intel_soc_dts_thermal.o
CC [M] drivers/thermal/intel/intel_bxt_pmic_thermal.o
CC [M] drivers/thermal/intel/intel_pch_thermal.o
AR drivers/thermal/st/built-in.a
AR drivers/thermal/tegra/built-in.a
CC drivers/thermal/thermal_core.o
CC drivers/thermal/thermal_sysfs.o
CC drivers/thermal/thermal_helpers.o
CC drivers/thermal/thermal_hwmon.o
CC drivers/thermal/fair_share.o
CC drivers/thermal/gov_bang_bang.o
CC drivers/thermal/step_wise.o
CC drivers/thermal/user_space.o
AR drivers/thermal/built-in.a

WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.

MODPOST 13 modules
CC [M] drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.mod.o
LD [M] drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.ko
CC [M] drivers/thermal/intel/int340x_thermal/int3400_thermal.mod.o
LD [M] drivers/thermal/intel/int340x_thermal/int3400_thermal.ko
CC [M] drivers/thermal/intel/int340x_thermal/int3402_thermal.mod.o
LD [M] drivers/thermal/intel/int340x_thermal/int3402_thermal.ko
CC [M] drivers/thermal/intel/int340x_thermal/int3403_thermal.mod.o
LD [M] drivers/thermal/intel/int340x_thermal/int3403_thermal.ko
CC [M] drivers/thermal/intel/int340x_thermal/int3406_thermal.mod.o
LD [M] drivers/thermal/intel/int340x_thermal/int3406_thermal.ko
CC [M] drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.mod.o
LD [M] drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.ko
CC [M] drivers/thermal/intel/int340x_thermal/processor_thermal_device.mod.o
LD [M] drivers/thermal/intel/int340x_thermal/processor_thermal_device.ko
CC [M] drivers/thermal/intel/intel_bxt_pmic_thermal.mod.o
LD [M] drivers/thermal/intel/intel_bxt_pmic_thermal.ko
CC [M] drivers/thermal/intel/intel_pch_thermal.mod.o
LD [M] drivers/thermal/intel/intel_pch_thermal.ko
CC [M] drivers/thermal/intel/intel_powerclamp.mod.o
LD [M] drivers/thermal/intel/intel_powerclamp.ko
CC [M] drivers/thermal/intel/intel_soc_dts_iosf.mod.o
LD [M] drivers/thermal/intel/intel_soc_dts_iosf.ko
CC [M] drivers/thermal/intel/intel_soc_dts_thermal.mod.o
LD [M] drivers/thermal/intel/intel_soc_dts_thermal.ko
CC [M] drivers/thermal/intel/x86_pkg_temp_thermal.mod.o
LD [M] drivers/thermal/intel/x86_pkg_temp_thermal.ko

This might sound really dumb but I thought as there is a file called cpuidle_cooling.c in that directory I expected to get a cpuidle_cooling.ko file, it did for many of the others. What am I doing wrong?

Is this:

WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.

MODPOST 13 modules

Why they weren’t made?

I’ve made a cpuidle_cooling.o file successfully by running:

make allmodconfig

instead of:

make oldconfig

That’s the first command while in the root of the kernel source.

1 Like

Does anyone know how to use the cpuidle_cooling.o file? I thought it would make a .ko file I could use as the cpuidle or cpufreq driver.

# probably it's an build artifact,
# (cpuidle_cooling.c --> .o --> .ko)
# please run:
file cpuidle_cooling.o
1 Like

Sorry I didn’t see this and gave up, I’ll remake it and post soon.

file shows this:

[am@ampc]: ~/Downloads/linux-5.6.5/drivers/thermal>$ file ./cpuidle_cooling.o
./cpuidle_cooling.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

objdump -t shows this:

[am@ampc]: ~/Downloads/linux-5.6.5/drivers/thermal>$ objdump -t ./cpuidle_cooling.o

./cpuidle_cooling.o:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000000 l    df *ABS*	0000000000000000 cpuidle_cooling.c
0000000000000000 l    d  .text	0000000000000000 .text
0000000000000000 l    d  .data	0000000000000000 .data
0000000000000000 l    d  .bss	0000000000000000 .bss
0000000000000000 l     F .text	0000000000000021 cpuidle_cooling_get_max_state
0000000000000000 l    d  __mcount_loc	0000000000000000 __mcount_loc
0000000000000030 l     F .text	0000000000000042 cpuidle_cooling_get_cur_state
0000000000000000 l    d  .rodata.str1.8	0000000000000000 .rodata.str1.8
0000000000000080 l     F .text	000000000000018e cpuidle_cooling_set_cur_state
0000000000000000 l    d  .rodata.str1.1	0000000000000000 .rodata.str1.1
0000000000000000 l    d  .rodata	0000000000000000 .rodata
0000000000000060 l     O .data	0000000000000058 cpuidle_ida
0000000000000000 l     O .data	0000000000000030 cpuidle_cooling_ops
0000000000000000 l    d  .text.exit	0000000000000000 .text.exit
0000000000000000 l     F .text.exit	0000000000000016 _GLOBAL__sub_D_65535_0_cpuidle_of_cooling_register
0000000000000000 l    d  .fini_array	0000000000000000 .fini_array
0000000000000000 l    d  .text.startup	0000000000000000 .text.startup
0000000000000000 l     F .text.startup	0000000000000016 _GLOBAL__sub_I_65535_1_cpuidle_of_cooling_register
0000000000000000 l    d  .init_array	0000000000000000 .init_array
0000000000000000 l    d  .note.GNU-stack	0000000000000000 .note.GNU-stack
0000000000000000 l    d  .comment	0000000000000000 .comment
0000000000000000         *UND*	0000000000000000 __fentry__
0000000000000000         *UND*	0000000000000000 __sanitizer_cov_trace_pc
0000000000000000         *UND*	0000000000000000 __asan_store8_noabort
0000000000000000         *UND*	0000000000000000 __asan_load8_noabort
0000000000000000         *UND*	0000000000000000 stackleak_track_stack
0000000000000000         *UND*	0000000000000000 idle_inject_get_duration
0000000000000000         *UND*	0000000000000000 __sanitizer_cov_trace_const_cmp8
0000000000000000         *UND*	0000000000000000 idle_inject_set_duration
0000000000000000         *UND*	0000000000000000 idle_inject_stop
0000000000000000         *UND*	0000000000000000 idle_inject_start
0000000000000000         *UND*	0000000000000000 __stack_chk_fail
0000000000000210 g     F .text	00000000000001f9 cpuidle_of_cooling_register
0000000000000000         *UND*	0000000000000000 kmalloc_caches
0000000000000000         *UND*	0000000000000000 kmem_cache_alloc_trace
0000000000000000         *UND*	0000000000000000 ida_alloc_range
0000000000000000         *UND*	0000000000000000 __sanitizer_cov_trace_const_cmp4
0000000000000000         *UND*	0000000000000000 idle_inject_register
0000000000000000         *UND*	0000000000000000 snprintf
0000000000000000         *UND*	0000000000000000 thermal_of_cooling_device_register
0000000000000000         *UND*	0000000000000000 idle_inject_unregister
0000000000000000         *UND*	0000000000000000 ida_free
0000000000000000         *UND*	0000000000000000 kfree
0000000000000410 g     F .text	0000000000000019 cpuidle_cooling_register
0000000000000000         *UND*	0000000000000000 __asan_unregister_globals
0000000000000000         *UND*	0000000000000000 __asan_register_globals

   Pity that doesn’t answered yet.  Do not think, though, that inserting a module from one Kernel to another (i.e. compiled with other parameters) is a good idea.