#嵌入式Linux最小系统移植# busybox分析和移植记录
2019-07-12 20:48发布
生成海报
1.init_main过程分析
init_main
parse_inittab();
file = fopen(INITTAB, "r");
new_init_action(a->action, command, id);
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);
"
Please 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");
for (a = last = init_action_list; a; a = a->next) {
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: :::
# :The contents of this field are appended to "/dev/" and used as-is.
# : Valid actions include: sysinit, respawn, askfirst, wait, once,
# restart, ctrlaltdel, and shutdown.
# : Specifies the process to be executed and its command line.
4.编译、安装busybox
#make menuconfig
出错:提示Makefile:1449: *** mixed implicit and normal rules. Stop.
解决:
出错: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
出错:undefined reference to `__cpu_to_be16
解决:修改 networking/libiproute/iptunnel.c文件
在#include
后面加上
#include
#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
[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
出错:starting pid 755, tty '': '/etc/init.d/rcS' 一直卡在/etc/init.d/rcS
解决:使用Busybox默认配置,Open(etc/inittab) = NULL
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮