Category:How to - Low Power

From Gumstix User Wiki
Jump to: navigation, search

Status

This page is a work in progress. Many users are running Gumstix COMs in power sensitive applications and need to reduce power consumption as much as possible. This page is being developed by the Gumstix community as the steps are learned for reducing power.

Relevant Community Mailing List Threads

sample numbers for Overo Earth COM power consumption

Building a linux omap3 pm for Overo

cpufreq on the Overo

Background

The default omap3 openembedded build does not provide an optimal setup for power reduction on Gumstix Overo COMS. In order to achieve the lowest power possible for your application, you have to perform a combination of the following:

  • Use the latest OMAP Power Management (pm) kernel branch
  • Enable power saving features such as sleep when idle, off mode, and dvfs
  • Disable internal OMAP devices
  • Hold unused external chips such as USB, Wifi, Bluetooth, etc. in reset
  • Turn off unused LEDs

PM Kernel

The PM kernel is a development branch of the linux-omap kernel focused on developing the power management features of OMAP. By default, openembedded does not use the PM kernel, but instead uses the mainstream linux-omap kernel. Some of the changes of the PM branch have been merged to the mainstream linux-omap branch. However, not all changes have been merged so you must manually configure openembedded to use the PM kernel to get the most power savings possible.

2.6.39 PM Kernel

Steve Sakoman has recently provided the 2.6.39 PM kernel with gumstix specific patches. This is the preferred kernel to use although no future PM changes will be back ported to this kernel. Steve will only maintain gumstix specific fixes for this kernel.

First download the custom PM recipes from here and extract the archive to your over-oe directory.

Note: If you have an existing user.collection in your overo-oe directory, you may want to back it up before extracting this archive.

Note: If you plan to use USB, then you will need to comment out the usb_off patch in the linux-omap-pm_2.6.39.bb recipe.

To enable the PM kernel edit the file

org.openembedded.dev/conf/machine/overo.conf

and change the line

PREFERRED_PROVIDER_virtual/kernel = "linux-omap3"

to

PREFERRED_PROVIDER_virtual/kernel = "linux-omap-pm"

Save the changes and then run bitbake to build the kernel.

$ bitbake -b user.collection/recipes/linux/linux-omap-pm_2.6.39.bb

Or simply run

$ bitbake virtual/kernel

and bitbake should use the new linux-omap-pm_2.6.39.bb recipe automatically.

You may get an error saying it can't download the tar archive but it should fallback to pulling the source using git. This step will take a while since the pm git is over 400 MB.

If the kernel builds fine, you can build your image normally.

$ bitbake omap3-console-image

Once you install the new build to your micro sd card, you need to make changes for the new kernel. The new kernel uses ttyO2 as the serial port instead of ttyS2. To make the changes,cd to the Gumstix os partition on your micro sd, and do the following:

  • Edit <path to mcirosd rootfs>/etc/inittab and change ttyS2 to ttyO2
  • Make a "node" in dev for ttyO2
$ mknod -m 660 <path to mcirosd rootfs>/dev/ttyO2 c 4 66
  • On bootup, execute these commands from the uboot command line (assumes your uboot and xload are setup previously)
mmc init
setenv console ttyO2,115200n8
saveenv (run only if you want to save the new console setting)
run loaduimage
run mmcboot

You should now boot into your new kernel. Follow the instructions in the sections below to use PM features.

PM Features

For a full list of PM features see OMAP Power Management. The features listed here are the most common needed to reduce power.

Setup Debug FS

If you are using any kernel higher than 2.6.29 (PM or standard kernel), then before you can enable PM features, you need to setup the debug file system for manipulating pm configuration.

mkdir /debug
mount -t debugfs debugfs /debug

Sleep While Idle

Next, enable "sleep while idle". This will allow the processor to attempt deeper sleep states when idle. You must also enable sleep timeouts for the serial ports, otherwise this will result in increased power consumption.

# echo 5 > /sys/devices/platform/omap/omap_uart.0/sleep_timeout
# echo 5 > /sys/devices/platform/omap/omap_uart.1/sleep_timeout
# echo 5 > /sys/devices/platform/omap/omap_uart.2/sleep_timeout
# echo 1 > /debug/pm_debug/sleep_while_idle

You can also enable "off mode" after enabling "sleep while idle".

# echo 1 > /debug/pm_debug/enable_off_mode

NOTE: Enabling sleep when idle will cause the device to "miss" the first character or two from the serial console (and most likely all UARTS). Since the UART is asleep, a character must be sent to wake it up. This character will be missed as well as subsequent characters until the UART is fully awake.

DVFS

Dynamic frequency and voltage scaling dynamically reduces clock frequency and voltage for further power savings. You must be running the PM kernel for DVFS functionality.

Note: DVFS may not work with the 2.6.39 PM kernel. DVFS was going through a rewrite and may not be stable enough to be used.

The cpufreq utils and daemon are needed to enable and configure DVFS. Use bitbake to manually build cpufreqd and cpufrequtils.

$ bitbake cpufreqd
$ bitbake cpufrequtils

Note: You can also copy the omap3-console-image.bb recipe over to your user.collection and add cpufreqd and cpufrequtils to the recipe. Doing so will automatically include the cpufreqd and cpufrequtils in your image.

Once the cpufreqd and cpufrequtils are built, you can build your image as normal, or you can simply copy the ipk files to your SD card and install them.

$ cp tmp/deploy/glibc/ipk/armv7a/cpufreqd_* tmp/deploy/glib/ipk/armv7a/cpufrequtils_* /media/SD_CARD/home/root/

To install, run the following command from your Overo COM:

# opkg install /home/root/cpufreq*.ipk

You may see some errors about a "hicolor-icon-theme" which can be ignored.

Now that you have cpufreq tools setup, run cpufreq-info and you will see output describing the cpu frequency modes for your cpu.

root@overo:~#cpufreq-info
cpufrequtils 006: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: omap
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.00 ms.
  hardware limits: 125 MHz - 600 MHz
  available frequency steps: 600 MHz, 550 MHz, 500 MHz, 250 MHz, 125 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 125 MHz and 600 MHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz (asserted by call to hardware).
  cpufreq stats: 600 MHz:100.00%, 550 MHz:0.00%, 500 MHz:0.00%, 250 MHz:0.00%, 125 MHz:0.00%  (1)

As you can see from the cpufreq stats line, we have run at full speed 600 MHz for 100% of the time. In order to reduce cpu frequency automatically, we have to change to a different "governor". For example, switching to the powersave governor will limit cpu frequency to between 0% and 33% of max speed.

root@overo:~# cpufreq-set -g powersave
root@overo:~# cpufreq-info
cpufrequtils 006: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: omap
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.00 ms.
  hardware limits: 125 MHz - 600 MHz
  available frequency steps: 600 MHz, 550 MHz, 500 MHz, 250 MHz, 125 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 125 MHz and 600 MHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 125 MHz (asserted by call to hardware).
  cpufreq stats: 600 MHz:86.17%, 550 MHz:0.00%, 500 MHz:0.00%, 250 MHz:0.00%, 125 MHz:13.83%  (2)

The cpufreq daemon automatically switches governors based on rules defined in

/etc/cpufreqd.conf

TODO: Examine how to use cpufreqd to manage the active governor.

Disable Internal Devices

The internal peripherals and devices such as the DSP and GPU consume power if not being used. All unused peripherals, DSP, and GPU should be turned off.

Note: All peripherals, DSP, and GPU are turned off when sleep while idle and off mode are enabled. Turning off peripherals, will only reduce power while the Gumstix is awake and processing, it won't allow for a lower power draw while sleeping.

Turn Off Peripherals

TBD

Turn Off DSP

This section applies only to the OMAP3530-based Overo COMs, as the OMAP3530 has both a DSP and Graphics engine.

TBD

Turn Off GPU

This section applies only to the OMAP3530-based Overo COMs, as the OMAP3530 has both a DSP and Graphics engine.

TBD

Disable External Chipsets

Several external chipsets on the Gumstix COM consume power even if not being used. Their power consumption can be reduced (although not completely eliminated) by holding the chips in reset.

USB

If you're running the Custom PM Kernel listed above, the kernel is already patched to disable power to USB. Otherwise, you can hold the USB chip in reset with the following commands:

$ echo 183 > /sys/class/gpio/export
$ echo out > /sys/class/gpio/gpio183/direction
$ echo 0 > /sys/class/gpio/gpio183/value 

These commands will export GPIO 183 for access through the sys interface, set the GPIO to output, and drive "0" to the reset line on the USB chip.

You can also turn off power to the USB chip.

If someone wanted to try the same nasty kernel hack, I added this two lines:
       twl_i2c_write_u8(TWL4030_MODULE_USB, 0x08 /* value */, 0xBB /* register (CARKIT_ANA_CTRL) */);
       twl_i2c_write_u8(TWL4030_MODULE_USB, 0x01 /* value */, 0xFD /*register (PHY_PWR_CTRL) */);
in the function "twl_probe" in /drivers/mfd/twl-core.c just prior to the comment "load power event scripts".

Disable Wifi

To disable Wifi

$ echo 0 > /sys/class/gpio/gpio16/value 

This will hold the Wifi chip in reset and reduce its power consumption to the absolute minimum. However, once disabled, you can't reenable the chip without powering down the gumstix.

If you wish to disable and enable the Wifi without powering off the gumstix, you'll have to use rfkill. Rfkill will do a software power down of the Wifi radio. The defconfig included with the PM recipe above will enable rfkill in the pm kernel. You can verify rfkill is setup and working as you should see /dev/rfkill on the gumstix.

$ bitbake rfkill

Will build rfkill, after which you can copy the binary over to your gumstix.

To disable the wifi using rfkill simply execute

$ rfkill block wlan

To bring it back up run

$ rfkill unblock wlan

Disable Bluetooth

To disable bluetooth

$ echo 0 > /sys/class/gpio/gpio164/value

This will hold the bluetooth in reset.

TBD: Does rfkill work for bluetooth???

Disable LEDs

The on-board blue LED can be disabled with the following commands.

$ echo 211 > /sys/class/gpio/export
$ echo out > /sys/class/gpio/gpio211/direction
$ echo 1 > /sys/class/gpio/gpio211/value 

Note: You must be running the 2.6.39 PM kernel to have access to GPIO 211.

Legacy PM Kernels

The instructions here are for legacy PM kernels. These should no longer be used since Steve Sakoman has provided a 2.6.39 PM kernel for gumstix.


There are three methods for compiling a PM kernel.

  • Use the PM recipe included with the current OpenEmbedded build.
  • Use a custom recipe with the latest PM kernel and patches for Overo COM's
  • Perform a manual build with CodeSourcery


OpenEmbedded PM Kernel

NOTE: The linux-omap-pm bitbake recipe is setup to use the 2.6.29 PM kernel. For a newer PM kernel with better power savings, see the next method.

To enable the PM kernel edit the file

org.openembedded.dev/conf/machine/overo.conf

and change the line

PREFERRED_PROVIDER_virtual/kernel = "linux-omap3"

to

PREFERRED_PROVIDER_virtual/kernel = "linux-omap-pm"

Save the changes and then run bitbake as usual e.g.

$ bitbake omap3-console-image

The pm branch will be downloaded and compiled.

Once you have the PM kernel built, follow the instructions for copying the new image and filesystem to your microSD card.

Custom PM Kernel

The "custom" PM kernel described here uses the 2.6.38-rc? PM kernel which at the time of this writing offers the best power saving features.

First download the custom PM recipes from here and extract the archive to your over-oe directory.

Note: If you have an existing user.collection in your overo-oe directory, you may want to back it up before extracting this archive.

Bitbake the new kernel and make sure it builds correctly.

Note: If you plan to use USB, then you will need to comment out the usb_off patch in the linux-omap-pm_2.6.38.bb recipe.

$ bitbake -b user.collection/recipes/linux/linux-omap-pm_2.6.38.bb

Or simply run

$ bitbake virtual/kernel

and bitbake should use the new linux-omap-pm_2.6.38.bb recipe automatically.

You may get an error saying it can't download the tar archive but it should fallback to pulling the source using git. This step will take a while since the pm git is over 400 MB.

If the kernel builds fine, you can build your image normally.

$ bitbake omap3-console-image

Once you install the new build to your micro sd card, you need to make changes for the new kernel. The new kernel uses ttyO2 as the serial port instead of ttyS2. To make the changes,cd to the Gumstix os partition on your micro sd, and do the following:

  • Edit <path to mcirosd rootfs>/etc/inittab and change ttyS2 to ttyO2
  • Make a "node" in dev for ttyO2
$ mknod -m 660 <path to mcirosd rootfs>/dev/ttyO2 c 4 66
  • On bootup, execute these commands from the uboot command line (assumes your uboot and xload are setup previously)
mmc init
setenv console ttyO2,115200n8
saveenv (run only if you want to save the new console setting)
run loaduimage
run mmcboot

You should now boot into your new kernel. Follow the instructions in the sections below to use PM features.

NOTE: Some things have changed in the sections below for the new kernel such as the path to set the serial timeout. Its now

/sys/devices/platform/omap/omap_uart.#/sleep_timeout

PM Kernel Alternate CodeSourcery Method

If you do not already have an openembedded build setup, then follow these step taken from Peter Lawrence on the Gumstix mailing list.

NOTE: As per the comments below, this method disables nand and microSD access. Use the Custom PM method above for best results.


Here are steps to build the kernel "the traditional way".

1) Download and install cross-compiler tools:

The easiest solution is to download the CodeSourcery binaries:

http://www.codesourcery.com/sgpp/lite/arm

CodeSourcery provides an install program.  (You'll have to set the 
executable bit on the file to run it.)

Note that the CodeSourcery install modifies .bash_profile to add the
path, but this file does not run automatically in Ubuntu.  To fix
this, refer to:

http://www.linuxquestions.org/questions/linux-general-1/do-i-put-path-in-bash_profile-or-bashrc-or-both-540288/

which says:

"You can change the second by opening a gnome-terminal window and
going to Edit / Profiles - select the Default profile and click the
Edit button. On the Title and Command tab, click the check box for Run
command as a login shell. Your .bash_profile file should be sourced
the next time you open a gnome-terminal."

2) Get latest Linux OMAP PM code

"git" the latest code:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-omap-pm.git;branch=pm

The result will be in the subdirectory "linux-omap-pm".

3) Build the OMAP3_PM Linux Kernel

Extract the download Linux kernel code and cd to that directory.  The
command sequence is:

export ARCH=arm
make omap3_pm_defconfig

Update: The omap3_pm_defconfig is no longer available. Use omap2plus_defconfig instead.

This creates a .config file suitable for Linux OMAP3 PM.

TBD: patch the .config file for JFFS2 and SD card

export CROSS_COMPILE=arm-none-eabi-
make uImage [this takes a very long while]

The resultant kernel file will be in: ./arch/arm/boot/uImage

4) Download the initramfs filesystem

Obtain "rd-ext2-8M.bin" from:

http://code.google.com/p/beagleboard/downloads/list

5) Create a bootable MicroSD card

Follow the [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html instructions here].

However, one can omit the "MLO" and the "u-boot.bin" files.

One should, however, copy over the "uImage" file created in step #3,
and the "rd-ext2-8M.bin" (as "rd-ext2.bin") created in step #4.

6) Boot the Overo

Use the "Press any key" prompt at boot to operate the U-Boot app.

Enter the following commands: (these commands must be done individually,
as U-Boot does not have a large enough buffer for the entire quantity
to be pasted at once)

mmc init
fatload mmc 1:1 0x80300000 uImage.pm
fatload mmc 1:1 0x81600000 rd-ext2-8M.bin
setenv bootargs console=ttyO2,115200n8 ramdisk_size=8192 root=/dev/ram0 rw rootfstype=ext2 initrd=0x81600000,8M
bootm 0x80300000

 TBD: change u-boot parameters to perform this automatically

 Linux should boot to a BusyBox console prompt.
 

This category currently contains no pages or media.