i.mx6 Android5.1.1 初始化流程之init进程(未完成)
概述:
接在i.mx6 Android5.1.1 初始化流程之框架之后
参考资料:http://blog.csdn.net/mr_raptor/article/category/799879
相关源码: /system/core/init/
相关配置文件:/system/core/rootdir/
从下面全文可以得出:
1).init进程和其相关的文件init.rc、ueventd.rc是在ramdisk.img中
2).修改节点权限: /ueventd.rc /ueventd.Freescale.rc
3). 修改相关服务和创建文件:/init.rc
1. mian.c
关于代码中的属性服务,可以查看:i.mx6 Android5.1.1 系统属性
关于代码中的init.rc,可以查看: i.mx6 Android5.1.1 初始化流程之init.rc解析
int main(int argc, char **argv)
{
int fd_count = ;
struct pollfd ufds[];
char *tmpdev;
char* debuggable;
char tmp[];
int property_set_fd_init = ;
int signal_fd_init = ;
int keychord_fd_init = ;
bool is_charger = false;
char watchdog[PROPERTY_MAX_VALUE];
int ret;
/*后面两个是初始化ueventd和看门狗,从上一章的ps中可以看出,这两个确实是进程init(PID=1)最初创建的两个进程*/
/*查看是否有看门狗的属性*/
ret = property_get("ro.boot.watchdogd", watchdog);
/*启动ueventd进程*/
if (!strcmp(basename(argv[]), "ueventd"))
return ueventd_main(argc, argv);
if (!strcmp(basename(argv[]), "watchdogd")) {
if(ret && !(strcmp(watchdog, "disabled"))) {
return ;
} else {
return watchdogd_main(argc, argv); /*在这里启动看门狗*/
}
} /* clear the umask */
umask(); /* Get the basic filesystem setup we need put
* together in the initramdisk on / and then we'll
* let the rc file figure out the rest.
*/ /* 创建目录,挂在文件系统,给权限
* tmpfs :/dev
* devpts :/dev/pts
* proc :/proc
* sysfs :/sys
*/
mkdir("/dev", );
mkdir("/proc", );
mkdir("/sys", ); mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
mkdir("/dev/pts", );
mkdir("/dev/socket", );
mount("devpts", "/dev/pts", "devpts", , NULL);
mount("proc", "/proc", "proc", , NULL);
mount("sysfs", "/sys", "sysfs", , NULL); close(open("/dev/.booting", O_WRONLY | O_CREAT, )); open_devnull_stdio(); //将标准输入、输出、错误定向到空
klog_init(); //将log重定向到/proc/kmsg当中
property_init(); //初始化属性服务,关于属性服务,可以查看:i.mx6 Android5.1.1 系统属性 get_hardware_name(hardware, &revision); //得到硬件信息和版本信息
get_soc_name(soc); //得到soc名字 process_kernel_cmdline(); // 设置基本属性 union selinux_callback cb;
cb.func_log = log_callback;
selinux_set_callback(SELINUX_CB_LOG, cb); cb.func_audit = audit_callback;
selinux_set_callback(SELINUX_CB_AUDIT, cb); selinux_initialize();
/* These directories were necessarily created before initial policy load
* and therefore need their security context restored to the proper value.
* This must happen before /dev is populated by ueventd.
*/
restorecon("/dev");
restorecon("/dev/socket");
restorecon("/dev/__properties__");
restorecon_recursive("/sys"); is_charger = !strcmp(bootmode, "charger"); INFO("property init\n");
property_load_boot_defaults(); //加载/default.prop文件 进行默认属性配置相关的工作 INFO("reading config file\n");
init_parse_config_file("/init.rc"); //注意:解析/init.rc,并将所有元素加入链表,关于init.rc,可以查看:i.mx6 Android5.1.1 系统属性 /* 首先说明一下,在函数中对于init.rc命令的解析之后,将所有命令分类分别挂在了action_list,service_list,action_queue三个链表当中
* serevice_list:用于保存init.rc当中的service配置信息
* action_list: 用于保存从init.rc当中解析出来的所有action
* action_queue: 用于保存所有待执行的action
*
* 下面的两个函数action_for_each_trigger和queue_builtin_action
* action_for_each_trigger:将action加入到action_queue当中,表示正准备执行
* queue_builtin_action: 创建一个action,并将其挂在atcion_queue和action_list当中,
*/
action_for_each_trigger("early-init", action_add_queue_tail); //接着上面,把链表中为on early-init的元素提取执行。(我们没有)将early-init动作添加到链表action_queue中
queue_builtin_action(wait_for_coldboot_done_action, "wait_for_coldboot_done"); //创建wait_for_coldboot_done动作并添加到链表action_queue和action_list中,在这里注意action_list用于保存从init.rc中解析出来的所有Action,而action_queue却是用于保存待执行的Action,action_queue是一个待执行队列。
queue_builtin_action(mix_hwrng_into_linux_rng_action, "mix_hwrng_into_linux_rng");
queue_builtin_action(keychord_init_action, "keychord_init");
queue_builtin_action(console_init_action, "console_init");
/* execute all the boot actions to get us started */
action_for_each_trigger("init", action_add_queue_tail);//执行Init.rc中的on init(这个我们就有了),后面分析
/* 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");
/* 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("late-init", action_add_queue_tail);
}
/* run all property triggers based on current state of the properties */
queue_builtin_action(queue_property_triggers_action, "queue_property_triggers");
#if BOOTCHART
queue_builtin_action(bootchart_init_action, "bootchart_init");
#endif
for(;;) {
int nr, i, timeout = -;
execute_one_command(); //按序执行action_queue里的action
restart_processes(); //重启一些关键进程,也就是守护进程
//添加,只执行一次
if (!property_set_fd_init && get_property_set_fd() > ) {
ufds[fd_count].fd = get_property_set_fd();
ufds[fd_count].events = POLLIN;
ufds[fd_count].revents = ;
fd_count++;
property_set_fd_init = ;
}
/*同上*/
if (!signal_fd_init && get_signal_fd() > ) {
ufds[fd_count].fd = get_signal_fd();
ufds[fd_count].events = POLLIN;
ufds[fd_count].revents = ;
fd_count++;
signal_fd_init = ;
}
/*同上*/
if (!keychord_fd_init && get_keychord_fd() > ) {
ufds[fd_count].fd = get_keychord_fd();
ufds[fd_count].events = POLLIN;
ufds[fd_count].revents = ;
fd_count++;
keychord_fd_init = ;
}
//计算超时时间
if (process_needs_restart) {
timeout = (process_needs_restart - gettime()) * ;
if (timeout < )
timeout = ;
}
if (!action_queue_empty() || cur_action)
timeout = ;
#if BOOTCHART
if (bootchart_count > ) {
if (timeout < || timeout > BOOTCHART_POLLING_MS)
timeout = BOOTCHART_POLLING_MS;
if (bootchart_step() < || --bootchart_count == ) {
bootchart_finish();
bootchart_count = ;
}
}
#endif
//监控句柄池中的事件,如果都没有变化,程序就停在这里了
nr = poll(ufds, fd_count, timeout);
if (nr <= )
continue;
//对于监听到的事件进行处理
for (i = ; i < fd_count; i++) {
if (ufds[i].revents & POLLIN) {
if (ufds[i].fd == get_property_set_fd())
handle_property_set_fd();
else if (ufds[i].fd == get_keychord_fd())
handle_keychord();
else if (ufds[i].fd == get_signal_fd())
handle_signal();
}
}
}
return ;
}
小结:
1。启动ueventd和watchdogd进程
2。将标准输入,输出,错误定向到null
3.重定向log
4.初始化属性的区域
5.添加各种属性
6.解析init.rc
7.将init.rc中解析出来的行为进行分类保存,并再添加一些默认行为
8.进入循环守护
1). 执行action_queue中的action
2). 守护一些关键进程
3). 建立属性、信号、组合按键的监听。当有行为发生时,对其进行相应处理,没有则停滞在这里
从上诉程序可以分析出action的执行顺序为:
early-init ------------------>>init.rc
wait_for_coldboot_done
mix_hwrng_into_linux_rng
keychord_init
console_init
init ------------------>>init.rc
mix_hwrng_into_linux_rng
property_service_init
signal_init
charger或者late-init ------------------>>init.rc
queue_property_triggers
2. ueventd_main
int ueventd_main(int argc, char **argv)
{
struct pollfd ufd;
int nr;
char tmp[]; /*
* init sets the umask to 077 for forked processes. We need to
* create files with exact permissions, without modification by
* the umask.
*/
umask(); /* Prevent fire-and-forget children from becoming zombies.
* If we should need to wait() for some children in the future
* (as opposed to none right now), double-forking here instead
* of ignoring SIGCHLD may be the better solution.
*/
signal(SIGCHLD, SIG_IGN); open_devnull_stdio();
klog_init();
#if LOG_UEVENTS
/* Ensure we're at a logging level that will show the events */
if (klog_get_level() < KLOG_INFO_LEVEL) {
klog_set_level(KLOG_INFO_LEVEL);
}
#endif union selinux_callback cb;
cb.func_log = log_callback;
selinux_set_callback(SELINUX_CB_LOG, cb); 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(, import_kernel_nv); get_hardware_name(hardware, &revision);
//解析ueventd.rc和ueventd.fressale.rc
ueventd_parse_config_file("/ueventd.rc"); snprintf(tmp, sizeof(tmp), "/ueventd.%s.rc", hardware);
ueventd_parse_config_file(tmp);
//设备初始化
device_init(); ufd.events = POLLIN;
ufd.fd = get_device_fd(); while() {
ufd.revents = ;
nr = poll(&ufd, , -); //循环等待
if (nr <= )
continue;
if (ufd.revents & POLLIN)
handle_device_fd(); //讲接收过来的信息进行处理
}
}
往下查看 i.mx6 Android5.1.1 初始化流程之init.rc解析
i.mx6 Android5.1.1 初始化流程之init进程(未完成)的更多相关文章
- i.mx6 Android5.1.1 初始化流程之init.rc解析(未完成)
接上一篇:i.mx6 Android5.1.1 初始化流程之init进程 参考资料:http://blog.csdn.net/mr_raptor/article/category/799879 这个博 ...
- i.mx6 Android5.1.1 初始化流程之框架
Android启动过程分为以下几个步骤: 1. Boot ROM: 上电后启动芯片固话代码. 2. BootLoader:固话代码会根据启动模式启动bootloader,(一般为启动引脚的电平的 ...
- i.mx6 Android5.1.1 servicemanager本地服务
接在之前的 i.mx6 Android5.1.1 初始化流程之init进程 i.mx6 Android5.1.1 初始化流程之init.rc解析 servicemanager是由init创建的本地服务 ...
- i.mx6 Android5.1.1 System server
1. 概述: 1. Zygote进程是Android Java世界的开创者,所有的Java应用程序进程都由Zygote进程创建: 2. Zygote创建应用程序进程过程其实就是复制自身进程地址空间作为 ...
- Android View 的绘制流程之 Layout 和 Draw 过程详解 (二)
View 的绘制系列文章: Android View 的绘制流程之 Measure 过程详解 (一) Android View 绘制流程之 DecorView 与 ViewRootImpl 在上一篇 ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(九):历史任务查询
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(八):完成个人任务
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(七):任务列表展示
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
- activiti自定义流程之Spring整合activiti-modeler5.16实例(六):启动流程
注:(1)环境搭建:activiti自定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自定义流程之Spring ...
随机推荐
- C#基础之流程控制语句详解
C#程序的执行都是一行接一行.自上而下地进行,不遗漏任何代码.为了让程序能按照开发者所设计的流程进行执行,必然需要进行条件判断.循环和跳转等过程,这就需要实现流程控制.C#中的流程控制包含了条件语句. ...
- 使用NPOI时ICSharpCode.SharpZipLib版本冲突问题解决
系统原来引用的ICSharpCode.SharpZipLib是0.84版本的, 添加了2.3版本的NPOI引用后,报版本冲突错误,因为NPOI用的ICSharpCode.SharpZipLib是0.8 ...
- TestNG参数化之@DataProvider传参
@parameters适合传递简单少量参数,复杂参数一般使用@DataProvider传递 @DataProvider语法: @DataProvider(name = "dataprovid ...
- 「NOI2014」魔法森林
题目链接 戳我 \(Solution\) 两个变量,emm...不好搞啊. 于是我们可以按照\(A\)排序.然后动态加边,因为\(A\)是越来越大,所以不需要管他,只要使得\(1\)~\(n\)的路径 ...
- nova network-vif-plugged 事件分析1
在创建虚机过程中,nova-compute会调用wait_for_instance_event函数(nova/compute/manage.py)进行network-vif-plugged的事件等待, ...
- Delphi XE7编译安卓程序出错了
昨天编译一个先前可以正常运行的程序,忽然就不能编译了,总是提示这个错误,经过一番排查,终于搞定了,原因:删除了安卓lib引用的JAR和单元文件.如果你也出现这个问题,打开工程全部目录,看一下是否有打小 ...
- 解决:sql server无法在C盘下创建database/操作系统错误5(拒绝访问)
问题: ——无法在C盘的任何位置创建数据库文件 ——在非系统盘的F盘可以创建数据库文件 解决方法1:禁用“以管理员批准模式运行所有管理员" 解决方法2:打开C盘对Users用户的完全控制权限 ...
- 【FAQ】tomcat启动jdk版本不一致
一.tomcat7.exe与startup.bat的区别: 1.这两个都可以启动tomcat,但tomcat7.exe必须安装了服务才能启动,而startup.bat不需要 2.另外一个区别是它们启动 ...
- java后台简单从阿里云上传下载文件并通知前端以附件的形式保存
一. 首先开通阿里的OSS 服务 创建一个存储空间在新建一个Bucket 在你新建的bucket有所需的id和key 获取外网访问地址或者是内网 看个人需求 我使用的是外网(内网没用过 估计是部署到阿 ...
- 算法导论-MIT笔记
第一部分 Analysis of Algorithms 算法分析是关于计算机程序性能(performance)和资源利用的理论研究 1 What's more important than perfo ...