Debugging Android
Kernel logs
While booted into Android
- Run
dmesgas root.
Failed boot
- Reboot into recovery and check for
/proc/last_kmsgor/sys/fs/pstore/*
Userspace
Stuck at boot animation (getting regular logs)
(Recovery) Mount System and delete file
/system/phh/secure. Reboot.Connect phone to PC.
Run
adb logcat -d all > logs.txtwhile on bootsplash
Override ADB authentication to capture logs during boot
Reboot into recovery.
Mount
systemin recovery.Connect to PC.
Run:
adb shell mount -o rw,remount /system_rootadb pull /system_root/system/build.propUse a text editor to change the following props in build.prop
ro.adb.secure=0ro.debuggable=1ro.secure=0persist.service.adb.enable=1persist.service.debuggable=1persist.sys.usb.config=adbor if
GNU sedis available on your system:bashsed -i 's/^ro\.adb\.secure=.*/ro.adb.secure=0/' build.prop sed -i 's/^ro\.debuggable=.*/ro.debuggable=1/' build.prop sed -i 's/^ro\.secure=.*/ro.secure=0/' build.prop sed -i 's/^persist\.service\.adb\.enable=.*/persist.service.adb.enable=1/' build.prop sed -i 's/^persist\.service\.debuggable=.*/persist.service.debuggable=1/' build.prop sed -i 's/^persist\.sys\.usb\.config=.*/persist.sys.usb.config=adb/' build.propNow copy the modified
build.propto /system by running:adb push build.prop /system_root/system/
Pull /data/boot_lc_main.txt
- Reboot into TWRP.
adb pull /data/boot_lc_main.txt(if it exists).
ADB not authorized
Reboot into recovery.
Connect to PC.
Run:
Linux/Unix:
adb push ~/.android/adbkey.pub /data/misc/adb/adb_keysWindows:
adb push C:\Users\%PutHereYourUsername%\.android\adbkey.pub /data/misc/adb/adb_keysNow ADB should be allowed.
Early-boot (bootloop at splash/OEM logo)
Checking pstore and last_kmsg
Reboot to TWRP.
Check
/sys/fs/pstore/*/proc/last_kmsgCopy logs to PC (Ex:
adb pull /proc/last_kmsg lastkmsg.txt)Note: This only works if the kernel is built with
CONFIG_PSTORE=y CONFIG_PSTORE_CONSOLE=y CONFIG_PSTORE_PMSG=y CONFIG_PSTORE_RAM=y CONFIG_PSTORE_LAST_KMSG=y
Using FBCon
FBCon enables kernel output to the display. Use this as a second to the last resort if the above mentioned methods don't work.
Build kernel with config options:
CONFIG_VT=y CONFIG_FB_SIMPLE=y CONFIG_FRAMEBUFFER_CONSOLE=y CONDIG_DRM_FBDEV_EMULATION=yModify kernel cmdline to include
androidboot.console=tty0 console=tty0Reboot into fastboot or recovery.
Grab another phone, make some contraption to keep it pointed at screen.
Adjust exposure and focus to make the text visible.
Run
bashadb rebootOR
bashfastboot rebootdepending on which mode you are in.
Pray that the recording is clear enough. If not, try again.
Import it into pc, flip it (if needed), start playing it slowed down and zoomed in.
Using UART / JTAG (or better known as Serial)
This is the ONLY WAY to grab logs if all of the aforementioned methods do not work.
This assumes your kernel has UART logging enabled, and your DTS has it enabled.
Disclaimer
I (the author), or OpenDroid are not responsible for any damage done to your board, whether it be a bad soldering job, scratched pcb, or fried board.
Prerequisites
• A gadget that does UART/TTL (for most devices)
• A multimeter
• Probes (or anything that lets you reach the UART points on the board)
• Oscilloscope (if your board has undocumented serial)
- Find your device's points
If your device has its points documented (usually somewhere in the postmarketOS wiki), then you're in luck.
If your device doesn't have the points, you can hook an oscilloscope to any points of interest and hope that your kernel has UART output enabled by default.
- Hooking up your hardware
Attach your probes (or solder a wire to said points, NOT RECOMMENDED!!)
Before plugging in your serial gadget, make sure you're using the right voltage AS THIS CAN FRY THE BOARD!
- Grabbing the logs
Fire up your serial reading program. The baud rate can be either found by cmdline passed by abl/preloader (or in defconfig.) If you can't find the baud rate then 115200 may be the default.
Now, power up your device. You may see early logs from abl/lk.
If all goes well, you should be able to find the root cause of your hang. If not, you can refer to the postmarketOS wiki as serial debugging is well documented there.