Ramblings of a dusty mind... Shashank Shekhar's Blog

Sunday Oct 19, 2008


October's been a good month for me, and better for my iPod. iPodLinux.org is back online and they've released a couple of pretty neat tools, and updated builds. Loader 2 (the new bootloader) is great - no more messing around with complicated wheel/key combinations to select the boot OS. Loader 2 gives you a GRUB-like list of installed OS images on the iPod disk, and can read kernel images from ext2 and ext3 partitions, as well as FAT32 (W95). So this effectively removes the need to re-create the firmware each time a kernel update takes place. All you need to do is use ipodpatcher (which originally was used for installing Rockbox) and install Loader 2, which will now get merged with the Apple Firmware.

The Podzilla interface has been improved too, and lots of annoying little problems have been ironed out mostly. The text-input is (or atleast, feels) WAY better now, and I can actually input something meaningful in a meaningful amount of time. Here is the text file I "typed" (with awkward scrolling and tapping) on my iPodLinux's PodWrite with a "Scroll with Prediction" text-input mode:

first.txt : "This isn't bad at all. The prediction algo is pretty good as far as this text input session is concerned. Took me 10 minutes to input this on the iPod, but I'll improve I guess."

Then I finally got my first Java program running on the iPod! After encountering wierd errors and battling nasty iPod text-input mechanisms for months, things have finally come to a closure. The latest build of podzilla, makes things easier, and thus enabled me to run Java programs using the K Virtual Machine (kvm) by Sun Microsystems. I got hold of the kvm binary from some place, but I don't think its available on the Sun website anymore, which is pretty odd. But this is how I got my "Hello world" in Java working on the iPod:

1. Install iPodLinux by using the latest Podzilla and loader.
2. Download kvm from here. Put the kvm binary into your iPod's /bin folder and make sure it has execute permission.
3. Write your java code, but keep it simple. KVM just supports basic I/O, data types, Vector, Stack and a couple of other simple things. No graphics, gui etc. For e.g.:

Test.java:
public class Test {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}


4. Then compile the code to the JDK 1.4 format:

#javac -source 1.4 -target 1.4 Test.java

5. Finally, create a script file in gedit or vim called, say, Test.sh:

Test.sh:
kvm Test


6. Save the script file in the same folder as the Test.class file, and give both Test.sh and Test.class execute permissions:

#chmod +x Test.sh
#chmod +x Test.class


7. Put all these files in some folder in the iPod's Linux partition. I put it in "/home/shashank/java" (on the iPod partition, not your own system! Also avoid spaces in your folder path.). Then boot into iPodLinux and open the folder where you placed the files using the File Browser, and scroll to "Test.sh", and keep the "Select" button of the iPod pressed until the context menu shows up. Then select "Execute" and select "Read output". Voila! You should get the two words: "Hello World!" on your screen!

No cross-compilation, no recompiling of gcc to work with ARM7 processors (most iPods run on ARM7 processors, thus C code compiled on your PC will not work on the iPod). Life is easier with this if you want to do simple programming. Maybe if someone wrote an extended Virtual Machine, with more libraries, then it would make this a pretty solid platform.

BTW, the above steps have been written assuming you have a Linux/UNIX machine. If you have Windows, a VMWare or xVM VirtualBox image of some Linux distro on your Windows machine would make life tonnes easier compared to trying to use Windows' limited functionality with everything in life in general.

Cheers
Shashank

Friday Oct 10, 2008


I've looked around the internet a lot and mostly didn't find any working solution apart from trying to make an image/virtualDisk from a raw physical disk (USB). I was basically experimenting with writing simple bootloaders in assembly language, and wanted to rapidly test and make changes to the code without rebooting my system again and again to try booting. The obvious solution is to use a Virtualization tool like VMWare or xVM VirtualBox by Sun (the latter is free), but the trouble is that neither of them support booting from pen-drives and I have long forgotten the existence of floppy drives, and have thus no way of directly writing to a disk and virtual booting straight-away, without creating an new image of the disk each time I make changes to it. So I decided to write to my USB pen-drive directly and try booting from it. It works when I boot the entire computer with it, but VMWare and VirtualBox do not have the option of booting from a USB device.

So messing around xVM VirtualBox 2.0.2 36488 for Windows yesterday, I was pretty surprised to find my USB Pen-Drive listed under the field of Floppies! That is,

a) Create a new Virtual "Machine"
b) Click on the "Floppy" link in the main screen (right panel)
c) Enable "Mount Floppy Drive", and from the drop-down list in "Host Floppy Device", select your USB drive's Drive Letter (haven't tried it in Linux, I guess you'll have to select the correct device like /dev/sdxx)

That's it. Try starting the Virtual Machine now.

Its quite wierd, and I'm still wondering why my USB drive gets listed under floppy, but it works for me! Neither VMWare Workstation, nor xVM VirtualBox permit booting directly from the USB otherwise.

Cheers
Shashank

Sunday Oct 05, 2008


Today morning I finally settled in to perform a long-pending weekend house-cleaning job, except that the cleaning work was electronic, i.e. my computer. It is a common scenario to find your files so badly scattered around the hard-disk, inspite of some organization scheme that we all implement. Years ago, I saw a nice scheme Roshan, a friend of mine, implemented. He created directories and sub-directories based on topics and categories, like "Science", "Computers", etc, and Science would contain "Physics", "Chemistry" ... while Computers would contain "Programming", "Internet" and so on. It was a complete hierarchial structure, and I've been using it on my systems too ever since I saw it there.

But, its hard to maintain my directory, as creating such a structure is a rather tough task. You could either create an entire directory structure before-hand, with empty folders waiting to be filled, or you could create new folders as and when you require, in the correct category of course. The latter option obviously seems more efficient, as you don't have an empty mammoth directory structure, but a dynamic and to-your-taste structure. But after several years of trying out both, I have found that the first approach is much better. When you are, say, saving a file from the Internet, you often don't have the patience to ponder over the hierarchial relationship between "Geese Hunting" and "Duck Hunting", and whether you should create a new directory for each, or just club them into one single directory called "Bird Hunting". This inherent impatience of people when using files, as understandable and natural it is, is THE reason why files are scattered and chaotic. Thus I have concluded that people need an existing order to follow, that is as extensive and accomodating as it can be, but also flexible in order to allow people to delete and modify and create new topics and directories.

With this long discourse on the philosophy of file management in mind, I sat about thinking! :-D

This is what I came up with: Why not use an existing MASSIVE topic-wise directory structure, which has been developed and nurtured for about a decade by tens of thousands of people across the world? That directory structure is the DMOZ Open Directory Project (http://www.dmoz.org) by the Mozilla Foundation (of Firefox fame). It forms the backbone of Google Directory and several other places on the internet, and is a collaborative and open effort at building efficient web directories. My interest, however, is not in the links to websites that is provides, but the topic-based organizational structure. And as luck has it, they offer a downloadable plain-text file containing the ENTIRE folder structure. Perfect. Its available at:
http://rdf.dmoz.org/rdf/categories.txt (57.4 MB)

Then I wrote a simple tool in Java called "BatchDMake", which will read a given text-file line-by-line and create the folders listed in it. Each folder path is listed in a separate line. For example, this is from the DMOZ dump:

Arts
Arts/Movies
Arts/Music
Computers
Computers/Artificial Intelligence
Computers/Games

The syntax for operating it is:
java BatchDMake [filename] [root folder]

The filename parameter is obvious, the root folder is the folder name relative to the current working directory in which it should create the folders listed in the text file. For e.g. using the downloaded DMOZ categories file:

java BatchDMake categories.txt dmozRoot

The source code for BatchDMake is available here, and the executable .class file is here.

I just created the ENTIRE folder structure of DMOZ on my hard-disk, it has about 770,000 directories & sub directories. A lot of them are useless ones, so I'll go about pruning the tree to come up with the most useful structure for normal users. Will post that one soon. In the meanwhile, you could try the DMOZ structure and use BatchDMake to create it on your system!

Cheers!
Shashank
PS: I even found the place I'm currently in!
root\Regional\Asia\India\Tamil_Nadu\Districts\Vellore
This is like exploring an uncharted world in your hard-disk! :-P