:: Re: [DNG] How to build a kernel mod…
Top Page
Delete this message
Reply to this message
Author: Dr. Nikolaus Klepp
Date:  
To: dng
Subject: Re: [DNG] How to build a kernel module?
Hi Aitor!

Anno domini 2019 Mon, 4 Mar 10:21:09 +0100
aitor_czr scripsit:
> Hi Nik,
>
> On 4/3/19 9:52, Dr. Nikolaus Klepp <dr.klepp@???> wrote:
> > Hi!
> >
> > I am trying to build a patched thinkpad_acpi module for 4.19 kernel (the patch removes the spaming error message from the battery charge/discharge levels BCTG/BCSG on thinkpads T60/T61/X61). I can build the module, but the creaded module won't load.
> >
> > This is what I did to compile the modules:
> >
> > # aptitude install linux-source-4.19
> > # cd /usr/src
> > # tar xJf linux-source-4.19.tar.xz
> > # cd linux-source-4.19/
> > # cp /boot/config-4.19.0-2-amd64 .config
> > # make modules_prepare
> > # make modules
> >
> > This succeeds, but the created modules won't load:
> >
> > root@t61:/usr/src/linux-source-4.19# insmod ./drivers/platform/x86/thinkpad_acpi.ko
> > insmod: ERROR: could not insert module ./drivers/platform/x86/thinkpad_acpi.ko: Invalid module format
> > root@t61:/usr/src/linux-source-4.19# file ./drivers/platform/x86/thinkpad_acpi.ko
> > ./drivers/platform/x86/thinkpad_acpi.ko: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=571675351aecfb803c56549d218d85d53f60b8d7, with debug_info, not stripped
> >
> > Any idea what I missed?
> >
> > Nik
>
> Where can we find the sources of this patched module? Did you give a try
> to module assistant?


It's just a patch for my laptop, nothing special.

How should I use module-assistant? I thought it was just for already-pprepared module packages, not arbitrary kernel modules?


Anyway, I finaly manged to build the patched module:

# mkdir /usr/src/thinkpad_acpi
# cd /usr/src/thinkpad_acpi
# echo 'obj-$(CONFIG_THINKPAD_ACPI)     += thinkpad_acpi.o' > Makefile
# cp ../thinkpad_acpi.c .
# make -C /usr/src/linux-headers-$(uname -r ) M=/usr/src/thinkpad_acpi
# insmod thinkpad_acpi.ko
#


And it works, no more error spam im dmesg :-)

Nik

>
> Aitor.





--
Please do not email me anything that you are not comfortable also sharing with the NSA, CIA ...
--- ./linux-source-4.19/drivers/platform/x86/thinkpad_acpi.c    2019-01-16 22:04:38.000000000 +0100
+++ thinkpad_acpi.c    2019-03-04 11:44:55.480443068 +0100
@@ -9315,6 +9315,8 @@ static acpi_status tpacpi_battery_acpi_e


 static int tpacpi_battery_get(int what, int battery, int *ret)
 {
+    return -ENODEV;
+    
     switch (what) {
     case THRESHOLD_START:
         if ACPI_FAILURE(tpacpi_battery_acpi_eval(GET_START, ret, battery))
@@ -9384,41 +9386,6 @@ static int tpacpi_battery_probe(int batt
      * 3) Get the current stop threshold
      * 4) Check for support
      */
-    if (acpi_has_method(hkey_handle, GET_START)) {
-        if ACPI_FAILURE(tpacpi_battery_acpi_eval(GET_START, &ret, battery)) {
-            pr_err("Error probing battery %d\n", battery);
-            return -ENODEV;
-        }
-        /* Individual addressing is in bit 9 */
-        if (ret & BIT(9))
-            battery_info.individual_addressing = true;
-        /* Support is marked in bit 8 */
-        if (ret & BIT(8))
-            battery_info.batteries[battery].start_support = 1;
-        else
-            return -ENODEV;
-        if (tpacpi_battery_get(THRESHOLD_START, battery,
-            &battery_info.batteries[battery].charge_start)) {
-            pr_err("Error probing battery %d\n", battery);
-            return -ENODEV;
-        }
-    }
-    if (acpi_has_method(hkey_handle, GET_STOP)) {
-        if ACPI_FAILURE(tpacpi_battery_acpi_eval(GET_STOP, &ret, battery)) {
-            pr_err("Error probing battery stop; %d\n", battery);
-            return -ENODEV;
-        }
-        /* Support is marked in bit 8 */
-        if (ret & BIT(8))
-            battery_info.batteries[battery].stop_support = 1;
-        else
-            return -ENODEV;
-        if (tpacpi_battery_get(THRESHOLD_STOP, battery,
-            &battery_info.batteries[battery].charge_stop)) {
-            pr_err("Error probing battery stop: %d\n", battery);
-            return -ENODEV;
-        }
-    }
     pr_info("battery %d registered (start %d, stop %d)",
             battery,
             battery_info.batteries[battery].charge_start,