2010-03-24 06:43:47     a problem about creat a node under /dev Automatically

Document created by Aaronwu Employee on Aug 21, 2013
Version 1Show Document
  • View in full screen mode

2010-03-24 06:43:47     a problem about creat a node under /dev Automatically

zhang zhihua (CHINA)

Message: 87662   

 

我想在加载驱动程序的时候就自动在/dev目录创建一个设备节点,我首先用class_create(…)函创建一个类my_class,这个类存放于sysfs下面,再调用device_create(…)函数来在/dev目录下创建test_dev设备节点,具体代码如下:

 

{

 

my_class = class_create(THIS_MODULE, "my_class");

 

if(IS_ERR(my_class))

     {

          printk("Err: failed in creating class.\n");

          return -1;

      }

 

 

   device_create( my_class, NULL, MKDEV(major, minor), "test_dev""%d", 0 );

 

}

 

{

 

static void test_cleanup(void)

{

   cdev_del(&test_dev);

   class_destroy(my_class);

   device_destroy(my_class, MKDEV(major, minor));         //delete device node under /dev

   unregister_chrdev_region(MKDEV(major, minor), DEVNUM);

   printk("Test device uninstalled\n");

}

 

}

 

但是我系统启动的时候却出现下面错误:

 

nari> bootm 1000000

## Booting kernel from Legacy Image at 01000000 ...

   Image Name:   Linux-2.6.28.10-ADI-2009R1

   Created:      2010-03-24   9:39:59 UTC

   Image Type:   Blackfin Linux Kernel Image (gzip compressed)

   Data Size:    3565280 Bytes =  3.4 MB

   Load Address: 00001000

   Entry Point:  00234bac

   Verifying Checksum ... OK

   Uncompressing Kernel Image ... OK

Starting Kernel at = 00234bac

Linux version 2.6.28.10-ADI-2009R1 (root@ubuntu) (gcc version 4.1.2 (ADI svn)) #

324 Wed Mar 24 02:39:40 PDT 2010

bootconsole [early_shadow0] enabled

bootconsole [early_BFuart0] enabled

early printk enabled on early_BFuart0

Board Memory: 32MB

Kernel Managed Memory: 32MB

Memory map:

  fixedcode = 0x00000400-0x00000490

  text      = 0x00001000-0x0017b500

  rodata    = 0x0017b500-0x001ea520

  bss       = 0x001eb000-0x00211af8

  data      = 0x00211af8-0x00228000

    stack   = 0x00226000-0x00228000

  init      = 0x00228000-0x00644000

  available = 0x00644000-0x01eff000

  DMA Zone  = 0x01f00000-0x02000000

Hardware Trace Active and Enabled

Boot Mode: 3

Blackfin support (C) 2004-2009 Analog Devices, Inc.

Compiled for ADSP-BF518 Rev 0.0

Warning: Compiled for Rev 0, but running on Rev 1

Blackfin Linux support by   blackfin.uclinux.org/

Processor Speed: 400 MHz core clock and 80 MHz System Clock

NOMPU: setting up cplb tables

Instruction Cache Enabled for CPU0

Data Cache Enabled for CPU0 (write-back)

Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 7873

Kernel command line: root=/dev/mtdblock3 rw rootfstype=jffs2 clkin_hz=25000000 e

arlyprintk=serial,uart0,57600 console=ttyBF0,57600

Configuring Blackfin Priority Driven Interrupts

PID hash table entries: 128 (order: 7, 512 bytes)

I-pipe 1.10-00: pipeline enabled.

Console: colour dummy device 80x25

console [ttyBF0] enabled, bootconsole disabled

console [ttyBF0] enabled, bootconsole disabled

Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)

Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)

Memory available: 25032k/32768k RAM, (4208k init code, 1513k kernel code, 691k d

ata, 1024k dma, 296k reserved)

Calibrating delay loop... 794.62 BogoMIPS (lpj=1589248)

Security Framework initialized

Mount-cache hash table entries: 512

Blackfin Scratchpad data SRAM: 4 KB

Blackfin L1 Data A SRAM: 16 KB (15 KB free)

Blackfin L1 Data B SRAM: 16 KB (16 KB free)

Blackfin L1 Instruction SRAM: 48 KB (42 KB free)

net_namespace: 288 bytes

NET: Registered protocol family 16

Blackfin DMA Controller

ezbrd_init(): registering device resources

NET: Registered protocol family 2

IP route cache hash table entries: 1024 (order: 0, 4096 bytes)

TCP established hash table entries: 1024 (order: 1, 8192 bytes)

TCP bind hash table entries: 1024 (order: 0, 4096 bytes)

TCP: Hash tables configured (established 1024 bind 1024)

TCP reno registered

NET: Registered protocol family 1

I-pipe: Domain Xenomai registered.

Xenomai: hal/blackfin started.

Xenomai: real-time nucleus v2.4.7 (Andalusia) loaded.

Xenomai: starting native API services.

Xenomai: starting POSIX services.

Xenomai: starting RTDM services.

NTFS driver 2.1.29 [Flags: R/O].

JFFS2 version 2.2. (NAND) (SUMMARY)  漏 2001-2006 Red Hat, Inc.

msgmni has been set to 48

io scheduler noop registered (default)

The major of the gpio device is 110

Registered character driver

The major of the test device is 253

NULL pointer access

Kernel OOPS in progress

Deferred Exception context

CURRENT PROCESS:

COMM=swapper PID=1

CPU = 0

invalid mm

return address: [0x000d7cee]; contents of:

0x000d7cc0:  05e3  e800  0044  0c81  e630  004d  e631  004e

0x000d7cd0:  e632  004f  e534  0050  1402  228a  e530  004d

0x000d7ce0:  e531  004e  5bc8  0a78  14e6  e531  004f [9949]

0x000d7cf0:  4308  0c00  19f3  e533  004d  612a  0810  1820

 

ADSP-BF518-0.0(Detected 0.1) 400(MHz CCLK) 80(MHz SCLK) (mpu off)

Linux version 2.6.28.10-ADI-2009R1

Built with gcc version 4.1.2 (ADI svn)

 

SEQUENCER STATUS:               Not tainted

SEQSTAT: 00000027  IPEND: 8030  SYSCFG: 0006

  EXCAUSE   : 0x27

  interrupts disabled

  physical IVG5 asserted : <0xffa00bfc> { _evt_ivhw + 0x0 }

  physical IVG15 asserted : <0xffa00da8> { _evt_system_call + 0x0 }

  logical irq   6 mapped  : <0xffa00310> { _timer_interrupt + 0x0 }

RETE: <0x00000000> /* Maybe null pointer? */

RETN: <0x01ee9cb4> /* kernel dynamic memory */

RETX: <0x00000480> /* Maybe fixed code section */

RETS: <0x000f6cb8> { _device_create_vargs + 0x68 }

PC  : <0x000d7cee> { _vsnprintf + 0x2e }

DCPLB_FAULT_ADDR: <0x00000000> /* Maybe null pointer? */

ICPLB_FAULT_ADDR: <0x000d7cee> { _vsnprintf + 0x2e }

 

PROCESSOR STATE:

R0 : 01970c8c    R1 : 00000014    R2 : 00000000    R3 : 01970e00

R4 : 001caf44    R5 : 00000000    R6 : 0fd00000    R7 : 01e8e220

P0 : 01970c8c    P1 : 00000000    P2 : 01970e00    P3 : 0020d484

P4 : 01ee9e44    P5 : 01970c00    FP : 01970ca0    SP : 01ee9bd8

LB0: 000d868c    LT0: 000d868c    LC0: 00000000

LB1: 00070bc8    LT1: 00070bb6    LC1: 00000000

B0 : 00000000    L0 : 00000000    M0 : 00000000    I0 : 00000003

B1 : 00000000    L1 : 00000000    M1 : 00000000    I1 : 019c9d44

B2 : 00000000    L2 : 00000000    M2 : 00000000    I2 : 00000000

B3 : 00000000    L3 : 00000000    M3 : 00000000    I3 : 00000000

A0.w: 00000000   A0.x: 00000000   A1.w: 00000000   A1.x: 00000000

USP : 00000000  ASTAT: 00003024

 

Hardware Trace:

   0 Target : <0x00004d34> { _trap_c + 0x0 }

     Source : <0xffa005f6> { _exception_to_level5 + 0xae } CALL pcrel

   1 Target : <0xffa00548> { _exception_to_level5 + 0x0 }

     Source : <0xffa00404> { _bfin_return_from_exception + 0x18 } RTX

   2 Target : <0xffa003ec> { _bfin_return_from_exception + 0x0 }

     Source : <0xffa004a0> { _ex_trap_c + 0x6c } JUMP.S

   3 Target : <0xffa00434> { _ex_trap_c + 0x0 }

     Source : <0xffa006c0> { _trap + 0x58 } JUMP (P4)

   4 Target : <0xffa00668> { _trap + 0x0 }

     Source : <0x000d7cea> { _vsnprintf + 0x2a } 0xe531

   5 Target : <0x000d7cdc> { _vsnprintf + 0x1c }

     Source : <0x000d7cd8> { _vsnprintf + 0x18 } IF CC JUMP

   6 Target : <0x000d7cc0> { _vsnprintf + 0x0 }

     Source : <0x000f6cb4> { _device_create_vargs + 0x64 } CALL pcrel

   7 Target : <0x000f6c7c> { _device_create_vargs + 0x2c }

     Source : <0x0006190a> { _kmem_cache_alloc + 0x66 } RTS

   8 Target : <0x00061902> { _kmem_cache_alloc + 0x5e }

     Source : <0x0006192e> { _kmem_cache_alloc + 0x8a } JUMP.S

   9 Target : <0x0006192e> { _kmem_cache_alloc + 0x8a }

     Source : <0x000d8692> { _memset + 0x2e } RTS

  10 Target : <0x000d8664> { _memset + 0x0 }

     Source : <0x0006192a> { _kmem_cache_alloc + 0x86 } CALL pcrel

  11 Target : <0x00061924> { _kmem_cache_alloc + 0x80 }

     Source : <0x00061900> { _kmem_cache_alloc + 0x5c } IF !CC JUMP

  12 Target : <0x000618fa> { _kmem_cache_alloc + 0x56 }

     Source : <0x0002e1ca> { ___ipipe_unstall_root + 0x2a } RTS

  13 Target : <0x0002e1a0> { ___ipipe_unstall_root + 0x0 }

     Source : <0x0002e1fe> { ___ipipe_restore_root + 0x2a } JUMP.L

  14 Target : <0x0002e1fe> { ___ipipe_restore_root + 0x2a }

     Source : <0x0002e1d6> { ___ipipe_restore_root + 0x2 } IF !CC JUMP

  15 Target : <0x0002e1d4> { ___ipipe_restore_root + 0x0 }

     Source : <0x000618f6> { _kmem_cache_alloc + 0x52 } CALL pcrel

 

Kernel Stack

Stack info:

SP: [0x01ee9c7c] <0x01ee9c7c> /* kernel dynamic memory */

FP: (0x01ee9cc0)

Memory from 0x01ee9c70 to 01eea000

01ee9c70: 01970c00  01ee9e44  0020d484 [01970e00] 00000000  01970c8c  01e8e220

0fd00000

01ee9c90: 00000000  001caf44  01970e00  00000000  00000014  01970c8c  01970c8c

01970c8c

01ee9cb0: 00000006  01ee8000  01ee8000  01ee8000 (01ee9d38)<0017a8c4> 00217e78

01ee8000

01ee9cd0: 01ee8000  7fffffff  00000000  01ee9d68  00000002  0020c444  00000001

01ee9d68

01ee9cf0: 001ca238  01efe8e0  01ef72f8  01ee9d34 <0000d9b2> 00000000 <0017a67c>

00217e78

01ee9d10: 7fffffff <0017a6d2> 01eca800  01efe8e0  01ece9e0  00000001  01ee6bc0

0000a80c

01ee9d30: 00100100  00200200 (00000000)<0001c9c4> 01e8e1e0  01ece9e0  0020c444 <

0001c9cc>

01ee9d50: 01e8e1e0  fffffffe <0001c9cc> 01ee9da0  0197d000  000007bb  00000000

01ee9d6c

01ee9d70: 01ee9d6c <000d44be> 0197d010  00000004 <000d44be> 01973ca0  01efac68

00000006

01ee9d90: 000000d0  000000d0  019ce780  0197d000  0021b6ac  01efe8e0  00000000

01e8e220

01ee9db0:<000d3e76> 01973ca0 <000d3cfe> 01973ca0  00000000  00000000 <000f6cb8>

01970c00

01ee9dd0: 00000000  0020d484  01e8e220  0fd00000  00000000  001caf44  01970c8c

00000014

01ee9df0: 00000000  01ee9e44 <000f6cfa> 0020d490  01ee9e44  0021bc48  00000000

00000000

01ee9e10: 01ee2c00  01ee9e34  001caf44  00000000  01ee9e44  01ee9e44 <000e7d6e>

0fd00000

01ee9e30: 0020d448  000000fd  ffffffff  001caf44  00000000  0fd00000 <00001028>

001eb024

01ee9e50: 000e7c9c  00244054  00000000  00000000  00000000  00000000  00000000 <

ffa00b98>

01ee9e70: 0008f328  00008050  00000026  00000000  00000000  00000000  0008f328 <

0008f278>

01ee9e90: 00000006  02003004  000d7b4e  000d868c  000d7b42  000d868c  00000000

00000000

01ee9eb0: 00000000  00000000  00000000  00000000  00000000  00000000  00000000

00000000

01ee9ed0: 00000000  ffffffff  01ee9f08 <000d32f2> 01ec6940 <000d2fea> 0020aa8c <

000d3366>

01ee9ef0: 0068e6a4  00000000  00000000  00000000  000080d0  01ee9f08  00000000

ffffffff

01ee9f10: 01ee9f40 <000d32f2> 01ec5920 <000d2fea> 0020aa8c <000d3366> 0068e6a4

00000000

01ee9f30:<000d3366> 0020aa8c  000080d0  01ee9f40  01ee5e10  00000000  00000000

00000000

01ee9f50:<000d352a> 0020aa8c  01ec59e0  00000000 <0008f278> 01ec5920  01ec59e0

00244054

01ee9f70: 01ee9f94  00004000  00000000  00000000  00000000  01ee9f98  01ee9f94 <

0008f49c>

01ee9f90: 001faa78  000000ff <0008f4aa> 001faa78  00243dd0  01ec5920  01ec5980

00243dd0

01ee9fb0: 00000076  00000001 <0002db86><002283a4> 00243f94  00243dd0  00000000

00000000

01ee9fd0: 00000000  00000000  00000000  00000000  00000000 <00001456> 00000000

00000000

01ee9ff0: 00000000  00000000  ffffffff  00000006

Return addresses in stack:

   frame  1 : <0x0017a8c4> { _schedule_timeout + 0x6c }

    address : <0x0000d9b2> { ___wake_up + 0x56 }

    address : <0x0017a67c> { _wait_for_common + 0x9c }

    address : <0x0017a6d2> { _wait_for_common + 0xf2 }

   frame  2 : <0x0001c9c4> { _call_usermodehelper_exec + 0x44 }

    address : <0x0001c9cc> { _call_usermodehelper_exec + 0x4c }

    address : <0x0001c9cc> { _call_usermodehelper_exec + 0x4c }

    address : <0x000d44be> { _kobject_uevent_env + 0xca }

    address : <0x000d44be> { _kobject_uevent_env + 0xca }

    address : <0x000d3e76> { _kset_register + 0x32 }

    address : <0x000d3cfe> { _kobject_get + 0x12 }

    address : <0x000f6cb8> { _device_create_vargs + 0x68 }

    address : <0x000f6cfa> { _device_create + 0x1a }

    address : <0x000e7d6e> { _test_init + 0xd2 }

    address : <0x00001028> { _do_one_initcall + 0x28 }

    address : <0xffa00b98> { __common_int_entry + 0x6c }

    address : <0x0008f278> { _proc_register + 0x30 }

    address : <0x000d32f2> { _ida_get_new_above + 0x92 }

    address : <0x000d2fea> { _get_from_free_list + 0x4e }

    address : <0x000d3366> { _ida_get_new_above + 0x106 }

    address : <0x000d32f2> { _ida_get_new_above + 0x92 }

    address : <0x000d2fea> { _get_from_free_list + 0x4e }

    address : <0x000d3366> { _ida_get_new_above + 0x106 }

    address : <0x000d3366> { _ida_get_new_above + 0x106 }

    address : <0x000d352a> { _ida_pre_get + 0xe }

    address : <0x0008f278> { _proc_register + 0x30 }

    address : <0x0008f49c> { _create_proc_entry + 0x3c }

    address : <0x0008f4aa> { _create_proc_entry + 0x4a }

    address : <0x0002db86> { ___ipipe_add_domain_proc + 0x1e }

    address : <0x002283a4> { _kernel_init + 0x88 }

    address : <0x00001456> { _kernel_thread_helper + 0x6 }

Modules linked in:

Kernel panic - not syncing: Kernel exception

TranslateQuoteReplyEditDelete

 

 

2010-03-24 12:39:59     Re: a problem about creat a node under /dev Automatically

Mike Frysinger (UNITED STATES)

Message: 87670   

 

you really need to read some basic linux books.  the wiki has pointers to plenty of free ones -- go start there.

 

i'm pretty sure you cant give device_create() a NULL parent.

QuoteReplyEditDelete

 

 

2010-03-24 21:23:25     Re: a problem about creat a node under /dev Automatically

zhang zhihua (CHINA)

Message: 87678   

 

sorry,Mike,

 

In this area, I was a novice!

 

But if I want to creat a char device driver ,which is the parent?

 

I am very urgent to solve this problem ,thank you!

 

This is the code:

 

 

 

static int test_init(void)

{

int result;

dev_t dev = MKDEV(major,minor);  /*MKDEV 实现主次设备号的组合来获得dev */

 

if (major)

  {

   result = register_chrdev_region(dev,DEVNUM,TEST_DEVICE_NAME);//

  }

  else

    {

     result = alloc_chrdev_region(&dev,minor,DEVNUM,TEST_DEVICE_NAME);

 

     major = MAJOR(dev);

    }

if (result < 0)

   {

   printk(KERN_WARNING "test: unable to get major %d\n", major);

   return result;

   }

  /*1st function*/

test_setup_cdev(&test_dev, minor, &test_fops);

printk (KERN_INFO "Registered character driver\n");

printk("The major of the test device is %d\n", major);

/* create your own class under /sysfs */

  my_class = class_create(THIS_MODULE, "my_class");

  if(IS_ERR(my_class))

     {

          printk("Err: failed in creating class.\n");

          return -1;

      }

/* register your own device in sysfs, and this will cause udev to create corresponding device node */

  device_create( my_class,NULL, MKDEV(major, minor), "test_dev""%d", 0 );

 

return 0;

}

 

/************************************************************************

* NAME:   test_cleanup

* FUNCTION:驱动程序卸载函数

* 参数值:

******************************************************************* ******/

static void test_cleanup(void)

{

   cdev_del(&test_dev);

   class_destroy(my_class);

   device_destroy(my_class, MKDEV(major, minor));         //delete device node under /dev

   unregister_chrdev_region(MKDEV(major, minor), DEVNUM);

   printk("Test device uninstalled\n");

}

 

/***********************************************************************************/

 

module_init(test_init);

module_exit(test_cleanup);

Attachments

    Outcomes