I need to make some changes in SPI in Linux. I found that IOCTL was the called function. So where is IOCTL defined? I am using Yocto linux on Intel edison (arduino breakout board).The function call is as:

ioctl (this->fd, SPI_IOC_MESSAGE(1),&msg);

In the IOCTL definition I want to add code to toggle some GPIOs. So how shall I do it?

I suppose that you can obtain the implementation of ioctl() by downloading the source code of the glibc library http://ftp.gnu.org/gnu/glibc/.

IOCTL is short for IO Control. It is a means to send messages and commands to the system kernel. If you want to add messages to a particular IOCTL then you will have to modify the kernel or kernel module sources and rebuild and reinstall it.

I am using yocto linux on intel edison.So where is IOCTL function defined in this version of linux?

The ioctl() function manipulates the underlying device parameters of special files. In particular, many operating characteristics of character special files may be controlled with ioctl() requests. The argument fd must be an open file descriptor. Yu can use this <url snipped> for any writing help.

The version of Linux has zip to do with where the ioctl() function is defined. It is a C function that runs in user space, but sends messages and data to kernel modules. A particular ioctl sub-function will be defined in a kernel module. As I said before, if you want to add another ioctl sub-function to a module, you have to modify the module's source code and rebuild it. If the module is loadable, then that's all you need to do - create a new .ko file and use the insmod system command as user root to load it into kernel memory. If the module is built into the kernel, then you will have to rebuild the entire kernel and install that. Depending upon how many CPU cores and how much RAM your system has, that can take (to build the entire kernel) anywhere from 15 minutes to several hours. On my 8 core system with 8GB of RAM, doing a parallel rebuild my RedHat Enterprise System clone (Scientific Linux) kernel takes 15-20 minutes. If I don't use 8 cores with a parallel build, but just one (the default for the make command), it takes about 2 hours. The speedup is pretty much linear with the number of cores you use with the -j (jobs) option to make. IE: make -j 8 or --jobs=8 will use 8 cores to build the kernel.

FWIW, the ioctl() function is declared in /usr/include/bits/ioctl-types.h and the function signature is this: extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;

Yeah I also know where it is declared but where is it defined.I want to add code to toggle a GPIO pin in this partcular IOCTL definition.Yeah I can recompile the kernel using bitbake. So rubberman tell me more...

You don't need to know where the ioctl function is defined, but just in case you have to know, this is from the stackoverflow forums: "The C library exports the functions, but they are just wrappers for sys calls. The actual socket functions themselves are implemented inside the kernel."

You will need to modify the kernel module source code for the particular ioctl sub-function. IE, you need to start studying up on this stuff because it isn't trivial and you need to get it right, including how the I/O sys_* functions work. Honestly, I don't have the time to teach an entire kernel I/O development course here, and you don't have the $$ to pay me. You can find a lot of stuff on the kernel.org and tldp.org web sites that will get you started.

If I know where the ioctl call is defined I can modify it there.I tried making changes to the kernel using some kernel print statements but they dont reflect again when I compile and load the kernel. I need to know where ioctl is defined, how to reflect the changes made in the kernel and yes underlying socket calls are also needed.

@danibootstrap - NO YOU CANNOT JUST MODIFY THE IOCTL CALL! This is what I've been trying to tell you. Ioctl is just a user-space function that sends messages to the appropriate kernel module. Changing ioctl will gain you nothing, nada, zip, zero... If you need to do what you say, and there are no means to set to set the GPIOs, then you need to get into kernel module programming, which is a pretty steep learning curve.

Good luck. I am done with this thread since you don't seem to be listening to me. I have over 15 years experience with Linux, including kernel module development, and kernel enhancement development and building. It is not uncommon for me to reconfigure a kernel and build/install it from scratch. That's the easy part. Again, good luck, and goodbye.

I am speaking about the kernel code it self. I am usnig bitbake to compile the yocto linux.I added few changes (just to see if it is working) like a kernel print statement (printk( )) but the changes dont reflect in dmesg.I also intentionally gave a wrong syntax in the printk() statement then it wont compile but when I give the right syntax it compiles but I dont seem to be hitting the right spot as I see no changes in the dmesg output. I read that ioctl is for data in and out from userspace to kernelspace. I mean my knowledge is like zero compared to your experience but somehow I dont seem to be modifying the kernel at the right place.So,welcome back.

I'll respond when I have a minute. Right now I have to take my car in to be serviced after a long cross country drive last week.

I literally searched every libray and got it here.

/drivers/tty/synclink_gt.c

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.