个人工具

UbuntuHelp:ACPIBattery

来自Ubuntu中文

跳转至: 导航, 搜索

This page is missing a diagnostic guide to be sure that the problem described here is what is happening to a specific system. If you know how to test for this issue please add such a diagnostic guide.

Introduction

Some Notebooks don't display the battery status. This HOWTO will show you how to fix this annoying problem. I am aware there are a lot of forum posts on this but none show you how to easily fix the problem. Note: The Ubuntu kernel already contains the patch that is needed for this to work, so no recompiling of the kernel is needed in this HOWTO!

Prerequisites

We need to compile some stuff along the way, so we need the package build-essential. We also need the packages flex-old (which will replace flex) and bison.

sudo apt-get install build-essential bison flex-old

The DSDT for your notebook

The DSDT (Differentiated System Description Table) sits in your BIOS and gives Linux all the information on your computer. Yours is obviously messed up, so we have to get a new one. Go to the ACPI page at sourceforge and in the menu on the left click on DSDT and View. Here you can select your manufacturer, model and BIOS version. On the page you will get then, you can download a fixed DSDT for your notebook. If there is none for you notebook, see the links at the end of this document. If there is no DSDT for you BIOS version, update your BIOS (which in fact might already fix the problem). So copy the download address (to paste it to the console) and in your $HOME do:

mkdir acpi
cd acpi
wget http://acpi.sourceforge.net/dsdt/tables/Manufacturer/Model/DSDT.asl.gz
gzip -d DSDT.asl.gz

(the link after wget has to be replaced with the link to your DSDT)

Obtaining Intel's iasl compiler

The DSDT has to be compiled. For this we need a special compiler from Intel. Download there Unix source here. You might have to replace the download link in the following.

tar zxf acpica-unix-20050624.tar.gz
cd acpica-unix-20050624/compiler
make
cp iasl ../..
cd ../..

If the make didn't work I can only assume that bison is not installed or you still have the flex instead of flex-old.

Compiling your DSDT

Since the 2005 versions of iasl are more restrictive than older versions your DSDT might not compile. You can either try to find an older version of iasl (I couldn't) or fix the DSDT by yourself (I will explain this).

cp yourdsdtfile.asl dsdt.asl # backup
./iasl -tc dsdt.asl          # compiling

If this works you should get 0 errors, a couple of warnings and two new files. A .hex and a .aml file. If it doesn't you will have alot of error messages telling you a ResourceSource string is missing. These errors are easy to fix. Keep the windows with the compile errors open, since we will need the line numbers. What the errors might look like:

dsdt.asl  1028:                     0x0100, 0x00)
Error    1094 -                                 ^ Missing ResourceSource string (required)

dsdt.asl  1034:                     0x00000CF8, 0x00)
Error    1094 -                                     ^ Missing ResourceSource string (required)

dsdt.asl  1041:                     0x0000F300, 0x00)
Error    1094 -                                     ^ Missing ResourceSource string (required)

Lets open the .asl file and look at line 1028.

gedit dsdt.asl&

It looks like this:

1023  WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
1024      0x0000, /* Address Space Granularity */
1025      0x0000, /* Address Range Minimum */
1026      0x00FF, /* Address Range Maximum */
1027      0x0000, /* Address Translation Offset */
1028      0x0100, 0x00)

What we have to do is simply remove the 0x00 so that line 1028 looks like

1028      0x0100)

Do this for all missing ResourceSource string errors (they should all be in the same place), save the file and close gedit. Now compile again with ./iasl -tc dsdt.asl and watch the magic.

Some backups

As we don't want to mess with your working system we'll work on a backup and add that backup to your bootloader.

sudo -s -H   # followed by user pw
cp /boot/initrd.img-2.6.10-5-686 /boot/initrd.img-2.6.10-5-386.acpi
cp /boot/vmlinuz-2.6.10-5-686 /boot/vmlinuz-2.6.10-5-386.acpi
exit

To be able to boot from this kernel-copy we need to add a section for it to the grub bootloader.

gedit /boot/grub/menu.lst&

Add a section that looks like this (see other sections in your menu.lst for comparison)...

title           Ubuntu, kernel 2.6.10-5-386 Battery
root            (hd0,3)
kernel          /boot/vmlinuz-2.6.10-5-386.acpi root=/dev/hda4 ro quiet splash
initrd          /boot/initrd.img-2.6.10-5-386.acpi
savedefault
boot

...and place it where you want it to appear in the bootmenu.

Putting your DSDT into initrd

What remains is to actually add the DSDT to your initrd. There are 2 ways of doing this. The first one is to patch the initrd.img file, so that the initrd.img will include the DSDT. (NOTE: if you are a BREEZY user the second method is prefered):

echo -n "INITRDDSDT123DSDT123" >> /boot/initrd.img-2.6.10-5-386.acpi
cat dsdt.asl >> /boot/initrd.img-2.6.10-5-386.acpi

The alternative option is to add the DSDT.aml file in a specific place so that the default initrd image will search for it and load it on boot. As a bonus, with every kernel update the DSDT will be loaded. Beware that if the DSDT is incorrect it may lead to a kernel panic. If you are using HOARY or below: Once you have the DSDT compiled, copy the DSDT.aml in /etc/mkinitrd/DSDT (without the extension, I don't know if this is necessary):

sudo cp dsdt.aml /etc/mkinitrd/DSDT

Then reconfigure the kernel package you are using:

sudo dpkg-reconfigure linux-image-$(uname -r)

If you are using BREEZY or DAPPER, the location to put the DSDT.aml file has changed, it's:

/etc/mkinitramfs/DSDT.aml

WITH the extension! it's necessary. Then reconfigure the kernel package as before:

sudo dpkg-reconfigure linux-image-$(uname -r)

If you are using EDGY, the location to put the DSDT.aml file has changed, it's:

/etc/initramfs-tools/DSDT.aml

WITH the extension! it's necessary. Then reconfigure the kernel package as before:

sudo dpkg-reconfigure linux-image-$(uname -r)

That's it. Reboot your computer and pick the newly created bootoption. If it all works out you can savely remove the $HOME/acpi directory and modify the bootmenu as you like (i.e. make the new bootoption default).

Links

acpi.sf.net - ACPI Homepage<
> Gentoo Forums - How to fix a DSDT yourself<
> Intel ACPI - Download iasl compiler<
> gaugusch.at - the kernel patch to make this work

Another possible solution (workaround)

If fixing your DSDT file like suggested avove doesn't solve your battery monitoring problem, you can try the folowing simple workaround. In my case, it seems that if I unload and reload the "battery" module, everything works fine after. But before unloading the battery module, I need to unload the smart battery module (acpi_usb).

  • How to determine if this solution works for you:

To try this solution, do the following: Open a terminal and enter the following commands, in this order:

 
sudo rmmod acpi_sbs
sudo rmmod battery
sudo modprobe battery

Then, enter this command:

sudo acpi -V

if you see someting like this:

 
Battery 1: charging, 100%
Thermal 1: ok, 56.0 degrees C
AC Adapter 1: on-line

Then, voila, your battery is now detected and monitored and you now know that this solution works in your case. If you don't see any reference to the battery after issuing the "acpi -V" command, the problem may be more complex...

  • Fixing the problem in a permanent way with this workaround:

I have created special init scripts that I put in /etc/init.d and /etc/acpi/resume.d in order to unload-reload battery module at each boot and resume after hibernation. In a more detailed way, here's what I did and what you can do (at your own risk!): 1. Using a text editor, put the following content in a file and save it:

 
#!/bin/bash
rmmod acpi_sbs
rmmod battery
modprobe battery

2. Make a copy of this file, name it "modules-load-battery", make it executable (in a console, you can use the command "sudo chmod a+x modules-load-battery") and put this file in /etc/init.d 3. Use the Ksysv editor (or whatever it is called in K menu/system or in the "System settings"/System Administration/System services), in order to make this script run at each boot time (you can make it run just before the "kdm" script; it works for me). 4. Make another copy of this file, name it "37-modules-load-battery.sh", make it executable (in a console, you can use the command "sudo chmod a+x 37-modules-load-battery.sh"), and put this file in /etc/acpi/resume.d; it will run at each resume from hibernate state.