[RAZR i Android Development] hotpokets:
rm -rf libsensorhub
git clone git@shsrv888.sh.intel.com:libsensorhub.git ./libsensorhub
rm -rf psh_fw
git clone git@shsrv888.sh.intel.com:psh_fw.git ./psh_fw
rm -rf sensor-hal
git clone git@shsrv888.sh.intel.com:sensor-hal.git ./sensor-hal

一：安装环境：
1.编辑Makefile,路径：/sourcecode/hardware/intel/linux-2.6/drivers/hwmon$
去掉原有驱动，找到Makefile把4行注释掉：
#obj-$(CONFIG_SENSORS_LTR502ALS) += ltr502als.o
#obj-$(CONFIG_SENSORS_LIS3DH_ACC) += lis3dh_acc.o
#obj-$(CONFIG_SENSORS_HMC5883) += hmc5883.o
#obj-$(CONFIG_SENSORS_MPU3050) += mpu3050.o
【/ice2/hardware/intel/linux-2.6/drivers/hwmon$ gedit Makefile】

2.编辑启动模块，增加：~/sourcecode/vendor/intel/mfld_pr2$ gedit init.mfld_pr2.rc
#自动加载驱动
on init
export PATH /system/sbin:/system/bin:/system/xbin:/sbin:/vendor/bin
insmod /data/psh_sc.ko

# adding sensorhubd开机自动启动sensorhubd
service sensorhubd /system/bin/sensorhubd --log-level=2
class main
group system
oneshot

3.重烧内核
A：源码编译boot
1.shenlin@linx:~/ice2$ . build/envsetup.sh
2.shenlin@linx:~/ice2$ lunch
3.Which would you like? [full-eng] 11

4.shenlin@linx:~/ice2$ make bootimage -j8

#4.shenlin@linx:~/ice2$ make boottarball -j8

B：BOOT：
adb reboot-bootloader
fastboot flash boot out/target/product/mfld_pr2/boot.bin
fastboot reboot

4.编译3个文件：
4.1 编译：libsensorhub
shenlin@linx:~/ice2$ . build/envsetup.sh
shenlin@linx:~/ice2$ lunch
11
shenlin@linx:~/ice2$ cd ..
shenlin@linx:~$ cd psh
shenlin@linx:~/psh$ ls
libsensorhub psh_fw sensor-hal
shenlin@linx:~/psh$ cd libsensorhub/
shenlin@linx:~/psh/libsensorhub$ mm
生成文件：out/target/product/mfld_pr2/obj/lib/libsensorhub.so
4.2 编译：psh_pw
首先修改Makefile 文件：
A：修改路径为ice源码路径：
BUILD_DIR=$(PWD)/out
KERNELDIR=~/ice2/out/target/product/mfld_pr2/kernel_build
B：增加代码覆盖语句（GCOV_PROFILE := y）：
# to build kernel module
else
obj-m += psh_sc.o
GCOV_PROFILE := y
C:增加：
/home/shenlin/ice2/hardware/intel/linux-2.6/arch/x86/configs/i386_mfld_defconfig
CONFIG_DEBUG_FS=y
CONFIG_GCOV_KERNEL=y
C：编译命令：
shenlin@linx:~/psh/psh_fw$ make module
生成文件：
shenlin@linx:~/psh/psh_fw$ adb push psh_sc.ko /data/

4.3编译sensor-hal：
shenlin@linx:~/psh/sensor-hal$ mm
生成文件：out/target/product/mfld_pr2/system/lib/hw/sensors.mfld_pr2.so

5.push第四步产生的文件至手机目录：
1.adb remout 使系统目录可写
2.push 2个文件：
A：
shenlin@linx:~/ice2/out/target/product/mfld_pr2/obj/lib$ adb push libsensorhub.so system/lib
B：
shenlin@linx:~/psh/libsensorhub$ adb push /home/shenlin/ice2/out/target/product/mfld_pr2/system/bin/sensorhubd /system/bin
3.进入PSH-FW目录：shenlin@linx:~/psh/psh_fw$ adb push psh_sc.ko data/
4.push sensors.mfld_pr2.so:
home/shenlin/ice2/out/target/product/mfld_pr2/system/lib/hw/sensors.mfld_pr2.so /system/lib/hw
『
1.
adb push /home/shenlin/sourcecode/out/target/product/mfld_pr2/obj/lib/libsensorhub.so /system/lib
2.
adb push /home/shenlin/sourcecode/out/target/product/mfld_pr2/system/bin/sensorhubd /system/bin
3.
adb push /home/shenlin/psh/psh_fw/psh_sc.ko /data/
4.
adb push /home/shenlin/sourcecode/out/target/product/mfld_pr2/system/lib/hw/sensors.mfld_pr2.so /system/lib/hw
』

adb remount
adb push /home/shenlin/ww25/out/target/product/mfld_pr2/obj/lib/libsensorhub.so /system/lib
adb push /home/shenlin/ww25/out/target/product/mfld_pr2/system/bin/sensorhubd /system/bin
adb push /home/shenlin/sensor/psh_fw/psh_sc.ko /data/
adb push /home/shenlin/ww25/out/target/product/mfld_pr2/system/lib/hw/sensors.mfld_pr2.so /system/lib/hw
adb push /home/shenlin/ww25/out/target/product/mfld_pr2/system/lib/libsensorservice.so /system/lib/
adb reboot

5.重启手机：adb reboot

6.确定驱动正常：
1.安装：shenlin@linx:~/take-over$
adb install com.miian.android.sensors-1.apk
adb install GyroRotate.apk
adb install opengl_es.exionfly-1.apk
adb install org.jtb.modelview-1.apk

2.adb shell
3.lsmod,可看到PSH节点：
root@android:/ # lsmod
atomisp 374417 0 - Live 0xf9b41000
lm3554 12405 1 - Live 0xf8069000
mt9m114 41077 1 - Live 0xf851a000
mt9e013 28789 1 - Live 0xf8511000
videobuf_vmalloc 12453 1 atomisp, Live 0xf8033000
videobuf_core 21336 2 atomisp,videobuf_vmalloc, Live 0xf84e1000
btwilink 12366 1 - Live 0xf8058000
st_drv 25655 1 btwilink, Live 0xf84b4000
psh_sc 198656 0 - Live 0xf8601000

二 测试：
1. 杀掉进程：root@android:/ # pkill sensorhubd

2.编译测试cat:resp_cat:
shenlin@linx:~/psh/psh_fw/test_cases/src/resp_cat$ make
shenlin@linx:~/psh/psh_fw/test_cases/src/resp_cat$ adb push resp_cat /data/

3. 打开另外一个窗口,在手机里运行resp_cat:
127|root@android:/data # ./resp_cat

4.进入手机/sys/class/hwmon/hwmon1/device目录，执行echo：
root@android:/sys/class/hwmon/hwmon1/device # ls

root@android:/sys/kernel/debug/gcov # ls

三、代码覆盖

1: mount -t debugfs none /sys/kernel/debug

1. 同步所有cases,使用sync：
shenlin@linx:~/psh/psh_fw/test_cases$ ./tools/sync

2.
adb reboot
adb shell
cd /sys/kernel/debug/gcov
root@android:/sys/kernel/debug/gcov # ls
home
reset
pkill sensorhubd
cd data/test
root@android:/data/test # ls
cases
helper

root@android:/data/test #for i in $(find cases -type f)
> do
> $i
> done

cd take-over/
adb push gather_gcov /sdcard/
./pull_gcov 收集手机测试文件
mv gcov.tar /tmp
cd /tmp
tar xf gcov.tar
cd ..
lcov -c -d sys -o psh.info
mkdir gcov
mv psh.info gcov
cd gcov/3
genhtml psh.info

===========
shenlin@linx:~/psh/psh_fw$ ctags -R

vi
:tag cmd_handlers (cmd)
1:echo 0 5 0 1 0 1 1 3 100 0 0 0 150 0 0 0 > control
2:echo 0 5 0 2 0 1 1 1 100 0 0 0 0 0 0 0 1 1 2 150 0 0 0 0 0 0 0 > control

==================
event_notification
1.编译libisensorhub后的event_notification:src/tests/event_notification.c
ice2/out/target/product/mfld_pr2/system/bin$
2.push编译后的文件至手机目录： system/bin
3.执行脚本测试：
shenlin@linx:~/psh/libsensorhub$ src/tests/event.py
accel x > 100
ctrl + D 执行
===================

root@android:/ # echo 0 2 7 > /sys/class/hwmon/hwmon1/device/control

==================
/sensorhub_client -c1 -t13 -r10 -d0

psh_fw/sensor_core/abstract

void get_AGM_angles_fixed(fix16_t *_phi, fix16_t *_theta, fix16_t *_psi)
{
if(_phi != NULL && _theta != NULL && _psi != NULL)
{
*_phi = Yaw*57/65536;
if (*_phi<0)
*_phi+=360;
psh_fatal(MY_TYPE,"********************%d\n",*_phi);
*_theta = Pitch*57/65536;
*_psi = Roll*57/65536;
}
} /*get_AG
-----------------------------------------------------------
git am 0001-sensor-core-lock-mechanism-change.patch(文件)

git reset --hard 1c1bccdd610b48cb6a91f3481b090fc9bffbc6b3(要回复到的commit)
---------------------------------
安装dos2unix
sudo apt-get install tofrodos
make mfld_pr2

sourcecode/out/host/linux-x86/bin
~/sourcecode/out/host/linux-x86/bin$ ./monkeyrunner
查看sensorhub loC
adb shell
# tail -f /data/sensorhubd.log
--------------
C
# tail -f /data/sensorhubd.log

**********************************************************
shenlin@linx:~/gcov$ ./command.sh

-------------------------------------------------------
crash log:
adb pull /mnt/sdcard/data/logs/crashlog11
vi aplog.1_ANR_19820101002029
cat crashfile

cat /data/logs/history_event
grep psh_close_session -r *
cat crashfile
vi tombstone_04

===============================
9dof
root@android:/sys/class/hwmon/hwmon2/device # echo 0 3 105 10 0 0 0 0 > control

addr2line -e -f libc.so 0001173c 红色是你的目标库，绿色是你出问题的地址，看看#15这行

结果出现:??pthread_create

??:0

恩，好了问题应该出在这个函数中，认为大功告成了？我，呸，还早呢。这个只是告诉你函数入口，至于具体执行到这个函数的哪个地方挂了，还得再看。

c 找到了是哪个部分出了问题，下面就是开启显微镜，看看谁搞的东东。

使用objdump -S -D libc.so > deassmble_libc.txt 反汇编下你的动态连接库文件，并且将它写入一个文件中。

打开这个反汇编过后的重定向文件，在查询的时候输入1173c这个偏移地址，你会看到在茫茫人海中