SlideShare una empresa de Scribd logo
1 de 47
Descargar para leer sin conexión
Um estudo nos drivers
                de dispositivo do Linux



                             Tiago Maluta
                           maluta@unifei.edu.br

Monday, June 28, 2010
Evolução

         1991                                  i386


                          avr32, frv, m32r, microblaze, parisc, score, um,
                        alpha, blackfin, h8300, m68k, mips, powerpcsh, x86,
         2010
                        arm, cris, ia64, m68knommu, mn10300, s390, sparc,
                                              xtensa
                                                                 Fonte: www.kernel.org




Monday, June 28, 2010
Como gerenciar este
                           crescimento?



Monday, June 28, 2010
Monday, June 28, 2010
Controle de versão descentralizado


       •      Linus tem seu repositório:
              git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git       Linus
       •      Recebe um e-mail do mantenedor do
              um subsistema
              “Linus, please pull from: ssh://master.kernel.org/pub/scm/linux/


                                                                                     A    B      C
              kernel/git/mchehab/linux-2.6.git v4l_for_2.6.35”




       •      Ele [Linus] faz o merge no seu
              repositório no momento que achar
              adequado.




Monday, June 28, 2010
Módulos no kernel


                         Módulos de sistemas
                            vfat - suporte ao filesystem FAT32
                            usbnet - subsistema de rede com USB
                         Módulos de dispositivo
                            asix - controlador do conversor USB/Ethernet
                            nvidia - placa de vídeo



                        Podem existir módulos proprietários, mas algumas interfaces são
                        exclusivas para licenças livres

Monday, June 28, 2010
#include <stdio.h>

                        static int start(void) {
                            printf(“Hello from userspace!”);
                            return 0;
                        }

                        int main(void) {
                             return start();
                        }




Monday, June 28, 2010
#include <stdio.h>

                        static int start(void) {
                            printf(“Hello from userspace!”);
                            return 0;
                        }

                        int main(void) {
                             return start();
                        }




Monday, June 28, 2010
#include <stdio.h>

                        static int start(void) {
                            printf(“Hello from userspace!”);
                            return 0;
                        }     gcc -Wall main.c -o main
                        int main(void) {
                             return start();
                        }




Monday, June 28, 2010
#include <linux/kernel .h>
                        #include <linux/init .h>
                        #include <linux/module.h>

                        static int __init start(void) {

                            printk(“Hello from kernelspace!”);

                            return 0;
                        }

                        static	void	 __exit	 stop(void) { }

                        module_init(start);
                        module_exit(stop);

                        MODULE_AUTHOR(“”);
                        MODULE_DESCRIPTION(“”);
                        MODULE_LICENSE(“GPL”) ;

Monday, June 28, 2010
#include <linux/kernel .h>
                        #include <linux/init .h>
                        #include <linux/module.h>

                        static int __init start(void) {

                            printk(“Hello from kernelspace!”);

                            return 0;
                        }

                        static	void	 __exit	 stop(void) { }

                        module_init(start);
                        module_exit(stop);

                        MODULE_AUTHOR(“”);
                        MODULE_DESCRIPTION(“”);
                        MODULE_LICENSE(“GPL”) ;

Monday, June 28, 2010
#include <linux/kernel .h>
                        #include <linux/init .h>
                        #include <linux/module.h>

                        static int __init start(void) {

                            printk(“Hello from kernelspace!”);

                            return 0;
                        }

                        static	void	 __exit	 stop(void) { }

                        module_init(start);
                        module_exit(stop);

                        MODULE_AUTHOR(“”);
                        MODULE_DESCRIPTION(“”);
                        MODULE_LICENSE(“GPL”) ;

Monday, June 28, 2010
#include <linux/kernel .h>
                        #include <linux/init .h>
                        #include <linux/module.h>

                        static int __init start(void) {

                            printk(“Hello from kernelspace!”);

                            return 0;
                        }

                        static	void	 __exit	 stop(void) { }

                        module_init(start);
                        module_exit(stop);

                        MODULE_AUTHOR(“”);
                        MODULE_DESCRIPTION(“”);
                        MODULE_LICENSE(“GPL”) ;

Monday, June 28, 2010
#include <linux/kernel .h>
                        #include <linux/init .h>
                        #include <linux/module.h>

                        static int __init start(void) {

                            printk(“Hello from kernelspace!”);

                            return 0;
                        }

                        static	void	 __exit	 stop(void) { }

                        module_init(start);
                        module_exit(stop);

                        MODULE_AUTHOR(“”);
                        MODULE_DESCRIPTION(“”);
                        MODULE_LICENSE(“GPL”) ;

Monday, June 28, 2010
#include <linux/kernel .h>
                             #include <linux/init .h>
                             #include <linux/module.h>

                             static int __init start(void) {

                                 printk(“Hello from kernelspace!”);
                        obj−m:= hello.o
                        KDIR := /lib/modules/$(shell uname −r)/build
                                  return 0;
                        PWD	}:= $(shell pwd)
                        default :
                            $(MAKE) −C __exit	 stop(void) { }
                             static	void	 $(KDIR) M=$(PWD) modules
                        clean :
                             module_init(start);
                            $(MAKE) −C $(KDIR) M=$(PWD) clean
                             module_exit(stop);

                             MODULE_AUTHOR(“”);
                             MODULE_DESCRIPTION(“”);
                             MODULE_LICENSE(“GPL”) ;

Monday, June 28, 2010
Liga


                                  BIOS/EFI


                        Bootloader (GRUB/Lilo/U-boot)


                              Kernel (modo real)


                           Kernel (modo protegido)


                                 Processo init


                            Processos dos usuários




Monday, June 28, 2010
Liga


                                  BIOS/EFI


                        Bootloader (GRUB/Lilo/U-boot)


                              Kernel (modo real)


                           Kernel (modo protegido)


                                 Processo init


                            Processos dos usuários




Monday, June 28, 2010
Liga


                                  BIOS/EFI


                        Bootloader (GRUB/Lilo/U-boot)


                              Kernel (modo real)


                           Kernel (modo protegido)


                                 Processo init


                            Processos dos usuários




Monday, June 28, 2010
Sincronismo

                        • Spinlocks

                        • Mutexes

                        • Operações atômicas




Monday, June 28, 2010
Sincronismo

                        • Spinlocks

                        • Mutexes

                        • Operações atômicas




Monday, June 28, 2010
Sincronismo
                        #include <linux/spinlock .h>

                        spinlock t mylock = SPIN_LOCK_ULOCKED;

                        spin_lock(&mylock );
                            •   Spinlocks
                        /∗ região crítica ∗/
                        spin_unlock(&mylock );


                            • Mutexes

                            • Operações atômicas




Monday, June 28, 2010
Sincronismo
                        #include <linux/spinlock .h>

                        spinlock t mylock = SPIN_LOCK_ULOCKED;

                        spin_lock(&mylock );
                            •   Spinlocks
                        /∗ região crítica ∗/
                        spin_unlock(&mylock );


                            • Mutexes

                            • Operações atômicas




Monday, June 28, 2010
Sincronismo
                         #include <linux/spinlock .h>

                         spinlock t mylock = SPIN_LOCK_ULOCKED;

                         spin_lock(&mylock );
                             •   Spinlocks
                         /∗ região crítica ∗/
                         spin_unlock(&mylock );


                             • Mutexes

                             • Operações atômicas
                        #include <linux/mutex .h>

                        static DEFINE_MUTEX(mymutex);

                        mutex_lock(&mymutex);
                        /∗ região crítica ∗/
                        mutex_unlock(&mymutex);




Monday, June 28, 2010
Facilitadores


                • Udev - para gerenciamento de nós /dev
                • Sysfs - exportar informações para os processos do usuário.
                • Kobjects e Krefs - contador de referências




Monday, June 28, 2010
Udev

                        /etc/udev/rules.d/70-persistent-cd.rules

         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrom", ENV{GENERATED}="1"
         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrw", ENV{GENERATED}="1"
         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvd", ENV{GENERATED}="1"
         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvdrw", ENV{GENERATED}="1"




Monday, June 28, 2010
Udev

                        /etc/udev/rules.d/70-persistent-cd.rules

         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrom", ENV{GENERATED}="1"
         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrw", ENV{GENERATED}="1"
         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvd", ENV{GENERATED}="1"
         ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvdrw", ENV{GENERATED}="1"




Monday, June 28, 2010
sysfs

                           kernel-space         user-space

                             Objetos              Diretórios

                            Atributos             Arquivos

                            Relações         Links simbólicos




               /sys/class/mmc_host/mmc0/device/leds/mmc0::

                         $ echo “1” > brightness
                         $ cat brightness

Monday, June 28, 2010
kobject krefs

               Contador de referências, para o kernel gerenciar o número de
               objetos associados em uma mesma estrutura.


                        struct kobject {                         struct kref {
                            const char *name;                        atomic_t refcount;
                            struct list_head entry;              }
                            struct kobject *parent;
                            struct kset *kset;
                            struct kobj_type *ktype;
                            struct sysfs_dirent *sd;
                            struct kref kref;
                        }




Monday, June 28, 2010
Modelo de Driver do Linux

                O modelo propôs uma representação genérica de objetos:




                        • Devices
                        • Devices drivers
                        • Bus drivers
                        • Devices Classes
                        • Devices Interfaces




Monday, June 28, 2010
Modelo de Driver do Linux

                O modelo propôs uma representação genérica de objetos:




                        • Devices
                        • Devices drivers
                        • Bus drivers
                        • Devices Classes
                        • Devices Interfaces


                  Funções para operar e controlar cada tipo de objeto.




Monday, June 28, 2010
Modelo de Driver do Linux

                O modelo propôs uma representação genérica de objetos:




                        • Devices
                        • Devices drivers
                        • Bus drivers
                        • Devices Classes
                        • Devices Interfaces


                  Funções para operar e controlar cada tipo de objeto.




Monday, June 28, 2010
Modelo de Driver do Linux

                O modelo propôs uma representação genérica de objetos:




                        • Devices                     Um device driver implementa uma ou
                                                      mais interfaces (devices interfaces) de
                        • Devices drivers
                                                      uma    classe   de   dispositivos   (devices
                        • Bus drivers                 classes) para um grupo de dipositivos
                        • Devices Classes             (devices) em um barramento (bus driver)
                                                      específico.
                        • Devices Interfaces


                  Funções para operar e controlar cada tipo de objeto.




Monday, June 28, 2010
USB/Ethernet


                   Ethernet                  USB


                               Controlador




                                 asix.ko


Monday, June 28, 2010
USB/Ethernet

                Preenchimento de estruturas:




Monday, June 28, 2010
USB/Ethernet

                Preenchimento de estruturas:




Monday, June 28, 2010
USB/Ethernet
                        static struct usb_driver asix_driver = {
                            .name =      "asix",
                            .id_table = products,
                            .probe =     usbnet_probe,
                Preenchimento de estruturas:
                            .suspend =    usbnet_suspend,
                            .resume =     usbnet_resume,
                            .disconnect = usbnet_disconnect,
                            .supports_autosuspend = 1,
                        };




Monday, June 28, 2010
USB/Ethernet
                        static struct usb_driver asix_driver = {
                            .name =      "asix",
                            .id_table = products,
                            .probe =     usbnet_probe,
                Preenchimento de estruturas:
                            .suspend =    usbnet_suspend,
                            .resume =     usbnet_resume,
                            .disconnect = usbnet_disconnect,
                            .supports_autosuspend = 1,
                        };




Monday, June 28, 2010
USB/Ethernet
                        static struct usb_driver asix_driver = {
                            .name =      "asix",
                            .id_table = products,
                            .probe =     usbnet_probe,
                Preenchimento de estruturas:
                            .suspend =    usbnet_suspend,
                            .resume =     usbnet_resume,
                            .disconnect = usbnet_disconnect,
                            .supports_autosuspend = 1,
                        };



                        static const struct net_device_ops ax88172_netdev_ops = {
                            .ndo_open           = usbnet_open,
                            .ndo_stop          = usbnet_stop,
                            .ndo_start_xmit        = usbnet_start_xmit,
                            .ndo_tx_timeout         = usbnet_tx_timeout,
                            .ndo_change_mtu          = usbnet_change_mtu,
                            .ndo_set_mac_address = eth_mac_addr,
                            .ndo_validate_addr       = eth_validate_addr,
                            .ndo_do_ioctl        = asix_ioctl,
                            .ndo_set_multicast_list = ax88172_set_multicast,
                        };



Monday, June 28, 2010
USB/Ethernet

                Operações:




Monday, June 28, 2010
USB/Ethernet

                Operações:




Monday, June 28, 2010
USB/Ethernet
          asix_read_cmd             asix_read_medium_status   asix_ioctl
          asix_write_cmd            asix_write_medium_mode    asix_set_mac_address
                Operações:
          asix_async_cmd_callback   asix_write_gpio           ax88172_set_multicast
          asix_write_cmd_async      asix_set_multicast        ax88172_link_reset
          asix_rx_fixup              asix_mdio_read            ax88172_bind
          asix_tx_fixup              asix_mdio_write           ax88772_link_reset

          asix_status               asix_get_phyid            ax88772_bind
          asix_set_sw_mii           asix_get_wol              marvell_phy_init
          asix_set_hw_mii           asix_set_wol              marvell_led_status
          asix_get_phy_addr         asix_get_eeprom_len       ax88178_link_reset

          asix_sw_reset             asix_get_eeprom           ax88178_set_mfb
          asix_read_rx_ctl          asix_get_drvinfo          ax88178_change_mtu
          asix_write_rx_ctl         asix_get_link             ax88178_bind



Monday, June 28, 2010
Conclusão



Monday, June 28, 2010
Crescimento com
      pouca manutenção
      do código.


Monday, June 28, 2010
Padronização das
      estruturas básicas.



Monday, June 28, 2010
Sistemas
      Embarcados



Monday, June 28, 2010
LKML et all;
      Linux Kernel Mail
      List


Monday, June 28, 2010
--tm
Monday, June 28, 2010

Más contenido relacionado

Similar a td

Hardware Open Source
Hardware Open SourceHardware Open Source
Hardware Open SourceTiago Maluta
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Giovanni Bechis
 
lesson03.ppt
lesson03.pptlesson03.ppt
lesson03.pptIraqReshi
 
Linux device driver
Linux device driverLinux device driver
Linux device driverchatsiri
 
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CGrand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CPavel Albitsky
 
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)Masashi Shibata
 
Linux Kernel Startup Code In Embedded Linux
Linux    Kernel    Startup  Code In  Embedded  LinuxLinux    Kernel    Startup  Code In  Embedded  Linux
Linux Kernel Startup Code In Embedded LinuxEmanuele Bonanni
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device driversAlexandre Moreno
 
C Under Linux
C Under LinuxC Under Linux
C Under Linuxmohan43u
 
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureKernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureAnne Nicolas
 
Gregor modules
Gregor modulesGregor modules
Gregor modulesskyshaw
 
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdfrrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdfYodalee
 
step by step to write a gnome-shell extension
step by step to write a gnome-shell extension step by step to write a gnome-shell extension
step by step to write a gnome-shell extension Yuren Ju
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 

Similar a td (20)

Hardware Open Source
Hardware Open SourceHardware Open Source
Hardware Open Source
 
Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)Linux seccomp(2) vs OpenBSD pledge(2)
Linux seccomp(2) vs OpenBSD pledge(2)
 
lesson03.ppt
lesson03.pptlesson03.ppt
lesson03.ppt
 
Linux device driver
Linux device driverLinux device driver
Linux device driver
 
Grand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-CGrand Central Dispatch in Objective-C
Grand Central Dispatch in Objective-C
 
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
 
Microkernel Development
Microkernel DevelopmentMicrokernel Development
Microkernel Development
 
Driver_linux
Driver_linuxDriver_linux
Driver_linux
 
Linux Kernel Startup Code In Embedded Linux
Linux    Kernel    Startup  Code In  Embedded  LinuxLinux    Kernel    Startup  Code In  Embedded  Linux
Linux Kernel Startup Code In Embedded Linux
 
Linux Device Driver’s
Linux Device Driver’sLinux Device Driver’s
Linux Device Driver’s
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
 
C Under Linux
C Under LinuxC Under Linux
C Under Linux
 
Kernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architectureKernel Recipes 2015 - Porting Linux to a new processor architecture
Kernel Recipes 2015 - Porting Linux to a new processor architecture
 
Gregor modules
Gregor modulesGregor modules
Gregor modules
 
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdfrrxv6 Build a Riscv xv6 Kernel in Rust.pdf
rrxv6 Build a Riscv xv6 Kernel in Rust.pdf
 
Sysprog 14
Sysprog 14Sysprog 14
Sysprog 14
 
Oop 1
Oop 1Oop 1
Oop 1
 
step by step to write a gnome-shell extension
step by step to write a gnome-shell extension step by step to write a gnome-shell extension
step by step to write a gnome-shell extension
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

td

  • 1. Um estudo nos drivers de dispositivo do Linux Tiago Maluta maluta@unifei.edu.br Monday, June 28, 2010
  • 2. Evolução 1991 i386 avr32, frv, m32r, microblaze, parisc, score, um, alpha, blackfin, h8300, m68k, mips, powerpcsh, x86, 2010 arm, cris, ia64, m68knommu, mn10300, s390, sparc, xtensa Fonte: www.kernel.org Monday, June 28, 2010
  • 3. Como gerenciar este crescimento? Monday, June 28, 2010
  • 5. Controle de versão descentralizado • Linus tem seu repositório: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git Linus • Recebe um e-mail do mantenedor do um subsistema “Linus, please pull from: ssh://master.kernel.org/pub/scm/linux/ A B C kernel/git/mchehab/linux-2.6.git v4l_for_2.6.35” • Ele [Linus] faz o merge no seu repositório no momento que achar adequado. Monday, June 28, 2010
  • 6. Módulos no kernel Módulos de sistemas vfat - suporte ao filesystem FAT32 usbnet - subsistema de rede com USB Módulos de dispositivo asix - controlador do conversor USB/Ethernet nvidia - placa de vídeo Podem existir módulos proprietários, mas algumas interfaces são exclusivas para licenças livres Monday, June 28, 2010
  • 7. #include <stdio.h> static int start(void) { printf(“Hello from userspace!”); return 0; } int main(void) { return start(); } Monday, June 28, 2010
  • 8. #include <stdio.h> static int start(void) { printf(“Hello from userspace!”); return 0; } int main(void) { return start(); } Monday, June 28, 2010
  • 9. #include <stdio.h> static int start(void) { printf(“Hello from userspace!”); return 0; } gcc -Wall main.c -o main int main(void) { return start(); } Monday, June 28, 2010
  • 10. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 11. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 12. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 13. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 14. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); return 0; } static void __exit stop(void) { } module_init(start); module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 15. #include <linux/kernel .h> #include <linux/init .h> #include <linux/module.h> static int __init start(void) { printk(“Hello from kernelspace!”); obj−m:= hello.o KDIR := /lib/modules/$(shell uname −r)/build return 0; PWD }:= $(shell pwd) default : $(MAKE) −C __exit stop(void) { } static void $(KDIR) M=$(PWD) modules clean : module_init(start); $(MAKE) −C $(KDIR) M=$(PWD) clean module_exit(stop); MODULE_AUTHOR(“”); MODULE_DESCRIPTION(“”); MODULE_LICENSE(“GPL”) ; Monday, June 28, 2010
  • 16. Liga BIOS/EFI Bootloader (GRUB/Lilo/U-boot) Kernel (modo real) Kernel (modo protegido) Processo init Processos dos usuários Monday, June 28, 2010
  • 17. Liga BIOS/EFI Bootloader (GRUB/Lilo/U-boot) Kernel (modo real) Kernel (modo protegido) Processo init Processos dos usuários Monday, June 28, 2010
  • 18. Liga BIOS/EFI Bootloader (GRUB/Lilo/U-boot) Kernel (modo real) Kernel (modo protegido) Processo init Processos dos usuários Monday, June 28, 2010
  • 19. Sincronismo • Spinlocks • Mutexes • Operações atômicas Monday, June 28, 2010
  • 20. Sincronismo • Spinlocks • Mutexes • Operações atômicas Monday, June 28, 2010
  • 21. Sincronismo #include <linux/spinlock .h> spinlock t mylock = SPIN_LOCK_ULOCKED; spin_lock(&mylock ); • Spinlocks /∗ região crítica ∗/ spin_unlock(&mylock ); • Mutexes • Operações atômicas Monday, June 28, 2010
  • 22. Sincronismo #include <linux/spinlock .h> spinlock t mylock = SPIN_LOCK_ULOCKED; spin_lock(&mylock ); • Spinlocks /∗ região crítica ∗/ spin_unlock(&mylock ); • Mutexes • Operações atômicas Monday, June 28, 2010
  • 23. Sincronismo #include <linux/spinlock .h> spinlock t mylock = SPIN_LOCK_ULOCKED; spin_lock(&mylock ); • Spinlocks /∗ região crítica ∗/ spin_unlock(&mylock ); • Mutexes • Operações atômicas #include <linux/mutex .h> static DEFINE_MUTEX(mymutex); mutex_lock(&mymutex); /∗ região crítica ∗/ mutex_unlock(&mymutex); Monday, June 28, 2010
  • 24. Facilitadores • Udev - para gerenciamento de nós /dev • Sysfs - exportar informações para os processos do usuário. • Kobjects e Krefs - contador de referências Monday, June 28, 2010
  • 25. Udev /etc/udev/rules.d/70-persistent-cd.rules ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrom", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrw", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvd", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvdrw", ENV{GENERATED}="1" Monday, June 28, 2010
  • 26. Udev /etc/udev/rules.d/70-persistent-cd.rules ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrom", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="cdrw", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvd", ENV{GENERATED}="1" ENV{ID_CDROM}=="?*", ENV{ID_PATH}=="ide-1:0", SYMLINK+="dvdrw", ENV{GENERATED}="1" Monday, June 28, 2010
  • 27. sysfs kernel-space user-space Objetos Diretórios Atributos Arquivos Relações Links simbólicos /sys/class/mmc_host/mmc0/device/leds/mmc0:: $ echo “1” > brightness $ cat brightness Monday, June 28, 2010
  • 28. kobject krefs Contador de referências, para o kernel gerenciar o número de objetos associados em uma mesma estrutura. struct kobject { struct kref { const char *name; atomic_t refcount; struct list_head entry; } struct kobject *parent; struct kset *kset; struct kobj_type *ktype; struct sysfs_dirent *sd; struct kref kref; } Monday, June 28, 2010
  • 29. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices • Devices drivers • Bus drivers • Devices Classes • Devices Interfaces Monday, June 28, 2010
  • 30. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices • Devices drivers • Bus drivers • Devices Classes • Devices Interfaces Funções para operar e controlar cada tipo de objeto. Monday, June 28, 2010
  • 31. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices • Devices drivers • Bus drivers • Devices Classes • Devices Interfaces Funções para operar e controlar cada tipo de objeto. Monday, June 28, 2010
  • 32. Modelo de Driver do Linux O modelo propôs uma representação genérica de objetos: • Devices Um device driver implementa uma ou mais interfaces (devices interfaces) de • Devices drivers uma classe de dispositivos (devices • Bus drivers classes) para um grupo de dipositivos • Devices Classes (devices) em um barramento (bus driver) específico. • Devices Interfaces Funções para operar e controlar cada tipo de objeto. Monday, June 28, 2010
  • 33. USB/Ethernet Ethernet USB Controlador asix.ko Monday, June 28, 2010
  • 34. USB/Ethernet Preenchimento de estruturas: Monday, June 28, 2010
  • 35. USB/Ethernet Preenchimento de estruturas: Monday, June 28, 2010
  • 36. USB/Ethernet static struct usb_driver asix_driver = { .name = "asix", .id_table = products, .probe = usbnet_probe, Preenchimento de estruturas: .suspend = usbnet_suspend, .resume = usbnet_resume, .disconnect = usbnet_disconnect, .supports_autosuspend = 1, }; Monday, June 28, 2010
  • 37. USB/Ethernet static struct usb_driver asix_driver = { .name = "asix", .id_table = products, .probe = usbnet_probe, Preenchimento de estruturas: .suspend = usbnet_suspend, .resume = usbnet_resume, .disconnect = usbnet_disconnect, .supports_autosuspend = 1, }; Monday, June 28, 2010
  • 38. USB/Ethernet static struct usb_driver asix_driver = { .name = "asix", .id_table = products, .probe = usbnet_probe, Preenchimento de estruturas: .suspend = usbnet_suspend, .resume = usbnet_resume, .disconnect = usbnet_disconnect, .supports_autosuspend = 1, }; static const struct net_device_ops ax88172_netdev_ops = { .ndo_open = usbnet_open, .ndo_stop = usbnet_stop, .ndo_start_xmit = usbnet_start_xmit, .ndo_tx_timeout = usbnet_tx_timeout, .ndo_change_mtu = usbnet_change_mtu, .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, .ndo_do_ioctl = asix_ioctl, .ndo_set_multicast_list = ax88172_set_multicast, }; Monday, June 28, 2010
  • 39. USB/Ethernet Operações: Monday, June 28, 2010
  • 40. USB/Ethernet Operações: Monday, June 28, 2010
  • 41. USB/Ethernet asix_read_cmd asix_read_medium_status asix_ioctl asix_write_cmd asix_write_medium_mode asix_set_mac_address Operações: asix_async_cmd_callback asix_write_gpio ax88172_set_multicast asix_write_cmd_async asix_set_multicast ax88172_link_reset asix_rx_fixup asix_mdio_read ax88172_bind asix_tx_fixup asix_mdio_write ax88772_link_reset asix_status asix_get_phyid ax88772_bind asix_set_sw_mii asix_get_wol marvell_phy_init asix_set_hw_mii asix_set_wol marvell_led_status asix_get_phy_addr asix_get_eeprom_len ax88178_link_reset asix_sw_reset asix_get_eeprom ax88178_set_mfb asix_read_rx_ctl asix_get_drvinfo ax88178_change_mtu asix_write_rx_ctl asix_get_link ax88178_bind Monday, June 28, 2010
  • 43. Crescimento com pouca manutenção do código. Monday, June 28, 2010
  • 44. Padronização das estruturas básicas. Monday, June 28, 2010
  • 45. Sistemas Embarcados Monday, June 28, 2010
  • 46. LKML et all; Linux Kernel Mail List Monday, June 28, 2010