LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-09-2013, 02:13 AM   #1
shaaraddalvi
LQ Newbie
 
Registered: Feb 2013
Posts: 2

Rep: Reputation: Disabled
Errors in making Kernel module


I have a sample code for kernel module, which when I try to compile I am continuously getting errors.
Code:
/* 
 *  kbleds.c − Blink keyboard leds until the module is unloaded.
 */
#include <linux/module.h>
#include <linux/config.h>
#include <linux/init.h>
#include <linux/tty.h>          /* For fg_console, MAX_NR_CONSOLES */
#include <linux/kd.h>           /* For KDSETLED */
#include <linux/vt.h>
#include <linux/console_struct.h>       /* For vc_cons */
MODULE_DESCRIPTION("Example module illustrating the use of Keyboard LEDs.");
MODULE_AUTHOR("Daniele Paolo Scarpazza");
MODULE_LICENSE("GPL");
struct timer_list my_timer;
struct tty_driver *my_driver;
char kbledstatus = 0;
#define BLINK_DELAY   HZ/5
#define ALL_LEDS_ON   0x07
#define RESTORE_LEDS  0xFF
/*
 * Function my_timer_func blinks the keyboard LEDs periodically by invoking
 * command KDSETLED of ioctl() on the keyboard driver. To learn more on virtual 
 * terminal ioctl operations, please see file:
 *     /usr/src/linux/drivers/char/vt_ioctl.c, function vt_ioctl().
 *
 * The argument to KDSETLED is alternatively set to 7 (thus causing the led 
 * mode to be set to LED_SHOW_IOCTL, and all the leds are lit) and to 0xFF
 * (any value above 7 switches back the led mode to LED_SHOW_FLAGS, thus
 * the LEDs reflect the actual keyboard status).  To learn more on this, 
 * please see file:
 *     /usr/src/linux/drivers/char/keyboard.c, function setledstate().
 * 
 */
static void my_timer_func(unsigned long ptr)
{
        int *pstatus = (int *)ptr;
		if (*pstatus == ALL_LEDS_ON)
                *pstatus = RESTORE_LEDS;
        else
                *pstatus = ALL_LEDS_ON;
        (my_driver−>ioctl) (vc_cons[fg_console].d−>vc_tty, NULL, KDSETLED,
                            *pstatus);
        my_timer.expires = jiffies + BLINK_DELAY;
        add_timer(&my_timer);
}
static int __init kbleds_init(void)
{
        int i;
        printk(KERN_INFO "kbleds: loading\n");
        printk(KERN_INFO "kbleds: fgconsole is %x\n", fg_console);
        for (i = 0; i < MAX_NR_CONSOLES; i++) {
                if (!vc_cons[i].d)
                        break;
                printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i,
                       MAX_NR_CONSOLES, vc_cons[i].d−>vc_num,
                       (unsigned long)vc_cons[i].d−>vc_tty);
        }
        printk(KERN_INFO "kbleds: finished scanning consoles\n");
        my_driver = vc_cons[fg_console].d−>vc_tty−>driver;
        printk(KERN_INFO "kbleds: tty driver magic %x\n", my_driver−>magic);
        /*
         * Set up the LED blink timer the first time
         */
        init_timer(&my_timer);
        my_timer.function = my_timer_func;
        my_timer.data = (unsigned long)&kbledstatus;
        my_timer.expires = jiffies + BLINK_DELAY;
        add_timer(&my_timer);
        return 0;
}
static void __exit kbleds_cleanup(void)
{
        printk(KERN_INFO "kbleds: unloading...\n");
        del_timer(&my_timer);
        (my_driver−>ioctl) (vc_cons[fg_console].d−>vc_tty, NULL, KDSETLED,
                            RESTORE_LEDS);
}
module_init(kbleds_init);
module_exit(kbleds_cleanup);

Why does it say that config.h is not found??
 
Old 02-09-2013, 02:55 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,517

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
No "config.h" any more in a contemporary kernel.
But you can make one :

cd /usr/src///<linux>//include/linux/
# ln -s ../generated/autoconf.h config.h
 
Old 02-09-2013, 03:35 AM   #3
shaaraddalvi
LQ Newbie
 
Registered: Feb 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Question

Thanks a lot!
Yes, that solved the problem of config.h not found, but now it is giving a bunch of errors like :
Code:
home/shaarad/Study/Linux/modtests/kbleds.c: In function ‘my_timer_func’:
/home/shaarad/Study/Linux/modtests/kbleds.c:42:9: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:42:9: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:42:9: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:42:23: error: ‘ioctl’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:42:23: note: each undeclared identifier is reported only once for each function it appears in
/home/shaarad/Study/Linux/modtests/kbleds.c:42:39: error: ‘fg_console’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:42:9: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:42:9: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:42:9: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:42:56: error: ‘vc_tty’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c: In function ‘kbleds_init’:
/home/shaarad/Study/Linux/modtests/kbleds.c:51:55: error: ‘fg_console’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:56:24: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:56:24: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:56:24: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:56:57: error: ‘vc_num’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:57:24: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:57:24: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:57:24: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:57:55: error: ‘vc_tty’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:60:9: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:60:9: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:60:9: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:60:9: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:60:9: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:60:9: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:60:56: error: ‘driver’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:61:9: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:61:9: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:61:9: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:61:72: error: ‘magic’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c: In function ‘kbleds_cleanup’:
/home/shaarad/Study/Linux/modtests/kbleds.c:76:9: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:76:9: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:76:9: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:76:23: error: ‘ioctl’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:76:39: error: ‘fg_console’ undeclared (first use in this function)
/home/shaarad/Study/Linux/modtests/kbleds.c:76:9: error: stray ‘\342’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:76:9: error: stray ‘\210’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:76:9: error: stray ‘\222’ in program
/home/shaarad/Study/Linux/modtests/kbleds.c:76:56: error: ‘vc_tty’ undeclared (first use in this function)
make[2]: *** [/home/shaarad/Study/Linux/modtests/kbleds.o] Error 1
make[1]: *** [_module_/home/shaarad/Study/Linux/modtests] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-29-generic'
make: *** [all] Error 2
 
Old 02-09-2013, 04:08 AM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,517

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
? Looks like you found "kbleds.c" here ..
http://www.tldp.org/LDP/lkmpg/2.6/ht...g.html#AEN1201
.. Latest update was '18 May 2007' : It's old code.
Quote : "2007-05-18 ver 2.6.4" (( May work with kernel-2.6.4 ? ))

! And : kbleds.c is particularly buggy.

No luck with any kernel examples : 3.2.18 (gcc-4.5.2), 2.6.18 (gcc-4.1.2),
2.6.32 (gcc-4.4.6) at kbleds.c build.


-

Last edited by knudfl; 02-09-2013 at 04:13 AM.
 
Old 02-13-2013, 12:39 AM   #5
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
here is the modified code for kernel version 3.7.5

http://tuxthink.blogspot.in/2013/02/...rsion-375.html
 
1 members found this post helpful.
Old 02-13-2013, 04:50 AM   #6
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,517

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
# 5 : Thank you.

Looks like the new kbleds.c works OK for all kernel 3.x.x.
( A test was run with version 3.2.18 ).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Making sure a module is loaded in the kernel upon boot. madde Linux - Newbie 2 12-23-2010 03:13 PM
Trouble making/inserting custom kernel module melodyincognito Linux - Kernel 3 06-18-2010 06:43 AM
Adaptec Kernel Module - Kernel Compile Errors dumbsheep Linux - General 3 11-07-2007 03:47 PM
Making kernel module yannifan Programming 1 02-04-2007 08:00 AM
Sound kernel module errors with FC4 since kernel 2.6.14 knutdc Linux - Software 2 12-23-2005 07:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration