Informatique Embarque M2 / 2010 - 2011 Distributions Linux pour systmes embarqus, Compilation croise, ELF...
2010 FA-M2-Info Emb.
1
Distributions Linux
Distribution Vs Systme
Systme: Systme d'exploitation, Noyau Linux: http://kernel.org/ Arbre des sources des diffrentes versions du noyau Distribution: Ensemble des logiciels ncessaires pour une fonctionnalit complte et du noyau Inclus: outils d'administrations et applications Mount, fsck, ifconfig, init,... diteurs, compilateurs,..
2010 FA-M2-Info Emb.
2
Distributions Linux
Versions: A.B.C[.D]
A: numro de noyau (2)
Rarement chang (1 en 1994, 2 en 1996)
Distributions Linux
2010
FA-M2-Info Emb.
Distributions Linux
Novell
Suse: commercial, avec support OpenSuse: gratuit http://www.opensuse.org/
Mandriva
2010 FA-M2-Info Emb.
5
Distributions Linux
2010
FA-M2-Info Emb.
Distributions Linux
http://www.linuxfoundation.org/en/LSB
2010 FA-M2-Info Emb.
7
Distributions Linux
LSB
Complte la norme SUS (Single Unix Specif.)
Single Unix Specification v3 / Posix
http://en.wikipedia.org/wiki/Single_UNIX_Specification http://www.unix.org/what_is_unix/single_unix_specificatio n.html
Distributions Linux
Dfinit les fichiers d'inclusions (header files) Dfinit le comportement de la fonction Permet la portabilit source des applications aprs recompilation Ne permet pas la portabilit binaire des applications => ABI. Posix (sous-ensemble de SUS v3) dfinit une API
2010 FA-M2-Info Emb.
9
Distributions Linux
Distributions Linux
Contraintes temporelles
Ordonnanceur et prmptabilit appropris.
2010 FA-M2-Info Emb.
11
Distributions Linux
MontaVista Linux
Professional Edition Carrier-Grade Edition (Carrier Grade Linux) MobiLinux
Wind-River:
Platform for General Purpose -Linux Edition Platform for Consumer Device -Linux Edition Platform for Network Equipments -Linux Edition
(Carrier Grade Linux)
2010 FA-M2-Info Emb.
12
Distributions Linux
2010
FA-M2-Info Emb.
13
Distributions Linux
CLinux (you-see-Linux)
Noyau pour processeurs sans MMU
Distributions Linux
2010
FA-M2-Info Emb.
15
Distributions Linux
Distributions Spcifiques
Pour tlphones mobiles:
Linux Mobile Foundation (LiMo)
http://www.limofoundation.org/
OpenMoko Android
MobLin MeeGo
2010
FA-M2-Info Emb.
16
Distributions Linux
LiMo Platform
2010
FA-M2-Info Emb.
17
Distributions Linux
Quelle distribution?
Quel noyau?
Facile: uname -a , ou cat /proc/version
Quelle distribution?
/etc/redhat-release /etc/fedora-release /etc/slackware-version /etc/debian_version
On trouve des scripts qui font une recherche sur ces noms
2010 FA-M2-Info Emb.
18
Distributions Linux
Linux et Temps-rel
Linux 2.4:
Requiert des modifications (patch) RT-preempt, Low
Latency, O(1) scheduler
Linux 2.6:
Certaines modifications intgres dans les sources du noyau Patch PREEMP-RT si ncessaire
Distributions Linux
kernel
fs
mm
net
include lib
ipv4 asm-i386 ipv6 linux x25 atm ... net config ...
sparc cdrom
20
Distributions Linux
Configuration et compilation
tar -zxvf mon-archive.tgz make config | xconfig |menuconfig
On peut aussi importer un fichier de configuration
make
=> bzImage => modules
Distributions Linux
Modules Linux
Fichier objet (suffixe: .ko) Chargeable / dchargeable dynamiquement
Selon configuration du noyau Un pilote de priphrique, Un file systme, Autre,...
Commandes (super-utilisateur)
lsmod, insmod, rmmod, depmod, modinfo modprobe
2010 FA-M2-Info Emb.
22
Distributions Linux
Squence de Boot
Firmware charge un bootloader: Noyau
Initialisation, Installation de initrd Dmarrage de /linuxrc (ou /init)
Lilo ou Grub, ou ...
Linuxrc (/init)
Dtermine les modules ncessaires la poursuite du dmarrage: accs au file system racine Monte le file system racine, Pivote les racines
Distributions Linux
Initrd
Initrd:
File system (ext2 ou autre) stock en mmoire Construction complexe:
Crer un fichier normal (via dd) Initialiser comme un file system: mkfs, mke2fs,... Le monter avec un device loopback (droits super utilisateur) Le peupler avec les modules, fichiers requis Dmonter, Compresser
Distributions Linux
Initramfs
Utilis dans les versions de noyau >= 2.6.13
Compatibilit / support initrd assur(e)
Distributions Linux
Montage racine
Tous les drivers et file systems inclus dans le noyau,
=> pas besoin de initrd/initramfs
2010
FA-M2-Info Emb.
26
Distributions Linux
diteur de liens
/bin/ld
toto
27
2010
FA-M2-Info Emb.
Distributions Linux
Exemple: hello.c
#include <stdio.h> void foo() { printf("Hello World!\n"); } int main() { foo(); /* Appel procdure locale */
2010
28
Distributions Linux
Obtenir le fichier .s
#gcc -s hello.c foo: pushl movl subl movl call leave ret
2010
# cre hello.s %ebp %esp, %ebp $8, %esp $.LC0, (%esp) puts
FA-M2-Info Emb.
29
Distributions Linux
main:
Obtenir le fichier .s
leal andl pushl pushl movl pushl subl call call addl ..... ret
(suite)
4(%esp), %ecx $-16, %esp -4(%ecx) %ebp %esp, %ebp %ecx $4, %esp foo pause $4, %esp
2010
FA-M2-Info Emb.
30
Distributions Linux
2010
FA-M2-Info Emb.
31
Distributions Linux
hello.o dsassembl!
00000000 <foo>: 0: 1: 3: 6: d: 12: 13: 55 89 e5 83 ec 08 c7 04 24 00 00 00 00 e8 fc ff ff ff c9 c3 push mov sub movl call leave ret %ebp %esp,%ebp $0x8,%esp $0x0,(%esp) e <foo+0xe>
2010
FA-M2-Info Emb.
32
Distributions Linux
hello.o dsassembl!
00000014 <main>: 14: 8d 4c 24 04 18: 83 e4 f0 1b: ff 71 fc 1e: 55 1f: 89 e5 21: 51 22: 83 ec 04 25: e8 fc ff ff ff 2a: e8 fc ff ff ff ....
2010 FA-M2-Info Emb.
(suite)
0x12 0x17
33
Distributions Linux
Hello.o relocation
#objdump -r hello.o > hello_o.reloc hello.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]: OFFSET TYPE 00000009 R_386_32 0000000e R_386_PC32
2010 FA-M2-Info Emb.
Distributions Linux
Hello dsassembl!
080483d4 <foo>: 80483d4: 80483d5: 80483d7: 80483da: 80483e1: 80483e6: 80483e7: 55 89 e5 83 ec 08 c7 04 24 d0 84 04 08 e8 22 ff ff ff c9 c3 push mov sub movl call leave ret %ebp %esp,%ebp $0x8,%esp $0x80484d0,(%esp) 8048308 <puts@plt>
2010
FA-M2-Info Emb.
35
Distributions Linux
Hello dsassembl!
080483e8 <main>: 80483e8: 80483ec: 80483ef: 80483f2: 80483f3: 80483f5: 80483f6: 80483f9: 80483fe: 8d 4c 24 04 83 e4 f0 ff 71 fc 55 89 e5 51 83 ec 04 e8 d6 ff ff ff e8 f5 fe ff ff lea and pushl push mov push sub call call
(suite)
0x4(%esp),%ecx $0xfffffff0,%esp -0x4(%ecx) %ebp %esp,%ebp %ecx $0x4,%esp 80483d4 <foo> 80482f8 <pause@plt>
2010
FA-M2-Info Emb.
36
Distributions Linux
map hello
08048000-08049000 r-xp 00000000 03:01 278109 08049000-0804a000 rw-p 00000000 03:01 278109 b7e0b000-b7e0c000 rw-p b7e0b000 00:00 0 b7e0c000-b7f61000 r-xp 00000000 03:01 833389 b7f61000-b7f62000 r--p 00155000 03:01 833389 b7f62000-b7f64000 rw-p 00156000 03:01 833389 b7f64000-b7f67000 rw-p b7f64000 00:00 0 b7f72000-b7f75000 rw-p b7f72000 00:00 0 b7f75000-b7f76000 r-xp b7f75000 00:00 0 b7f76000-b7f90000 r-xp 00000000 03:01 824174 b7f90000-b7f92000 rw-p 0001a000 03:01 824174 bfb7c000-bfb91000 rw-p bffeb000 00:00 0
2010 FA-M2-Info Emb.
/home/debian/TP/hello /home/debian/TP/hello
Distributions Linux
/opt/arm/include stdio.h Binaire relogeable arm Binaire excutable arm Langage assembleur arm error! sh (i386)
diteur de liens
toto
/opt/arm/ bin/ld
2010
FA-M2-Info Emb.
38
Distributions Linux
Compilation, symboles
hello.c main() { printf("Hello\n"); } cc hello.s .LC0: .string "Hello\n" .text .globl main .type main,@function main: .... subl $12, %esp pushl $.LC0 call printf ..... as hello.o
nm
Distributions Linux
Librairies statiques
# cc hello.c -o hello -Wl,-static # file hello hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, statically linked, not stripped Utilise libc.a # size hello text data bss 365785 3820 315
2010
Distributions Linux
Librairies dynamiques
# cc hello.c -o hello #file hello hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped Utilise libc.so # size hello text data bss dec hex filename 818 256 4 1078 436 hello
2010 FA-M2-Info Emb.
41
Distributions Linux
Librairies
Statiques hello.o main libc.a printf malloc Copie hello main printf malloc hello main /lib/libc.so Dynamiques hello.o main libc.so printf malloc
2010
FA-M2-Info Emb.
42
Distributions Linux
Librairies statiques
Librairies
Duplique le code des librairies dans chaque excutable, disque et mmoire Taille sur disque (de(s) l'excutable(s)) plus importante Mais pas de dpendances, excutable "autonome" Chargement en mmoire: simple
Librairies dynamiques
Ne duplique pas le code des librairies (ni sur disque ni en mmoire) Taille sur disque (de l'excutable) moins importante, mais ncessit d'avoir la librairie Dpendances entre excutables et librairies Chargement en mmoire plus complexe: besoin d'un "loader" Bibliothques compiles avec "Position Independent Code"
2010 FA-M2-Info Emb.
43
Distributions Linux
Librairies
Statiques Dynamiques pile pile
libc.so
donnes hello
FA-M2-Info Emb.
Distributions Linux
Distributions Linux
Accs aux donnes: Par table d'indirection (GOT: Global Offset Table) Calcul au chargement ou la demande (lazy)
Impact sur le dterminisme
2010 FA-M2-Info Emb.
46
Distributions Linux
Fichiers ELF
ELF: Executable and Linking Format Les fichiers binaires utilisent gnralement un format baptis ELF (impos par LSB)
Binaires relogeables (.o) Binaires xutables Librairies partages (.so) Core dump
Distributions Linux
Fichiers ELF
Program Header Table
Dcrit un ou plusieurs segments Program Header Table Utile ( run-time) pour le Text / Code chargement
Entte ELF
48
Distributions Linux
Manipulation ELF
Commandes:
objdump readelf
Librairie de manipulation
Libelf (FreeBSD) Linux?
2010
FA-M2-Info Emb.
49
Distributions Linux
ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Intel 80386 Version: 0x1 Entry point address: 0x8048100 Start of program headers: 52 (bytes into file) Start of section headers: 373088 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers:4 Size of section headers: 40 (bytes) Number of section headers:21 Section header string table index: 18
2010 FA-M2-Info Emb.
50
Distributions Linux
Program Headers
Program Headers: Type Offset Flg Align VirtAddr PhysAddr FileSiz MemSiz
LOAD 0x000000 0x08048000 0x08048000 0x595e8 0x595e8 R E 0x1000 LOAD RW NOTE R 0x05a000 0x080a2000 0x080a2000 0x00eec 0x01b54 0x1000 0x0000b4 0x080480b4 0x080480b4 0x00020 0x00020 0x4
2010
FA-M2-Info Emb.
51
Distributions Linux
ELF: sections
Section Headers: [Nr] Name [ 0] [ 1] .init [ 2] .text [ 3] __libc_freeres_fn [ 4] .fini [ 5] .rodata [ 6] __libc_subfreeres [ 7] __libc_atexit [ 8] .eh_frame [ 9] .data [10] .ctors [11] .dtors
2010
[Nr] Name [12] .jcr [13] .got [14] .bss [15] __libc_freeres_pt [16] .comment [17] .note.ABI-tag [18] .shstrtab [19] .symtab [20] .strtab
FA-M2-Info Emb.
52
Distributions Linux
2010
FA-M2-Info Emb.
53
Distributions Linux
# size hello_dyn text data bss dec 818 256 4 1078 # ls -l hello_dyn -rwxr-x--4662
FA-M2-Info Emb.
54
Distributions Linux
BusyBox: Principes
http://www.busybox.net/ Crer une commande unique fournissant les services des commandes usuelles
Exemples: ls, cp, sed, diff, mkdir... Gains:
Rutilisation de code commun non fourni par des librairies vite les copies bibliothques statiques sur disque/mmoire, mais on peut utiliser les librairies dynamiques
Fournir des versions rduites de ces commandes Voir aussi FreeBSD crunchgen
2010 FA-M2-Info Emb.
55
Distributions Linux
BusyBox
On peut excuter les commandes individuelles:
# busybox ls # discrimine sur argv[1] # ln busybox ls; ls # discrimine sur argv[0]
Le "contenu" de BusyBox est configurable par makefile: make menuconfig On peut ajouter ses propres "applets" (attention, GPL, pas LGPL) Souvent combin avec Clibc, et LinuxTiny
2010 FA-M2-Info Emb.
56
Distributions Linux
Compilation croise
make CROSS_COMPILE=arm-linux-uclibcgnueabi-
Distributions Linux
uClibc (LGPL)
http://www.uclibc.org/ Initialement cre pour supporter uCLinux
Machines sans MMU -> sans support mmoire virtuelle
Utilisable sur toute machine Gnrer avec une chane croise toolchain On peut aussi utiliser des versions binaires disponibles sur le site.
2010
FA-M2-Info Emb.
58
Distributions Linux
Toolchain, binutils
(http://sources.redhat.com/binutils/)
Distributions Linux
Distributions Linux
OpenWrt
Distribution Linux embarqu
Focus sur intgration rseau Utilisation dans routeurs WiFi par exemple
Distributions Linux
OpenEmbedded
http://www.openembedded.org
Approche similaire OpenWrt Utilis par OpenMoko, Palm pour WebOS Supporte environnement graphique pour les machines cibles (FB, Qt) Permet de maintenir les modifications / adaptations dans des overlays
2010
FA-M2-Info Emb.
62
Distributions Linux
OpenEmbedded
http://www.openembedded.org
Compilation croise pour # processeurs Construction distribution complte pour mmoires flash Possibilit de construire pour d'autres environnements (OpenWrt) Multiples format de paquetages (rpm, deb, ipk) Librairies: uClibc, glibc, eglibc ...
2010 FA-M2-Info Emb.
63