Emacs and Slime highlight changes and how to control it

2008-05-14 18:23:26 PST

Tags: , ,

Massive thanks to durka on #lisp on irc.freenode.net.
New versions of slime for emacs have had enabled by default a new feature, essentially a light highlighting of uncompiled changes to a file. At first I found it annoying but then I got used to it. It is kind of handy. However I wouldn't find out how to turn it on or off. Oh well.

Then I went to use emacs on the console and the subtle light grey background highlight was suddenly grey text on a white background and completely unreadable. Very annoying, suddenly this little feature rendered -nox emacs useless.

Hours of google searching turned up nothing so finally I resorted to the irc channel. In only 10 minutes we got the answer.

<durka> aha
 customize emacs - applications - slime - slime mode - slime mode faces
 change highlight edits face

Thank you.

Setting up a remote git repository with just git

2008-04-27 23:30:38 PST

Tags: , , ,

So Ubuntu hardy doesn't ship with the handy git wrapper/tool cogito because git has all the features in it incoperated... somewhere...

But documentation is surprisingly sparse. Anyways, if you want to set up a git repo nowadays using just git, it should go as something like follows:

root@server # cd /git
root@server # mkdir newrepo
root@server # chgrp git newrepo
root@server # chmod g+ws newrepo
root@server # cd newrepo
root@server # git init

And if this is a public repository

root@server # touch git-daemon-export-ok

On the client side.

user@client $ cd project
user@client $ git init
user@client $ git add *
user@client $ git commit -m "Initial code dump"
user@client $ git remote add origin ssh://user@git.server.com/git/reponame
user@client $ git push origin master

and after that regular

user@client $ git push

works just fine.

Rsync for backup: a surprising easy and good solution

2008-02-05 18:11:53 PST

Tags: , ,

I just stumbled on an really neat simple little article on how dead easy rsync is for doing backup work. It's easy to use, can use existing infrastructure (SSH) and does diffs to minimize data transmission.

It's as simple as this

rsync -a -e ssh Documents haplo@kvasir.mindstab.net:~/backup

And then the reverse to get new stuff.

The full article is at www.enterprisenetworkingplanet.com/netos/article.php/10951_1573881_2. I'm doing this with a bunch of my data now! I'm excited because I'd been thinking about setting up some backup solution for a bit but this is so trivially easy and more than good enough it's delightful.

Deleted file recovery on unix

2008-01-06 23:31:35 PST

Tags: ,

Well, because I'm a cocky moron I was working on a new project but hadn't "gotten around to putting it in a git repo" or backing it up at all and sure enough I accidentally deleted one of the files that was over 25% of the project. Severed me right I suppose. Well, I didn't want to let that go. Too much work and hassle to redo, I'd already done a lot of bug tweaking on it. So I decided to investigate file recovery on Unix. Long story short, not so great, no fancy programs to go looking for your files. However, there's always the DIU approach. So I started by grepping the harddrive (/dev/md/5) for a unique-ish string in the file and having it print out the an appropriate number of surrounding lines to get the file back.

 
grep -a -A 1000 -B 100 "import netpipe" /dev/md/5 > results.txt
 

The '-a' switch makes grep treat binary files like text files, so it'll work on devices, the '-A' switch tells grep how many lines to print After the line with the text we want is found and the '-B' switch tells grep how many line to print Before the line we want. I choose the numbers because the line I was looking for was clearly nearer the top of the file.

However this approach failed with grep giving me a ran out of memory error.

So a little more googleing and I found the solution, this little baby of a shell script

 
for ((skipamount=1 ; skipamount < 88188637184 ; ))
do
dd if=/dev/md/5 of=./testhex bs=1024 count=1024 skip=$((skipamount+=1024))
echo "Sector" $skipamount of 85899345920 echo "S" $skipamount>> ./found
echo >> ./found
grep "import netpipe" ./testhex --binary-files=text -A 1000 -B 100 >> ./found
done
date
echo "Done"
 

It's not pretty and you'll have to hand edit it to your particulars but essentially it reads over the hard drive picking out 1MB chunks piece at a time and running grep on those. The positive side of this is that it actually succeeded on running over my whole hard drive. The catches are that the found file is somewhat polluted with lines stating where it is, but this is actually handy because the other catch is that since we're pulling discreet 1MB chunks off the hard drive it's possible the file you are looking for will be arbitrarily split across them and you won't get all of it in your results file. But all the extra information in the fill will tell you exactly where to look and you can just use 'dd' to go in and get a more proper sized chunk with your whole file.

Anyways, a long story short, I found my file and was able to recover it. Hooray!

Also, a note! Crucial to deleted file recovery is to minimize writing to the drive the file was deleted on. Recovery works because the only information actually deleted are the pointers in the filesystem tree. The actually contents of the file are still on the drive, but now are as far as the file system is concerned, adrift in unused space and free to be allocated to be written over by the next program. So try to shut things down and stop writing to the partition with the lost files and run the recovery on a different partition or your recovery might overwrite your target!

Making Familiar 0.8.4 Linux useful on the IPaq hx4700

2007-11-09 13:42:42 PST

Tags: , , , ,

These are notes and utilities and files I've gathered together to make my IPaq hx4700 useful to me, and setting it up decently easy. I know it took forever to type them up and finally publish them, but better late than never.

Mission

To turn basic Familiar 0.8.4 on the IPaq hx4700 into something useful. More specifically, to make IR and Bluetooth work, to make my Belkin IR Keyboard (F8U1500-E) work, and then to install a Debian chroot on an SD card where we can then install, for example, every programming language and text editor we could want for portable programming purposes.

Getting Started

So, first things first, you need an IPaq hx4700. Or at least an IPaq, and hopefully one supported by Familiar Linux. As you can see from the list the hx4700 is supposed to have A+ support. It turns out that's kind of a lie. But we can do surprisingly well with some work. First off, throw away the Familiar Installation guide, it doesn't apply to the hx4700. They put together a different one on the wiki at handhelds.org/moin/moin.cgi/HpIpaqHx4700HowtoInstallLinux. Read it.

Files and Filesystems

So now's as good a time as any to mention that I've collected all the files you'll need and put them on my FTP at ftp.mindstab.net/ipaq-hx4700.

First off you need a SD card and you need to write the bootloader all over it so whip out DD and does as the instructions say. Then when that's done toss an ext2 file system on your SD card, we'll need it later.

Now for some work with the CF card. Since we're flashing from it I'd suggest using the FAT filesystem. We'll stash all our system stuff on it here's a quick list of what you should grab from the FTP and put on it.

  • zImage-2.6.15-hh2-ipaq-pxa270: kernel
  • zImage-2.6.17-hh3: exciting new and more useful kernel, but we can't install it until the system is up and we copy it's modules over to the ipaq.
  • bootgpe-v0.8.4-ipaq-pxa270.jffs2: Root filesystem with GPE installed. I'd recomend GPE over OPIE.
  • reflash.ctl: Control file for hte bootloader to know what it can flash. This one is updated with an option for the new kernel.
  • RADIO0d.BIN: Firmware driver
  • radio11.bin: Firmware driver
  • wlangen.bin: Firmware driver
  • 2.6.17-hh3.tar.gz: Kernel modules for a newer kernel. Untar it in place.
  • install-firmware.sh: Shell script to install the firmware. The names are case sensitive so depending on how your FAT filesystem performs this might not work :/.
  • install-modules.sh: Install the kernel modules for the 2.6.17 kernel. Assumes it's running with the untarred file 2.6.17-hh3.tar.gz. Copies the modules to /lib/modules on the ipaq.

And now is a good time to mention that I got an IR keyboard with my IPaq, specifically a Belkin F8U1500-E, which didn't work with the IPaq for a number of reasons at first. I solved them all. If you have this key board you'll also want the following files. If you have any IR keyboard you still might want at least the init.d file from the list.

  • install-kbdd.sh: Shell script to install the files
  • init.d.kbdd: Adds lines to the start function to remove extra IR kernel modules that prevent simply IR keyboards from working. Also kill irattach.
  • kbdd.conf: Config file that just says use a belkinir keyboard on /dev/tts/2.
  • kbdd: My patched kbdd program with proper support for my keyboard.

I also put up kbd.c which is the file I modified from the kbdd source for anyone who wanted to see what I'd done (also, I suppose, to comply with the GPL ;)). I know it's a hideous mess and hack, but using a case statement was easier initially in order for me to figure out how to get the keyboard working. I fully intended to turn it into an array latter, but once it worked I got lazy and left it. Meh.

Getting Familiar up and Running

Ok, you now have the CF card with all the files you need. Toss it in the IPaq and follow the flashing instructions on the wiki. Flash the 2.6.15 kernel, and then the GPE root filesystem. Then you can let GPE boot. It might take a bit.

Also, the boot loader and possibly the IPaq itself are kind of finicky. If it just won't turn on, don't worry, you probably haven't bricked it, its just in a funk. Let it sit for like 5 minutes. Also try pulling its battery for a bit, putting it back in and then putting it on AC power. Eventually it'll decide that the time is right to try booting again.

So, once GPE is up, there are a few change that we need to make to make life easier and better. First, go to "Setup->Login Setup" and set "Automatic Login" to yes. This will automatically log you on as root, instead of asking you for user name and password of some non root user. Really much beter in the long run for this device. Then log out and you should automatically be logged back in as root.

Now we can proceed.

We'll need to do some typing to get the necessary files installed, so you'll need to bring up the on screen keyboard. It kind of sucks, but I've seen worse. It is usable. Also, I've tried to write scripts to automate a bunch of stuff to keep the typing to a minimum until a real key board can be used.

So, bring up a root console from "Others->Root Console". "cd" onto the CF card, "/media/cf".

First we'll install the firmware, so run "sh install-firmware". Ideally this will work but you should double check and fix if it doesn't. What should happen is the 3 ".bin" files are copied into "/lib/firmware" and their names are all uppercase except the "d" in RADIO0d.BIN.

Next run "sh install-modules" which should copy the 2.6.17 kernel module directory (you untared the .tar.gz right :)) into /lib/modules. Now when we flash our new kernel it'll find it's kernel modules installed and actually work, as opposed to choking in boot, or booting but being generally useless.

If you have a Belkin IR Keyboard (F8U1500-E) then you'll also want my kbdd, and if you have any IR keyboard you might want my init.d.kbdd file.

So run "sh instal-kbdd". It should copy kbdd to /usr/sbin/kbdd (saving the old one as /usr/sbin/kbdd.old), copy kbdd.conf to /etc and copy init.d.kbdd to /etc/init.d/kbdd.

Now you should have your base system much closer to ready. Now that the firmware is installed if you were to reboot your Bluetooth should work. However the kernel that shipped with Familiar 0.8.4 had broken IR support, so we need to upgrade to the 2.6.17 kernel I compiled for the IPaq. If you have a different piece of hardware there are instructions in the handhelds.org wiki for getting and compiling kernel source. Ignore the part about them making their own configs, it didn't work for me, instead just copy /proc/config.gz to your sd/cf card and use that.

So to flash the new kernel after the modules are installed, reboot the IPaq holding the two upper keys (as the instructions said) as well to bring up the boot flasher and this time pick the 2.6.17 kernel.

Now it should boot up and Bluetooth and IR should work and your Belkin IR keyboard should work. Like magic. I still haven't gotten wireless to work but I'll update this if/when I do.

Wired USB internet

Next? We need connectivity. I still haven't gotten the wireless to work, but you can easily do ethernet-over-usb and use a desktop as a router. My instructions are Linux specific but I'm sure other OS specific instructions can easily be found by Google.

I already wrote instruction on how to get a mobile Linux device online with Linux so check out the instructions at www.mindstab.net/wordpress/archives/174#gp2x_networking.

The net.sh script for the IPaq has an extra line and looks like

#!/bin/sh

ifconfig usb0 up 10.1.0.2
route add default gw 10.1.0.1

and you can get it at ftp.mindstab.net/ipaq-hx4700/net.sh.

Native Video

So the IPaq can play video. It's a smidgen of a hack for GPE because the version with familiar doesn't actually have a mplayer compiled for it so I nicked the one for OPIE and flubbed one of the dependancies: instead of using the SDL 1.2.7 compiled for OPIE and depending on OPIE on used teh 1.2.4 version compiled for GPE. This might be why the video is currently choppy until I can find a better solution because there might be a much faster rendering path on OPIE for SDL than there is under GPE. Still, this will work if you don't mind choppy video (but at least the audio is 100% solid). What I think I really need to do is find a way to make XV work on GPE and get mplayer to use it.

As for getting this working, all you need are some packages I've collected. Just grab the following from my iipkg collection at ftp.mindstab.net/ipaq-hx4700/ipkg:

  • libmad.ipk
  • libpostproc.ipk
  • libsdl.ipk
  • mplayer.ipk

I think that's all you need. Either way, if it asks for other dependancies they are in the folder, so just grab everything. I think you have to force one of them to install ignoring it's dependancies with the '-nodeps' flag. Anyway, once you get mplayer installed, it uses the SDL video output plugin. In order to make video and audio sync and not play laggy or slow I recomend the following flags:

mplayer -framedrop -nocache $MOVIE

As I said, it's currently laggy, but it works, and I'm looking for a better solution.

Making an ARM Debian Chroot

Note: For anyone who has been waiting for almost a year for my promised guide on how to make a Debian chroot for the GP2X, this is it. The instructions are the same. I originally did this on my GP2X until I got netwokring working on the IPaq, and shared the chroot SD card between them.

Now the IPaq only has limited space and only a limited number of programs compiled for it. If you want access to absolutely all software, then we need another source. The answer is a Debian chroot. Debian has great arm support so about 99% (Not Java) of stuff in the Debian repository will be accessible to you. All you need is space. So grab a decently sized SD card and put a reasonable filesystem on it, like ext2. Now, in order to install Debian we need Debootstrap, their utility for installing Debian from anywhere. You could try and install it on the IPaq but it'd be a hassle. I found the best solution was to download the ARM install disks (or minimal CD) and just copy off the entire filesystem. It's only a few MB. You can get my copy at ftp.mindstab.net/ipaq-hx4700/deboot.tar.gz Untar it on the SD card.

For this to work you'll need a network connection on the IPaq so make sure that's setup and working.

(For GP2X users, for each chroot (the debootstrap one, and the final one) you'll also want to run 'cp /lib/libiconv_plug.so lib' where lib is what will be the root lib directory in the chroot.)

Then on the IPaq execute the following to set up the environment to chroot into the Debian install environment.

cd deboot
cp /etc/resolve.conf etc
mount -t proc none proc
mount -o bind /dev dev
chroot .

Now you're in the actual minimal Debian install environment that is really only capable of doing one thing: running Debootstrap. So go for it. Install it in the chroot for now, you can always move it out once done.

debootstrap --verbose --arch arm etch /mnt/etch http://gulus.usherbrooke.ca/debian

Keeping in mind to change the Debian release name to what you want and to change the mirror to something appropriate to you. For a full list of Debian mirrors look at www.debian.org/mirror/list.

When it's done, you'll have your very own Debian chroot in /mnt/etch under the chroot or /media/card/deboot/mnt/etch in the IPaq filesystem.

You'll probably want to move the chroot to either the root of the SD card or just a subdirectory, so exit the chroot and then

mv /media/card/deboot/mnt/etch /media/card/etch

Now you have your very own Debian chroot. A few last things need to be set up before using it. Again, it will need internet too if you want to be able to install software, so run

cp /etc/resolve.conf /media/card/etch/etc

Next you need to add a few things so the environment will be have as Debian expects, and not inherit the slightly different IPaq environment, so grab profile and profile.ipaq and put them in the /etc directory of your chroot. Mostly it just sets your home directory to /root instead of /home/root and a few other minor things but important things.

Finally, get the chrootme.sh script and put it in the root of your chroot.

Now all you should need to do to use your chroot is

cd /media/card/etch
./chrootme.sh
source /etc/profile

Now you are in your live Debian chroot! Congrats! So why did we go to all this effort to just get another Linux environment when IPaq already has one? Well, this one can now install any software that Debian supports, which is pretty much all software :). But first, at least in my case, we have to do a few things for apt so it will be happy. Run

touch /root/.gnupg/trustedkeys.gpg

gpg  --keyserver subkeys.pgp.net --no-default-keyring --primary-keyring /etc/apt/trusted.gpg --recv 359AAB34 

wget http://ftp-master.debian.org/ziyi_key_2006.asc
gpg --no-default-keyring --primary-keyring /etc/apt/trusted.gpg --import ziyi_key_2006.asc

This install the required gpg trust info so that you can securely talk to the Debian package server.
You can also select a mirror by editing '/etc/apt/sources.list'. Now just

apt-get update

and then you can 'apt-get install ' any piece of software you want. I'd recommend starting off with a text editor like vim and/or emacs, and the some programming languages like Python, Ruby, Lisp, or C. Now you have a mobile coding environment that fits in your pocket!

Conclusion

Well, now you have an ultra portable computer that can run any piece of Linux software. I turned mine into a portable development machine. I've been using it at University in my CS classes, but you can do what ever you want with yours.

As for the future, the only real things this tutorial still need are ways to get the WiFi working and usable, and a way to squeeze better framerate out of MPlayer. If anyone has any ideas, please get in touch and let me know :)

I hope this set of notes/tutorial/howto is useful to anyone.

Conectivity the old school way: Toshiba laptop modem (intel) and dialup

2007-07-26 13:56:53 PST

Tags: , , ,

So you might be noticing a theme emerge between this and my last post. Yes, after watching terrible movies and reading some books, some of which are sub optimal, and then generally immersing myself in the internet, I decided I needed to be more connected. So I have several projects on the go to fix that. The earlier post of getting GPRS internet on my laptop from my cell via bluetooth was one such project. But it's also financially impractical. However, my Telus ADSL package comes with 40 hours a month of dialup included. So I thought it was time to turn my attention to that. I'd ignored the old technology of modems forever, not thinking that they can still come in handy in pinch until the city is covered in municipal WiFi. Phone lines are often more prevalent then unsecured wifi in the city, especially in buildings or houses.

So, first, I hopped over to the Telus website and found that the Vancouver dial in number is 604-280-9000. Next, I had to determine the modem that my Toshiba Satellite m40x has. As it turns out there are tools for that: scanModem, a little shell script that does the trick. Downloaded it, unzipped it and ran it. It told me I had an Intel/Alsa modem. So I loaded up the snd-intel8x0m kernel module. Then I installed the sl-modem-daemon package that uses the module and provides the rest of the softmodem. It neede to be setup:

 # dpkg-reconfigure sl-modem-daemon -plow

And it just asked the county I was in, and the set things up. The modem was then controllable from '/etc/init.d/sl-modem-daemon' and could be started and stoped accordingly. The device that was created was /dev/ttySL0 but /dev/modem was also turned into a symlink that pointed to it so either was usable. With the modem setup and on, I then needed a dialer to connect me to my ISP.

First, a simple but verbose and command line dialer: wvdial. To set it up I ran

# wvdialconf /etc/wvdial.conf

It worked and the config file was created. But it needed editing. So I loaded it up in a text editor and uncommented the phone number (one number, no dashes or spaces), username, and password fields and filled them out accordingly. Lastly, for this modem, I needed to add the 'Carrier Check = no' line at the end of the file for it to connect properly. Then everything was in order and connecting was as simple as

# wvdial

Success. I had dailup internet. Ctrl-C in the terminal to disconnect.

The softmodem is flaky though and its often a good idea to restart it between dials

# invoke-rc.d sl-modem-daemon restart

Still, command line isn't as sexy as GUI, or at least not as convenient. So I then installed gnome-ppp and found it in the Applications->Internet menu. I put in the pertinent information again (phone number, username, password) and then tweaked a few options in it's setup window like device in the Modem section, and turning on 'Dock in notification area', and turning off 'Check carrier line' in the Options section. Then I hit the connect button and it connected and minimized to the notification area. Beautiful slow internet was mine!

Reference

Getting my Ubuntu laptop and Sony Ericsson k510a cell phone to talk to each other with Bluetooth: file sharing and internet over GPRS and ppp

2007-07-26 08:23:38 PST

Tags: , , , ,

Well, I taught my laptop a new trick.

I went out and bought a DLink DBT-122 Bluetooth adapter (USB). Cheapest one they had, plugged it into my laptop (Ubuntu Feisty) and it was recognized right away. Installed bluez and bluetooth related packages and started to play.

First thing I did was enable the bluetooth applet that runs in the notification area. It can also be accessed from System->Preferences->Bluetooth Preferences. Once that was on and my cell phone's (Sony Ericsson k510a) bluetooth was on I was able to use nautilus' sendto to send files via bluetooth to my cell phone. Then after turning on Applications->Accessories->Bluetooth File Sharing, which starts an applet in the notification area, I was able to send files to my laptop from my cell phone via bluetooth. So that was all cool, but it was also just warm up.

Next I wanted to get internet on my laptop through my cell phone. While impractical in the areas on cost and speed, it does have far greater coverage than random unsecured wifi access points around the city (especially as of late as people are finally starting to use WEP and WPA) and it's coverage out of city is of course no contest either.

So I installed a few more tools, ppp (Point to Point Protocol) related, like ppp and pppconfig.

The first tool I used was 'hcitool' which is used for establishing bluetooth connections and other bluetooth related issues.

# hcitool scan
Scanning ...
         00:17:B9:DA:E4:F2       phone.mindstab.net

This will scan for all bluetooth devices in range and return their name and MAC address. Next I had to connect to the phone and laptop or 'pair' the devices. For my phone, the Sony Ericsson k510a, I had to do this on the phone's side. I went to Settings->Connectivity->Bluetooth->My Devices. Then I selected New Device and after it scanned, I selected my laptop. It then bid me enter a 'password' so I choose a few numbers, and then the bluetooth manager on my laptop notified me a device was trying to 'pair' and asked me to enter the number there. That done my cell phone accepted my laptop. I selected my laptop/device on my cell phone and told it to always accept connections from that device. Also, to be safe, I put the password/number in '/etc/bluetooth/pin' although I'm not really certain if that was necessary.

Now the devices were set to connect to each other on a regular basis so back to hcitool to handle that. The 'cc' argument establishes or breaks a connection and the 'auth' argument authenticates the connection.

# hcitool cc 00:17:B9:DA:E4:F2
# hcitool auth 00:17:B9:DA:E4:F2

Now a bluetooth connection with the phone was established. Next up it was time to configure the ppp connection that would run from my laptop, over bluetooth to the cell, and from there over GPRS (or possibly EDGE?) to the internet.

First, I needed to further setup Bluez (Bluetooth handler on Linux) to facilitate this by creating a /dev/ entry for the connection. And I needed a bit more info. The command 'sdptool' delivered this to me. It can be used to list all the supported features of a device and their details. I was specifically interested in the 'Dial-up Networking' section.

# sdptool browse 00:17:B9:DA:E4:F2
...
Service Name: Dial-up Networking
Service RecHandle: 0x10002
Service Class ID List:
  "Dialup Networking" (0x1103)
  "Generic Networking" (0x1201)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 2
Profile Descriptor List:
  "Dialup Networking" (0x1103)
    Version: 0x0100
...

In there I found the 'Channel' that the protocol was operating on, in this case '2'. Now I opened up '/etc/bluetooth/rfcomm.conf' and setup the device.

/etc/bluetooth/rfcomm.conf

rfcomm0 {
        bind yes;
        device 00:17:B9:DA:E4:F2;
        channel 2;
        comment "Bluetooth PPP Connection";
}

Then I restart bluetooth. On newer Ubuntu versions the service is just called 'bluetooth' but on older versions it's apparently called 'bluez'.

# invoke-rd.d bluetooth restart

Now I had setup a connection to my cell phone and created '/dev/rfcomm0' for it. I was now ready to setup a ppp connection over bluetooth.

pppconfig thankfully does most of the hard work here. It configures the ppp/peer files and the even more convoluted chatscript (some kind of text file that contains the initial connection protocol text that is used to establish the connection).

# pppconfig

pppconfig gives you a menu. I chose 'Create Connection'. Called it whatever, I chose 'gprs'. Next I selected 'Dynamic' (for DNS). Then I selected 'Chat' for the Authentication Method. I entered no password or login, and then deleted the text when it asked for a User name and another password. The default speed of '115200' baud was fine. 'Tone' is the choice for the 'Pulse or Tone' section. The number to dial was a bit tricky. It's in the form of something like '*99***slot-of-internet-on-cell#' so for me '*99***2#' was what I entered but others might try '*99***1#' or possibly '*99#'. I entered the port to use manually and entered '/dev/rfcomm0'. Then it gave me a chance to review and then write the file. I did so.

The two main files it creates are '/etc/ppp/peers/gprs' and '/etc/chatscripts/gprs'. If you are lucky you should just be able to connect now, but I had problems, so I had to tweak the files a bit. In '/etc/ppp/peers/gprs' I had to comment out the 'remotename' and 'ipparam' lines with hashs [#].

/etc/ppp/peers/gprs

...
user ""
#remotename gprs2
#ipparam gprs2

and in '/etc/chatscripts/gprs' I had to comment out the 'ogin:' and 'ssword:' lines again with hashes.

/etc/chatscripts/gprs

...
# ispname
#ogin: ""
# isppassword
#ssword: ""
# postlogin

Now all the ppp config files were properly configured to work with my phone, so it was time to try the connection out. Before that though, I turned other networking off, which is easy enough with NetworkManager, I just right clicked on it and unchecked 'Networking'. Then to turn on the connection over bluetooth, ppp, and gprs, I just used the 'pon' command.

# pon gprs

and gave it a few seconds. My cell lit up and told me it was connecting and then it connected. Then I was good to go. Sadly gprs internet rates are expensive here at $0.05 / kB. Also, it's a bit firewalled so the standard ping google.com test to see if the connection is working fails. I just loaded a small web page in my browser. It worked! Then tried to 'ssh' to my server, and that also worked! When I was done, I just

# poff gprs

to turn the connection off.

And that's it. Now I can get files to and from my cell phone and get internet from it for my laptop as well.

When I was having trouble, I looked in '/var/log/syslog' to see where the trouble was coming from.

Also, for some reason, the next day, 'sdptool' was reporting that the 'Dailup Networking' service had moved to channel 2 so I had to change '/etc/bluetooth/rfcomm.conf' file to represent that and restart bluetooth with 'invoke-rc.d bluetooth restart', so keep an eye out for that if your connection starts failing later for no reason.

References

Having trouble with new Java packages?

2007-02-28 16:24:37 PST

Tags: , ,

If you're updating some Java packages, like Azureus and its dependancies, and something fails spectacularly to build, the following prefix to emerge may fix that:

JAVA_PKG_FORCE_VM="sun-jdk-1.5" JAVA_PKG_BSFIX="off"  \
JAVA_PKG_FORCE_COMPILER="ecj-3.2" JAVA_PKG_FORCE_CFLAGS="-source 1.5  -target 1.5" \
emerge  ... -va

From what I can tell the problem stems from Java build scripts not specifying what version of Java they need and so Portage defaults to blackdown-java 1.4. Sadly, these packages need Java 1.5 for generics etc. The above command forces Portage to use Sun Java 1.5.

Installing chrootable Gentoo on a GP2X

2006-12-11 23:35:32 PST

Tags: , , ,

Contents

Why?

Because now that the GP2X can use ethernet over USB and Wifi it's pretty much a small form factor 200MHz ARM computer, and extremely portable at that. I've installed Gentoo on lesser machines. Also, I wanted an ultra portable box I could do programing with in whatever language I want, like Ruby or Lisp. But more generally, there is a vast array of software available to Gentoo that isn't available for the native Linux of the GP2X. If I could get Gentoo on the GP2X (which considering it's basically just a small ARM box, shouldn't be too hard) then I'd be opening up a whole new and vast world of software for the GP2X.

As for why chrootable and not a full install? The GP2X firmware does a good job and is extremely compact (~20MB). Getting Gentoo down to that might be a trick. Plus, with the custom hardware, rolling my own kernel might be a bit of work. And it would also probably preclude me from using any GP2X specific software. A chrootable Gentoo environment gives me the best of both worlds. I can use the GP2X and assorted software as normal, but pop in an SD card, and suddenly I also have a Gentoo environment. The GP2X Linux ends up acting like a bootloader and an abstraction layer between the somewhat custom hardware of the GP2X and the Gentoo environment.

Getting the GP2X fully online

Note: On the computer side of things it is assumed you are running Gentoo, as I am, so some things may have to be changed accordingly

First, we have to get the GP2X properly online. Upgrade to the latest firmware (anything 2.* should do). Once the GP2X is upgraded, turn it on and go into the Settings->System. Turn on advanced options, USB Networking, set the IP to 10.1.0.2, and turn on at least Telnet and FTP.

On the computer end, you need to add some additional support to your kernel. You'll need USB->USB Gadget Device support and from there 'Ethernet Gadget (CDC)' and 'RNDIS' support. Also, you need from USB->Networking: at least 'Host for RNDIS', and support for devices, so I went with 'Simple USB Network Links (CDC)' and 'Netchip 1080'. Finally, you need from 'Networking' enough stuff to get iptables up and running and doing NAT (network address translation). Recompile your kernel. Reboot if needed. Load the appropriate modules if needed (and add them to /etc/modules.autoload).

Now connect the GP2X via USB to your computer. To see if the connection was noticed check dmesg. To try it out

ifconfig usb0 up 10.1.0.1

Then trying pinging the GP2X (10.1.0.2). If that works, you should then also be able to telnet and ftp to the GP2X.

If it fails, you may need to update your g_ether module on the GP2X. Follow this quick guide to update it and try again.

We're almost there. We now have a LAN between your computer and the GP2X, but the GP2X doesn't have net access. We need to setup the computer as a firewall that does NAT for the GP2X. On the computer run

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables save
echo 1 > /proc/sys/net/ipv4/ip_forward
/etc/init.d/iptables start

Now your desktop should do port forwarding for the GP2X. But the GP2X doesn't know about it. So telnet onto the GP2X. We need to set it up for full internet access. Copy the contents of your '/etc/resolv.conf' to the GP2X's '/etc/resolv.conf' (This lets it know what name servers it should use for DNS). Finally, we write a simple script you can leave in /root that sets up the routing.

net.sh

#!/bin/sh

route add default gw 10.1.0.1

Then on the GP2X

chmod a+x net.sh
./net.sh

Now the GP2X knows that all connections to the net should be sent to your computer, which is now set up to forward them to the internet. The info in /etc/resolv.conf tells the GP2X where to look for DNS info (changing names into IPs).

To test, on the GP2X

ping google.com

It should work. (net.sh will have to be run every time the GP2X reboots, you may want to make arrangements for that.)

Now, to make this setup more permanent on the computer side of things, we need to set up a few things. We can automate iptables by

rc-update add iptables default

And we can automate port forwarding by editing '/etc/sysctrl.conf' and changing

#net.ipv4.ip_forward = 0

to

net.ipv4.ip_forward = 1

Finally, we need to set up the usb0 connection.

ln -sf /etc/init.d/net.lo /etc/init.d/net.usb0

Then edit '/etc/conf.d/net' and add
config_usb0=( "10.1.0.1/24" )

Now you can

/etc/init.d/net.usb0 start

When ever you want to activate the connection to your GP2X. You can automate it with rc-update, but the connection may not work if the GP2X isn't plugged in before net.usb0 is started. Your millage may vary. But it's easily restartable :).

Preparing the media

We will be installing onto an SD card because the NAND on the GP2X is just about full, and we don't really want to mess with it anyway. We will use the ext2 file system because it's light, but provides all the features any UNIX like OS needs (unlike FAT which most glaringly doesn't support file permissions or links).

First we format the SD card:

mkfs.ext2 /dev/sda1

/dev/sda1 being the devices for the SD card on my computer. Check first before formating that you aren't formating your sata harddrive or something.

There are a few ARM Gentoo stage 3 tarballs floating around.

Since the GP2X runs glibc, I figured that we didn't need the ultra embedded images with uclibc. So I opted for the ArmV4L (glibc) images from 2005.1. 'uname -a' on the GP2X reveals it is in indeed an ARMV4L CPU.

I made a 'gentoo' directory on the SD card (because you don't want to mix GP2X things and Gentoo things) and put the stage3 tarball in it. Then I untared it.

Volia. That's sort of it actually. You now have a Gentoo chrootable environment on an SD card. But we're not really done yet. We need to initialize it, and get it ready for use, and there are a few more things to be done to the GP2X to make it ready. So don't unmount that SD card yet.

The GP2X Linux is based around a limited version of busybox that lacks a few essential (IMHO) utilities. Among them is chroot. Thankfully I was able to dig up a copy of chroot for the GP2X. I grabbed it from the 'GPE for GP2X' package. Unfortunately it is statically compiled so it's 2.3MB. Still, it does the trick. I put it online by it self at ftp.mindstab.net/gp2x/chroot.static for use.

Note: I'm trying to get a dynamic version of chroot for the GP2X. I have the GP2X SDK installed and can cross compile for the GP2X. I tried using chroot from coreutils but I can't get it to crosscompile properly. It still seg faults. It'd probably be better if I could track down the source to a stand alone version of chroot. Help would be appreciated.

I made a 'gp2x' directory on the SD card and tossed chroot.static in there (see, aren't you glad you didn't use the whole SD as the Gentoo root?). Now we are just about ready.

Networked File Systems

SD cards don't have the hugest life spans. Lots of writes can reduce those lifespans. So it makes sense that if we can, we should farm out directories with lots of write to computers with real harddrives that can handle them. Also, if we have directories that we don't often need but are huge, we should farm those out to. This is where networked file systems come in. We're going to at least get /usr/portage to be on some other machine and just mount it over the network to our chroot Gentoo environment to save on space.

Samba for the GP2X

Get the Samba package for the GP2X from www.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,8,1478.

Now we install it to the GP2X's root ('firmware'). This will take up about 2.2 MB of space, which the GP2X's NAND (where the firmware/Linux is installed) can spare. The package is a zip and the GP2X doesn't have unzip, which is slightly annoying. They recommend turning the GP2X's samba server on, mounting it, and unziping the packge to the root. This will work fine. I on the other hand unziped the packages to a directory on the SD card ('samba') and then put the SD card in the GP2X. Once in, I telneted onto the GP2X and copied all the files over to the root:

cp -r /mnt/sd/samba/* ./

(But that is slightly getting ahead of ourselves because we haven't put the SD card in the GP2X yet and it doesn't automount ext2 partitions, so if you are using this method you may want to jump ahead and then come back.)

To mount samba partitions the samba module has to be loaded on the GP2X

modprobe smbfs

Then you can mount directories as easy as

smbmount //10.1.0.1/portage /mnt/sd/gentoo/usr/portage

Again, slightly ahead of ourselves, but you get the idea.

Samba server Quickie

Now the GP2X can mount Samba file systems but we need to export some for that to be of any use. Install samba

emerge samba -va

On your computer and also add support for it to your kernel under filesystems->networked filesystems. You'll need server support.

Then edit '/etc/samba/smb.conf' and add something like the following

 hosts allow = 10.1.0.

...

[Portage]
path = /usr/portage
comment = Portage
available = yes
browsable = yes
public = yes
writeable = yes

Then turn the sambe server on with

/etc/init.d/samba start

and automate samba server starting with

rc-update add samba default

If you want to use NFS on your computer to export /usr/portage, you can get the required NFS client package for the GP2X at archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,42,1880.

Chrooting the Gentoo environment

Now we have everything in place to use our Gentoo environment. So, put the SD card into the GP2X. The GP2X doesn't automount ext2 fire systems, only FAT. That's okay. Create a script to do it for you because it's slightly a hassle.

/root/mount.sh

#!/bin/sh

mount /dev/discs/disc0/part1 /mnt/sd

Then run it. Now the SD card is mounted.

Now we have a Gentoo chroot ready for us and we can parallel the Gentoo Handbook for how to get into it.

Copy '/etc/resolv.conf' into the chroot's /etc ('/mnt/sd/gentoo/etc'). You'll only need to do this once. Now the chroot knows where to look for DNS info.

Next we copy '/lib/libiconv_plug.so' into '/mnt/sd/gentoo/lib'. I'm not 100% sure why, but libiconv is some extension for glibc and since the GP2X uses it, if the chroot environment doesn't use it, every command throws a harmless but annoying warning

ERROR: ld.so: object '/lib/libiconv_plug.so' from LD_PRELOAD cannot be preloaded: ignored.

Now the environment is ready to be chrooted. We'll use a small script to automate the few steps we need.

/root/chroot.sh

#!/bin/sh

cd /mnt/sd/gentoo
mount -t proc none proc
mount -o bind /dev dev

/mnt/sd/gp2x/chroot.static /mnt/sd/gentoo /bin/bash

umount dev
umount proc

cd  /root

Finally, before chrooting, we'll want to setup the remote portage directory.

smbmount //10.1.0.1/portage /mnt/sd/gentoo/usr/portage/

Now we can chroot to the environment.

/root/chroot.sh

Once in the environment, it's common practice to

env-update
source /etc/profile

Now the environment is initialized and you can do what ever you want. We don't really have to install anything or make the system bootable, because that's what the GP2X firmware is for. We're just hijacking it to jump start our more powerful environment.

Most likely you'll want to install more software. That's why we picked Gentoo, because it has more software available for it than the GP2X currently. Still, you'll probably want to edit '/etc/make.conf' and remove some flags, especially ones related to X.

/etc/make.conf

...
USE="-alsa -X -gnome -qt -qt3 -gtk -gtk2"
...

Also, before you can emerge anything, you'll need to set up your profile:

ln -snf /usr/portage/profiles/default-linux/arm/ /etc/make.profile

Now you are ready to emerge software.

Note: Software installation is currently not recommended at this point. Compilation takes place at '/vat/tmp/portage' which is on the SD card. This will start to take it's toll on the SD card. I attempted to get /var/tmp/portage to also be a Samba mount and succeeded as far as I could mount it remotely, however, portage complained it could not chmod the directory appropriately and thus failed. Until I can get this working I'm not too eager to emerge much software and would recommend you also take it easy until you can successfully get /var/tmp/portage remotely mounted. Suggestions would be appreciated.

Crossdev

Another way to install software on the GP2X is to cross compile it, which is compiling it on another computer, for ARM, and then package it (yes portage supports binary packages). There are some difficulties which I'll outline, but this method should be possible at least.

You should start by reading www.gentoo.org/proj/en/base/embedded/cross-development.xml. It's a comprehensive run down of crossdev, a Gentoo app to help setup a cross compiling environment. It's what you would use to get the tools you need to cross compile for the GP2X. It also goes over packaging something for another computer for easy deployment. It's required reading.

I've started playing around with this so I have some pointers for anyone else looking to try it. The GP2X funs Linux 2.4.25, but the closest matching kernel in portage is 2.4.26-r1. Use it. The Linux chroot has glibc-2.3.5 but that doesn't work with crossdev, go with 2.3.6-r5 at the least. The chroot also has gcc 3.4.4, but that again doesn't play nice in crossdev, use gcc-3.4.6-r1 instead. My final crossdev command looked like

USE="-*" crossdev -v --libc 2.3.6-r5 --gcc 3.4.6-r1 --kernel 2.4.26-r1 --ex-gdb --target arm-unknown-linux-gnu

When setting up your 'make.conf', the architecture of the GP2X you'll want to use in CFLAGS for -mcpu and other tuning arguments is 'arm920t'.

I was able to get crossdev installed, but using xmerge, I was unable to then compile anything, instead I kept getting 'C compiler cannot create executables.' errors.

Also, the crossdev solution seems slightly more geared towards more embedded devices where you will be creating a whole environment in one go and then doing something like flashing it onto the device. It feels less suitable for package by package software installation (by proxy) for the GP2X. PArtly because you'll have to keep track of all the dependencies installed and package those too and install then on the GP2X. Another problem that then creeps up is that since hte GP2X has a Stage3 install, it already has lots of software, but the crossdev environment has none, so it will compile newer versions of everything for it self. It does seem to start to become a bit of a hassle and mess.

Conclusion

Well, I got a chrootable Gentoo environment setup on the GP2X. That's pretty impressive. The only hitch is that I currently don't feel comfortable installing (emerging) software due to the adverse effects it might have on my SD card. But there are options from here. You could set up a cross compilation system, fairly easily accomplished with crossdev, and cross compile packages for the GP2X on a computer and then just install the precompiled packages. This may end up being more effort than it's worth, see above. Also, research further on how to get portage to play nice with samba mounted /var/tmp/portage.

Also, as an after thought, you might want to take the SDL libs for the GP2X and untar them in the chroot environment and emerge --inject SDL. It's possible you might be able t install some SDL applications then. Or at the least you should be able to write your own.

Finally, I hope this ends up being a useful tutorial/howto for anyone out there interested in any of the topics covered.

Reference

A hint of things to come… (How to get around GP2X FTPD stalls on large files)

2006-12-04 10:11:20 PST

Tags: , , ,

So the ftpd on the GP2X doesn't appear to sync when transferring large files. It just stalls. How do I know? I was trying to transfer a 108 MB stage3-armv4l-2005.1.tar.gz to my 1 GB SD card in my GP2X (located at home) while I was at school. I couldn't very well reboot the GP2X into USB storage device mode so I tried to make use of FTP server, but it kept stalling. After a bit of experimentation I guessed that the FTP wasn't syncing the FAT filesysem on the SD card. I was proved right when in a telnet session I ran

while [ 1 ] ;do sleep 2; sync; done

and the FTP transfer then went to completion.

Valid XHTML 1.0!
Valid CSS!
Mindstab.net is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
18 queries. 0.718 seconds.