Find the answer to your Linux question:
Results 1 to 6 of 6
Hello! I'm really new to all these things so please be patient with me. Here is the thing: I work on some embedded device with Linux on it. I loaded ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! rostfrei's Avatar
    Join Date
    Oct 2006
    Posts
    17

    help: using loaded modules


    Hello!

    I'm really new to all these things so please be patient with me. Here is the thing: I work on some embedded device with Linux on it. I loaded some module (LED driver) with insmod and I can see new symbols loaded into kernel symbol table with cat /proc/ksyms. I can also see new entry in /proc/devices and /proc/ioports. Now I can use this device if I make char device with mknod and use the device trough ioctl commands.

    I don't want to use the driver this way because driver also exports some functions into kernel symbol table. Problem is, I don't know how to use the code this way. If I use this exported functions in my simple application, I get undefined references when the linker tries to make the executable. That is logical of course. So, how can I use functions loaded into kernel symbol table? Is there some kind of define, way to compile the application?

    Regards,
    Rostfrei

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Quote Originally Posted by rostfrei
    If I use this exported functions in my simple application,
    In which application?

    Best Regards

  3. #3
    Just Joined! rostfrei's Avatar
    Join Date
    Oct 2006
    Posts
    17
    This is header of the LED driver

    Code:
    #ifndef led_H
    #define led_H
    
    #ifdef __KERNEL__
    /* Function Prototypes */
    extern u32	led_off		(u32 indexLED);
    extern u32	led_on		(u32 indexLED);
    extern u8	led_eth_ctrl	(int eth_port, u8 ethleds);
    #endif
    
    /* IOCTLs */
    #define LED_ON		_IOW('T', 1, unsigned int)
    #define LED_OFF		_IOW('T', 2, unsigned int)
    #define LED_ETH_PC	_IOW('T', 3, unsigned char)
    #define LED_ETH_LAN	_IOW('T', 4, unsigned char)
    
    #endif /* led_H */

    I can successfully use it in my mini test app

    Code:
    #include "led.h"
    #include <sys/ioctl.h>
    
    int main(void){
      long f = 0;
      f = open("/dev/led", 0);
      ioctl(f, LED_ON, 0x1);
      close(f);
      return 0;
    }

    As you can see, module exports some functions to the linux kernel symbol table. I can see that in the implementation. How can I use this functions in my mini app? How can I call led_on or led_off without linkage problem? I can see those symbols with cat /proc/ksyms.

    Regards,

  4. #4
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Probably I'm wrong because it's late and I had a hard working day... but you can't use that functions.

    That functions are exported to other kernel code, not to user space. For examle, say that I write a module with a function that calculates a square root. If I export this function, other kernel code (other modules, the scheduler, etc) can use that function, but you can't from your user app.

    In fact, the header is telling you "only if __KERNEL__ is defined these declarations are valid"

    Your app is linked against libc and other libraries, but not against the kernel, the same way the kernel is not linked against any libraries.

    Best Regards

  5. #5
    Just Joined! rostfrei's Avatar
    Join Date
    Oct 2006
    Posts
    17
    I suspected this will be the answer. I know that kernel space is totally separate from user space. But one thing keeps puzzling me. Why would somebody implement this handy functions in the driver and then export them to kernel space. Why not implement just ioctl interface? As I understand there is no other way of communicating with the driver code as trough direct writing and reading from character devices or trough ioctl calls?

    I also have other drivers for DSP and Keyboard implemented similarly. There is ioctl interface and there are also those handy functions exported to the kernel. What is the purpose of those functions if they can't be used from the user space?

    Regards,

  6. #6
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Quote Originally Posted by rostfrei
    Why would somebody implement this handy functions in the driver and then export them to kernel space. Why not implement just ioctl interface?
    Just to build, for example, modules in a stacked fashion. For example, you could write a generic USB module that provides raw access to the port and export functions as interface for the proper and specific device drivers.

    Best Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •