//busybox/init.c
1.init_main过程分析
init_main
parse_inittab();
file = fopen(INITTAB, "r"); //#define INITTAB "/etc/inittab" /* inittab file location */
new_init_action(a->action, command, id); //1.创建一个init-action结构,填充
//2.加入init_action_list链表
run_actions(SYSINIT);
waitfor(a, 0);
run(a);
waitpid(runpid, &status, 0);
delete_init_action(a);
run_actions(WAIT);
waitfor(a, 0);
run(a);
waitpid(runpid, &status, 0);
delete_init_action(a);
run_actions(ONCE);
run(a);
delete_init_action(a);
while (1) {
run_actions(RESPAWN);
if (a->pid == 0) {
a->pid = run(a);/
run_actions(ASKFIRST);
if (a->pid == 0) {
a->pid = run(a);
"\nPlease press Enter to activate this console. ";
wpid = wait(NULL);
while (wpid > 0) {
a->pid = 0;
}
}
}
2.new_init_action举例分析
new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
new_init_action(ASKFIRST, "-/bin/sh", "/dev/tty2");
//查找init_action_list中是否已经存在要添加的init_action结构
//存在,则覆盖
for (a = last = init_action_list; a; a = a->next) {
/* don't enter action if it's already in the list,
* but do overwrite existing actions */
if ((strcmp(a->command, command) == 0)
&& (strcmp(a->terminal, cons) == 0)
) {
a->action = action;
return;
}
last = a;
}
//不存在,则创建
new_action = xzalloc(sizeof(struct init_action));
if (last) {
last->next = new_action;
} else {
init_action_list = new_action;
}
#define LIBBB_DEFAULT_LOGIN_SHELL "-/bin/sh"
const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL;
# define VC_2 "/dev/tty2"
#define ASKFIRST 0x004
3.inittab格式
# Format for each entry: <id>:<runlevels>:<action>:<process>
# <id> :The contents of this field are appended to "/dev/" and used as-is.
# <action>: Valid actions include: sysinit, respawn, askfirst, wait, once,
# restart, ctrlaltdel, and shutdown.
# <process>: Specifies the process to be executed and its command line.
4.编译、安装busybox
#make menuconfig
出错:提示Makefile:1449: *** mixed implicit and normal rules. Stop.
解决:/*翻译为中文:混合的和隐含普通规则
是由于我的系统的make工具太新(系统:fedora15),make的旧版规则已经无法兼容新版。
按照以下方式,问题得到解决:
修改前:416行 config %config: scripts_basic outputmakefile FORCE
修改后:416 行 %config: scripts_basic outputmakefile FORCE
修改前:1449 行 / %/: prepare scripts FORCE
修改后:1449 行 %/: prepare scripts FORCE*/
出错:error: field 'in' has incomplete type
解决:arm-linux 交叉编译工具链
在 usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include/linux/netfilter.h 头文件的开头
添加缺少的头文件:
#include <netinet/in.h>
出错:undefined reference to `__cpu_to_be16
解决:修改 networking/libiproute/iptunnel.c文件
在#include <asm/types.h>
后面加上
#include <asm/byteorder.h>
#make CONFIG_PREFIX=/home/invoker/busybox/myfilesystem/ install
#cd /home/invoker/busybox/myfilesystem/
#ls
bin linuxrc sbin usr
# mkdir dev
# cd dev/
# ls /dev/console /dev/null -l
crw-------. 1 root root 5, 1 12月 4 11:51 /dev/console
crw-rw-rw-. 1 root root 1, 3 12月 4 11:50 /dev/null
# mknod console c 5 1
# mknod null c 1 3
[root@localhost dev]# ls // dev/console /dev/null
console null
//安装gibc库
[root@localhost myfilesystem]# mkdir lib
[root@localhost myfilesystem]# ls
bin dev etc lib linuxrc sbin usr
[root@localhost myfilesystem]# cd /home/invoker/tools/opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/lib
[root@localhost lib]# cp *.so* /home/invoker/busybox/myfilesystem/lib -d
//到此可以生成最小文件系统
//制作yaffs2文件系统
出错:starting pid 755, tty '': '/etc/init.d/rcS' 一直卡在/etc/init.d/rcS
解决:使用Busybox默认配置,Open(etc/inittab) = NULL
#嵌入式Linux最小系统移植# busybox分析和移植记录
最新推荐文章于 2022-12-11 20:39:27 发布