Interface Hardware-Software
IHS - §7 Driver Intro 2
Tópicos
1) Device Driver Introduction 2) Linux embedded system 3) Cross compile
Tópicos
1) Device Driver Introduction
2) Linux embedded system 3) Cross compile
IHS - §7 Driver Intro 4
Input/Output Device Access
I/O Communication Infrastructure - Hardware
IHS - §7 Driver Intro 6
HW Controllers
I/O devices are managed by HW controllers Transfer data to/from device
Synchronize operations with software Have a working protocol
Usually have a standard communication interface Controllers have different registers:
Command Registers: Initiate some device operation
Status Registers: Indicate what the device is doing and the occurrence of errors
IHS - §7 Driver Intro 8
I/O Communication Infrastructure - Software
Device Drivers
SW specific to a device used by the higher layers Manage device usage
Provides an API for higher SW layers System calls usually call device drivers
Usually provides 6 basic features for using the device Device Initialization/Reset Open Close Read Write I/O control
IHS - §7 Driver Intro 10
Device Driver Development
Requires good understanding how the device's HW controller (working protocol) and bus work
Requires the writing of very complex code that
includes many specific details of the HW device often represents the largest SW part of a system Employs generally high-level languages
Specific small parts written in assembly
Many system libraries or routines available that allow low level access for high level languages
x86 Support for I/O Communication
The x86 processor instruction set supports two I/O communication mechanisms:
1) Memory mapped I/O
Memory reading and writing instructions (e.g. mov) 2) Specific Instructions for I/O ports
Read/write instructions for I/O ports (e.g. in and out) See later, Accessing the speaker
IHS - §7 Driver Intro 12
What Does Driver Development Involve?
In addition to the code required to perform the operations offered by a device, Operation Systems impose rules and procedures for
developing a driver: Register Driver
Inform the Driver type
Associate a driver with a unique identifier in the OS Associate a driver with one or more devices
Sign the operations that will be implemented within the interface established by OS
Associate Driver with an I/O port
OS Support for Driver Development
As mentioned, great part of the code is written in high level languages (C or C ++)
Operating systems offer libraries or software development kits (SDKs) for faster and more systematic driver development
Standard Interfaces for different device classes
Functions already implemented to register, enable and release drivers as well as add devices, among others
IHS - §7 Driver Intro 14
Linux Driver Development
Drivers are developed in layers
One less specific to the bus/device communication interface and another more specific
Provides driver development libraries for a variety of buses PCI, USB, Firewire, etc
Differences in features do not allow a single driver development standard for different communication interface types
Tópicos
1) Device Driver Introduction
2) Linux embedded system
IHS - §7 Driver Intro 16
NXP I.MX 7Dual SABRE Board
ARM Cortex-A7 (1GHz) Memory 1GB DDR3
Display/Camera Connectors Wireless
Ethernet, USB, PCI, SIM card slot
Accelerometer,
Magnetometer, Gyroscope, Barometer, Altimeter
Microchip SAMA5D2 Xplained Ultra board
ARM Cortex-A5 Memory 2GB DDR3 SD/MMC interface USB RGB LCDISC interface and
connector (Image sensor) Expansion connector
User push button Tri-color user LED
IHS - §7 Driver Intro 18
Broadcom BCM2837 board
Raspberry Pi 3 Model A+ ARM Cortex-A53 Memory 512MB SDRAM Wireless, Bluetooth HDMICSI camera port DSI display port
4-pole stereo output Composite video port Micro SD port
IHS - §7 Driver Intro 20
Linux embedded architecture
Linux embedded system
Bootloader:
Configures the memory system
Loads the kernel image and the device tree Kernel: Core of the OS
Lowest level of software
Manages the HW, runs user programs, maintains system security and integrity
System call interface
Allows user space applications to interact with the kernel Generally not invoked directly but rather through wrapper functions in the C runtime library, like glibc, newlib, …,
IHS - §7 Driver Intro 22
Linux embedded system (cont.)
System shared library
Linked with an user space application to provide it access to a specific system functionality
Abstracts the complexities of the kernel or direct driver access Examples (required by the Linux standard base): libc, libm,
libcrypt, …
Root filesystem
Stores all the files contained in the file hierarchy (including device nodes)
Includes, e.g., /bin, /sbin, /etc, /root, /tmp, /boot, /opt,
Build Embedded Linux Systems
Creating your own scripts
Using complete distributions, e.g., Ubuntu, Debian, Raspbian, … Preselected kernel version and a root filesystem with a
preselected set of libraries, utilities and applications Easy to get started, but harder to customize
Using Build frameworks, e.g., Buildroot, Yocto
Scripts and configuration meta-data that control the build process
Downloads, configures, compiles and installs all required components of the system taking version conflicts and dependencies into account
IHS - §7 Driver Intro 24
Build Framework Yocto
Typical Steps Using a Complete Distribution
Building the Linux kernel Cross-compile
Cross-compiler executables are prefixed by the name of the target system
Compress and write kernel image on SD card Use tools like Etcher
Copying Files
Transfer files from the host to the target using ssh
The IP address, the Netmask and Gateway need to be set Copy a simple “Hello World” app to the target system
IHS - §7 Driver Intro 26
Tópicos
1) Device Driver Introduction 2) Linux embedded system
Cross Compile User Space Apps with Eclipse
1) New C Project
IHS - §7 Driver Intro 28
Cross Compile User Space Apps with Eclipse
Driver Development
A key concept in the design of the Linux embedded system is the separation of user applications from the underlying hardware
The hardware is exclusively accessed via kernel drivers Provides robustness
Provides portability
Device drivers can be kernel modules or statically built into the kernel image
Building a device driver as a module makes the development easier since it can be loaded, tested, and unloaded without rebooting the kernel
The kernel modules are usually located in /lib/modules/ <kernel_version>/ on the root filesystem
IHS - §7 Driver Intro 30
Cross Compile User Space Apps with Docker
InfoWorld article Containers 101: Linux container and Docker
explained: “[containers are] something that feels like a virtual
machine, but sheds all the weight and startup overhead of a guest operating system”
Advantage: Large number of already configured docker images available, e.g., docker pull mitchallen/pi-cross-compile
Build a “Hello, World” example with Docker: docker run -it -v ~/ raspberry/hello:/build mitchallen/pi-cross-compile
Uses a Makefile
Example: Cross Compile Linux Kernel
Docker image: docker pull simonvanderveldt/rpi3-kernel-builder
Checkout kernel sources: git clone --single-branch --branch rpi-4.14.y --depth 1 https://www.github.com/raspberrypi/linux
Build a kernel archive with the docker image using a volume mount:
docker run --rm -ti -v "${PWD}":/workdir rpi3-kernel-builder
To apply patches to the kernel sources make the patches available at PATCH_DIRS
The kernel can be configured using a defconfig:
make ARCH=arm bcm2709_defconfig make ARCH=arm menuconfig