From e4b7b294f37d9b64d6b7c1931e2c9bfb1a500d68 Mon Sep 17 00:00:00 2001 From: Riley Andrews Date: Mon, 16 Jun 2014 15:06:21 -0700 Subject: [PATCH] Add ability to boot from charger mode. Add the ability to boot up directly from charger mode, instead of forcing charger mode to initiate a full restart to launch 'full' android. This should shave a few seconds off of boot time on supported devices (just manta for now). Change-Id: Ieec4494d929e92806e039f834d78b9002afd15c4 --- charger/charger.c | 13 +++++++++++-- init/builtins.c | 8 ++++++++ init/init.c | 16 +++------------- init/init_parser.c | 1 + init/keywords.h | 2 ++ init/property_service.c | 9 ++++++--- init/property_service.h | 1 + rootdir/init.rc | 25 +++++++++++++++++++++++++ 8 files changed, 57 insertions(+), 18 deletions(-) diff --git a/charger/charger.c b/charger/charger.c index e3cadb1dd..15add87d0 100644 --- a/charger/charger.c +++ b/charger/charger.c @@ -40,6 +40,7 @@ #include #include #include +#include #ifdef CHARGER_ENABLE_SUSPEND #include @@ -830,8 +831,16 @@ static void process_key(struct charger *charger, int code, int64_t now) if (key->down) { int64_t reboot_timeout = key->timestamp + POWER_ON_KEY_TIME; if (now >= reboot_timeout) { - LOGI("[%lld] rebooting\n", now); - android_reboot(ANDROID_RB_RESTART, 0, 0); + /* We do not currently support booting from charger mode on + all devices. Check the property and continue booting or reboot + accordingly. */ + if (property_get_bool("ro.enable_boot_charger_mode", false)) { + LOGI("[%lld] booting from charger mode\n", now); + property_set("sys.boot_from_charger_mode", "1"); + } else { + LOGI("[%lld] rebooting\n", now); + android_reboot(ANDROID_RB_RESTART, 0, 0); + } } else { /* if the key is pressed but timeout hasn't expired, * make sure we wake up at the right-ish time to check diff --git a/init/builtins.c b/init/builtins.c index d9f7bbe71..0c32b2a7b 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -877,6 +877,14 @@ int do_load_persist_props(int nargs, char **args) { return -1; } +int do_load_all_props(int nargs, char **args) { + if (nargs == 1) { + load_all_props(); + return 0; + } + return -1; +} + int do_wait(int nargs, char **args) { if (nargs == 2) { diff --git a/init/init.c b/init/init.c index c79929bf7..97c33e481 100644 --- a/init/init.c +++ b/init/init.c @@ -1051,8 +1051,7 @@ int main(int argc, char **argv) is_charger = !strcmp(bootmode, "charger"); INFO("property init\n"); - if (!is_charger) - property_load_boot_defaults(); + property_load_boot_defaults(); INFO("reading config file\n"); init_parse_config_file("/init.rc"); @@ -1067,28 +1066,19 @@ int main(int argc, char **argv) /* execute all the boot actions to get us started */ action_for_each_trigger("init", action_add_queue_tail); - /* skip mounting filesystems in charger mode */ - if (!is_charger) { - action_for_each_trigger("early-fs", action_add_queue_tail); - action_for_each_trigger("fs", action_add_queue_tail); - action_for_each_trigger("post-fs", action_add_queue_tail); - action_for_each_trigger("post-fs-data", action_add_queue_tail); - } - /* Repeat mix_hwrng_into_linux_rng in case /dev/hw_random or /dev/random * wasn't ready immediately after wait_for_coldboot_done */ queue_builtin_action(mix_hwrng_into_linux_rng_action, "mix_hwrng_into_linux_rng"); - queue_builtin_action(property_service_init_action, "property_service_init"); queue_builtin_action(signal_init_action, "signal_init"); queue_builtin_action(check_startup_action, "check_startup"); + /* Don't mount filesystems or start core system services if in charger mode. */ if (is_charger) { action_for_each_trigger("charger", action_add_queue_tail); } else { - action_for_each_trigger("early-boot", action_add_queue_tail); - action_for_each_trigger("boot", action_add_queue_tail); + action_for_each_trigger("late-init", action_add_queue_tail); } /* run all property triggers based on current state of the properties */ diff --git a/init/init_parser.c b/init/init_parser.c index 78000825d..289e75975 100644 --- a/init/init_parser.c +++ b/init/init_parser.c @@ -120,6 +120,7 @@ static int lookup_keyword(const char *s) case 'l': if (!strcmp(s, "oglevel")) return K_loglevel; if (!strcmp(s, "oad_persist_props")) return K_load_persist_props; + if (!strcmp(s, "oad_all_props")) return K_load_all_props; break; case 'm': if (!strcmp(s, "kdir")) return K_mkdir; diff --git a/init/keywords.h b/init/keywords.h index 6625330c1..2d97e5b99 100644 --- a/init/keywords.h +++ b/init/keywords.h @@ -39,6 +39,7 @@ int do_chown(int nargs, char **args); int do_chmod(int nargs, char **args); int do_loglevel(int nargs, char **args); int do_load_persist_props(int nargs, char **args); +int do_load_all_props(int nargs, char **args); int do_wait(int nargs, char **args); #define __MAKE_KEYWORD_ENUM__ #define KEYWORD(symbol, flags, nargs, func) K_##symbol, @@ -101,6 +102,7 @@ enum { KEYWORD(chmod, COMMAND, 2, do_chmod) KEYWORD(loglevel, COMMAND, 1, do_loglevel) KEYWORD(load_persist_props, COMMAND, 0, do_load_persist_props) + KEYWORD(load_all_props, COMMAND, 0, do_load_all_props) KEYWORD(ioprio, OPTION, 0, 0) #ifdef __MAKE_KEYWORD_ENUM__ KEYWORD_COUNT, diff --git a/init/property_service.c b/init/property_service.c index fb3bc8d13..a6cbde492 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -621,10 +621,8 @@ void load_persist_props(void) load_persistent_properties(); } -void start_property_service(void) +void load_all_props(void) { - int fd; - load_properties_from_file(PROP_PATH_SYSTEM_BUILD, NULL); load_properties_from_file(PROP_PATH_SYSTEM_DEFAULT, NULL); load_properties_from_file(PROP_PATH_FACTORY, "ro.*"); @@ -633,6 +631,11 @@ void start_property_service(void) /* Read persistent properties after all default values have been loaded. */ load_persistent_properties(); +} + +void start_property_service(void) +{ + int fd; fd = create_socket(PROP_SERVICE_NAME, SOCK_STREAM, 0666, 0, 0, NULL); if(fd < 0) return; diff --git a/init/property_service.h b/init/property_service.h index 46cbd8ff5..730495e68 100644 --- a/init/property_service.h +++ b/init/property_service.h @@ -24,6 +24,7 @@ extern void handle_property_set_fd(void); extern void property_init(void); extern void property_load_boot_defaults(void); extern void load_persist_props(void); +extern void load_all_props(void); extern void start_property_service(void); void get_property_workspace(int *fd, int *sz); extern int __property_get(const char *name, char *value); diff --git a/rootdir/init.rc b/rootdir/init.rc index a176e03b2..08b08fe01 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -154,6 +154,31 @@ on init chown system log /sys/fs/pstore/console-ramoops chmod 0440 /sys/fs/pstore/console-ramoops +# Healthd can trigger a full boot from charger mode by signaling this +# property when the power button is held. +on property:sys.boot_from_charger_mode=1 + class_stop charger + trigger late-init + +# Load properties from /system/ + /factory after fs mount. +on load_all_props_action + load_all_props + +# Mount filesystems and start core system services. +on late-init + trigger early-fs + trigger fs + trigger post-fs + trigger post-fs-data + + # Load properties from /system/ + /factory after fs mount. Place + # this in another action so that the load will be scheduled after the prior + # issued fs triggers have completed. + trigger load_all_props_action + + trigger early-boot + trigger boot + on post-fs # once everything is setup, no need to modify / mount rootfs rootfs / ro remount