linux kernel/android debug notes
7233 ワード
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 set CONFIG_APANIC_PLABEL to 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 //cache pronounce [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 using linux-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
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.
4 The single module compilation for android 4.2.2
first look up the Android.mk to get module name.
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 set CONFIG_APANIC_PLABEL to 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 //cache pronounce [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 using linux-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, // 644
read_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 data
struct msm_fb_data_type *mfd;
struct fb_info *fbi = dev_get_drvdata(dev); // get private data
mfd = (struct msm_fb_data_type *) fbi->par; // get mfd
id = id; // some devices' id
name = "a device's name";
len = strlen(name) + 1;
strncpy(buf, name, len); // Or use the function of snprintf
return 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