1 1 Embedded Linux in a Nutshell Marcel Ziswiler Noser Engineering AG
Nov 26, 2015
1 1
Embedded Linux in a Nutshell
Marcel ZiswilerNoser Engineering AG
2 2
ContentsContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
Development Environment Boot Loader Embedded Linux Kernel Root File System Real-World Experience
3
Development Environment
Difference between development vs. final deployment?How to setup DHCP, TFTP and NFS server?
What about a serial terminal console?How to cross compile?
Security?
4
Product Deployment Most embedded systems need to be self-contained Operate from internal flash storage to avoid moving parts (HDs) Update requires lengthy download - flash - re-boot procedure Dynamic data kept on volatile RAM file system
Development Direct network connection to development workstation Linux kernel (and boot loader update) downloaded via TFTP Root file system mounted via NFS Allows for quick development cycle
Development vs. Product DeploymentContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
5
Convenient use of protocols for automatic network configuration
Avoid messing with company network infrastructure
Separate physical network connection Embedded target - development workstation
Plug-and-play USB network adapter No need to open PC to plug in secondary network card Drivers readily available in mainstream Linux distributions
Network SetupContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
6
DHCP server provides complete development configurationhosttarget{filename"uImage";fixedaddress192.168.1.2;hardwareethernet;nextserver192.168.1.1;optionhostname"colibri";optionrootpath"/home/colibri/rootfs";}
TFTP server transfers images to target Embedded Linux kernel Boot loader update
NFS server serves development root file system to target Directory on development host exported as target root Cross compiled binaries immediately available for execution
Network Setup (cont.)Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
7
Target console as a simple means for early debugging Boot loader and Linux kernel output their progress
UARTs available on most embedded controllers/processors
Simple and cheap hardware Level shifters optionally on special debug adapter No need to populate Connectors/headers on production boards
Serial ports still readily available on Pcs/notebooks Use USB to serial adapter on legacy free PCs/notebooks
Simple terminal application minicom -c on and -w parameters to enabe color and line wrap modes
Target Console via Serial TerminalContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
8
Cross compiler allows building executables for target architecture
Cumbersome to build your own toolchainWhat version of gcc, Glibc or rather uClibc?Patches required for my platform?
Third party or pre-built toolchains simplify your lifeCareful they are mostly laid out to be installed at a specific location
Target architecture selectable by environment variables ARCH= CROSS_COMPILE=
or directly on the command-line via makeARCH=CROSS_COMPILE=
9
Pre-built toolchains ARM: emdebian or handhelds.org MIPS: linux-mips.org PowerPC: emdebian
Toolchain building tools Crosstool: kegel.com/crosstool Buildroot: buildroot.uclibc.org OpenEmbedded: openembedded.org Scratchbox: scratchbox.org ELDK: denx.de/wiki/DULG/ELDK
Cross Compiler Toolchain (cont.)Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
10
Make sure your toolchain includes a cross debugger as well
GDB server to be started on the target gdbserver:
Cross debugger to be started on development workstation gdb
Connect to GDB server running on target targetremote:
Now debug your application as usual
Graphical debugging with DDD or even integrate into Eclipse
DebuggerContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
11
Activate firewall (e.g. iptables) Open only minimally required ports
Enable SELinux Allow policy nfs_export_all_rw
Never log into a Unix machine and work as root user Use sudo environment instead
Add user to uucp group for read/write access to serial port
SecurityContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
Service PortName PortNumber TCP/IPProtocolDHCP 67UDPTFTP 69UDPNFS 111UDP
2049UDP32770or32772 UDP
bootpstftpsunrpcnfsmountd
12
Boot Loader
How to boot an embedded system?Who starts the Linux kernel?
How does U-Boot get configured and built?
13
The booting of a system is greatly architecture specific
Boot loader in charge of Initialisation of Hardware
(CPU speed, memory, IRQ, EIA-232) Kernel loading, uncompressing and starting Initialising the RAM disc
Optional monitoring commands Image download Flash access (read/write) System update
Boot LoaderContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
14
Mostly very hardware specific Adapted for one special HW Their own configuration
Generally rather simple device management Only physical memory (e.g. no memory management) Only polling drivers (e.g. no interrupts)
Boot Loader (cont.)Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
15
Das U-Boot a universal boot loader
Most popular open-source Linux boot loader
Contains Ethernet download as well as debug functionality
Includes framework for NAND booting latest micros
Can receive IP parameters via BOOTP or DHCP
Images can be transferred via TFTP, X- or Y-Modem protocol
Make sure to add u-boot's tools directory to PATH or copy tools/mkimage into a searched directory
U-BootContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
16
Download source denx.de/wiki/U-Boot
Extract source tarxjvfuboot1.3.4.tar.bz2
Optionally modify configuration file viinclude/configs/pxa255_idp.h
Configure for your board makepxa255_idp_config
Build make
Configure & Build U-BootContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
17
Linux Kernel
What is the purpose of the Linux kernel?How does it get configured and built?
What about the boot process?
18
Process managementcreate, destroy, IO, IPC, Scheduler
Memory managementVirtual memory area, malloc/free function calls
File systems
Device control
NetworkingTransmission, flow control, routing
Purpose of the Linux KernelContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
19
Overview of the KernelContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
20
Kernel Configuration
Flexibility in what can be configured
Thousands of configuration options
Optimised or even just runnable system requires a carefully
configured kernel
Requires a high level of understanding of one's system
Special third party board support package (BSP) required for
most embedded targets
Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
21
Download source from kernel.org
Extract and optionally patch source tarxjvflinux2.6.26.tar.bz2;cdlinux2.6.26 bzcatpatch2.6.27rc5.bz2|patchp1
Configure for your board makepxa255_idp_defconfig
Optionally modify configuration makemenuconfig
Build makeuImage
Configure & Build Linux KernelContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
22
Loading architecture specific setup code
Upon failure kernel stays in endless loop
Compressed kernel image is decompressed
Rest happens in linux/init/main.c
Low-Level Initialisation (ASM)Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
23
The function start_kernel() does the following steps:
Global kernel lock
Architecture specific setup
Initialisation of IRQs, the scheduler and the softirq sub system
Parsing of the boot command line options
Initialisation of the dynamic module loading facility
High-Level Initialisation (C)Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
24
Releasing interrupts
Initialisation of the structures used by the procfs
fork_init() calculates max_threads based on the available memory
check for bugs
Kernel thread init() is executed trying to spawn init=/sbin/init,/etc/init,/bin/init or /bin/sh. Kernel panic!
Init is the parent of all processes and has a PID of 1
High-Level Initialisation (cont.)Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
25
Root File System
What happens after the kernel got started?What is BusyBox?
How does it get configured and built?
26
The kernel starts /sbin/init as parent of all processes Spawns further daemons (e.g. klogd/syslogd, dropbear) Finally executes the console shell /bin/sh
File system with libraries, daemons (i.e. services) and applications
Reduced complexity compared to regular desktop/server Linux
Root File SystemContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
27
The Swiss Army Knife of embedded Linux
Combines the most important commands in one size optimized
multi-call binary (< 250k)
Either explicitly choose applet /bin/busybox
or just use links /bin/sh>/bin/busybox
BusyBoxContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
28
Download source from busybox.net
Extract and optionally patch source tarxjvfbusybox1.12.0.tar.bz2;cdbusybox1.12.0 patchp1
29
Real-World Experience
Aartec: Customised BSP for embedded panelAndroid: What it is and its Architecture
Toradex: Embedded Linux BSPs for Colibri modules
30
Develops professional embedded panels and controllers
Based on industrial PC and embedded technology
Noser Engineering AG customised Colibri BSP for their TPA200 Implemented and documented a prototype Display parametrisation Remote display functionality using X server with rotation FTP and Telnet server USB memory stick autorun functionality
AartecContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
31
Open-source mobile phone platform initiated by Google Building a better phone for consumers code.google.com/android
Open handset alliance Several companies innovate in the open Increased openness will enable everyone in our industry to
innovate more rapidly and respond better to consumer's demands.
openhandsetalliance.com
Noser Engineering AG works on core functionality
Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
32
Android ArchitectureContents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
33
Colibri XScale PXA270/PXA3xx Modules Embedded computing platform 806 MHz Marvell XScale PXA320 processor 128 MB mobile DDR memory 1 GB NAND flash Audio codec and touch screen controller Fast Ethernet controller Aggressive price/performance ratio
Noser Engineering AG provides the embedded Linux BSP
Contents
Development Environment
Boot Loader
Embedded Linux Kernel
Root File System
Real-World Experience
34
Continuing Books
Advanced Linux Programming by CodeSourcery LLC, Mark L.
Mitchell, Alex Samuel, and Jeffrey Oldham (Jun 11, 2001)
Building Embedded Linux Systems by Karim Yaghmour (April
22, 2003)
Embedded Linux Primer: A Practical Real-World Approach by
Christopher Hallinan (Sep 18, 2006)
Linux Device Drivers, 3rd Edition by Jonathan Corbet,
Alessandro Rubini, and Greg Kroah-Hartman (Feb 7, 2005)
Or just attend one of our next trainings and ask the experts
www.noser.com/linux, [email protected]
Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34