Busybox questions - Android Software Development

1. When I make an app for rooted devices, are there any commands I can count on working on the device, whether or not it has busybox? On my Archos, all standard Linux commands including the shell itself, mount, cat, chmod, echo, cp and mv are provided by busybox. Are any of these commands available on a device without a busybox? I read some instructions on the web on how to install a busybox on a device that doesn't have it, and the instructions talked of copying it to some directory and using chmod, but I don't see how that can be done on a device that doesn't have a busybox. Or do no-busybox devices still provide a shell and some basic commands (which ones?)?
2. I suppose one solution to the no-busybox problem is just to package a copy of busybox in the apk, but that requires my app to be GPL. Titanium Backup seems to solve the problem by downloading busybox from a website. I guess that's GPL-compliant, as long as one provides source code for busybox, though it's a messy way of proceeding. But there is also a bootstrapping question. If my app downloads busybox, how can it install it without busybox working? Minimally, one needs to set busybox to be executable, and without chmod, how to do that?

Most androids have a stripped-down busybox-like app called toolbox. It is linked to several of the commands you listed. busybox adds dozens more.
Here's a list of /system/bin on a stock Inspire4G
Code:
find -type l -printf "%l %f\n"
toolbox date
toolbox ls
toolbox top
toolbox printenv
toolbox nandread
toolbox ionice
toolbox sync
toolbox log
toolbox getprop
toolbox getevent
toolbox ioctl
toolbox rmdir
toolbox vmstat
toolbox smd
toolbox umount
toolbox route
toolbox cat
toolbox hd
toolbox dd
toolbox schedtop
toolbox uptime
toolbox rm
toolbox ln
toolbox lsmod
toolbox kill
toolbox lsof
toolbox newfs_msdos
toolbox id
toolbox df
toolbox mv
toolbox ps
toolbox renice
toolbox sendevent
toolbox wipe
toolbox dmesg
toolbox rmmod
toolbox mkdir
toolbox sleep
toolbox chownto
toolbox mount
toolbox chmod
toolbox watchprops
toolbox notify
toolbox stop
toolbox cmp
toolbox ifconfig
toolbox insmod
toolbox setprop
toolbox start
toolbox chown
toolbox netstat
toolbox setconsole
toolbox iftop

Thanks! This is good to know, especially that there is no echo.
My Archos has both toolbox and busybox, but links the standard commands to busybox, though it uses toolbox for a small handful of things.
Do the devices that don't have busybox have some sort of a shell? If so, what kind of shell? (Bourne?) I assume they have some sort of shell since you can apparently do "adb shell" on them.

Yes, /system/bin/sh is a stripped down (bourne based I think) shell. A shell is necessary for a lot of the base operations of the device. Most ROM cookers install bash as a replacement, but busybox has a pretty decent built-in shell. The busybox shell is actually more strict that the built-in shell and some necessary command scripts like `am' and `pm' wont work since they don't have a script header ("#!/systen/bin/sh"):
Code:
cat am
# Script to start "am" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/am.jar
exec app_process $base/bin com.android.commands.am.Am "[email protected]"

Thanks again for the help!
So the lesson is that for maximum portability, one should use the toolbox commands, and then check with the toolbox source code (system/core/toolbox) to see what options are available for the commands and make sure that whatever options one is using work on both busybox and toolbox.
In particular, if one needs to write a line to a file, "echo" is not acceptable. I guess one way to write portably is chmod a+w, then write with java.io, and then chmod a-w when finished. I'll have to revise my SuperDim to do this.
By the way, it looks like toolbox is apache-licensed, so if there are some systems that don't have it (are there?), one can just package it up and include it (plus include an apache notice) in a closed source app.

arpruss said:
By the way, it looks like toolbox is apache-licensed, so if there are some systems that don't have it (are there?), one can just package it up and include it (plus include an apache notice) in a closed source app.
Click to expand...
Click to collapse
It is part of the AOSP Android project so I imagine every device has it. It contains the minimum shell commands necessary to boot, mount, and load the davlik VM.
Note: there are duplicates of tools in both toolbox and busybox. A few I unlink from toolbox and relink to busybox are ls (to get colors and extra options like -lrS) mount (to do proper remounts) and maybe a couple of others I can't remember.

Related

Adfree does not updating [Updated 2/17/11]

So I am running Adfree and everytime I update it and restart the phone and launch an app, in this case XDA, I still have adds, any ideas. Thanks.
Sent from my GT-P1000 using XDA App
EDIT: ok so i found this on another thread and it states do use the following:
adb shell
su
remount rw /system
cd /system/etc
cp hosts /data/data/
rm hosts
ln -s /data/data/hosts .
remount ro /system
since i am not familiar with adb i tried running via terminal emulator and i get the following error:
remount: not found
any suggestions?
EDIT [2/17/11] thanks to shmigao for the answer, it seems that apparently the command remount is not available in this ROM (MoDaCo Custom ROM)

Creating Custom ROM...Need help!

Hi All,
So here's the thing.. I've started to dabble in creating my own ROM, and I've hit a roadblock. I've started out with the basics, took JS7 from Samfirmware.com, replaced Zimage with a Hardcore Kernel, Zipaligned and de-odexed it, changed boot animation and shutdown animation, and created an update.zip. That's all. When I try to flash through CWM Recovery, (I did factory reset, dalvik, cache partion) I get an error:
E: Can't symlink /system/bin/cat
E: Failure at line 7:
symlink toolbox SYSTEM:bin/cat
Installation aborted.
I've messed around with the Galaxy for quite a while, but when am fairly new to the creation process.....Any and all help would be greatly appreciated, as when I get the hang of the basics of this I have big plans for an awesome ROM!
Thanks in advance,
Marky
what does line 7 says in updater-script? can you post the script?
deconfrost said:
what does line 7 says in updater-script? can you post the script?
Click to expand...
Click to collapse
Hey thanks for responding...so it is a problem with the updater-script? Forgive my ignorance...like i said im new to the cooking thing...where is it located in the rom?
Sent from my GT-I9000 using Tapatalk
Nevermind found it will post in a sec
Sent from my GT-I9000 using Tapatalk
show_progress 0.1 0
format SYSTEM:
delete DATA:local
delete_recursive SYSTEM:
delete_recursive DATA:dalvik-cache
copy_dir PACKAGE:system SYSTEM:
symlink toolbox SYSTEM:bin/cat
symlink toolbox SYSTEM:bin/chmod
symlink toolbox SYSTEM:bin/chown
symlink toolbox SYSTEM:bin/cmp
symlink toolbox SYSTEM:bin/date
symlink toolbox SYSTEM:bin/dd
symlink toolbox SYSTEM:bin/df
symlink toolbox SYSTEM:bin/dmesg
symlink toolbox SYSTEM:bin/getevent
symlink toolbox SYSTEM:bin/getprop
symlink toolbox SYSTEM:bin/hd
symlink toolbox SYSTEM:bin/id
symlink toolbox SYSTEM:bin/ifconfig
symlink toolbox SYSTEM:bin/iftop
symlink toolbox SYSTEM:bin/insmod
symlink toolbox SYSTEM:bin/ioctl
symlink toolbox SYSTEM:bin/ionice
symlink toolbox SYSTEM:bin/kill
symlink toolbox SYSTEM:bin/ln
symlink toolbox SYSTEM:bin/log
symlink toolbox SYSTEM:bin/ls
symlink toolbox SYSTEM:bin/lsmod
symlink toolbox SYSTEM:bin/mkdir
symlink toolbox SYSTEM:bin/mount
symlink toolbox SYSTEM:bin/mv
symlink toolbox SYSTEM:bin/nandread
symlink toolbox SYSTEM:bin/netstat
symlink toolbox SYSTEM:bin/newfs_msdos
symlink toolbox SYSTEM:bin/notify
symlink toolbox SYSTEM:bin/printenv
symlink toolbox SYSTEM:bin/ps
symlink toolbox SYSTEM:bin/reboot
symlink toolbox SYSTEM:bin/renice
symlink toolbox SYSTEM:bin/rm
symlink toolbox SYSTEM:bin/rmdir
symlink toolbox SYSTEM:bin/rmmod
symlink toolbox SYSTEM:bin/route
symlink toolbox SYSTEM:bin/schedtop
symlink toolbox SYSTEM:bin/sendevent
symlink toolbox SYSTEM:bin/setconsole
symlink toolbox SYSTEM:bin/setprop
symlink toolbox SYSTEM:bin/sleep
symlink toolbox SYSTEM:bin/smd
symlink toolbox SYSTEM:bin/start
symlink toolbox SYSTEM:bin/stop
symlink toolbox SYSTEM:bin/sync
symlink toolbox SYSTEM:bin/top
symlink toolbox SYSTEM:bin/umount
symlink toolbox SYSTEM:bin/vmstat
symlink toolbox SYSTEM:bin/watchprops
symlink toolbox SYSTEM:bin/wipe
show_progress 0.1 10
show_progress 0.2 0
set_perm_recursive 0 0 0755 0644 SYSTEM:
set_perm_recursive 0 2000 0755 0755 SYSTEM:bin
set_perm_recursive 0 0 0755 0755 SYSTEM:etc
set_perm 0 3003 02755 SYSTEM:bin/netcfg
set_perm 0 3004 02755 SYSTEM:bin/ping
set_perm_recursive 1002 1002 0755 0440 SYSTEM:etc/bluetooth
set_perm 0 0 0755 SYSTEM:etc/bluetooth
set_perm 1002 1002 0440 SYSTEM:etc/dbus.conf
set_perm 1014 2000 0550 SYSTEM:etc/dhcpcd/dhcpcd-run-hooks
set_perm 0 2000 0550 SYSTEM:etc/init.goldfish.sh
set_perm_recursive 0 0 0777 0777 SYSTEM:etc/init.d
set_perm 0 0 04755 SYSTEM:xbin/su
set_perm 0 0 04755 SYSTEM:xbin/busybox
show_progress 0.2 10
show_progress 0.3 0
symlink /system/xbin/su SYSTEM:bin/su
run_program PACKAGE:root
show_progress 0.3 10
show_progress 0.4 0
format CACHE:
copy_dir PACKAGE:data DATA:
set_perm 2000 2000 0771 DATA:local
set_perm 1000 1000 0771 DATA:app
copy_dir PACKAGE:sdcard SDCARD:
copy_dir PACKAGE:updates TMP:/updates
set_perm 0 0 755 TMP:/updates/redbend_ua
run_program /tmp/updates/redbend_ua restore /tmp/updates/modem.bin /dev/block/bml12
run_program /tmp/updates/redbend_ua restore /tmp/updates/zImage /dev/block/bml7
show_progress 0.4 10
have you try doing a nandroid backup, format system, wipe the rest, then flash?
If you have that error when the updater tries to create that symlink, that means most of the time that a /system/bin/cat file already exists.
Thanks, I will look into that....appreciate you taking the time to try to help
Does that mean each symlink command creates the file it describes in System/bin?
I would hope so
Ok, so I tried what you said, formatted system, wiped, still getting the same error at the /cat file...btw doesn't the line in the script that says "delete_recursive SYSTEM:" do that? when I apply the zip it says formatting system...
THX
markywylder said:
Hi All,
Zipaligned and de-odexed it, changed boot animation and shutdown animation, and created an update.zip.
Click to expand...
Click to collapse
Sorry, how do you make zipalign and odex? And how do you create update.zip?
Sent from my GT-I9000 using Tapatalk
markywylder said:
Ok, so I tried what you said, formatted system, wiped, still getting the same error at the /cat file...btw doesn't the line in the script that says "delete_recursive SYSTEM:" do that? when I apply the zip it says formatting system...
THX
Click to expand...
Click to collapse
that's strange, may need someone more experience than I on your case, Im not that experienced. I did created a working update.zip but I can't see what went wrong on yours, or maybe im just missing something.
I will post back if I can find anything for you.
Your English is fine
Funny to be answering a question in my thread asking a question...lol
Follow this Link http://forum.xda-developers.com/showthread.php?t=633246
and do a little reading
Once again I really appreciate you trying to help me, I hit the thanks button If I can ask what steps/Base Rom did you use to create yours, and did you create your own updater-script?
I made mine based on CM7 for the Desire HD, mostly like what you did, changed boot animation, removed some system apps that I dont want, added a few tools and apps I want, changed the launcher etc, I went through updater-script that was already there for CM7 stock rom, yes mine uses updater-script and update-binary, zipalign and resigned, flashed and worked.
deconfrost said:
I made mine based on CM7 for the Desire HD, mostly like what you did, changed boot animation, removed some system apps that I dont want, added a few tools and apps I want, changed the launcher etc, I went through updater-script that was already there for CM7 stock rom, yes mine uses updater-script and update-binary, zipalign and resigned, flashed and worked.
Click to expand...
Click to collapse
I don't know if this means anything or not, but I don't have an update-binary, but I've looked at some updater-scripts for Galaxy S and they seem to have them...Any Idea where I find/create this for mine? I can't seem to find the updater script on the stock ROM...
if its update-script you have in yours, it doesnt use update-binary, updater-script uses update-binary, also got something to do with the version of clockwork you use, I'm using 3.0.0.6 for Desire HD, and it will not work with update-script, so it needs to be converted to updater-script and the binary, and the codes are slightly different in the script.
deconfrost said:
if its update-script you have in yours, it doesnt use update-binary, updater-script uses update-binary, also got something to do with the version of clockwork you use, I'm using 3.0.0.6 for Desire HD, and it will not work with update-script, so it needs to be converted to updater-script and the binary, and the codes are slightly different in the script.
Click to expand...
Click to collapse
yes, you're right, I've just found that out...upgraded dsixda's kitchen and it converts the update-script to updater-script and adds a binary for you. Thanks, zipping and signing the file now wish me luck!
good luck on it
I'm heading for the bed hope it works for you this time.
deconfrost said:
good luck on it
I'm heading for the bed hope it works for you this time.
Click to expand...
Click to collapse
whether it does or not, thanks for your time dude
Got the ROM to install, but when rebooting I'm hanging on the Galaxy Screen (not the animated one)....Anyone?
I would say the problem is to do with boot.img

sl4a shell script help

Hi all,
I'm trying to run a shell script in sl4a but I'm running into problems. Here's what I want to do: change ADW configuration files in one click (since the app doesn't yet do it natively). There are two files that need to be changed for this to happen:
Code:
/data/data/org.adwfreak.launcher/databases/launcher.db
/data/data/org.adwfreak.launcher/shared_prefs/adw_ex_preferences.xml
I'm trying to delete those files and copy in new files from a stored location on the SD card but I can't get the sl4a script to run the following rm commands:
Code:
rm -rR /data/data/org.adwfreak.launcher/databases/launcher.db
rm -rR /data/data/org.adwfreak.launcher/shared_prefs/adw_ex_preferences.xml
I use
Code:
su -c
before the rm commands to run them as root, but the error then is that the /data partition is not mounted (which I find strange since it should be rw anyway...). I've tried using
Code:
mount -o remount,rw /dev/block/userdata /data
and it looks like it runs but then it doesn't work and I can't rm the files anyway.
Am I running into a limitation of sl4a or shell scripts in sl4a? I can rm the files from the terminal, so I'm not sure what the issue is. I'm very new to this (obviously) so any tips would be helpful. Thanks!
Here is my full script currently:
Code:
#!
kill android.process.acore
kill org.adwfreak.launcher
busybox rm -R /data/data/org.adwfreak.launcher/databases/*
busybox rm -R /data/data/org.adwfreak.launcher/files/*
busybox rm -R /data/data/org.adwfreak.launcher/shared_prefs/*
cp /sdcard/adw_ex_launcher.db /sdcard/ADW/Honeycomb/adw_ex_launcher.db
cp /sdcard/adw_ex_settings.xml /sdcard/ADW/Honeycomb/adw_ex_settings.xml
cp /sdcard/ADW/Portrait/adw_ex_launcher.db /sdcard/adw_ex_launcher.db
cp /sdcard/ADW/Portrait/adw_ex_launcher.db /data/data/org.adwfreak.launcher/databases/launcher.db
chmod 664 /data/data/org.adwfreak.launcher/databases/launcher.db
cp /sdcard/ADW/Portrait/adw_ex_settings.xml /sdcard/adw_ex_settings.xml
cp /sdcard/ADW/Portrait/adw_ex_settings.xml /data/data/org.adwfreak.launcher/shared_prefs/adw_ex_preferences.xml
chmod 664 /data/data/org.adwfreak.launcher/shared_prefs/adw_ex_preferences.xml
exit
When I test the rm commands in the sl4a shell, they don't remove the files even when the /data partition is mounted. I've tried all that I know. Help please!
Sent from my DROIDX
I don't know what you are trying in your second post, but from your first post I would say:
Code:
su
busybox rm -r /data/data/org.adwfreak.launcher/databases/*
busybox rm -r /data/data/org.adwfreak.launcher/files/*
busybox rm -r /data/data/org.adwfreak.launcher/shared_prefs/*
cp /sdcard/adw/prefs.xml /data/data/org.adwfreak.launcher/shared_prefs/
..
kill org.adwfreak.launcher
If you do "chmod 664" on the files, you also have to do "chown & chgrp" or the launcher won't be able to write into the settings xml's/db's.
And /data ist mounted rw, everything else would be senseless.
Thanks for the response.
I'm trying to change ADW configuration with one click. I'm going to use Tasker to create a widget that, when clicked, runs a script. That script will:
1. delete the current ADW configuration files (launcher.db and adw_ex_preferences.xml)
2. copy the target configuration files to the proper places (and set permissions, owner, group)
3. restart ADW so that the configuration is loaded
OR
3. open the ADW settings page so that I can click "restore desktop" and "restore preferences" and have the configuration loaded in an almost-one-click solution.
The script in the 2nd post is my best effort at that. I have tried the busybox part of the script, but I don't believe it makes a difference. I will try again, though, and report back.
As far as chown and chgrp goes, I'll add in what I think that should be and post that back later, too.
Fr4gg0r said:
I don't know what you are trying in your second post, but from your first post I would say:
Code:
su
busybox rm -r /data/data/org.adwfreak.launcher/databases/*
busybox rm -r /data/data/org.adwfreak.launcher/files/*
busybox rm -r /data/data/org.adwfreak.launcher/shared_prefs/*
cp /sdcard/adw/prefs.xml /data/data/org.adwfreak.launcher/shared_prefs/
..
kill org.adwfreak.launcher
If you do "chmod 664" on the files, you also have to do "chown & chgrp" or the launcher won't be able to write into the settings xml's/db's.
And /data ist mounted rw, everything else would be senseless.
Click to expand...
Click to collapse
Progress update: Success! More or less.
I realized I wouldn't need to remove the files since the ones I was copying in would just overwrite them anyway, so that cleared up that issue.
I did add chown and chgrp (a piece of information I'm sure I'll find useful in the future) so I'm sure that helped. Making sure to get the group and owner right PER YOUR OWN SETUP was key. When I changed ROMs I had to redo it... so check properties with Root Explorer or whatever.
I revised my script a little to add the background wall paper, too.
The true key, however, was using Lua in SL4A and using the 'sush' script in this post here:
http://code.google.com/p/android-scripting/issues/detail?id=184 (comment #9). That allowed me to run my script in the 'sush' format and do what I wanted.
I also had to add a line to kill the launcher process (android.process.acore) so it would restart itself.
I now have a one-click solution to changing between two ADW desktop configurations/settings!
I've attached my script if anyone would like it. Just get SL4A, the Lua interpreter, and put the pieces together! (Use a custom shortcut on the desktop and not a widget and the desktop setup will be preserved; widgets aren't supported in any method...)

Replacing Toolbox with Busybox

Hi,
I've just replaced the stock toolbox with busybox provided by netarchy kernel package. Maybe there is a better way to do this, but I'm just playing with my new phone
Anyway, this is what I did:
Info
nexus model: I9023
rom: stock 2.3.4 with root permission
kernel: 2.6.35.13-netarchy-nexus-1.3.7-bfs-2.3.4
busybox version: 1.16.0 (included in netarchy kernel package)
Entering adb shell
Code:
adb shell
Inside adb shell:
Replacing toolbox with busybox
Code:
mount -o rw,remount /dev/block/mmcblk0p1 /system
busybox mv /system/bin/toolbox /system/bin/toolbox.bak
busybox ln -s /system/xbin/busybox /system/bin/toolbox
mount -o ro,remount /dev/block/mmcblk0p1 /system
Add a new command
After remounting rw /system
Code:
ln -s /system/xbin/busybox /system/xbin/COMMAND
For example:
Code:
mount -o rw,remount /dev/block/mmcblk0p1 /system
ln -s /system/xbin/busybox /system/xbin/chroot
mount -o ro,remount /dev/block/mmcblk0p1 /system
If you know a better way, tell me! Anyway I hope this could be useful
Download "busybox" by Stericson
Install busybox thru that app
Uninstall "busybox" by Stericson (busybox will stay intact)
snandlal said:
Download "busybox" by Stericson
Install busybox thru that app
Uninstall "busybox" by Stericson (busybox will stay intact)
Click to expand...
Click to collapse
Or just download BusyBox from Titanium Backup.
Code:
# busybox --install /system/xbin
should do the trick -- be warned, you'll get *a whole lot* of symlinks to busybox
snandlal said:
Download "busybox" by Stericson
Install busybox thru that app
Uninstall "busybox" by Stericson (busybox will stay intact)
Click to expand...
Click to collapse
Great, thanks. I've installed that busybox and it works great!
suksit said:
Code:
# busybox --install /system/xbin
should do the trick -- be warned, you'll get *a whole lot* of symlinks to busybox
Click to expand...
Click to collapse
Yes, I installed busybox in /system/xbin and it created a lot of symlinks, but it's ok because in this dir there is almost nothing.
Anyway, thanks for the tip
???
Weird! After running shell script, I can no longer stay connected on wireless for more than a couple of minutes. I think something was replaced and it shouldn't be replaced!
Any hint?
In most Android systems, the c binary stalk is installed in /system/bin and is handled by TOOLBOX.
If we install BUSYBOX with any of the apps mentioned above, it will most likely be installed in /system/xbin
So at the end we'll end up with 2 utilities handling some binaries that are clones as it show in both /system/bin and /system/xbin
and because the PATH includes both locations then wouldn't that create some complications and possible hanging/crashing of the android system ???

SwiFTP - fix for freezing downloads

I was using SwiFTP to upload files, but it seemed to freeze when downloading ...
The reason is that the /system/bin/ls command on S3 returns output which is different from previous Android versions ...
The solution is to replace /system/bin/ls (which points to toolbox) to point to busybox.
Code:
cd /system/bin
mv ls ls.orig
ln -s /system/xbin/busybox ls
Make sure you have busybox installed in /system/xbin and that your /system partition is mounted read/write.
If you don't know what this is doing, please don't attempt to do it

Categories

Resources