diff options
Diffstat (limited to 'init')
-rw-r--r-- | init/init.cpp | 72 | ||||
-rw-r--r-- | init/ueventd.cpp | 26 | ||||
-rw-r--r-- | init/util.cpp | 33 | ||||
-rw-r--r-- | init/util.h | 1 |
4 files changed, 56 insertions, 76 deletions
diff --git a/init/init.cpp b/init/init.cpp index e1c82a4..a27221a 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -15,6 +15,7 @@ */ #include <ctype.h> +#include <dirent.h> #include <errno.h> #include <fcntl.h> #include <libgen.h> @@ -34,12 +35,16 @@ #include <termios.h> #include <unistd.h> +#include <memory> + #include <mtd/mtd-user.h> #include <selinux/selinux.h> #include <selinux/label.h> #include <selinux/android.h> +#include <base/file.h> +#include <base/stringprintf.h> #include <cutils/android_reboot.h> #include <cutils/fs.h> #include <cutils/iosched_policy.h> @@ -59,6 +64,9 @@ #include "ueventd.h" #include "watchdogd.h" +using android::base::ReadFileToString; +using android::base::StringPrintf; + struct selabel_handle *sehandle; struct selabel_handle *sehandle_prop; @@ -66,8 +74,6 @@ static int property_triggers_enabled = 0; static char console[32]; static char bootmode[32]; -static char hardware[32]; -static unsigned revision = 0; static char qemu[32]; static struct action *cur_action = NULL; @@ -773,6 +779,8 @@ static void export_kernel_boot_props(void) { "ro.boot.mode", "ro.bootmode", "unknown", }, { "ro.boot.baseband", "ro.baseband", "unknown", }, { "ro.boot.bootloader", "ro.bootloader", "unknown", }, + { "ro.boot.hardware", "ro.hardware", "unknown", }, + { "ro.boot.revision", "ro.revision", "0", }, }; for (i = 0; i < ARRAY_SIZE(prop_map); i++) { @@ -791,16 +799,6 @@ static void export_kernel_boot_props(void) property_get("ro.bootmode", tmp); strlcpy(bootmode, tmp, sizeof(bootmode)); - /* if this was given on kernel command line, override what we read - * before (e.g. from /proc/cpuinfo), if anything */ - ret = property_get("ro.boot.hardware", tmp); - if (ret) - strlcpy(hardware, tmp, 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"); @@ -810,6 +808,40 @@ static void export_kernel_boot_props(void) property_set("ro.factorytest", "0"); } +static void process_kernel_dt(void) +{ + static const char android_dir[] = "/proc/device-tree/firmware/android"; + + std::string file_name = StringPrintf("%s/compatible", android_dir); + + std::string dt_file; + ReadFileToString(file_name, &dt_file); + if (!dt_file.compare("android,firmware")) { + ERROR("firmware/android is not compatible with 'android,firmware'\n"); + return; + } + + std::unique_ptr<DIR, int(*)(DIR*)>dir(opendir(android_dir), closedir); + if (!dir) + return; + + struct dirent *dp; + while ((dp = readdir(dir.get())) != NULL) { + if (dp->d_type != DT_REG || !strcmp(dp->d_name, "compatible")) + continue; + + file_name = StringPrintf("%s/%s", android_dir, dp->d_name); + + ReadFileToString(file_name, &dt_file); + std::replace(dt_file.begin(), dt_file.end(), ',', '.'); + + std::string property_name = StringPrintf("ro.boot.%s", dp->d_name); + if (property_set(property_name.c_str(), dt_file.c_str())) { + ERROR("Could not set property %s to value %s", property_name.c_str(), dt_file.c_str()); + } + } +} + static void process_kernel_cmdline(void) { /* don't expose the raw commandline to nonpriv processes */ @@ -822,11 +854,6 @@ static void process_kernel_cmdline(void) 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) @@ -1014,10 +1041,17 @@ int main(int argc, char** argv) { klog_init(); property_init(); - get_hardware_name(hardware, &revision); - + process_kernel_dt(); + /* in case one is passing arguments both on the command line and in DT + * Properties set in DT always have priority over the command-line ones + */ process_kernel_cmdline(); + /* now propogate the kernel variables to internal variables + * used by init as well as the current required properties + */ + export_kernel_boot_props(); + selinux_callback cb; cb.func_log = log_callback; selinux_set_callback(SELINUX_CB_LOG, cb); diff --git a/init/ueventd.cpp b/init/ueventd.cpp index d56b91a..5af6e3d 100644 --- a/init/ueventd.cpp +++ b/init/ueventd.cpp @@ -30,28 +30,13 @@ #include "util.h" #include "devices.h" #include "ueventd_parser.h" - -static char hardware[32]; -static unsigned revision = 0; - -static void import_kernel_nv(char *name, int in_qemu) -{ - if (*name != '\0') { - char *value = strchr(name, '='); - if (value != NULL) { - *value++ = 0; - if (!strcmp(name,"androidboot.hardware")) - { - strlcpy(hardware, value, sizeof(hardware)); - } - } - } -} +#include "property_service.h" int ueventd_main(int argc, char **argv) { struct pollfd ufd; int nr; + char hardware[PROP_VALUE_MAX]; char tmp[32]; /* @@ -83,12 +68,7 @@ int ueventd_main(int argc, char **argv) INFO("starting ueventd\n"); - /* Respect hardware passed in through the kernel cmd line. Here we will look - * for androidboot.hardware param in kernel cmdline, and save its value in - * hardware[]. */ - import_kernel_cmdline(0, import_kernel_nv); - - get_hardware_name(hardware, &revision); + property_get("ro.hardware", hardware); ueventd_parse_config_file("/ueventd.rc"); diff --git a/init/util.cpp b/init/util.cpp index c805083..8b238d4 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -400,39 +400,6 @@ void open_devnull_stdio(void) exit(1); } -void get_hardware_name(char *hardware, unsigned int *revision) { - // Hardware string was provided on kernel command line. - if (hardware[0]) { - return; - } - - FILE* fp = fopen("/proc/cpuinfo", "re"); - if (fp == NULL) { - return; - } - char buf[1024]; - while (fgets(buf, sizeof(buf), fp) != NULL) { - if (strncmp(buf, "Hardware", 8) == 0) { - const char* hw = strstr(buf, ": "); - if (hw) { - hw += 2; - size_t n = 0; - while (*hw) { - if (!isspace(*hw)) { - hardware[n++] = tolower(*hw); - } - hw++; - if (n == 31) break; - } - hardware[n] = 0; - } - } else if (strncmp(buf, "Revision", 8) == 0) { - sscanf(buf, "Revision : %ux", revision); - } - } - fclose(fp); -} - void import_kernel_cmdline(int in_qemu, void (*import_kernel_nv)(char *name, int in_qemu)) { diff --git a/init/util.h b/init/util.h index 77da3ac..e0b3c69 100644 --- a/init/util.h +++ b/init/util.h @@ -42,7 +42,6 @@ void make_link(const char *oldpath, const char *newpath); void remove_link(const char *oldpath, const char *newpath); int wait_for_file(const char *filename, int timeout); void open_devnull_stdio(void); -void get_hardware_name(char *hardware, unsigned int *revision); void import_kernel_cmdline(int in_qemu, void (*import_kernel_nv)(char *name, int in_qemu)); int make_dir(const char *path, mode_t mode); int restorecon(const char *pathname); |