PrefacexxiChapter13,“Development Tools,”examines many useful development toolsDebugging with gdb is introduced, including coverage of core dump analysis. Manymore tools are presented and explained, with examples including strace, ltrace,top, and ps, and the memory profilers mtrace and dmalloc. The chapter con-cludes with an introduction to the more important binary utilities, including thepowerfulreadelfutility.Chapter 14,“Kernel Debugging Techniques,”provides a detailed examinationof many debugging techniques useful for debugging inside the Linux kernel.Weintroduce the use of the kernel debugger KGDB and present many useful debuggingtechniques using the combination of gdb and KGDB as debugging tools. Includedis an introduction to using hardware JTAG debuggers and some tips for analyzingfailures when thekernel won't boot.Chapter 15, “Debugging Embedded Linux Applications,” moves the debuggingcontext from the kernel to your application programs. We continue to build on thegdb examples from the previous two chapters, and we present techniques for multi-threadedandmultiprocess debugging.Chapter16,“Open SourceBuild Systems,"replacesthekernel porting chapterfrom the first edition.That chapter had become hopelessly outdated, and propertreatment of that topic in modern kernels would take a book of its own. I thinkyou will be pleased with the new Chapter 16, which covers the popular build sys-tems availablefor building complete embedded Linux distributions.Among othersystems, we introduce OpenEmbedded, a build system that has gained significanttraction in commercial and other open source projects.Chapter 17,“Linux and Real Time,” introduces one of the more interesting chal-lenges in embedded Linux: configuring for real time via the PREEMPT_RT option.We cover the features available with RT and how they can be used in a design. Wealso present techniquesfor measuring latency in your application configuration.Chapter 18,“Universal Serial Bus,”describes the USB subsystem in easy-to-understandlanguage.Weintroduceconcepts and USBtopologyandthen presentseveral examples of USB configuration. We take a detailed look at the role of sysfsand USB to help you understand this powerfulfacility.We also present several toolsthatareusefulforunderstandingandtroubleshootingUSBChapter 19, “udev,” takes the mystery out of this powerful system configurationutility. We examine udev's default behavior as a foundation for understanding how
ptg Preface xxxi Chapter 13, “Development Tools,” examines many useful development tools. Debugging with gdb is introduced, including coverage of core dump analysis. Many more tools are presented and explained, with examples including strace, ltrace, top, and ps, and the memory profilers mtrace and dmalloc. The chapter concludes with an introduction to the more important binary utilities, including the powerful readelf utility. Chapter 14, “Kernel Debugging Techniques,” provides a detailed examination of many debugging techniques useful for debugging inside the Linux kernel. We introduce the use of the kernel debugger KGDB and present many useful debugging techniques using the combination of gdb and KGDB as debugging tools. Included is an introduction to using hardware JTAG debuggers and some tips for analyzing failures when the kernel won’t boot. Chapter 15, “Debugging Embedded Linux Applications,” moves the debugging context from the kernel to your application programs. We continue to build on the gdb examples from the previous two chapters, and we present techniques for multithreaded and multiprocess debugging. Chapter 16, “Open Source Build Systems,” replaces the kernel porting chapter from the first edition. That chapter had become hopelessly outdated, and proper treatment of that topic in modern kernels would take a book of its own. I think you will be pleased with the new Chapter 16, which covers the popular build systems available for building complete embedded Linux distributions. Among other systems, we introduce OpenEmbedded, a build system that has gained significant traction in commercial and other open source projects. Chapter 17, “Linux and Real Time,” introduces one of the more interesting challenges in embedded Linux: configuring for real time via the PREEMPT_RT option. We cover the features available with RT and how they can be used in a design. We also present techniques for measuring latency in your application configuration. Chapter 18, “Universal Serial Bus,” describes the USB subsystem in easy-tounderstand language. We introduce concepts and USB topology and then present several examples of USB configuration. We take a detailed look at the role of sysfs and USB to help you understand this powerful facility. We also present several tools that are useful for understanding and troubleshooting USB. Chapter 19, “udev,” takes the mystery out of this powerful system configuration utility. We examine udev’s default behavior as a foundation for understanding how Download at www.wowebook.com
xxii Embedded Linux Primer, Second Editionto customize it. Several real-world examples are presented.For BusyBox users, weexamineBusyBox'smdevutility.The appendixes cover the GNU Public License, U-Boot configurable com-mands,BusyBox commands, SDRAM interface considerations, resources for theopen source developer, and a sample configuration file for one of the more popularhardwareJTAG debuggers, theBDI-2000.FOLLOWALONGYou will benefit most from this book if you can divide your time between this bookand yourfavoriteLinux workstation.Graban old x86computer to experimentonan embedded system. Even better, if you have access to a single-board computerbased on another architecture, use that.The BeagleBoard makes an excellent low-cost platform for experimentation. Several examples in this book are based on thatplatform.You will benefit from learning the layout and organization of a very largecode base (the Linux kernel), and you will gain significant knowledge and experi-ence as you poke around thekernel and learn by doing.Look at the code and try to understand the examples produced in this book.Experiment with different settings, configuration options, and hardware devices.You can gain much in terms of knowledge, and besides, it's loads of fun.If youare so inclined, please log on and contribute to the website dedicated to this book,www.embeddedlinuxprimer.com. Feel free to create an account, add content andcomments to other contributions, and share your own successes and solutions as yougain experience in this growing segment of the Linux community.Your input willhelp others as theylearn.It is a work in progress,and your contributions will help itbecomeavaluable communityresource.GPLCOPYRIGHTNOTICEPortions of open-source code reproduced in this book are copyrighted by a largenumber of individual and corporate contributors.The code reproduced here hasbeenlicensedunderthetermsoftheGNUPublicLicense(GPL).AppendixAcontainsthetextoftheGNUPublicLicense
ptg xxxii Embedded Linux Primer, Second Edition to customize it. Several real-world examples are presented. For BusyBox users, we examine BusyBox’s mdev utility. The appendixes cover the GNU Public License, U-Boot configurable commands, BusyBox commands, SDRAM interface considerations, resources for the open source developer, and a sample configuration file for one of the more popular hardware JTAG debuggers, the BDI-2000. FOLLOW ALONG You will benefit most from this book if you can divide your time between this book and your favorite Linux workstation. Grab an old x86 computer to experiment on an embedded system. Even better, if you have access to a single-board computer based on another architecture, use that. The BeagleBoard makes an excellent lowcost platform for experimentation. Several examples in this book are based on that platform. You will benefit from learning the layout and organization of a very large code base (the Linux kernel), and you will gain significant knowledge and experience as you poke around the kernel and learn by doing. Look at the code and try to understand the examples produced in this book. Experiment with different settings, configuration options, and hardware devices. You can gain much in terms of knowledge, and besides, it’s loads of fun. If you are so inclined, please log on and contribute to the website dedicated to this book, www.embeddedlinuxprimer.com. Feel free to create an account, add content and comments to other contributions, and share your own successes and solutions as you gain experience in this growing segment of the Linux community. Your input will help others as they learn. It is a work in progress, and your contributions will help it become a valuable community resource. GPL COPYRIGHT NOTICE Portions of open-source code reproduced in this book are copyrighted by a large number of individual and corporate contributors. The code reproduced here has been licensed under the terms of the GNU Public License (GPL). Appendix A contains the text of the GNU Public License. Download at www.wowebook.com
Acknowledgments for theFirst EditionI am constantly amazed by the graciousness of open source developers. I am hum-bled by the talent in our community that often far exceeds my own.During thecourse of this project, I reached out to many people in the Linux and open sourcecommunity with questions. Most often my questions were answered quickly andwith encouragement. In no particular order, I'd like to express my gratitude to thefollowing members of the Linux and open source communitywho contributed an-swerstomyquestions:Dan Malek provided inspiration for some of the contents of Chapter 2.Dan Kegel and Daniel Jacobowitz patiently answered my toolchain questions.Scott Anderson provided the original ideas for the gdb macros presented inChapter14.Brad Dixon continues to challenge and expand my technical vision through hisown.GeorgeDavisansweredmyARMquestions.Jim Lewis provided comments and suggestions on the MTD coverage.Cal Erickson answered my gdb use questions.JohnTwomeyadvisedmeonChapter3.Lee Revell, Sven-Thorsten Dietrich, and Daniel Walker advised me on real-timeLinux content. Klaas van Gend provided excellentfeedback and ideas for my devel-opmenttools anddebuggingcontent.Many thanks to AMCC, Embedded Planet, Ultimate Solutions, and UnitedElectronic Industries for providing hardware for the examples.Many thanks to myemployer, Monta Vista Software,for tolerating the occasional distraction and forproviding software for some of the examples. Many others contributed ideas, en-couragement, and support over the course of the project. To themI am also grateful.xoxili
ptg xxxiii Acknowledgments for the First Edition I am constantly amazed by the graciousness of open source developers. I am humbled by the talent in our community that often far exceeds my own. During the course of this project, I reached out to many people in the Linux and open source community with questions. Most often my questions were answered quickly and with encouragement. In no particular order, I’d like to express my gratitude to the following members of the Linux and open source community who contributed answers to my questions: Dan Malek provided inspiration for some of the contents of Chapter 2. Dan Kegel and Daniel Jacobowitz patiently answered my toolchain questions. Scott Anderson provided the original ideas for the gdb macros presented in Chapter 14. Brad Dixon continues to challenge and expand my technical vision through his own. George Davis answered my ARM questions. Jim Lewis provided comments and suggestions on the MTD coverage. Cal Erickson answered my gdb use questions. John Twomey advised me on Chapter 3. Lee Revell, Sven-Thorsten Dietrich, and Daniel Walker advised me on real-time Linux content. Klaas van Gend provided excellent feedback and ideas for my development tools and debugging content. Many thanks to AMCC, Embedded Planet, Ultimate Solutions, and United Electronic Industries for providing hardware for the examples. Many thanks to my employer, Monta Vista Software, for tolerating the occasional distraction and for providing software for some of the examples. Many others contributed ideas, encouragement, and support over the course of the project. To them I am also grateful
ooxivEmbeddedLinuxPrimer,SecondEditionI offer my sincere appreciation to my primary review team, who promptly readeach chapter and provided excellent feedback, comments, and ideas. Thanks to Ar-nold Robbins, Sandy Terrace, Kurt Lloyd, and Rob Farber. Thanks also to DavidBrief, who reviewed the proposal and provided valuable input on the book's orga-nization. Many thanks to Arnold for helping this newbie learn the ropes of writinga technical book.Although I have made every attempt to eliminate mistakes, thosethat remainaresolelymyown.I want to thank Mark L.Taub for bringing this project to fruition and for his en-couragement and infinite patience.I want to thank the production team, includingKristyHart, Jennifer Cramer, Krista Hansing,and Cheryl Lenser.Finally, a very special and heartfelt thank-you to Cary Dillman, who read eachchapter as it was written, and for her constant encouragement and occasional sacri-fice throughout the project
ptg xxxiv Embedded Linux Primer, Second Edition I offer my sincere appreciation to my primary review team, who promptly read each chapter and provided excellent feedback, comments, and ideas. Thanks to Arnold Robbins, Sandy Terrace, Kurt Lloyd, and Rob Farber. Thanks also to David Brief, who reviewed the proposal and provided valuable input on the book’s organization. Many thanks to Arnold for helping this newbie learn the ropes of writing a technical book. Although I have made every attempt to eliminate mistakes, those that remain are solely my own. I want to thank Mark L. Taub for bringing this project to fruition and for his encouragement and infinite patience. I want to thank the production team, including Kristy Hart, Jennifer Cramer, Krista Hansing, and Cheryl Lenser. Finally, a very special and heartfelt thank-you to Cary Dillman, who read each chapter as it was written, and for her constant encouragement and occasional sacri- fice throughout the project. Download at www.wowebook.com
Acknowledgments fortheSecond EditionFirst I must acknowledge the guidance, experience, and endless patience of DebraWilliams Cauley,Executive Acquisitions Editor, without whom this project wouldneverhavehappened.Many thanks to my dedicated primary review team: Robert PJ. Day, SandyTerrace, Kurt Lloyd, Jon Masters, and series editor Arnold Robbins. I cannot sayenough about the value of their individual contributions to the quality of this book.Thanks also to Professor Mark A. Yoder and his embedded Linux class for givingthemanuscripta thoroughclassroomtest.A special thanks to Freescale Semiconductor for providing hardware that servedas the basis for many of the examples in this book.I would not have enjoyed thissupport without the efforts of Kalpesh Gala, who facilitated these arrangements.ThanksalsotoEmbeddedPlanetandTimVandeWalle,whoprovidedhardwareforsomeoftheexamples.Several individuals were especially helpful with adviceand answers toquestionsduring the project. In no particular order, my appreciation and thanks are extendedto Cedric Hombourger, Klaas van Gend, George Davis, Sven-Thorsten Dietrich,JasonWessels,and DaveAnders.I also want to thank the production team who endured my sometimes-hecticschedule.They include Alexandra Maurer,Michael Thurston, Jovana San Nicolas-Shirley, Gayle Johnson, Heather MeNeill, Tricia Bronkella, and Sarah Kearns.With every project of thismagnitude,countless people provide input in theformof an answer to a quick question, or perhaps an idea from a conversation.They aretoo numerous tomention but nonetheless deservecreditfortheirwillingand some-times unknowing support.In the first edition, I specifically thanked Cary Dillman for her tireless efforts toreview my chapters as they were written. She is now mylovely wife, Cary Hallinan.Cary continued her support by providing much-needed inspiration, patience, andoccasional sacrificethroughoutthe second-edition project.XOXV
ptg xxxv Acknowledgments for the Second Edition First I must acknowledge the guidance, experience, and endless patience of Debra Williams Cauley, Executive Acquisitions Editor, without whom this project would never have happened. Many thanks to my dedicated primary review team: Robert P.J. Day, Sandy Terrace, Kurt Lloyd, Jon Masters, and series editor Arnold Robbins. I cannot say enough about the value of their individual contributions to the quality of this book. Thanks also to Professor Mark A. Yoder and his embedded Linux class for giving the manuscript a thorough classroom test. A special thanks to Freescale Semiconductor for providing hardware that served as the basis for many of the examples in this book. I would not have enjoyed this support without the efforts of Kalpesh Gala, who facilitated these arrangements. Thanks also to Embedded Planet and Tim Van de Walle, who provided hardware for some of the examples. Several individuals were especially helpful with advice and answers to questions during the project. In no particular order, my appreciation and thanks are extended to Cedric Hombourger, Klaas van Gend, George Davis, Sven-Thorsten Dietrich, Jason Wessels, and Dave Anders. I also want to thank the production team who endured my sometimes-hectic schedule. They include Alexandra Maurer, Michael Thurston, Jovana San NicolasShirley, Gayle Johnson, Heather McNeill, Tricia Bronkella, and Sarah Kearns. With every project of this magnitude, countless people provide input in the form of an answer to a quick question, or perhaps an idea from a conversation. They are too numerous to mention but nonetheless deserve credit for their willing and sometimes unknowing support. In the first edition, I specifically thanked Cary Dillman for her tireless efforts to review my chapters as they were written. She is now my lovely wife, Cary Hallinan. Cary continued her support by providing much-needed inspiration, patience, and occasional sacrifice throughout the second-edition project