SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler offline
Character Device Driver runs in Beaglebone Black
Create a directory in source code and create files in this
directory:
1.Create a character device driver code:
$ vi char_drv.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
int file_open (struct inode *pinode, struct file *pfile)
{
printk(KERN_INFO "Inside the %s functionn",__FUNCTION__);
return 0;
}
size_t file_read (struct file *pfile, char __user *buffer, size_t length, loff_t *offset)
{
printk(KERN_INFO "Inside the %s functionn",__FUNCTION__);
return 0;
}
ssize_t file_write (struct file *pfile, const char __user *buffer, size_t length, loff_t *offset)
{
printk(KERN_INFO "Inside the %s functionn",__FUNCTION__);
return length;
}
int file_close (struct inode *pinode, struct file *pfile)
{
printk(KERN_INFO "Inside the %s functionn",__FUNCTION__);
return 0;
}
/* To hold the file operations performed on the device */
struct file_operations fops = {
.owner = THIS_MODULE,
.open = file_open,
.read = file_read,
.write = file_write,
.release = file_close,
};
Character Device Driver runs in Beaglebone Black
static int __init char_drv_init(void)
{
printk(KERN_INFO "Inside the %s functionn",__FUNCTION__);
/* Register with the kernel and indicate that we are registering character device driver */
register_chrdev(240 /* Major Number */,
"char_drv" /* Name of the driver */,
&fops /* file operations */);
return 0;
}
static void __exit char_drv_exit(void)
{
printk(KERN_INFO "Inside the %s functionn",__FUNCTION__);
/* unregister the character device driver */
unregister_chrdev(240, "char_drv");
}
module_init(char_drv_init);
module_exit(char_drv_exit);
MODULE_LICENSE("GPL");
2. Create Make file:
$ vi Makefile
obj-m += char_drv.o
3. Building the driver:
The kernel path should be given with care, the module should be created with the
same version as used in the kernel path in make command. If the version does not
match with the kernel object file, then we get errors while inserting the kernel
module.
$ make -C <kernel path> M=$PWD ARCH=arm CROSS_COMPILE=arm-linux-
gnueabi- modules
After using this command, you will get kernel object file “char_drv.ko”
Character Device Driver runs in Beaglebone Black
4. Contents of micro sd card:
copy following files to sd card :
# uImage from path arch/arm/boot
# am335x-boneblack.dtb from path arch/arm/boot/dts
# char_drv.ko from directory first_driver
along with these files the sd card should contain MLO, u-boot.img.
5. Boot the beaglebone black board through micro sd card:
After power up the board, stop the terminal using “space bar” to stop auto boot and
to boot u-boot.
u-boot# setenv bootargs console=tty00, 115200n8 root=/dev/mmcblk1p2 ro
rootfstype=ext4 rootwait init=/lib/systemd/systemd
u-boot# fatload mmc 0:1 0x80200000 uImage
u-boot# fatload mmc 0:1 0x82000000 am335x-boneblack.dtb
u-boot# bootm 0x80200000 – 0x82000000
after booting to kernel, it will ask beaglebone login and password:
beaglebone login: debian
password: temppwd
you will get the prompt like this “debian@beaglebone:~$”
$ cd /
$ mount /dev/mmcblk0p1 /mnt
$ cd /mnt
mnt$ ls
am335x-boneblack.dtb MLO uImage
char_drv.ko u-boot.img
Character Device Driver runs in Beaglebone Black
Inserting the module:
mnt$ sudo insmod ./char_drv.ko
[ 101.221609] Inside the char_drv_init function
mnt$ cat /proc/devices // displays the device number attached with driver
240 char_drv
mnt$ sudo mknode -m 666 /dev/char_drv c 240 0 // To do device entry
mnt$ ls -l /dev/char_drv
crw-rw-rw- 1 root root 240 , 0 Jun 27 17:40 /dev/char_drv
Verification of function call during the following operations:
mnt$ cat /dev/char_drv
[ 425.548044] Inside the file_open function
[ 425.554154] Inside the file_read function
[ 425.559639] Inside the file_close function
mnt$ echo “testing” > /dev/char_drv
[ 556.667994] Inside the file_open function
[ 556.674165] Inside the file_write function
[ 556.679561] Inside the file_close function
Removing the module:
mnt$ sudo rmmod char_drv.ko
[ 699.507815] Inside the char_drv_exit function

Mais conteúdo relacionado

Mais procurados

Torrent downloaded from demonoid.com
Torrent downloaded from demonoid.comTorrent downloaded from demonoid.com
Torrent downloaded from demonoid.commark_james_buyao
 
Profiling with Xhprof
Profiling with XhprofProfiling with Xhprof
Profiling with XhprofTim Massey
 
Writing flexible filesystems in FUSE-Python
Writing flexible filesystems in FUSE-PythonWriting flexible filesystems in FUSE-Python
Writing flexible filesystems in FUSE-PythonAnurag Patel
 
MindMap - Forensics Windows Registry Cheat Sheet
MindMap - Forensics Windows Registry Cheat SheetMindMap - Forensics Windows Registry Cheat Sheet
MindMap - Forensics Windows Registry Cheat SheetJuan F. Padilla
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with PerlKazuho Oku
 
DEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them allDEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them allFelipe Prado
 
Remove Duplicate Files & Manage
Remove Duplicate Files & ManageRemove Duplicate Files & Manage
Remove Duplicate Files & Managefolderorganizer
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to ProveKazuho Oku
 
puppet @techlifecookpad
puppet @techlifecookpadpuppet @techlifecookpad
puppet @techlifecookpadNaoya Nakazawa
 
Windows Registry Tips & Tricks
Windows Registry Tips & TricksWindows Registry Tips & Tricks
Windows Registry Tips & TricksRaghav Bisht
 
Chap 5 php files part-2
Chap 5 php files   part-2Chap 5 php files   part-2
Chap 5 php files part-2monikadeshmane
 

Mais procurados (20)

Unix class 5_23
Unix class 5_23Unix class 5_23
Unix class 5_23
 
Python & FUSE
Python & FUSEPython & FUSE
Python & FUSE
 
Git installation
Git installationGit installation
Git installation
 
Torrent downloaded from demonoid.com
Torrent downloaded from demonoid.comTorrent downloaded from demonoid.com
Torrent downloaded from demonoid.com
 
Profiling with Xhprof
Profiling with XhprofProfiling with Xhprof
Profiling with Xhprof
 
Perl Programming - 03 Programming File
Perl Programming - 03 Programming FilePerl Programming - 03 Programming File
Perl Programming - 03 Programming File
 
Writing flexible filesystems in FUSE-Python
Writing flexible filesystems in FUSE-PythonWriting flexible filesystems in FUSE-Python
Writing flexible filesystems in FUSE-Python
 
What we-don't-know
What we-don't-knowWhat we-don't-know
What we-don't-know
 
MindMap - Forensics Windows Registry Cheat Sheet
MindMap - Forensics Windows Registry Cheat SheetMindMap - Forensics Windows Registry Cheat Sheet
MindMap - Forensics Windows Registry Cheat Sheet
 
Distribuido
DistribuidoDistribuido
Distribuido
 
Intro to my sql
Intro to my sqlIntro to my sql
Intro to my sql
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
 
DEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them allDEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them all
 
Remove Duplicate Files & Manage
Remove Duplicate Files & ManageRemove Duplicate Files & Manage
Remove Duplicate Files & Manage
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to Prove
 
puppet @techlifecookpad
puppet @techlifecookpadpuppet @techlifecookpad
puppet @techlifecookpad
 
Windows Registry Tips & Tricks
Windows Registry Tips & TricksWindows Registry Tips & Tricks
Windows Registry Tips & Tricks
 
Chap 5 php files part-2
Chap 5 php files   part-2Chap 5 php files   part-2
Chap 5 php files part-2
 
CS50x Permissions, Files, Users
CS50x Permissions, Files, UsersCS50x Permissions, Files, Users
CS50x Permissions, Files, Users
 
Cpsh sh
Cpsh shCpsh sh
Cpsh sh
 

Destaque

Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)
Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)
Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)HarunyahyaTurkish
 
Tarea 2 sesión virtual aplicaciones
Tarea 2 sesión virtual aplicacionesTarea 2 sesión virtual aplicaciones
Tarea 2 sesión virtual aplicacionesYamilett Mata
 
Potato production in Rwanda
Potato production in RwandaPotato production in Rwanda
Potato production in RwandaHarahagazwe
 
Darwin dna'yı bilseydi. turkish (türkçe)
Darwin dna'yı bilseydi. turkish (türkçe)Darwin dna'yı bilseydi. turkish (türkçe)
Darwin dna'yı bilseydi. turkish (türkçe)HarunyahyaTurkish
 
Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016
Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016
Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016Media Perspectives
 
TIME TREX- 01 - Computación I
TIME TREX- 01 - Computación I TIME TREX- 01 - Computación I
TIME TREX- 01 - Computación I Clarissa Pérez
 
Old Dominion Electrical Supply 4IN PVC SCH 80
Old Dominion Electrical Supply 4IN PVC SCH 80Old Dominion Electrical Supply 4IN PVC SCH 80
Old Dominion Electrical Supply 4IN PVC SCH 80savomir
 

Destaque (13)

Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)
Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)
Becerikli baraj inşaatçıları kunduzlar. turkish (türkçe)
 
Tarea 2 sesión virtual aplicaciones
Tarea 2 sesión virtual aplicacionesTarea 2 sesión virtual aplicaciones
Tarea 2 sesión virtual aplicaciones
 
Potato production in Rwanda
Potato production in RwandaPotato production in Rwanda
Potato production in Rwanda
 
Darwin dna'yı bilseydi. turkish (türkçe)
Darwin dna'yı bilseydi. turkish (türkçe)Darwin dna'yı bilseydi. turkish (türkçe)
Darwin dna'yı bilseydi. turkish (türkçe)
 
Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016
Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016
Presentatie Matt Locke (Storythings) op het Mediapark Jaarcongres 2016
 
TIME TREX- 01 - Computación I
TIME TREX- 01 - Computación I TIME TREX- 01 - Computación I
TIME TREX- 01 - Computación I
 
10 reasons for husband wife disputes
10 reasons for husband wife disputes10 reasons for husband wife disputes
10 reasons for husband wife disputes
 
Southwest airlines
Southwest airlinesSouthwest airlines
Southwest airlines
 
El solitario
El solitarioEl solitario
El solitario
 
Como construir un Banco Digital
Como construir un Banco DigitalComo construir un Banco Digital
Como construir un Banco Digital
 
Old Dominion Electrical Supply 4IN PVC SCH 80
Old Dominion Electrical Supply 4IN PVC SCH 80Old Dominion Electrical Supply 4IN PVC SCH 80
Old Dominion Electrical Supply 4IN PVC SCH 80
 
Trabajo de microsoft word
Trabajo de microsoft wordTrabajo de microsoft word
Trabajo de microsoft word
 
Angostura House of Flavours
Angostura House of FlavoursAngostura House of Flavours
Angostura House of Flavours
 

Semelhante a Character_device_driver_bbb

Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxRajKumar Rampelli
 
Working with core dump
Working with core dumpWorking with core dump
Working with core dumpThierry Gayet
 
Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesYourHelper1
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelDivye Kapoor
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Thomas Petazzoni
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal BootloaderSatpal Parmar
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New HardwareRuggedBoardGroup
 
101 2.2 install boot manager
101 2.2 install boot manager101 2.2 install boot manager
101 2.2 install boot managerAcácio Oliveira
 
Confraria SECURITY & IT - Lisbon Set 29, 2011
Confraria SECURITY & IT - Lisbon Set 29, 2011Confraria SECURITY & IT - Lisbon Set 29, 2011
Confraria SECURITY & IT - Lisbon Set 29, 2011ricardomcm
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ublnewrforce
 
Oracle11g On Fedora14
Oracle11g On Fedora14Oracle11g On Fedora14
Oracle11g On Fedora14kmsa
 

Semelhante a Character_device_driver_bbb (20)

Writing Character driver (loadable module) in linux
Writing Character driver (loadable module) in linuxWriting Character driver (loadable module) in linux
Writing Character driver (loadable module) in linux
 
How to build and load linux to embedded system
How to build and load linux to embedded systemHow to build and load linux to embedded system
How to build and load linux to embedded system
 
Working with core dump
Working with core dumpWorking with core dump
Working with core dump
 
Linux configer
Linux configerLinux configer
Linux configer
 
Char Drivers And Debugging Techniques
Char Drivers And Debugging TechniquesChar Drivers And Debugging Techniques
Char Drivers And Debugging Techniques
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
005 skyeye
005 skyeye005 skyeye
005 skyeye
 
Beagleboard xm-setup
Beagleboard xm-setupBeagleboard xm-setup
Beagleboard xm-setup
 
Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)
 
OS_lab_file.pdf
OS_lab_file.pdfOS_lab_file.pdf
OS_lab_file.pdf
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
101 2.2 install boot manager
101 2.2 install boot manager101 2.2 install boot manager
101 2.2 install boot manager
 
Linux
LinuxLinux
Linux
 
sift_cheat_sheet.pdf
sift_cheat_sheet.pdfsift_cheat_sheet.pdf
sift_cheat_sheet.pdf
 
Confraria SECURITY & IT - Lisbon Set 29, 2011
Confraria SECURITY & IT - Lisbon Set 29, 2011Confraria SECURITY & IT - Lisbon Set 29, 2011
Confraria SECURITY & IT - Lisbon Set 29, 2011
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ubl
 
Oracle11g On Fedora14
Oracle11g On Fedora14Oracle11g On Fedora14
Oracle11g On Fedora14
 
Oracle11g on fedora14
Oracle11g on fedora14Oracle11g on fedora14
Oracle11g on fedora14
 

Character_device_driver_bbb

  • 1. Character Device Driver runs in Beaglebone Black Create a directory in source code and create files in this directory: 1.Create a character device driver code: $ vi char_drv.c #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/fs.h> int file_open (struct inode *pinode, struct file *pfile) { printk(KERN_INFO "Inside the %s functionn",__FUNCTION__); return 0; } size_t file_read (struct file *pfile, char __user *buffer, size_t length, loff_t *offset) { printk(KERN_INFO "Inside the %s functionn",__FUNCTION__); return 0; } ssize_t file_write (struct file *pfile, const char __user *buffer, size_t length, loff_t *offset) { printk(KERN_INFO "Inside the %s functionn",__FUNCTION__); return length; } int file_close (struct inode *pinode, struct file *pfile) { printk(KERN_INFO "Inside the %s functionn",__FUNCTION__); return 0; } /* To hold the file operations performed on the device */ struct file_operations fops = { .owner = THIS_MODULE, .open = file_open, .read = file_read, .write = file_write, .release = file_close, };
  • 2. Character Device Driver runs in Beaglebone Black static int __init char_drv_init(void) { printk(KERN_INFO "Inside the %s functionn",__FUNCTION__); /* Register with the kernel and indicate that we are registering character device driver */ register_chrdev(240 /* Major Number */, "char_drv" /* Name of the driver */, &fops /* file operations */); return 0; } static void __exit char_drv_exit(void) { printk(KERN_INFO "Inside the %s functionn",__FUNCTION__); /* unregister the character device driver */ unregister_chrdev(240, "char_drv"); } module_init(char_drv_init); module_exit(char_drv_exit); MODULE_LICENSE("GPL"); 2. Create Make file: $ vi Makefile obj-m += char_drv.o 3. Building the driver: The kernel path should be given with care, the module should be created with the same version as used in the kernel path in make command. If the version does not match with the kernel object file, then we get errors while inserting the kernel module. $ make -C <kernel path> M=$PWD ARCH=arm CROSS_COMPILE=arm-linux- gnueabi- modules After using this command, you will get kernel object file “char_drv.ko”
  • 3. Character Device Driver runs in Beaglebone Black 4. Contents of micro sd card: copy following files to sd card : # uImage from path arch/arm/boot # am335x-boneblack.dtb from path arch/arm/boot/dts # char_drv.ko from directory first_driver along with these files the sd card should contain MLO, u-boot.img. 5. Boot the beaglebone black board through micro sd card: After power up the board, stop the terminal using “space bar” to stop auto boot and to boot u-boot. u-boot# setenv bootargs console=tty00, 115200n8 root=/dev/mmcblk1p2 ro rootfstype=ext4 rootwait init=/lib/systemd/systemd u-boot# fatload mmc 0:1 0x80200000 uImage u-boot# fatload mmc 0:1 0x82000000 am335x-boneblack.dtb u-boot# bootm 0x80200000 – 0x82000000 after booting to kernel, it will ask beaglebone login and password: beaglebone login: debian password: temppwd you will get the prompt like this “debian@beaglebone:~$” $ cd / $ mount /dev/mmcblk0p1 /mnt $ cd /mnt mnt$ ls am335x-boneblack.dtb MLO uImage char_drv.ko u-boot.img
  • 4. Character Device Driver runs in Beaglebone Black Inserting the module: mnt$ sudo insmod ./char_drv.ko [ 101.221609] Inside the char_drv_init function mnt$ cat /proc/devices // displays the device number attached with driver 240 char_drv mnt$ sudo mknode -m 666 /dev/char_drv c 240 0 // To do device entry mnt$ ls -l /dev/char_drv crw-rw-rw- 1 root root 240 , 0 Jun 27 17:40 /dev/char_drv Verification of function call during the following operations: mnt$ cat /dev/char_drv [ 425.548044] Inside the file_open function [ 425.554154] Inside the file_read function [ 425.559639] Inside the file_close function mnt$ echo “testing” > /dev/char_drv [ 556.667994] Inside the file_open function [ 556.674165] Inside the file_write function [ 556.679561] Inside the file_close function Removing the module: mnt$ sudo rmmod char_drv.ko [ 699.507815] Inside the char_drv_exit function