分类: LINUX
2006-08-18 08:41:18
Adding a new command to BusyBox is simple because of its well-defined architecture. The first step is to choose a location for your new command's source. Select the location based on the type of command (networking, shell, and so on), and be consistent with other commands. This is important because your new command will ultimately show up in the particular configuration menu for menuconfig (in this case, in the Miscellaneous Utilities menu).
For this example, I've called the new command
(newcmd
) and placed it in the ./miscutils directory. The new command's source is shown in Listing 13.
|
Next, add your new command source to
Makefile.in
in the chosen subdirectory. In this
example, I update ./miscutils/Makefile.in
.
Add your new command in alphabetical order to maintain consistency with the
existing commands:
MISCUTILS-$(CONFIG_MT) += mt.o |
Next, update the configuration file, again within the ./miscutils directory, to make your new command visible within the configuration process. This file is called Config.in, and your new command is added in alphabetical order:
config CONFIG_NEWCMD |
This structure defines a new config entry (through the
config
keyword) and then the config option
(CONFIG_NEWCMD
). Your new command will either be
enabled or disabled, so use the bool
(Boolean)
menu attribute for configuration. Its default is disabled
(n
for No), and you end with a short Help description. You can see the
entire grammar for the configuration syntax in the source tree at
./scripts/config/Kconfig-language.txt.
Next, update the ./include/applets.h file to include your new command. Add the following line to this file, remembering to keep it in alphabetical order. It's important to maintain this order, otherwise your command will not be found.
USE_NEWCMD(APPLET(newcmd, newcmd_main, _BB_DIR_USER_BIN, _BB_SUID_NEVER)) |
This defines your command name (newcmd
), its
function name in the Busybox source (newcmd_main
),
where the link will be created for this new command (in this case, in
the /usr/bin directory), and, finally, whether the command has
permissions to set the user id (in this case, no).
The penultimate step is to add detailed Help information to the ./include/usage.h file. As you'll see from examples in this file, usage information can be quite verbose. In this case, I've just added a little information so I can build the new command:
#define newcmd_trivial_usage "None" |
The final step is to enable your new command (through make menuconfig
and then enable the option in the Miscellaneous Utilities menu) and then build BusyBox with make
.
With your new BusyBox available, you can test your new command, as shown in Listing 18.
$ ./busybox newcmd arg1 |
That's it! The BusyBox developers made a tool that's not only great but also simple to extend.