Book Image

Instant Optimizing Embedded Systems Using BusyBox

By : Wu Zhangjin, Cao Ziqiang
Book Image

Instant Optimizing Embedded Systems Using BusyBox

By: Wu Zhangjin, Cao Ziqiang

Overview of this book

As hundreds of millions of people have started using Android smartphones, embedded Linux systems are becoming more and more popular. To get more market share, not only for hardware and function piling up, smartphone manufacturers gradually realized the importance of user experience. To improve user experience, the back-end Linux system must be optimized in many ways. Instant Optimizing Embedded System Using BusyBox is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises to help you take advantage of the real power behind Busybox, and give you a good grounding for using it to optimize your embedded (Android Linux) systems. Moving on from the basics, this book will teach you how to configure and compile it from source code, including cross-compiling it with static linking and dynamic linking. You will also learn how to install and use Busybox on the Android emulator. You will learn to replace the simple Android mksh console with Busybox ash console and start a telnet and HTTP service provided by Busybox. You will also build embedded Linux file system from scratch and start it on Android emulator. We will take a look at how to add functionality to Busybox based system, including adding external applets to Busybox, as well as building development environments (like Bash and C) for it manually or with the automatic Buildroot system. If want to learn how to take advantage of using Busybox applets to optimize your embedded system, then this is the book for you for it will also show you how to use the powerful applets to optimize multiple aspects of an embedded (Android Linux) system.This book will teach you how to build an embedded (Android Linux) system with Busybox, enhance its functionality to meet diverse system requirements, and optimize it to provide a better user experience for embedded products.
Table of Contents (8 chapters)

Preface

BusyBox is a free GPL-licensed toolbox aimed at the embedded world. It is a collection of the tiny versions of many common Unix utilities. It can be compiled into one single binary and it provides a fairly complete environment for any small or large embedded system.

It is specifically designed for resource-limited and requirement-diverse embedded systems. It was written for size optimization and is extremely modular and highly configurable for system customization. Besides, it allows us to easily integrate new applets and to build embedded systems with it as a system base.

It provides basic shell programming and running environment. With the help of system generation tools like Buildroot, other generic tools and development environments can be added into the target embedded system easily. The benefit of these environments is that the target system can be enhanced to meet diverse requirements.

Besides daily-use utilities, it provides lots of lightweight replacements for powerful optimization tools and allows us to optimize the embedded system in many aspects, such as size tailoring, system stability enhancements, power consumption saving, system boot speedup, and debugging and tracing.

Android, a free ASL-licensed smartphone platform, is designed, developed, and released by Google. Benefitting from its Apache Software License (ASL), lots of third-party companies joined and formed the Open Handset Alliance. Without worrying about using open Android with their own non-open proprietary software, they produced many famous Android smartphones and eventually expanded the popularity of Android.

Behind the success of Android is a huge development investment. A large number of powerful software components have been developed, including the Android Goldfish emulator, Goldfish Linux kernel, Bionic libc, Java VM Dalvik, SDK, and NDK. Besides a BusyBox-like toolbox is added, but it is licensed under ASL and tailor-made for Android, only include a few of utilities and some platform-specific applets.

For embedded system optimization, we have no reason not to choose the famous BusyBox and Android. BusyBox is used as the toolbox and Android as the target platform. Their combination makes the requirement clear, experiment practical, and demonstration easy to understand.

What this book covers

Configuring BusyBox (Simple) introduces from where to download BusyBox source code, how to configure it for a particular requirement using defconfig, xxx_defconfig, oldconfig, allyesconfig/allnoconfig, menuconfig, and randconfig.

Compiling BusyBox (Simple) reveals that BusyBox supports multiple architectures and explains how to compile them locally for an x86 host and how to cross-compile it for the ARM platform. Static linking and dynamic linking are also discussed here.

Installing BusyBox (Simple) will introduce how BusyBox applets are invoked in different methods and demonstrate how to install BusyBox on a local host at the compiling stage or at runtime. Besides, its elaborate use as a root filesystem is shown with the chroot command.

Creating a virtual Android device (Simple) will use an Android emulator to create a virtual Android device as our embedded experimental platform. A virtual Nexus 7 will be created and launched on an Android emulator. The debugging features, adb, and the serial port are also demonstrated.

Playing BusyBox on a virtual Android device (Intermediate) will show the usage of the cross-compiled BusyBox on the virtual Android device. It will hack the prebuilt Android ramdisk image and use the BusyBox ash shell instead of an Android toolbox mksh shell and start it as the default console. Besides, network services such as telnetd and httpd will be shown to provide a remote shell and launch a remote web service respectively.

Building BusyBox-based embedded system (Intermediate) talks in depth about an Android ramdisk image. It shows how to make a bootable BusyBox-based root filesystem and convert it to an Android ramdisk. To boot it on an Android Emulator, a new version of Linux kernel is required and compiled.

Adding new applets to a BusyBox-based embedded system (Intermediate) introduces methods to enhance the functionality of BusyBox-based embedded systems. It shows how to integrate new lightweight applets. Besides this, it also teaches how to build standalone tools (Bash) and build utilities (C programming environment) with the automatic system, Buildroot.

Tailoring the system size of an embedded (Android) system (Advanced) will show you how to optimize the size of an embedded system to reduce disk and memory footprint and reserve more free storage for end users. Tools such as size is demonstrated.

Reducing the power consumption of an embedded (Android) system (Advanced) will discuss the common methods used to reduce power cost and show the usage of a power cost measuring tool called PowerTOP. The tools on an Android system, such as dumpsys alarm, dumpsys power, and /proc/wakelocks or /d/wakelocks interfaces, are also introduced.

Speeding up the system boot of an embedded (Android) system (Advanced) talks about how to reduce the time cost from system power on to the display of the graphic UI using both common methods and the measuring tool, bootchart. Besides, the grabserial tool is recommended for measuring the time taken for bootloader and kernel booting.

Enhancing the system stability of an embedded (Android) system (Advanced) shows the common methods to enhance system stability; the test automation method with the shell environment provided by BusyBox is discussed in depth with an open source Linux Device Driver Test framework: OMAP DDT. Also, Android tools such as CTS and monkeyrunner are introduced.

Increasing the serviceability of an embedded (Android) system (Advanced) introduces the methods to restore the failure generation scene; they include system logging, system debugging, and tracing. The Linux Kernel built-in debugfs, sysfs, procfs and Ftrace are discussed. The BusyBox built-in top, iostat, and devmems are demonstrated. Android-specific tools such as ram console, logger/logcat, and systrace are also introduced.

What you need for this book

BusyBox is a free GPL-licensed open source software. It can be downloaded easily from its main site or other mirror sites. An Ubuntu host is preferred for performing experiments and it's even better with a real (rooted) Android device.

Who this book is for

This book is written specifically for embedded system developers and Android developers who wish to optimize system performance. The prerequisites are basic knowledge of Linux and Unix utilities. This book also helps new developers start with BusyBox and Android development.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "In this recipe, we'll download BusyBox and configure it using defconfig, xxx_defconfig, oldconfig, allyesconfig/allnoconfig, menuconfig, and randconfig."

A block of code is set as follows:

# Start httpd service
httpd -h /data/www -p 8080
# Start telnetd service
telnetd -f /data/telnetd.issue -p 3333 -l /bin/ash

Any command-line input or output is written as follows:

$ adb forward tcp:3333 tcp:3333
$ adb forward tcp:8080 tcp:8080

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Start the AVD manager with android avd, choose the just created AVD and click on Start, choose Scale display to real size and click on Launch to start it.".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.