On Saturday 27 August 2011 21:07:31 André Barboza wrote:
> Qual a versão do kernel?

2.6.37.6

> Qual erro?

gcc memory.c
memory.c:2:24: fatal error: linux/init.h: Arquivo ou diretório não encontrado
compilation terminated.


gcc paralelport.c
paralelport.c:2:24: fatal error: linux/init.h: Arquivo ou diretório não 
encontrado
compilation terminated.

Os fontes do kernel estão instalados em /usr/src/linux.


> 
> 2011/8/27 Jorge Barros de Abreu <[email protected]>
> 
> > Olá.
> > 
> > Preciso de ajuda com esse tutorial. O título é:
> > 
> > Writing device drivers in Linux: A brief tutorial
> > 
> > O link é:
> > 
> > http://www.freesoftwaremagazine.com/node/1238/pdf
> > 
> > Não consegui fazer a compilação do memory.c e nem do paralelport.c
> > 
> > nem com gcc nem com makefile.
> > 
> > memory.c
> > ###################
> > /* Necessary includes for device drivers */
> > #include <linux/init.h>
> > #include <linux/config.h>
> > #include <linux/module.h>
> > #include <linux/kernel.h> /* printk() */
> > #include <linux/slab.h> /* kmalloc() */
> > #include <linux/fs.h> /* everything... */
> > #include <linux/errno.h> /* error codes */
> > #include <linux/types.h> /* size_t */
> > #include <linux/proc_fs.h>
> > #include <linux/fcntl.h> /* O_ACCMODE */
> > #include <asm/system.h> /* cli(), *_flags */
> > #include <asm/uaccess.h> /* copy_from/to_user */
> > 
> > MODULE_LICENSE("Dual BSD/GPL");
> > 
> > /* Declaration of memory.c functions */
> > int memory_open(struct inode *inode, struct file *filp);
> > int memory_release(struct inode *inode, struct file *filp);
> > ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t
> > *f_pos);
> > ssize_t memory_write(struct file *filp, char *buf, size_t count, loff_t
> > *f_pos);
> > void memory_exit(void);
> > int memory_init(void);
> > 
> > /* Structure that declares the usual file */
> > /* access functions */
> > struct file_operations memory_fops = {
> > 
> >  read: memory_read,
> >  write: memory_write,
> >  open: memory_open,
> >  release: memory_release
> > 
> > };
> > 
> > /* Declaration of the init and exit functions */
> > module_init(memory_init);
> > module_exit(memory_exit);
> > 
> > /* Global variables of the driver */
> > /* Major number */
> > int memory_major = 60;
> > /* Buffer to store data */
> > char *memory_buffer;
> > 
> > 
> > 
> > 
> > 
> > 
> > int memory_init(void) {
> > 
> >  int result;
> >  
> >  /* Registering device */
> >  result = register_chrdev(memory_major, "memory", &memory_fops);
> >  if (result < 0) {
> >  
> >    printk(
> >    
> >      "<1>memory: cannot obtain major number %d\n", memory_major);
> >    
> >    return result;
> >  
> >  }
> >  
> >  /* Allocating memory for the buffer */
> >  memory_buffer = kmalloc(1, GFP_KERNEL);
> >  if (!memory_buffer) {
> >  
> >    result = -ENOMEM;
> >    goto fail;
> >  
> >  }
> >  memset(memory_buffer, 0, 1);
> >  
> >  printk("<1>Inserting memory module\n");
> >  return 0;
> >  
> >  fail:
> >    memory_exit();
> >    return result;
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > 
> > void memory_exit(void) {
> > 
> >  /* Freeing the major number */
> >  unregister_chrdev(memory_major, "memory");
> >  
> >  /* Freeing buffer memory */
> >  if (memory_buffer) {
> >  
> >    kfree(memory_buffer);
> >  
> >  }
> >  
> >  printk("<1>Removing memory module\n");
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > 
> > int memory_open(struct inode *inode, struct file *filp) {
> > 
> >  /* Success */
> >  return 0;
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > 
> > ssize_t memory_read(struct file *filp, char *buf,
> > 
> >                    size_t count, loff_t *f_pos) {
> >  
> >  /* Transfering data to user space */
> >  copy_to_user(buf,memory_buffer,1);
> >  
> >  /* Changing reading position as best suits */
> >  if (*f_pos == 0) {
> >  
> >    *f_pos+=1;
> >    return 1;
> >  
> >  } else {
> >  
> >    return 0;
> >  
> >  }
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > ssize_t memory_write( struct file *filp, char *buf,
> > 
> >                      size_t count, loff_t *f_pos) {
> >  
> >  char *tmp;
> >  
> >  tmp=buf+count-1;
> >  copy_from_user(memory_buffer,tmp,1);
> >  return 1;
> > 
> > }
> > 
> > 
> > 
> > Paralelport.c
> > #################
> > /* Necessary includes for drivers */
> > #include <linux/init.h>
> > #include <linux/config.h>
> > #include <linux/module.h>
> > #include <linux/kernel.h> /* printk() */
> > #include <linux/slab.h> /* kmalloc() */
> > #include <linux/fs.h> /* everything... */
> > #include <linux/errno.h> /* error codes */
> > #include <linux/types.h> /* size_t */
> > #include <linux/proc_fs.h>
> > #include <linux/fcntl.h> /* O_ACCMODE */
> > #include <linux/ioport.h>
> > #include <asm/system.h> /* cli(), *_flags */
> > #include <asm/uaccess.h> /* copy_from/to_user */
> > #include <asm/io.h> /* inb, outb */
> > 
> > MODULE_LICENSE("Dual BSD/GPL");
> > 
> > /* Function declaration of parlelport.c */
> > int parlelport_open(struct inode *inode, struct file *filp);
> > int parlelport_release(struct inode *inode, struct file *filp);
> > ssize_t parlelport_read(struct file *filp, char *buf,
> > 
> >                       size_t count, loff_t *f_pos);
> > 
> > ssize_t parlelport_write(struct file *filp, char *buf,
> > 
> >                       size_t count, loff_t *f_pos);
> > 
> > void parlelport_exit(void);
> > int parlelport_init(void);
> > 
> > /* Structure that declares the common */
> > /* file access fcuntions */
> > struct file_operations parlelport_fops = {
> > 
> >  read: parlelport_read,
> >  write: parlelport_write,
> >  open: parlelport_open,
> >  release: parlelport_release
> > 
> > };
> > 
> > /* Driver global variables */
> > /* Major number */
> > int parlelport_major = 61;
> > 
> > /* Control variable for memory */
> > /* reservation of the parallel port*/
> > int port;
> > 
> > module_init(parlelport_init);
> > module_exit(parlelport_exit);
> > 
> > 
> > 
> > 
> > int parlelport_init(void) {
> > 
> >  int result;
> >  /* Registering device */
> >  result = register_chrdev(parlelport_major, "parlelport",
> >  
> >      &parlelport_fops);
> >  
> >  if (result < 0) {
> >  
> >    printk(
> >    
> >      "<1>parlelport: cannot obtain major number %d\n",
> >      parlelport_major);
> >    
> >    return result;
> >  
> >  }
> >  <parlelport modified init module>
> >  printk("<1>Inserting parlelport module\n");
> >  return 0;
> >  
> >  fail:
> >    parlelport_exit();
> >    return result;
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > void parlelport_exit(void) {
> > 
> >  /* Make major number free! */
> >  unregister_chrdev(parlelport_major, "parlelport");
> >  <parlelport modified exit module>
> >  printk("<1>Removing parlelport module\n");
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > 
> > int parlelport_open(struct inode *inode, struct file *filp) {
> > 
> >  /* Success */
> >  return 0;
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > int parlelport_release(struct inode *inode, struct file *filp) {
> > 
> >  /* Success */
> >  return 0;
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > ssize_t parlelport_read(struct file *filp, char *buf,
> > 
> >  size_t count, loff_t *f_pos) {
> >  /* Buffer to read the device */
> >  char parlelport_buffer;
> >  <parlelport inport>
> >  /* We transfer data to user space */
> >  copy_to_user(buf,&parlelport_buffer,1);
> >  /* We change the reading position as best suits */
> >  if (*f_pos == 0) {
> >  
> >    *f_pos+=1;
> >    return 1;
> >  
> >  } else {
> >  
> >    return 0;
> >  
> >  }
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > 
> > ssize_t parlelport_write( struct file *filp, char *buf,
> > size_t count, loff_t *f_pos) {
> > 
> >  char *tmp;
> >  /* Buffer writing to the device */
> >  char parlelport_buffer;
> > 
> > }
> > 
> > 
> > 
> > 
> > 
> > tmp=buf+count-1;
> > copy_from_user(&parlelport_buffer,tmp,1);
> > 
> >  <parlelport outport>
> >  return 1;
> > 
> > }
> > 
> > 
> > 
> > --
> > Data Estelar 2455801,305336
> > http://sites.google.com/site/ficmatinf
> > Desejo-lhe Paz, Vida Longa e Prosperidade.
> > São Bem Vindas Mensagens no Formato texto UTF-8 com Acentos.
> > 
> > --
> > GUS-BR - Grupo de Usuários de Slackware Brasil
> > http://www.slackwarebrasil.org/
> > http://groups.google.com/group/slack-users-br
> > 
> > Antes de perguntar:
> > http://www.istf.com.br/perguntas/
> > 
> > Para sair da lista envie um e-mail para:
> > [email protected]

-- 
Data Estelar 2455802,425509
http://sites.google.com/site/ficmatinf
Desejo-lhe Paz, Vida Longa e Prosperidade.
São Bem Vindas Mensagens no Formato texto UTF-8 com Acentos.

-- 
GUS-BR - Grupo de Usuários de Slackware Brasil
http://www.slackwarebrasil.org/
http://groups.google.com/group/slack-users-br

Antes de perguntar:
http://www.istf.com.br/perguntas/

Para sair da lista envie um e-mail para:
[email protected]

Responder a