Single Linux Device Driver code for multiple Linux versions using LINUX_VERSION

The arguments of the kernel functions changes with new releases.

For example, Kernel versions > 3.10 use the below function to create a proc entry

  proc_file_entry = proc_create("proc_file_name", 0, NULL, &proc_file_fops);

For kernel versions < 3.10, this API was

  proc_file_entry = create_proc_entry("proc_file_name", 0, NULL);
If you want to have a Linux Device Driver which supports multiple Linux Versions, use the macro LINUX_VERSION_CODE

This macro expands to the binary representation of the kernel version
For example for Linux version 2.6.10, the value is 132618(0x02060a)

There is another macro KERNEL_VERSION(major, minor, release). This builds up the version number from the individual numbers. For example KERNEL_VERSION(2,6,10) will return 132618

Sample Code:


Output:




Comments

Post a Comment

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto