最近在研究android的移植,目標平台是s3c6410。
在網上看到很多高手的文章,得到很多啟發。
這裡有一篇如何使用nfs作為根檔案系統的文章,寫的不錯, 轉載到這裡了,看了這篇文章以後,根據自己的使用心得,把自己的使用方法也寫了下來,供大家參考
[First written by Steve Guo, please keep the mark if forwarding.]Usually the Android uses YAFFS as rootfs and uses the mtd device as storage media, the bad blocks in the mtd device seldom cause YAFFS file system to work abnormally. if the Android uses NFS as the rootfs, there will not exist such problem. So here is the solution to use NFS as the rootfs of Android.
1. Setup host machine as NFS server (I will use ubuntu 8.0.4 as an example.).
$ sudo apt-get install nfs-kernel-server portmap
$ sudo mkdir /nfsroot
$ sudo vim /etc/exports
Add one line in /etc/exports,
/nfsroot 192.168.1.101(rw,no_root_squash,sync)
Then restart NFS server.
$ sudo /etc/init.d/nfs-kernel-server restart Here setups an NFS server which exports /nfsroot directory only to 192.168.1.101(Which is the default IP address of Android eth0).
2. Build a Linux kernel image to use NFS as rootfs.
$make menuconfig
Modify the default setup. In "general setup" section, uncheck the "initial RAM filesystem and RAM disk(initramfs/initrd) support". In "file systems" section, check the "Network File Systems" and mark it as kernel built-in. In "boot options" section, add the kernel parameter "root=/dev/nfs nfsroot=192.168.1.100:/nfsroot init=/init". 192.168.1.100 is the IP address of host machine running NFS server.
3. Modify init program.
To make log system work, in the device/system/init modify the device.c by change the statement '!strncmp(uevent->path,"/class/misc/",12) && !strncmp(name, "log_", 4) to '!strncmp(name, "log_", 4)'.
4. Modify init.rc config file.
Comment out below statements
mount rootfs rootfs /ro remount
mount yaffs mtd@system /system
mount yaffs2 mtd@system /system ro remout
mount yaffs2 mtd@userdata /data nosuid nodev
mount yaffs2 mtd@cache /cache nosuid nodev
5. Add the user id and group id used by android on the NFS server.
Android does not use /ect/passwd file to record the user name and user id, it uses a fixed method to map the user name to user id through the head file device/include/private/android_filesystem_config.h, e.g. the user "system" has the user id of 1000.
So to correctly set the file ownership(owner and group), the NFS server should have these users with correct user IDs. Such as system(1000). For ubuntu, you can call like this.
$sudo userdd -u 1000 android_system
This step is not necessary. It only allows you to display a user name in the develop machine.
6. Prepare the rootfs.
Assume the built output of device lies in device/out/target/product/***/, which is called $OUTPUTDIR later. Do the follwings:
$cp -rf $OUTPUTDIR/root/* /nfsroot
$cp -rf $OUTPUTDIR/system /nfsroot
$cp -rf $OUTPUTDIR/data /nfsroot
使用心得:
我在使用NFS過程中第二步驟與作者的不同,我是設定的Uboot的啟動參數,沒有像作者那樣在linux核心 中固定參數,我在Uboot中設定的參數是這樣的:
setenv bootargs "root=/dev/nfs nfsroot=192.168.0.232:/forlinux/root ip=192.168.0.231:192.168.0.232:192.168.0.201:255.255.255.0:witech.com.cn:eth0:off init=/linuxrc console=ttySAC0,115200 "
saveenv
其中 192.168.0.232是主機IP(運行Ubuntu系統的PC),192.168.0.231是Android嵌入式裝置的IP地址,在這裡設定。192.168.0.201是我的網路的網關,當然這三個IP地址可以跟據你的當前網路情況來設定,不一定跟我的相同。
:/forlinux/root 是NFS開放的目錄,裡面存放著Android的檔案系統,跟作者第一步驟中 /nfsroot 192.16 8.1.101(rw,no_root_squash,sync) 雷同,他開放的是 /nfsroot目錄,我開放的是 /forlinux/root目錄。
設定好參數後就可以順利的掛載NFS檔案系統了。