12/07/13 - Marc Leeman
Company Confidential - 1
Basic Introduction to
Embedded Linux
Barco Seminar
11/07/2013
Marc Leeman
12/07/13 - Marc Leeman
Company Confidential - 2
Patches Accepted
● 11th time we do this training
● 5th time based on SheevaPlug
● Bear with us
● Developed over time
● Inconsistencies in course text/slides(?)
● Feedback welcome!
12/07/13 - Marc Leeman
Company Confidential - 3
Goals
● Huge topic, so only introduction
● Hands on, examples, share experience
● Become acquainted with typical small
footprint embedded Linux
● Where to look for setting up or obtaining
a cross compile toolchain environment
● Get to know the typical bootloaders
● Lots-of-examples
12/07/13 - Marc Leeman
Company Confidential - 4
Hardware
● SheevaPlug
● Marvell Arm Kirkwood processor
● 1.2 GHz
● 512 MB RAM
● U-Boot bootloader
● 512 MB NAND Flash
● Gb Ethernet, Serial, SD Card, USB, ...
12/07/13 - Marc Leeman
Company Confidential - 5
SheevaPlug
12/07/13 - Marc Leeman
Company Confidential - 6
Contents
● The GNU/Linux System
● System Overview
● System Design
● Cross Compilation Toolchain
● The Linux Boot Process
● Boot Loaders
● The Linux Kernel
● File Systems
● Userspace
12/07/13 - Marc Leeman
Company Confidential - 7
The GNU/Linux System
12/07/13 - Marc Leeman
Company Confidential - 8
● Computer operating system and its
kernel -> GNU/Linux, GNU+Linux, ...
● The GNU Project (1983)
● Hurd kernel 1990
● Linux kernel: 1991
● Estimated cost typical linux distribution is
10.8 billion; the kernel alone an extra 1.4
billion (2008, Fedora 9)
● All the underlying source code is
available
Linux
12/07/13 - Marc Leeman
Company Confidential - 9
Applications
● LAMP
● Linux, Apache, MySQL, Perl/PHP/Python
● Gaming (PS3)
● Embedded
● Set top boxes, mobile phones, routers &
switches, dreambox, TiVo, …
● Handhelds
● Supercomputers
● 34 fastest running Linux, 92% of top 500
12/07/13 - Marc Leeman
Company Confidential - 10
Linux & Super computing
12/07/13 - Marc Leeman
Company Confidential - 11
Usability
● KDE/Gnome
● Office, Calenders, ...
● plethora of programs/utilities
● Eye candy: 3D Desktop accelleration
● usability in par with commercial OSes.
12/07/13 - Marc Leeman
Company Confidential - 12
Installation
● Easy installation
● Powerful development environment
● Wide architecture support
● Live-CDs, Dual Boot, ...
12/07/13 - Marc Leeman
Company Confidential - 13
System Overview
12/07/13 - Marc Leeman
Company Confidential - 14
System on Chip
● Hardware varies a lot
● Linux kernel and OS abstracts HW from software
● CPU
● PowerPC (was?) popular in Barco
● ARM seems to be picking up
● Focus on ARM, but techniques can be applied
to other archs.
● X86 systems
12/07/13 - Marc Leeman
Company Confidential - 15
System on Chip
● RAM
● Storage
● Used to be typically NOR flash, sometimes
NAND
● Currently NAND due to cost (eMMC)
● I/O
● Lot of variation
● Serial and Ethernet
12/07/13 - Marc Leeman
Company Confidential - 16
Embedded Linux Components
● Bootloader
● Linux kernel
● 1 (or more) file systems with userspace
● Kernel sometimes inside rootfs as well
12/07/13 - Marc Leeman
Company Confidential - 17
Layering
● Boot loader only active during powerup
● Only kernel talks to hardware
● Same for ALL Linux systems
12/07/13 - Marc Leeman
Company Confidential - 18
System Design
12/07/13 - Marc Leeman
Company Confidential - 19
Considerations
● Redundancy
● Hardware (network interfaces)
● Software (factory/upgrade)
● Configuration (redundant flash with CRC)
● Predictability
● Uncertainty => fall back to factory settings
● Stability
● Linux :-)
● Monitoring
● Quis custodiet ipsos custodes
12/07/13 - Marc Leeman
Company Confidential - 20
Basic choice
● Small and minimalistic
● Focus on minimal footprint
● Reduce component cost (large volumes)
● Minimal functionality
● Often one indivisible deliverable
● Platform approach
● Focus on software design
● Reduce software development cost (a lot of
low volume platforms)
● Pluggable functionality
● Easy functionality extension and system
configuration.
● Trend seems is to focus on software
12/07/13 - Marc Leeman
Company Confidential - 21
Small is Beautiful
Speed increase RAM reduction Power reduction Cost reduction
More speed ­ CPU can run slower or stay
longer in power saving mode
­ Slower, cheaper
CPU
Less RAM ­ Faster allocations
­ Less swapping
­ Sometimes less
cache flushing
­ Fewer / smaller RAM chips:
less dynamic and standby
power.
­ CPU with less cache: less power
­ Fewer / cheaper
RAM chips
­ CPU with less
cache: cheaper
Less space ­ Faster application
loading from
storage and in
RAM.
­ Sometimes,
simpler, faster
code.
­ Less RAM usage ­ Fewer / smaller storage chips:
less power
­ Fewer / cheaper
storage
Less power ­ Cheaper batteries
­ or cheaper
AC/DC converter
●No black and white choice
●Storage is cheap
●Small does have a cost:
● Focus on software that adds value
12/07/13 - Marc Leeman
Company Confidential - 22
Components
● File systems
● Rw: Jffs2, ubifs
● Ro: cramfs, squashfs
● Ext2, FAT
● Glibc or uclibc
● Glibc: localisation (l10n), internationalisation support
(I18n), threading
● Uclibc: replace (configurable) parts of libc allows
optimisation for size
● Scales up to 33% wrt original libc reference
● System utils or busybox
● all-in-one, GNU utils optimised for size
12/07/13 - Marc Leeman
Company Confidential - 23
The bootloader
● Das U-Boot
● Extracts kernel image to RAM and sets
Program Counter
● But is much more!
● executes scripts
● can get kernel over network
● can be used to upgrade the flash sections
● debugging over network
● ...
12/07/13 - Marc Leeman
Company Confidential - 24
The Linux Kernel
● Basic hardware detection and
initialisation
● In the kernel image is needed:
● minimal configuration to allow recognition of root
FS
● hardware access for root partition
● SCSI, IDE, LIBATA, FLASH, MAC/PHY, ...
● File system
● ext2, ext3, jfs, ubifs, xfs, nfs, reiserfs, ...
● What is not needed:
● Firewall (iptables), keyboard, mouse, ...
(peripherals)
● Can be postponed to the final stages of booting
● Good Practice
● only include needed functionality
12/07/13 - Marc Leeman
Company Confidential - 25
Static or Dynamic Linking (1)
Static linking
● All shared library code duplicated in the
executables
● Allows not to copy the C library in the file
system.
Simpler and smaller when very few
executables (busybox)
● Library code duplication: bad for systems with
more executables (code size and RAM)
Best for small systems (< 1-2 MB) with few
executables!
Not used that much anymore
12/07/13 - Marc Leeman
Company Confidential - 26
Static or Dynamic Linking (2)
Dynamic linking
● Shared library code not duplicated in
the executables
● Makes much smaller executables
● Saves space in RAM (bigger executable
take more RAM)
● Requires the library to the copied to the
file system
Best for medium to big systems (> 500 KB
- 1 MB)
12/07/13 - Marc Leeman
Company Confidential - 27
Libc
● glibc (GNU C library):
http://www.gnu.org/software/libc/
Found on most computer type GNU/Linux machines
Size on arm: approx 1.7 MB
● uClibc: http://www.uclibc.org/
Found in more and more embedded Linux systems!
Size on arm: approx 400 KB (you save 1.2 MB!)
C program Compiled with shared libraries Compiled statically
glibc uClibc glibc uClibc
Plain “hello world” 4.6 K 4.4 K 475 K 25 K
Busybox 245 K 231 K 843 K 311 K
12/07/13 - Marc Leeman
Company Confidential - 28
Stripping
● Compiled executables contain extra information which
can be used to investigate problems in a debugger.
● This was useful for the tool developer, but not for the
final user.
● To remove debugging information, use the strip
command.
This can save a very significant amount of space!
gcc ­o hello hello.c (output size: 4635 bytes)
strip hello (output size: 2852 bytes, -38.5%)
12/07/13 - Marc Leeman
Company Confidential - 29
Setting up our Cross
Compilation Toolchain
12/07/13 - Marc Leeman
Company Confidential - 30
Terminology
● build platform: where the code is
compiled
● host platform: where the compiled code
will be executed
● target platform: for compilers,
represents what type of object code the
package itself will produce
● preferred compiler for code that runs on
different archs
12/07/13 - Marc Leeman
Company Confidential - 31
Terminology (2)
● gcc: GNU Compiler Collection
● 1987...
● glibc: GNU C standard library
● Unix98, POSIX, C99, +extensions
● x86, m68k, Alpha, PPC, ARM, CRIS, MIPS,
s390, SPARC
● Linux +Hurd kernels, also FreeBSD and
NetBSD
● glibc 2 = libc6; (older glibc -> libc5)
● uclibc
● cf. Supra
12/07/13 - Marc Leeman
Company Confidential - 32
Top Down Approach
Top-down approach to building an embedded system
● Starting from a complete desktop GNU/Linux
distribution (Debian, Fedora...) and removing
unneeded stuff.
● Very tedious job: need to go through a huge number
of files and packages. Need to understand what each
file and package is about before removing it.
● Keeping unnecessarily complex scripts and
configuration files.
● The end result is still quite big, as standard desktop
tool sets and libraries are used. Lots of shared
libraries still needed too.
12/07/13 - Marc Leeman
Company Confidential - 33
Bottom Up Approach
Bottom-up approach to building embedded systems
● Starting with an empty or minimalistic root file
system, adding only things that you need.
● Much easier to do! You just spend time on things you
need.
● Much easier to control and maintain: you build an
understanding about the tools you use.
● You only need very simple configuration scripts.
● The end result can be extremely small, all the more
as you use lightweight tool sets instead.
12/07/13 - Marc Leeman
Company Confidential - 34
Toolchain
● gcc:
● cross-compiling: compile for a target
configuration other than the build host.
● $(arch)-$(os){-$(lib)}-gcc
● powerpc-linux-uclibc-gcc,
arm-linux-newlib-gcc
● typical gcc toolchain links against libc
● When uclibc is used, a compiler is needed
that matches that exact uclibc configuration
● automated with buildroot
12/07/13 - Marc Leeman
Company Confidential - 35
Toolchain selection
● Depends on your environment
● Native build (x86, emulation, arm, ...)
● Cross compilation build
● Glibc cross compilations toolchains are often
available
● Native complation toolchains are ALWAYS
available (e.g. qemu)
● With uClibc, a exactly matched toolchain is
required
12/07/13 - Marc Leeman
Company Confidential - 36
Native and emulation
● The target hardware is very performant
● Target instruction set is emulated
● Both use a 'native' compiler
● Typical easier to use for complex
software environments
12/07/13 - Marc Leeman
Company Confidential - 37
Buildroot
● Classic cross compilation
● Set of Makefiles and patches
● Generates:
● cross-compilation toolchain
● gcc, binutils, gdb, ...
● (root filesystem for target, kernel,
bootloader, ..)
12/07/13 - Marc Leeman
Company Confidential - 38
Buildroot configuration
● Kconfig interface
● make menuconfig
● Select compiler, binutils and gdb
version.
● http://buildroot.net
12/07/13 - Marc Leeman
Company Confidential - 39
Exercise
● Retrieve buildroot 2012.08 from
● http://www.buildroot.org/download.html
● $ make sheevaplug_defconfig
● $ make
●
● Note: you will need to set your http_proxy environment variable
to http://neo.barco.com:3128/ and/or use
http://sleipner.barco.com/downloads/ as primary download site
(Build Options → Mirrors and Download locations)
12/07/13 - Marc Leeman
Company Confidential - 40
The Linux Boot Process
12/07/13 - Marc Leeman
Company Confidential - 41
High Level View
12/07/13 - Marc Leeman
Company Confidential - 42
System startup
● CPU executes code at a predefined
address (e.g. CS0, address 0x100)
● for a PC: BIOS in flash on motherboard
● embedded e.g. U-Boot, Redboot or similar
● PC:
● if valid boot device is found, the 1st
stage
bootloader is loaded
12/07/13 - Marc Leeman
Company Confidential - 43
Stage 1 Bootloader (x86)
● <512 bytes, fits in 1 sector
● binary itself < 446 bytes
● 64 byte partition table
● 2 byte signature
● loaded from MBR boot device
● Task is to load second stage bootloader
12/07/13 - Marc Leeman
Company Confidential - 44
Boot device signature
12/07/13 - Marc Leeman
Company Confidential - 45
Stage 2 bootloader
● LILO/GRUB
● load and select kernel
● optionally selects initrd
● pass control to the kernel
12/07/13 - Marc Leeman
Company Confidential - 46
Kernel
● zImage (zlib, lzo or lzma compressed)
● without initrd, kernel should contain just
the functionality to detect & mount root
filesystem
12/07/13 - Marc Leeman
Company Confidential - 47
Kernel startup
12/07/13 - Marc Leeman
Company Confidential - 48
kernel startup (2)
● Assembly, arch specific
● head.S
● hardware initialisation and setup basic
environment
● decompress kernel in memory
● Uncompressing Linux... Ok, booting the kernel
● startup_32:
● initialise page tables and enable memory
paging
● CPU detection
12/07/13 - Marc Leeman
Company Confidential - 49
kernel startup (3)
● C, non arch specific
● start_kernel in init/main.c
● init interrupts
● (init ramdisk)
● initial root fs in memory/detect hardware
● embedded: can be final root filesystem
● memory initialisation
● thread_kernel starts /sbin/init
● first user-level application
● Can be modified to another application
12/07/13 - Marc Leeman
Company Confidential - 50
init
● First user-level application
● compiled/linked with libc
● uses /etc/inittab
● Spawn services
● sshd, apache, ...
● /bin/sh can also be used to start a
single shell instead of init
12/07/13 - Marc Leeman
Company Confidential - 51
Runlevels (sysv)
● startup behaviour of init is divided in
“runlevels”
● 0: Halt
● 1: Single User Mode
● 2: Basic Multi-User mode without NFS
● 3: Full Multi-User mode
● 4: Not used
● 5: Full Multi User Mode with X11 Login
● 6: Reboot
● Not so fixed, some distros use fewer
levels (e.g. Slackware, Debian, ...)
12/07/13 - Marc Leeman
Company Confidential - 52
init scripts
● Most start scripts can be found in
● /etc/init.d/
● /etc/rcX.d contains symbolic links to the
scripts
● X: 1,2,3,4,5,6,S
● K20autofs
● S: start
● K: stop
● number for ordering: e.g. start network
daemons after network devices.
12/07/13 - Marc Leeman
Company Confidential - 53
inittab entry
● 1:2345:respawn/sbin/getty 38400 tty1
● id
● runlevels
● action
● process to be executed
● id:3:initdefault:
● default runlevel
● /etc/init.d/networking
● {start|stop|restart|force-reload}
12/07/13 - Marc Leeman
Company Confidential - 54
Boot Loaders
12/07/13 - Marc Leeman
Company Confidential - 55
Overview
● First thing to run after power on
● Tasks:
● Initialize (some of) hardware
● Load a kernel
● Execute it
● Boot loaders often have extra
functionality:
● Access memory and registers
● Program flash
● ..
12/07/13 - Marc Leeman
Company Confidential - 56
Boot Loaders
● Lots of Linux compatible boot loaders
● LILO & GRUB well known
● PC specific
● Often platform specific
● Portable:
● RedBoot
● Das U-Boot
12/07/13 - Marc Leeman
Company Confidential - 57
Das U-Boot
● The universal boot loader
● Probably most feature full, flexible and
most actively developed boot loader
● Very much focused on Linux
● Started as PPCBoot, but now portable
● Licensed under the GPL
● Has a alternative implementation
barebox (u-boot-v2).
12/07/13 - Marc Leeman
Company Confidential - 58
U-Boot Features
● Flash support
● NOR, NAND, Dataflash, ..
● Compression
● GZIP, BZIP2
● Interactive command line interface
● Boot scripting
● TCP/IP stack with BOOTP and DHCP,
TFTP and NFS
● LOTS of drivers:
● Often ported from Linux
● IDE, SCSI, MMC, PCMCIA, USB, LCD, I2C,
SPI, ..
12/07/13 - Marc Leeman
Company Confidential - 59
U-Boot Features (2)
● x86 emulation
● Graphics card POST on non-x86
● File Systems
● JFFS2, Cramfs, squashfs EXT2, FAT,
Reiserfs, ..
● Boot splash images
● FPGA configuration
● ...
12/07/13 - Marc Leeman
Company Confidential - 60
Exercise
● Bootup SheevaPlug in U-Boot and
explore commands (type help) and
environment variables (type printenv)
12/07/13 - Marc Leeman
Company Confidential - 61
U-Boot operation
● Once a working U-Boot (flash) is installed,
upgrading can be done with
serial/tftp/u-boot
tftp 100000 /home/services/tftpboot/u-boot.bin
protect off fe000000 fe03ffff
era fe000000 fe03ffff
cp.b 100000 fe000000 ${filesize}
protect on fe000000 fe03ffff
● scripting helps :-)
run burnfact
12/07/13 - Marc Leeman
Company Confidential - 62
Exercise
● Download u-boot 2010.06 and build for
SheevaPlug. Update through JTAG or
TFTP
● Check section 4.6 in manual
● Needed .deb's at
http//neo.barco.com/~mleeman/downloads/SheevaPlugCourse
12/07/13 - Marc Leeman
Company Confidential - 63
The Linux Kernel
12/07/13 - Marc Leeman
Company Confidential - 64
History
● 1991: post in comp.os.minix
● Linux 0.1
● 1994: Linux 1.0.0
● 1996: Linux 2.0.0
● 1999: Linux 2.2.0
● 2001: Linux 2.4.0
● 2003: Linux 2.6.0
● 2011: Linux 3.0
● 2012: Linux 3.5
12/07/13 - Marc Leeman
Company Confidential - 65
Architecture
● monolithic kernel
● drivers run in ring 0
● X11 is in userspace
● contrary to Windows
● Supports
● preemption
● virtual memory
● memory management
● threading
● TCP/IP
● ...
● Mostly in C (97%), 3% ASM
12/07/13 - Marc Leeman
Company Confidential - 66
Modules
● kernel code that can access hardware
directly
● modules can be loaded/unloaded and
re-configured at run-time
● e.g.
sudo modprobe xfs
lsmod
sudo insmod /path/to/xfs.ko
sudo modprobe module param=1
● Also in configuration file
/etc/modprobe.d/module.conf
12/07/13 - Marc Leeman
Company Confidential - 67
Source Tree
● BIG! (~525 MB, 10M lines)
● A lot is drivers
● Core kernel ~5MB
12/07/13 - Marc Leeman
Company Confidential - 68
Source Tree (2)
Kernel 2.6.36
● 216M drivers
● 114M arch
● 32M fs
● 21M sound
● 19M include
● 19M net
● 17M Documentation
● 4.6M kernel
● 2.2M scripts
● 2.2M mm
● 1.7M crypto
● 1.4M lib
● 1.4M security
● 544K block
● 244K ipc
● 144K init
● 108K samples
● 56K usr
12/07/13 - Marc Leeman
Company Confidential - 69
Architecture Specific code
● arch/<cpu>
● arch/<cpu>/include/asm
● A few MB per arch
● Depending on no. supported boards
12/07/13 - Marc Leeman
Company Confidential - 70
Release Schedule
● New release every 2-3 months
● 2.6.39 19/05/2011
● 3.0 22/07/2011
● 3.1 24/10/2011
● 3.2 05/01/2012
● 3.3 22/03/2012
● 3.4 21/05/2012
● 3.5 21/07/2012
● 3.6 01/10/2012
● 3.7 11/12/2012
● 3.8 19/02/2013
● 3.9 29/04/2013
● 3.10 30/06/2013
12/07/13 - Marc Leeman
Company Confidential - 71
Release Schedule (2)
● Tree is open for 2 weeks after release
● LOTS of activity – rc1 diff ~1M lines
● After that only bugfixes
● New -rcX release every 1-2 weeks
● 3.x.y stable releases for serious bugs
found after release
12/07/13 - Marc Leeman
Company Confidential - 72
Tracking Development
● Linux kernel mailing list (2-300 mails/day)
● lwn.net Kernel - http://lwn.net/Kernel
● http://www.kernelnewbies.org/LinuxChan
ges
● kernel.org gitweb:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=summary
12/07/13 - Marc Leeman
Company Confidential - 73
Device Tree
● Introduced in the PowerPC processor
ports, moving to other archs (ARM,
Microblaze)
● The Device Tree describes the
hardware to the kernel
● Includes e.g. Flash map, PCI
addresses, MAC addresses, ...
● U-Boot has support for modifying the
dts/dtb
12/07/13 - Marc Leeman
Company Confidential - 74
User Space Interface
● Basically 3 types of interfaces:
● Character Devices
● Block Devices
● Network Devices
● (procfs, sysfs, netlink)
● Rarely needs to be implemented
directly
● Kernel provides frameworks
12/07/13 - Marc Leeman
Company Confidential - 75
Character Devices
● Most common type
● Anything that can be viewed as a stream of
bytes (serial ports, input devices,
framebuffers, sound devices, ..)
● Accessed like normal files
● open/close/read/write/lseek/..
● Additional settings through ioctl
● Added in kernel by
● Registering a cdev and implement
file_operations
12/07/13 - Marc Leeman
Company Confidential - 76
Block Devices
● For Storage Devices
● Harddisks, MMC, USB keys, ..
● Accessed like Character Devices
● Kernel Interface More Complicated
● Added in kernel by
● Registering a gendisk and implement
block_device_operations
12/07/13 - Marc Leeman
Company Confidential - 77
Network Devices
● For Network Devices
● Ethernet, Wireless, PPP, ..
● Accessed using socket API
● socket/accept/listen/recv/send/..
● Configuration typically through
programs/scripts
● ip/ifconfig/vconfig/ethtool/..
● Added in kernel by
● Registering a net_device and implement
net_device_ops
12/07/13 - Marc Leeman
Company Confidential - 78
Hardware Access
● Memory mapped registers
● Linux uses virtual memory (MMU)
● ioremap(physical address)
logical
● read{b,w,l}(logical)
● write{b,w,l}(value, logical)
● iounmap(logical)
12/07/13 - Marc Leeman
Company Confidential - 79
Device Model
● Object Oriented, Tree Structured
● Busses (struct bus_type)
● Devices (struct device)
● Drivers (struct driver)
● Visible in sysfs
● Take a look on your PC!
● Saves code, Tree hierarchy important
for E.G. power management
12/07/13 - Marc Leeman
Company Confidential - 80
Busses
● Devices connect to CPU through
busses
● USB, PCI, I2C, SPI, Platform, ..
● Each corresponds to a specific bus_type
● Bus-specific interface for drivers
● Tree Based
● E.G. a USB controller on a PCI bus
12/07/13 - Marc Leeman
Company Confidential - 81
Devices and Drivers
● Object Oriented
● Drivers (Classes)
● Devices (Instances)
● Common interface
● Probe (Constructor)
● Remove (Destructor)
● Bus connects (binds) both together
12/07/13 - Marc Leeman
Company Confidential - 82
Platform Bus
● “Dummy” bus for simple memory
mapped devices on SoCs
● Plug-n-play binding emulated through
string matching (driver/device name
member)
12/07/13 - Marc Leeman
Company Confidential - 83
Platform Bus Binding
struct platform_device {
const char * name;
…
};
struct platform_driver {
struct device_driver driver {
const char *name;
};
...
};
● Platform_device in platform code
● Platform_driver in device driver
12/07/13 - Marc Leeman
Company Confidential - 84
Resources
static struct resource smc911x_resources[] = {
[0] = {
.start = 0x8e000000,
.end = 0x8e0000ff,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = 4,
.end = 4,
.flags = IORESOURCE_IRQ,
},
};
● Generic way of providing platform
details such as base address and IRQ:
●Platform data pointer for special stuff
12/07/13 - Marc Leeman
Company Confidential - 85
PCI Bus
● Device/Driver binding using PCI
Vendor/Product ID (PnP)
● lspci
● USB is very similar
00:1f.3 SMBus: Intel Corporation N10/ICH 7 Family SMBus Controller (rev 02)
01:00.0 Ethernet controller: Marvell Technology Group Ltd. 88E8053 PCI-E
Gigabit Ethernet Controller (rev 22)
02:00.0 Network controller: Atheros Communications Inc. AR5008 Wireless
Network Adapter (rev 01)
03:03.0 FireWire (IEEE 1394): Agere Systems FW322/323 (rev 61)
..
12/07/13 - Marc Leeman
Company Confidential - 86
Character Interface
● Make communication available to
userspace via device files
# ls -l /dev |grep dsp
crw-rw-rw- 1 0 0 252, 4 Jul 20 2006 dspa
crw-r----- 1 0 0 252, 0 Jul 20 2006 dspa0
crw-r----- 1 0 0 252, 1 Jul 20 2006 dspa1
crw-r----- 1 0 0 252, 2 Jul 20 2006 dspa2
crw-r----- 1 0 0 252, 3 Jul 20 2006 dspa3
# ls -l /dev |grep fpga
crw-r----- 1 0 0 253, 0 Jul 20 2006 fpgaa
crw-r----- 1 0 0 251, 0 Jul 20 2006 nwwfpgaa
12/07/13 - Marc Leeman
Company Confidential - 87
read/write
● read/write on file handles
● copy data from the kernel to application
code
● copy_to_user(...)
● copy data from application code to the
kernel
● copy_from_user(...)
● If user reads
● kernel writes from userspace
● If user writes
● kernel reads from userspace
12/07/13 - Marc Leeman
Company Confidential - 88
Device Files
● ioctl is often used in code to send
commands and data to the kernel/device
● For register access, read/write/lseek is
better.
● bad example:
static inline uint32_t ppc2dsp_getregister(const DSP
*dsphandle,uint32_t address){
TSBarcoMemEntry entry;
entry.addr = address;
ioctl(*dsphandle,PPC2DSP_GET_REG,&entry);
return entry.value;
}
dsp = open ("/dev/dspa", O_RDWR);
12/07/13 - Marc Leeman
Company Confidential - 89
ioctl
● fine tuned and often specialised
hardware control
● allows to pass arbitrary data from user
to kernel and vice versa
● int(*ioctl)(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg);
● switch(cmd)
● number 0..N cmd X-(
12/07/13 - Marc Leeman
Company Confidential - 90
Interrupts
● Kernel needs to act on a “hardware
event”
● polling?
● slow and CPU intensive!
● An interrupt is a signal that the
hardware can send when it wants the
processor's attention.
12/07/13 - Marc Leeman
Company Confidential - 91
Flash Map
● Add partitions to the flash
● different functionality
● select between
● kernels
● root filesystems
● redundant configuration spaces
● file systems (jffs2, squashfs, ...)
● Create one logical area from multiple
flash chips
12/07/13 - Marc Leeman
Company Confidential - 92
LED Class
● Kernel already has a framework for this
● See:
● drivers/leds
● Documentation/leds-class.txt
● /sys/class/leds
● gpio_led driver makes this very easy
● Various led-triggers can be hooked up
12/07/13 - Marc Leeman
Company Confidential - 93
File Systems
12/07/13 - Marc Leeman
Company Confidential - 94
Introduction
● More than 50 file systems supported
● More than any other OS
● What to choose?
12/07/13 - Marc Leeman
Company Confidential - 95
File System Types
● Disk based
● Flash based
● Network file systems
● “Virtual” file systems
12/07/13 - Marc Leeman
Company Confidential - 96
Disk Based
● Biggest group
● Native
● Supports all POSIX features
● EXT2/3/4, Reiserfs3/4, XFS, JFS, Btrfs, ..
● Recommended
● Compatibility
● Might not support all POSIX features
● Less performance
● FAT, NTFS, HPFS, BEFS, AFFS, ISO9660,
UDF, ..
12/07/13 - Marc Leeman
Company Confidential - 97
Disk Based (2)
● Disks are not common in embedded
systems
● PC-Like
● Flash with disk interface (USB, CF, MMC,..)
● Limit writes for flash!
● No journalling file systems
● noatime mount option
● EXT2 or FAT
12/07/13 - Marc Leeman
Company Confidential - 98
Flash Based
● Disk based can be used
● Kernel MTD layer can emulate block device
● Only realistic for read only
● Optimized for flash
● Cramfs (old)
● Squashfs
● Journalling file system 2 (JFFS2) (old)
● UBIFS
12/07/13 - Marc Leeman
Company Confidential - 99
Cramfs / Squashfs
● Read only
● Compression
● Squashfs finally in mainline
● Squashfs newer
● More features, better compression, faster
● Can also be used on disks
● Often combined with RAM disk for /tmp
● OpenWRT uses squashfs-lmza
● Squashfs + better compression
● Complex to implement: lmza non standard
12/07/13 - Marc Leeman
Company Confidential - 100
JFFS2
● Read/write
● Compression, but less effective
● Journalling, so no fsck
● Long mount time on big partitions
● Complex
● Consider raw flash partition or
EEPROM if data limited
12/07/13 - Marc Leeman
Company Confidential - 101
UBIFS
● Similar to JFFS2 but newer
● Uses UBI (Unsorted Block Images)
● More Scalable, faster mount time
● Better fit for (big) NAND flash
12/07/13 - Marc Leeman
Company Confidential - 102
Network File Systems
● NFS, SMBFS/CIFS
● AFS, CODA, 9FS, ..
● Not commonly used in production
● NFS very handy for development
● Kernel can boot on NFS
● NFS supports normal POSIX features
12/07/13 - Marc Leeman
Company Confidential - 103
“Virtual” File Systems
● No underlying media to store data
● Sysfs, procfs: Interface to kernel
● TMPFS: Dynamic RAM disks
● Devtmpfs: Dynamic /dev
12/07/13 - Marc Leeman
Company Confidential - 104
Conclusion
● Lots to choose from
● Most systems use more than one
12/07/13 - Marc Leeman
Company Confidential - 105
Userspace
12/07/13 - Marc Leeman
Company Confidential - 106
busybox
http://www.busybox.net/
● Most Unix command line utilities within a
single executable!
● includes a web server!
● Sizes less than 1 MB (statically compiled
with glibc)
less than 500 KB (statically compiled with
uClibc)
● Easy to configure
● The best choice for
● Initrds with complex scripts
12/07/13 - Marc Leeman
Company Confidential - 107
busybox
● combine unix utilities in one single small
executable
● share startup code
● configurable commands
● configurable functionality of the
commands
● applets easy to add
12/07/13 - Marc Leeman
Company Confidential - 108
● Best way to describe:
root@OpenWrt:~# busybox
BusyBox v1.4.2 (2007-09-29 07:21:40 CEST) multi-call binary
Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.
Licensed under GPLv2. See source distribution for full notice.
Usage: busybox [function] [arguments]...
or: [function] [arguments]...
BusyBox is a multi-call binary that combines many common Unix
utilities into a single executable. Most people will create a
link to busybox for each function they wish to use and BusyBox
will act like whatever it was invoked as!
Currently defined functions:
[, [[, arping, ash, awk, awx, basename, bunzip2, bzcat, cat, chgrp, chmod, chown, chroot,
clear,
cp, crond, crontab, cut, date, dd, df, dirname, dmesg, du, echo, egrep, env, expr, false,
fgrep,
find, free, grep, gunzip, gzip, halt, head, hexdump, hostid, httpd, id, ifconfig, init,
insmod,
ipkg, kill, killall, killall5, klogd, length, less, ln, lock, logger, logread, ls, lsmod,
md5sum,
mesg, mkdir, mkfifo, mknod, mktemp, mount, mv, nc, netmsg, netstat, nslookup, passwd, pidof,
ping, ping6, pivot_root, poweroff, printf, ps, pwd, rdate, reboot, reset, rm, rmdir, rmmod,
route, sed, seq, sh, sleep, sort, strings, switch_root, sync, sysctl, syslogd, tail, tar,
tee,
telnet, telnetd, test, time, top, touch, tr, traceroute, true, udhcpc, umount, uname, uniq,
uptime, vconfig, vi, watchdog, wc, wget, which, xargs, yes, zcat
12/07/13 - Marc Leeman
Company Confidential - 109
Configuration
● Again, Kconfig based
12/07/13 - Marc Leeman
Company Confidential - 110
CGI
`
12/07/13 - Marc Leeman
Company Confidential - 111
dropbear
● replaces telnetd
● obsolete since mid '90s
● secure communication
● no need for
● telnetd, ftpd, samba, ...
● tunnelling :-)
● Typical W32 clients
● PuTTy, WinSSH
● jcterm, mindterm
● GNU/Linux
● default
12/07/13 - Marc Leeman
Company Confidential - 112
Buildroot
● Not just for toolchains
● Can build entire Linux systems
● Make files, downloads over net
● No root permissions required
● Used in D&A and Medical
● Used in several Open Source projects:
● OpenWrt, Gumstix, ...
12/07/13 - Marc Leeman
Company Confidential - 113
Full blown Distributions
● Interesting option
● If disk(-like) storage available
● Little difference between SoC target and
desktop/server
● Functionality is can easily be expanded
● Debugging tools
● Verification
● GNU/Debian supports 11 archs
● Lots of precompiled packages
● ~20.000
● No need to cross compile
12/07/13 - Marc Leeman
Company Confidential - 114
First stage bootstrap
● Nice for development together with NFS
● Debootstrap –verbose –variant=minbase 
–keyring=/home/me/pubring.gpg –include=apt 
–arch=armhf –foreign vclub /home/me/chroot­2013 
ftp://cypher.barco.com/nvslinux 
/usr/share/debootstrap/scripts/wheezy
● Result is a armhf target on an x86-64
machine
● Installation requires a 'second-stage'
installation
● Does not run natively (<==> x86 (i386))
12/07/13 - Marc Leeman
Company Confidential - 115
Second Stage bootstrap
● Qemu is needed
● QEMU can launch Linux processes compiled for one CPU on
another CPU
● Fully system emulation
● Copy /usr/bin/qemu-static into
$TARGET/usr/bin/qemu-static
● Why 'static'?
● Debootstrap /home/me/chroot­2013/ 
/debootstrap/debootstrap –second­stage
12/07/13 - Marc Leeman
Company Confidential - 116
Qemu
● Spot the difference
● marc@drd1812:~/Development$ uname ­a
● Linux drd1812 3.9.4 #1 SMP PREEMPT Thu May 30 12:53:13 CEST 2013 x86_64 GNU/Linux
● marc@drd1812:~/Development$ sudo chroot dolphin­dev­env­2013­03­11/
● root@drd1812:/ dolphin­dev$ uname ­a
● Linux drd1812 3.9.4 #1 SMP PREEMPT Thu May 30 12:53:13 CEST 2013 armv7l GNU/Linux
12/07/13 - Marc Leeman
Company Confidential - 117
Packages
● a “package” refers to a compressed file
archive containing all of the files that
come with a particular application.
● Typical binary in nature
● Can install new functionality
● Can expand current functionality
● Can modify existing functionality
● Most common forms
● Debian package: file.deb
● Debian, Ubuntu, ...
● Redhat package: file.rpm
● Redhat, SuSE, Fedora, …
12/07/13 - Marc Leeman
Company Confidential - 118
Packages
● Selective upgrade
● Once deployed, typical bugfixes, security
fixes
12/07/13 - Marc Leeman
Company Confidential - 119
Packages 101
● Concept of a 'repo'
● Can be networked, on disk, on CD, USB, …
● deb
● deb­src
● Can be networked, on disk, on CD, USB, …
● In /etc/apt/sources.list.d/file.list
● deb ftp://cypher.barco.com/nvslinux/ vclub 
main contrib non­free
● File, cdrom, http, ftp, copy, rsh, ssh, …
● Lots of command line, console and GUI
front-ends
12/07/13 - Marc Leeman
Company Confidential - 120
Packages 101
● Update the package descriptions
● $ sudo apt­get update
● Install a single package
● $ sudo dpkg barco­mna240_123­1.deb
● Install a single package with
dependencies from the network
● $ sudo apt­get install barco­mna240
● $ sudo apt­get remove barco­mna280
● $ sudo apt­get purge barco­mna280
● Upgrade the system without installing
extra packages
● $ sudo apt­get upgrade
12/07/13 - Marc Leeman
Company Confidential - 121
Packages 101
● Upgrade the system
● $ sudo apt­get dist­upgrade
● Search the package descriptions
● $ sudo apt­get search barco
● Show detailed package description
● $ sudo apt­get show barco­c12
● Housekeeping
● Clear package cache
● $ sudo apt­get cache clear
● Remove unused packages
● $ sudo apt­get autoremove
12/07/13 - Marc Leeman
Company Confidential - 122
Privilege separation
● Services run as a separate
(unprivileged) user: e.g. webserver, ftp,
ssh, …
● Security concerns
12/07/13 - Marc Leeman
Company Confidential - 123
Setting up a Server
12/07/13 - Marc Leeman
Company Confidential - 124
General
● Platform of choice: GNU/Debian
● the developers' platform
● powerful, handy package management
● Check with IT:
● we will need DHCP (conflicts with corporate)
● Alternate: 2 network cards, external (Barco),
internal (my.net.local).
12/07/13 - Marc Leeman
Company Confidential - 125
Needed & (Useful)
● NFS
● mount root filesystem without re-burning it
to flash: much faster
● use larger filesystem than can be stored on
flash for development
● DHCP/BOOTP
● cf. supra
● kernel send BOOTP package to get
kernel/filesystem location over the network
12/07/13 - Marc Leeman
Company Confidential - 126
Needed & (Useful)
● atftpd
● Trivial ftp protocol
● used by U-Boot to obtain files over the
network
● used by BDI2000 to get files over the
network
● (bind)
● DNS server
● e.g. bdi02.smd.localnet is handier than 10.2.0.17
12/07/13 - Marc Leeman
Company Confidential - 127
Needed & (Useful)
● SSH
● Secure Shell
ssh-keygen -t dsa -b 4096
scp ~/.ssh/id_dsa.pub me@remote:
ssh me@remote 'mkdir -p ~/.ssh'
ssh me@remote 'cat id_dsa.pub > ~/.ssh/authorized_keys'
● (Samba)
● Windows Share access
● (LDAP)
● Centralised account and rights and service
management
● sudo & fakeroot
● selective super user root rights assignment
12/07/13 - Marc Leeman
Company Confidential - 128
Conclusions
● improvements to upstream sources
● communicate upstream
● e.g. Das U-Boot
● e.g. buildroot
● Kernel changes
● minimise them ASAP
● reduces maintenance to a minimum
● focus on the important code
● Montavista, MetroWerx
12/07/13 - Marc Leeman
Company Confidential - 129
References
● Update version of the examples, course text and slides:
● http://neo.barco.com/~mleeman/embedded_linux/
● D&A info:
● http://ccwiki/EmbeddedLinuxTraining

Embedded Linux Basics

  • 1.
    12/07/13 - MarcLeeman Company Confidential - 1 Basic Introduction to Embedded Linux Barco Seminar 11/07/2013 Marc Leeman
  • 2.
    12/07/13 - MarcLeeman Company Confidential - 2 Patches Accepted ● 11th time we do this training ● 5th time based on SheevaPlug ● Bear with us ● Developed over time ● Inconsistencies in course text/slides(?) ● Feedback welcome!
  • 3.
    12/07/13 - MarcLeeman Company Confidential - 3 Goals ● Huge topic, so only introduction ● Hands on, examples, share experience ● Become acquainted with typical small footprint embedded Linux ● Where to look for setting up or obtaining a cross compile toolchain environment ● Get to know the typical bootloaders ● Lots-of-examples
  • 4.
    12/07/13 - MarcLeeman Company Confidential - 4 Hardware ● SheevaPlug ● Marvell Arm Kirkwood processor ● 1.2 GHz ● 512 MB RAM ● U-Boot bootloader ● 512 MB NAND Flash ● Gb Ethernet, Serial, SD Card, USB, ...
  • 5.
    12/07/13 - MarcLeeman Company Confidential - 5 SheevaPlug
  • 6.
    12/07/13 - MarcLeeman Company Confidential - 6 Contents ● The GNU/Linux System ● System Overview ● System Design ● Cross Compilation Toolchain ● The Linux Boot Process ● Boot Loaders ● The Linux Kernel ● File Systems ● Userspace
  • 7.
    12/07/13 - MarcLeeman Company Confidential - 7 The GNU/Linux System
  • 8.
    12/07/13 - MarcLeeman Company Confidential - 8 ● Computer operating system and its kernel -> GNU/Linux, GNU+Linux, ... ● The GNU Project (1983) ● Hurd kernel 1990 ● Linux kernel: 1991 ● Estimated cost typical linux distribution is 10.8 billion; the kernel alone an extra 1.4 billion (2008, Fedora 9) ● All the underlying source code is available Linux
  • 9.
    12/07/13 - MarcLeeman Company Confidential - 9 Applications ● LAMP ● Linux, Apache, MySQL, Perl/PHP/Python ● Gaming (PS3) ● Embedded ● Set top boxes, mobile phones, routers & switches, dreambox, TiVo, … ● Handhelds ● Supercomputers ● 34 fastest running Linux, 92% of top 500
  • 10.
    12/07/13 - MarcLeeman Company Confidential - 10 Linux & Super computing
  • 11.
    12/07/13 - MarcLeeman Company Confidential - 11 Usability ● KDE/Gnome ● Office, Calenders, ... ● plethora of programs/utilities ● Eye candy: 3D Desktop accelleration ● usability in par with commercial OSes.
  • 12.
    12/07/13 - MarcLeeman Company Confidential - 12 Installation ● Easy installation ● Powerful development environment ● Wide architecture support ● Live-CDs, Dual Boot, ...
  • 13.
    12/07/13 - MarcLeeman Company Confidential - 13 System Overview
  • 14.
    12/07/13 - MarcLeeman Company Confidential - 14 System on Chip ● Hardware varies a lot ● Linux kernel and OS abstracts HW from software ● CPU ● PowerPC (was?) popular in Barco ● ARM seems to be picking up ● Focus on ARM, but techniques can be applied to other archs. ● X86 systems
  • 15.
    12/07/13 - MarcLeeman Company Confidential - 15 System on Chip ● RAM ● Storage ● Used to be typically NOR flash, sometimes NAND ● Currently NAND due to cost (eMMC) ● I/O ● Lot of variation ● Serial and Ethernet
  • 16.
    12/07/13 - MarcLeeman Company Confidential - 16 Embedded Linux Components ● Bootloader ● Linux kernel ● 1 (or more) file systems with userspace ● Kernel sometimes inside rootfs as well
  • 17.
    12/07/13 - MarcLeeman Company Confidential - 17 Layering ● Boot loader only active during powerup ● Only kernel talks to hardware ● Same for ALL Linux systems
  • 18.
    12/07/13 - MarcLeeman Company Confidential - 18 System Design
  • 19.
    12/07/13 - MarcLeeman Company Confidential - 19 Considerations ● Redundancy ● Hardware (network interfaces) ● Software (factory/upgrade) ● Configuration (redundant flash with CRC) ● Predictability ● Uncertainty => fall back to factory settings ● Stability ● Linux :-) ● Monitoring ● Quis custodiet ipsos custodes
  • 20.
    12/07/13 - MarcLeeman Company Confidential - 20 Basic choice ● Small and minimalistic ● Focus on minimal footprint ● Reduce component cost (large volumes) ● Minimal functionality ● Often one indivisible deliverable ● Platform approach ● Focus on software design ● Reduce software development cost (a lot of low volume platforms) ● Pluggable functionality ● Easy functionality extension and system configuration. ● Trend seems is to focus on software
  • 21.
    12/07/13 - MarcLeeman Company Confidential - 21 Small is Beautiful Speed increase RAM reduction Power reduction Cost reduction More speed ­ CPU can run slower or stay longer in power saving mode ­ Slower, cheaper CPU Less RAM ­ Faster allocations ­ Less swapping ­ Sometimes less cache flushing ­ Fewer / smaller RAM chips: less dynamic and standby power. ­ CPU with less cache: less power ­ Fewer / cheaper RAM chips ­ CPU with less cache: cheaper Less space ­ Faster application loading from storage and in RAM. ­ Sometimes, simpler, faster code. ­ Less RAM usage ­ Fewer / smaller storage chips: less power ­ Fewer / cheaper storage Less power ­ Cheaper batteries ­ or cheaper AC/DC converter ●No black and white choice ●Storage is cheap ●Small does have a cost: ● Focus on software that adds value
  • 22.
    12/07/13 - MarcLeeman Company Confidential - 22 Components ● File systems ● Rw: Jffs2, ubifs ● Ro: cramfs, squashfs ● Ext2, FAT ● Glibc or uclibc ● Glibc: localisation (l10n), internationalisation support (I18n), threading ● Uclibc: replace (configurable) parts of libc allows optimisation for size ● Scales up to 33% wrt original libc reference ● System utils or busybox ● all-in-one, GNU utils optimised for size
  • 23.
    12/07/13 - MarcLeeman Company Confidential - 23 The bootloader ● Das U-Boot ● Extracts kernel image to RAM and sets Program Counter ● But is much more! ● executes scripts ● can get kernel over network ● can be used to upgrade the flash sections ● debugging over network ● ...
  • 24.
    12/07/13 - MarcLeeman Company Confidential - 24 The Linux Kernel ● Basic hardware detection and initialisation ● In the kernel image is needed: ● minimal configuration to allow recognition of root FS ● hardware access for root partition ● SCSI, IDE, LIBATA, FLASH, MAC/PHY, ... ● File system ● ext2, ext3, jfs, ubifs, xfs, nfs, reiserfs, ... ● What is not needed: ● Firewall (iptables), keyboard, mouse, ... (peripherals) ● Can be postponed to the final stages of booting ● Good Practice ● only include needed functionality
  • 25.
    12/07/13 - MarcLeeman Company Confidential - 25 Static or Dynamic Linking (1) Static linking ● All shared library code duplicated in the executables ● Allows not to copy the C library in the file system. Simpler and smaller when very few executables (busybox) ● Library code duplication: bad for systems with more executables (code size and RAM) Best for small systems (< 1-2 MB) with few executables! Not used that much anymore
  • 26.
    12/07/13 - MarcLeeman Company Confidential - 26 Static or Dynamic Linking (2) Dynamic linking ● Shared library code not duplicated in the executables ● Makes much smaller executables ● Saves space in RAM (bigger executable take more RAM) ● Requires the library to the copied to the file system Best for medium to big systems (> 500 KB - 1 MB)
  • 27.
    12/07/13 - MarcLeeman Company Confidential - 27 Libc ● glibc (GNU C library): http://www.gnu.org/software/libc/ Found on most computer type GNU/Linux machines Size on arm: approx 1.7 MB ● uClibc: http://www.uclibc.org/ Found in more and more embedded Linux systems! Size on arm: approx 400 KB (you save 1.2 MB!) C program Compiled with shared libraries Compiled statically glibc uClibc glibc uClibc Plain “hello world” 4.6 K 4.4 K 475 K 25 K Busybox 245 K 231 K 843 K 311 K
  • 28.
    12/07/13 - MarcLeeman Company Confidential - 28 Stripping ● Compiled executables contain extra information which can be used to investigate problems in a debugger. ● This was useful for the tool developer, but not for the final user. ● To remove debugging information, use the strip command. This can save a very significant amount of space! gcc ­o hello hello.c (output size: 4635 bytes) strip hello (output size: 2852 bytes, -38.5%)
  • 29.
    12/07/13 - MarcLeeman Company Confidential - 29 Setting up our Cross Compilation Toolchain
  • 30.
    12/07/13 - MarcLeeman Company Confidential - 30 Terminology ● build platform: where the code is compiled ● host platform: where the compiled code will be executed ● target platform: for compilers, represents what type of object code the package itself will produce ● preferred compiler for code that runs on different archs
  • 31.
    12/07/13 - MarcLeeman Company Confidential - 31 Terminology (2) ● gcc: GNU Compiler Collection ● 1987... ● glibc: GNU C standard library ● Unix98, POSIX, C99, +extensions ● x86, m68k, Alpha, PPC, ARM, CRIS, MIPS, s390, SPARC ● Linux +Hurd kernels, also FreeBSD and NetBSD ● glibc 2 = libc6; (older glibc -> libc5) ● uclibc ● cf. Supra
  • 32.
    12/07/13 - MarcLeeman Company Confidential - 32 Top Down Approach Top-down approach to building an embedded system ● Starting from a complete desktop GNU/Linux distribution (Debian, Fedora...) and removing unneeded stuff. ● Very tedious job: need to go through a huge number of files and packages. Need to understand what each file and package is about before removing it. ● Keeping unnecessarily complex scripts and configuration files. ● The end result is still quite big, as standard desktop tool sets and libraries are used. Lots of shared libraries still needed too.
  • 33.
    12/07/13 - MarcLeeman Company Confidential - 33 Bottom Up Approach Bottom-up approach to building embedded systems ● Starting with an empty or minimalistic root file system, adding only things that you need. ● Much easier to do! You just spend time on things you need. ● Much easier to control and maintain: you build an understanding about the tools you use. ● You only need very simple configuration scripts. ● The end result can be extremely small, all the more as you use lightweight tool sets instead.
  • 34.
    12/07/13 - MarcLeeman Company Confidential - 34 Toolchain ● gcc: ● cross-compiling: compile for a target configuration other than the build host. ● $(arch)-$(os){-$(lib)}-gcc ● powerpc-linux-uclibc-gcc, arm-linux-newlib-gcc ● typical gcc toolchain links against libc ● When uclibc is used, a compiler is needed that matches that exact uclibc configuration ● automated with buildroot
  • 35.
    12/07/13 - MarcLeeman Company Confidential - 35 Toolchain selection ● Depends on your environment ● Native build (x86, emulation, arm, ...) ● Cross compilation build ● Glibc cross compilations toolchains are often available ● Native complation toolchains are ALWAYS available (e.g. qemu) ● With uClibc, a exactly matched toolchain is required
  • 36.
    12/07/13 - MarcLeeman Company Confidential - 36 Native and emulation ● The target hardware is very performant ● Target instruction set is emulated ● Both use a 'native' compiler ● Typical easier to use for complex software environments
  • 37.
    12/07/13 - MarcLeeman Company Confidential - 37 Buildroot ● Classic cross compilation ● Set of Makefiles and patches ● Generates: ● cross-compilation toolchain ● gcc, binutils, gdb, ... ● (root filesystem for target, kernel, bootloader, ..)
  • 38.
    12/07/13 - MarcLeeman Company Confidential - 38 Buildroot configuration ● Kconfig interface ● make menuconfig ● Select compiler, binutils and gdb version. ● http://buildroot.net
  • 39.
    12/07/13 - MarcLeeman Company Confidential - 39 Exercise ● Retrieve buildroot 2012.08 from ● http://www.buildroot.org/download.html ● $ make sheevaplug_defconfig ● $ make ● ● Note: you will need to set your http_proxy environment variable to http://neo.barco.com:3128/ and/or use http://sleipner.barco.com/downloads/ as primary download site (Build Options → Mirrors and Download locations)
  • 40.
    12/07/13 - MarcLeeman Company Confidential - 40 The Linux Boot Process
  • 41.
    12/07/13 - MarcLeeman Company Confidential - 41 High Level View
  • 42.
    12/07/13 - MarcLeeman Company Confidential - 42 System startup ● CPU executes code at a predefined address (e.g. CS0, address 0x100) ● for a PC: BIOS in flash on motherboard ● embedded e.g. U-Boot, Redboot or similar ● PC: ● if valid boot device is found, the 1st stage bootloader is loaded
  • 43.
    12/07/13 - MarcLeeman Company Confidential - 43 Stage 1 Bootloader (x86) ● <512 bytes, fits in 1 sector ● binary itself < 446 bytes ● 64 byte partition table ● 2 byte signature ● loaded from MBR boot device ● Task is to load second stage bootloader
  • 44.
    12/07/13 - MarcLeeman Company Confidential - 44 Boot device signature
  • 45.
    12/07/13 - MarcLeeman Company Confidential - 45 Stage 2 bootloader ● LILO/GRUB ● load and select kernel ● optionally selects initrd ● pass control to the kernel
  • 46.
    12/07/13 - MarcLeeman Company Confidential - 46 Kernel ● zImage (zlib, lzo or lzma compressed) ● without initrd, kernel should contain just the functionality to detect & mount root filesystem
  • 47.
    12/07/13 - MarcLeeman Company Confidential - 47 Kernel startup
  • 48.
    12/07/13 - MarcLeeman Company Confidential - 48 kernel startup (2) ● Assembly, arch specific ● head.S ● hardware initialisation and setup basic environment ● decompress kernel in memory ● Uncompressing Linux... Ok, booting the kernel ● startup_32: ● initialise page tables and enable memory paging ● CPU detection
  • 49.
    12/07/13 - MarcLeeman Company Confidential - 49 kernel startup (3) ● C, non arch specific ● start_kernel in init/main.c ● init interrupts ● (init ramdisk) ● initial root fs in memory/detect hardware ● embedded: can be final root filesystem ● memory initialisation ● thread_kernel starts /sbin/init ● first user-level application ● Can be modified to another application
  • 50.
    12/07/13 - MarcLeeman Company Confidential - 50 init ● First user-level application ● compiled/linked with libc ● uses /etc/inittab ● Spawn services ● sshd, apache, ... ● /bin/sh can also be used to start a single shell instead of init
  • 51.
    12/07/13 - MarcLeeman Company Confidential - 51 Runlevels (sysv) ● startup behaviour of init is divided in “runlevels” ● 0: Halt ● 1: Single User Mode ● 2: Basic Multi-User mode without NFS ● 3: Full Multi-User mode ● 4: Not used ● 5: Full Multi User Mode with X11 Login ● 6: Reboot ● Not so fixed, some distros use fewer levels (e.g. Slackware, Debian, ...)
  • 52.
    12/07/13 - MarcLeeman Company Confidential - 52 init scripts ● Most start scripts can be found in ● /etc/init.d/ ● /etc/rcX.d contains symbolic links to the scripts ● X: 1,2,3,4,5,6,S ● K20autofs ● S: start ● K: stop ● number for ordering: e.g. start network daemons after network devices.
  • 53.
    12/07/13 - MarcLeeman Company Confidential - 53 inittab entry ● 1:2345:respawn/sbin/getty 38400 tty1 ● id ● runlevels ● action ● process to be executed ● id:3:initdefault: ● default runlevel ● /etc/init.d/networking ● {start|stop|restart|force-reload}
  • 54.
    12/07/13 - MarcLeeman Company Confidential - 54 Boot Loaders
  • 55.
    12/07/13 - MarcLeeman Company Confidential - 55 Overview ● First thing to run after power on ● Tasks: ● Initialize (some of) hardware ● Load a kernel ● Execute it ● Boot loaders often have extra functionality: ● Access memory and registers ● Program flash ● ..
  • 56.
    12/07/13 - MarcLeeman Company Confidential - 56 Boot Loaders ● Lots of Linux compatible boot loaders ● LILO & GRUB well known ● PC specific ● Often platform specific ● Portable: ● RedBoot ● Das U-Boot
  • 57.
    12/07/13 - MarcLeeman Company Confidential - 57 Das U-Boot ● The universal boot loader ● Probably most feature full, flexible and most actively developed boot loader ● Very much focused on Linux ● Started as PPCBoot, but now portable ● Licensed under the GPL ● Has a alternative implementation barebox (u-boot-v2).
  • 58.
    12/07/13 - MarcLeeman Company Confidential - 58 U-Boot Features ● Flash support ● NOR, NAND, Dataflash, .. ● Compression ● GZIP, BZIP2 ● Interactive command line interface ● Boot scripting ● TCP/IP stack with BOOTP and DHCP, TFTP and NFS ● LOTS of drivers: ● Often ported from Linux ● IDE, SCSI, MMC, PCMCIA, USB, LCD, I2C, SPI, ..
  • 59.
    12/07/13 - MarcLeeman Company Confidential - 59 U-Boot Features (2) ● x86 emulation ● Graphics card POST on non-x86 ● File Systems ● JFFS2, Cramfs, squashfs EXT2, FAT, Reiserfs, .. ● Boot splash images ● FPGA configuration ● ...
  • 60.
    12/07/13 - MarcLeeman Company Confidential - 60 Exercise ● Bootup SheevaPlug in U-Boot and explore commands (type help) and environment variables (type printenv)
  • 61.
    12/07/13 - MarcLeeman Company Confidential - 61 U-Boot operation ● Once a working U-Boot (flash) is installed, upgrading can be done with serial/tftp/u-boot tftp 100000 /home/services/tftpboot/u-boot.bin protect off fe000000 fe03ffff era fe000000 fe03ffff cp.b 100000 fe000000 ${filesize} protect on fe000000 fe03ffff ● scripting helps :-) run burnfact
  • 62.
    12/07/13 - MarcLeeman Company Confidential - 62 Exercise ● Download u-boot 2010.06 and build for SheevaPlug. Update through JTAG or TFTP ● Check section 4.6 in manual ● Needed .deb's at http//neo.barco.com/~mleeman/downloads/SheevaPlugCourse
  • 63.
    12/07/13 - MarcLeeman Company Confidential - 63 The Linux Kernel
  • 64.
    12/07/13 - MarcLeeman Company Confidential - 64 History ● 1991: post in comp.os.minix ● Linux 0.1 ● 1994: Linux 1.0.0 ● 1996: Linux 2.0.0 ● 1999: Linux 2.2.0 ● 2001: Linux 2.4.0 ● 2003: Linux 2.6.0 ● 2011: Linux 3.0 ● 2012: Linux 3.5
  • 65.
    12/07/13 - MarcLeeman Company Confidential - 65 Architecture ● monolithic kernel ● drivers run in ring 0 ● X11 is in userspace ● contrary to Windows ● Supports ● preemption ● virtual memory ● memory management ● threading ● TCP/IP ● ... ● Mostly in C (97%), 3% ASM
  • 66.
    12/07/13 - MarcLeeman Company Confidential - 66 Modules ● kernel code that can access hardware directly ● modules can be loaded/unloaded and re-configured at run-time ● e.g. sudo modprobe xfs lsmod sudo insmod /path/to/xfs.ko sudo modprobe module param=1 ● Also in configuration file /etc/modprobe.d/module.conf
  • 67.
    12/07/13 - MarcLeeman Company Confidential - 67 Source Tree ● BIG! (~525 MB, 10M lines) ● A lot is drivers ● Core kernel ~5MB
  • 68.
    12/07/13 - MarcLeeman Company Confidential - 68 Source Tree (2) Kernel 2.6.36 ● 216M drivers ● 114M arch ● 32M fs ● 21M sound ● 19M include ● 19M net ● 17M Documentation ● 4.6M kernel ● 2.2M scripts ● 2.2M mm ● 1.7M crypto ● 1.4M lib ● 1.4M security ● 544K block ● 244K ipc ● 144K init ● 108K samples ● 56K usr
  • 69.
    12/07/13 - MarcLeeman Company Confidential - 69 Architecture Specific code ● arch/<cpu> ● arch/<cpu>/include/asm ● A few MB per arch ● Depending on no. supported boards
  • 70.
    12/07/13 - MarcLeeman Company Confidential - 70 Release Schedule ● New release every 2-3 months ● 2.6.39 19/05/2011 ● 3.0 22/07/2011 ● 3.1 24/10/2011 ● 3.2 05/01/2012 ● 3.3 22/03/2012 ● 3.4 21/05/2012 ● 3.5 21/07/2012 ● 3.6 01/10/2012 ● 3.7 11/12/2012 ● 3.8 19/02/2013 ● 3.9 29/04/2013 ● 3.10 30/06/2013
  • 71.
    12/07/13 - MarcLeeman Company Confidential - 71 Release Schedule (2) ● Tree is open for 2 weeks after release ● LOTS of activity – rc1 diff ~1M lines ● After that only bugfixes ● New -rcX release every 1-2 weeks ● 3.x.y stable releases for serious bugs found after release
  • 72.
    12/07/13 - MarcLeeman Company Confidential - 72 Tracking Development ● Linux kernel mailing list (2-300 mails/day) ● lwn.net Kernel - http://lwn.net/Kernel ● http://www.kernelnewbies.org/LinuxChan ges ● kernel.org gitweb: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=summary
  • 73.
    12/07/13 - MarcLeeman Company Confidential - 73 Device Tree ● Introduced in the PowerPC processor ports, moving to other archs (ARM, Microblaze) ● The Device Tree describes the hardware to the kernel ● Includes e.g. Flash map, PCI addresses, MAC addresses, ... ● U-Boot has support for modifying the dts/dtb
  • 74.
    12/07/13 - MarcLeeman Company Confidential - 74 User Space Interface ● Basically 3 types of interfaces: ● Character Devices ● Block Devices ● Network Devices ● (procfs, sysfs, netlink) ● Rarely needs to be implemented directly ● Kernel provides frameworks
  • 75.
    12/07/13 - MarcLeeman Company Confidential - 75 Character Devices ● Most common type ● Anything that can be viewed as a stream of bytes (serial ports, input devices, framebuffers, sound devices, ..) ● Accessed like normal files ● open/close/read/write/lseek/.. ● Additional settings through ioctl ● Added in kernel by ● Registering a cdev and implement file_operations
  • 76.
    12/07/13 - MarcLeeman Company Confidential - 76 Block Devices ● For Storage Devices ● Harddisks, MMC, USB keys, .. ● Accessed like Character Devices ● Kernel Interface More Complicated ● Added in kernel by ● Registering a gendisk and implement block_device_operations
  • 77.
    12/07/13 - MarcLeeman Company Confidential - 77 Network Devices ● For Network Devices ● Ethernet, Wireless, PPP, .. ● Accessed using socket API ● socket/accept/listen/recv/send/.. ● Configuration typically through programs/scripts ● ip/ifconfig/vconfig/ethtool/.. ● Added in kernel by ● Registering a net_device and implement net_device_ops
  • 78.
    12/07/13 - MarcLeeman Company Confidential - 78 Hardware Access ● Memory mapped registers ● Linux uses virtual memory (MMU) ● ioremap(physical address) logical ● read{b,w,l}(logical) ● write{b,w,l}(value, logical) ● iounmap(logical)
  • 79.
    12/07/13 - MarcLeeman Company Confidential - 79 Device Model ● Object Oriented, Tree Structured ● Busses (struct bus_type) ● Devices (struct device) ● Drivers (struct driver) ● Visible in sysfs ● Take a look on your PC! ● Saves code, Tree hierarchy important for E.G. power management
  • 80.
    12/07/13 - MarcLeeman Company Confidential - 80 Busses ● Devices connect to CPU through busses ● USB, PCI, I2C, SPI, Platform, .. ● Each corresponds to a specific bus_type ● Bus-specific interface for drivers ● Tree Based ● E.G. a USB controller on a PCI bus
  • 81.
    12/07/13 - MarcLeeman Company Confidential - 81 Devices and Drivers ● Object Oriented ● Drivers (Classes) ● Devices (Instances) ● Common interface ● Probe (Constructor) ● Remove (Destructor) ● Bus connects (binds) both together
  • 82.
    12/07/13 - MarcLeeman Company Confidential - 82 Platform Bus ● “Dummy” bus for simple memory mapped devices on SoCs ● Plug-n-play binding emulated through string matching (driver/device name member)
  • 83.
    12/07/13 - MarcLeeman Company Confidential - 83 Platform Bus Binding struct platform_device { const char * name; … }; struct platform_driver { struct device_driver driver { const char *name; }; ... }; ● Platform_device in platform code ● Platform_driver in device driver
  • 84.
    12/07/13 - MarcLeeman Company Confidential - 84 Resources static struct resource smc911x_resources[] = { [0] = { .start = 0x8e000000, .end = 0x8e0000ff, .flags = IORESOURCE_MEM, }, [1] = { .start = 4, .end = 4, .flags = IORESOURCE_IRQ, }, }; ● Generic way of providing platform details such as base address and IRQ: ●Platform data pointer for special stuff
  • 85.
    12/07/13 - MarcLeeman Company Confidential - 85 PCI Bus ● Device/Driver binding using PCI Vendor/Product ID (PnP) ● lspci ● USB is very similar 00:1f.3 SMBus: Intel Corporation N10/ICH 7 Family SMBus Controller (rev 02) 01:00.0 Ethernet controller: Marvell Technology Group Ltd. 88E8053 PCI-E Gigabit Ethernet Controller (rev 22) 02:00.0 Network controller: Atheros Communications Inc. AR5008 Wireless Network Adapter (rev 01) 03:03.0 FireWire (IEEE 1394): Agere Systems FW322/323 (rev 61) ..
  • 86.
    12/07/13 - MarcLeeman Company Confidential - 86 Character Interface ● Make communication available to userspace via device files # ls -l /dev |grep dsp crw-rw-rw- 1 0 0 252, 4 Jul 20 2006 dspa crw-r----- 1 0 0 252, 0 Jul 20 2006 dspa0 crw-r----- 1 0 0 252, 1 Jul 20 2006 dspa1 crw-r----- 1 0 0 252, 2 Jul 20 2006 dspa2 crw-r----- 1 0 0 252, 3 Jul 20 2006 dspa3 # ls -l /dev |grep fpga crw-r----- 1 0 0 253, 0 Jul 20 2006 fpgaa crw-r----- 1 0 0 251, 0 Jul 20 2006 nwwfpgaa
  • 87.
    12/07/13 - MarcLeeman Company Confidential - 87 read/write ● read/write on file handles ● copy data from the kernel to application code ● copy_to_user(...) ● copy data from application code to the kernel ● copy_from_user(...) ● If user reads ● kernel writes from userspace ● If user writes ● kernel reads from userspace
  • 88.
    12/07/13 - MarcLeeman Company Confidential - 88 Device Files ● ioctl is often used in code to send commands and data to the kernel/device ● For register access, read/write/lseek is better. ● bad example: static inline uint32_t ppc2dsp_getregister(const DSP *dsphandle,uint32_t address){ TSBarcoMemEntry entry; entry.addr = address; ioctl(*dsphandle,PPC2DSP_GET_REG,&entry); return entry.value; } dsp = open ("/dev/dspa", O_RDWR);
  • 89.
    12/07/13 - MarcLeeman Company Confidential - 89 ioctl ● fine tuned and often specialised hardware control ● allows to pass arbitrary data from user to kernel and vice versa ● int(*ioctl)(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg); ● switch(cmd) ● number 0..N cmd X-(
  • 90.
    12/07/13 - MarcLeeman Company Confidential - 90 Interrupts ● Kernel needs to act on a “hardware event” ● polling? ● slow and CPU intensive! ● An interrupt is a signal that the hardware can send when it wants the processor's attention.
  • 91.
    12/07/13 - MarcLeeman Company Confidential - 91 Flash Map ● Add partitions to the flash ● different functionality ● select between ● kernels ● root filesystems ● redundant configuration spaces ● file systems (jffs2, squashfs, ...) ● Create one logical area from multiple flash chips
  • 92.
    12/07/13 - MarcLeeman Company Confidential - 92 LED Class ● Kernel already has a framework for this ● See: ● drivers/leds ● Documentation/leds-class.txt ● /sys/class/leds ● gpio_led driver makes this very easy ● Various led-triggers can be hooked up
  • 93.
    12/07/13 - MarcLeeman Company Confidential - 93 File Systems
  • 94.
    12/07/13 - MarcLeeman Company Confidential - 94 Introduction ● More than 50 file systems supported ● More than any other OS ● What to choose?
  • 95.
    12/07/13 - MarcLeeman Company Confidential - 95 File System Types ● Disk based ● Flash based ● Network file systems ● “Virtual” file systems
  • 96.
    12/07/13 - MarcLeeman Company Confidential - 96 Disk Based ● Biggest group ● Native ● Supports all POSIX features ● EXT2/3/4, Reiserfs3/4, XFS, JFS, Btrfs, .. ● Recommended ● Compatibility ● Might not support all POSIX features ● Less performance ● FAT, NTFS, HPFS, BEFS, AFFS, ISO9660, UDF, ..
  • 97.
    12/07/13 - MarcLeeman Company Confidential - 97 Disk Based (2) ● Disks are not common in embedded systems ● PC-Like ● Flash with disk interface (USB, CF, MMC,..) ● Limit writes for flash! ● No journalling file systems ● noatime mount option ● EXT2 or FAT
  • 98.
    12/07/13 - MarcLeeman Company Confidential - 98 Flash Based ● Disk based can be used ● Kernel MTD layer can emulate block device ● Only realistic for read only ● Optimized for flash ● Cramfs (old) ● Squashfs ● Journalling file system 2 (JFFS2) (old) ● UBIFS
  • 99.
    12/07/13 - MarcLeeman Company Confidential - 99 Cramfs / Squashfs ● Read only ● Compression ● Squashfs finally in mainline ● Squashfs newer ● More features, better compression, faster ● Can also be used on disks ● Often combined with RAM disk for /tmp ● OpenWRT uses squashfs-lmza ● Squashfs + better compression ● Complex to implement: lmza non standard
  • 100.
    12/07/13 - MarcLeeman Company Confidential - 100 JFFS2 ● Read/write ● Compression, but less effective ● Journalling, so no fsck ● Long mount time on big partitions ● Complex ● Consider raw flash partition or EEPROM if data limited
  • 101.
    12/07/13 - MarcLeeman Company Confidential - 101 UBIFS ● Similar to JFFS2 but newer ● Uses UBI (Unsorted Block Images) ● More Scalable, faster mount time ● Better fit for (big) NAND flash
  • 102.
    12/07/13 - MarcLeeman Company Confidential - 102 Network File Systems ● NFS, SMBFS/CIFS ● AFS, CODA, 9FS, .. ● Not commonly used in production ● NFS very handy for development ● Kernel can boot on NFS ● NFS supports normal POSIX features
  • 103.
    12/07/13 - MarcLeeman Company Confidential - 103 “Virtual” File Systems ● No underlying media to store data ● Sysfs, procfs: Interface to kernel ● TMPFS: Dynamic RAM disks ● Devtmpfs: Dynamic /dev
  • 104.
    12/07/13 - MarcLeeman Company Confidential - 104 Conclusion ● Lots to choose from ● Most systems use more than one
  • 105.
    12/07/13 - MarcLeeman Company Confidential - 105 Userspace
  • 106.
    12/07/13 - MarcLeeman Company Confidential - 106 busybox http://www.busybox.net/ ● Most Unix command line utilities within a single executable! ● includes a web server! ● Sizes less than 1 MB (statically compiled with glibc) less than 500 KB (statically compiled with uClibc) ● Easy to configure ● The best choice for ● Initrds with complex scripts
  • 107.
    12/07/13 - MarcLeeman Company Confidential - 107 busybox ● combine unix utilities in one single small executable ● share startup code ● configurable commands ● configurable functionality of the commands ● applets easy to add
  • 108.
    12/07/13 - MarcLeeman Company Confidential - 108 ● Best way to describe: root@OpenWrt:~# busybox BusyBox v1.4.2 (2007-09-29 07:21:40 CEST) multi-call binary Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others. Licensed under GPLv2. See source distribution for full notice. Usage: busybox [function] [arguments]... or: [function] [arguments]... BusyBox is a multi-call binary that combines many common Unix utilities into a single executable. Most people will create a link to busybox for each function they wish to use and BusyBox will act like whatever it was invoked as! Currently defined functions: [, [[, arping, ash, awk, awx, basename, bunzip2, bzcat, cat, chgrp, chmod, chown, chroot, clear, cp, crond, crontab, cut, date, dd, df, dirname, dmesg, du, echo, egrep, env, expr, false, fgrep, find, free, grep, gunzip, gzip, halt, head, hexdump, hostid, httpd, id, ifconfig, init, insmod, ipkg, kill, killall, killall5, klogd, length, less, ln, lock, logger, logread, ls, lsmod, md5sum, mesg, mkdir, mkfifo, mknod, mktemp, mount, mv, nc, netmsg, netstat, nslookup, passwd, pidof, ping, ping6, pivot_root, poweroff, printf, ps, pwd, rdate, reboot, reset, rm, rmdir, rmmod, route, sed, seq, sh, sleep, sort, strings, switch_root, sync, sysctl, syslogd, tail, tar, tee, telnet, telnetd, test, time, top, touch, tr, traceroute, true, udhcpc, umount, uname, uniq, uptime, vconfig, vi, watchdog, wc, wget, which, xargs, yes, zcat
  • 109.
    12/07/13 - MarcLeeman Company Confidential - 109 Configuration ● Again, Kconfig based
  • 110.
    12/07/13 - MarcLeeman Company Confidential - 110 CGI `
  • 111.
    12/07/13 - MarcLeeman Company Confidential - 111 dropbear ● replaces telnetd ● obsolete since mid '90s ● secure communication ● no need for ● telnetd, ftpd, samba, ... ● tunnelling :-) ● Typical W32 clients ● PuTTy, WinSSH ● jcterm, mindterm ● GNU/Linux ● default
  • 112.
    12/07/13 - MarcLeeman Company Confidential - 112 Buildroot ● Not just for toolchains ● Can build entire Linux systems ● Make files, downloads over net ● No root permissions required ● Used in D&A and Medical ● Used in several Open Source projects: ● OpenWrt, Gumstix, ...
  • 113.
    12/07/13 - MarcLeeman Company Confidential - 113 Full blown Distributions ● Interesting option ● If disk(-like) storage available ● Little difference between SoC target and desktop/server ● Functionality is can easily be expanded ● Debugging tools ● Verification ● GNU/Debian supports 11 archs ● Lots of precompiled packages ● ~20.000 ● No need to cross compile
  • 114.
    12/07/13 - MarcLeeman Company Confidential - 114 First stage bootstrap ● Nice for development together with NFS ● Debootstrap –verbose –variant=minbase  –keyring=/home/me/pubring.gpg –include=apt  –arch=armhf –foreign vclub /home/me/chroot­2013  ftp://cypher.barco.com/nvslinux  /usr/share/debootstrap/scripts/wheezy ● Result is a armhf target on an x86-64 machine ● Installation requires a 'second-stage' installation ● Does not run natively (<==> x86 (i386))
  • 115.
    12/07/13 - MarcLeeman Company Confidential - 115 Second Stage bootstrap ● Qemu is needed ● QEMU can launch Linux processes compiled for one CPU on another CPU ● Fully system emulation ● Copy /usr/bin/qemu-static into $TARGET/usr/bin/qemu-static ● Why 'static'? ● Debootstrap /home/me/chroot­2013/  /debootstrap/debootstrap –second­stage
  • 116.
    12/07/13 - MarcLeeman Company Confidential - 116 Qemu ● Spot the difference ● marc@drd1812:~/Development$ uname ­a ● Linux drd1812 3.9.4 #1 SMP PREEMPT Thu May 30 12:53:13 CEST 2013 x86_64 GNU/Linux ● marc@drd1812:~/Development$ sudo chroot dolphin­dev­env­2013­03­11/ ● root@drd1812:/ dolphin­dev$ uname ­a ● Linux drd1812 3.9.4 #1 SMP PREEMPT Thu May 30 12:53:13 CEST 2013 armv7l GNU/Linux
  • 117.
    12/07/13 - MarcLeeman Company Confidential - 117 Packages ● a “package” refers to a compressed file archive containing all of the files that come with a particular application. ● Typical binary in nature ● Can install new functionality ● Can expand current functionality ● Can modify existing functionality ● Most common forms ● Debian package: file.deb ● Debian, Ubuntu, ... ● Redhat package: file.rpm ● Redhat, SuSE, Fedora, …
  • 118.
    12/07/13 - MarcLeeman Company Confidential - 118 Packages ● Selective upgrade ● Once deployed, typical bugfixes, security fixes
  • 119.
    12/07/13 - MarcLeeman Company Confidential - 119 Packages 101 ● Concept of a 'repo' ● Can be networked, on disk, on CD, USB, … ● deb ● deb­src ● Can be networked, on disk, on CD, USB, … ● In /etc/apt/sources.list.d/file.list ● deb ftp://cypher.barco.com/nvslinux/ vclub  main contrib non­free ● File, cdrom, http, ftp, copy, rsh, ssh, … ● Lots of command line, console and GUI front-ends
  • 120.
    12/07/13 - MarcLeeman Company Confidential - 120 Packages 101 ● Update the package descriptions ● $ sudo apt­get update ● Install a single package ● $ sudo dpkg barco­mna240_123­1.deb ● Install a single package with dependencies from the network ● $ sudo apt­get install barco­mna240 ● $ sudo apt­get remove barco­mna280 ● $ sudo apt­get purge barco­mna280 ● Upgrade the system without installing extra packages ● $ sudo apt­get upgrade
  • 121.
    12/07/13 - MarcLeeman Company Confidential - 121 Packages 101 ● Upgrade the system ● $ sudo apt­get dist­upgrade ● Search the package descriptions ● $ sudo apt­get search barco ● Show detailed package description ● $ sudo apt­get show barco­c12 ● Housekeeping ● Clear package cache ● $ sudo apt­get cache clear ● Remove unused packages ● $ sudo apt­get autoremove
  • 122.
    12/07/13 - MarcLeeman Company Confidential - 122 Privilege separation ● Services run as a separate (unprivileged) user: e.g. webserver, ftp, ssh, … ● Security concerns
  • 123.
    12/07/13 - MarcLeeman Company Confidential - 123 Setting up a Server
  • 124.
    12/07/13 - MarcLeeman Company Confidential - 124 General ● Platform of choice: GNU/Debian ● the developers' platform ● powerful, handy package management ● Check with IT: ● we will need DHCP (conflicts with corporate) ● Alternate: 2 network cards, external (Barco), internal (my.net.local).
  • 125.
    12/07/13 - MarcLeeman Company Confidential - 125 Needed & (Useful) ● NFS ● mount root filesystem without re-burning it to flash: much faster ● use larger filesystem than can be stored on flash for development ● DHCP/BOOTP ● cf. supra ● kernel send BOOTP package to get kernel/filesystem location over the network
  • 126.
    12/07/13 - MarcLeeman Company Confidential - 126 Needed & (Useful) ● atftpd ● Trivial ftp protocol ● used by U-Boot to obtain files over the network ● used by BDI2000 to get files over the network ● (bind) ● DNS server ● e.g. bdi02.smd.localnet is handier than 10.2.0.17
  • 127.
    12/07/13 - MarcLeeman Company Confidential - 127 Needed & (Useful) ● SSH ● Secure Shell ssh-keygen -t dsa -b 4096 scp ~/.ssh/id_dsa.pub me@remote: ssh me@remote 'mkdir -p ~/.ssh' ssh me@remote 'cat id_dsa.pub > ~/.ssh/authorized_keys' ● (Samba) ● Windows Share access ● (LDAP) ● Centralised account and rights and service management ● sudo & fakeroot ● selective super user root rights assignment
  • 128.
    12/07/13 - MarcLeeman Company Confidential - 128 Conclusions ● improvements to upstream sources ● communicate upstream ● e.g. Das U-Boot ● e.g. buildroot ● Kernel changes ● minimise them ASAP ● reduces maintenance to a minimum ● focus on the important code ● Montavista, MetroWerx
  • 129.
    12/07/13 - MarcLeeman Company Confidential - 129 References ● Update version of the examples, course text and slides: ● http://neo.barco.com/~mleeman/embedded_linux/ ● D&A info: ● http://ccwiki/EmbeddedLinuxTraining