insmod时出现问题

内核编译和嵌入式产品的设计与开发
回复
jonahsyh
帖子: 2
注册时间: 2014-12-28 22:00
系统: ubuntu

insmod时出现问题

#1

帖子 jonahsyh » 2014-12-28 22:08

编译一段tty驱动时,terminal出现killed,用dmesg查看时,出现以下信息,请高人赐教!
root@ubuntu:/opt/c6678-master/projects/TTY# insmod tty_lan.ko
Killed
root@ubuntu:/opt/c6678-master/projects/TTY# dmesg | tail -12
[ 75.820095] [<c03b83a2>] ? tty_register_driver+0xf2/0x1c0
[ 75.820111] [<c03b8761>] ? alloc_tty_driver+0x51/0x70
[ 75.820311] [<d085307b>] ? tty_lan_init+0x7b/0xb7 [tty_lan]
[ 75.820329] [<c0101131>] ? do_one_initcall+0x31/0x190
[ 75.820334] [<d0853000>] ? tty_lan_init+0x0/0xb7 [tty_lan]
[ 75.820340] [<c01833c0>] ? sys_init_module+0xb0/0x210
[ 75.820346] [<c01033ec>] ? syscall_call+0x7/0xb
[ 75.820351] [<c0590000>] ? mutex_lock_interruptible+0x10/0x40
[ 75.820417] Code: 53 83 ec 08 0f 1f 44 00 00 89 c3 8b 40 48 85 c0 74 0a 8b 93 98 00 00 00 85 d2 74 09 83 c4 08 5b 5d c3 8d 76 00 8b 93 b0 00 00 00 <8b> 92 84 00 00 00 85 d2 74 e7 8b 0d 2c 16 8d c0 89 14 24 31 d2
[ 75.820550] EIP: [<c0255fae>] proc_tty_register_driver+0x2e/0x60 SS:ESP 0068:c933df1c
[ 75.820590] CR2: 0000000000000084
[ 75.820888] ---[ end trace bd3692bac1ff243b ]---
jonahsyh
帖子: 2
注册时间: 2014-12-28 22:00
系统: ubuntu

Re: insmod时出现问题

#2

帖子 jonahsyh » 2014-12-28 22:30

#include <linux/module.h>
#include <linux/kernel.h>
这是编译源码:
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/tty.h>

#include <linux/tty_driver.h>
#include <linux/fs.h>
#include <linux/ioport.h>
#include <linux/serial_reg.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("lan");

#define TTY_LAN_MINORS_NUM 5
#define TTY_LAN_MAJOR 202
static struct tty_driver *tty_lan_driver;

static int tty_lan_open(struct tty_struct *tty, struct file *filp);
static struct tty_operations tty_lan_ops = {
.open = tty_lan_open,
};

static int __init tty_lan_init(void)
{
int i;
int retval;

tty_lan_driver = alloc_tty_driver(TTY_LAN_MINORS_NUM);
if(!tty_lan_driver)
return -ENOMEM;

tty_lan_driver->owner = THIS_MODULE;
tty_lan_driver->driver_name = "tty_lan";
tty_lan_driver->name = "ttty_lan";
tty_lan_driver->major = TTY_LAN_MAJOR,
tty_lan_driver->minor_start = 0;
tty_lan_driver->type = TTY_DRIVER_TYPE_SERIAL;
tty_lan_driver->subtype = SERIAL_TYPE_NORMAL;
tty_lan_driver->flags = TTY_DRIVER_REAL_RAW;
tty_lan_driver->init_termios = tty_std_termios;
tty_lan_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;

retval = tty_register_driver(tty_lan_driver);
if(retval){
printk(KERN_ERR"Failed to register tty_lan_driver!\n");
put_tty_driver(tty_lan_driver);
return retval;
}

for(i = 0; i < TTY_LAN_MINORS_NUM; i++)
tty_register_device(tty_lan_driver, i, NULL);
return 0;
}

static int tty_lan_open(struct tty_struct *tty, struct file *filp)
{
return 0;
}
static void __exit tty_lan_exit(void)
{
int i;
for(i = 0; i < TTY_LAN_MINORS_NUM; i++)
tty_unregister_device(tty_lan_driver, i);
tty_unregister_driver(tty_lan_driver);
}

module_init(tty_lan_init);
module_exit(tty_lan_exit);
回复