您的位置:首页 > 运维架构 > Linux

为linux建立最小的根文件系统

2015-06-17 10:46 633 查看


为linux建立最小的根文件系统

在编译内核时候,可以指定一个文件夹作为内核启动时候的根文件系统,linux中管这个文件系统叫做initramfs。
具体做法如下(以i386为例)
1.下载内核文件
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.tar.bz2 2.解压内核
bzip2 -d linux-2.6.26.tar.bz2 生成一个linux-2.6.26.tar文件,然后
tar xvf linux-2.6.26.tar
解压后,将有个linux-2.6.26文件夹存在
3.准备一个iniramfs文件系统的文件夹
在linux-2.6.26文件夹下建立一个文件夹 myinitramfs
写一个测试用的hello world,起名为hello.c,如下:
#include <stdio.h>
#include <unistd.h>
int main(int argc,char *argv[])
{
int i = 0;
while (1) {
printf("hello world (%d)\n",i);
}
return 0;
}
编译 gcc -static -o init hello.c
把init拷贝到myinitramfs文件夹下。
cp init myinitramfs/
由于需要显示文字,还需要在文件夹下准备console设备文件。
mkdir myinitramfs/dev
cp -a /dev/console myinitramfs/
4.编译内核
在linux-2.6.26文件下下,执行make help。
将看到很多帮助信息,其中有一项是 i386_defconfig
执行 make i386_defconfig,将生成一个.config文件。
为了把之前准备好的文件夹添加到内核配置文件中,还需要重新配置下config文件
make config
在 General Setup --->
Initial RAM filesystem and RAM disk (initramfs/initrd) support (BLK_DEV_INITRD) [Y/n/?]
Initramfs source file(s) (INITRAMFS_SOURCE) [myinitramfs]
处,输入准备好的文件夹.
配置好后,在.config文件中会有如下一条定义
CONFIG_INITRAMFS_SOURCE="myinitramfs"
保存.config
make 编译内核
5.用qemu测试内核和initramfs
qemu -kernel linux-2.6.26/arch/i386/boot/bzImage -initrd linux-2.6.26/usr/initramfs_data.cpio.gz /dev/zero
initramfs_data.cpio.gz 这个文件是内核自动生成的,具体名字可能不同的系统或者内核有差异,但是后缀应该是.cpio.gz

开工啦!

为了不看起来那么乏味,我们尝试通过一个看的着的例子来展示这个过程。

唔,我们还是把“hello world”作为第一个要放到initramfs中去的程序。事实上,rootfs和其它的root filesystem并没有什么区别,如果你喜欢,你可以放/etc和/usr和/tmp和。。。然后还可以mount /proc 和/sysfs过去。但是这里我们只需要放/init过去。程序的最后我们使用sleeping而不是exiting,这主要是考虑如果PID 1的程序退出,kernel会panic,这会干扰我们的视线。

#include

int main(int argc, char *argv[])
{
printf("Hello world\n");
sleep(999999999);
}


然后呢,静态编译,然后我们就不用考虑拷贝需要的库过去了~

gcc -static hello.c -o hello


如果在命令行执行这个小程序,它会打印hello world,让后停在那里。你可以用ctrl-x让它退出。如果是initramfs执行这个程序,我们会看到在boot messages的最后,有个“hello world”被打印。

注意:如果是要放到你的开发板上去执行,记得使用你的交叉编译工具。打包的过程是和平台无关的,但是二进制文件需要用目标系统的compiler。

那么,我们该怎样把这个程序给kernel用内?好吧,有四种基本方法:第一种是把cpio.gz作为一个独立的包,然后告诉bootloader它在哪里;或者你可以用下面三种方法之一,把initramfs直接编译进kernel里去。

把cipo.gz作为独立的档案

很多人喜欢把它编译进内核里面去,如果你乐意,你也可以这么做。但是我们现在要用另一种方式。我们可以使能内核的initrd支持,然后用cpio.gz来代替ramdisk(initrd)。聪明的内核会为我们自动检测文件的类型,然后把我们的压缩包解压放进rootfs;它不是创建一个ram disk,这不会影响initramfs内存效率高这一优势。

因为external initramfs是在built-in initramfs之后执行的,所以如果两个档案内包含有同名的内容,独立档案会覆盖掉built-in填进去去的东西。这意味着,你不用修改kernel,就可以update或者是ucstomize你的rootfs而不用换掉你的内核。

另外一个好消息是,这样做你可以不用顾虑license的问题!你可以在rootfs里面运行non-GPL的程序,或者是给你的驱动提供non-GPL的firmware...额,编译进内核的话,算是内核的修改吧?制作自己的initramfs,只是算是使用,你不用公布你的源代码哦亲!

那么,怎么制作cpio.gz档案呢?一种方法是你用cpio和gzip命令自己来压缩。当然,你也可以用kernel build来做这个,如果你觉得不是那么麻烦的话。原意自己做的,只需要敲下面这些代码进去...

mkdir sub
cp hello sub/init
cd sub
find . | cpio -o -H newc | gzip > ../initramfs_data.cpio.gz
cd ..
rm -rf sub


按照传统的使用initrd的方法,把上面生成的initramfs_data.cpio.gz放到该放的地方去(别问我要放哪里,我也还不知道),它就会在boot结束的地方为你打印一朵漂亮的“hello world”,然后等待一段时间并重启。

试试吧!

如果它没有工作,照例的你该查查initial ramdisk支持是不是有被选中,然后看看你的init 程序是不是静态链接的,再看看它是不是又执行权限,或者是名字是不是对的。你可以用下面的命令来解压任何的initramfs档案到当前文件夹:

zcat initramfs_data.cpio.gz | cpio -i -d -H newc --no-absolute-filenames


把initramfs编译到内核里面去

使用initramfs最简单的方式,莫过于用已经做好的cpio.gz把kernel里面那个空的给换掉。这是2.6 kernel天生支持的,所以,你不用做什么特殊的设置。

kernel的config option里面有一项CONFIG_INITRAMFS_SOURCE(I.E. General setup--->Initramfs source file(s) in menuconfig)。这个选项指向放着内核打包initramfs需要的所有文件。默认情况下,这个选项是留空的,所以内核编译出来之后initramfs也就是空的,也就是前面提到的rootfs什么都不做的情形。

CONFIG_INITRAMFS_SOURCE 可以是一个绝对路径,也可以是一个从kernel’s top build dir(你敲入build或者是make的地方)开始的相对路径。而指向的目标可以有以下三种:一个已经做好的cpio.gz,或者一个已经为制作cpio.gz准备好所有内容的文件夹,或者是一个text的配置文件。第三种方式是最灵活的,我们先依次来介绍这三种方法。

1)使用一个已经做好的cpio.gz档案

If you already have your own initramfs_data.cpio.gz file (because you created it yourself, or saved the cpio.gz file produced by a previous kernel build), you can point CONFIG_INITRAMFS_SOURCE at it and the kernel build will autodetect the file type and link
it into the resulting kernel image.

You can also leave CONFIG_INITRAMFS_SOURCE empty, and instead copy your cpio.gz file to usr/initramfs_data.cpio.gz in your kernel's build directory. The kernel's makefile won't generate a new archive if it doesn't need to.

Either way, if you build a kernel like this you can boot it without supplying an external initrd image, and it'll still finish its boot by running your init program out of rootfs. This is packaging method #2, if you'd like to try it now.

2)指定给内核一个文件或者文件夹

If CONFIG_INITRAMFS_SOURCE points to a directory, the kernel will archive it up for you. This is a very easy way to create an initramfs archive, and is method #3.

Interestingly, the kernel build doesn't use the standard cpio command to create initramfs archives. You don't even need to have any cpio tools installed on your build system. Instead the kernel build (in usr/Makefile) generates a text file describing the directory
with the script "gen_initramfs_list.sh", and then feeds that descript to a program called "gen_init_cpio" (built from C source in the kernel's usr directory), which create the cpio archive. This looks something like the following:

scripts/gen_initramfs_list.sh $CONFIG_INITRAMFS_SOURCE > usr/initramfs_list
usr/gen_init_cpio usr/initramfs_list > usr/initramfs_data.cpio
gzip usr/initramfs_data.cpio


To package up our hello world program, you could simply copy it into its own directory, name it "init", point CONFIG_INITRAMFS_SOURCE at that directory, and rebuild the kernel. The resulting kernel should end its boot by printing "hello world". And if you need
to tweak the contents of that directory, rebuilding the kernel will re-package the contents of that directory if anything has changed.

The downside of this method is that it if your initramfs has device nodes, or cares about file ownership and permissions, you need to be able to create those things in a directory for it to copy. This is hard to do if you haven't got root access, or are using
a cross-compile environment like cygwin. That's where the fourth and final method comes in.

3)使用configuration文件initramfs_list来告诉内核initramfs在哪里

This is the most flexible method. The kernel's gen_initramfs_list.sh script creates a text description file listing the contents of initramfs, and gen_init_cpio uses this file to produce an archive. This file is a standard text file, easily editable, containing
one line per file. Each line starts with a keyword indicating what type of entry it describes.

The config file to create our "hello world" initramfs only needs a single line:

file /init usr/hello 500 0 0


This takes the file "hello" and packages it so it shows up as /init in rootfs, with permissions 500, with uid and gid 0. It expects to find the source file "hello" in a "usr" subdirectory under the kernel's build directory. (If you're building the kernel in
a different directory than the source directory, this path would be relative to the build directory, not the source directory.)

To try it yourself, copy "hello" into usr in the kernel's build directory, copy the above configuration line to its own file, use "make menuconfig" to point CONFIG_INITRAMFS_SOURCE to that file, run the kernel build, and test boot the new kernel. Alternately,
you can put the "hello" file in its own directory and use "scripts/gen_initramfs_list.sh dirname" to create a configuration file (where dirname is the path to your directory, from the kernel's build directory). For large projects, you may want to generate
a starting configuration with the script, and then customize it with any text editor.

This configuration file can also specify device nodes (with the "nod" keyword), directories ("dir"), symbolic links ("slink"), named FIFO pipes ("pipe"), and unix domain sockets ("sock"). Full documentation on this file's format is available by running "usr/gen_init_cpio"
(with no arguments) after a kernel build.

A more complicated example containing device nodes and symlinks could look like this:

dir /dev 755 0 0
nod /dev/console 644 0 0 c 5 1
nod /dev/loop0 644 0 0 b 7 0
dir /bin 755 1000 1000
slink /bin/sh busybox 777 0 0
file /bin/busybox initramfs/busybox 755 0 0
dir /proc 755 0 0
dir /sys 755 0 0
dir /mnt 755 0 0
file /init initramfs/init.sh 755 0 0


One significant advantage of the configuration file method is that any regular user can create one, specifying ownership and permissions and the creation of device nodes in initramfs, without any special permissions on the build system. Creating a cpio archive
using the cpio command line tool, or pointing the kernel build at a directory, requires a directory that contains everything initramfs will contain. The configuration file method merely requires a few source files to get data from, and a description file.

This also comes in handy cross-compiling from other environments such as cygwin, where the local filesystem may not even be capable of reproducing everything initramfs should have in it.

总结一下

这四种给rootfs提供内容的方式都有一个共同点:在kernel启动时,一系列的文件被解压到rootfs,如果kernel能在其中找到可执行的文件“/init”,kernel就会运行它;这意味着,kernel不会再去理会“root=”是指向哪里的。

此外,一旦initramfs里面的init 进程运行起来,kernel就会认为启动已经完成。接下来,init将掌控整个宇宙!它拥有霹雳无敌的专门为它预留的Process ID #1,整个系统接下来的所有都将由它来创造!还有,它的地位将是不可剥夺的,嗯哼,PID 1 退出的话,系统会panic的。

接下来我会介绍其他一些,在rootfs中,init程序可以做的事。

UBOOT已经烧录成功,LINUX内核也烧录了,根文件系统也可以这么打包烧录进去。但如果每改一下内核或程序文件都要这么打包烧录是比较麻烦的,接下来就是如何利用TFTP和NFS让UBOOT自动从ubuntu的文件系统中加载内核和挂载根文件系统。

首先安装tftp:

TFTP和NFS是为了方便调试,开发板接上网线可以连到PC的TFTP,下载编译好的Linux内核uImage,挂接PC机上的NFS网络文件系统作为根文件系统,这样你编译好的程序可以程序文件可以直接发布到NFS文件夹中,然后直接就可以在开发板加载运行了。

(xinetd是网络服务主程序,一般是要与TFTP一起安装)

root@ubuntu:/# apt-get install xinetd tftpd
tftp

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following packages were automatically installed and are no longer required:

ssl-cert

Use 'apt-get autoremove' to remove them.

The following NEW packages will be installed:

tftp tftpd xinetd

0 upgraded, 3 newly installed, 0 to remove and 61 not upgraded.

Need to get 0B/185kB of archives.

After this operation, 578kB of additional disk space will be used.

Selecting previously deselected package tftp.

(Reading database ... 40278 files and directories currently installed.)

Unpacking tftp (from .../tftp_0.17-17ubuntu1_i386.deb) ...

Selecting previously deselected package xinetd.

Unpacking xinetd (from .../xinetd_1%3a2.3.14-7ubuntu2_i386.deb) ...

Selecting previously deselected package tftpd.

Unpacking tftpd (from .../tftpd_0.17-17ubuntu1_i386.deb) ...

Processing triggers for man-db ...

Setting up tftp (0.17-17ubuntu1) ...

Setting up xinetd (1:2.3.14-7ubuntu2) ...

* Stopping internet superserver xinetd [ OK ]

* Starting internet superserver xinetd [ OK ]

Setting up tftpd (0.17-17ubuntu1) ...

--------- IMPORTANT INFORMATION FOR XINETD USERS ----------

The following line will be added to your /etc/inetd.conf file:

tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /srv/tftp

If you are indeed using xinetd, you will have to convert the

above into /etc/xinetd.conf format, and add it manually. See

/usr/share/doc/xinetd/README.Debian for more information.

Suggested entry (automatically converted using itox):

service tftp

{

socket_type = dgram

protocol = udp

wait = yes

user = nobody

You must use option -daemon_dir if you use tcpd

-----------------------------------------------------------

创建目录:

root@ubuntu:/# mkdir tftpboot

root@ubuntu:~# chmod o+w /tftpboot

root@ubuntu:~# chown -R nobody /tftpboot

编辑TFTP配置文件:

root@ubuntu:/# vi /etc/xinetd.d/tftp

按i进入编辑模式,输入以下内容:

service tftp

{

socket_type = dgram

protocol = udp

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s /tftpboot

disable = no

per_source = 11

cps = 100 2

flags = IPv4

}

按ESC,输入:wq指令保存退出。

重新启动xinetd:

root@ubuntu:/# /etc/init.d/xinetd reload

* Reloading internet superserver configuration xinetd [ OK ]

root@ubuntu:/# /etc/init.d/xinetd restart

* Stopping internet superserver xinetd [ OK ]

* Starting internet superserver xinetd [ OK ]

查找并测试一下tftp:

root@ubuntu:/# netstat -a|grep tftp

udp 0 0 *:tftp *:*

root@ubuntu:/# cd ~

root@ubuntu:~# dir / >/tftpboot/a2.txt

root@ubuntu:~# tftp 192.168.1.234

tftp> get a2.txt

Received 161 bytes in 0.0 seconds

tftp> q

root@ubuntu:~# ls

a2.txt

root@ubuntu:~

能下载文件,说明tftp安装并启动成功了。

接下来安装NFS网络文件系统:

root@ubuntu:/# apt-get install nfs-kernel-server

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following packages were automatically installed and are no longer required:

ssl-cert

Use 'apt-get autoremove' to remove them.

The following extra packages will be installed:

libevent-1.4-2 libgssglue1 libnfsidmap2 librpcsecgss3 nfs-common portmap

The following NEW packages will be installed:

libevent-1.4-2 libgssglue1 libnfsidmap2 librpcsecgss3 nfs-common

nfs-kernel-server portmap

0 upgraded, 7 newly installed, 0 to remove and 61 not upgraded.

Need to get 551kB of archives.

After this operation, 1,692kB of additional disk space will be used.

Do you want to continue [Y/n]?

Get:1 http://us.archive.ubuntu.com karmic/main
libevent-1.4-2 1.4.11-stable-1 [60.4kB]

Get:2 http://us.archive.ubuntu.com karmic/main
libgssglue1 0.1-3 [23.6kB]

Get:3 http://us.archive.ubuntu.com karmic/main
libnfsidmap2 0.21-2 [28.4kB]

Get:4 http://us.archive.ubuntu.com karmic/main
librpcsecgss3 0.18-1 [32.4kB]

Get:5 http://us.archive.ubuntu.com karmic/main
portmap 6.0-10ubuntu2 [37.4kB]

Get:6 http://us.archive.ubuntu.com karmic/main
nfs-common 1:1.2.0-2ubuntu8 [211kB]

Get:7 http://us.archive.ubuntu.com karmic/main
nfs-kernel-server 1:1.2.0-2ubuntu8 [158kB]

Fetched 551kB in 13s (39.5kB/s)

Preconfiguring packages ...

Selecting previously deselected package libevent-1.4-2.

(Reading database ... 40313 files and directories currently installed.)

Unpacking libevent-1.4-2 (from .../libevent-1.4-2_1.4.11-stable-1_i386.deb) ...

Selecting previously deselected package libgssglue1.

Unpacking libgssglue1 (from .../libgssglue1_0.1-3_i386.deb) ...

Selecting previously deselected package libnfsidmap2.

Unpacking libnfsidmap2 (from .../libnfsidmap2_0.21-2_i386.deb) ...

Selecting previously deselected package librpcsecgss3.

Unpacking librpcsecgss3 (from .../librpcsecgss3_0.18-1_i386.deb) ...

Selecting previously deselected package portmap.

Unpacking portmap (from .../portmap_6.0-10ubuntu2_i386.deb) ...

Selecting previously deselected package nfs-common.

Unpacking nfs-common (from .../nfs-common_1%3a1.2.0-2ubuntu8_i386.deb) ...

Selecting previously deselected package nfs-kernel-server.

Unpacking nfs-kernel-server (from .../nfs-kernel-server_1%3a1.2.0-2ubuntu8_i386.deb) ...

Processing triggers for man-db ...

Setting up libevent-1.4-2 (1.4.11-stable-1) ...

Setting up libgssglue1 (0.1-3) ...

Setting up libnfsidmap2 (0.21-2) ...

Setting up librpcsecgss3 (0.18-1) ...

Setting up portmap (6.0-10ubuntu2) ...

portmap start/running, process 2393

Setting up nfs-common (1:1.2.0-2ubuntu8) ...

Creating config file /etc/idmapd.conf with new version

Creating config file /etc/default/nfs-common with new version

Adding system user `statd' (UID 104) ...

Adding new user `statd' (UID 104) with group `nogroup' ...

Not creating home directory `/var/lib/nfs'.

statd start/running, process 2615

gssd stop/pre-start, process 2640

idmapd stop/pre-start, process 2668

Setting up nfs-kernel-server (1:1.2.0-2ubuntu8) ...

Creating config file /etc/exports with new version

Creating config file /etc/default/nfs-kernel-server with new version

* Exporting directories for NFS kernel daemon... [ OK ]

* Starting NFS kernel daemon [ OK ]

Processing triggers for libc-bin ...

ldconfig deferred processing now taking place

root@ubuntu:/#

创建共享目录并配置输出共享:

root@ubuntu:/# mkdir nfsroot

root@ubuntu:/# chmod 777 nfsroot

root@ubuntu:/# vi /etc/exports

在最后追加输入一行:

/nfsroot *(rw,sync,no_root_squash)

保存退出。

重启NFS服务:

root@ubuntu:/# /etc/init.d/nfs-kernel-server
restart

* Stopping NFS kernel daemon [ OK ]

* Unexporting directories for NFS kernel daemon... [ OK ]

* Exporting directories for NFS kernel daemon...

exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/nfsroot".

Assuming default behaviour ('no_subtree_check').

NOTE: this default has changed since nfs-utils version 1.0.x

* Starting NFS kernel daemon [ OK ]

测试一下:

root@ubuntu:/# dir / >/nfsroot/a3.txt

root@ubuntu:/# ls /nfsroot/

a3.txt

root@ubuntu:/# mount 192.168.1.234:/nfsroot
/mnt/

root@ubuntu:/# ls /mnt

a3.txt

root@ubuntu:/#

root@ubuntu:/# umount /mnt

能挂截网络文件系统,列出共享文件,说明NFS安装启动成功了。

接下来将编译好的uImage放到/tftpboot目录:

root@ubuntu:~# cd /opt/linux-2.6.24.3/arch/mips/boot/

root@ubuntu:/opt/linux-2.6.24.3/arch/mips/boot#
ls

addinitrd.c compressed ecoff.h elf2ecoff.c Makefile tools uImage vmlinux.bin.gz

root@ubuntu:/opt/linux-2.6.24.3/arch/mips/boot#
cp uImage /tftpboot/

root@ubuntu:/opt/linux-2.6.24.3/arch/mips/boot#
cd /

root@ubuntu:/# ls /tftpboot/

a2.txt uImage

root@ubuntu:/#
把根文件系统解压到/nfsroot目录:

root@ubuntu:/# mount /dev/cdrom
/mnt

mount: block device /dev/sr0 is write-protected, mounting read-only

root@ubuntu:/# ls /mnt

celinux-040503-jz-20080409.patch.gz mipseltools-gcc412-lnx24.tar.gz

celinux-040503.tar.bz2 mipseltools-gcc412-lnx26.tar.gz

linux2.4_developer_guide.pdf mips_toolchain_guide.pdf

linux-2.6.24.3-jz-20090218.patch.gz MPlayer-1.0rc2-20090218.tar.bz2

linux-2.6.24.3.tar.bz2 mxu_user_guide.pdf

linux2.6_developer_guide_v1.4.1.pdf root-jz-20090216.tar.bz2

linux_resource_guide_v1.1.pdf u-boot-1.1.6-jz-20090216.patch.gz

mipsel-gcc4.1-cygwin-nopic.tar.bz2 uboot-1.1.6.tar.gz

mipseltools-gcc412-glibc261.tar.bz2 uboot_developer_guide.pdf

root@ubuntu:/# cd /nfsroot/

root@ubuntu:/nfsroot#
tar -xjf /mnt/root-jz-20090216.tar.bz2

root@ubuntu:/nfsroot#
ls

a3.txt root-jz-20090216

root@ubuntu:/nfsroot#

接下来设置UBOOT从TFTP和NFS加载内核和根文件系统。打开COM口的终端,按开发板的RESET键,在COM口提示按任意键时,按一下空格,开发板将停止加载内核,进入UBOOT命令行:

NAND Secondary Program Loader

Starting U-Boot ...

U-Boot 1.1.6 (May 21 2009 - 16:21:12)

Board: Ingenic APUS (CPU Speed 336 MHz)

DRAM: 64 MB

Flash: 0 kB

NAND:1024 MiB

*** Warning - bad CRC or NAND, using default environment

In: serial

Out: lcd

Err: lcd

Net: JZ ETHERNET

Hit any key to stop autoboot: 0

APUS #

这时可输入命令查看启动参数:

APUS # printenv

bootargs=mem=64M ip=off rootfstype=yaffs2 root=/dev/mtdblock2 rw

bootcmd=nand read 0x80600000 0x200000 0x200000;bootm

bootdelay=1

baudrate=57600

loads_echo=1

ethaddr=00:2a:c6:2c:ab:f0

autoload=n

bootfile="uImage"

stdin=serial

stdout=lcd

stderr=lcd

ethact=JZ ETHERNET

Environment size: 267/262139 bytes

APUS #

其中bootcmd为启动入口和命令,bootargs为启动参数。

接下来我设置它从TFTP和NFS加载内核和文件系统:

APUS # setenv ipaddr 192.168.1.239

APUS # setenv serverip 192.168.1.234

APUS # setenv bootargs console=ttyS3,57600n8 mem=128M ip=192.168.1.239 ethaddr=00:2a:c6:2c:ab:f0 nfsroot=192.0.0.234:/nfsroot/root-jz-20090216 rw

APUS # askenv bootcmd

Please enter 'bootcmd':tftpboot;bootm

APUS #

其中两个IP分别是开发板和ubuntu主机的,两者应在同一网段。

最后,保存设置,启动开发板:

APUS # saveenv

Saving Environment to NAND...

Erasing Nand...Writing to Nand... done

APUS # boot

Using JZ ETHERNET device

TFTP from server 192.168.1.234; our IP address is 192.168.1.239

Filename 'uImage'.

Load address: 0x80600000

Loading: #################################################################

#################################################################

#################################################################

#################################################################

#################################################################

#################################

done

Bytes transferred = 1828764 (1be79c hex)

## Booting image at 80600000 ...

Image Name: Linux-2.6.24.3

Image Type: MIPS Linux Kernel Image (gzip compressed)

Data Size: 1828700 Bytes = 1.7 MB

Load Address: 80010000

Entry Point: 80326730

Verifying Checksum ... OK

Uncompressing Kernel Image ... OK

Starting kernel ...

Linux version 2.6.24.3 (root@ubuntu)
(gcc version 4.1.2) #1 PREEMPT Sun Jan 31 10:11:58 EST 2010

CPU revision is: 1ed0024f (Ingenic JZRISC)

CPU clock: 336MHz, System clock: 112MHz, Peripheral clock: 112MHz, Memory clock: 112MHz

JZ4750 APUS board setup

Determined physical RAM map:

memory: 04000000 @ 00000000 (usable)

User-defined physical RAM map:

memory: 08000000 @ 00000000 (usable)

Zone PFN ranges:

Normal 0 -> 32768

Movable zone start PFN for each node

early_node_map[1] active PFN ranges

0: 0 -> 32768

Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512

Kernel command line: console=ttyS3,57600n8 mem=128M ip=192.168.1.239 ethaddr=00:2a:c6:2c:ab:f0 nfsroot=192.168.1.234:/nfsroot/root-jz-20090216 rw

Primary instruction cache 16kB, VIPT, 4-way, linesize 32 bytes.

Primary data cache 16kB, 4-way, VIPT, no aliases, linesize 32 bytes

Synthesized clear page handler (25 instructions).

Synthesized copy page handler (44 instructions).

Synthesized TLB refill handler (20 instructions).

Synthesized TLB load handler fastpath (32 instructions).

Synthesized TLB store handler fastpath (32 instructions).

Synthesized TLB modify handler fastpath (31 instructions).

PID hash table entries: 512 (order: 9, 2048 bytes)

Console: colour dummy device 80x25

console [ttyS3] enabled

Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)

Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)

Memory: 125540k/131072k available (3182k kernel code, 5428k reserved, 761k data, 172k init, 0k highmem)

Mount-cache hash table entries: 512

net_namespace: 64 bytes

NET: Registered protocol family 16

SCSI subsystem initialized

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

NET: Registered protocol family 2

Time: jz_clocksource clocksource has been installed.

IP route cache hash table entries: 1024 (order: 0, 4096 bytes)

TCP established hash table entries: 4096 (order: 3, 32768 bytes)

TCP bind hash table entries: 4096 (order: 2, 16384 bytes)

TCP: Hash tables configured (established 4096 bind 4096)

TCP reno registered

Total 4MB memory at 0x7c00000 was reserved for IPU

Power Management for JZ

yaffs Jan 31 2010 10:04:39 Installing.

io scheduler noop registered

io scheduler anticipatory registered (default)

io scheduler deadline registered

io scheduler cfq registered

LCDC: PixClock:9333333 LcdClock:25846153

LCDC: PixClock:9333333 LcdClock:25846153

jz4750fb_set_par, not implemented

Console: switching to colour frame buffer device 60x34

fb0: jz-lcd frame buffer device, using 512K of video memory

JzSOC: char device family.

Jz generic touch screen driver registered

JZ4740 SAR-ADC driver registered

Virtual Driver of TCSM registered

Serial: 8250/16550 driver $Revision: 1.5 $ 4 ports, IRQ sharing disabled

serial8250: ttyS0 at MMIO 0x0 (irq = 6) is a 16550A

serial8250: ttyS1 at MMIO 0x0 (irq = 5) is a 16550A

serial8250: ttyS2 at MMIO 0x0 (irq = 4) is a 16550A

RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize

loop: module loaded

Jz CS8900A driver for Linux (V0.02)

eth%d: CS8900A rev E detected

Driver 'sd' needs updating - please use bus_type methods

JZ NAND init<6> DMA mode, using DMA buffer in upper layer.

NAND device: Manufacturer ID: 0xec, Chip ID: 0xd3 (Samsung NAND 1GiB 3,3V 8-bit) planenum:2

Nand using two-plane mode, and resized to writesize:4096 oobsize:128 blocksize:0x80000

Scanning device for bad blocks

Creating 4 MTD partitions on "NAND 1GiB 3,3V 8-bit":

0x000000000-0x000400000 : "NAND BOOT partition"

0x000400000-0x000800000 : "NAND KERNEL partition"

0x000800000-0x020000000 : "NAND ROOTFS partition"

0x020000000-0x040000000 : "NAND VFAT partition"

usbmon: debugfs is not available

jz-ohci jz-ohci.0: JZ OHCI

jz-ohci jz-ohci.0: new USB bus registered, assigned bus number 1

jz-ohci jz-ohci.0: irq 17, io mem 0x13030000

usb usb1: configuration #1 chosen from 1 choice

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 2 ports detected

Initializing USB Mass Storage driver...

usbcore: registered new interface driver usb-storage

USB Mass Storage support registered.

mice: PS/2 mouse device common for all mice

JZ SD/MMC card driver registered

usbcore: registered new interface driver hiddev

usbcore: registered new interface driver usbhid

drivers/hid/usbhid/hid-core.c: v2.6:USB HID core driver

JzSOC On-Chip I2S controller registered (DAC: DMA(play):9/IRQ41,

ADC: DMA(record):8/IRQ40)

JZ I2S OSS audio driver initialized

TCP cubic registered

NET: Registered protocol family 1

NET: Registered protocol family 17

RPC: Registered udp transport module.

RPC: Registered tcp transport module.

IP-Config: Guessing netmask 255.255.255.0

IP-Config: Complete:

device=eth0, addr=192.168.1.239, mask=255.255.255.0, gw=255.255.255.255,

host=192.168.1.239, domain=, nis-domain=(none),

bootserver=255.255.255.255, rootserver=192.168.1.234, rootpath=

Looking up port of RPC 100003/2 on 192.168.1.234

Looking up port of RPC 100005/1 on 192.168.1.234

VFS: Mounted root (nfs filesystem).

Freeing unused kernel memory: 172k freed

Algorithmics/MIPS FPU Emulator v1.5

INIT: version 2.86 booting

Starting udevd

Starting portmap daemon: portmap.

INIT: Entering runlevel: 5

Starting telnet daemon: telnetd.

Starting Dropbear SSH server: dropbear.

Starting Xserver

Ingenic Mobile Linux Platform

Kernel 2.6.24.3 on XBurst Core

192.168.1.239 login: jz4750fb_check_var, not implement

jz4750fb_set_par, not implemented

Ingenic Mobile Linux Platform

Kernel 2.6.24.3 on XBurst Core

192.168.1.239 login:

至此,网络文件系统挂载成功了。接下来回到ubuntu的putty终端,可以直接编辑一下nfsroot里开发板的启动配置文件。

由于我不需要默认的X桌面,因此我直接把运行级别改成3了:

root@ubuntu:/# cd /nfsroot/root-jz-20090216/

root@ubuntu:/nfsroot/root-jz-20090216#
ls

bin dev home linuxrc media proc root sys usr

Changelog etc lib make-release.sh mnt README sbin tmp var

root@ubuntu:/nfsroot/root-jz-20090216#
cd etc

root@ubuntu:/nfsroot/root-jz-20090216/etc#
ls

dbus-1 gconf hostname mtab pointercal rc1.d rc6.d shadow

default group init.d network profile rc2.d rcS.d shadow-

dropbear gshadow inittab pango profile.d rc3.d resolv.conf udev

fonts gtk-2.0 issue passwd protocols rc4.d scim X11

fstab hal issue.net passwd- rc0.d rc5.d services xml

root@ubuntu:/nfsroot/root-jz-20090216/etc#
vi inittab

在VI里把id:5:initdefault:改成id:3:initdefault:,保存退出,再重启,则X窗口不再启动。

另外,把上一篇写的HELLO程序复制到nfs目录:

root@ubuntu:/# cd /opt

root@ubuntu:/opt# ls

hello hello.c linux-2.6.24.3 mipseltools-gcc412-glibc261 u-boot-1.1.6

root@ubuntu:/opt# cp hello /nfsroot/root-jz-20090216/

root@ubuntu:/opt#

从COM终端中以root身份登录(如果登录界面没出来,可按一下回车,默认是没有密码的),可以根目录找到我们的hello程序,运行之:

192.168.1.239 login: root

login[332]: root login on 'console'

root@192.168.1.239:~# cd /

root@192.168.1.239:/# ls

bin home mnt sys

Changelog lib proc tmp

dev linuxrc README usr

etc make-release.sh root var

hello media sbin

root@192.168.1.239:/# ./hello

hello jz-mipsel-linux

root@192.168.1.239:/#

至此根文件系统运行正常,可以使用了。下一篇我们接着说QTE图形开发环境和TSLIB触摸屏配置。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: