%include "default.mgp" %default 1 bgrad 0 0 256 0 1 "black" "blue" %page %nodefault %center, size 7, font "standard", fore "white", vgap 20 Intro to Embedded Linux Programming %center, size 5, font "standard", fore "white" Linux Users Los Angeles 21 October 2003 *Draft* %center, size 7, font "standard", fore "white", vgap 20 Dan Kegel www.kegel.com www.lalugs.org %page Programming Embedded Linux Embedded Systems Developers Love Linux Accessing Embedded Linux Installing a Cross-Toolchain on your PC Compiling C/C++ Programs For Embedded Linux Building Embedded Linux from Scratch Summary / Questions %page Embedded Systems Developers Love Linux Linux is the OS of choice for new embedded systems Highly reliable, customizable, royalty-free Huge base of existing software New protocols often developed for Linux first Open Source -> you can fix problems yourself %page Getting At Embedded Linux Many devices officially support running Linux programs Handheld barcode scanners Upcoming cellphones from Motorola and Samsung Ixia network testers Others only support it unofficially or unwillingly :-) The TiVo personal video recorder Linksys routers Once you have a login prompt on the device, you're in business %page Yes, Virginia, you have to cross-compile Embedded Linux mindshare of top six CPU types (2002 LinuxDevices.com developer poll): x86 - 32% Arm - 27% (e.g. Linksys) PowerPC - 16% (e.g. TiVo 1) MIPS - 9% (e.g. Linksys, TiVo 2) SH - 5% (e.g. Dreamcast) Coldfire- 4% (e.g. Snapgear) To reach most of the market, you need to cross-compile! Most open-source software supports being cross-compiled (though you may have to nudge it a bit) %page Installing a Cross-Toolchain on your PC First, identify which CPU and C library the device uses Log in to the device and ask it what CPU it has, e.g. $ uname -m or $ cat /proc/cpuinfo That should display the CPU type (e.g. i386, ppc, arm, mips, sh, m68k...) Then guess the C library type with the command $ ls /lib/*libc-* If you see libuClibc-0.9.8.so, the device uses uClibc-0.9.8. If you see libc-2.2.5.so, the device uses glibc-2.2.5. %page Installing a Cross-Toolchain -- glibc One easy way: wget www.kegel.com/crosstool/crosstool-0.24.tar.gz tar -xzvf crosstool-0.24.tar.gz cd crosstool-0.24 export PREFIX=/mygcc eval `cat ppc405.dat` `cat gcc3.3.1-glibc2.3.2.dat` all.sh CPU and glibc version must match those of the device! Toolchain problems may require expertise to solve %page Compiling C/C++ Programs For Embedded Linux -- Hello, World! Put the toolchain's bin directory on your PATH, e.g. $ PATH=${PATH}:/mygcc/bin Then instead of cc, use the cross-compiler to compile, e.g. $ ppc-405-linux-gnu-gcc hello.c Projects using Makefiles can usually be compiled like this: $ make CC=ppc-405-linux-gnu-gcc though you should read and understand the Makefile first. %page Compiling C/C++ Programs For Embedded Linux -- autoconf Many open source projects use configure scripts. Some need overrides when cross-compiling, e.g. $ export ac_cv_func_setpgrp_void=yes $ ./configure --target=ppc-405-linux-gnu --build=i686-linux This generates a Makefile with CC=ppc-405-linux-gnu-gcc Autoconf is complex; read its tutorials and macro library! %page Building Embedded Linux from Scratch Cross-compiling not standardized; each package different Best practices dictate that you script the cross-compile Laziness dictates that you use someone else's scripts :-) ptxdist is a collection of Makefiles, one per package, so you don't have to reinvent the wheel "make menuconfig" picks which programs to install Supports about 80 packages so far (e.g. strace, nmap, oprofile, inetutils...) %page Summary Embedded Linux is becoming ubiquitous Embedded Linux tools are getting easier to set up and use Distributions like ptxdist make building custom embedded Linux systems from scratch easier Some Embedded Linux devices let end users run their own programs built with Embedded Linux tools %page Links Slides for this talk www.kegel.com/linux/embed Crosstool http://kegel.com/crosstool/ ptxdist http://www.pengutronix.de/software/ptxdist_en.html %page %center Questions %center %size 6 Questions? %page Legal stuff Copyright (C) 2003, Dan Kegel All rights reserved