Foreword for theSecond EditionSmartphones.PDAs.Home routers.Smarttelevisions.SmartBlu-rayplayers.Smart yo-yos.OK, maybe not.More and more of the everyday items in our homesand offices, used for work and play, have computers embedded in them.And thosecomputers arerunningGNU/Linux.YoumaybeaGNU/Linuxdeveloperusedtoworkingondesktop(ornotebook)Intel Architecture systems. Or you may be an embedded systems developer usedto more traditional embedded and/or real-time operating systems. Whatever yourbackground, if you're entering the world of embedded Linux development, Dorothy's“Toto, I've a feeling we're not in Kansas anymore"applies to you.Welcome tothe adventure!Dorothy had a goal, and some good friends, but no guide. You, however, are bet-ter off, since you're holding an amazing field guide to the world of embedded Linuxdevelopment. Christopher Hallinan lays it all out for you-the how, the where,the why, and also the“what not to do."This book will keep you out of the schoolof hard knocks and get you going easily and quickly on the road to building yourproduct.It is no surprise that this book has been a leader in its market. This new edition iseven better. It is up to date and brings all the author's additional experience to bearonthe subject.I am very proud to have this book in my series.But what's more important isthat you will be proud of yourself for having built a better product because you readit! Enjoy!Arnold RobbinsSeries Editorxxvi
ptg xxvi Foreword for the Second Edition Smart phones. PDAs. Home routers. Smart televisions. Smart Blu-ray players. Smart yo-yos. OK, maybe not. More and more of the everyday items in our homes and offices, used for work and play, have computers embedded in them. And those computers are running GNU/Linux. You may be a GNU/Linux developer used to working on desktop (or notebook) Intel Architecture systems. Or you may be an embedded systems developer used to more traditional embedded and/or real-time operating systems. Whatever your background, if you’re entering the world of embedded Linux development, Dorothy’s “Toto, I’ve a feeling we’re not in Kansas anymore” applies to you. Welcome to the adventure! Dorothy had a goal, and some good friends, but no guide. You, however, are better off, since you’re holding an amazing field guide to the world of embedded Linux development. Christopher Hallinan lays it all out for you—the how, the where, the why, and also the “what not to do.” This book will keep you out of the school of hard knocks and get you going easily and quickly on the road to building your product. It is no surprise that this book has been a leader in its market. This new edition is even better. It is up to date and brings all the author’s additional experience to bear on the subject. I am very proud to have this book in my series. But what’s more important is that you will be proud of yourself for having built a better product because you read it! Enjoy! Arnold Robbins Series Editor Download at www.wowebook.com
PrefaceAlthough many good books cover Linux, this one brings together many dimensionsof information and advice specifically targeted to the embedded Linux developer.Indeed, some very good books have been written about the Linux kernel, Linuxsystem administration, and so on.This book refers to many of the ones I consider tobeatthetopoftheircategories.Much of the material presented in this book is motivated by questions I've re-ceived over the years from development engineers in my capacity as an embeddedLinux consultant and from my direct involvement in the commercial embeddedLinux market.Embedded Linux presents the experienced software engineer with several uniquechallenges. First, those with many years of experience with legacy real-time operat-ing systems (RTOSs) find it difficult to transition their thinking from those environ-ments to Linux. Second, experienced application developers often have difficulryunderstanding the relative complexities of a cross-development environment.Although this is aprimer, intended for developers new to embedded Linux, I amconfident that even developers who are experienced in embedded Linux will benefitfrom the useful tips and techniques I have learned over the years.PRACTICALADVICEFORTHEPRACTICINGEMBEDDEDDEVELOPERThis book describes my view of what an embedded engineer needs to know to getup to speed fast in an embedded Linux environment. Instead of focusing on Linuxkernel internals,thekernel chapters in this bookfocus on the project nature of thekernel and leave the internals to the other excellent texts on the subject. You willlearn the organization and layout of the kernel source tree. You will discover thexovi
ptg xxvii Preface Although many good books cover Linux, this one brings together many dimensions of information and advice specifically targeted to the embedded Linux developer. Indeed, some very good books have been written about the Linux kernel, Linux system administration, and so on. This book refers to many of the ones I consider to be at the top of their categories. Much of the material presented in this book is motivated by questions I’ve received over the years from development engineers in my capacity as an embedded Linux consultant and from my direct involvement in the commercial embedded Linux market. Embedded Linux presents the experienced software engineer with several unique challenges. First, those with many years of experience with legacy real-time operating systems (RTOSs) find it difficult to transition their thinking from those environments to Linux. Second, experienced application developers often have difficulty understanding the relative complexities of a cross-development environment. Although this is a primer, intended for developers new to embedded Linux, I am confident that even developers who are experienced in embedded Linux will benefit from the useful tips and techniques I have learned over the years. PRACTICAL ADVICE FOR THE PRACTICING EMBEDDED DEVELOPER This book describes my view of what an embedded engineer needs to know to get up to speed fast in an embedded Linux environment. Instead of focusing on Linux kernel internals, the kernel chapters in this book focus on the project nature of the kernel and leave the internals to the other excellent texts on the subject. You will learn the organization and layout of the kernel source tree. You will discover the
xviliEmbedded LinuxPrimer,SecondEditionbinarycomponentsthatmakeupakernel image,howthey areloaded, andwhatpurpose they serve on an embedded system.In this book, you will learn how the Linux kernel build system works and howto incorporate your own custom changes that are required for your projects. Youwill learn the details of Linux system initialization, from the kernel to user spaceinitialization.You will learn many useful tips and tricks for your embedded project,from bootloaders,system initialization,file systems,and Flash memory to advancedkernel-and application-debugging techniques.This second edition features muchnew and updated content, as well as new chapters on open source build systems,USB and udev, highlighting how to configure and use these complex systems onyour embedded Linux project.INTENDEDAUDIENCEThis book is intended for programmers who have working knowledge of program-ming in C. I assume that you have a rudimentary understanding of local area net-works and the Internet. You should understand and recognize an IP address andhow it is used on a simple local area network.I also assume that you understandhexadecimal and octal numbering systems and their common usage in a book suchas this.Several advanced concepts related to C compiling and linking are explored, soyou will benefit from having at least a cursory understanding of the role of the linkerin ordinary Cprogramming.Knowledge of the GNU make operation and seman-tics also will prove beneficial.WHATTHISBoOKIsNoTThis book is not a detailed hardware tutorial. One of the difficulties the embeddeddeveloper faces is the huge variety of hardware devices in use today. The user manualfor a modern 32-bit processor with some integrated peripherals can easily exceed3,000 pages. There are no shortcuts. If you need to understand a hardware devicefrom a programmer's point of view, you need to spend plenty of hours in your fa-vorite reading chair with hardware data sheets and reference guides,and manymorehourswritingand testing codeforthesehardwaredevices!This is also not a book about the Linux kernel or kernel internals. In this book,you won't learn about the intricacies of the Memory Management Unit (MMU)
ptg xxviii Embedded Linux Primer, Second Edition binary components that make up a kernel image, how they are loaded, and what purpose they serve on an embedded system. In this book, you will learn how the Linux kernel build system works and how to incorporate your own custom changes that are required for your projects. You will learn the details of Linux system initialization, from the kernel to user space initialization. You will learn many useful tips and tricks for your embedded project, from bootloaders, system initialization, file systems, and Flash memory to advanced kernel- and application-debugging techniques. This second edition features much new and updated content, as well as new chapters on open source build systems, USB and udev, highlighting how to configure and use these complex systems on your embedded Linux project. INTENDED AUDIENCE This book is intended for programmers who have working knowledge of programming in C. I assume that you have a rudimentary understanding of local area networks and the Internet. You should understand and recognize an IP address and how it is used on a simple local area network. I also assume that you understand hexadecimal and octal numbering systems and their common usage in a book such as this. Several advanced concepts related to C compiling and linking are explored, so you will benefit from having at least a cursory understanding of the role of the linker in ordinary C programming. Knowledge of the GNU make operation and semantics also will prove beneficial. WHAT THIS BOOK IS NOT This book is not a detailed hardware tutorial. One of the difficulties the embedded developer faces is the huge variety of hardware devices in use today. The user manual for a modern 32-bit processor with some integrated peripherals can easily exceed 3,000 pages. There are no shortcuts. If you need to understand a hardware device from a programmer’s point of view, you need to spend plenty of hours in your favorite reading chair with hardware data sheets and reference guides, and many more hours writing and testing code for these hardware devices! This is also not a book about the Linux kernel or kernel internals. In this book, you won’t learn about the intricacies of the Memory Management Unit (MMU) Download at www.wowebook.com
Prefacexxixused to implement Linux's virtual memory-management policies and procedures;there are already several good books on this subject.You are encouraged to takeadvantage of the“Suggestions for Additional Reading”sections found at the end ofeverychapter.CONVENTIONSUSEDFilenames,directories,utilities,tools,commands,and codestatements are presentedin a monospace font, Commands that the user enters appear in bold monospace.New terms or important concepts are presented in italics.When you see a pathname preceded by three dots, this refers to a well-knownbut unspecified top-level directory.The top-level directory is context-dependent butalmost universally refers to a top-level Linux source directory. For example, .../arch/powerpc/kernel/setup_32.c refers to the setup_32.c file located in thearchitecture branch ofa Linux source tree.The actual path might be something like~/sandbox/linux.2.6.33/arch/power/kernel/setup_32.c.HOWTHISBoOKIsORGANIZEDChapter 1,“Introduction,"provides a brief look at the factors driving the rapidadoption of Linux in the embedded environment. Several important standards andorganizations relevant to embedded Linux are introduced.Chapter 2,“The Big Picture,”introduces many concepts related to embeddedLinux upon which later chapters are built.Chapter 3, “Processor Basics,” presents a high-level look at the more popularprocessors and platforms that are being used to build embedded Linux systems.Weexamine selected products from many of the major processor manufacturers.All themajorarchitecturefamilies arerepresented.Chapter 4,“The Linux Kernel: A Different Perspective,”examines the Linuxkernel from a slightly different perspective.Instead ofkernel theory or internals,welook at its structure,layout, and build construction so that you can begin learningyour way around this large software project and,more important, learn where yourown customization efforts must befocused.This includes detailed coverageof thekernel build system
ptg Preface xxix used to implement Linux’s virtual memory-management policies and procedures; there are already several good books on this subject. You are encouraged to take advantage of the “Suggestions for Additional Reading” sections found at the end of every chapter. CONVENTIONS USED Filenames, directories, utilities, tools, commands, and code statements are presented in a monospace font. Commands that the user enters appear in bold monospace. New terms or important concepts are presented in italics. When you see a pathname preceded by three dots, this refers to a well-known but unspecified top-level directory. The top-level directory is context-dependent but almost universally refers to a top-level Linux source directory. For example, ./ arch/powerpc/kernel/setup_32.c refers to the setup_32.c file located in the architecture branch of a Linux source tree. The actual path might be something like ~/sandbox/linux.2.6.33/arch/power/kernel/setup_32.c. HOW THIS BOOK IS ORGANIZED Chapter 1, “Introduction,” provides a brief look at the factors driving the rapid adoption of Linux in the embedded environment. Several important standards and organizations relevant to embedded Linux are introduced. Chapter 2, “The Big Picture,” introduces many concepts related to embedded Linux upon which later chapters are built. Chapter 3, “Processor Basics,” presents a high-level look at the more popular processors and platforms that are being used to build embedded Linux systems. We examine selected products from many of the major processor manufacturers. All the major architecture families are represented. Chapter 4, “The Linux Kernel: A Different Perspective,” examines the Linux kernel from a slightly different perspective. Instead of kernel theory or internals, we look at its structure, layout, and build construction so that you can begin learning your way around this large software project and, more important, learn where your own customization efforts must be focused. This includes detailed coverage of the kernel build system. Download at www.wowebook.com
xoxEmbedded Linux Primer, Second EditionChapter 5,“Kernel Initialization," details the Linux kernel's initialization pro-cess. You will learn how the architecture- and bootloader-specific image componentsareconcatenatedtotheimageofthekernelproperfordownloadingtoFlashandbooting by an embedded bootloader. The knowledge you gain here will help youcustomize the Linux kernel to your own embedded application requirements.Chapter6,“User SpaceInitialization,"continuesthedetailedexaminationof theinitialization process. When the Linux kernel has completed its own initialization,application programs continue the initialization process in a predetermined manner.Upon completing Chapter 6,you will have the necessaryknowledge to customizeyourownuserlandapplication startup sequence.Chapter 7,“Bootloaders,” is dedicated to the bootloader and its role in an em-bedded Linux system.We examine the popular open-source bootloader U-Boot andpresent a porting example. We briefly introduce additional bootloaders in use todayso that you can make an informed choice about your particular requirements.Chapter 8,“Device Driver Basics," introduces the Linux device driver model andprovides enough background to launch into one of the great texts on device drivers,listed in“"Suggestions for Additional Reading”at the end of the chapter.Chapter 9,“File Systems,"describes the more popular file systems being used inembedded systems today.We include coverage of theJFFS2,an important embed-ded file system used on Flash memory devices. This chapter includes a brief intro-ductiontobuildingyour own file system image,oneofthemoredifficult taskstheembeddedLinuxdeveloperfaces.Chapter 10,“MTD Subsystem,”explores theMemoryTechnology Devices(MTD) subsystem.MTD is an extremely useful abstraction layer between the Linuxfilesystem and hardware memory devices,primarilyFlash memory.Chapter 11,“BusyBox," introduces BusyBox, one of the most useful utilities forbuilding small embedded systems.Wedescribe howto configure and build BusyBoxfor your particular requirements, along with detailed coverage of system initializa-tion unique to a BusyBox environment.Appendix C,“BusyBox Commands," liststhe available BusyBox commands from a recent BusyBox release.Chapter 12,“Embedded Development Environment,"takes a detailed look atthe unique requirements of a typical cross-development environment. Several tech-niques are presented to enhance your productivity as an embedded developer, in-cluding the powerful NFS root mount development configuration
ptg xxx Embedded Linux Primer, Second Edition Chapter 5, “Kernel Initialization,” details the Linux kernel’s initialization process. You will learn how the architecture- and bootloader-specific image components are concatenated to the image of the kernel proper for downloading to Flash and booting by an embedded bootloader. The knowledge you gain here will help you customize the Linux kernel to your own embedded application requirements. Chapter 6, “User Space Initialization,” continues the detailed examination of the initialization process. When the Linux kernel has completed its own initialization, application programs continue the initialization process in a predetermined manner. Upon completing Chapter 6, you will have the necessary knowledge to customize your own userland application startup sequence. Chapter 7, “Bootloaders,” is dedicated to the bootloader and its role in an embedded Linux system. We examine the popular open-source bootloader U-Boot and present a porting example. We briefly introduce additional bootloaders in use today so that you can make an informed choice about your particular requirements. Chapter 8, “Device Driver Basics,” introduces the Linux device driver model and provides enough background to launch into one of the great texts on device drivers, listed in “Suggestions for Additional Reading” at the end of the chapter. Chapter 9, “File Systems,” describes the more popular file systems being used in embedded systems today. We include coverage of the JFFS2, an important embedded file system used on Flash memory devices. This chapter includes a brief introduction to building your own file system image, one of the more difficult tasks the embedded Linux developer faces. Chapter 10, “MTD Subsystem,” explores the Memory Technology Devices (MTD) subsystem. MTD is an extremely useful abstraction layer between the Linux file system and hardware memory devices, primarily Flash memory. Chapter 11, “BusyBox,” introduces BusyBox, one of the most useful utilities for building small embedded systems. We describe how to configure and build BusyBox for your particular requirements, along with detailed coverage of system initialization unique to a BusyBox environment. Appendix C, “BusyBox Commands,” lists the available BusyBox commands from a recent BusyBox release. Chapter 12, “Embedded Development Environment,” takes a detailed look at the unique requirements of a typical cross-development environment. Several techniques are presented to enhance your productivity as an embedded developer, including the powerful NFS root mount development configuration. Download at www.wowebook.com