Tuesday, May 19, 2009

Getting HDASP to work on Jaunty

When working on getting the IBM Hard Drive Active Protection System (HDAPS) to work properly on Intrepid (8.10), I found out the newer kernel that would be part of Jaunty would support some things out of the box. As I hate compiling kernels and love to leave that to the more gifted, I decided then I'd sit it out until Jaunty would come out.

Having said that, it turned out it wasn't going to work out of the box on Jaunty either, but... it would not require any kernel compilations either. So I decided to give it a go.

Some things are documented on other blogs as well and I'll be copying/pasting a lot of content from there. However, I still ran into quite some problems that required digging further and further through the internet. Luckily I wasn't the only one, so I was able to find out how to get it to work properly. Please regard this post as summary of information gathered from all kinds of sources on the net. Unfortunately I can't remember all sources I used exactly, there were just too many before I found the ultimate solution, so I won't be giving any credits as I wouldn't like to ommit any (so therefor I give none - but I won't take credits either, it's mostly copy/paste completed with the things I recovered from the xterm history!!!).

How to get it to work:

The HDAPS system consist of two parts. The driver that enables reading the acceleration data and some sort of userspace software that does the actual parking of the harddrive heads, usually hdapsd.

The hdaps driver is part of the kernel but the driver maintainers actually recommend using the tp-smapi driver instead. So that’s what we’ll do.

Start by making sure you have the necessary tools installed

$ sudo apt-get install build-essential module-assistant

Luckily it’s in the package repository (universe)

$ sudo m-a a-i tp-smapi

this will fetch and install the tp-smapi-source package, unpack the source and then compile and install the kernel module. If you ever get the message that it is already compiled and you still want to recompile/reinstall it, throw in the -f (force) option here.

Try loading it:

$ sudo modprobe tp_smapi
$ sudo modprobe hdaps

The kernel log should show something like this (use dmesg):

[ 1546.780684] thinkpad_ec: thinkpad_ec 0.37 loaded.
[ 1546.784125] tp_smapi 0.37 loading...
[ 1546.784406] tp_smapi successfully loaded (smapi_port=0xb2).
[ 1571.445942] hdaps: LENOVO ThinkPad T61 detected, setting orientation 1
[ 1571.446111] hdaps: initial mode latch is 0x05
[ 1571.446265] hdaps: setting ec_rate=250, filter_order=2
[ 1571.446493] hdaps: device successfully initialized.
[ 1571.446607] input: ThinkPad HDAPS joystick emulation as /devices/virtual/input/input13
[ 1571.469284] input: ThinkPad HDAPS accelerometer data as /devices/virtual/input/input14
[ 1571.505138] hdaps: driver successfully loaded.

For some reason some configuration for udev is missing. Fix this by running

echo 'KERNEL=="event[0-9]*", ATTRS{phys}=="hdaps/input1",ATTRS{modalias}=="input:b0019v1014p5054e4801-*",SYMLINK+="input/hdaps/accelerometer-event"' | sudo tee /etc/udev/rules.d/51-hdaps.rules

Now for the userspace stuff. First let us test if APS is actually working.

$ sudo apt-get install hdaps-utils

After installation you can use hdaps-pivot or hdaps-gl to verify that the sensors are working


hdapsd in Jaunty is old. There is a PPA with newer versions.

Add the PPA to your repository list

$ cat | sudo tee /etc/apt/sources.list.d/hdapsd.list <<> deb http://ppa.launchpad.net/jonasped/ppa/ubuntu jaunty main
> deb-src http://ppa.launchpad.net/jonasped/ppa/ubuntu jaunty main
> EOF

And add the PPA key

$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 45EA2DEACE74152B61554DE4036A90F2BEFC6EB4

and then update the package list and install the package

$ sudo apt-get update
$ sudo apt-get install hdapsd

Remember to edit /etc/default/hdapsd to match your system. Most likely you will want to change the sensitivity settings. I found '15' to be too sensitive. At the moment I use '50', but you might want another setting...

Now, we're not there just yet. It will work with the above once, but after a reboot it will stop working again. Modprobe'ing will not work anymore either. It'll throw an error like:

thinpad_ec: Unknown parameter 'force_io'

when you try (check with dmesg). It took me 5 hours to find out why and how to resolve this.

It is because there an entry in /etc/modprobe.d/local.conf which explicitly loads the thinkpad_ec module with the option 'force_io=1'.
Open this file as root (sudo) for editing and comment the line which mentions the thinpad_ec module:

$ sudo gedit /etc/modprobe.d/local.conf
The you can restart the HDASP demon with
$ sudo /etc/init.d/hdasp restart

Now you should be fine and it will work over reboots.
There are some pretty cool applets that will show you the status of the HDAPS system. I still use the Avant Window Manager and the latest version has an applet that shows it's status too. With these you can check if it actually works.

Also, the newer HDAPS system you now got implements a joystick device; now you can play Tuxrace by tilting your Thinkpad! Also available: an anti-theft alarm... more on these on the thinkwiki.

20 comments:

  1. Hi,
    First of all many thanks for this hdaps howto!
    I tried to follow this and it helped a lot, but I've got one issue remaining: after reboot tp_smapi module is not loaded and demon starts using only thinkpad_ec + hdaps. I can add tp_smapi to /etc/modules, but I wonder if the fact it is not loaded automatically doesn't mean that sth is wrong?

    The second question I have is if there's a way to test if the hdaps demon works correcly without avant?

    It is also worth to mention that for some models you have to pass invert param to hdaps module so the axis are oriented in a proper way.

    Many thanks

    Morg

    ReplyDelete
  2. Ok, the second question about testing if it works was solved by following /var/log/daemon.log file ;)

    ReplyDelete
  3. Hi I have many problems with this procedure.

    It seems it creates the new module for tp_smapi but in the end it loads the old tp_smapi from stock kernel no matter what, also when I modprobe hdaps it says non found, the file is in lib/mod/ker/updates but it keeps on searching it in the stock kernel drivers.

    Of course the rest of the procedures is useless.

    Btw I have no etc/modprobe.d/local.conf file and never had it

    please help me

    ReplyDelete
  4. Lele,
    First check if all modules were installed in the proper place, ie
    /lib/modules/2.6.28-12-generic/extra/tp_smapi.ko
    /lib/modules/2.6.28-12-generic/kernel/updates/hdaps.ko
    /lib/modules/2.6.28-12-generic/extra/thinkpad_ec.ko
    (change kernel version to the one you are using)
    If they are there then try to run `sudo depmod` and check if it works.
    If they are not there then check if you have package tp-smapi-modules-2.6.28-12-generic installed (again change the kernel version). If not that means `sudo m-a a-i tp-smapi` step has failed: try to rerun this command and look for errors.

    Hope it helps

    Cheers

    Morg

    ReplyDelete
  5. Thanks for the help, the files are installed in the correct folders and I run sudo depmod but when i run sudo modprobe hdaps its says error inserting hdasp (lib/modules/2.6.28.12....../drivers/hwmon/hdaps.ko) no such devide or address

    ReplyDelete
  6. I also have the package installed correctly

    ReplyDelete
  7. I have a huge problem, I depmod all three modules with their full path, the thing seemed to run and hdaps was finally loaded, the hdaps-gl thing worked, the hdapsd program was loaded fine and I expect the hard disk was stopped on bumps.

    The problem is that when I restarted the notebook the system crashed at start and enter a loop with strange graphical issues, not gdm no login nothing, not even ubuntu logo loading.

    Now I'm using the "old" 2.6.28-11 kernel which works fine but how do I revert thing back in -12 the way they where ? what did I do wrong ?

    Thanks for the help sincerily

    ReplyDelete
  8. ok sorry if I'm monopolizing the comment section...
    I solved the crash problem reistalling all packages with linux 2.6.28-12 name and uninstalled all that I had installed with the procedure. Now everything is reverted.

    But where did I go wrong ?

    ReplyDelete
  9. I suppose it's some problem with modprobe configuration, but I don't have any more specific idea. Did you played previously (directly or throug some program or by installing some strange packages) with files in /etc/modprobe.d/ ? If so try to revert those changes.

    Cheers

    Morg

    ReplyDelete
  10. Hello!

    Very nice howto, I've been looking for something like this for months.
    One question before I try to do this: will it work on 8.10?

    Thanks!

    ReplyDelete
  11. I've tried installing the source downloading them from the website and "make install" as the official read me says. First thing I discovered is that the tp_smapi module loaded with your procedure is actually the old 0.37 one and not the one its should have compiled, because if you "make load" the module on the dir of the downloaded source its says 0.40 loaded. It happens to me too that the system loads the old stock kernel one if I just modprobe tp_smapi or when I reboot, I really don't know why.

    Anyway with the classic method the hdaps gets loaded correctly and it works, the annoying thing is that I discovered a raise in watt consumption of at least 4 watts, more or less 20 minute less of autonomy.

    Sincerely I don't know how crucial is hdaps for your safety, I guess a lot, but to lose 20 minutes of battery is not acceptable for me.

    ReplyDelete
  12. No clue why I am getting this error now. Perhaps you can help?

    root@jgarcia-laptop:~# /etc/init.d/hdapsd start
    * Not starting hdapsd: /sys/block/sda/device/unload_heads exists, but is not writeable, please read /usr/share/doc/hdapsd/README.Debian

    ReplyDelete
  13. I figured it out in /etc/defaults/hdapsd you need to set

    FORCEENABLE="yes"

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Thanks for this thorough guide. One comment: I also don't have /etc/modprobe.d/local.conf, and HDAPS seems to work fine without it.

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. ubuntu 9.04 X200
    sudo modprobe tp_smapi
    FATAL: Error inserting tp_smapi (/lib/modules/2.6.28-14-generic/kernel/ubuntu/misc/tp_smapi.ko): No such device or address
    sudo modprobe tp_smapi
    sudo modprobe hdaps
    FATAL: Error inserting hdaps (/lib/modules/2.6.28-14-generic/kernel/updates/hdaps.ko): No such device or address

    ReplyDelete
  18. Thanks...
    After a lot of trying I got batterie charging options working - on Karmic (9.10), X61

    ReplyDelete