Permalink
Browse files

init: add detection of charging mode

-when BOARD_CHARGING_MODE_BOOTING_LPM is set to a path_to_sysfs_attribute
 then it and lpm.rc will be read accordingly.

-adapted from techomancer's original change:
 (add detection of charging mode, remove the code for parsing param.lfs,
  since it is not needed)
 http://goo.gl/I19GG

Change-Id: I64c2379225e00afaaf17ee03eab67546781668f8
  • Loading branch information...
pershoot committed Dec 17, 2011
1 parent 16e6332 commit 559ecfba5041890f53ec24164d4ef0d87d3b990c
Showing with 38 additions and 4 deletions.
  1. +8 −0 init/Android.mk
  2. +30 −4 init/init.c
View
@@ -22,6 +22,14 @@ LOCAL_SRC_FILES += bootchart.c
LOCAL_CFLAGS += -DBOOTCHART=1
endif
+SYSTEM_CORE_INIT_DEFINES := BOARD_CHARGING_MODE_BOOTING_LPM
+
+$(foreach system_core_init_define,$(SYSTEM_CORE_INIT_DEFINES), \
+ $(if $($(system_core_init_define)), \
+ $(eval LOCAL_CFLAGS += -D$(system_core_init_define)=\"$($(system_core_init_define))\") \
+ ) \
+ )
+
LOCAL_MODULE:= init
LOCAL_FORCE_STATIC_EXECUTABLE := true
View
@@ -665,6 +665,25 @@ static int bootchart_init_action(int nargs, char **args)
}
#endif
+static int charging_mode_booting(void)
+{
+#ifndef BOARD_CHARGING_MODE_BOOTING_LPM
+ return 0;
+#else
+ int f;
+ char cmb;
+ f = open(BOARD_CHARGING_MODE_BOOTING_LPM, O_RDONLY);
+ if (f < 0)
+ return 0;
+
+ if (1 != read(f, (void *)&cmb,1))
+ return 0;
+
+ close(f);
+ return ('1' == cmb);
+#endif
+}
+
int main(int argc, char **argv)
{
int fd_count = 0;
@@ -710,15 +729,22 @@ int main(int argc, char **argv)
klog_init();
INFO("reading config file\n");
- init_parse_config_file("/init.rc");
+
+ if (!charging_mode_booting())
+ init_parse_config_file("/init.rc");
+ else
+ init_parse_config_file("/lpm.rc");
/* pull the kernel commandline and ramdisk properties file in */
import_kernel_cmdline(0, import_kernel_nv);
/* don't expose the raw commandline to nonpriv processes */
chmod("/proc/cmdline", 0440);
- get_hardware_name(hardware, &revision);
- snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware);
- init_parse_config_file(tmp);
+
+ if (!charging_mode_booting()) {
+ get_hardware_name(hardware, &revision);
+ snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware);
+ init_parse_config_file(tmp);
+ }
/* Check for a target specific initialisation file and read if present */
if (access("/init.target.rc", R_OK) == 0) {

0 comments on commit 559ecfb

Please sign in to comment.