1.格式化打印

v1
#define CHARGER_PRINT(fmt,arg...)          printk("<<-CHARGER_PRINT->> "fmt"\n",##arg)

v2 
#define CHARGER_PRINT(fmt,arg...)          printk("<<-CHARGER_PRINT====func=%s, line =%d  ->> "fmt"\n",__func__,__LINE__,##arg)

v3 添加控制开关
#define MYDEBUG_ON 1
#define CHARGER_PRINT(fmt,arg...)   do{\
                                         if(MYDEBUG_ON)\
                                          printk("<<-CHARGER_PRINT====func=%s, line =%d  ->> "fmt"\n",__func__,__LINE__,##arg);\
                                      }while(0)


2.查看所有的中断

—— 可以看到名字,中断发生的次数

		 中断发生次数  中断类型(gpio中断还是其他)      中断名字
314:          0  		qpnp-int  					usb-ocp
318:          4  		qpnp-int  					qpnp_adc_tm_high_interrupt
319:          5  		qpnp-int  					qpnp_adc_tm_low_interrupt
320:          0  		qpnp-int  					pm8110_tz
325:          0  		qpnp-int  					ocv_thr
326:          0  		qpnp-int  					sw_cc_thr
329:          0  		qpnp-int  					qpnp_rtc_alarm
330:          0   		msmgpio  					hall_sensor_irq
331:       1334   		msmgpio  					gt915l
335:          5   		msmgpio  					ap3426

3.uevent事件添加打印

kernel\lib\kobject_uevent.c
kobject_uevent_env

...
/* default keys */
	retval = add_uevent_var(env, "ACTION=%s", action_string);
	if (retval)
		goto exit;
	retval = add_uevent_var(env, "DEVPATH=%s", devpath);
	if (retval)
		goto exit;
	retval = add_uevent_var(env, "SUBSYSTEM=%s", subsystem);
	if (retval)
		goto exit;
		
// 添加uevent事件打印
printk("zch=====kobject_get_path DEVPATH =%s,ACTION=%s,SUBSYSTEM=%s",devpath,action_string, subsystem);
...

4.设备树中的 dev_get_platdata

设备树中并没有 platdata ,这个指针,

要么直接赋值:

pdev->dev.platform_data = pdata; 

要么调用

platform_device_add_data

和device tree没有关系。


  1. 启动过程

// arch\arm\mach-msm\board-8610.c

DT_MACHINE_START(MSM8610_DT, "Qualcomm MSM 8x10 / MSM 8x12 (Flattened Device Tree)")
	.map_io = msm_map_msm8610_io,
	.init_irq = msm_dt_init_irq,
	.init_machine = msm8610_init,
	.handle_irq = gic_handle_irq,
	.timer = &msm_dt_timer,
	.dt_compat = msm8610_dt_match,
	.restart = msm_restart,
	.reserve = msm8610_reserve,
	.init_very_early = msm8610_early_memory,
	.smp = &arm_smp_ops,
MACHINE_END


msm8610_init
	board_dt_populate             // board-dt.c
		of_platform_populate      // ★ 解析设备树

  1. 查看硬件信息

查看CPU信息:cat /proc/cpuinfo

查看内存信息:cat /proc/meminfo

查看USB设备:cat /proc/bus/usb/devices

查看键盘和鼠标:cat /proc/bus/input/devices

查看各分区使用情况:df

查看体系结构:busybox uname -a

查看中断信息:cat /proc/interrupts


7.看门狗 WDT (watch dog timer)

原理:不停喂狗,确保软件正常运行
涉及文件:drivers/watchdog/wtd.c
关键字:ping
结构:

struct watchdog_ops {
	struct module *owner;
	/* mandatory operations */
	int (*start)(struct watchdog_device *);
	int (*stop)(struct watchdog_device *);
	/* optional operations */
	int (*ping)(struct watchdog_device *);   //喂狗操作 The routine that sends a keepalive ping to the watchdog device.
	unsigned int (*status)(struct watchdog_device *);
	int (*set_timeout)(struct watchdog_device *, unsigned int);
	unsigned int (*get_timeleft)(struct watchdog_device *);
	void (*ref)(struct watchdog_device *);
	void (*unref)(struct watchdog_device *);
	long (*ioctl)(struct watchdog_device *, unsigned int, unsigned long);
};

8.查看usb控制器类型 uhci/ehci/xhci 1.0 2.0 3.0

cat /sys/bus/usb/devices/usb1/product
xHCI Host Controller


9.查看所有input 事件对应的event、name、键盘映射等详细信息

cat /proc/bus/input/devices

10.关闭 2.6内核的 lcd 光标, lcd console

这个办法就是: 

写一个哑巴函数,直接返回,形如: 
static int dummy_cursor(struct fb_info *info, struct fb_cursor *cursor) 
{ 
return 0; 
} 

然后给 struct fb_ops 的 .fb_cursor 成员传入这个哑巴函数的地址,形如: 

.fb_cursor = dummy_cursor, 

黑色小方块就不见了。

11.sdcard插拔打印


#1.kernel/vold/framwork sdcard插拔打印		

 KERNEL  : [70056.058716] mmc2: new high speed SDXC card at address 0007
 KERNEL  : [70056.069514] mmc2: calculated max. discard sectors 131072 for timeout 2684 ms
 KERNEL  : [70056.077736] mmcblk1: mmc2:0007 SD128 117 GiB 
 KERNEL  : [70056.094389]  mmcblk1: p1 p2

 ...
 KERNEL  : [ 1072.835709] mmc2: card 0007 removed



 vold    : /system/bin/sgdisk
 vold    :     --android-dump
 vold    :     /dev/block/vold/disk:179,80
 VoldConnector: RCV <- {640 disk:179,80 5}
 VoldConnector: RCV <- {641 disk:179,80 125652959232}
 VoldConnector: RCV <- {642 disk:179,80 }
 VoldConnector: RCV <- {644 disk:179,80 /sys//devices/pci0000:00/INT33BB:01/mmc_host/mmc2/mmc2:0007/block/mmcblk1}
 vold    : DISK gpt D9C01263-43A8-4E4D-8A84-88C4A2DBDA64
 vold    : PART 1 19A710A2-B3CA-11E4-B026-10604B889DCF CAC02517-91B0-4DC7-A034-B691B17C1BDC android_meta
 vold    : PART 2 193D1EA4-B3CA-11E4-B075-10604B889DCF ACBB35BB-C0D7-0437-7CB7-734CCA913C86 android_expand
 vold    : Found key for GUID acbb35bbc0d704377cb7734cca913c86
 
 vold    : Disk at 253:3 changed
 VoldConnector: RCV <- {650 private:179,82 1 "disk:179,80" "ACBB35BB-C0D7-0437-7CB7-734CCA913C86"}
 VoldConnector: RCV <- {651 private:179,82 0}
 VoldConnector: RCV <- {643 disk:179,80}
 VoldConnector: SND -> {42 volume mount private:179,82 0 -1}
 vold    : /system/bin/blkid
 vold    :     -c
 vold    :     /dev/null
 vold    :     -s
 vold    :     TYPE
 vold    :     -s
 vold    :     UUID
 vold    :     -s
 vold    :     LABEL
 vold    :     /dev/block/dm-3
 VoldConnector: RCV <- {651 private:179,82 1}




MountService: Volume public:179,64 broadcasting checking to UserHandle{0}
MountService: Volume public:179,64 broadcasting xxx      to   xxx 
 

 
 
 
 
 
 

#2. 开始格式化为fat32 ☆


 VoldConnector: SND -> {31 volume partition disk:179,64 public}
 vold    : /system/bin/sgdisk
 vold    :     --zap-all
 vold    :     /dev/block/vold/disk:179,64
 sgdisk  : GPT data structures destroyed! You may now partition the disk using fdisk or
 sgdisk  : other utilities.
 VoldConnector: RCV <- {200 31 Command succeeded}
 VoldConnector: NDC Command {31 volume partition disk:179,64 public} took too long (2554ms)
 vold    : Disk at 179:64 changed
 vold    : /system/bin/sgdisk
 vold    :     --android-dump
 vold    :     /dev/block/vold/disk:179,64
 VoldConnector: RCV <- {641 disk:179,64 15523119104}
 VoldConnector: RCV <- {642 disk:179,64 }
 VoldConnector: RCV <- {644 disk:179,64 /sys//devices/pci0000:00/INT33BB:01/mmc_host/mmc2/mmc2:0007/block/mmcblk1}
 vold    : DISK mbr
 vold    : PART 1 c
 vold    : Device just partitioned; silently formatting
 vold    : Failed to determine size of /dev/block/vold/public:179,65: Bad address
 vold    : public:179,65 failed to wipe
 vold    : /system/bin/newfs_msdos
 vold    :     -F
 vold    :     32
 vold    :     -O
 vold    :     android
 vold    :     -c
 vold    :     64
 vold    :     -A
 vold    :     /dev/block/vold/public:179,65
 Vold    : Filesystem formatted OK
 VoldConnector: RCV <- {650 public:179,65 0 "disk:179,64" ""}
 VoldConnector: RCV <- {651 public:179,65 0}
 VoldConnector: RCV <- {643 disk:179,64}
 VoldConnector: SND -> {32 volume mount public:179,65 2 0}
 vold    : /system/bin/blkid
 vold    :     -c
 vold    :     /dev/null
 vold    :     -s
 vold    :     TYPE
 vold    :     -s
 vold    :     UUID
 vold    :     -s
 vold    :     LABEL
 vold    :     /dev/block/vold/public:179,65
 VoldConnector: RCV <- {651 public:179,65 1}

11.sdcard 读写超时

由于各sdcard厂商生产的sdcard传输速率不同,可能会造成如下的现象,在如下代码位置中将timeout时间加大

/*(drivers/mmc/core/core.c)
	mmc_set_data_timeout


if (mmc_card_sd(card)) {
		unsigned int timeout_us, limit_us;

		timeout_us = data->timeout_ns / 1000;
		if (mmc_host_clk_rate(card->host))
			timeout_us += data->timeout_clks * 1000 /
				(mmc_host_clk_rate(card->host) / 1000);

// modify by zch for add read/write sdcard timeout value        
#if 0
		if (data->flags & MMC_DATA_WRITE)
			/*
			 * The MMC spec "It is strongly recommended
			 * for hosts to implement more than 500ms
			 * timeout value even if the card indicates
			 * the 250ms maximum busy length."  Even the
			 * previous value of 300ms is known to be
			 * insufficient for some cards.
			 */
			limit_us = 3000000;
		else
			limit_us = 100000;
#else
                    limit_us = 5000000;
#endif

(2)add timeout

sdhci.c中的sdhci_send_command()
// 打印如下log
KERNEL  : [ 5796.264938] mmcblk1: error -84 transferring data, sector 0, nr 8, cmd response 0x900, card status 0xb00


07-18 13:27:35.373     0     0 E KERNEL  : [ 2793.354386] mmc2: Timeout waiting for hardware interrupt.
07-18 13:27:35.379     0     0 E KERNEL  : [ 2793.360428] sdhci: =========== REGISTER DUMP (mmc2)===========
07-18 13:27:35.385     0     0 E KERNEL  : [ 2793.366945] sdhci: Sys addr: 0x00000100 | Version:  0x00001002
07-18 13:27:35.392     0     0 E KERNEL  : [ 2793.373461] sdhci: Blk size: 0x00007200 | Blk cnt:  0x00000100
07-18 13:27:35.398     0     0 E KERNEL  : [ 2793.379979] sdhci: Argument: 0x00000000 | Trn mode: 0x0000003b
07-18 13:27:35.405     0     0 E KERNEL  : [ 2793.386495] sdhci: Present:  0x01ff0001 | Host ctl: 0x00000016
07-18 13:27:35.411     0     0 E KERNEL  : [ 2793.393011] sdhci: Power:    0x0000000f | Blk gap:  0x00000080
07-18 13:27:35.418     0     0 E KERNEL  : [ 2793.399527] sdhci: Wake-up:  0x00000000 | Clock:    0x00000007
07-18 13:27:35.424     0     0 E KERNEL  : [ 2793.406044] sdhci: Timeout:  0x0000000a | Int stat: 0x00000000
07-18 13:27:35.431     0     0 E KERNEL  : [ 2793.412562] sdhci: Int enab: 0x02ff008b | Sig enab: 0x02ff008b
07-18 13:27:35.438     0     0 E KERNEL  : [ 2793.419078] sdhci: AC12 err: 0x00000000 | Slot int: 0x00000000
07-18 13:27:35.444     0     0 E KERNEL  : [ 2793.425596] sdhci: Caps:     0x0568c8b2 | Caps_1:   0x00000807
07-18 13:27:35.451     0     0 E KERNEL  : [ 2793.432113] sdhci: Cmd:      0x0000123a | Max curr: 0x00000000
07-18 13:27:35.457     0     0 E KERNEL  : [ 2793.438629] sdhci: Host ctl2: 0x0000008b
07-18 13:27:35.461     0     0 E KERNEL  : [ 2793.443009] sdhci: ADMA Err: 0x00000000 | ADMA Ptr: 0x7b85b800
07-18 13:27:35.468     0     0 E KERNEL  : [ 2793.449523] sdhci: ===========================================



12、 设置sdcard mmc控制器时钟

// (drivers/mmc/core/core.c)   
mmc_set_clock  	// 设置速率函数

13.打印内核调用关系

		 printk(KERN_ALERT "zch=========dump_stack start\n");
         dump_stack();
         printk(KERN_ALERT "zch=========dump_stack over\n");

14、内核中xxx、_xxx、__xxx、___xxx函数的使用情况

内核中经常有这样的函数,xxx、_xxx或者__xxx,区别是一个或者两个下划线,其中的含义是:
xxx接口,通常需要由某个锁保护,一般提供给其它模块调用。它会直接调用_xxx接口;
_xxx接口,则不需要保护,一般由模块内部在确保安全的情况下调用。有时,外部模块确信可行(不需要保护),也可能会直接调用;
__xxx接口,一般提供给arch-dependent的软件层实现,比如这里的arch/arm64/kernel/xxx.c。
理解这些含义后,会加快我们阅读代码的速度,另外,如果直接写代码,也尽量遵守这样的原则,以便使自己的代码更规范、更通用。

15、查看pmic寄存器值

cd /sys/kernel/debug/spmi/spmi-0
echo 0xA000> address
echo 0x27FF > count
cat data

16、qcom pmic mpp pwm参数配置



mpp@a300 {
	/* Backlight PWM */
	reg = <0xa300 0x100>;         
	qcom,pin-num = <4>;
	qcom,mode = <1>;		/* 模式选择:Digital output */
	qcom,invert = <0>;		/* Disable invert */
	qcom,src-sel = <5>;		/* 通道选择 DTEST1 4 DTEST2 5  */
	qcom,vin-sel = <2>;		/* 电压选择:设置了此选项一般为1.8v ,不设置为3.6v */
	qcom,ain-route = <3>;   /* AMUX 8 */
	qcom,master-en = <1>;	/* Enable MPP */
	};
	
	


----------


pm8953_pwm: pwm@bc00 {	
	status = "disabled";
	status = "okay";
	compatible = "qcom,qpnp-pwm";
	reg = <0xbc00 0x100>;
	reg-names = "qpnp-lpg-channel-base";
	qcom,channel-id = <0>;
	qcom,supported-sizes = <6>, <9>;
	#pwm-cells = <2>;
	qcom,mode-select = <0>;
	qcom,period = <100>;
	
	/*
	 indicates which DTEST line to be configured for LPG or PWM output. 
	 For LPG subtypes, possible values are 1, 2, 3 and 4.
	 For PWM subtype, possibe values are 1 and 2.*/ 
	*/
	qcom,dtest-line = <2>;		
	qcom,dtest-output = <2>;
	qcom,pwm {
		qcom,duty = <100>;
		label = "pwm";
	};



18.高通平台drv关机动作

//  /drivers/power/reset/msm-poweroff.c
void export_do_msm_poweroff(void)
{
	do_msm_poweroff();  // 关机
}


//使用 (qpnp-smbcharger.c)  
batt_pres_handler(int irq, void *_chip)
	if (chip->batt_present == 0)
			export_do_msm_poweroff();

  1. 反编译dtb文件成为dts文件



/data/QCT/A6090_LENOVO_code/out/target/product/hq_msm8953_64/obj/kernel/msm-3.18/dtc/dtc -I dtb -O dts -o my.dts  msm8953-qrd-sku3.dtb

20.触发dump

 adb shell echo c > /proc/sysrq-trigger

21.马达

pmi_haptic: qcom,haptic@c000 {
			compatible = "qcom,qpnp-haptic"

22.设备树


kernel/Documentation/devicetree/bindings/arm/msmboard-id.txt文件的解释如下:

  qcom,board-id = <board_id, reserved>
  
	where board_id is a 32-bit integer whosebit values are defined as follows:
   bits 31-24 = Platform Subtype ID			Platform Subtype ID=0x00=0
   bits 23-16 = Platform Version (Major)	Platform Version (Major)=0x12=18
   bits 15-8  = Platform Version(Minor)		Platform Version(Minor)=0x00=0
   bits  7-0  =Platform Type ID				Platform Type ID=0xb=11
   
这和串口打印信息是一致的:B-    390766 - CDT version:3,PlatformID:11,Major ID:18,Minor ID:0,Subtype:0

23 .dmesg 打印

1|ac8x_saic_zp:/ # dmesg -n 1
ac8x_saic_zp:/ #
ac8x_saic_zp:/ #
ac8x_saic_zp:/ # cat /proc/sys/kernel/printk
1 4 1 7
ac8x_saic_zp:/ # cat /proc/sys/kernel/printk
1 4 1 7
ac8x_saic_zp:/ #
ac8x_saic_zp:/ #
ac8x_saic_zp:/ # dmesg -n 8
ac8x_saic_zp:/ # cat /proc/sys/kernel/printk
8 4 1 7
ac8x_saic_zp:/ #

Logo

更多推荐