Chapter5_Driver_Firmware
Chapter5_Driver_Firmware
Chapter5_Driver_Firmware
Device Driver
Tien Pham Van, Dr. rer. nat.
Hanoi University of Science and Technology
Compiled with reference to other presentations
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Course Objectives
• System software
• Device driver
• Firmware
• Middleware
• System building
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fundamentals
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded Software
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
System tiers
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
I/O and Devices
Bus
command status data 0
data 1
Device Controller
(firmware and logic) ...
Device X data N-1
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology 6
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
What is firmware?
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
What are device drivers ?
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
I/O System
USB
Network
Device driver SSD
driver
Driver
driver
SSD USB
Network
Device controller controller Dev
controller adapter
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Functions of Device Driver
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Driver - from RTOS perspective
◼ Locating the right device for the I/O request
◼ Locating the right device driver for the device
◼ Issuing the request to the device driver
◼ Ensure synchronized access to the device
◼ Facilitate an abstraction that hides both the device
characteristics and specifics from the application
developers
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
• Device Drivers - RTOS | Coursera
https://www.coursera.org/lecture/iot-
architecture/device-drivers-AL7YG
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
3 I/O Data Transfer techniques
• Polling
• Interrupt-driven I/O
– CPU transfers data between memory and I/O
– Time consuming for high-speed devices
• Direct memory access (DMA)
– OS provides start info: memory address, control
– DMA controller transfers to/from memory
autonomously - direct
– Controller interrupts on completion / error
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
I/O Mechanisms - Polling
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Interrupts - review
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
• Linux device driver lecture 11 : Hello world
module and module build system – YouTube
https://www.youtube.com/watch?v=fWw7gQzYTWc
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Port-Mapped vs. Memory-Mapped
All IO devices must be initialized through device
control registers which located on the CPU board or
in the devices themselves
During operation, the device registers are accessed
again and are programmed to process data transfer
requests
To access these devices, it is necessary for the
developer to determine if the device is port mapped
or memory mapped
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Port-Mapped I/O
The I/O device address space is separate from the system memory address
space, special processor instructions, such as the IN and OUT instructions
offered
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Memory-Mapped IO
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
I/O Subsystem and the Layered Design
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
IO Functions
Function Description
Create Creates a virtual instance of an I/O device
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
C Structure Defining the
Uniform IO API Set
typedef struct
{
int (*Create)( );
int (*Open) ( );
int (*Read)( );
int (*Write) ( );
int (*Close) ( );
int (*Ioctl) ( );
int (*Destroy) ( );
} UNIFORM_IO_DRV;
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Uniform IO Driver Table
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Device tree
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Device tree
https://www.youtube.com/watch?v=Nz6aBff
v-Ek&ab_channel=Bootlin
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
User space driver
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
User space driver
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Firmware
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Features
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
C programming for microcontrollers
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Key steps
1. Identify requirements
2. Differentiate the architecture from the design
3. Manage time constraints (soft, firm, hard real-
time)
4. Design for testing in different levels
5. Foresee customizing plans
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Tools for firmware developments
1. PyCharm
2. WebStorm
3. Qt Creator
4. MPLAB X
5. Visual Studio
6. Eclipse
7. NetBeans
8. MATLAB
9. Arduino
10.ARM Keil
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Middleware
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Concepts
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Popular middlewares in embedded world
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Popular middlewares in embedded world
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
POSIX threads
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
UPnP and DPWS
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Miscellaneous middlewares
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Challenges in building embedded systems
• Systems are huge
• Dependency Hell is a thing
• Builds take a long time
• Builds take a lot of
resources
• Embedded applications
require significant
customization
• Developers need to
modify from defaults
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Build System Defined
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Yocto Project - Getting Started
$ git clone -b rocko \
git://git.yoctoproject.org/poky.git
$ source poky/oe-init-build-env
$ MACHINE=qemux86 bitbake \
core-image-minimal
$ runqemu qemux86
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Buildroot -Overview
“Buildroot is a simple, efficient and easy-to-use tool to
generate embedded Linux systems through cross-
compilation.”1
● Primary output: boot images
● Does not support rpm-style package mgmt
● “Firmware Generator”
● Builds all components from source
● Focus on simplicity
Products:
● Root filesystem image
● Kernel, Bootloader, Toolchain
1 See more at https://buildroot.org/
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Buildroot - Getting Started
$ git clone -b 2018.02 https://git.buildroot.net/buildroot
$ cd buildroot
$ make qemu_arm_vexpress_defconfig
$ make
$ eval $(grep qemu-system-arm board/qemu/arm-vexpress/readme.txt)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
OpenWRT -Overview
Products:
○ Firmware image in device-specific format
○ Network availablepackage repositories
1See more at https://openwrt.org/
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
OpenWRT - Build System
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Desktop Distros
• Use installer from favorite
distro
• Increased usage (Raspberry Pi)
• Slim down to meet your needs
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Summary
Expandability
Configurability
Ease of Getting
Started
Package
Availability
Industry Support
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596