2007-12-27 01:38:05

by Siva Prasad

[permalink] [raw]
Subject: Device node - How does kernel know about it

Hi,

How do the device nodes work as an interface between user and kernel
programs, and how to go debugging it?
This is as part of my debugging effort on an embedded board.

* It all started with the problem of "not printing" any thing that comes
from ramdisk (echo and printf statements), while kernel printk's work
perfectly fine.
* Ramdisk is also executing fine, just that prints are not coming out of
serial. I can see the execution of various user programs with a printk
in sys_execve() routine. Ramdisk has all the required files like
/dev/console, /dev/ttyS0, etc.
* Looking further into tty driver, I noticed that call to tty_write() or
do_tty_write() is not happening at all. So, somewhere the interface
between kernel and user program is lost.
* Just to check it out, I tried to write a small kernel module and a
test program.
- Attached memtest.c module (not really testing memory there. :-))
- Attached testmemtest.c user program, that just open's it and reads
the information
- Created a device node using "mknod /dev/memtest c 168 0"
- When I do "insmod memtest.ko" inside the ramdisk bootup scripts, I
could see all the printk's on the console
- When I execute "testmemtest" next in the same script, it does not
display the printk inside of memtest.c module. This only indicates that
read call did not really go to the kernel side.
- Just to check my program's validity, I checked on a similar machine
and all the code works fine.
- "uname -r" also matches with what I built. So, chances of exiting
from open call because of mismatch is remote. Since userland cannot
print, I have no idea what exactly is happening there.

Now going back to the original question...
How does a kernel know about device nodes and how to link with it.
Basically I believe interface between user programs and kernel is lost
at device nodes.

Appreciate any help in continuing my debugging efforts.

Thanks
Siva


Attachments:
memtest.c (4.60 kB)
memtest.c
testmemtest.c (574.00 B)
testmemtest.c
Download all attachments

2007-12-27 20:10:29

by Phillip Susi

[permalink] [raw]
Subject: Re: Device node - How does kernel know about it

Siva Prasad wrote:
> Hi,
>
> How do the device nodes work as an interface between user and kernel
> programs, and how to go debugging it?
> This is as part of my debugging effort on an embedded board.

The filesystem sets specific bits in the mode mask and elsewhere in the
inode to mark the file as a dev node, and which major/minor device
number it should be linked to. The kernel device drivers register to
handle a given device number.

> * It all started with the problem of "not printing" any thing that comes
> from ramdisk (echo and printf statements), while kernel printk's work
> perfectly fine.
> * Ramdisk is also executing fine, just that prints are not coming out of
> serial. I can see the execution of various user programs with a printk
> in sys_execve() routine. Ramdisk has all the required files like
> /dev/console, /dev/ttyS0, etc.

So you did you pass the console=ttyS0 parameter to the kernel? Did you
configure your inittab to spawn the getty on the serial port instead of
/dev/ttyN? You might want to take a look at the Linux Serial Console
HOWTO.

2007-12-28 03:27:27

by Siva Prasad

[permalink] [raw]
Subject: RE: Device node - How does kernel know about it

Thanks for the response Phillip. See below for response.

I already am using "console=ttyS0" as well as set the inittab correctly.

I would like to debug this node behavior. Can you please let me know
which routine gets called first when there is, for example a read() call
from user program. Eventually it will result in a call to what ever read
routine registered, but that must be a call back function or some thing.
Right?

- Siva


-----Original Message-----
From: Phillip Susi [mailto:[email protected]]
Sent: Thursday, December 27, 2007 12:10 PM
To: Siva Prasad
Cc: [email protected]
Subject: Re: Device node - How does kernel know about it

Siva Prasad wrote:
> Hi,
>
> How do the device nodes work as an interface between user and kernel
> programs, and how to go debugging it?
> This is as part of my debugging effort on an embedded board.

The filesystem sets specific bits in the mode mask and elsewhere in the
inode to mark the file as a dev node, and which major/minor device
number it should be linked to. The kernel device drivers register to
handle a given device number.

> * It all started with the problem of "not printing" any thing that
comes
> from ramdisk (echo and printf statements), while kernel printk's work
> perfectly fine.
> * Ramdisk is also executing fine, just that prints are not coming out
of
> serial. I can see the execution of various user programs with a printk
> in sys_execve() routine. Ramdisk has all the required files like
> /dev/console, /dev/ttyS0, etc.

So you did you pass the console=ttyS0 parameter to the kernel? Did you
configure your inittab to spawn the getty on the serial port instead of
/dev/ttyN? You might want to take a look at the Linux Serial Console
HOWTO.