Introduction:
I just got a new G1 Android phone, and since it runs Linux I just had to get the Bash shell running on it, the built in shell would just not do. I do need my tab completion after all. Cross compilation is the process of compiling software on one platform that is meant to run on another. With the following an ARM executable is compiled on a x86 Linux machine.

Requirements (Not sure if all this is needed, but it is what I used):

  • Cupcake 1.5 JS Build with root access: http://androidandme.com/2009/05/guides/beginners-guide-for-rooting-your-android-g1-to-install-cupcake/
  • ARM Toolkit (The Cross Compiler): http://www.codesourcery.com/gnu_toolchains/arm/download.html
  • Android SDK installed on Linux: http://developer.android.com/sdk/1.5_r2/index.htm
  • A G1
  • The source code for Bash 4.0: ftp://ftp.cwru.edu/pub/bash/bash-4.0.tar.gz

Step 1: Connect your pc to your phone with the SDK
You first have to be able to connect to your computer with adp which is included with the sdk. To do this with Ubuntu Januty Jackalope you first need to create a /etc/udev/rules.d/51-android.rules file with the following contents:

view source print ? 1. SUBSYSTEM== "usb" , SYSFS{idVendor}== "0bb4" , MODE= "0666"

After this run the following to restart udev: ’sudo /etc/init.d/udev reload’. Lastly, on your phone make sure Settings :: Applications :: Development :: USB Debugging is enabled and the plug in your phone. When you run ‘./adp devices’ you should see a device listed.

Step 2: Build the Bash Shell
After installing ARM toolkit in /home/kbrandt/bin/arm-toolkit (used for this example) set the following environment variables in your shell.

1. CC= '/home/kbrandt/bin/arm-toolkit/bin/arm-none-linux-gnueabi-gcc' 2. PATH= "$PATH:$HOME/bin/"

Then cd to the directory where you extracted the Bash source and run the following:

1. ./configure --prefix=/opt/arm_bash/ -host=arm-linux --enable- static -link --without-bash-malloc

Assuming that worked, edit the ‘Makefile’ file and change ‘CFLAGS = -g -O2′ to ‘CFLAGS = -g -O2 -static’ and then run ‘make’. If this works, it should create a bash executable in the current directory. You can verify that this has been compiled for the ARM architecture with ‘file bash’. This should return:

bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped

Step 3: Copy the File to your android.
From the host computer in the tools directory of the SDK run ‘./adb push ~/src/bash-4.0/bash /data/’ to copy the executable to the phone. If you try to copy it to your sdcard, make sure the sdcard is not mounted with the noexec mount option as this disables the executable permission bit.

Step 4: Run, Enjoy, and Find Bugs.
You can now connect to your phone with ‘./adp shell’ and cd to the data directory and run ‘./bash’ and you should get a bash prompt. You might need to ‘chmod 555 bash’ if you get permission denied.

References:
http://jiggawatt.org/badc0de/android/index.html

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Angular2-对象作为无线电输入值
  2. 如何在HTML视频标签中播放FLV视频?
  3. HTML5-Service Worker实现离线页面访问
  4. reload a div without reloading the who
  5. js获取html下拉框中选中值的自定义属性值
  6. html+css 图片右上角加删除叉,图片删除
  7. HTML DIV百分比宽度奇奇怪怪的间距产生了
  8. seo 优化去掉html 页面的后缀 .html
  9. form在提交时被取消:因为form没有被连接
  10. 使用表单字段值定制CSS属性。