uclinux很久前笔记9

【bin/init程序解析】

在uClinux-dist/user/busybox中:

/********Init.c************/

init_main

       parse_inittab

              file = fopen(inittabs[i], "r");

// inittabs[0]= INITTAB 打开etc/inittab配置文件

//#define INITTAB  "/etc/inittab"  /* inittab file location */

              new_init_action

              ……

       run_actions(SYSINIT);

              if (a->action & (SYSINIT|WAIT|CTRLALTDEL|SHUTDOWN|RESTART)) {

                            waitfor(a);

                            delete_init_action(a);

                     } else if (a->action & ONCE) {

                            run(a);

                            delete_init_action(a);

                     } else if (a->action & (RESPAWN|ASKFIRST)) {

                            /* Only run stuff with pid==0.  If they have

                             * a pid, that means it is still running */

                            if (a->nextrun <= now) {

                                   if (a->pid == 0) {

                                          a->pid = run(a);

                                          a->lastrun = now;

                                   }

                            } else {

                                   if (alarm_delay == 0 || a->nextrun - now < alarm_delay)

                                          alarm_delay = a->nextrun - now;

                            }

                     }

              }

       run_actions(WAIT);

       run_actions(ONCE);

       while (1) {

              run_actions(RESPAWN);

              run_actions(ASKFIRST);

              wpid = wait(&status);

              while (wpid > 0) {

                     a->pid = 0;

              }

 

【inittab格式】

<id>:<runlevels>:<action>:<process>

<id>:/dev/id,用作终端

<runlevels>: The runlevels field is completely ignored.

<action>: Valid actions include: sysinit, respawn, askfirst, wait, once,

                          restart, ctrlaltdel, and shutdown.

<process>: Specifies the process to be executed and it's command line.

#If no inittab is found, it has the following default behavior:

#         ::sysinit:/etc/init.d/rcS

#         ::askfirst:/bin/sh

#         ::ctrlaltdel:/sbin/reboot

#         ::shutdown:/sbin/swapoff -a

#         ::shutdown:/bin/umount -a -r

#         ::restart:/sbin/init

在busybox中的init编译出来后是不能运行的:

/>busybox init

init started:  BusyBox v0.60.5 (2014.02.08-09:36+0000)multi-call binary

/> busybox

BusyBox v0.60.5 (2014.02.08-10:36+0000)multi-call binary

 

Usage: busybox[function] [arguments]...

  or: [function] [arguments]...

 

       BusyBox is a multi-call binary that combines many common Unix

       utilities into a single executable. Most people will create a

       link to busybox for each function they wish to use, and BusyBox

       will act like whatever it was invoked as.

 

Currently definedfunctions:

        busybox, ifconfig, init, mount,poweroff, reboot, reset, umount

/>

注意:Currently definedfunctions是在make menuconfig中的busybox菜单中选择编译进去的,由上面用法可以看出busybox可以两种用法。

【bin/init程序解析】

在uclinux中bin/init程序是在uclinux-dist/user/init/simpleinit.c

int main(int argc, char *argv[])
{
……
if(do_rc() != 0 && boot_single(1, argc, argv)&& !stopped)
       enter_single();
……
}
static int do_rc(void)
{
       intrc;
       rc = do_command(_PATH_BSHELL, _PATH_RC, 1);
// _PATH_BSHELL="/bin/sh",_PATH_RC="/etc/rc"这都被宏定义了的。
//init程序会启动sh执行/etc/rc脚本
       if(rc)
              return(rc);
#ifdef CONFIG_USER_INIT_RUN_FIREWALL
       rc= do_command(_PATH_FIREWALL, "-i", 1);
       if(rc)
              err(_PATH_FIREWALL" failed!");
#endif
#ifdef CONFIG_USER_FLATFSD_FLATFSD
       rc= do_command(_PATH_BSHELL, _PATH_CONFIGRC, 1);
       if(rc)
              err(_PATH_CONFIGRC" failed!");
#endif
#ifdef CONFIG_USER_INIT_RUN_FIREWALL
       rc= do_command(_PATH_FIREWALL, NULL, 0);
       if(rc)
              err(_PATH_FIREWALL" failed!");
#endif
……
}

uClinux v3.1.0Configuration

 ──────────────────────────────────────

  ┌──────────────── Core Applications ───────────┐

  │  Arrow keys navigate the menu.  <Enter> selects submenus --->.               │ 

  │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N>excludes,            │ 

  │  <M> modularizes features.  Press <Esc><Esc> to exit,<?> for Help.               │ 

  │  Legend: [*] built-in  [ ] excluded <M> module  < > modulecapable                   │ 

  │ ┌─────────────────────────────────┐│ 

  │ │               [*] init   注意:这是编译进内核中的应用程序         │ │ 

  │ │               [*]   enable console shell                            │ │ 

  │ │               [ ]   execute firewall rules                                              │ │ 

  │ │               (Sash) Shell Program                                     │ │ 

  │ │               [*] simple history (sash)                              │ │ 

  │ │               [ ] reboot (sash)                                     │ │ 

  │ │               [ ] SnapGear reboot script                            │ │ 

  │ │               [*] shutdown (sash)                                            │ │ 

  │ │               [*] expand                                              │ │ 

  │ │               [*]   expand should not write zeroes                   │ │ 

  │ └───────────────v(+)────────────────┘ │ 

  ├────────────────────────────────────┤ 

  │                    <Select>    < Exit >    < Help >                      │ 

  └────────────────────────────────────┘ 

   注释:该init程序位于uclinux-dist/user/init/simpleinit.c


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值