diff options
author | Dima Zavin <dima@android.com> | 2012-01-06 15:26:30 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-01-06 15:26:30 -0800 |
commit | 829c0b8d9e7ac32141349117ba4364a2f63b22d8 (patch) | |
tree | b5a4bf3a69229bf8ac6681a94ce8165c3cab832e /init/init.c | |
parent | ae8b56c0d17a97aff0b98e6405c7cc9811bbbc3d (diff) | |
parent | ebe2cb312d36788fa9956ef6829c6aada495606f (diff) | |
download | system_core-829c0b8d9e7ac32141349117ba4364a2f63b22d8.zip system_core-829c0b8d9e7ac32141349117ba4364a2f63b22d8.tar.gz system_core-829c0b8d9e7ac32141349117ba4364a2f63b22d8.tar.bz2 |
Merge changes I3c284860,I06dc35ff,Iedda6c90,I933e5bba,I9205d7d7,Iae9ed109
* changes:
init: use init's property expansion code for setprop/write
init: delay importing files until after parsing the current file
init: export all androidboot cmd line values as ro.boot.xx props
init: import the hardware specific init file in init.rc
init: allow init file imports to use properties in names
init: initialize property area early at boot
Diffstat (limited to 'init/init.c')
-rwxr-xr-x | init/init.c | 178 |
1 files changed, 100 insertions, 78 deletions
diff --git a/init/init.c b/init/init.c index d10ca47..c3be93d 100755 --- a/init/init.c +++ b/init/init.c @@ -59,11 +59,7 @@ static int bootchart_count; #endif static char console[32]; -static char serialno[32]; static char bootmode[32]; -static char baseband[32]; -static char carrier[32]; -static char bootloader[32]; static char hardware[32]; static unsigned revision = 0; static char qemu[32]; @@ -420,45 +416,6 @@ void handle_control_message(const char *msg, const char *arg) } } -static void import_kernel_nv(char *name, int in_qemu) -{ - char *value = strchr(name, '='); - - if (value == 0) return; - *value++ = 0; - if (*name == 0) return; - - if (!in_qemu) - { - /* on a real device, white-list the kernel options */ - if (!strcmp(name,"qemu")) { - strlcpy(qemu, value, sizeof(qemu)); - } else if (!strcmp(name,"androidboot.console")) { - strlcpy(console, value, sizeof(console)); - } else if (!strcmp(name,"androidboot.mode")) { - strlcpy(bootmode, value, sizeof(bootmode)); - } else if (!strcmp(name,"androidboot.serialno")) { - strlcpy(serialno, value, sizeof(serialno)); - } else if (!strcmp(name,"androidboot.baseband")) { - strlcpy(baseband, value, sizeof(baseband)); - } else if (!strcmp(name,"androidboot.carrier")) { - strlcpy(carrier, value, sizeof(carrier)); - } else if (!strcmp(name,"androidboot.bootloader")) { - strlcpy(bootloader, value, sizeof(bootloader)); - } else if (!strcmp(name,"androidboot.hardware")) { - strlcpy(hardware, value, sizeof(hardware)); - } - } else { - /* in the emulator, export any kernel option with the - * ro.kernel. prefix */ - char buff[32]; - int len = snprintf( buff, sizeof(buff), "ro.kernel.%s", name ); - if (len < (int)sizeof(buff)) { - property_set( buff, value ); - } - } -} - static struct command *get_first_command(struct action *act) { struct listnode *node; @@ -518,17 +475,6 @@ static int wait_for_coldboot_done_action(int nargs, char **args) return ret; } -static int property_init_action(int nargs, char **args) -{ - bool load_defaults = true; - - INFO("property init\n"); - if (!strcmp(bootmode, "charger")) - load_defaults = false; - property_init(load_defaults); - return 0; -} - static int keychord_init_action(int nargs, char **args) { keychord_init(); @@ -576,30 +522,104 @@ static int console_init_action(int nargs, char **args) return 0; } -static int set_init_properties_action(int nargs, char **args) +static void import_kernel_nv(char *name, int for_emulator) +{ + char *value = strchr(name, '='); + int name_len = strlen(name); + + if (value == 0) return; + *value++ = 0; + if (name_len == 0) return; + + if (for_emulator) { + /* in the emulator, export any kernel option with the + * ro.kernel. prefix */ + char buff[PROP_NAME_MAX]; + int len = snprintf( buff, sizeof(buff), "ro.kernel.%s", name ); + + if (len < (int)sizeof(buff)) + property_set( buff, value ); + return; + } + + if (!strcmp(name,"qemu")) { + strlcpy(qemu, value, sizeof(qemu)); + } else if (!strncmp(name, "androidboot.", 12) && name_len > 12) { + const char *boot_prop_name = name + 12; + char prop[PROP_NAME_MAX]; + int cnt; + + cnt = snprintf(prop, sizeof(prop), "ro.boot.%s", boot_prop_name); + if (cnt < PROP_NAME_MAX) + property_set(prop, value); + } +} + +static void export_kernel_boot_props(void) { char tmp[PROP_VALUE_MAX]; + const char *pval; + unsigned i; + struct { + const char *src_prop; + const char *dest_prop; + const char *def_val; + } prop_map[] = { + { "ro.boot.serialno", "ro.serialno", "", }, + { "ro.boot.mode", "ro.bootmode", "unknown", }, + { "ro.boot.baseband", "ro.baseband", "unknown", }, + { "ro.boot.carrier", "ro.carrier", "unknown", }, + { "ro.boot.bootloader", "ro.bootloader", "unknown", }, + }; + + for (i = 0; i < ARRAY_SIZE(prop_map); i++) { + pval = property_get(prop_map[i].src_prop); + property_set(prop_map[i].dest_prop, pval ?: prop_map[i].def_val); + } - if (qemu[0]) - import_kernel_cmdline(1, import_kernel_nv); + pval = property_get("ro.boot.console"); + if (pval) + strlcpy(console, pval, sizeof(console)); + + /* save a copy for init's usage during boot */ + strlcpy(bootmode, property_get("ro.bootmode"), sizeof(bootmode)); + + /* if this was given on kernel command line, override what we read + * before (e.g. from /proc/cpuinfo), if anything */ + pval = property_get("ro.boot.hardware"); + if (pval) + strlcpy(hardware, pval, sizeof(hardware)); + property_set("ro.hardware", hardware); + + snprintf(tmp, PROP_VALUE_MAX, "%d", revision); + property_set("ro.revision", tmp); + /* TODO: these are obsolete. We should delete them */ if (!strcmp(bootmode,"factory")) property_set("ro.factorytest", "1"); else if (!strcmp(bootmode,"factory2")) property_set("ro.factorytest", "2"); else property_set("ro.factorytest", "0"); +} - property_set("ro.serialno", serialno[0] ? serialno : ""); - property_set("ro.bootmode", bootmode[0] ? bootmode : "unknown"); - property_set("ro.baseband", baseband[0] ? baseband : "unknown"); - property_set("ro.carrier", carrier[0] ? carrier : "unknown"); - property_set("ro.bootloader", bootloader[0] ? bootloader : "unknown"); +static void process_kernel_cmdline(void) +{ + /* don't expose the raw commandline to nonpriv processes */ + chmod("/proc/cmdline", 0440); - property_set("ro.hardware", hardware); - snprintf(tmp, PROP_VALUE_MAX, "%d", revision); - property_set("ro.revision", tmp); - return 0; + /* first pass does the common stuff, and finds if we are in qemu. + * second pass is only necessary for qemu to export all kernel params + * as props. + */ + import_kernel_cmdline(0, import_kernel_nv); + if (qemu[0]) + import_kernel_cmdline(1, import_kernel_nv); + + /* now propogate the info given on command line to internal variables + * used by init as well as the current required properties + */ + export_kernel_boot_props(); } static int property_service_init_action(int nargs, char **args) @@ -668,6 +688,7 @@ int main(int argc, char **argv) int property_set_fd_init = 0; int signal_fd_init = 0; int keychord_fd_init = 0; + bool is_charger = false; if (!strcmp(basename(argv[0]), "ueventd")) return ueventd_main(argc, argv); @@ -701,31 +722,32 @@ int main(int argc, char **argv) */ open_devnull_stdio(); klog_init(); + property_init(); + + get_hardware_name(hardware, &revision); + + process_kernel_cmdline(); + + is_charger = !strcmp(bootmode, "charger"); + + INFO("property init\n"); + if (!is_charger) + property_load_boot_defaults(); INFO("reading config file\n"); init_parse_config_file("/init.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); - action_for_each_trigger("early-init", action_add_queue_tail); queue_builtin_action(wait_for_coldboot_done_action, "wait_for_coldboot_done"); - queue_builtin_action(property_init_action, "property_init"); queue_builtin_action(keychord_init_action, "keychord_init"); queue_builtin_action(console_init_action, "console_init"); - queue_builtin_action(set_init_properties_action, "set_init_properties"); /* 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 (strcmp(bootmode, "charger") != 0) { + 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); @@ -736,7 +758,7 @@ int main(int argc, char **argv) queue_builtin_action(signal_init_action, "signal_init"); queue_builtin_action(check_startup_action, "check_startup"); - if (!strcmp(bootmode, "charger")) { + if (is_charger) { action_for_each_trigger("charger", action_add_queue_tail); } else { action_for_each_trigger("early-boot", action_add_queue_tail); |