6/01/2012

How to enable dynamic kernel logging (debugfs) on Android/Linux builds?

To enable debugfs based dynamic kernel logging feature, please follow the steps below.

Background:
Recent kernel camera driver in Android (Froyo and after releases) adopted debugfs based kernel logging feature. By default, unlike previous releases, CDBG (camera debug message) logs can be captured dynamically by following procedure section below. You can check if your build has the feature by:

FILE: arch/arm/mach-msm/include/mach/camera.h
...
#define CDBG(fmt, args...) pr_debug(fmt, ##args)
...

Procedure:

Make sure CONFIG_DYNAMIC_DEBUG=y is set into corresponding target defconfig file.

First, please copy the following script provided at the end of this solution in between the marker <<<START OF FILE>> and <<<END OF FILE>>> and create a Windows/DOS batch file with an appropriate, such as "kernel_log.bat".
This batch file requires ADB connection from Windows/DOS to your device.
Execute the script by issuing command: kernel_log.bat enable all
After successful enabling the dynamic kernel logging after step #4, you can capture camera kernel logs like as you used to do in the normal way: ex.) adb shell cat /proc/kmsg > kernel.log
You can selectively enable only relevant logs by specifying the module provided in the script:
All (VFE, Sensor, Gemini, VPE)
kernel_log.bat <enable/disable> all
VFE (msm_io7x.c msm_io8x.c msm_io_vfe31.c msm_vfe31.c msm_vfe7x.c msm_vfe8x.c msm_vfe8x_proc.c msm_io_8x60.c)
kernel_log.bat <enable/disable> vfe
Sensor (sn12m0pz.c sn12m0pz_reg.c mt9d112.c mt9d112_reg.c mt9p012_bam.c mt9p012_fox.c mt9p012_km.c mt9p012_km_reg.c mt9p012_reg.c mt9t013.c mt9t013_reg.c s5k3e2fx.c vb6801.c vx6953.c vx6953_reg.c imx074.c imx074_reg.c)
kernel_log.bat <enable/disable> sensor
VPE (msm_vpe1.c)
kernel_log.bat <enable/disable> vpe
Gemini (msm_gemini_core.c msm_gemini_dev.c msm_gemini_hw.c msm_gemini_platform.c msm_gemini_sync.c)
kernel_log.bat <enable/disable> Gemini
Individual File (under kernel/drivers/media/video/msm with CDBG or pr_debug messages only)

kernel_log.bat <enable/disable> <file names>

FILE: kernel_log.bat

==========<<<START OF FILE>>==========
@echo off

if "%1" == "help" (
echo Usage: kernel_log.bat enable/disable modules
echo Valid modules: all vfe sensor gemini vpe file_name
goto end
)

if "%1" == "" (
echo Usage: kernel_log.bat enable/disable modules
echo Valid modules: all vfe sensor gemini vpe file_name
goto end
)

echo DYNAMIC DEBUG MSG CONF SCRIPT FOR Linux Camera

echo Define module lists for different modules
set all_module_list=flash.c msm_axi_qos.c msm_camera.c msm_gemini_core.c ov8810.c msm_gemini_dev.c msm_gemini_hw.c msm_gemini_platform.c msm_gemini_sync.c msm_io7x.c msm_io8x.c msm_io_vfe31.c msm_v4l2.c msm_vfe31.c msm_vfe7x.c msm_vfe8x.c msm_vfe8x_proc.c mt9d112.c mt9d112_reg.c mt9p012_bam.c mt9p012_fox.c mt9p012_km.c mt9p012_km_reg.c mt9p012_reg.c mt9t013.c mt9t013_reg.c s5k3e2fx.c vb6801.c vx6953.c vx6953_reg.c
set vfe_list=msm_camera.c msm_io7x.c msm_io8x.c msm_io_vfe31.c msm_vfe31.c msm_vfe7x.c msm_vfe8x.c msm_vfe8x_proc.c msm_io_8x60.c
set sensor_list=sn12m0pz.c sn12m0pz_reg.c mt9d112.c mt9d112_reg.c ov8810.cmt9p012_bam.c mt9p012_fox.c mt9p012_km.c mt9p012_km_reg.c mt9p012_reg.c mt9t013.c mt9t013_reg.c s5k3e2fx.c vb6801.c vx6953.c vx6953_reg.c imx074.c imx074_reg.c ov7692.c
set gemini_list=msm_gemini_core.c msm_gemini_dev.c msm_gemini_hw.c msm_gemini_platform.c msm_gemini_sync.c
set vpe_list=msm_camera.c msm_vpe1.c

echo Mount debufs interface
adb shell "mount -t debugfs debugfs /sys/kernel/debug"

if "%2" == "all" (
if "%1" == "enable" (
for %%a in (%all_module_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%all_module_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)

if "%2" == "vfe" (
if "%1" == "enable" (
for %%a in (%vfe_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%vfe_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)

if "%2" == "sensor" (
if "%1" == "enable" (
for %%a in (%sensor_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%sensor_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)

if "%2" == "gemini" (
if "%1" == "enable" (
for %%a in (%gemini_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%gemini_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)

if "%2" == "vpe" (
if "%1" == "enable" (
for %%a in (%vpe_list%) do adb shell "echo -n \"file %%a +p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
if "%1" == "disable" (
for %%a in (%vpe_list%) do adb shell "echo -n \"file %%a -p\" > /sys/kernel/debug/dynamic_debug/control"
goto end
)
)

if "%1" == "disable" goto loop_disable

:loop_enable
if "%1" == "enable" adb shell "echo -n \"file %2 +p\" > /sys/kernel/debug/dynamic_debug/control"
shift /2
if not "%2" == "" goto loop_enable
goto end

:loop_disable
if "%1" == "disable" adb shell "echo -n \"file %2 -p\" > /sys/kernel/debug/dynamic_debug/control"
shift /2
if not "%2" == "" goto loop_disable
goto end

:end
echo END OF SCRIPT
==========<<<END OF FILE>>==========

No comments:

Post a Comment