Search code examples
linux-kernelraspberry-pilinux-device-driverraspberry-pi4printk

RPi4 : Device Driver - pr_info with float causing build error


I am working on a device driver for a sensor in Raspberry Pi 4. In the program of a kernel device driver for a sensor, I used the following code to print the resulting distance

pr_info( "Distance (cm) : %.2f \n", cm );

where cm was declared as, float cm = 0.0;

On making the file, I get the following errors

pi@raspberrypi:~/TestCodes/3_10MAR21 $ make
make -C /lib/modules/5.10.20-v7l+/build M=/home/pi/TestCodes/3_10MAR21 modules
make[1]: Entering directory '/home/pi/kernel/linux'
  CC [M]  /home/pi/TestCodes/3_10MAR21/driver_ultraS_2.o
  MODPOST /home/pi/TestCodes/3_10MAR21/Module.symvers
ERROR: modpost: "__aeabi_f2iz" [/home/pi/TestCodes/3_10MAR21/driver_ultraS_2.ko] undefined!
ERROR: modpost: "__aeabi_ddiv" [/home/pi/TestCodes/3_10MAR21/driver_ultraS_2.ko] undefined!
ERROR: modpost: "__aeabi_f2d" [/home/pi/TestCodes/3_10MAR21/driver_ultraS_2.ko] undefined!
ERROR: modpost: "__aeabi_d2f" [/home/pi/3_10MAR21/driver_ultraS_2.ko] undefined!
ERROR: modpost: "__aeabi_dadd" [/home/pi/TestCodes/3_10MAR21/driver_ultraS_2.ko] undefined!
ERROR: modpost: "__aeabi_dmul" [/home/pi/TestCodes/3_10MAR21/driver_ultraS_2.ko] undefined!
ERROR: modpost: "__aeabi_ui2d" [/home/pi/TestCodes/3_10MAR21/driver_ultraS_2.ko] undefined!
make[2]: *** [scripts/Makefile.modpost:111: /home/pi/TestCodes/3_10MAR21/Module.symvers] Error 1
make[2]: *** Deleting file '/home/pi/TestCodes/3_10MAR21/Module.symvers'
make[1]: *** [Makefile:1708: modules] Error 2
make[1]: Leaving directory '/home/pi/kernel/linux'
make: *** [Makefile:7: all] Error 2

When I comment off the above mentioned line of code pr_info( "Distance (cm) : %.2f \n", cm ); the make of driver is successful

pi@raspberrypi:~/TestCodes/3_10MAR21 $ make
make -C /lib/modules/5.10.20-v7l+/build M=/home/pi/TestCodes/3_10MAR21 modules
make[1]: Entering directory '/home/pi/kernel/linux'
  CC [M]  /home/pi/TestCodes/3_10MAR21/driver_ultraS_2.o
  MODPOST /home/pi/TestCodes/3_10MAR21/Module.symvers
  CC [M]  /home/pi/TestCodes/3_10MAR21/driver_ultraS_2.mod.o
  LD [M]  /home/pi/TestCodes/3_10MAR21/driver_ultraS_2.ko
make[1]: Leaving directory '/home/pi/kernel/linux'

The contents of Makefile

obj-m += driver_ultraS_2.o

KDIR = /lib/modules/$(shell uname -r)/build


all:
    make -C $(KDIR) M=$(shell pwd) modules

clean:
    make -C $(KDIR) M=$(shell pwd) clean

I couldn't find the solution for this. Are we not able to print floating values? Above the mentioned code I used pr_info() to print an integer which did not give any errors.


Solution

  • The Linux kernel has no support for floating point and correct code, which is run in the kernel space, should not use floating point
    -Tsyvarev

    That solves the problem.