Skip to main content

Posts

User application to test char driver

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int8_t write_buf[1024];
int8_t read_buf[1024];
int main()
{
        int fd;
        char option;
        printf("*********************************\n");
        printf("*******Char driver test application*******\n");

        fd = open("/dev/lk_device", O_RDWR);
        if(fd < 0) {
                printf("Cannot open device file...\n");
                return 0;
        }

        while(1) {
                printf("****Please Enter the Option******\n");
                printf("        1. Write               \n");
                printf("        2. Read                 \n");
                printf("        3. Exit                 \n");
                printf("*********************************\n");
                …
Recent posts

Linux Kernel Drivers -- Char , Mutex, Spinlock, Kthread, Tasklet

Makefile:
--------------------

//obj-m += mod.o
//bj-m += char.o
//obj-m += kthread.o
//obj-m += mutex.o
//obj-m += slock.o
//obj-m += rwslock.o
//obj-m += interrupt.o
//obj-m += workqueue.o
obj-m += tasklet.o


KDIR = /lib/modules/$(shell uname -r)/build

all:
        make -C $(KDIR) M=$(shell pwd) modules

clean:
        make -C $(KDIR) M=$(shell pwd) clean




Driver for Simple Module:
--------------------------------------

#include <linux/module.h>
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/time.h>

static int __init lk_init(void) /* Constructor */
{
    printk(KERN_INFO "Welcome to Linux Kernel:Insert Module");
    return 0;
    //sleep(100);
}

static void __exit lk_exit(void) /* Destructor */
{
    printk(KERN_INFO "Remove : Remove Module");
}

module_init(lk_init);
module_exit(lk_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("G Satish Kumar");
MODULE_DESCRIPTION("FIrst Module");


Char Driver…

Linux Kernel Porting to New Architecture. includes Processor Specific & Board Specific

1.Processor-specific or Architecture changes to the kernel code
1.  The number of TLB3 (translation look aside buffers) entries may be different for different implementations.
2. Add a config option (CONFIG_MYCPU) to include code that is specific to the processor. 
3.  Directories $(TOPDIR)/arch/MY_ARCH/kernel and $(TOPDIR)/arch/MY_ARCH/mm  contain the processor-specific code that require modifications if you are dealing with a new implementation.
4. Assembly file $(TOPDIR)/arch/MY_ARCH/kernel/head.S contains kernel_entry, the entry point for the kernel.  This file also contains the exception handling code. Listing 1 shows the implementation of the kernel_entry routine in pseudo code.
5. Kernel entry pseudo code:  Set desired endian modeClear the BEV bitSet the TLB bitGOTO cpu_probe and returnSet up stack for kernelClear bssGOTO prom_init and returnGOTO loadmmu and returnDisable coprocessorsGOTO start_kernel        la       t3, mips_cputype
       b       probe_done
       sw       t2, (t3)
END(c…