Archive for the ‘Hacks’ Category

Knowing that it could be difficult to get printers and scanners working with Linux, I did quite a bit of research before settling on the Brother DCP-7065DN. Because I use Ubuntu, I did not have much trouble installing Brother’s proprietary debs. The scanner worked nicely; but the printer test page was shifted up and right, such that the output was clipped on the top and right borders, with the correct paper size setting.

Enabling Job Options > Scale to fit fixed the clipping, but the image was still off-center. I played around with the PPD file a bit, and achieved favorable results by shifting the ImageableArea values a bit in the opposite direction:
Read on »

I return to school at noon, but before then, I’d like to share my evening project: agcc.bash, a rewrite of agcc and that works with revisions 6 and 7 of the Android NDK.

The NDK is a GCC-based cross-compiler that lets you embed object code in a traditional Android app. It also works as a standalone cross-compiler, though it is not advertised as such. It is quite rough when used by itself, and agcc wraps the complexity in a little script. While agcc and are written in Perl, agcc.bash is a Bash script. It also supports the latest revisions of the NDK, though r7 is slightly buggy.

With agcc.bash, building native Android software feels almost like working with GCC. As a quick example, let’s try the classic hello world:

AGCC_NDK=~/android-ndk-r6 ./agcc.bash hello.c -o hello

That wasn’t too exciting… but what happened there? I have the NDK installed at ~/android-ndk-r6 and I told agcc.bash where to look for it, using the AGCC_NDK environment variable. I then invoked agcc.bash as if it were GCC. Let’s see what agcc.bash did behind the scenes:

AGCC_NDK=~/android-ndk-r6 AGCC_ECHO=yes ./agcc.bash hello.c -o hello

=> ./agcc.bash hello.c -o hello
<= /home/jyio/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc -o hello -I/home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/include -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -DSK_RELEASE -DNDEBUG -UDEBUG -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -fpic -fno-exceptions -ffunction-sections -funwind-tables -fmessage-length=0 -march=armv5te -mtune=xscale -msoft-float -mthumb-interwork -fpic -fno-exceptions -ffunction-sections -funwind-tables -fmessage-length=0 hello.c -Bdynamic -Wl,-T,/home/jyio/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x -Wl,-dynamic-linker,/system/bin/linker -Wl,–gc-sections -Wl,-z,nocopyreloc -Wl,–no-undefined -Wl,-rpath-link=/home/jyio/android-ndk-r6/platforms/android-8/arch-arm -L/home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/lib -nostdlib /home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/lib/crtend_android.o /home/jyio/android-ndk-r6/platforms/android-8/arch-arm/usr/lib/crtbegin_dynamic.o -lc /home/jyio/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a -lm -ldl

See how it transformed our innocent little command into a monster! This might be overkill for a hello world program, but it provides pretty good support for more complex software such as OpenSSL, cURL, and Python. It would be a good idea to add the NDK toolchain and agcc.bash to $PATH before trying to build a big program. In my case, the toolchain resides in ~/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin. If you want to build some software that come with configure scripts, you might start with:

CC=agcc.bash ./configure

Do try this at home! Relevant links:

One of the improvements in the Amazon Kindle3 OS is the WebKit-based browser. Based on a tip, I tried communicating on Freenode using the Webchat interface.

How do you get this particular OS update on a second-generation Kindle? Well, let’s just say it’s not officially supported.

Since I’ve been asked several times to demonstrate how to make a reblox, I decided to put together a little photo tutorial. Enjoy!

Look at the pretty pictures.

The Bloxes website features construction images as well, and the process is similar.

Bloxes are nifty “modular adult-sized building blocks.” They are actually interlocking cardboard boxes that can be used to build things such as furniture.

They’re not exactly inexpensive, and shipping takes a while. Instead of ordering bloxes, I decided to prototype my own on paper just for fun. This design might require some modification for use with cardboard (in particular, I’m sure you could figure out how the original design works and apply it to your project).

If you have the resources, go ahead and roll your own cardboard modules. As usual, it’s easier said than done…

I got a bit closer to integrating Twisted with gevent. So far, I’m liking gevent’s speed and blocking style, but it does lack Twisted’s extensive library. Well, this new Twisted reactor runs on gevent and makes it a bit painful to use both frameworks together.

Here is where the magic happens.

Note that this code is for using Twisted with gevent (i.e. libevent and greenlet). For using Twisted with greenlet alone, there is corotwine. Twisted can also be used with Eventlet.

Now, Twisted is a pretty awesome framework. It’s not only a networking library, but it’s a framework that provides all sorts of functionality. There’s also plenty of example code, and many things are already implemented. It is somewhat slow, however, and it likes to take control of the whole program. Keeping track of all the deferreds is not really a problem for me, but greenlet’s blocking syntax is quite nice.

If you haven’t seen corotwine yet, I’d urge you to have a look. It lets you use Twisted with a blocking syntax. It’s not quite what I wanted, but it does what it says on the tin. I wanted to use Twisted with Twisted syntax, greenlet with greenlet syntax, and maybe even let the Twisted bits talk with the greenlet bits. It is apparently quite easy with gevent.

The first thing you want to do is monkey-patch This is the method that Twisted uses to wait for file descriptors, and we can let gevent handle that with libevent and greenlet. Next, you run either in the main greenlet or in a new greenlet.

As long as Twisted and greenlet code stay separate, everything is peachy. There are some problems when they start mixing. Because the Twisted reactor runs in a single greenlet, calling gevent.sleep (or doing anything else that involves a greenlet switch) actually blocks all of Twisted. Long-running jobs could be done in new greenlets, though. And if another greenlet wants to work with a Twisted transport (i.e. to send or receive data), it’s not going to happen until gevent sees some network activity destined for Twisted and switches to its reactor. These are the same problems you’d see with corotwine, and I suspect they might be alleviated with a greenlet-aware reactor.

Update: gTwist, the original code for gevent-Twisted integration, has been replaced with a more robust system called geventreactor. As its name implies, geventreactor is a gevent-powered Twisted reactor.

Opkg is not limited to using packages from files; it is also capable of using apt-get style repositories, vastly simplifying the job of fetching dependencies and updating packages. I already have a repository set up, and it could be added as such

echo "src/gz inportb-android-froyo" > /cache/etc/opkg/inportb.conf

After doing that, we could refresh the package list

opkg update

Installing a package then becomes as easy as

opkg install name-of-package

And we could keep all our packages up-to-date using

opkg update; opkg upgrade

It’s also quite simple to set up a repository for distributing packages.

Read on »

Now that we have Opkg for Android, we could use it to install packages from local files or off Web servers. Installing a package is as simple as

opkg install path/to/package.opk

or, if it’s on the Web

opkg install http://host/path/to/package.opk

And to remove the package, we would go

opkg remove name-of-package

But what if we wanted to share our own software with others? In this case, we would create our own packages. An Opkg package is essentially a Debian package with fewer control fields. If you know how to make a Debian package, you should be well on your way. In general, a package is an ar archive containing a control tarball, a data tarball, and a debian-binary file. For example let’s have a look at the opkg-hello package:

Read on »

Well, almost. While one could theoretically install Debian packages on Android phones, it is generally a bad idea to install software designed for one system onto a different system. However, the Debian package manager is excellent for keeping track of software, and it would be nice if it could be used on Android as well. iPhone users already have access to this mechanism in the form of Cydia, so why not put it on Android too?

Read on »