SlideShare a Scribd company logo
1 of 40
Download to read offline
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Developing and testing a device driver
without the device
1
git clone --recurse-submodules git@github.com:mdionisio/linuxlab2018.git
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
BEFORE WE START
2
git clone --recurse-submodules git@github.com :mdionisio/linuxlab2018.git
apt-get install build-essential
apt-get install crossbuild-essential-armhf
apt-get install gcc-arm-linux-gnueabihf
apt-get install gcc-arm-none-eabi
apt-get install libncurses5-dev
apt-get install bison flex libssl-dev bc
apt-get install python pkg-config libglib2.0-dev libpixman-1-dev
apt-get install sudo cpio lzop gzip
apt-get install gdb-multiarch
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Who we are
3
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
What we will see
4
1. Qemu
a. Introduction
b. Developing a new simple emulated device
c. Adding it to an existing machine
2. Test
a. Simple bare-metal cortex a9 project
b. Test and debug with qemu
3. Test with Linux
a. Create a minimal rootfs
4. Develop a test a linux driver
a. Developing device driver
b. Adding it to and existing board configuring the device tree
c. Test
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com 5
Image coming from qemu web site: www.qemu.org
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Device Specification
6
1. One memory mapped RW registry. You can read on it the last value write plus 1.
2. If you write 1 and interrupt is raised and writing 0 the interrupt is acknowledged
Device is installed in a custom board
coming from Sambrelite board
This board is based on i.mx6 that is a ARM Cortex A9 MP processor so we will use a
gcc for that platform for developing and testing
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
And now …. A brief introduction to QOM.
And jump to the C code
7
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
We have the device emulated and we
can start to add it to a machine emulated.
So go back to the QEMU source code
8
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
A bare metal CORTEX-A9
startup.S
9
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
And now LINUX
10
To develop and test a linux device driver we need a working Linux system.
So before start to develop we have to create a minimal Linux system.
1. Build linux kernel
2. Build busybox
3. Build a minimal rootfs that can be mounted in ram. INITRAMFS
The result is not a full linux distribution but is something perfect for develop and test.
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Test the created Linux system
11
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com 12
Questions ?
Image coming from film Io Robot
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Organization of a Linux system
13
© CC BY-SA 3.0 Bootlin, 2004-2018
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Role of the Linux kernel
▸ Interact with the underlying hardware
▸ Provide a set of portable, architecture-independent API
▸ Handle concurrent access
14
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Interacting with the kernel: syscalls
▸ Kernel and userspace communicate using system calls, or syscalls
▹ A modern Linux kernel implements around 300 syscalls
▸ Syscalls are propagated by the kernel to the dedicated driver
▸ Drivers handle the request and return a status code to the calling process
15
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Interacting with the kernel: pseudo-filesystems
▸ Kernel can also present statistics and configurations using pseudo-filesystems
▸ Usually mounted automatically at boot
▸ Several pseudo-filesystems exist with different roles
▹ proc, mounted on /proc
▹ sysfs, mounted on /sys
16
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Kernel organization
17
© CC BY-SA 3.0 Bootlin, 2004-2018
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Working on the Linux kernel
18
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Cross-compiling
19
▸ By default, Linux is configured and built for the host system
▸ Use ARCH and CROSS_COMPILE variables to change target platform
▸ Different configuration options are available for different platforms
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Configuring the kernel
20
▸ To use an existing configuration: make <config-name>_defconfig
▹ Configurations available in arch/<arch>/configs/
▸ To modify the current configuration: make menuconfig
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Building the kernel
21
▸ To build the kernel: make -jN
▸ Build outputs
▹ ./vmlinux
▹ ./arch/<arch>/boot/*Image
▹ ./arch/<arch>/boot/dts/*.dtb
▹ ./**/*.ko
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Writing a kernel driver
22
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Hello World!
23
▸ (Optional) Create a dedicated directory under drivers/
▸ Create the necessary Kconfig options and Makefile rules
▸ Write code!
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Some words of warning
▸ A kernel module is not a userspace application!
▹ Does not execute sequentially
▹ Does no automatic cleanup
▹ Can be interrupted
▹ Does not have floating-point support
24
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Device drivers
25
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
▸ Access to the hardware is abstracted as a stream of bytes
▹ Serial ports and text consoles are example of char devices
▸ Many hardware peripherals can be abstracted as char devices
▹ Flash memories
▹ Frame grabbers
▹ ADC, DAC, shift registers
Character device
26
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Majors and minors
27
▸ Char devices are accessed using device nodes
▹ Usually located in the /dev directory
▸ A combination of major and minor is used to identify the device
▹ The major number identifies the device driver
▹ Minors usually identify a device instance of a given driver
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Platform drivers
28
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Platform device
▸ A device located on a bus with minimal infrastructure
▹ Most peripheral controllers on ARM SoCs are platform devices
▸ Usually addressed directly by the CPU
▹ Eg. using memory-mapped registers
▸ In Linux, they are handled using platform drivers
29
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Platform driver
▸ Implemented using struct platform_driver
▹ Registered using platform_driver_register()
▸ Enumeration is performed by the kernel
▹ During enumeration, .probe() is invoked
▹ During shutdown, .remove() is invoked
▸ The driver should actually check that the hardware exists
30
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Device Tree
31
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Device Tree
32
▸ Embedded architectures often have non-discoverable peripherals
▹ This is the case for ARM processors, for example
▸ We need a way to describe the hardware connected to such platforms
▸ Enter the Device Tree!
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Device Tree
33
▸ Organized in .dts and .dtsi files
▸ Compiled in .dtb files
▸ Several roles in the Linux kernel
▹ Describing devices attached to non-discoverable buses
▹ Configure pin muxing on SoCs
▹ Configure some system parameters (memory layout, flash partitioning etc.)
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Device Tree
34
#include "imx6q.dtsi"
#include "imx6qdl-sabrelite.dtsi"
/ {
model = "Freescale i.MX6 Quad SABRE Lite Board";
compatible = "fsl,imx6q-sabrelite", "fsl,imx6q";
soc {
qemudev: qemu-test@50000000 {
compatible = "linuxlab,qemu-test";
reg = <0x50000000 4>;
status = "okay";
};
};
};
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
I/O operations
35
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
I/O operations
▸ I/O operations performed on device nodes are propagated to the driver
▹ open(), read(), write(), close(), …
▸ Drivers need to define a callback for each handled syscall
▸ This is done using the struct file_operations
▹ Structure members are all function pointers
36
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Common file operations
▸ open() – called each time the device is opened from userspace
▸ read() – called when data is sent from the device to userspace
▸ write() – called when data is sent from userspace to the device
▸ release() – called when the device is closed in userspace
37
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Exchanging data with userspace
▸ Special care must be used to access user memory pointers in I/O callbacks
▹ User memory is different from kernel memory, and can’t be accessed directly
▸ copy_to_user() – Copy data from kernel memory to user memory
▸ copy_from_user() – Copy data from user memory to kernel memory
38
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Interrupt handling
39
Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com
Interrupts
▸ Most peripherals or devices use interrupts to signal asynchronous events
▹ ADC conversion performed, SPI transfer completed, etc.
▸ In Linux, drivers can request to serve one or more specific interrupts
▹ Usually each peripheral controller has its own interrupt line
▸ A device tree entry can be used to specify the interrupt index
▹ Interrupt numbering is platform- and controller-specific
40

More Related Content

What's hot

Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchlinuxlab_conf
 
Tommaso Cucinotta - Low-latency and power-efficient audio applications on Linux
Tommaso Cucinotta - Low-latency and power-efficient audio applications on LinuxTommaso Cucinotta - Low-latency and power-efficient audio applications on Linux
Tommaso Cucinotta - Low-latency and power-efficient audio applications on Linuxlinuxlab_conf
 
MOVED: RDK/WPE Port on DB410C - SFO17-206
MOVED: RDK/WPE Port on DB410C - SFO17-206MOVED: RDK/WPE Port on DB410C - SFO17-206
MOVED: RDK/WPE Port on DB410C - SFO17-206Linaro
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Golinuxlab_conf
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectYen-Chin Lee
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to BottomKernel TLV
 
BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108Linaro
 
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Linaro
 
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSDLAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSDLinaro
 
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗Macpaul Lin
 
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...linuxlab_conf
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Kernel TLV
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesLinaro
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 
BKK16-309A Open Platform support in UEFI
BKK16-309A Open Platform support in UEFIBKK16-309A Open Platform support in UEFI
BKK16-309A Open Platform support in UEFILinaro
 
Using SoC Vendor HALs in the Zephyr Project - SFO17-112
Using SoC Vendor HALs in the Zephyr Project - SFO17-112Using SoC Vendor HALs in the Zephyr Project - SFO17-112
Using SoC Vendor HALs in the Zephyr Project - SFO17-112Linaro
 
Yocto Project introduction
Yocto Project introductionYocto Project introduction
Yocto Project introductionYi-Hsiu Hsu
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardAnne Nicolas
 
LAS16-400K2: TianoCore – Open Source UEFI Community Update
LAS16-400K2: TianoCore – Open Source UEFI Community UpdateLAS16-400K2: TianoCore – Open Source UEFI Community Update
LAS16-400K2: TianoCore – Open Source UEFI Community UpdateLinaro
 

What's hot (20)

Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Tommaso Cucinotta - Low-latency and power-efficient audio applications on Linux
Tommaso Cucinotta - Low-latency and power-efficient audio applications on LinuxTommaso Cucinotta - Low-latency and power-efficient audio applications on Linux
Tommaso Cucinotta - Low-latency and power-efficient audio applications on Linux
 
MOVED: RDK/WPE Port on DB410C - SFO17-206
MOVED: RDK/WPE Port on DB410C - SFO17-206MOVED: RDK/WPE Port on DB410C - SFO17-206
MOVED: RDK/WPE Port on DB410C - SFO17-206
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Go
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto project
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
 
BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108BSD Sockets API in Zephyr RTOS - SFO17-108
BSD Sockets API in Zephyr RTOS - SFO17-108
 
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
Secure Boot on ARM systems – Building a complete Chain of Trust upon existing...
 
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSDLAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
LAS16-210: Hardware Assisted Tracing on ARM with CoreSight and OpenCSD
 
OpenWRT and Perl
OpenWRT and PerlOpenWRT and Perl
OpenWRT and Perl
 
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
 
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...
Luca Cipriani - Control your Embedded Linux remotely by using MQTT and a web ...
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
BKK16-309A Open Platform support in UEFI
BKK16-309A Open Platform support in UEFIBKK16-309A Open Platform support in UEFI
BKK16-309A Open Platform support in UEFI
 
Using SoC Vendor HALs in the Zephyr Project - SFO17-112
Using SoC Vendor HALs in the Zephyr Project - SFO17-112Using SoC Vendor HALs in the Zephyr Project - SFO17-112
Using SoC Vendor HALs in the Zephyr Project - SFO17-112
 
Yocto Project introduction
Yocto Project introductionYocto Project introduction
Yocto Project introduction
 
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime RipardKernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
Kernel Recipes 2017 - An introduction to the Linux DRM subsystem - Maxime Ripard
 
LAS16-400K2: TianoCore – Open Source UEFI Community Update
LAS16-400K2: TianoCore – Open Source UEFI Community UpdateLAS16-400K2: TianoCore – Open Source UEFI Community Update
LAS16-400K2: TianoCore – Open Source UEFI Community Update
 

Similar to Michele Dionisio & Pietro Lorefice - Developing and testing a device driver without the device

The Container Security Checklist
The Container Security Checklist The Container Security Checklist
The Container Security Checklist LibbySchulze
 
Jump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & GithubJump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & Githubhubx
 
Upgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with SecurebootUpgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with SecurebootJonathan MICHEL-VILLAZ
 
There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018
There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018
There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018Giulio Vian
 
Introduction to Linux Kernel Development
Introduction to Linux Kernel DevelopmentIntroduction to Linux Kernel Development
Introduction to Linux Kernel DevelopmentLevente Kurusa
 
DevNet Associate : Python introduction
DevNet Associate : Python introductionDevNet Associate : Python introduction
DevNet Associate : Python introductionJoel W. King
 
the NML project
the NML projectthe NML project
the NML projectLei Yang
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made EasyAlon Fliess
 
Kernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootKernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootAnne Nicolas
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...Felipe Prado
 
A million ways to provision embedded linux devices
A million ways to provision embedded linux devicesA million ways to provision embedded linux devices
A million ways to provision embedded linux devicesMender.io
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushPantheon
 
Open Source Virtualization Hacks
Open Source Virtualization HacksOpen Source Virtualization Hacks
Open Source Virtualization HacksNiel Bornstein
 
TIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by stepTIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by stepThe Incredible Automation Day
 
Bkk16 309B Enterprise Firmware - The gold standard and how to get there
Bkk16 309B Enterprise Firmware - The gold standard and how to get thereBkk16 309B Enterprise Firmware - The gold standard and how to get there
Bkk16 309B Enterprise Firmware - The gold standard and how to get thereLinaro
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Fabrice Bernhard
 
2.4.0 software installation v2
2.4.0 software installation v22.4.0 software installation v2
2.4.0 software installation v2Acácio Oliveira
 
AV Evasion with the Veil Framework
AV Evasion with the Veil FrameworkAV Evasion with the Veil Framework
AV Evasion with the Veil FrameworkVeilFramework
 

Similar to Michele Dionisio & Pietro Lorefice - Developing and testing a device driver without the device (20)

The Container Security Checklist
The Container Security Checklist The Container Security Checklist
The Container Security Checklist
 
Jump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & GithubJump into Squeak - Integrate Squeak projects with Docker & Github
Jump into Squeak - Integrate Squeak projects with Docker & Github
 
Upgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with SecurebootUpgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with Secureboot
 
There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018
There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018
There and Back Again (My DevOps journey) - DevOps Days Copenhagen 2018
 
101 1.2 boot the system
101 1.2 boot the system101 1.2 boot the system
101 1.2 boot the system
 
Introduction to Linux Kernel Development
Introduction to Linux Kernel DevelopmentIntroduction to Linux Kernel Development
Introduction to Linux Kernel Development
 
DevNet Associate : Python introduction
DevNet Associate : Python introductionDevNet Associate : Python introduction
DevNet Associate : Python introduction
 
the NML project
the NML projectthe NML project
the NML project
 
C# Production Debugging Made Easy
 C# Production Debugging Made Easy C# Production Debugging Made Easy
C# Production Debugging Made Easy
 
Kernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using BuildrootKernel Recipes 2013 - Easy rootfs using Buildroot
Kernel Recipes 2013 - Easy rootfs using Buildroot
 
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
DEF CON 27 - HUBER AND ROSKOSCH - im on your phone listening attacking voip c...
 
A million ways to provision embedded linux devices
A million ways to provision embedded linux devicesA million ways to provision embedded linux devices
A million ways to provision embedded linux devices
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
 
Open Source Virtualization Hacks
Open Source Virtualization HacksOpen Source Virtualization Hacks
Open Source Virtualization Hacks
 
TIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by stepTIAD - DYI: A simple orchestrator built step by step
TIAD - DYI: A simple orchestrator built step by step
 
Bkk16 309B Enterprise Firmware - The gold standard and how to get there
Bkk16 309B Enterprise Firmware - The gold standard and how to get thereBkk16 309B Enterprise Firmware - The gold standard and how to get there
Bkk16 309B Enterprise Firmware - The gold standard and how to get there
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
2.4.0 software installation v2
2.4.0 software installation v22.4.0 software installation v2
2.4.0 software installation v2
 
AV Evasion with the Veil Framework
AV Evasion with the Veil FrameworkAV Evasion with the Veil Framework
AV Evasion with the Veil Framework
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 

More from linuxlab_conf

Jonathan Corbet - Keynote: The Kernel Report
Jonathan Corbet - Keynote: The Kernel ReportJonathan Corbet - Keynote: The Kernel Report
Jonathan Corbet - Keynote: The Kernel Reportlinuxlab_conf
 
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...linuxlab_conf
 
Bruno Verachten - The Android device farm that fits in a (cloudy) pocket
Bruno Verachten - The Android device farm that fits in a (cloudy) pocketBruno Verachten - The Android device farm that fits in a (cloudy) pocket
Bruno Verachten - The Android device farm that fits in a (cloudy) pocketlinuxlab_conf
 
Jacopo Mondi - Complex cameras are complex
Jacopo Mondi - Complex cameras are complexJacopo Mondi - Complex cameras are complex
Jacopo Mondi - Complex cameras are complexlinuxlab_conf
 
Alessio Lama - Development and testing of a safety network protocol
Alessio Lama - Development and testing of a safety network protocolAlessio Lama - Development and testing of a safety network protocol
Alessio Lama - Development and testing of a safety network protocollinuxlab_conf
 
Dario Faggioli - Virtualization in the age of speculative execution HW bugs
Dario Faggioli - Virtualization in the age of speculative execution HW bugsDario Faggioli - Virtualization in the age of speculative execution HW bugs
Dario Faggioli - Virtualization in the age of speculative execution HW bugslinuxlab_conf
 
Luca Abeni - Real-Time Virtual Machines with Linux and kvm
Luca Abeni - Real-Time Virtual Machines with Linux and kvmLuca Abeni - Real-Time Virtual Machines with Linux and kvm
Luca Abeni - Real-Time Virtual Machines with Linux and kvmlinuxlab_conf
 

More from linuxlab_conf (7)

Jonathan Corbet - Keynote: The Kernel Report
Jonathan Corbet - Keynote: The Kernel ReportJonathan Corbet - Keynote: The Kernel Report
Jonathan Corbet - Keynote: The Kernel Report
 
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...
Marco Cavallini - Yocto Project, an automatic generator of embedded Linux dis...
 
Bruno Verachten - The Android device farm that fits in a (cloudy) pocket
Bruno Verachten - The Android device farm that fits in a (cloudy) pocketBruno Verachten - The Android device farm that fits in a (cloudy) pocket
Bruno Verachten - The Android device farm that fits in a (cloudy) pocket
 
Jacopo Mondi - Complex cameras are complex
Jacopo Mondi - Complex cameras are complexJacopo Mondi - Complex cameras are complex
Jacopo Mondi - Complex cameras are complex
 
Alessio Lama - Development and testing of a safety network protocol
Alessio Lama - Development and testing of a safety network protocolAlessio Lama - Development and testing of a safety network protocol
Alessio Lama - Development and testing of a safety network protocol
 
Dario Faggioli - Virtualization in the age of speculative execution HW bugs
Dario Faggioli - Virtualization in the age of speculative execution HW bugsDario Faggioli - Virtualization in the age of speculative execution HW bugs
Dario Faggioli - Virtualization in the age of speculative execution HW bugs
 
Luca Abeni - Real-Time Virtual Machines with Linux and kvm
Luca Abeni - Real-Time Virtual Machines with Linux and kvmLuca Abeni - Real-Time Virtual Machines with Linux and kvm
Luca Abeni - Real-Time Virtual Machines with Linux and kvm
 

Recently uploaded

Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 

Recently uploaded (20)

Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 

Michele Dionisio & Pietro Lorefice - Developing and testing a device driver without the device

  • 1. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Developing and testing a device driver without the device 1 git clone --recurse-submodules git@github.com:mdionisio/linuxlab2018.git
  • 2. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com BEFORE WE START 2 git clone --recurse-submodules git@github.com :mdionisio/linuxlab2018.git apt-get install build-essential apt-get install crossbuild-essential-armhf apt-get install gcc-arm-linux-gnueabihf apt-get install gcc-arm-none-eabi apt-get install libncurses5-dev apt-get install bison flex libssl-dev bc apt-get install python pkg-config libglib2.0-dev libpixman-1-dev apt-get install sudo cpio lzop gzip apt-get install gdb-multiarch
  • 3. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Who we are 3
  • 4. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com What we will see 4 1. Qemu a. Introduction b. Developing a new simple emulated device c. Adding it to an existing machine 2. Test a. Simple bare-metal cortex a9 project b. Test and debug with qemu 3. Test with Linux a. Create a minimal rootfs 4. Develop a test a linux driver a. Developing device driver b. Adding it to and existing board configuring the device tree c. Test
  • 5. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com 5 Image coming from qemu web site: www.qemu.org
  • 6. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Device Specification 6 1. One memory mapped RW registry. You can read on it the last value write plus 1. 2. If you write 1 and interrupt is raised and writing 0 the interrupt is acknowledged Device is installed in a custom board coming from Sambrelite board This board is based on i.mx6 that is a ARM Cortex A9 MP processor so we will use a gcc for that platform for developing and testing
  • 7. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com And now …. A brief introduction to QOM. And jump to the C code 7
  • 8. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com We have the device emulated and we can start to add it to a machine emulated. So go back to the QEMU source code 8
  • 9. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com A bare metal CORTEX-A9 startup.S 9
  • 10. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com And now LINUX 10 To develop and test a linux device driver we need a working Linux system. So before start to develop we have to create a minimal Linux system. 1. Build linux kernel 2. Build busybox 3. Build a minimal rootfs that can be mounted in ram. INITRAMFS The result is not a full linux distribution but is something perfect for develop and test.
  • 11. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Test the created Linux system 11
  • 12. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com 12 Questions ? Image coming from film Io Robot
  • 13. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Organization of a Linux system 13 © CC BY-SA 3.0 Bootlin, 2004-2018
  • 14. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Role of the Linux kernel ▸ Interact with the underlying hardware ▸ Provide a set of portable, architecture-independent API ▸ Handle concurrent access 14
  • 15. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Interacting with the kernel: syscalls ▸ Kernel and userspace communicate using system calls, or syscalls ▹ A modern Linux kernel implements around 300 syscalls ▸ Syscalls are propagated by the kernel to the dedicated driver ▸ Drivers handle the request and return a status code to the calling process 15
  • 16. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Interacting with the kernel: pseudo-filesystems ▸ Kernel can also present statistics and configurations using pseudo-filesystems ▸ Usually mounted automatically at boot ▸ Several pseudo-filesystems exist with different roles ▹ proc, mounted on /proc ▹ sysfs, mounted on /sys 16
  • 17. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Kernel organization 17 © CC BY-SA 3.0 Bootlin, 2004-2018
  • 18. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Working on the Linux kernel 18
  • 19. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Cross-compiling 19 ▸ By default, Linux is configured and built for the host system ▸ Use ARCH and CROSS_COMPILE variables to change target platform ▸ Different configuration options are available for different platforms
  • 20. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Configuring the kernel 20 ▸ To use an existing configuration: make <config-name>_defconfig ▹ Configurations available in arch/<arch>/configs/ ▸ To modify the current configuration: make menuconfig
  • 21. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Building the kernel 21 ▸ To build the kernel: make -jN ▸ Build outputs ▹ ./vmlinux ▹ ./arch/<arch>/boot/*Image ▹ ./arch/<arch>/boot/dts/*.dtb ▹ ./**/*.ko
  • 22. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Writing a kernel driver 22
  • 23. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Hello World! 23 ▸ (Optional) Create a dedicated directory under drivers/ ▸ Create the necessary Kconfig options and Makefile rules ▸ Write code!
  • 24. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Some words of warning ▸ A kernel module is not a userspace application! ▹ Does not execute sequentially ▹ Does no automatic cleanup ▹ Can be interrupted ▹ Does not have floating-point support 24
  • 25. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Device drivers 25
  • 26. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com ▸ Access to the hardware is abstracted as a stream of bytes ▹ Serial ports and text consoles are example of char devices ▸ Many hardware peripherals can be abstracted as char devices ▹ Flash memories ▹ Frame grabbers ▹ ADC, DAC, shift registers Character device 26
  • 27. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Majors and minors 27 ▸ Char devices are accessed using device nodes ▹ Usually located in the /dev directory ▸ A combination of major and minor is used to identify the device ▹ The major number identifies the device driver ▹ Minors usually identify a device instance of a given driver
  • 28. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Platform drivers 28
  • 29. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Platform device ▸ A device located on a bus with minimal infrastructure ▹ Most peripheral controllers on ARM SoCs are platform devices ▸ Usually addressed directly by the CPU ▹ Eg. using memory-mapped registers ▸ In Linux, they are handled using platform drivers 29
  • 30. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Platform driver ▸ Implemented using struct platform_driver ▹ Registered using platform_driver_register() ▸ Enumeration is performed by the kernel ▹ During enumeration, .probe() is invoked ▹ During shutdown, .remove() is invoked ▸ The driver should actually check that the hardware exists 30
  • 31. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Device Tree 31
  • 32. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Device Tree 32 ▸ Embedded architectures often have non-discoverable peripherals ▹ This is the case for ARM processors, for example ▸ We need a way to describe the hardware connected to such platforms ▸ Enter the Device Tree!
  • 33. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Device Tree 33 ▸ Organized in .dts and .dtsi files ▸ Compiled in .dtb files ▸ Several roles in the Linux kernel ▹ Describing devices attached to non-discoverable buses ▹ Configure pin muxing on SoCs ▹ Configure some system parameters (memory layout, flash partitioning etc.)
  • 34. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Device Tree 34 #include "imx6q.dtsi" #include "imx6qdl-sabrelite.dtsi" / { model = "Freescale i.MX6 Quad SABRE Lite Board"; compatible = "fsl,imx6q-sabrelite", "fsl,imx6q"; soc { qemudev: qemu-test@50000000 { compatible = "linuxlab,qemu-test"; reg = <0x50000000 4>; status = "okay"; }; }; };
  • 35. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com I/O operations 35
  • 36. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com I/O operations ▸ I/O operations performed on device nodes are propagated to the driver ▹ open(), read(), write(), close(), … ▸ Drivers need to define a callback for each handled syscall ▸ This is done using the struct file_operations ▹ Structure members are all function pointers 36
  • 37. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Common file operations ▸ open() – called each time the device is opened from userspace ▸ read() – called when data is sent from the device to userspace ▸ write() – called when data is sent from userspace to the device ▸ release() – called when the device is closed in userspace 37
  • 38. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Exchanging data with userspace ▸ Special care must be used to access user memory pointers in I/O callbacks ▹ User memory is different from kernel memory, and can’t be accessed directly ▸ copy_to_user() – Copy data from kernel memory to user memory ▸ copy_from_user() – Copy data from user memory to kernel memory 38
  • 39. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Interrupt handling 39
  • 40. Pietro Lorefice | Develer S.r.l. | pietro@develer.comMichele Dionisio | Powersoft SPA | michele.dionisio@powersoft.com Interrupts ▸ Most peripherals or devices use interrupts to signal asynchronous events ▹ ADC conversion performed, SPI transfer completed, etc. ▸ In Linux, drivers can request to serve one or more specific interrupts ▹ Usually each peripheral controller has its own interrupt line ▸ A device tree entry can be used to specify the interrupt index ▹ Interrupt numbering is platform- and controller-specific 40