Wednesday, March 28, 2012

memory leak tracking on android, cont

You have Android version >= 2.2.

Make sure you have libc_malloc_debug_leak.so:
  • > adb shell ls /system/lib/libc_malloc_debug_leak.so
Enable the memory leak check:
  • > adb shell setprop libc.debug.malloc 1
Restart the Android framework, make sure the memory leak check is functional:
  • > adb shell stop
  • > adb shell start
  • > adb logcat -b main -v threadtime (you see this line in the printed log: 03-29 03:10:52.942 4200 4200 I libc : /system/bin/logcat using MALLOC_DEBUG = 1 (leak checker))
In your DDMS configuration file (e.g. ~/.android/ddms.cfg on Linux), add "native=true". This enables the Native Heap tab. Now you can use the "Native Heap" tab features to grab snapshots of the heap memory usage. Group by library to view the memory usage in libraries. Show new allocations comparing to the previous snapshot to monitor the memory allocation increments. If you are using the images built by your own, fill the "Symbol Search Path" to get more details information.

More options:
  • > adb shell setprop libc.debug.malloc 5
# For filling allocated /freed memory with patterns defined by CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
  • > adb shell setprop libc.debug.malloc 10
# For adding pre-, and post- allocation stubs in order to detect buffer overruns.

Monday, September 26, 2011

Android sh script, why failed with [ not found

A simple sh script, but run failure with error: [ not found.

#!/system/bin/sh
if [ $? eq 0 ]; then
    echo "Command run successful"
fi
The same script can run well on Linux.
I dont know why, but I finally got a solution.
Upload a busybox, change it to executable permissions, create a soft link "[" to busybox. Like the following:
-rwxr-xr-x 500      500       1877260 2011-09-22 02:42 busybox
lrwxrwxrwx root     root              2011-09-26 08:15 [ -> /sbin/busybox
Run the sh script again, which shall give no error any more.
Finally, make sure the searching path $PATH can find command "busybox", and "[".

Thursday, July 14, 2011

Disable Linux kernel version magic check

Linux kernel will refuse to load kernel module if the version magic is not match. It can be easily disabled for some ease.
Find linux kernel kernel/module.c, find "check_modinfo" function, comment out "return -ENOEXEC;" for same_magic(...) check function.

How to get a console with root if Motorola XOOM is working as USB Host and connected with USB devices

If Motorola XOOM is connected with USB devices and working as USB Host mode, you will not be able to have adb shell work on PC. The only USB connection is used for other purpose. Here is a tip to have a console with root even the USB connection is used for USB device.

  • Motorola XOOM is rooted
  • Push a busybox to Motorola XOOM, make it executable
  • Connect Motorola XOOM with PC, in a PC cmd window, adb shell to the device, the shell must be a root shell.
  • Start telnetd: busybox telnetd -l /system/bin/sh
  • Download a telnet APP for Motorola XOOM, e.g. BlowTorch. Launch telnet client (BlowTorch), telnet to device, a root console is served.

Wednesday, July 13, 2011

USB Host Mode on Motorola XOOM

Motorola XOOM gets USB host functionality. No software changes, this article shows you how to enable Motorola XOOM the ability of USB host functionality, which grant you the potential to have the ability to read media from external SD card reader, USB HD, USB DVD adapter, USB LAN adapter, and etc. Potentially, Motorola XOOM can work as a PC and access all kinds of external USB devices. Will introduce the software level changes later to enable reading from SD card reader, connect USB LAN, etc.
Motorola XOOM works as a portable device (just like the mobile phone), provides a micro-usb to connect to PC. In this way, PC can access media in the Motorola XOOM. Motorola XOOM works as a USB client.
Motorola XOOM can also work in Host mode, because it has the USB OTG (on-the-go). How to switch the USB OTG on the Motorola XOOM to USB Host mode? It is very simple. You just need need a USB toggle cable. The USB toggle cable looks like the following:

After the Motorola XOOM plugs with this USB toggle cable, it can connect with all kinds of USB devices. To make the USB devices work on Motorola XOOM, linux drivers change may be needed. Will introduce some later.
In the kernel log, following message will be shown after USB toggle cable connected:

Tuesday, July 12, 2011

Step by step to enable LAN access for Motorola XOOM

With the USB toggle cable connected with Motorola XOOM, Motorola XOOM can work with all kinds of USB devices, such as USB LAN, so to connect with Local Area Network.
Pre-requisite:

  • A rooted Motorola XOOM
  • USB toggle cable
  • USB LAN adapter
  • Networking Cat5 cable
USB LAN adapter:
Google USB LAN adapter, there are many USB LAN adapter. A typical USB LAN adapter is shown below.
Networking Cat5 cable:
Not sure why, but looks a straight through Networking Cat5 cable does not work with the above USB LAN adapter. Make sure the cable has one end terminated with T568A scheme, the other end terminated with T568B scheme. Google them for more details.
Kernel driver changes:
  • Get to know the USB LAN adapter device ID and vendor ID. With USB LAN adapter connected with Motorola XOOM through USB toggle cable, find dmesg kernel log with following information. Write down the device ID and vendor ID.
  • Add "CONFIG_USB_NET_DM9601=y" into kernel config file to have drivers/net/usb/dm9601.c compiled into kernel object.
  • Add vendor ID and device ID into drivers/net/usb/dm9601.c, struct usb_device_id structure, referenced by variable products[]. e.g.
  • + {
  • + USB_DEVICE(0x0fe6, 0x9700), /* XXXY */
  • + .driver_info = (unsigned long)&dm9601_info,
  • + },
  • Compile the kernel, and apply new kernel to Motorola XOOM. New kernel will fail to load Wifi module because of un-matched kernel version magic, disable kernel version magic matching will resolve this issue.
DHCP client for USB LAN adapter interface:
Power up Motorola XOOM with Network Cat5 cable connected with Motorola XOOM through USB LAN adapter and USB toggle cable. The connection looks like the following. After XOOM is up, run "dhcpcd eth0" in a console with root. After dhcpcd return, eth0 shall get an IP. Ping command shall work. But browser still not work.
Make XOOM browser work in LAN:
In a console with root, run following commands:
  • getprop dhcp.eth0.dns1 # get dns1
  • getprop dhcp.eth0.dns2 # get dns2
  • setprop net.dns1 dns1
  • setprop net.dns2 dns2
  • Browser shall work now
How to have USB LAN work automatically:
Write a NETLINK socket program to listen all NETLINK socket event, if eth0 interface is UP, run dhcpcd on eth0 and set net.dns1, net.dns2 with dhcp.eth0.dns1 and dhcp.eth0.dns2. If eth0 interface is DOWN, reset those properties.

Friday, August 27, 2010

patch the kernel image boot.img

Tools list:

  1. split_bootimg.pl
  2. mkbootimg
  3. mkbootfs
boot.img contains the linux kernel and the ramdisk, while the default.prop in ramdisk can enable/disable the adb root permission. following is the default.prop contents for a droid product device:
  • ro.secure=1
  • ro.allow.mock.location=0
  • ro.debuggable=0
  • persist.service.adb.enable=0
droid product device with above default.prop has no adb root permissions if the device is not hacked. the default.prop with the following contents has the adb root permissions by default:
  • ro.secure=0
  • ro.allow.mock.location=0
  • ro.debuggable=1
  • persist.service.adb.enable=1
to create a boot.img with such default.prop, here is the steps:
  1. split the boot.img: split_bootimg.pl boot.img, after running the command, two files are generated: boot.img-kernel and boot.img-ramdisk.gz.
  2. create a temp folder (e.g. ramdisk), change to that folder, run the following command to extract the boot.img-ramdisk.gz: cat ../boot.img-ramdisk.gz | gzip -d | cpio -idm.
  3. make the changes to the ramdisk file system in ramdisk folder, e.g. change the default.prop file to get adb root permissions.
  4. return the parent folder, and run the following command to recreate the ramdisk package: mkbootfs ./ramdisk | gzip > ramdisk-new.gz
  5. recreate the boot image: mkbootimg --kernel boot.img-kernel --ramdisk ramdisk-new.gz -o boot-new.img
done. flash the boot-new.img to the device with fastboot.
more things can be done with the above steps, such as change the boot up sequence by modify the init.rc.