Thursday, June 15, 2017

Compiling Device Driver for Android (e.g. new wireless driver)

This is a quick tutorial on compiling a device driver / kernel module for Android. For the purpose of the tutorial, I'll be using a wireless driver (mt7601u) and android-x86 as an example. But the steps should work with the standard/arm version as well. Just make sure to use the correct compiler/gnu tool chain.

I had a USB wifi adapter like the one below which was mediatek's mt7601u based.
Googling around I found that the support for this is present from version 4.2+ (Reference: MediaTek MT7601 USB WIFI on the Raspberry Pi ). I also found multiple drivers for the same like, https://github.com/imZack/mt7601 and https://github.com/kuba-moo/mt7601u . Since the kernel that I was using was 4.0.x, the later worked. We'll be using that going forward.

There are two ways to get the kernel headers to compile the driver. The fool proof way is to compile the kernel that we are going to use with Android either just the kernel or the entire Android. Both methods has its own advantages. Another hackish way is to find the kernel headers closest to the kernel that we'd like to compile against. This should work mostly, but then...

What I did was to get the Android-x86 entirely - in my case I wanted to get an entire custom android build. Follow instructions on Android-x86 - Get Source

Once compiled clone the repo https://github.com/kuba-moo/mt7601u. You could try compiling on native linux for testing. Post that, edit the Makefile to force the path:

KDIR = /home/muthu/android-x86/out/target/product/x86/obj/kernel

run (after making sure you are using the correct gnu tool chain if you are cross compiling for arm)
make clean
make

you have the required mt7601u.ko file. Push that to Android (which is rooted), and push also the firmware bin file (e.g. you can get it from https://github.com/imZack/mt7601/blob/master/src/mcu/bin/MT7601.bin) to

/lib/firmware/mt7601u.bin

After which load the drivers (mt7601u depends on mac80211)
modprobe mac80211
insmod mt7601u.ko

Then insert the usb dongle to check if the wifi is working.
ip addr
ifconfig




Sunday, June 4, 2017

Creating a custom data image / userdata.img for Android

This is a small description / tutorial on how to create a custom data image for flashing along with Android files. This is usually done to preload settings (if you created one e.g. from Customizing / Changing Android DPI settings or would like to load other data related files / information)

Get the required tools:


Create an ext4 img file (in the example ~10GB)
dd if=/dev/zero of=data.img bs=1M count=10240
mkfs.ext4 data.img

Populate the data (sudo might be required)
mount -o loop data1.img mnt
// copy files to mnt
umount mnt 

Convert to simg
img2simg data.img userdata.img

You can now use userdata.img to flash with fastboot and other flashers/installers.

Customizing / Changing Android DPI settings

There are multiple ways in which the Android DPI Settings and other window manager settings can be changed.One common method is to use the wm helper, for example:
wm density 160

Another common method is to modify dpi settings using the prop file (/system/build.prop). This is mostly done by adding/modifying the following line
ro.sf.lcd_density=160

in the build.prop file by editing it via fastboot, root, or helper apps.

Both these have limitations, the first method may not work on all platforms and the second method doesn't work in newer android verified boot (verity).

Given that the first method is preferable, because of its 'setting' kind of behavior and doesn't touch unnecessary system files. I am writing about a method of directly modifying the settings database to achieve the same result. There are many such android settings that can be edited / modified similarly. In any case, wm and similar tools help with editing the settings.

The file that we are interested in is:
/data/data/com.android.providers.settings/databases/settings.db

Pull this with various tools like fastboot. If Android is booted, one might need it rooted to access this file. [ Articles like How to Copy Files Over to your Android In a Bootloop with No OS using ADB! and The Most Useful Things You Can Do with ADB and Fastboot on Android might help for this ]

Insert / Update the dpi in settings - for this we'll use sqlite3. 'global' is the table that we are interested there, since this is part of the global settings in android.

sqlite3 settings.db
insert or replace into global values(null, 'display_density_forced', 160);
.quit

Push the file to the same location where we picked it from and we are done.





Sunday, August 28, 2016

Make USB storage as a GRUB bootable device

I normally have multiple operating systems on my machine. I thought I'd remove my old Ubuntu installation and use the partitions for other purposes. I knew I'd have GRUB issues, but thought it'd be relatively easy to find how to make a bootable USB pendrive. But, I was wrong!

Seems like most installers use syslinux based boot loaders and grub kicks in later. So, getting hold off one wasn't easy. After searching and reading, I found some useful information (I'm missing exact links though :( ). But here's the brief steps to get a plain grub bootable device.

(This is assuming you have access to some other Linux/GRUB based system)

Assuming /dev/sdb1 is your usb (FAT32 or otherwise) device - BE CAREFUL TO PICK THE RIGHT DEVICE!

[ Run as root / sudo as required ]

[ Mount the device ]
$ mount /dev/sdb1 /media

[ Create folders ]
$ mkdir -p /media/boot/grub

[ Next copy stage1, stage2 files ]
cp /boot/grub/stage* /media/boot/grub/

[ Start grub ]
$ grub

[ Change grub root device - normally hd0 => sda and hd1 => sdb and so on...again be careful! ]
grub> root (hd1, 0)

[ Setup as boot device ]
grub> setup (hd1)

....some messages, statuses, warnings, etc...

[ Quit ]
grub> quit

It should be a bootable device now and should give the grub boot prompt...you can use that to boot Windows e.g.
[ Again, use the correct number - it depends on your boot order ]
rootnoverify (hd1,0)
chainloader +1
boot

Sunday, October 25, 2015

LibreOffice Conference 2015 (Aarhus)

This year's LibreOffice conference was at Aarhus, a growing beautiful city. I presented around the ongoing work (specifically in Impress) and at Ericsson (EGI). Yes, my travel this year to the conference was sponsored by TDF.

Networking

A lot of interesting developers, translators, QA and other contributors to LibreOffice project made it to this year's conference (Credits to Sophie & TDF for making the additional efforts). This was something nicer.

Of course, I was able to network with the new people as well as my friends from the project.

Presentations

There were some interesting presentations around LibreOffice in the cloud and Android - seemed like most were from Collabora.
Missed the PyUNO talk :( just heard the last part, it was supposedly quite good - so waiting for the videos to watch it.
Of course, the talks by RedHat, CIB and the others were really good as well.

Other than the development talks, I enjoyed some talks about efforts around LibreOffice for government and migrations. And the celebrations around success at the LibreItalia (specifically around LibreOffice for the army in Italy) was really nice to know.

I also enjoyed talks about language translations and support for LibreOffice. Though I couldn't attend many of these (because the simultaneous tracks), I'm hoping to catch these up from the video recordings.

Pictures

Some pictures for your enjoyment.

Saturday, October 3, 2015

Solving "Unfortunately the process com.android.phone has stopped" problem (on Android Emulator)

Not sure why, but, suddenly one of my Android Emulators started throwing out the "...com.android.phone has stopped..." message. Unfortunately, it continuously throws that popup over and over again...

While googling around for the solutions - it seemed like there is some problem with the sqlite database of one of the telephony applications.

Logcat shows something like:
E/AndroidRuntime( 1293): android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 327686 to 393222: /data/data/com.android.providers.telephony/databases/telephony.db

To solve this some posts suggested clearing cache, unfortunately navigating to the menu was troublesome (and didn't really work for me), so I instead used:
$ adb shell
$ pm clear com.android.phone
$ rm /data/data/com.android.providers.telephony/databases/telephony.db
(I guess, pm clear com.android.providers.telephony should work as well instead of the last command) 


References:
http://www.redips.net/android/emulator-phone-stopped-unexpectedly/ 
http://stackoverflow.com/questions/16879346/the-process-com-android-phone-has-stopped-unexpectedly-please-try-again

Monday, January 30, 2012

Ultimate PDF Converter (on Cloud)

Introduction

I wrote an android app and related server scripts for converting documents to pdf for viewing on the phone. The app can be downloaded here.
I wrote this for a few reasons including experimenting with AdMob, so caution: the app is an adware.

I have cleaned up the sources and uploaded it to google code.
The server scripts can be found here
and the android application can be found here

Some Technical Details
The flow is normally like the following:
  1. Android Application sends the file to the server using the upload.php script
  2. upload.php generates a unique key for this file and passes on the information to the app as well as updates the database
  3. The python converter polls this database and calls the converters (libreoffice/openoffice) and updates the database with success/failure
  4. The app now queries the getfile.php to get the file or the queue number it is in.
  5. The file (converted pdf file) is then downloaded to /sdcard
TODOs
  1. Change the irritating 'open with' to may be 'share with' rather
  2. Conversion of pdfs into maybe images for directly viewing from the app rather than opening it with another pdf viewer.
  3. Conversion of other files: e.g. audio files into wave screenshots or something (?)
  4. Robustness of the scripts and app needs improvement
Any contributors, please?