[RK3288][Android6.0] Debugging notes --- print the current reboot or shutdown process information

Platform: RK3288
OS: Android 6.0
Kernel: 3.10.92

Background:
encountered a black screen of a machine, unable to connect adb and uart, but the work indicator is still on 


Log:
Logcat found no exceptions, and the Kernel log is as follows:

<4>[ 1294.653184] ^^^^^^^^^^^^^^^^^Device Mode
<4>[ 1294.653230] *******************soft connect!!!*******************
<4>[ 1294.773441] USB RESET
<6>[ 1294.860784] android_work: sent uevent USB_STATE=CONNECTED
<6>[ 1295.035427] android_usb gadget: high-speed config #1: android
<6>[ 1295.035833] android_work: sent uevent USB_STATE=CONFIGURED
<6>[ 1295.061410] mtp_open
<6>[ 1318.881611] SysRq : Emergency Remount R/O

Analysis:
The last Log indicates that the system has entered the reboot and shutdown process, but the board is still working, indicating that the shutdown is not normal.
You need to add Log to determine whether to call this process. The entry function of user space is android_reboot()@anroid_reboot.c.
There are two ways to call:
1. Directly include the library (libcutils.so) corresponding to this function to call this interface
2. Through The property_set() function calls the powerctrl command of the init process to indirectly call this interface

Therefore, the process information of the log print call is added in two places.


change:

diff --git a/libcutils/android_reboot.c b/libcutils/android_reboot.c
index 6ae23c1..198f951 100644
--- a/libcutils/android_reboot.c
+++ b/libcutils/android_reboot.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  */

+
 #include <unistd.h>
 #include <sys/reboot.h>
 #include <sys/syscall.h>
@@ -26,6 +27,8 @@

 #include <cutils/android_reboot.h>

+
 #define UNUSED __attribute__((unused))

 /* Check to see if /proc/mounts contains any writeable filesystems
@@ -88,11 +91,33 @@ static void remount_ro(void)
     return;
 }

+/*Kris, 180420, add reboot log.  {*/
+#define LOG_TAG "android_reboot"
+#include <utils/Log.h>
+int print_current_process_info()
+{
+    pid_t pid = getpid();
+    char path[1024] = {0};
+    if(readlink("/proc/self/exe", path,1024) <=0)
+            return -1;
+
+    char *name = strrchr(path, '/');
+    if(name)
+        ALOGI("Pid: %d name:%s path:%s\n", pid, ++name, path);
+
+    return 0 ;
+}
+/*Kris, 180420, add reboot log.  }*/

 int android_reboot(int cmd, int flags UNUSED, const char *arg)
 {
     int ret;

+    /*Kris, 180420, add reboot log.  {*/
+    ALOGI("android_reboot start...\n");
+    print_current_process_info();
+    /*Kris, 180420, add reboot log.  }*/
+
     sync();
     remount_ro();

diff --git a/libcutils/properties.c b/libcutils/properties.c
index 4e46e02..cbce234 100644
--- a/libcutils/properties.c
+++ b/libcutils/properties.c
@@ -107,8 +107,19 @@ int32_t property_get_int32(const char *key, int32_t default_value) {
 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
 #include <sys/_system_properties.h>

+
+/*Kris, 180420, add reboot log.  {*/
+extern  int print_current_process_info()  ;
+/*Kris, 180420, add reboot log.  }*/
+
+
 int property_set(const char *key, const char *value)
 {
+    /*Kris, 180420, add reboot log.  {*/
+    if (!strcmp(key,"sys.powerctl"))
+        print_current_process_info();
+    /*Kris, 180420, add reboot log.  }*/
+
     return __system_property_set(key, value);
 }

Points to note:
1. The system provides a reboot command to execute the reboot and shutdown functions. If the caller calls it through the type system() method, only the reboot process information will be printed (because a process will be re-forked), so you need to Globally search for places to call, but there shouldn't be many places to call.
2. When calling to add Log, note that libcutils may be statically included, such as init, then compile init (corresponding to bootimage) instead of libcutils.so.


Reference:
[RK3288][Android6.0] Summary of system restart calling process

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325987777&siteId=291194637