eBUS / ttyebus

Real time linux kernel module for the ebusd using the PL011 UART on a Rasperry Pi
22 stars 7 forks source link

Compile error on kernel 5.15.84-v7+ #14

Open Dinth opened 1 year ago

Dinth commented 1 year ago

Im getting the following error:

make -C /lib/modules/5.15.84-v7+/build M=/home/dinth/ttyebus modules
make[1]: Entering directory '/usr/src/linux-headers-5.15.84-v7+'
  CC [M]  /home/dinth/ttyebus/ttyebusm.o
/home/dinth/ttyebus/ttyebusm.c: In function ‘ttyebus_raspi_model’:
/home/dinth/ttyebus/ttyebusm.c:805:27: error: implicit declaration of function ‘get_fs’; did you mean ‘sget_fc’? [-Werror=implicit-function-declaration]
  805 |     mm_segment_t old_fs = get_fs();
      |                           ^~~~~~
      |                           sget_fc
/home/dinth/ttyebus/ttyebusm.c:805:27: error: invalid initializer
/home/dinth/ttyebus/ttyebusm.c:806:5: error: implicit declaration of function ‘set_fs’; did you mean ‘sget_fc’? [-Werror=implicit-function-declaration]
  806 |     set_fs(KERNEL_DS);
      |     ^~~~~~
      |     sget_fc
/home/dinth/ttyebus/ttyebusm.c:806:12: error: ‘KERNEL_DS’ undeclared (first use in this function); did you mean ‘KERNFS_NS’?
  806 |     set_fs(KERNEL_DS);
      |            ^~~~~~~~~
      |            KERNFS_NS
/home/dinth/ttyebus/ttyebusm.c:806:12: note: each undeclared identifier is reported only once for each function it appears in
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:289: /home/dinth/ttyebus/ttyebusm.o] Error 1
make[1]: *** [Makefile:1902: /home/dinth/ttyebus] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.84-v7+'
make: *** [Makefile:24: all] Error 2
Dinth commented 1 year ago

Possibly related to https://github.com/eBUS/ttyebus/issues/6

ITachiLab commented 9 months ago

The bad news are that in newer Kernel versions the functions get_fs and set_fs are not available by default. The good news – they are not used for anything critical in ttyebus, and can be completely removed from the code as a one-time workaround. Tested on Raspberry Pi Zero W v1.1 running on the latest Raspbian Kernel (6.1.21+).

The patch below should explain everything:

diff --git a/ttyebusm.c b/ttyebusm.c
index f79468c..3197e75 100644
--- a/ttyebusm.c
+++ b/ttyebusm.c
@@ -782,59 +782,6 @@ static long ttyebus_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
     }

-// ===============================================================================================
-//
-//                                      ttyebus_raspi_model
-//
-// ===============================================================================================
-// Description:
-//      Get the Rasperry Pi model number from /sys/firmware/devicetree/base/model. The string
-//      has usually the form "Raspberry Pi 3 Model B Rev 1.2"
-//      Extract the number and return it.
-//
-// ===============================================================================================
-unsigned int ttyebus_raspi_model(void)
-    {
-    struct file* filp = NULL;
-    char buf[32];
-    unsigned int NumBytes = 0;
-
-    // get current segment descriptor, set segment descriptor
-    // associated to kernel space
-    // ======================================================
-    mm_segment_t old_fs = get_fs();
-    set_fs(KERNEL_DS);
-
-    // read the file
-    // =============
-    filp = filp_open("/sys/firmware/devicetree/base/model", O_RDONLY, 0);
-    if (filp == NULL)
-        {
-        set_fs(old_fs);
-        return 0;
-        }
-    NumBytes = filp->f_op->read(filp, buf, sizeof(buf), &filp->f_pos);
-    set_fs(old_fs);
-
-    // restore the segment descriptor
-    // ==============================
-    filp_close(filp, NULL);
-
-    // interpret the data from the file
-    // ================================
-    if (NumBytes < 14)
-        return 0;
-
-    switch(buf[13])
-        {
-        case '2' : return 2; break;
-        case '3' : return 3; break;
-        case '4' : return 4; break;
-        default: return 1;
-        }
-    }
-
-
 // ===============================================================================================
 //
 //                                    ttyebus_register
@@ -864,7 +811,7 @@ int ttyebus_register(void)

     // Get the RASPI model
     // ===================
-    RaspiModel = ttyebus_raspi_model();
+    RaspiModel = 1; // Change accordingly to your Raspberry model
     if (RaspiModel < 1 || RaspiModel > 4)
         {
         printk(KERN_NOTICE "ttyebus: Unknown RASPI model %d\n", RaspiModel);