After a few days of tossing and suffering from the poor shell commands of Android, I finally made up my revolutionary determination. Let's take a look at how to replace a tiny toolbox with a great busybox. First, let's roughly describe the shell program in the Android system.
Shell implementation is divided into two parts:
I. shell interpreter and built-in commands
The source code is located in the system/CORE/SH Directory, which mainly completes the interpretation of shell commands, for builtins. the built-in commands in c are directly executed. For the extended toolbox commands, the toolbox program is called indirectly.
2. toolbox extension commands
This mainly completes the execution of extension commands. Each extension command corresponds to a name_main function, such as the LS command, corresponding to the ls_main function. At the same time, each extension command is implemented by the. c file under the system/CORE/toolbox/directory. Toolbox. C will generate the tools. h header file based on the. c file under this directory, and generate a connection to toolbox for each command in the system/CORE/toolbox/Android. mk file. The implementation structure of toolbox makes it easy to extend a command.
Suppose we want to manually add a shell command mycommand, as long as a new mycommand is created under the system/CORE/toolbox/directory. c file, and implement a mycommand_main function in it, and then in system/CORE/toolbox/android. add mycommand. c. Android. mk will automatically compile it into the Toolbox program, and generate a connection to the toolbox for this command under the compiled Android system/bin directory.
Next, I will translate an article on the Internet and use it to replace the toolbox that comes with Android with busybox.
Installing busybox command line tools
Original English address:
Https://gforge.ti.com/gf/project/omapandroid/wiki? Pagename = installing + busybox + command + LINE + tools
Install busybox command line tool in Android
This article briefly introduces how to install busybox to the android file system. If you want to install it directly, download the pre-compiled busybox that has been successfully tested on the android2.1 system from the address below, and skip the following installation steps.
Http://download.csdn.net/source/3093680
1. Compile busybox
1. download the latest busybox version. The latest version is 1.13.3 when writing this article.
: Http://www.busybox.net/
2. decompress the source code:
Tar jxf busybox-1.13.3.tar.bz2
3. Run menuconfig to configure busybox
CD busybox-1.13.3/
Make menuconfig
4. Set the following options in menuconfig:
Busybox settings --> build options --> build busybox as a static binary (no shared libs)-enable this option by pressing "Y"
Busybox settings --> build options --> Cross Compiler prefix-set this option equal to "arm-None-Linux-gnueabi -"
Busybox settings --> Installation Options --> don't use/usr-enable this option by pressing "Y"
5. Import the cross-compiler address to the environment variable:
Export Path =/opt/ARM/arm-2007q3/bin: $ path
6. Compile busybox
Make
Ii. Install busybox
Install busybox In the Android system and perform the following steps:
1. Create a/bin directory under the root directory of the Android system.
Mkdir/<path-to-Android-Fs>/bin
2. Copy the compiled busybox to the/bin directory.
CP busybox/<path-to-Android-Fs>/bin
3. Install busybox on the android machine.
CD/bin
./Busybox -- install
3. Use busybox as the default shell
Edit init. RC as follows:
1. Edit the console service to run busybox by default.
Service Console/system/bin/sh-> service console/bin/sh
2. Add the busybox path to the environment variable.
Export path/sbin:/system/bin:/system/xbin --> export path/bin:/sbin:/system/bin: /system/xbin
Note:
When I use busybox, I just want to simply add some commands and replace some of the functions of toolbox with incomplete commands, so the operations are not as complex as described above. Here is my alternative solution. You can try it:
1. Copy busybox to the/system/bin directory.
ADB push busybox/system/bin
2. Use ln to establish a connection to busybox.
For example, the toolbox provided by Android does not have the test command. To add the test command, we can:
CD/system/bin
Ln-s busybox Test
In this way, when you run the test command through the shell on the machine, the applet that implements the test function in busybox will be called.
For some original commands, such as LS and chown, if you do not want to use toolbox, you can also point their connection targets to toolbox and use chown as an example.
CD/system/bin
Rm chown
Ln-s busybox chown
In this way, the biggest benefit is to ensure that the system has the least changes and the shell function can be expanded to the maximum extent.
Reference:
Add busybox tool for Android
Http://blog.csdn.net/liaoshengjiong/archive/2009/03/04/3957725.aspx
What is cross-compilation?
Http://www.linuxeden.com/doc/article.php/21264
Add busybox Source
Http://cwhuang.info/2010/03/ad-busybox-source