init.rc到底在做些什么

当我们只是按下电源键开机时,会进入正常启动模式。 Secondary stage bootloader 会从boot 分区开始启动。Boot 分区的格式是固定的,首先是一个头部,然后是 Linux 内核,最后是用作根文件系统的 ramdisk。
当 Linux 内核启动完毕后,就开始执行根文件系统中的 init 程序,init 程序会读取启动脚本文件(init.rc 和init.goldfish)。

现在就来说一下,init.rc到底在做些什么,我会在附件上传有关init_rc脚本语法和自己阅读是坐下到笔记,希望对各位有所帮助。
  1. on boot-pause
  2.     exec sbin/chargerlogo #运行sbin/chargerlogo(此运行在内核目录下)

  3. on early-init
  4.     start ueventd #调用sbin/uventd链接所指的可执行程序,其源码位于system/core/init/ueventd.c,为设备赋予权限

  5. on init #源码位于system/core/init/init.c
  6. #主要完成一下的工作
  7. #清空umask、创建并挂载一些基本的目录(/dev-设备、/proc-系统信息、/sys-系统信息、/dev/pts-终端控制字,用于执行adb、/dev/socket)

  8. sysclktz 0 #把硬件时钟当成本地时间(GMT时区)

  9. loglevel 3 #讲系统LOG设置成可见,0为(NONE)

  10.     write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "performance"

  11. # setup the global environment 设置全局变量
  12.     export PATH /sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin #PATH变量
  13.     export LD_LIBRARY_PATH /vendor/lib:/system/lib #库
  14.     export ANDROID_BOOTLOGO 1
  15.     export ANDROID_CACHE /cache #cache目录
  16.     export ANDROID_ROOT /system #安卓系统root分区-->/system
  17.     export ANDROID_ASSETS /system/app #安卓系统可访问到-->/system/app(这就是为什么没有root权限不能删除/system/app下到文件)
  18.     export ANDROID_DATA /data #安卓data区
  19.     export DOWNLOAD_CACHE /cache/download #下载缓存为/cache/download
  20.     export EXTERNAL_STORAGE /mnt/sdcard #附加存储-->sdcard卡
  21.     export ASEC_MOUNTPOINT /mnt/asec #asec根文件目录
  22.     export LOOP_MOUNTPOINT /mnt/obb
  23.     export SD_EXT_DIRECTORY /sd-ext #sdcard挂载格式
  24.     export BOOTCLASSPATH /system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/core-junit.jar #bootclasspath
  25.     export DSP_PATH /system/lib/dsp #dsp(数字信号处理器) path
  26.     export DEFAULT_BASEIMAGE /system/lib/dsp/baseimage.dof
  27.     export QOSDYN_FILE /system/lib/dsp/qosdyn_3430.dll64P

  28. # Backward compatibility #反向兼容,确保对以前版本到兼容?(不缺定)
  29.     symlink /system/etc /etc #在/etc下创建链接到/system/etc到链接
  30.     symlink /sys/kernel/debug /d

  31. # Right now vendor lives on the same filesystem as system,
  32. # but someday that may change.
  33.     symlink /system/vendor /vendor

  34. # create mountpoints
  35.     mkdir /mnt 0775 root system
  36.     #给system赋予0775的权限,也就是rwx-rwx-rw-现在详细解释如下
  37.     #此权限数值对应为:
  38.     #u(用户):r(读)-w(写)-x(执行)
  39.     #g(群组):r(读)-w(写)-x(执行)
  40.     #0(其他):r(读)-w(写)-
  41.     #对应到2进制数值为:
  42.     #1  1 1  :111 ---7
  43.     #1  1 1  :111 ---7
  44.     #1  1 0  :110 ---5
  45.     #
  46.     mkdir /mnt/sdcard 0000 system system

  47. # Create cgroup mount point for cpu accounting #为cpu创建
  48.     mkdir /acct
  49.     mount cgroup none /acct cpuacct
  50.     mkdir /acct/uid

  51. # Backwards Compat - XXX: Going away in G*
  52.     symlink /mnt/sdcard /sdcard

  53.     mkdir /system
  54.     mkdir /data 0771 system system
  55.     mkdir /cache 0771 system cache
  56.     mkdir /config 0500 root root

  57.     mkdir /sqlite_stmt_journals 01777 root root
  58.     mount tmpfs tmpfs /sqlite_stmt_journals size=4m

  59.     # Directory for putting things only root should see.#创建用于存放root用户才能可见到文件夹
  60.     mkdir /mnt/secure 0700 root root

  61.     # Directory for staging bindmounts #伺服器根文件目录
  62.     mkdir /mnt/secure/staging 0700 root root

  63.     # Directory-target for where the secure container
  64.     # imagefile directory will be bind-mounted
  65.     mkdir /mnt/secure/asec  0700 root root

  66.     # Secure container public mount points.
  67.     mkdir /mnt/asec  0700 root system
  68.     mount tmpfs tmpfs /mnt/asec mode=0755,gid=1000

  69.     # Filesystem image public mount points.
  70.     mkdir /mnt/obb 0700 root system
  71.     mount tmpfs tmpfs /mnt/obb mode=0755,gid=1000

  72.     mkdir /sd-ext 0771 system system

  73.     write /proc/sys/kernel/panic_on_oops 1
  74.     write /proc/sys/kernel/hung_task_timeout_secs 0
  75.     write /proc/cpu/alignment 4
  76.     write /proc/sys/kernel/sched_latency_ns 10000000
  77.     write /proc/sys/kernel/sched_wakeup_granularity_ns 2000000
  78.     write /proc/sys/kernel/sched_compat_yield 1
  79.     write /proc/sys/kernel/sched_child_runs_first 0

  80. # Create cgroup mount points for process groups
  81.     mkdir /dev/cpuctl
  82.     mount cgroup none /dev/cpuctl cpu
  83.     chown system system /dev/cpuctl
  84.     chown system system /dev/cpuctl/tasks
  85.     chmod 0777 /dev/cpuctl/tasks
  86.     write /dev/cpuctl/cpu.shares 1024

  87.     mkdir /dev/cpuctl/fg_boost
  88.     chown system system /dev/cpuctl/fg_boost/tasks
  89.     chmod 0777 /dev/cpuctl/fg_boost/tasks
  90.     write /dev/cpuctl/fg_boost/cpu.shares 1024

  91.     mkdir /dev/cpuctl/bg_non_interactive
  92.     chown system system /dev/cpuctl/bg_non_interactive/tasks
  93.     chmod 0777 /dev/cpuctl/bg_non_interactive/tasks
  94.     # 5.0 %
  95.     write /dev/cpuctl/bg_non_interactive/cpu.shares 52

  96. #[LGE_start] hyunwoong.ahn
  97.     mkdir /dvp 0771 system system
  98.     mkdir /dvp/hwkey 0771 system system
  99.     mkdir /dvp/userdata 0771 system system
  100. #[LGE_end] hyunwoong.ahn

  101.     chown system system /sys/class/leds/lcd-backlight/als

  102.     # Increase readahead buffers on MMC devices
  103.     write /sys/block/mmcblk0/bdi/read_ahead_kb 1024
  104.     write /sys/block/mmcblk1/bdi/read_ahead_kb 1024

  105. on fs
  106. # mount mtd partitions
  107.     # Mount /system rw first to give the filesystem a chance to save a checkpoint
  108.     mount ext4 /dev/block/mmcblk0p8 /system ro noatime barrier=1 wait
  109.     # We chown/chmod /data again so because mount is run as root + defaults
  110.     mount ext4 /dev/block/mmcblk0p9 /data nosuid nodev noatime barrier=1 wait
  111.     chown system system /data
  112.     chmod 0771 /data

  113. #[LGE_star]Hyunwoong.ahn^M
  114.     mount ext3 /dev/block/mmcblk0p6 /dvp/hwkey nosuid nodev
  115.     chown system system /dvp/hwkey
  116.     chown system divxdrm /dvp/hwkey/key.hw
  117.     chmod 0660 /dvp/hwkey/key.hw
  118.     mount ext3 /dev/block/mmcblk0p6 /dvp/userdata nosuid nodev
  119.     chown system divxdrm /dvp/userdata
  120.     chmod 0770 /dvp/userdata
  121.     chown system system /dev/block/mmcblk0p5
  122.     chown system system /dev/block/mmcblk0p12
  123.         chmod 0777 /dev/block/mmcblk0p5
  124.         chmod 0777 /dev/block/mmcblk0p12

  125.     mount ext4 /dev/block/mmcblk0p10 /cache nosuid nodev noatime barrier=1 wait

  126.     mkdir /lgdrm 0770 lgdrm lgdrm_acc
  127.     mount ext3 /dev/block/mmcblk0p5 /lgdrm nosuid nodev





  128. on post-fs

  129.     # once everything is setup, no need to modify /
  130.     mount rootfs rootfs / ro remount

  131.     # We chown/chmod /data again so because mount is run as root + defaults
  132.     chown system system /data
  133.     chmod 0771 /data

  134.     # Mount compressed filesystems
  135.     mount squashfs loop@/system/lib/modules/modules.sqf /system/lib/modules ro
  136.     mount squashfs loop@/system/xbin/xbin.sqf /system/xbin ro

  137.     # Create dump dir and collect dumps.
  138.     # Do this before we mount cache so eventually we can use cache for
  139.     # storing dumps on platforms which do not have a dedicated dump partition.
  140.    
  141.     mkdir /data/dontpanic
  142.     chown root log /data/dontpanic
  143.     chmod 0750 /data/dontpanic

  144.     # Collect apanic data, free resources and re-arm trigger
  145.     copy /proc/apanic_console /data/dontpanic/apanic_console
  146.     chown root log /data/dontpanic/apanic_console
  147.     chmod 0640 /data/dontpanic/apanic_console

  148.     copy /proc/apanic_threads /data/dontpanic/apanic_threads
  149.     chown root log /data/dontpanic/apanic_threads
  150.     chmod 0640 /data/dontpanic/apanic_threads

  151.     write /proc/apanic_console 1

  152.     # Same reason as /data above
  153.     chown system cache /cache
  154.     chmod 0771 /cache

  155.     # This may have been created by the recovery system with odd permissions
  156.     chown system cache /cache/recovery
  157.     chmod 0770 /cache/recovery

  158.     #change permissions on vmallocinfo so we can grab it from bugreports
  159.     chown root log /proc/vmallocinfo
  160.     chmod 0440 /proc/vmallocinfo

  161.     #change permissions on kmsg & sysrq-trigger so bugreports can grab kthread stacks
  162.     chown root system /proc/kmsg
  163.     chmod 0440 /proc/kmsg
  164.     chown root system /proc/sysrq-trigger
  165.     chmod 0220 /proc/sysrq-trigger

  166. # create basic filesystem structure
  167.     mkdir /data/misc 01771 system misc
  168.     mkdir /data/misc/bluetoothd 0770 bluetooth bluetooth
  169.     mkdir /data/misc/bluetooth 0770 system system
  170.     mkdir /data/misc/keystore 0700 keystore keystore
  171.     mkdir /data/misc/vpn 0770 system system
  172.     mkdir /data/misc/systemkeys 0700 system system
  173.     mkdir /data/misc/vpn/profiles 0770 system system
  174.     # give system access to wpa_supplicant.conf for backup and restore
  175.     mkdir /data/misc/wifi 0770 wifi wifi
  176.     chmod 0770 /data/misc/wifi
  177.     chmod 0660 /data/misc/wifi/wpa_supplicant.conf
  178.     mkdir /data/local 0771 shell shell
  179.     mkdir /data/local/tmp 0771 shell shell
  180.     mkdir /data/local/download 0771 system cache
  181.     mkdir /data/data 0771 system system
  182.     mkdir /data/app-private 0771 system system
  183.     mkdir /data/app 0771 system system
  184.     mkdir /data/property 0700 root root

  185.     mkdir /cache/download 0771 system cache

  186.     # create dalvik-cache and double-check the perms
  187.     mkdir /data/dalvik-cache 0771 system system
  188.     chown system system /data/dalvik-cache
  189.     chmod 0771 /data/dalvik-cache

  190.     mkdir /cache/dalvik-cache 0771 system system
  191.     chown system system /cache/dalvik-cache
  192.     chmod 0771 /cache/dalvik-cache

  193.     # create the lost+found directories, so as to enforce our permissions
  194.     mkdir /data/lost+found 0770
  195.     mkdir /cache/lost+found 0770

  196.     # double check the perms, in case lost+found already exists, and set owner
  197.     chown root root /data/lost+found
  198.     chmod 0770 /data/lost+found
  199.     chown root root /cache/lost+found
  200.     chmod 0770 /cache/lost+found

  201.     # allow net_raw to have access to /dev/socket directory
  202.     chown root net_raw /dev/socket
  203.     chmod 0775 /dev/socket

  204.     # allow system to modify cpufreq control files
  205.     chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
  206.     chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
  207.     chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
  208.     chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
  209.     chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
  210.     chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq

  211.     chmod 0777 /data/misc/wifi/config_mac
  212.     mkdir /data/misc/wifi/sockets 0770 wifi wifi
  213.     mkdir /data/misc/dhcp 0777 dhcp dhcp
  214.     setprop wifi.supplicant_scan_interval 20
  215.     setprop wifi.interface wlan0

  216. on boot
  217. # basic network init
  218.     ifup lo
  219.     hostname localhost
  220.     domainname localdomain

  221. # set RLIMIT_NICE to allow priorities from 19 to -20
  222.     setrlimit 13 40 40

  223. # Define the oom_adj values for the classes of processes that can be
  224. # killed by the kernel.  These are used in ActivityManagerService.
  225.     setprop ro.FOREGROUND_APP_ADJ 0
  226.     setprop ro.VISIBLE_APP_ADJ 1
  227.     setprop ro.PERCEPTIBLE_APP_ADJ 2
  228.     setprop ro.HEAVY_WEIGHT_APP_ADJ 3
  229.     setprop ro.SECONDARY_SERVER_ADJ 4
  230.     setprop ro.BACKUP_APP_ADJ 5
  231.     setprop ro.HOME_APP_ADJ 6
  232.     setprop ro.HIDDEN_APP_MIN_ADJ 7
  233.     setprop ro.EMPTY_APP_ADJ 15

  234. # Define the memory thresholds at which the above process classes will
  235. # be killed.  These numbers are in pages (4k).
  236.     setprop ro.FOREGROUND_APP_MEM 2048
  237.     setprop ro.VISIBLE_APP_MEM 3072
  238.     setprop ro.PERCEPTIBLE_APP_MEM 4096
  239.     setprop ro.HEAVY_WEIGHT_APP_MEM 4096
  240.     setprop ro.SECONDARY_SERVER_MEM 6144
  241.     setprop ro.BACKUP_APP_MEM 6144
  242.     setprop ro.HOME_APP_MEM 6144
  243.     setprop ro.HIDDEN_APP_MEM 7168
  244.     setprop ro.EMPTY_APP_MEM 8192

  245. # Write value must be consistent with the above properties.
  246. # Note that the driver only supports 6 slots, so we have combined some of
  247. # the classes into the same memory level; the associated processes of higher
  248. # classes will still be killed first.
  249.     write /sys/module/lowmemorykiller/parameters/adj 0,1,2,4,7,15

  250.     write /proc/sys/vm/overcommit_memory 1
  251.     write /proc/sys/vm/min_free_order_shift 4
  252.     write /sys/module/lowmemorykiller/parameters/minfree 2048,3072,4096,6144,7168,8192

  253.     # Set init its forked children's oom_adj.
  254.     write /proc/1/oom_adj -16

  255.     # Tweak background writeout
  256.     write /proc/sys/vm/dirty_expire_centisecs 200
  257.     write /proc/sys/vm/dirty_background_ratio  5

  258.     # Permissions for System Server and daemons.
  259.     chown radio system /sys/android_power/state
  260.     chown radio system /sys/android_power/request_state
  261.     chown radio system /sys/android_power/acquire_full_wake_lock
  262.     chown radio system /sys/android_power/acquire_partial_wake_lock
  263.     chown radio system /sys/android_power/release_wake_lock
  264.     chown radio system /sys/power/state
  265.     chown radio system /sys/power/wake_lock
  266.     chown radio system /sys/power/wake_unlock
  267.     chmod 0660 /sys/power/state
  268.     chmod 0660 /sys/power/wake_lock
  269.     chmod 0660 /sys/power/wake_unlock
  270.     chown system system /sys/class/timed_output/vibrator/enable
  271.     chown system system /sys/class/leds/keyboard-backlight/brightness
  272.     chown system system /sys/class/leds/lcd-backlight/brightness
  273.     chown system system /sys/class/leds/button-backlight/brightness
  274.     chown system system /sys/class/leds/jogball-backlight/brightness
  275.     chown system system /sys/class/leds/red/brightness
  276.     chown system system /sys/class/leds/green/brightness
  277.     chown system system /sys/class/leds/blue/brightness
  278.     chown system system /sys/class/leds/red/device/grpfreq
  279.     chown system system /sys/class/leds/red/device/grppwm
  280.     chown system system /sys/class/leds/red/device/blink
  281.     chown system system /sys/class/leds/red/brightness
  282.     chown system system /sys/class/leds/green/brightness
  283.     chown system system /sys/class/leds/blue/brightness
  284.     chown system system /sys/class/leds/red/device/grpfreq
  285.     chown system system /sys/class/leds/red/device/grppwm
  286.     chown system system /sys/class/leds/red/device/blink
  287.     chown system system /sys/class/timed_output/vibrator/enable
  288.     chown system system /sys/module/sco/parameters/disable_esco
  289.     chown system system /sys/kernel/ipv4/tcp_wmem_min
  290.     chown system system /sys/kernel/ipv4/tcp_wmem_def
  291.     chown system system /sys/kernel/ipv4/tcp_wmem_max
  292.     chown system system /sys/kernel/ipv4/tcp_rmem_min
  293.     chown system system /sys/kernel/ipv4/tcp_rmem_def
  294.     chown system system /sys/kernel/ipv4/tcp_rmem_max
  295.     chown root radio /proc/cmdline

  296. # Define TCP buffer sizes for various networks
  297. #   ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,
  298.     setprop net.tcp.buffersize.default 4096,87380,110208,4096,16384,110208
  299.     setprop net.tcp.buffersize.wifi    4095,87380,110208,4096,16384,110208
  300.     setprop net.tcp.buffersize.umts    4094,87380,110208,4096,16384,110208
  301.     setprop net.tcp.buffersize.edge    4093,26280,35040,4096,16384,35040
  302.     setprop net.tcp.buffersize.hspa    4094,87380,110208,4096,16384,110208
  303.     setprop net.tcp.buffersize.gprs    4092,8760,11680,4096,8760,11680

  304.     chmod 0660 /sys/class/rfkill/rfkill0/state
  305.     chmod 0660 /sys/class/rfkill/rfkill0/type
  306.     chmod 0660 /sys/class/rfkill/rfkill1/state
  307.     chmod 0660 /sys/class/rfkill/rfkill1/type
  308.     chmod 0666 /sys/devices/platform/bd_address/bdaddr_if
  309.     chown bluetooth bluetooth /sys/class/rfkill/rfkill0/state
  310.     chown bluetooth bluetooth /sys/class/rfkill/rfkill0/type
  311.     chown bluetooth bluetooth /sys/class/rfkill/rfkill1/state
  312.     chown bluetooth bluetooth /sys/class/rfkill/rfkill1/type
  313.     write /sys/class/rfkill/rfkill0/state 0

  314.     chown system system /sys/devices/platform/motion_sensor/accel_onoff
  315.     chown system system /sys/devices/platform/motion_sensor/accel_delay
  316.     chown system system /sys/devices/platform/motion_sensor/compass_onoff
  317.     chown system system /sys/devices/platform/motion_sensor/compass_delay
  318.     chown system system /sys/devices/platform/motion_sensor/tilt_onoff
  319.     chown system system /sys/devices/platform/motion_sensor/tilt_delay
  320.     chown system system /sys/devices/platform/motion_sensor/gyro_onoff
  321.     chown system system /sys/devices/platform/motion_sensor/gyro_delay
  322.     chown system system /sys/bus/i2c/drivers/hub_proxi/3-0044/onoff
  323.     chown system system /sys/bus/i2c/drivers/hub_proxi/3-0044/delay
  324.     chown system system /sys/devices/platform/motion_sensor/shake_onoff
  325.     chown system system /sys/bus/i2c/drivers/kxtf9/3-000f/shake_onoff
  326.     chown system system /sys/devices/platform/motion_sensor/snap_onoff
  327.     chown system system /sys/bus/i2c/drivers/kxtf9/3-000f/snap_onoff
  328.     chown system system /sys/devices/platform/motion_sensor/flip_onoff
  329.     chown system system /sys/bus/i2c/drivers/kxtf9/3-000f/flip_onoff
  330.     chown system system /sys/devices/platform/motion_sensor/tap_onoff
  331.     chown system system /sys/bus/i2c/drivers/kxtf9/3-000f/tap_onoff
  332.     chown system system /sys/devices/platform/motion_sensor/yawimage_onoff
  333.     chown system system /sys/devices/platform/i2c-gpio.7/i2c-adapter/i2c-7/7-001c/checkresult
  334.     chown system system /sys/devices/platform/i2c-gpio.7/i2c-adapter/i2c-7/7-001c/checkopmode
  335.     chmod 0666 /sys/devices/platform/motion_sensor/accel_onoff
  336.     chmod 0666 /sys/devices/platform/motion_sensor/accel_delay
  337.     chmod 0666 /sys/devices/platform/motion_sensor/compass_onoff
  338.     chmod 0666 /sys/devices/platform/motion_sensor/compass_delay
  339.     chmod 0666 /sys/devices/platform/motion_sensor/tilt_onoff
  340.     chmod 0666 /sys/devices/platform/motion_sensor/tilt_delay
  341.     chmod 0666 /sys/devices/platform/motion_sensor/gyro_onoff
  342.     chmod 0666 /sys/devices/platform/motion_sensor/gyro_delay
  343.     chmod 0666 /sys/bus/i2c/drivers/hub_proxi/3-0044/onoff
  344.     chmod 0666 /sys/bus/i2c/drivers/hub_proxi/3-0044/delay
  345.     chmod 0666 /sys/devices/platform/motion_sensor/shake_onoff
  346.     chmod 0666 /sys/bus/i2c/drivers/kxtf9/3-000f/shake_onoff
  347.     chmod 0666 /sys/devices/platform/motion_sensor/snap_onoff
  348.     chmod 0666 /sys/bus/i2c/drivers/kxtf9/3-000f/snap_onoff
  349.     chmod 0666 /sys/devices/platform/motion_sensor/flip_onoff
  350.     chmod 0666 /sys/bus/i2c/drivers/kxtf9/3-000f/flip_onoff
  351.     chmod 0666 /sys/devices/platform/motion_sensor/tap_onoff
  352.     chmod 0666 /sys/bus/i2c/drivers/kxtf9/3-000f/tap_onoff
  353.     chmod 0666 /sys/devices/platform/motion_sensor/yawimage_onoff
  354.     chmod 0666 /sys/devices/platform/i2c-gpio.7/i2c-adapter/i2c-7/7-001c/checkresult
  355.     chmod 0666 /sys/devices/platform/i2c-gpio.7/i2c-adapter/i2c-7/7-001c/checkopmode

  356.     chmod 0666 /sys/devices/platform/omapdss/display0/name
  357.     chmod 0666 /sys/devices/platform/omapdss/display1/name
  358.     chmod 0666 /sys/devices/platform/omapdss/display0/enabled
  359.     chmod 0666 /sys/devices/platform/omapdss/display1/enabled
  360.     chmod 0666 /sys/devices/platform/omapdss/display0/timings
  361.     chmod 0666 /sys/devices/platform/omapdss/display1/timings
  362.     chmod 0666 /sys/devices/platform/omapdss/overlay0/manager
  363.     chmod 0666 /sys/devices/platform/omapdss/overlay1/manager
  364.     chmod 0666 /sys/devices/platform/omapdss/overlay2/manager
  365.     chmod 0666 /sys/devices/platform/omapdss/overlay0/zorder
  366.     chmod 0666 /sys/devices/platform/omapdss/overlay1/zorder
  367.     chmod 0666 /sys/devices/platform/omapdss/overlay2/zorder
  368.     chmod 0666 /sys/devices/platform/omapdss/overlay0/enabled
  369.     chmod 0666 /sys/devices/platform/omapdss/overlay1/enabled
  370.     chmod 0666 /sys/devices/platform/omapdss/overlay2/enabled
  371.     chmod 0666 /sys/devices/platform/omapdss/manager0/display
  372.     chmod 0666 /sys/devices/platform/omapdss/manager1/display
  373.     chmod 0666 /sys/devices/platform/omapdss/manager0/trans_key_enabled
  374.     chmod 0666 /sys/devices/platform/omapdss/manager1/trans_key_enabled
  375.     chmod 0666 /sys/devices/platform/omapdss/manager0/trans_key_type
  376.     chmod 0666 /sys/devices/platform/omapdss/manager1/trans_key_type
  377.     chmod 0666 /sys/devices/platform/omapdss/manager0/trans_key_value
  378.     chmod 0666 /sys/devices/platform/omapdss/manager1/trans_key_value
  379.     chmod 0666 /sys/devices/platform/omapdss/manager0/alpha_blending_enabled
  380.     chmod 0666 /sys/devices/platform/omapdss/manager1/alpha_blending_enabled
  381.     write /sys/devices/platform/omapdss/manager0/alpha_blending_enabled 1

  382. # MMS: Create log directory for fw3a_core
  383.     mkdir /data/log/fw3A 0775 root root

  384. # change permissions for alsa nodes
  385.     symlink /dev/snd/pcmC0D0c /dev/pcmC0D0c
  386.     symlink /dev/snd/pcmC0D0p /dev/pcmC0D0p
  387.     symlink /dev/snd/controlC0 /dev/controlC0
  388.     symlink /dev/snd/timer /dev/timer
  389.     chmod 0777 /dev/pcmC0D0c
  390.     chmod 0777 /dev/pcmC0D0p
  391.     chmod 0777 /dev/controlC0
  392.     chmod 0777 /dev/timer

  393.     chmod 0664 /sys/devices/platform/i2c_omap.2/i2c-2/2-0060/leds/lcd-backlight/als
  394.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-0060/leds/lcd-backlight/als

  395.     # Batt gauge error detection
  396.     chmod 0666 /sys/bus/platform/drivers/twl4030_bci/twl4030_bci/gauge_if

  397.     # Enabling sleep in idle path
  398.     write /sys/power/sleep_while_idle 1

  399.     # Enabling Off mode
  400.     write /sys/power/enable_off_mode 1

  401.     # Enabling voltage off while idle
  402.     write /sys/power/voltage_off_while_idle 1

  403.     # Permissions for setting the DSP Frequency
  404.     chown media root /sys/power/dsp_freq
  405.     chown media system /sys/devices/platform/omap3isp/isp_reserve

  406. # Include extra init file
  407.     import /system/etc/init.local.rc

  408. # gps permissions
  409.     chown system system /sys/devices/platform/hub_gps_gpio/poweron
  410.     chown system system /sys/devices/platform/hub_gps_gpio/reset
  411.     mkdir /data/gps
  412.     chmod 777 /data/gps
  413.     mkdir /data/gps/var
  414.     chmod 777 /data/gps/var
  415.     mkdir /data/gps/var/run
  416.     chmod 777 /data/gps/var/run
  417.     mkdir /data/gps/log
  418.     chmod 777 /data/gps/log
  419.     mkdir /data/cache
  420.     chmod 777 /data/cache

  421.     ## Torch perms
  422.     chown system camera /sys/class/leds/rt8515/brightness
  423.     chmod 0660 /sys/class/leds/rt8515/brightness

  424.     ## liblights
  425.     chown system system /sys/class/leds/lcd-backlight/brightness
  426.     chown system system /sys/class/leds/lcd-backlight/onoff
  427.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/led_brightness
  428.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/led_onoff
  429.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/led_sync
  430.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/blink_enable
  431.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x06
  432.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x07
  433.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x0D
  434.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x0E
  435.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x10
  436.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x11
  437.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x03
  438.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x04
  439.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x09
  440.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x0A
  441.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x13
  442.     chown system system /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/0x14

  443. # Run sysinit
  444.     exec /system/bin/sysinit

  445.     class_start default

  446. ## Daemon processes to be run by init.
  447. ##
  448. service ueventd /sbin/ueventd
  449.     critical

  450. service prb /sbin/prb
  451.     user root
  452.     disabled
  453.     oneshot
  454.     keycodes 114 116

  455. service console /system/bin/sh
  456.     console
  457.     disabled
  458.     user shell
  459.     group log

  460. on property:ro.secure=0
  461.     start console

  462. # adbd is controlled by the persist.service.adb.enable system property
  463. service adbd /sbin/adbd
  464.     disabled

  465. # adbd on at boot in emulator
  466. on property:ro.kernel.qemu=1
  467.     start adbd

  468. on property:persist.service.adb.enable=1
  469.     start adbd

  470. on property:persist.service.adb.enable=0
  471.     stop adbd

  472. service pvrsrvinit /system/bin/pvrsrvinit
  473.         user root
  474.         oneshot

  475. # load DSP firmware 防火墙
  476. service baseimage /system/bin/cexec.out /system/lib/dsp/baseimage.dof
  477.     user root
  478.     group audio
  479.     oneshot

  480. service fw3a /system/bin/fw3a_core --dbgport=6660 --dbgremote --dbgpath=/data/log/fw3A
  481.     user root
  482.     group root

  483. service servicemanager /system/bin/servicemanager
  484.     user system
  485.     critical
  486.     onrestart restart zygote
  487.     onrestart restart media

  488. service vold /system/bin/vold
  489.     socket vold stream 0660 root mount
  490.     ioprio be 2

  491. service netd /system/bin/netd
  492.     socket netd stream 0660 root system
  493.     socket dnsproxyd stream 0660 root inet

  494. service debuggerd /system/bin/debuggerd

  495. service ril-daemon /system/bin/rild
  496.     socket rild stream 660 root radio
  497.     socket rild-debug stream 660 radio system
  498.     user root
  499.     group radio cache inet misc audio sdcard_rw net_admin net_raw

  500. service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
  501.     socket zygote stream 666
  502.     onrestart write /sys/android_power/request_state wake
  503.     onrestart write /sys/power/state on
  504.     onrestart restart media
  505.     onrestart restart netd

  506. service media /system/bin/mediaserver
  507.     user media
  508.     group system audio camera graphics inet net_bt net_bt_admin net_raw
  509.     ioprio rt 4

  510. service bootanim /system/bin/bootanimation
  511.     user graphics
  512.     group graphics
  513.     disabled
  514.     oneshot

  515. service dbus /system/bin/dbus-daemon --system --nofork
  516.     socket dbus stream 660 bluetooth bluetooth
  517.     user bluetooth
  518.     group bluetooth net_bt_admin

  519. service bluetoothd /system/bin/bluetoothd -n
  520.     socket bluetooth stream 660 bluetooth bluetooth
  521.     socket dbus_bluetooth stream 660 bluetooth bluetooth
  522.     # init.rc does not yet support applying capabilities, so run as root and
  523.     # let bluetoothd drop uid to bluetooth with the right linux capabilities
  524.     group bluetooth net_bt_admin misc
  525.     disabled

  526. service hfag /system/bin/sdptool add --channel=10 HFAG
  527.     user bluetooth
  528.     group bluetooth net_bt_admin
  529.     disabled
  530.     oneshot

  531. service hsag /system/bin/sdptool add --channel=11 HSAG
  532.     user bluetooth
  533.     group bluetooth net_bt_admin
  534.     disabled
  535.     oneshot

  536. service opush /system/bin/sdptool add --channel=12 OPUSH
  537.     user bluetooth
  538.     group bluetooth net_bt_admin
  539.     disabled
  540.     oneshot

  541. service pbap /system/bin/sdptool add --channel=19 PBAP
  542.     user bluetooth
  543.     group bluetooth net_bt_admin
  544.     disabled
  545.     oneshot

  546. service installd /system/bin/installd
  547.     socket installd stream 600 system system

  548. service racoon /system/bin/racoon
  549.     socket racoon stream 600 system system
  550.     # racoon will setuid to vpn after getting necessary resources.
  551.     group net_admin
  552.     disabled
  553.     oneshot

  554. service mtpd /system/bin/mtpd
  555.     socket mtpd stream 600 system system
  556.     user vpn
  557.     group vpn net_admin net_raw
  558.     disabled
  559.     oneshot

  560. service keystore /system/bin/keystore /data/misc/keystore
  561.     user keystore
  562.     group keystore
  563.     socket keystore stream 666

  564. service dumpstate /system/bin/dumpstate -s
  565.     socket dumpstate stream 0660 shell log
  566.     disabled
  567.     oneshot
  568. #开启GPS服务,配置文件位置位于:/system/etc/gps_brcm_conf.xml
  569. service glgps /system/bin/glgps -c /system/etc/gps_brcm_conf.xml
  570.     user root
  571.     group system

  572. on property:dev.bootcomplete=1
  573.     write /sys/devices/platform/i2c_omap.2/i2c-2/2-001a/blink_enable 0
  574.     write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor "interactive"
  575.     #write /sys/devices/system/cpu/cpu0/cpufreq/ondemand/up_threshold 90
  576.     #write /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate 40000
  577.     write /sys/devices/system/cpu/cpu0/cpufreq/turn_on_lg_dvfs 1

  578. service dhcpcd_wlan0 /system/bin/dhcpcd -BKA wlan0
  579.     disabled
  580.     oneshot

  581. service iprenew_wlan0 /system/bin/dhcpcd -n wlan0
  582.     disabled
  583.     oneshot

  584. on property:init.svc.wpa_supplicant=stopped
  585.     stop dhcpcd_wlan0

  586. service wpa_supplicant /system/bin/wpa_supplicant -Dwext -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf #-dd
  587.     socket wpa_wlan0 dgram 660 wifi wifi
  588.     group system wifi inet
  589.     disabled

  590. service hciattach /system/bin/brcm_patchram_plus --enable_hci --enable_lpm \
  591.     --baudrate 3000000 --patchram /etc/firmware/BCM43291A0_003.001.013.0066.xxxx_B-Project.hcd /dev/ttyO1
  592.     user bluetooth
  593.     group bluetooth net_bt_admin
  594.     disabled

  595. service rawip_vsnet1 /system/bin/init.vsnet 1
  596.    user root
  597.    group radio cache inet misc
  598.    disabled
  599.    oneshot

  600. service wlan_precheck /system/bin/wlan-precheck
  601.     oneshot
复制代码

++++++++++++++++++++++++++++++++++++++++语法+++++++++++++++++++++++++++++++++++++++++++++++++++
  1. system/core/init/readme.txt(此文也是对init.rc 的解释)内容不同:
  2. socket <name> <type> <perm> [ <user> [ <group> ] ]
  3. -----------------------------------------------

  4. 注1:另外还讲述了怎样输出log:


  5. Debugging notes
  6. ---------------
  7. By default, programs executed by init will drop stdout and stderr into
  8. /dev/null. To help with debugging, you can execute your program via the
  9. Andoird program logwrapper. This will redirect stdout/stderr into the
  10. Android logging system (accessed via logcat).
  11. For example
  12. service akmd /system/bin/logwrapper /sbin/akmd
  13. 注2:讲述了一个新的命令




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



  16. 注3:triggers



  17. boot
  18.    This is the first trigger that will occur when init starts
  19.    (after /init.conf is loaded)
  20. <name>=<value>
  21.    Triggers of this form occur when the property <name> is set
  22.    to the specific value <value>.
  23. device-added-<path>
  24. device-removed-<path>
  25.    Triggers of these forms occur when a device node is added
  26.    or removed.
  27. service-exited-<name>
  28.    Triggers of this form occur when the specified service exits.
  29. ------------------------------------------





  30. init 由如下四种类型语句组成:

  31. Actionn       :行为
  32. Commands  
  33. Services
  34. Options
  35. 语法(language syntax)结构如下:


  36. 每一个语句占据一行,并且各个关键字被空格分开。c规范中的(如 /n)反斜杠将被忽略(backslash escapes)而被认为是一个空格 ,双引号用来保证空格不会把一个文字串分分为多个关键字。行最后的反斜杠用作续行。
  37. 由 # (前面允许有空格)开始的行都是注释行(comment)
  38. 一个actions 或 services 的开始隐含声明了一个新的段,所有commands 或 options 属于最近的声明。在第一个段之前的 commands 或 options 都会被忽略
  39. 每一个actions 和 services 都有不同的名字。后面与前面发生重名的,那么这个后面重名的将被忽略或被认为是一个错误
  40. Actions
  41. Actions其实就是一组被命名的命令序列。actions 都有一个触发条件,触发条件决定了action何时执行。当一个事件发生如果匹配action的触发条件,那么这个action将会被添加到预备执行队列的尾部(除非它已经在队列当中)

  42. 每一个action中的命令将被顺序执行。init进程负责在其它activities(如:设备创建/销毁,属性设置,进程重启)之间执行这些命令序列。



  43. action 的格式如下
  44. on <trigger>
  45.   <command>
  46.   <command>
  47.   <command>


  48. Services

  49. services 是一些由init 启动 和 重新(如果有需要)启动的程序,当然这些程序如果是存在的。




  50. services 的格式如下:
  51. service <name> <pathname> [ <argument> ]*
  52.   <option>
  53.   <option>
  54.   ...




  55. Options

  56. options 是service的修饰符,用来告诉init 怎样及何时启动service。



  57. Option        Description
  58. disabled        This service will not automatically start with its class. It must be explicitly started by name.
  59. socket <type> <name> <perm> [ <user> [ <group> ] ]       
  60. Create a unix domain socket named /dev/socket/<name> and pass its fd to the launched process. Valid <type>dgram and stream. user and group default to 0.(type 实际中是放在name之后)

  61. values include
  62. user <username>        Change to username before exec'ing this service. Currently defaults to root.
  63. group <groupname> [ <groupname> ]*        Change to groupname before exec'ing this service.  Additional  groupnames beyond the first, which is required, are used to set additional groups of the process (with setgroups()). Currently defaults to root.
  64. capability [ <capability> ]+        Set linux capability before exec'ing this service
  65. oneshot        Do not restart the service when it exits.
  66. class <name>        Specify a class name for the service.  All services in a named class must start and stop together. A service is considered of class "default" if one is not specified via the class option.




  67. Triggers

  68. Triggers are strings used to match certain kinds of events that cause an action to occur.

  69. Trigger        Description
  70. boot        This is the first trigger that occurs when init starts (after /init.conf is loaded).
  71. <name>=<value>        Triggers of this form occur when the property <name> is set to the specific value <value>.
  72. device-added-<path>
  73. device-removed-<path>        Triggers of these forms occur when a device node is added or removed.
  74. service-exited-<name>        Triggers of this form occur when the specified service exits.

  75. Commands

  76. Command        Description
  77. exec <path> [ <argument> ]*        Fork and execute a program (<path>). This will block until the program completes execution. Try to avoid exec. Unlike the builtin commands, it runs the risk of getting init "stuck".
  78. 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).
  79. ifup <interface>        Bring the network interface <interface> online.
  80. import <filename>        Parse an init config file, extending the current configuration.
  81. hostname <name>        Set the host name.
  82. class_start <serviceclass>        Start all services of the specified class if they are not already running.
  83. class_stop <serviceclass>        Stop all services of the specified class if they are currently running.
  84. domainname <name>        Set the domain name.
  85. insmod <path>        Install the module at <path>.
  86. mkdir <path>        Make a directory at <path>.
  87. mount <type> <device> <dir> [ <mountoption> ]*        Attempt to mount the named device at the directory <dir> <device>. This may be of the form mtd@name to specify a mtd block device by name.
  88. setkey        - currenlty undefined -
  89. setprop <name> <value>        Set system property <name> to <value>.
  90. setrlimit <resource> <cur> <max>        Set the rlimit for a resource.
  91. start <service>        Start a service running if it is not already running.
  92. stop <service>        Stop a service from running if it is currently running.
  93. symlink <target> <path>        Create a symbolic link at <path> with the value <target>.
  94. write <path> <string> [ <string> ]*        Open the file at <path> and write one or more strings to it with write(2).
  95. Properties

  96. Init updates some system properties to provide some insight into
  97. what it's doing:
  98. Property        Description
  99. init.action        Equal to the name of the action currently being executed or "" if none.
  100. init.command        Equal to the command being executed or "" if none.
  101. init.svc.<name>        State of a named service ("stopped", "running", or "restarting").
  102. 在init.rc中使用属性的范例如下:



  103. setprop ro.FOREGROUND_APP_MEM 1536

  104. setprop ro.VISIBLE_APP_MEM 2048

  105. on property:ro.kernel.qemu=1

  106. start adbd

  107. setprop用于设置属性,on property可以用于判断属性,这里的属性在整个Android系统运行中都是一致的。



  108. init脚本中的关键字可以参考:system/core/init/keywords.h

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值