Category Archives: Android 2.3.3 Gingerbread

How to Enable the USB Host Mode of your Samsung Galaxy S2

If you want to plug USB devices (USB sticks, keyboard,…) to your Samsung Galaxy i9100 S2 you can do this. Even for more sophisticated devices like inertial measurement units (IMU). But you will have to enable the USB host mode for this.

For the physical connection, a USB micro-A (5-pin) to USB A female adapter is necessary. Note that it really has to be a 5-pin adapter. Usual 4-pin adapters would not be able to recognise the USB client device. For example this one works.

If your USB device is not recognised (or only as an unknown device) this may be due to the missing drivers. Your next step is then the installation of the respective drivers – e.g. a┬áserial to USB converter for an xsens IMU which is based on a FTDI chip set. If there is no compiled driver available for the required kernel version on the SGS2, it is necessary to compile the drivers for the kernel and to include them.

Another possible cause for your device not being recognised is that your device is not allowed to be used. According to the USB OTG speci fication, USB devices supported by the USB OTG host have to be specifi ed in a white-list, the so called targeted peripherals list. If your device isn’t, again you will have to modify the kernel. Either you add it to this white-list, or you disable this white-list altogether.

The process for editing the kernel is described in the following post.

How to Flash the Kernel of Samsung Galaxy i9100 S2?

This post gives a tutorial on how to flash a kernel on the SGS2 describing all steps. These steps can be taken to install a beforehand created kernel (see the last post) on the SGS2.

It is crucial that the phone is not switched o ff during the process, neither by running out of battery. It only takes a few seconds, but still – make sure! You would be running a high risk otherwise.

  1. The respective Samsung USB drivers have to be installed (using Kies or the supplied drivers disk) on the computer you use to flash your phone.
  2. The utility program Odin 1.85 has to be installed on the computer (can be downloaded for free, e.g. here).
  3. The kernel has to be flashed to the device using Odin (described below).

Flashing a kernel using Odin 1.85 is a straightforward task, but – again – it has to be conducted very carefully as a mistake in the flashing process can severely damage the phone. Hence it is very important to follow the instructions below to the letter to avoid problems or bricking the device. You start with the phone disconnected from the computer and switched off.

  1. Start the SGS2 in download mode: you do this by pressing “Volume down”, the “Home” button and the “Power” button at the same time. Don’t release them until the download mode screen appears (it looks totally different from the normal starting screen).
  2. Follow the on-screen instructions: ‘Continue’ by pressing “Volume up”.
  3. Start Odin 1.85 on your computer.
  4. Click on PDA and select the tar-archive containing the kernel you want to install.
  5. DO ONLY check the option boxes “Auto Reboot” and “F. Reset Time”.
  6. Connect the SGS2 to the PC via USB. The first field of “ID:COM” should turn yellow stating the COM Port of your device. Continue only after this has happened. It can take a couple of seconds.
  7. Click Start and wait for the flashing process to finish. Do not disconnect or switch off the device. If it gets stuck in “Setup Connection..” your phone might be running only in normal mode. Make sure you start it in the download mode (see 1). For me, flashing the kernel never took more than 30 seconds.

Your phone will reboot now into the normal mode. On the bottom of the start-up screen you will find a yellow warning sign. This only indicates that an “unsafe” kernel version is in use. You could get rid of this sign – just check in the web, google will help you!

Have fun with the new version!

Kernel Modifications for USB Client Devices of Samsung Galaxy i9100 S2

This post gives two options for the creation of a kernel version with which your Samsung Galaxy S2 supports otherwise unknown USB client devices – see the problem description in the last post.

The kernel modifications described here are based on the kernel here with the initramfs (find its source code here). This original kernel could be used to enable basic root access on your phone.

Creating a kernel module for USB-to-serial connectors

In order to get the needed USB-to-serial kernel module different steps are necessary:

  1. First, the development environment has to be prepared by downloading the Samsung Kernel source code which is freely available as it is based on the open-source Android operating system. Also the tool-chain for cross-compiling the source code has to be installed [http://forum.xda-developers.com/showthread.php?t=1123643].
  2. Second, “USB serial converter support” and the respective driver for FTDI serial converter have to be selected for module compilation by calling menu “makeconfig”.
  3. Third, the kernel Make file is modified changing the kernel version to ‘xyz’ to reflect the currently installed kernel version on the mobile phone. Additionally, the path to the used tool-chain for cross-compiling has to be changed according to the installation. E.g.:
    CROSS_COMPILE ?= /opt/toolchains/arm-2009q3/bin/arm-none-eabi-
  4. Finally the following lines in the .config file have to be changed according to the xda-developer forum to successfully compile the driver:

CONFIG_DEBUG_PREEMPT
CONFIG_DEBUG_RT_MUTEXES
CONFIG_DEBUG_SPINLOCK
CONFIG_DEBUG_MUTEXES
CONFIG_PROFILING
CONFIG_PERF_EVENTS
CONFIG_PERF_COUNTERS
CONFIG_LATENCYTOP
CONFIG_FTRACE

With these steps the modules can be successfully compiled using the command “make modules”.

If you try to insert the drivers to the mobile device using the “insmod” command and this fails due to the following error: ‘unknown format?’, you can do the following: Using “dmesg” a more precise error description states that no symbol version was found for module layout. This information points to a missing
symbol table. In order to receive a symbol table the kernel was built again by using “make”, which builds the complete kernel including modules. The resulting new modules ‘usbserial.ko’ and ‘ftdi_sio.ko’ were then successfully installed using “insmod”. The order of inserting the modules is very important as the ‘ftdi_sio’ module depends on the ‘usbserial’ module.

If your external USB device then receives sufficient power from your S2 and is white-listed, it would be ready to use!

Removing the White-List Requirement for USB devices

If your USB device is still not recognised because it is not white-listed, the only solution for this problem is a custom kernel supporting both, the respective kernel modules and the deactivation of the USB OTG targeted peripherals list.

To achieve this the following steps are necessary:

The Kernel base

The kernel base we used for building the custom version is the “backslash-1.3″ kernel. It includes a modified “initramfs” from the “CF-Root 4.1″ Kernel and incorporates performance changes to the stock kernel “XXKG1″. The source code for the kernel and the “initramfs” have to be installed. It is important to check out the right branches for successfully compiling the source code. The branch ‘master’ was used for the kernel and ‘backslash-1.3-CF-Root-XXKG1′ for the initramfs.

Kernel changes

Different files need to be changed. First, the configuration file has to be updated. Therefore the line fololowing in file “/arch/arm/con g/c1 defcon g”
CONFIG_USB_SEC_WHITELIST = y
has to be changed to
CONFIG_USB_SEC_WHITELIST = n

Second, the build script build “kernel.sh” is modified due to the differences in the development environment under which the kernel was originally created. Thus the following lines are changed:

INITRAMFS_SRC=”/home/ubuntu/dev/samsung/initramfs-galaxysii”
INITRAMFS_TMP=”/home/ubuntu/dev/samsung/master/initramfs-galaxysii”

export CROSS_COMPILE=/home/ubuntu/opt/toolchains/arm-2009q3/bin/arm-none-eabi-

With the command “make c1 defconfig” the configuration file “.config” for the kernel compilation has to be prepared and by using “make menuconfig” the missing modules, as mentioned above, can be selected as kernel-built-in modules.

Last, the kernel can be compiled executing the modifi ed kernel build script.

Permission changes

In the “initramfs” access rights have to be modified to provide access to the devices using USB Serial ports for all applications. To achieve this, the “ueventd.rc” has to be modified adding the following lines at the end of the file:

/dev/ 0666 root root
/dev/ttyUSB* 0666 root root

These changes have the effect that, whenever a USB Serial device is connected, all users or applications can access the port. It is also necessary to change the permission for the parent directory to
allow access. Otherwise, e.g. the RXTXLibrary is not able to enumerate the available ports, which would cause a “no such port exception”.

If the kernel has been successfully compiled using the new con guration, it will result in a zImage usable to update your Samsung Galaxy S2. The following post shows how to install this kernel then.

Automatically Changing Read and Write Permissions for USB Client Devices under Android

A prerequisite for executing native linux commands is a ‘rooted’ Android device with a custom initram filesystem installed. See the related post about rooting android phones.

On Android, Linux commands can be executed by calling:

Runtime.getRuntime().exec('command').

For instance to change file access permissions, the following code could be used (supposed the custom initram filesystem provides busybox):

 Runtime rt = Runtime.getRuntime();
 String command = "busybox chmod 777 file";
 Process process = rt.exec("su");

 DataOutputStream os = new DataOutputStream(process.getOutputStream());
 os.writeBytes(command + "\n");
 os.flush();
 os.writeBytes("exit\n");
 os.flush();

 process.waitFor();

Example taken from here

If you want to apply this to USB-to-serial converteers like in the related posts here, you have to apply this both for the devcie <file>, “/dev/ttyUSB0″ and the local temp file “/data/local/tmp/”.