linux

Posted on 05-19-2008 under linux

The recent frequency of electric breakdowns, coupled with sitting in front of a dimmed laptop screen hoping against hope that the power would come back on before my battery died, produced an interesting result. Fortunately, my brain doesn’t need electricity to light bulbs in the air above my head.

With the blessings of KESC and Worldcall, I went through some web pages about ACPI, the linux power management framework. I found this website quite helpful. Really interesting stuff. (No seriously).

In particular, reading sections 6.3 and 6.4, I struck on a wonderful idea. What if I could log when KESC shuts down my electricity and when it brings it back up. Now what if that data were to be made available on the web!

No, its not that awesome. Still, it would be interesting to see the trends (or lack thereof), appearing through the statistics.

For those of you who don’t want to read my ravings about how I did it, here’s the link to the log. Let me know if you have any problems viewing it. Keep in mind, this is running off my laptop, with my not-so-reliable connection, so you might see some problems.

Now to the meat. There’s this daemon by the name of acpid which should be running on your linux system already. It’s included in most distributions, so if its not running you can probably install it very easily. This daemon has certain events that cause it to do certain things. For example, if you’ve got a laptop with some extra keys (brightness, hibernate etc.), its more than likely they’re functionality is controlled through the ACPI daemon. What we need to do is find the events corresponding to AC Power and Battery status. In my case these were ac_adapter and battery respectively. (If you haven’t read the sections in the article I mentioned earlier, I strongly recommend you do so before reading further. The path names could vary depending on your system, as they did in my case.)

What we need to know is that there needs to be a file in /etc/acpi/events/ that indicates which script to run when a particular even occurs. In addition, of course, there needs to be a script file for the acpi daemon to actually run when the event occurs. You can download my script files here.

You will probably have to change the paths in these scripts. The files powerlog.sh and battlog.sh should go into /etc/acpi, and the files ac_adapter and battery should go into /etc/acpi/events.

Once you’ve edited and copied to the proper directories, you need to restart the ACPI daemon. This can be done ( on a Debian system),

# /etc/init.d/acpid restart

And your scripts should start logging. Have fun!

For my part, I’ll keep my script running, and see what turns up.

Posted on 05-18-2008 under linux

Following on my previous two posts on No-IP, I finally figured out what was wrong with my system. In particular, even though the init scripts were installed, noip would not start at boot up. I had to manually run noip2 to start it up every time I rebooted.

The init scripts themselves were probably installed due to the debian package. I had earlier (naively) indicated that the init script would be installed by simply copying it to /etc/init.d/. This however is wrong and at the very least you would need to run update-rc.d to install it completely. A detailed description of init scripts under Debian can be read here.

I’m not sure if this was a problem with the debian package, but the script did not exist in /etc/rc2.d/. If you know anything about runlevels, you would know this is the runlevel in which debian enters after all initializations are complete to log the user in. I got wind of this when I did a find under the rc?.d directories

$ find /etc/rc*/ -name *noip*

which gave me

/etc/rc0.d/K20noip2
/etc/rc1.d/K20noip2
/etc/rc3.d/S20noip2
/etc/rc4.d/S20noip2
/etc/rc5.d/S20noip2
/etc/rc6.d/K20noip2

As you can see, rc2.d is missing. Sure enough adding a link in rc2.d fixed the problem.

Looking at the links in the other rc* directories, I found the name for the link I was about to create.

$ ls -l /etc/rc3.d/ | grep noip
lrwxrwxrwx 1 root root  15 2008-04-10 22:46 S20noip2 -> ../init.d/noip2

so,

# ln -s /etc/init.d/noip2 /etc/rc2.d/S20noip2

A quick reboot (ughh!) and a check

$ ps -A | grep noip
4108 ?        00:00:00 noip2

shows noip merrily buzzing away.

That was certainly a relief. I wasn’t looking forward to sludging through arcane scripting syntax, and obscure manuals.

Who am I kidding. I would’ve loved doing that :D

Posted on 04-16-2008 under electronics, howto, linux

After two days of banging my head against the wall, interspersed with issuing ineffectual commands, I’ve finally done it. (See shot below).

Xilinx Cable Connected and Running!

The cable drivers available with the Xilinx 9.1i software suite just won’t compile on my system. Apparently they use some proprietary functionality that does not support any kernel other than 2.4. And since I have 2.6 installed…

I had help from here, here and here.

Here’s a rundown of how I made it run on my system, which is a Debian 4.0 testing, with the following output for uname -a

Linux galileo 2.6.24-1-686 #1 SMP Thu Mar 27 17:45:04 UTC 2008 i686 GNU/Linux

I used bash throughout. If you use another shell, some commands may change.

1.

In order to avoid problems later, install libusb-dev and fxload.

 aptitude install libusb-dev fxload

2.

Make a directory somewhere to store the driver’s sources.

mkdir ~/tmp/xildriver
cd ~/tmp/xildriver

3.

Download the source tarball.

 wget "http://git.zerfleddert.de/cgi-bin/gitweb.cgi/
usb-driver?a=snapshot;h=HEAD;sf=tgz" -O usb-driver.tar.gz

(without the line breaks)

 tar zxvf usb-driver.tar.gz
 cd usb-driver

4.

Compile the driver.

 make

5.

copy the library to a lib directory.

 su
 cp *.so /usr/local/lib/
 exit

This step is totally optional. Just make sure you substitute the right path in the next step.

6.

make the linker aware of the new library

 export LD_PRELOAD=/usr/local/lib/libusb-driver.so

This step will need to be repeated every time you login. Or you can add it to your shell’s rc file. For bash this is /home/user/.bashrc.

All the previous steps are common to all tutorials and sources I’ve mentioned earlier. Its also given in the README file that comes with the source. After this though, its all from Verhaegen’s email.

7.

Make a new udev rule file
I absolutely do not understand this step, but I believe it has something to do with how the USB cable is detected.

 su
 vim /etc/udev/50-xilinx-usb-osdriver.rules    # a new file with arbitrary
#name ("50" is recommended)

Now paste this into the file and save it.

ACTION=="add", BUS=="usb", SYSFS{idVendor}=="03fd", MODE="666"

If you don’t know how to use vim, use nano instead ( or learn it). If you would rather use a graphical editor, then exit from root user and type

kdesu kwrite /etc/udev/50-xilinx-usb-osdriver.rules

Now restart udev.

 /etc/init.d/udev restart

8.

Get the bus and number of the USB cable.
Plug the board in and type

lsusb | grep Xilinx

Note the bus number and the device number. Here’s my output

 Bus 005 Device 016: ID 03fd:0008 Xilinx, Inc.

9.

Update firmware
If the ID in the above line is not 03fd:0008 in your case, do the following.

 su
 /sbin/fxload -v -t fx2 -I /home/zohair/installed/Xilinx91i/bin/
lin/xusbdfwu.hex -D /proc/bus/usb/005/016

Again without the linebreaks.
Replace your bus and device numbers from the above step into this command.

10.

Start impact (as normal user of course)

 ~/installed/Xilinx91i/bin/lin/impact

Impact should detect your cable automatically. If it does not go to Output->Cable Setup: and choose Xilinx USB cable.

If it still does not work, there are some more instructions in Verhaegen’s email (steps 13 onwards).

Credits

Credits go to Michael Gernoth who took the time out to make these drivers. And also to Paul Verhaegen’s excellent email and Luzerne GANHIR . Thanks guys.

Posted on 04-13-2008 under linux

Referring to my previous post on getting a domain name for my dynamic IP home server, there was one thing left to do.

Recently I had to reboot my computer, because I had to get some work done on Windows. (Orcad don’t work on ‘Nix.) Long story short, noip2 didn’t start automatically on reboot. No surprise as nobody installed the startup script (duh!).

The noip2 tarball contains the init script for Debian, as well as for Gentoo and Redhat. This should be copied to /etc/init.d and renamed to noip2.sh, as is written down in the file itself. I don’t understand init scripts at all, but somehow this worked. Apparently noip2 runs under root, which is no big deal really. But you won’t be able to see the stats if you use

 noip2 -S

under normal user mode. You’ll have to change to root to see any stats.

[Update] Please read No-IP continued for updates.

Posted on 04-10-2008 under linux

I just registered for No-IP.com, just to see what my server would look like from the web. Brilliantly, the No-IP dynamic update program is available on Debian. A quick

 aptitude install noip2

and I was enjoying the joys of being url accessible.

Not surprisingly my ISP soon hiccuped, causing me to lose my IP address. This was the perfect test for No-IP.

Which went bad. It soon became apparent that no-ip wasn’t doing what it was meant to. After looking through the excellent guide by No-IP, forum posts, and more, I still couldn’t get it to run.

It then occurred to me that the utility could be using a different port, one that would be blocked by my firewall. So I tried a really risky, “disable firewall” test. And what do you know, no-ip worked just fine. So the problem was with the port, but which one? I can’t test all 65,536 ports!

Since I already had the utility’s source code, as I had followed their guide, I looked through the files. Thankfully there was only one C file, and a quick look uncovered this line.

 #define CLIENT_IP_PORT		8245

Bloody ****, if you had only told us there was a port you needed ….

Problem fixed. But I shouldn’t have had to muck about in the code in the first place. No-IP is a business and they could lose customers this way. The guide was written for complete laymen, and such a person just cannot go looking through code. Proper documentation is necessary people.

Then again, if No-IP hadn’t given us the code, I wouldn’t have found that port so easily.

[Update] Please read No-IP continued for updates.

Next entries »