1 Read panic information

Question: How to save kernel panic information? What is apanic and how to enable apanic?

Answer:
apanic is a panic handler that google added to implement feature that when linux kernel panic, the console message and call stack can be saved to flash.
apanic implemention file is at drivers/misc/apanic.c

To enable apanic:
1.define a partition on nand flash
2.enable CONFIG_APANIC and setCONFIG_APANIC_PLABELto the partition name you add, the default name is "kpanic"

apanic will register mtd partition notifier and it will use mtd_info mtd->read, mtd->write and mtd->panic_write.
Qualcomm's flash driver is at drivers/flash/devices/msm_nand.c
currently, there is no panic_write implementation.
So OEM need to add it in msm_nand_scan().
Without panic_write, if panic happen in irq context, then the panic information can not be saved.
As it is in interrupt context, so on panic_write, there shall not call any api that could schedule out, can not use DMA/DMOV.

When APANIC is enabled, when panic happen, apanic handler will save kernel dmesg log and all process's call stack to the "kpanic" partition.
When reboot, the apanic init will detect there is panic info in the partition, and it will expose the information by

/proc/apanic_console

/proc/apanic_threads

in init.rc (system/core/rootdir/init.c)

it will save them to

/data/dontpanic/apanic_console

/data/dontpanic/apanic_threads

then clear the partition by write 1 to /proc/apanic_console


For emmc device, current framework does not support, but it is not difficult to add this feature,also need a read/write/panic_write for emmc device.



root@android:/dev/block/platform/msm_sdcc.1/by-name # ll
lrwxrwxrwx root root 1970-01-08 08:01 aboot -> /dev/block/mmcblk0p5
lrwxrwxrwx root root 1970-01-08 08:01 auto -> /dev/block/mmcblk0p20
lrwxrwxrwx root root 1970-01-08 08:01 boot -> /dev/block/mmcblk0p7
lrwxrwxrwx root root 1970-01-08 08:01 cache -> /dev/block/mmcblk0p15 // cachepronounce
[kæʃ]
lrwxrwxrwx root root 1970-01-08 08:01 fsg -> /dev/block/mmcblk0p19
lrwxrwxrwx root root 1970-01-08 08:01 grow -> /dev/block/mmcblk0p24
lrwxrwxrwx root root 1970-01-08 08:01 kpanic -> /dev/block/mmcblk0p22
lrwxrwxrwx root root 1970-01-08 08:01 misc -> /dev/block/mmcblk0p17
lrwxrwxrwx root root 1970-01-08 08:01 modem -> /dev/block/mmcblk0p1
lrwxrwxrwx root root 1970-01-08 08:01 modemst1 -> /dev/block/mmcblk0p10
lrwxrwxrwx root root 1970-01-08 08:01 modemst2 -> /dev/block/mmcblk0p11
lrwxrwxrwx root root 1970-01-08 08:01 params -> /dev/block/mmcblk0p21
lrwxrwxrwx root root 1970-01-08 08:01 persist -> /dev/block/mmcblk0p14
lrwxrwxrwx root root 1970-01-08 08:01 recovery -> /dev/block/mmcblk0p18
lrwxrwxrwx root root 1970-01-08 08:01 rpm -> /dev/block/mmcblk0p6
lrwxrwxrwx root root 1970-01-08 08:01 sbl1 -> /dev/block/mmcblk0p2
lrwxrwxrwx root root 1970-01-08 08:01 sbl2 -> /dev/block/mmcblk0p3
lrwxrwxrwx root root 1970-01-08 08:01 sbl3 -> /dev/block/mmcblk0p4
lrwxrwxrwx root root 1970-01-08 08:01 ssd -> /dev/block/mmcblk0p23
lrwxrwxrwx root root 1970-01-08 08:01 system -> /dev/block/mmcblk0p12
lrwxrwxrwx root root 1970-01-08 08:01 tombstones -> /dev/block/mmcblk0p16
lrwxrwxrwx root root 1970-01-08 08:01 tz -> /dev/block/mmcblk0p8
lrwxrwxrwx root root 1970-01-08 08:01 userdata -> /dev/block/mmcblk0p13


root@android:/dev/block/platform/msm_sdcc.1 # cat /proc/partitions
cat /proc/partitions
major minor #blocks name


179 0 7634944 mmcblk0
179 1 65536 mmcblk0p1
179 2 512 mmcblk0p2
179 3 1536 mmcblk0p3
179 4 2048 mmcblk0p4
179 5 2560 mmcblk0p5
179 6 512 mmcblk0p6
179 7 10240 mmcblk0p7
179 8 512 mmcblk0p8
179 9 2560 mmcblk0p9
179 10 3072 mmcblk0p10
179 11 3072 mmcblk0p11
179 12 819200 mmcblk0p12 system
179 13 6459375 mmcblk0p13 userdata
179 14 20480 mmcblk0p14
179 15 184320 mmcblk0p15
179 16 10240 mmcblk0p16
179 17 1024 mmcblk0p17
179 18 10240 mmcblk0p18
179 19 3072 mmcblk0p19
179 20 10240 mmcblk0p20
179 21 4096 mmcblk0p21
179 22 4096 mmcblk0p22
179 23 8 mmcblk0p23
179 24 4071 mmcblk0p24


2 qualcomm kernel dump panic information

2.1 usinglinux-ramdump-parser-v2.2013JAN15

#python ramparse.py --vmlinux .../obj/KERNEL_OBJ/vmlinux --auto-dump ../dump/to_dump_files/ --everything


3 notes for using container_of and adding devices' attribution

static DEVICE_ATTR(name4userspace, S_IRUGO | S_IWUSR | S_IWGRP, // 644read_name_of_a_device, write_a_function);static struct attribute *fs_attrs[] = {&dev_attr_name4userspace.attr,NULL,}static struct attribute_group fs_attr_group = {.attrs = fs_attrs,};rc = sysfs_create_group(&mfd->fbi->dev->kobj, &fs_attr_group);

Remember the following rules for using the function of container_of
container_of(pointer, container's type, container's member);
The above macro needs a pointer which points to container's member which is in the corresponding structure including container's type.
/** * container_of - cast a member of a structure out to the containing structure * @ptr:the pointer to the member. * @type:the type of the container struct this is embedded in. * @member:the name of the member within the struct. * */#define container_of(ptr, type, member) ({\const typeof( ((type *)0)->member ) *__mptr = (ptr);\(type *)( (char *)__mptr - offsetof(type,member) );})


static ssize_t read_name_of_some_device(struct device *dev,struct device_attribute *attr, char *buf){int id, len;char *name;//struct platform_device *pdev;//pdev = container_of(dev, struct platform_device, dev); // the device must be exactly in platform_device!!//mfd = platform_get_drvdata(pdev); // get private datastruct msm_fb_data_type *mfd;struct fb_info *fbi = dev_get_drvdata(dev); // get private datamfd = (struct msm_fb_data_type *) fbi->par; // get mfdid = id; // some devices' idname = "a device's name";len = strlen(name) + 1;strncpy(buf, name, len); // Or use the function of snprintfreturn len; // returned value should have length, otherwise the command "cat" can't read the file}


4 The single module compilation for android 4.2.2

first look up the Android.mk to get module name.
# make hwcomposer.msm8930


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 2011.11.22——— android jni简单用法
  2. Android之蓝牙设备使用
  3. Android(安卓)打开浏览器的几种方法
  4. Android(安卓)获取包名,版本信息
  5. ADT下载地址整理
  6. Android下Notification(通知栏)的使用
  7. Android(安卓)ListView简单实用
  8. Android之圆角矩形
  9. Android(安卓)ListView(Selector 颜色)
  10. Android(安卓)app版本号的修改