Article title: transmit information to LinuxThinkPad through vibration. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
January 15, 2007
By modifying the kernel to automatically reset the Linux laptop in case of kernel emergency caused by a vibration, your computer is protected. Implement the vibration detection algorithm in the kernel space and user space, so as to execute automatic shutdown and restart when the specific dynamic conditions are met.
2003, IBM®Began to sell ThinkPad laptops that integrate acceleration sensors and related software in commercial operating systems to protect hard disks when ThinkPad falls to the ground. Powerful computer programmers from IBM and elsewhere have developed modules that utilize these sensors for the Linux kernel. The screen display direction, desktop switch, game control, real-time 3D model, and other features of a laptop have been achieved.
In the middle of 2006, percussion-based commands for Linux laptops began to be used in user space Perl scripts (compared with C-based code in kernel space ), allows you to run random commands based on a specific strike sequence. This article describes how to modify the Linux kernel to add frequently needed features: provide feedback on physical input. When the Linux kernel is in an emergency, the user can shake the computer (or execute the physical movement that a developer can configure on the laptop) and the computer will be reset.
This document also describes how to disable the function normally in non-emergency mode. For example, if you do not pay attention to placing your computer in a computing environment that has not yet been pulled, you need the computer to detect normal walking or driving operations and shut down the computer.
Prerequisites
Hardware
Many IBM ThinkPad manufactured after 2003 (including 2003) are equipped with HDAPS hardware. If you cannot determine the hardware configuration, go to Lenovo's Web site to view detailed technical information. To run the following code, you must have ThinkPad. Some macOS are equipped with an accelerometer and a common method to access these sensors through the kernel. However, the code here is not tested on Apple hardware, but developed and tested based on two IBM ThinkPad T42p models. For links to how to find ThinkPad hardware that is physically required to support laptops, see references.
Software
This document assumes that you are familiar with the kernel build process and understand the inconsistency between releases caused by kernel compilation. For an introduction to the kernel build process and some excellent entry-level examples, see references.
From kernel V2.6.15, the HDAPS driver has been included in the Linux kernel. For simplicity, obtain the latest kernel program. This article is based on Fedora Core V5 for ease of development and management. The following provides guidance for setting the kernel build environment specifically for Fedora Core, but the general principle applies to all Linux distributions.
Kernel development settings
Kernel configuration, compilation, and testing
To modify the kernel, follow the instructions in version information. Open the Web browser and follow the instructions in Section 8.6: "Preparing for Kernel Development. When Part 1 is executed, problems may occur when executing the second command su-c 'yumdownloader -- source kernel. If this command fails to download the kernel-2.6.15-1.2054_FC5.src.rpm package, use the wget command wget ftp://ftp.linux.ncsu.edu/pub/fedora/linux/core/5/source/SRPMS/kernel-2.6.15-1.2054_FC5.src.rpm to get the package.
When performing step 5, use the cp configs/kernel-2.6.15-i686.config. config command to select the basic i686 default configuration. Make sure to change the EXTRAVERSION part of makefile from-prep to-1.2054_FC5. Use make oldconfig to update the build configuration. Run the su-c "yum install kernel-devel" command to install the kernel development module. This module is used to compile the emergency trigger module.
We have now completed the kernel configuration section described in the Fedora Core V5 Release Notes document. The remaining steps are common standard steps for all kernel build processes. We recommend that you build and install new kernel, module, and RAM disk settings to ensure that everything runs as expected. If you are confident in your new kernel configuration, skip the following steps and directly go to the kernel modification section.
Use the make command to build a new kernel. After the kernel is built, run the su-c "cp./arch/i386/boot/bzImage/boot/vmlinuz-2.6.15hdaps" command to copy it to the/boot directory. You need to use the su-c "make modules_install" command to build the module. The last building step is to use the su-c "/sbin/mkinitrd hdapsInitrd. img 2.6.15-1.2054_FC5" command to create a RAM disk for the HDAPS kernel. Run the su-c "cp hdapsInitrd. img/boot/" command to copy the new RAM disk to the boot area. During boot, it is used to update the grub. conf file downstream:
Listing 1. grub configuration
title Fedora Core (2.6.15hdaps) root (hd0,0) kernel /vmlinuz-2.6.15hdaps ro root=/dev/VolGroup00/LogVol00 rhgb quiet initrd /hdapsInitrd.img
|
Modify panic. c and hdaps. c
Now you are ready to start some kernel configurations that can be completed quickly. Make sure to be in ~ /Rpmbuild/BUILD/kernel-2.6.15/linux-2.6.15.i686 directory. Be sure to include the hdaps module as the built-in component of the kernel, so that it is ready to provide vibration checks for various places in the computer running mode.
Run the make menuconfig command and select Device Drivers> Hardware Monitoring Support. Type Y to include the Hardware Monitoring Support module because the HDAPS module depends on this module. Scroll to the bottom of the list and type Y again next to the IBM Hard Drive Active Protection System (hdaps) entry. Exit the menu and save the configuration.
Open the drivers/hwmon/hdaps. c file and add the following text to the include section: # include . Next to the hdaps_read_pair subroutine, add the following new subroutine:
List 2. complete panicShake subroutine from hdaps. c
/* * panicShake - reboot the machine if shaken */ extern void panicShake(void){ int ret, x, y; // return value and x,y from hdaps int int baseX = -5000; // off scale default values int baseY = -5000; int totalDev = 0; // running total of deviations from rest (shaking total) int devThreshold = 4000; // larger threshold for more shaking int dimShiftX = 150; // in case your users shake more in a certain dimension int dimShiftY = 150; while(1) { ret = hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y); if (!ret) { if( x != 0 && y != 0 ) { // if its a successful read and not a zero read if( baseX == -5000 ) { baseX = x; baseY = y; } if( abs(baseX - x) > dimShiftX || abs(baseY - y) > dimShiftY ) { totalDev += abs(baseX - x); totalDev += abs(baseY - y); } if( totalDev > devThreshold ) { printk(KERN_EMERG "ok, ok! you're shaking my substrate - restarting"); emergency_restart(); } }//if not a zero value }//if successful read of hdaps data }//infinite while }//panicShake
|
After the vibration detection program is ready, it must be called in an emergency. Open the kernel/panic. c file, and place a call to the panicShake (); subroutine near the position next to the panicBlink condition. Issue the make command. When re-constructing the kernel, let's review the vibration detection code. First, set some variables:
Listing 3. panicShake variable
int ret, x, y; // return value and x,y from hdaps int baseX = -5000; // off scale default values int baseY = -5000; int totalDev = 0; // running total of deviations from rest (shaking total) int devThreshold = 4000; // larger threshold for more shaking int dimShiftX = 150; // in case your users shake more in a certain dimension int dimShiftY = 150; |
[1] [2] [3] Next page