Android init language与init.rc初始化脚本

深入分析AIL语言及init.rc文件 init.rc简介init.rc文件由系统第一个启动的init程序进行解析.它由”Android Init Language”语言编写而成.init.rc文件可以在你android设备根目录下找到.还记得我们上次编译的Android源码么?如果你已经编译过源码了,那么可以在out/target/generic/root/目录下找到该文件.要想读懂init.rc文件,首先要掌握AIL语言 阅读详情

参考: android源码目录里的system/core/init/readme.txt.

Android系统里以*.rc为扩展名为系统初始化脚本,脚本里就是使用安卓初始化语言.


语句都是一行为一条语句,没有符号分隔. 语句里的每个词用空格隔开.
如: service ueventd /sbin/ueventd

备注语句以符号”#”作为注释.

语言基本上分为4个块: Actions Commands Services 和 Options.

每个Actions和Services关键词开始的语句作为一个新的区块.
Commands和Options就是属于就近的Actions或Services块.
如:
Actions的形式:

on <trigger>
   <command>
   <command>
   <command>

Services的形式:

service <name> <pathname> [ <argument> ]*
   <option>
   <option>


rc文件里实例:

service logd /system/bin/logd
    class core
    socket logd stream 0666 logd logd
    socket logdr seqpacket 0666 logd logd
    socket logdw dgram 0222 logd logd
    group root system
     writepid /dev/cpuset/system-background/tasks

service healthd /sbin/healthd
    class core
    critical
    seclabel u:r:healthd:s0

# Actions
# on <trigger>      
on property:sys.powerctl=*
    powerctl ${sys.powerctl}

on early-init
    # Set init and its forked children's oom_adj.
    write /proc/1/oom_score_adj -1000
    # Set the security context of /adb_keys if present.
    restorecon /adb_keys
    start ueventd

每个rc文件里又可以包含其它rc文件:

import /init.environ.rc
import /init.usb.rc
import /init.${ro.hardware}.rc
import /init.usb.configfs.rc
import /init.${ro.zygote}.rc
import /init.trace.rc

Actions里常用的trigger有:

on early-init
    <command>

on init
    <command>

on late-init
    <command>

on post-fs
   <command>

on boot
   <command>

on property:sys.init_log_level=*  //在设置属性值时触发
   <command>

on charger
   <command>

on property:sys.powerctl=*
   <command>

常用的Commands有:
//参考system/core/init/keywords.h

bootchart_init
   Start bootcharting if configured (see below).
   This is included in the default init.rc.

chmod <octal-mode> <path>
   Change file access permissions.

chown <owner> <group> <path>
   Change file owner and group.

class_start <serviceclass>
   Start all services of the specified class if they are
   not already running.

class_stop <serviceclass>
   Stop and disable all services of the specified class if they are
   currently running.

class_reset <serviceclass>
   Stop all services of the specified class if they are
   currently running, without disabling them. They can be restarted
   later using class_start.

copy <src> <dst>
   Copies a file. Similar to write, but useful for binary/large
   amounts of data.

domainname <name>
   Set the domain name.

enable <servicename>
   Turns a disabled service into an enabled one as if the service did not
   specify disabled.
   If the service is supposed to be running, it will be started now.
   Typically used when the bootloader sets a variable that indicates a specific
   service should be started when needed. E.g.
     on property:ro.boot.myfancyhardware=1
        enable my_fancy_service_for_my_fancy_hardware

exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]*
   Fork and execute command with the given arguments. The command starts
   after "--" so that an optional security context, user, and supplementary
   groups can be provided. No other commands will be run until this one
   finishes. <seclabel> can be a - to denote default.

export <name> <value>
   Set the environment variable <name> equal to <value> in the
   global environment (which will be inherited by all processes
   started after this command is executed)

hostname <name>
   Set the host name.

ifup <interface>
   Bring the network interface <interface> online.

import <filename>
   Parse an init config file, extending the current configuration.

insmod <path>
   Install the module at <path>

load_all_props
   Loads properties from /system, /vendor, et cetera.
   This is included in the default init.rc.

load_persist_props
   Loads persistent properties when /data has been decrypted.
   This is included in the default init.rc.

loglevel <level>
   Sets the kernel log level to level. Properties are expanded within <level>.

mkdir <path> [mode] [owner] [group]
   Create a directory at <path>, optionally with the given mode, owner, and
   group. If not provided, the directory is created with permissions 755 and
   owned by the root user and root group. If provided, the mode, owner and group
   will be updated if the directory exists already.

mount_all <fstab>
   Calls fs_mgr_mount_all on the given fs_mgr-format fstab.

mount <type> <device> <dir> [ <flag> ]* [<options>]
   Attempt to mount the named device at the directory <dir>
   <device> may be of the form mtd@name to specify a mtd block
   device by name.
   <flag>s include "ro", "rw", "remount", "noatime", ...
   <options> include "barrier=1", "noauto_da_alloc", "discard", ... as
   a comma separated string, eg: barrier=1,noauto_da_alloc

powerctl
   Internal implementation detail used to respond to changes to the
   "sys.powerctl" system property, used to implement rebooting.

restart <service>
   Like stop, but doesn't disable the service.

restorecon <path> [ <path> ]*
   Restore the file named by <path> to the security context specified
   in the file_contexts configuration.
   Not required for directories created by the init.rc as these are
   automatically labeled correctly by init.

restorecon_recursive <path> [ <path> ]*
   Recursively restore the directory tree named by <path> to the
   security contexts specified in the file_contexts configuration.

rm <path>
   Calls unlink(2) on the given path. You might want to
   use "exec -- rm ..." instead (provided the system partition is
   already mounted).

rmdir <path>
   Calls rmdir(2) on the given path.

setprop <name> <value>
   Set system property <name> to <value>. Properties are expanded
   within <value>.

setrlimit <resource> <cur> <max>
   Set the rlimit for a resource.

start <service>
   Start a service running if it is not already running.

stop <service>
   Stop a service from running if it is currently running.

swapon_all <fstab>
   Calls fs_mgr_swapon_all on the given fstab file.

symlink <target> <path>
   Create a symbolic link at <path> with the value <target>

sysclktz <mins_west_of_gmt>
   Set the system clock base (0 if system clock ticks in GMT)

trigger <event>
   Trigger an event.  Used to queue an action from another
   action.

verity_load_state
   Internal implementation detail used to load dm-verity state.

verity_update_state <mount_point>
   Internal implementation detail used to update dm-verity state and
   set the partition.<mount_point>.verified properties used by adb remount
   because fs_mgr can't set them directly itself.

wait <path> [ <timeout> ]
   Poll for the existence of the given file and return when found,
   or the timeout has been reached. If timeout is not specified it
   currently defaults to five seconds.

write <path> <content>
   Open the file at <path> and write a string to it with write(2).
   If the file does not exist, it will be created. If it does exist,
   it will be truncated. Properties are expanded within <content>.


Services里常用的options有:

critical
  This is a device-critical service. If it exits more than four times in
  four minutes, the device will reboot into recovery mode.

disabled
  This service will not automatically start with its class.
  It must be explicitly started by name.

setenv <name> <value>
  Set the environment variable <name> to <value> in the launched process.

socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]
  Create a unix domain socket named /dev/socket/<name> and pass
  its fd to the launched process.  <type> must be "dgram", "stream" or "seqpacket".
  User and group default to 0.
  'seclabel' is the SELinux security context for the socket.
  It defaults to the service security context, as specified by seclabel or
  computed based on the service executable file security context.

user <username>
  Change to username before exec'ing this service.
  Currently defaults to root.  (??? probably should default to nobody)
  Currently, if your process requires linux capabilities then you cannot use
  this command. You must instead request the capabilities in-process while
  still root, and then drop to your desired uid.

group <groupname> [ <groupname> ]*
  Change to groupname before exec'ing this service.  Additional
  groupnames beyond the (required) first one are used to set the
  supplemental groups of the process (via setgroups()).
  Currently defaults to root.  (??? probably should default to nobody)

seclabel <seclabel>
  Change to 'seclabel' before exec'ing this service.
  Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
  Services on the system partition can instead use policy-defined transitions
  based on their file security context.
  If not specified and no transition is defined in policy, defaults to the init context.

oneshot
  Do not restart the service when it exits.

class <name>
  Specify a class name for the service.  All services in a
  named class may be started or stopped together.  A service
  is in the class "default" if one is not specified via the
  class option.

onrestart
  Execute a Command (see below) when service restarts.

writepid <file...>
  Write the child's pid to the given files when it forks. Meant for
  cgroup/cpuset usage.

实现直接使用root用户进入终端, 修改android/out/target/product/tulip-p1/root/init.rc :

574 service console /system/bin/sh
575     class core
576     console
577     disabled
578 #    user shell
579 #    group shell log
580 #    seclabel u:r:shell:s0

//备注使用shell用户进入终端. 会默认使用root用户操作


实现系统进入后执行自定义的脚本 :
修改android/out/target/product/tulip-p1/root/init.rc , 增加内容:

service start_mytest /system/bin/mytest.sh    
    oneshot
    on property:sys.boot_completed=1
    start start_mytest

在android/out/target/product/tulip-p1/system/bin目录下,增加mytest.sh, 内容:

#!/system/bin/sh

echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
echo "mytest ...!" > /dev/ttyS0
android init language trigger触发条件分析 一下所有分析均基于最新安卓系统android-4.4源码: system/core/init/init.c: INFO("reading config file\n"); init_parse_config_file("/init.rc"); action_for_each_trigger("early-init", action_add_queue_tail); 阅读详情

相关推荐

麦克风声源定位原理_声源定位—如何定位到噪声根源?

前言TPA(传递路径分析)专题系列已经开篇。其遵循方法论:源(Source)——路径(Path)——响应(Receiver)有人说TPA好,它可以识别出路径处甚至源的载荷特征,可以量化各个路径的贡献量。有人说声源定位好,不管东西南北中,“源”自其中。但是,声源定位识别出来色彩丰富的一个结果,这结果被您拿来应付工作了,还是真正帮您解决了问题?声源定位定位到了噪声的根源了么?对于一些声源现,...

weixin_39943678的博客 3973

Android init.rc on property

在 init.rc 中,可以见到下面类似的用法,当一个属性值等于XX时,触发下面的事件,比如启动一个进程 on property:sys.init_log_level=*     loglevel ${sys.init_log_level} 那么它是如何实现的,启动时触发一次?还是任何时刻只要属性值满足条件就触发?  实验验证结果: 1、启动时,如果属性满足设定条件会触发一次

漫不经心 1万+

写给音响工程师的科普文章(二)——从模电角度去了解调音台话放

    上一篇讲到调音台第一级放大电路为差分放大器,关于差分放大器的基础知识可以参考以下资料:https://wenku.baidu.com/view/e6a46aaa2af90242a995e537 在教材中的差分放大器基本形式是这样子的,在实际电路中把RE电阻换成两个2倍RE,于是变成这样 然后我们现在来对比调音台中的差分放大器和教材中的有什么区别,我就拿yamaha 01V 96来说...

huanghaoAudio的博客 7700

init.rc中设置log的打印等级loglevel

在init.rc等类似的*.rc文件中,可以用loglevel来设置printk等函数输出的log的等级,eg on early-init     loglevel 7

rockly89的博客 5036

当兵心理测试软件,当兵心理测试题及答案

心理测试是一种比较先进的测试方法,它是指通过一系列手段,将人的某些心理特征数量化,来衡量个体心理因素水平和个体心理差异差异的一种科学测量方法。小编为你整理了当兵心理测试题及答案,希望对你有所参考帮助。征兵心理测试题(1代表是2代表否)1、我的胃口很好。12、我早上起来的时候,多半觉得睡眠充足,头脑清醒13、我喜欢看报纸上的犯罪新闻。14、有时我常感到困难重重,无法克服。25、我时常遇见一些所谓的专...

weixin_42128393的博客 1万+

SAP采购信息记录批量维护实战:用BAPI ME_INFORECORD_MAINTAIN搞定价格等级和条件记录

本文深入解析SAP标准BAPI ME_INFORECORD_MAINTAIN在采购信息记录批量维护中的应用,特别聚焦价格等级和条件记录的技术难点。通过实战案例和代码示例,帮助用户高效处理供应商-物料价格数据,提升供应链管理效率。

weixin_42522320的博客 410

Linux 日志级别(loglevel)详解

前几天,我在想printk中到底是哪些信息会打印到console上,哪些东西可以通过dmesg来查看。参考了网上一些资料以及自己做的一些实验,总结一下Linux中的console loglevel以及printk, dmesg知识。 只有当printk打印信息时的loglevel小于console loglevel的值(即:优先级高于console loglevel),这些信息才会被打印到c

3390

【Hadoop】开发插件安装

前言 Eclipse 是一个开放源代码的、基于 Java 的可扩展开发平台。就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境。幸运的是Eclipse 附带了一个标准的插件集,包括 Java 开发工具(Java Development Tools,JDT)。 Eclipse的插件机制是轻型软件组件化架构。在客户机平台上,Eclipse使用插件来提供所有的附加功能,例如支持Java...

weixin_44039347的博客 3207

Linux服务器开发---简单日志系统实现

本文重点在Linux操作系统上实现日志系统,用于记录部分业务或者重要参数便于以后追查问题。logging.h#pragma once #include &lt;string.h&gt; #include "timestamp.h" #include "logstream.h" class Logger { public: enum LogLevel { TRACE, DEBUG...

游学四方的博客 748

UVM(5)-TLM通信

TLM是一种基于事务 (transaction) 的通信方式,通常在高抽象级语言例如SystemC或者SV/UVM中作为模块之间的通讯方式。

2301_76431006的博客 2106

ROS2+MoveIt2+Gazebo仿真实战:从零搭建六轴机械臂控制闭环

本文详细介绍了如何从零搭建一个完整的ROS2+MoveIt2+Gazebo六轴机械臂仿真控制闭环。通过手写URDF模型、配置MoveIt2运动规划、集成Gazebo物理仿真与ROS2 Control控制器,最终实现RViz中规划轨迹、Gazebo中同步执行的完整数字孪生验证平台,为机器人算法开发和硬件验证提供低成本、高效的仿真解决方案。

weixin_29093017的博客 484

学习笔记之进阶解密

一、Android系统启动过程 启动电源以及系统启动:当电源按下时引导芯片代码从预定义的地方(固化在ROM)开始执行。加载引导程序BootLoader到RAM中并执行 引导程序BootLoader:它是在Android操作系统开始运行前的一个小程序,其主要作用是把系统OS拉起来并运行 Linux内核启动:当内核被引导程序拉起来启动时,设置缓存、被保护存储器、计划列表、加载驱动。在内核完...

qq_27672101的博客 5058

196、NPU的编译器开发:教程与示例代码编写

NPU编译器开发实战指南 摘要:本文分享了NPU编译器开发中的核心挑战与实战经验,通过具体代码示例展示了关键实现技术: 指令生成:必须考虑硬件特性(如地址对齐)和芯片配置抽象化 图优化:重点处理常见冗余结构(Reshape合并、BN融合),并注意数值稳定性 算子拆分:采用分块计算策略适配有限SRAM,需特别注意边界条件处理 内存分配:基于张量使用频率的贪心算法优化SRAM使用效率 文中包含多个真实踩坑案例: DMA地址未对齐导致硬件错误 BN融合时的除零风险 tile边界处理不当引起的精度下降 这些经验为开

m0_50546716的博客 75

android 初始化 脚本,Android init language与init.rc初始化脚本

微信公众号:杨源鑫如果你觉得文章对你有帮助,欢迎在评论区交流讨论参考: android源码目录里的system/core/init/readme.txt.Android系统里以*.rc为扩展名为系统初始化脚本,脚本里就是使用安卓初始化语言.语句都是一行为一条语句,没有符号分隔. 语句里的每个词用空格隔开.如: service ueventd /sbin/ueventd备注语句以符号”#”作为注释....

weixin_33292780的博客 312

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Android的启动脚本–init.rc

<br />由于工作的需要,今天研究了Android的启动脚本–init.rc 。<br />在 Android中使用启动脚本init.rc可以在系统的初始化过程中进行一些简单的初始化操作。这个脚本被直接安装到目标系统的根文件系统中,被 init可执行程序解析。 init.rc是在init启动后被执行的启动脚本。<br />我们可以通过修改init.rc脚本来修改启动过程。但是,一般情况下,我们不直接修改init.rc,而是在文件 init.%PRODUCT%.rc文件中添加或修改我们需要的额外的初始化

wangyunqian6的专栏 1551

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

android boot 代码流程 2,android boot 代码流程

all story begin with the init process startup故事从 init 进程启动开始init 运行,代码:system/core/init ,入口:system/core/init/init.c main 函数:1 int main(int argc, char **argv){23 ...4 // 初始化文件系统5 mkdir("/dev", ...

weixin_42143806的博客 363

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

Android Init Language--安卓初始化语言

1、Android Init Language Android Init Language,也就是Android初始化语言,就是init.rc文件的语法 Android 初始化语言包含五种主要的语句类:Actions, Commands, Services, Options, and Imports.(操作,命令,服务,选项和导入) 所有这些都是...

PefectWorld的博客 924

android 11--- init.rc文件介绍

在Android 11中,init.rc文件是一个关键的配置文件,它负责系统的初始设置和启动流程。提示:以下是本篇文章正文内容,下面案例可供参考续行:使用反斜杠 \ 可以将一行代码分成多行。转义:使用反斜杠或双引号转义空白字符。空白字符:rc 文件中的标记由空白字符分隔。注释:以 # 开头,用于说明代码。

weixin_43129806的博客 1503

Android Init language

Android Init Language 对于大多数的Android开发者来说,Init语言使用频率应该不高; 但是阅读.rc文件对理解开机过程很有帮助,所以还是要学习下Init语言。下面的内容来自于/system/core/init目录下的readme文件,readme算是官方文档了,当作手册来用。 语法 Android Init 语言比较简单,只有五种类别的声明/语句:Actio

Dylan_Sen的博客 1587

【init.rc】Android Init Language (AIL) 语法参考手册

这是一份非常详尽的 Android Init Language (AIL) 语法参考手册。

特立独行的博客 1384

Android init.rc整理

AIL概述 init.rc由AIL语言编写而成。可以参考system/core/init/README.md来学习AIL语法相关知识。不同Android版本关于AIL的说明存在一些细微差异,但基本语法和总的思路是不变的。往往我们可以先查看对应的system/core/init/README.md来了解这些差异。 以下是我们参考Android11下的system/core/init/README.md,对AIL的学习总结。 Android Init Language由五大类语句组成:Actions, Com

愿有岁月可回首,且以深情共白头 6136

android 初始化语言,Android Init Language(安卓初始化语言)

android源码学习目录了解Android init进程的都知道,启动 init进程之前会解析init.rc文件,init.rc是Android的配置文件脚本,它由一种被称为"Android初始化语言"--Android init Language 编写。1. android init language(简称 AIL)组成动作--(Actions)命令--(Commands)服务--(Servi...

weixin_36374105的博客 372

Android rc 文件详解

作为Android系统的第一个进程,Init进程承担这很多重要的初始化任务,一般Init进程的初始化可以分为两部分,前半部分挂载文件系统,初始化属性系统和Klog, selinux的初始化等,后半部分重要通过解析init.rc来初始化系统daemon服务进程,然后以epoll的监控属性文件,系统信号等。init.rc则是init进程启动的配置脚本,这个脚本是用一种叫Android Init Language(Android初始化语言)的语言写的。如果你的进程请求Linux的特殊能力,就不要用这个命令。

yanglin10000的博客 3800

Android Init 系列专题【篇四:Init RC Language解析】

摘要:Android初始化语言(Android Init Language)是构建Native层的基础,主要包含Actions、Commands、Services等五类语句。Actions通过触发器(Trigger)激活命令序列,Services定义后台运行的服务。RC文件分布在/system、/vendor等分区,通过LOCAL_INIT_RC宏配置。APEX模块支持版本化RC文件(如init.31rc)以适应不同SDK版本。关键命令包括启动服务(class_start)、设置属性(setprop)等

qq_27672101的博客 412

Android Init Language

Android Init语言包含五种主要的语句类:Actions, Commands, Services, Options, and Imports. 所有这些都是面向行的,由用空格分隔的标记组成。C样式的反斜杠转义符可用于将空格插入token。也可以使用双引号来防止空格将文本分成多个标记。反斜杠是一行中的最后一个字符时,可用于折行。 以#开头的行(允许前导空格)是注释。 可以使用语法$ {property.name}扩展系统属性。这也适用于需要连接的上下文,例如import /init.recov.

hi_zhengjian的专栏 1576

cm-14.1 Android系统启动过程分析(4)-init进程的启动、rc脚本解析、zygote启动、属性服务

前阶段在项目中涉及到了Android系统定制任务,Android系统定制前提要知道Android系统是如何启动的。

Android系统工程师--小馬佩德罗 1万+
上一篇: 全志A64 设备树里的gpio应用开发
下一篇: 电气工程师软件笔试题
jklinux
博客等级 码龄10年 1060粉丝 276原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值