Archive for the ‘Computing’ Category

I return to school at noon, but before then, I’d like to share my evening project: agcc.bash, a rewrite of agcc and agcc2.pl 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 agcc2.pl 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:

For months, I’ve been using a Kubuntu 11.04 pre-release on my Lenovo IdeaPad S10-3t, a convertible tablet netbook. In general, the Plasma Netbook interface is reasonably touch-friendly with large buttons that I could easily access with my fingers. It tries to save space by hiding the global application menu behind a button, but I would have liked easier access to the menu. Application support for touch input is rather spotty, as expected, but some software come with plugins to make the touch experience a bit more compelling. For example, Firefox has the Grab and Drag extension and Chromium has chromeTouch. The virtual keyboard (kvkbd) is somewhat awkward, however, so I usually have the keyboard out.

Read on »

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 select.select. 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 reactor.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.

Google is currently starting a Chrome OS evaluation program, which involves distributing some 60000 computers for free to guinea pigs in the United States. The device, codenamed Cr-48, is an unbranded notebook with a black rubberized exterior. Here are the technical specifications:

Dimensions: 0.9″h × 11.8″w × 8.6″d @ 3.8 lb (1.72 kg)
Motherboard: Tripod Motherboard MARIO-6050A240910-MB-A03
Chipset: Intel CG82NM10 PCH
Processor: Intel Atom N455 (Pine Trail) @ 1.66 GHz single-core with hyperthreading
Graphics: integrated Intel GMA (Pineview) @ 200 MHz with VGA port
Audio: integrated Intel 82801G HDA with stereo speakers and 3.5 mm stereo output plug
Memory: 2GB Hynix DDR3 1Rx8 PC3-10600S RAM
Flash: ITE IT8500E Flash ROM
Storage: 16 GB SanDisk SDSA4DH-016G SSD on 1.5 Gbps SATA interface
Display: 12.1″ 1280×800 active-matrix color CCFL-backlit LCD with matte surface
Keyboard: full-sized 74-key keyboard
Touchpad: oversized multitouch clickpad
WiFi: AzureWave Atheros 9280 802.11 a/b/g/n supporting WEP, WPA, and WPA2
Bluetooth: Atheros AR5BBU12 with V2.1 EDR
Mobile: Qualcomm Novatel Gobi2000 PCI Express Mini Card
Battery: 63 Wh removable Li-po battery for up to 8 hours use or 8 days standby
Cooling: fan
Other: integrated USB 2.0 port, webcam, and SD card reader

Read on »

Since it’s early in the morning, I’m going to make this short and let the pictures do the talking. Having collected almost 700000 Omegle logs, I decided to run through them all and see if there might be any patterns to be noticed. The following is a general view of some specific topics discussed on Omegle, in bulk. I chose these keywords because “ASL” is, by far, the most popular theme.

Read on »

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 http://repo.inportb.com/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 »

I wanted to install Windows 7 on my netbook, but I didn’t have access to a Windows environment from which I could run bootsect.exe or install Grub4Dos; so I figured I’d install Grub2 on my USB disk using Ubuntu, have Grub2 chainload Grub4Dos, and finally let Grub4Dos chainload the Windows installer. This worked for me:

  1. Prepare a fresh NTFS partition on the USB disk /dev/sdX and mount it at /mntX1, then copy all files from the Windows installer disc or image into /mntX1
  2. Install Grub2:
    cd /mntX1; sudo grub-install --no-floppy --root-directory=/mntX1 /dev/sdX; sync
  3. Download the latest Grub4Dos, and unpack grub.exe into /mntX1
  4. Create /mntX1/boot/grub/grub.cfg:
    set timeout=0
    set default=0
    menuentry “Install Windows” {
         linux16 /grub.exe --config-file=”root (hd0,0); chainloader (hd0,0)/bootmgr”
    }

I was surprised that such a complicated setup actually worked. Be sure to substitute your own values for /mntX1 and /dev/sdX. In the Grub4Dos config, (hd0,0) refers to the first partition on the boot disk; you’d need to change that if you want to boot the installer from a different partition.