?? : Dummy ???? ???? ?? ? ?? - PowerPoint PPT Presentation

About This Presentation
Title:

?? : Dummy ???? ???? ?? ? ??

Description:

Title: Last modified by: Created Date: 9/7/1998 9:18:45 PM Document presentation format: (4:3) Company – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 34
Provided by: tis68
Category:
Tags: dummy | linux

less

Transcript and Presenter's Notes

Title: ?? : Dummy ???? ???? ?? ? ??


1
?? ???? ????
  • ???? ???

2
??
  • ?? ??
  • ?? ??
  • ?? ?? ?? ??
  • ??? ???? ????
  • ?? Dummy ???? ???? ?? ? ??

3
kernel configuration
  • ?? kernel ??? ?? ???
  • MTD file system? mount?? ?? ???

4
system type
5
Serial drivers
  • Device drivers -gt Character devices -gt Serial
    drivers

6
Boot options
7
MTD
  • Device drivers -gt Memory Technology Devices (MTD)
    -gt

8
MTD
  • Device drivers -gt Memory Technology Devices (MTD)
    -gt
  • Ram/Rom/Flash chip drivers

9
MTD
  • Device drivers -gt Memory Technology Devices (MTD)
    -gt
  • Mapping drivers for chip access

10
File systems
  • File systems -gt Miscellaneous filesystems -gt

11
?? ??
  • ??? ?? ?? ???? loading ? ? ?? ?? ????
  • ??? ?? ??? ??? ??? ??? ? ?? ?? ??? ???? ???? ??
    ??
  • ???? ????, ?? ???, ???? ???? ?? ??? ???
  • ???? ?? ?? ??? ???? ??, ?? ???? ?? ?? ??? ???? ?
  • ltlinux/module.hgt? ???? ??
  • ?? ??? ?? ???? ??? ???? ?
  • ?? ?? ?????? ???
  • main() ??? ??
  • ??? ?? ? ?? ? ? ???? ??? ??
  • Loading ? - int init_module(void) ?? ??
  • Unloading ? - void cleanup_module() ?? ??

12
?? ?? ?? ??
  • Hello World ????
  • ??? ??? ?
  • Hello world ??
  • ??? ??? ?
  • Goodbye world ??
  • / hello.c /
  • include ltlinux/module.hgt / ?? ??? ?? /
  • include ltlinux/kernel.hgt / printk() ?? ?? /
  • int hello_init(void) // ??? ??? ? ??
  • printk (Hello world\n)
  • return 0
  • void hello_exit(void) // ?? ? ? ??
  • printk (Goodbye world)
  • module_init(hello_init)
  • module_exit(hello_exit)
  • MODULE_LICENSE(GPL)

13
?? ?? ?? ???
  • arm-linux-gcc ????? ??
  • ???? ?? Makefile ??
  • Makefile
  • obj-m hello.o
  • KDIR (?? ??? ??? ?? ??)
  • PWD (shell pwd)
  • all
  • (MAKE) -C (KDIR) SUBDIRS(PWD) modules
  • clean
  • rm -rf .ko
  • rm -rf .mod.
  • rm -rf ..cmd
  • rm -rf .o

14
?? ?? ?? ?? ??
  • ??? ??? ??
  • rx hello.ko
  • ??? ??(x??)? ?? ???? ???? ko ?? ??
  • insmod hello.ko
  • ??? ??? ?? ?? ??
  • lsmod
  • ?? ??
  • rmmod hello
  • ?? ??? ?? ?? ?? ???? ????? ???? ? ??

15
??? ???? ????
  • ?? ?? ??? ??? ?? ??? ????? ???? ?????? ?? ?????
    ??? ? ??? ??? ????
  • ???? ??? ??? ???? ????? ??? ???? ??? ????? ???
  • ????? ?? ??? ??? ???? ??? ????? ??
  • ???? ???? ????? ??? ???? ?
  • ?? ??? ?? ??? ??

16
??? ???? ????? ??
  • ?? ???? ????
  • ??? ???? ?? ??
  • ????? ???? ??? ??? ??
  • ?) ???, ??? ?? ?
  • ?? ???? ????
  • ?? ??? ??? ???
  • ?????? ??? ?? ???? ??
  • ????? ???? ??? ??? ??? ??
  • ?) ?? ???, CD?, ??? ??? ?
  • ???? ???? ????
  • ???? ????? ??
  • ???????? ??? ?? ?? ????? ? ?? socket(), bind() ??
    ??? ? ??

17
??? ???? ????? ??(2)
18
???? ?? ??
  • ????? ??? ??? ???
  • ls l /dev ??? ???? ?? ??

???? ??
???
???
19
???? ?? ??(2)
  • ? ??(Major Number)
  • ???? ???? ????? ??/????? ??
  • ?? Device? ??? ??, 1Byte (0255??? ?)
  • ? ??(Minor Number)
  • ???? ???? ??? ??? ???? ?? ??
  • ? Device? ???? ??? ???, 2Byte (???)
  • ??? ???? ????? ?? ?? ???? ?? ??

???
???
20
?? ???? ???? ?? ??
include ltlinux/kernel.hgt include ltlinux/module.hgt include ltlinux/init.hgt
int device_open( ) int device_release( ) ssize_t device_write( ) ssize_t device_read( )
static struct file_operations device_fops ssize_t (read) () ssize_t (write) () int (open) () int (release) ()
int init_module(void) void cleanup_module(void)
module_init(hello_init) module_exit(hello_exit)
?? ??
?? ?? ?? ??
?? ?? ???
21
???? ???? ?? ??
  • ???? ???? ??
  • ????? ??? ????, ?? ??? ???? ?? ??? ?? ??? ??
  • insmod? ???? ??? ??? ??? ? init???? ??? ??
  • ?? ???? ?? ??
  • ??? ???? ?? chrdevs ??? ??? ?? ???? ??
  • major number ???, 0? ?? ???? ?? ?? ??
  • name ???? ???? /proc/devices? ???
  • fops ????? ??? ?? ?? ??? ???
  • ??? ???? ??? ????? ???

int register_chrdev( unsigned int major, const
name, struct file_operations fops)
22
???? ???? ?? ??(2)
  • ???? ???? ??
  • rmmod ???? ????? ??? ? cleanup ???? ??
  • ?? ???? ?? ??

int unregister_chrdev( unsigned int major, const
name)
23
???? ???? ?? ??(3)
  • ?? ?? ??? ??
  • ???? ????? ???? ??? ??? ?????? ???? ??
  • ? ????? ?? ??? ????, ??? ?? ??? ???? I/O ???
    ????? ????? ??
  • ???? ????? ????? ?? ???? ???? ????? ???? ????
    ????? ??? ?? ??

struct file_operations dummy_fops .owner
THIS_MODULE, .open dummy_open,     .read
dummy_read,         .write dummy_write,   
    .ioctl dummy_ioctl     .release
dummy_release,  
24
???? ???? ?? ??(4)
  • ?? ??? ??
  • read
  • ?????? ???? ???? ??? ??
  • write
  • ????? ???? ?? ??? ??
  • ioctl
  • ????? ???? ??? ??? ?? ??
  • mmap
  • ???? ???? ???? ???? ??
  • open
  • ????? ? ? ??
  • release
  • ????? ?? ? ??

25
?? Dummy ???? ???? ??
  • ?? ?? ? ??? ??

include ltlinux/module.hgt include
ltlinux/kernel.hgt include ltlinux/fs.hgt include
ltlinux/errno.hgt include ltlinux/types.hgt include
ltlinux/fcntl.hgt define DUMMY_NAME
dummy define DUMMY_MAJOR_NUMBER 240
26
?? Dummy ???? ???? ??(2)
  • ???? ??

static int dummy_init(void)         int
ret         printk(dummy init\n)     
ret register_chrdev(DUMMY_MAJOR_NUMBER,     
        DUMMY_NAME, dummy_fops)         if
(res lt 0)                 return
ret         return 0 module_init(dummy_init)
27
?? Dummy ???? ???? ??(3)
  • ???? ??

static void dummy_exit(void)
        printk(dummy exit\n)         unregist
er_chrdev( DUMMY_MAJOR_NUMBER,     
        DUMMY_NAME) module_exit(dummy_exit)
MODULE_LICENSE(GPL)
28
?? Dummy ???? ???? ??(4)
  • ?? ?? ??? ??

struct file_operations dummy_fops .owner
THIS_MODULE, .open dummy_open,   .read
dummy_read,         .write dummy_write,   
   .ioctl dummy_ioctl,     .release
dummy_release,  
29
?? Dummy ???? ???? ??(5)
  • open release

int dummy_open(struct inode inode, struct file
filep)         int num MINOR(inode-gti_rdev)
        printk(dummy dev open -gt minor d\n,
num)         return 0 int
dummy_release(struct inode inode, struct file
filep)         printk(dummy dev
close\n)         return 0
30
?? Dummy ???? ???? ??(6)
  • read write

size_t dummy_read(struct file filep, char buf,
size_t count, loff_t f_pos)         printk(du
mmy dev read -gt buf 0x08x, count 0x08x\n, buf,
count)         return 0x33 size_t
dummy_write(struct file filep, const char buf,
size_t count,         loff_t f_pos)
        printk(dummy dev write -gt buf 0x08x,
count 0x08x\n, buf, count)         return
0x43
31
?? Dummy ???? ???? ??(7)
  • ioctl

int dummy_ioctl(struct inode inode, struct file
filep,         unsigned int cmd, unsigned long
arg)         printk(dummy dev ioctl -gt cmd
0x08x, arg 0x08x\n, cmd, arg)         return
0x53
32
?? Dummy ????? ???? ?? ?????? ??
  • app.c

include ltstdio.hgt include ltsys/types.hgt include
ltsys/stat.hgt include ltsys/ioctl.hgt include
ltfcntl.hgt include ltunistd.hgt define DEV_NAME
/dev/dummy_device int main()         int
dev         char buf128         int
ret         printf(1gt device
open\n)         dev open(DEV_NAME,           
      O_RDWRO_NDELAY)         printf(dev
d\n, dev)         if (dev gt 0)         
                printf(2gt read
function\n)                 ret read(dev,
0x30, 0x31)                 printf(ret
0xx08x\n, ret)                 printf(3gt
write function\n)                 ret
write(dev, 0x40, 0x41)                 printf(re
t 0xx08x\n, ret)                 printf(4gt
ioctl function\n)                 ret
ioctl(dev, 0x51, 0x52)                 printf(re
t 0xx08x\n,                 printf(5gt
device close\n)                 ret
close(dev)                 printf(ret
0xx08x\n, ret)                  return 0
33
?? ???? ???? ?? ? ??
  • ???? ???? ???
  • ?? ?? ??? ??
  • ???? ???? ??
  • insmod dummy.ko
  • ?? ??
  • ????? ???? ???? ??(??)? ???? ?
  • ??(??)? ??? ??? ??
  • mknod /dev/dummy_device c 240 0
  • ???? ???? ??
  • rmmod dummy
  • ????? ?? ??
  • lsmod
Write a Comment
User Comments (0)
About PowerShow.com