2008/12/3 Rene Gonzalez <[EMAIL PROTECTED]> > Hi guys I'm a beginner in Android and Linux kernel. As an entry point to > Android first of all I have to deal with the Linux kernel so one of the > first tasks that I have to do is a simple driver
You don't need to start with the linux kernel to use Android. First consider what task to you need to achieve, later you'll decide if you need to use the linux kernel or not. > runnable or configurable as module or embedded into the kernel (this > configuration has been done within the menuconfig). Let me introduce my > source code that I tried: > > #define PROCFS_MAX_SIZE 80 > #define procfs_name "calc1" > > static struct proc_dir_entry *Our_Proc_File; Careful with the coding style. You're advised to always follow the coding style of the software you are using. For linux, see: http://pantransit.reptiles.org/prog/CodingStyle.html > > static unsigned long procfs_buffer_size = 0; > > int procfile_read (char *buffer, char **buffer_location, off_t offset, int > buffer_length, int *eof, void *data) > { > int ret; > if (offset > 0) // we have finished to read, return 0 > ret = 0; > > else // fill the buffer, return the buffer size > ret = sprintf(buffer, "%s= %d\n",equation,solution); > //variables defined somewhere else > return ret; > } > > // This function is called with the /proc file is written > int procfile_write(struct file *file, const char *buffer, unsigned long > count, void *data) > { > int i; > procfs_buffer_size = count; > > for (i=0; i<count-1; i++) > equation[i]= buffer[i]; > equation[i]= '\0'; > calc1(); //this function is defined somewhere else > return procfs_buffer_size; > } > > int init_module() > { > Our_Proc_File = create_proc_entry(procfs_name, 0644, NULL); > > if (Our_Proc_File == NULL) > { > remove_proc_entry(procfs_name, &proc_root); > printk(KERN_ALERT "Error: Not initialize /proc/%s\n", > procfs_name); > return -ENOMEM; > } > > Our_Proc_File->read_proc = procfile_read; > Our_Proc_File->write_proc = procfile_write; > Our_Proc_File->owner = THIS_MODULE; > Our_Proc_File->mode = S_IFREG | S_IRUGO; > Our_Proc_File->uid = 0; > Our_Proc_File->gid = 0; > Our_Proc_File->size = 37; > > printk(KERN_ALERT "/proc/%s created\n", procfs_name); > return 0; // everything is ok > } > > void cleanup_module() > { > remove_proc_entry(procfs_name, &proc_root); > printk(KERN_ALERT "/proc/%s removed\n", procfs_name); > } > > MODULE_LICENSE("Dual BSD/GPL");RT_SYMBOL(procfile_write); > A book about linux is "Linux Device Drivers, 3rd edition", available at: http://lwn.net/Kernel/LDD3/ > > > This works fine as module an initializing with insmod & ending with rmmod > constructs. the main goal is that, if it's a module avoid the needed of the > uses of insmod/rmmod constructs or....... if this is embedded into the > kernel....I coulded find and use this driver. > > If any one can help me to fix that I'll be really grateful: > - How to link or init the module without using the insmod/rmmod > constructs, and > - If the driver (module) is embedded into th kernel, where is it placed or > haw to use it. > This could be confusing. You have to browse linux directory structure a little to find where to place your module. The idea is that you add a macro corresponding to the functionality you added to the kernel in the corresponding Kconfig file in the proper directory. Also, you add the list of code files you added to the Makefile. > > > In advance many thaks for any help, > Best regards. > Reno. > Bye, > > > > -- Henrique Dante de Almeida [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ unsubscribe: [EMAIL PROTECTED] website: http://groups.google.com/group/android-kernel -~----------~----~----~----~------~----~------~--~---
