Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2225748
  • 博文数量: 668
  • 博客积分: 10016
  • 博客等级: 上将
  • 技术积分: 8588
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-29 19:22
文章分类

全部博文(668)

文章存档

2011年(1)

2010年(2)

2009年(273)

2008年(392)

分类:

2008-08-28 15:04:39

此文章是关于嵌入式LINUX的

编译内核 /*linux-2.6.15*/
-------------
进入内核文件夹

打补丁使其支持at91rm9200
#zcat ../2.6.15-at91.patch.gz | patch -p1

编辑Makefile
ARCH            ?= $(SUBARCH)
CROSS_COMPILE   ?=
变为
ARCH  ?= arm
CROSS_COMPILE ?= /usr/local/eldk/usr/bin/arm-linux-
保存

编辑include/config/cmdline.h /*如果你的ramdisk在3M之内就跳过这一系列操作*/
#define CONFIG_CMDLINE "mem=32M console=ttyS0,115200 initrd=0x20410000,3145728 root=/dev/ram0 rw"
mem为你的sdmem大小,initrd为你的ramdisk加载地址,ramdisk大小,和加载设备。改为你需要的。
#define CONFIG_CMDLINE "mem=32M console=ttyS0,115200 initrd=0x20410000,4096000 root=/dev/ram0 rw"
保存

编辑include/linux/autoconf.h里的CMDLINE
同include/config/cmdline.h
保存

#make at91rm9200dk_defconfig

编辑.config
CONFIG_CMDLINE="mem=32M console=ttyS0,115200 initrd=0x20410000,3145728 root=/dev/ram0 rw"
同include/config/cmdline.h
保存

#make clean
#make zImage
#make modules

#mkdir images
#cp arch/arm/boot/zImage images/zImage-2.6.15
#cp vmlinux images/vmlinux-2.6.15
#cp System.map images/System.map-2.6.15
#cp .config images/2.6.15.config

#make INSTALL_MOD_PATH=images/modules-2.6.15 modules_install
copy busybox/examples 下的depmod.pl到内核文件夹
#./depmod.pl -b images/modules-2.6.15/lib/modules -k vmlinux


配置busybox /*busybox-1.1.1*/
--------------
#make menuconfig

下面是需要编译进busybox的功能选项,其他的可以根据需要自选。
General Configuration应该选的选项
Show verbose applet usage messages
Runtime SUID/SGID configuration via /etc/busybox.conf

Build Options
----------如果选用glibc则不选------
Build BusyBox as a static binary (no shared libs)
这个选项是一定要选择的,这样才能把busybox编译成静态链接的可执行文件,运行时才独立于其他函数库。否则必需要其他库文件才能运行,在单一个linux内核不能使他正常工作。
------------------------------------
选择交叉编译环境

Installation Options
Don't use /usr
这个选项也一定要选,否则make install 后busybox将安装在原系统的/usr下,这将覆盖掉系统原有的命令。选择这个选项后,make install后会在busybox目录下生成一个叫_install的目录,里面有busybox和指向他的链接。

其他选项都是一些linux基本命令选项,自己需要哪些命令就编译进去就可以了。

配置好后退出并保存。

4,编译并安装busybox

#make
#make install

编译好后在busybox目录下生成子目录_install,里面的内容:
drwxr-xr-x   2 root root     4096 2006-03-30 00:50 bin
drwxr-xr-x   2 root root     4096 2006-03-30 00:50 lib
lrwxrwxrwx   1 root root       11 2006-03-30 00:50 linuxrc -> bin/busybox
drwxr-xr-x   2 root root     4096 2006-03-30 00:50 sbin


制作根文件系统
--------------
1,基本目录结构
#mkdir /mnt/rootfs
#cd /mnt/rootfs
#mkdir etc usr var tmp proc home root dev
#chmod 1777 tmp
进入usr
#mkdir bin sbin
进入var
#mkdir lib lock log run tmp
#chmod 1777 tmp
进入proc
#mkdir self self/fd
#mkdir boot mnt opt (可选)
进入dev
#mkdir pts

其中etc,proc和dev是一定要建的,bin和sbin不用建,因为busybox中已经有了。
其他的可以象征性的建几个就可以了。

拷贝busybox
#cp -a 你的目录/_install/* /mnt/rootfs
*/
2,建立设备文件名

#cd /mnt/rootfs/dev
你可以用mknod手工建立,也可以直接从原系统的/dev目录下拷贝过来。

手工建立的方法:
#ls -l /dev/console
crw------- 1 root root 5, 1 11月 30 09:02 /dev/console
这样就查看到了console设备的主设备号是5,辅设备号是1,是一个标记为C的字符设备。
于是,我们可以用mknod建立一个同样的设备文件:

#mknod console c 5 1

但是手工方法建立太麻烦了,通常直接从/dev下把需要的设备文件拷贝过来。
这些设备文件是特殊文件,在拷贝时一定要加上-R参数才能拷贝。

#cp -R /dev/console ./
#cp -R /dev/null ./
#cp -R /dev/zero ./
...

另外可以代替:
#mknod -m 600 mem c 1 1
#mknod -m 644 random c 1 8
挂载eldk下面的/usr/local/eldk/arm/images的ramdisk_image.gz
#gunzip -v ramdisk_image.gz
#mkdir -p /mnt/tmp
#mount -o loop ramdisk_image /mnt/tmp
拷贝/mnt/tmp/dev到/mnt/rootfs/dev
#cp -R /mnt/tmp/dev/* /mnt/rootfs/dev
*/
进入/dev
#cp -R cdrom fd0 hda14 hda4 hdb11 hdb19 hdc hdc16 hdc6 hdd13 hdd3 loop2 ram2 /mnt/rootfs/dev
#cp -R console fd0H1440 hda15 hda5 hdb12 hdb2 hdc1 hdc17 hdc7 hdd14 hdd4 loop3 tty0 /mnt/rootfs/dev
#cp -R fb hda hda16 hda6 hdb13 hdb3 hdc10 hdc18 hdc8 hdd15 hdd5 loop4 tty1 /mnt/rootfs/dev
#cp -R fb0 hda1 hda17 hda7 hdb14 hdb4 hdc11 hdc19 hdd hdd16 hdd6 loop5 tty2 /mnt/rootfs/dev
#cp -R fb1 hda10 hda18 hda8 hdb15 hdb5 hdc12 hdc2 hdd1 hdd17 hdd7 null tty3 /mnt/rootfs/dev
#cp -R fb2 hda11 hda19 hdb hdb16 hdb6 hdc13 hdc3 hdd10 hdd18 hdd8 ram tty4 /mnt/rootfs/dev
#cp -R fb3 hda12 hda2 hdb1 hdb17 hdb7 hdc14 hdc4 hdd11 hdd19 initctl ram0 tty5 /mnt/rootfs/dev
#cp -R fb4 hda13 hda3 hdb10 hdb18 hdb8 hdc15 hdc5 hdd12 hdd2 loop1 ram1 zero /mnt/rootfs/dev
#cp -R usbdev* /mnt/rootfs/dev
#mkdir bus
#cp -R bus/* /mnt/rootfs/dev/bus/
*/
如果“没有找到文件”是可以忽略的
#cp -R /dev/pts/0 /mnt/rootfs/dev/pts
#ln -s ../proc/self/fd fd
#ln -s fd/0 stdin
#ln -s fd/1 stdout
#ln -s fd/2 stderr
进入proc/self/fd/
#ln -s ../../../dev/pts/0 0
#ln -s ../../../dev/pts/0 1
#ln -s ../../../dev/pts/0 2

以下是我认为可以加入的设备名:
cdrom fd0 hda14 hda4 hdb11 hdb19 hdc hdc16 hdc6 hdd13 hdd3 loop2 ram2
console fd0H1440 hda15 hda5 hdb12 hdb2 hdc1 hdc17 hdc7 hdd14 hdd4 loop3 tty0
fb hda hda16 hda6 hdb13 hdb3 hdc10 hdc18 hdc8 hdd15 hdd5 loop4 tty1
fb0 hda1 hda17 hda7 hdb14 hdb4 hdc11 hdc19 hdd hdd16 hdd6 loop5 tty2
fb1 hda10 hda18 hda8 hdb15 hdb5 hdc12 hdc2 hdd1 hdd17 hdd7 null tty3
fb2 hda11 hda19 hdb hdb16 hdb6 hdc13 hdc3 hdd10 hdd18 hdd8 ram tty4
fb3 hda12 hda2 hdb1 hdb17 hdb7 hdc14 hdc4 hdd11 hdd19 initctl ram0 tty5
fb4 hda13 hda3 hdb10 hdb18 hdb8 hdc15 hdc5 hdd12 hdd2 loop1 ram1 zero

其中,fd0,hda,ram0,ttyS0,tty1,null,zero,loop1,fb0,fb等是必备的.
其它的hda,hda1,hdb等可以根据实际需要决定.但是上表中的选择是比较合理的,即能满足大部分的需要,有没有不用的设备浪费空间。注意,千万不要把/dev下的设备全拷贝过来,那将产生大约420K的/dev目录,这样来说太大了。

3,建立etc目录下的配置文件

busybox.conf group inittab motd passwd resolv.conf
fstab init.d issue mtab profile shadow modules.conf

执行:
touch busybox.conf group inittab motd passwd resolv.conf
touch fstab issue mtab profile shadow modules.conf

其中init.d是一个目录,从busybox源代码目录下拷贝过来。

#cp -R 你的目录/examples/bootflopyp/etc/init.d /mnt/rootfs/etc/

busybox.conf是一个空文件
其他文件的内容如下:

fstab:
/dev/fd0 /  ext2  defaults 0 0
none  /proc  proc  defaults 0 0
none  /dev/pts devpts  mode=0622 0 0

group:
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin
tty:x:5:
disk:x:6:root
lp:x:7:daemon
mem:x:8:
kmem:x:9:
ftp:x:50:
nobody:x:99:
users:x:100:

inittab:
::sysinit:/etc/init.d/rcS
::respawn:/sbin/getty 115200 ttyS0
::respawn:/bin/sh
::askfirst:/bin/sh
# Stuff to do when restarting the init process
::restart:/sbin/init
# Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a

issue:
Lianic Arm Linux release 0.1(2006-04-05)

motd是一个空文件

mtab是一个空文件

passwd:
root:x:0:0:root:/:/bin/ash
bin:x:1:1:bin:/bin:
daemon:x:2:2:daemon:/sbin:
halt:x:7:0:halt:/sbin:/sbin/halt
ftp:x:14:50:FTP User:/
nobody:*:99:99:Nobody:/:

profile:
# /etc/profile: system-wide .profile file for the Bourne shells
export PS1="[u@h w]$"
echo "Done"
alias ll='ls -l'11 ll
alias du='du -h'
alias df='df -h'
alias rm='rm -i'
echo
# Set path
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

resolv.conf:dns域名解析
nameserver 127.0.0.1
search localhost

shadow:根据自己的设置
root:$2a$05$xyunjFqZ9SVeqkDHWlmQd.hMEeBteWCFQ.yfkmf5DSrihghkwA.w6:13243::::::
bin:*:13080::::::
daemon:*:13080::::::
ftp:*:13080::::::
nobody:*:13080::::::

其中有很多是从原系统的/etc下拷贝过来修改的,如果你是一个具有中等以上水平的linux爱好者,那么应该一看就明白了,当然,你也可以根据自己的需要修改这些文件。其中最重要的是fstab和inittab,busybox内建的init程序用到的inittab文件的语法和一般的不一样,不能直接把原系统/etc下inittab文件拷贝过来。可以把busybox-1.00目录下的示例文件拷贝过来修改用.具体请看busybox的文档。

init.d下的文件:rcS
rcS的内容:
#! /bin/sh
mount -o remount,rw /

/sbin/ifconfig lo 127.0.0.1
#/sbin/ifconfig eth0 192.168.1.2

/bin/mount -a
>/etc/mtab
echo
echo "+++++++++++++ Welcom to Lianic Arm Linux ++++++++++++++++++ "
echo "+ This is a arm linux system which is running on at91rm9200."
echo "+ It contains more than 100 basic Linux commands and tools."
echo "+ All these great features are powered by BusyBox 1.1.1 "
echo "+ This is a free system tool developed by Edward Lianic. "
echo "+ If you have any problem please mailto : "
echo "+ Enjoy!!!"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "
echo
hostname LianicLinux

可以自己作相应的修改。

请确保这个文件是可执行的,否则请改成可执行的:
#chmod a+x rcS

4,建立boot目录下文件(可选,建议但内核启动失败的时候可以加载)
进入内核文件夹
#cp images/zImage-2.6.15 /mnt/rootfs/boot/
#cp images/2.6.15.config /mnt/rootfs/boot/

5,建立lib目录下文件
进入内核文件夹
#cp -a images/modules-2.6.15/* /mnt/rootfs/
进入/usr/local/eldk/arm/lib /*完整glibc链接库*/
#cp *-*.so /mnt/rootfs/lib
#cp *.so.[*0-9] /mnt/rootfs/lib
#cp libSegFault.so libmemusage.so libpcprofile.so /mnt/rootfs/lib
#arm-linux-strip /mnt/rootfs/lib/*.so
*/
如果拷贝了NSS,如libnss_file,libnss_dns,libnss_nis则执行,否则跳过
进入etc
#touch nsswitch.conf
nsswitch.conf:
# ---nsswitch.conf---begin
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
#       compat                  Use compatibility setup
#       nisplus                 Use NIS+ (NIS version 3)
#       nis                     Use NIS (NIS version 2), also called YP
#       dns                     Use DNS (Domain Name Service)
#       files                   Use the local files
#       [NOTFOUND=return]       Stop searching if not found so far
#
# For more information, please read the nsswitch.conf.5 manual page.
#

# passwd: files nis
# shadow: files nis
# group:  files nis

passwd: compat
group: compat

hosts: files dns
networks: files dns

services: files
protocols: files
rpc: files
ethers: files
netmasks: files
netgroup: files
publickey: files

bootparams: files
automount: files nis
aliases: files
# ---nsswitch.conf---end

以上是Lianic Arm Linux根文件系统的所有内容,他的总大小应该在6.8M左右。


建立ramdisk
--------------
1建立新的ramdisk大小为8M
#dd if=/dev/zero of=ramdisk bs=1k count=8192
2格式为ext2
#/sbin/mke2fs -F -m 0 ramdisk
3禁止check
#/sbin/tune2fs -c 0 ramdisk
4挂载
#mkdir -p /mnt/ramdisk
#mount -o loop ramdisk /mnt/ramdisk
5拷贝根文件系统
#cp -a /mnt/rootfs/* /mnt/ramdisk/
6解挂和压缩
#umount /mnt/ramdisk/
#gzip -v9 ramdisk

阅读(1332) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~