上班时间很少有机会搞这些东西,基本上都是下班在家里搞,不过在公司写写文挡还是可以的。调试uClinux也是断断续续进行的。以前根本没接触过linux,搞起来可真是头都要大了。虽说到最后调通比前面耗时少很多,主要原因是网上很多参考资料。但个人感觉这部分难度要更大一些。
接着前面的说吧,编译出一个uClinux的内核出来,就必须在linux环境下,windows下是编译不了的(如果可行的话,我很愿意那样做)。一阵迷惑,根本没有方向,从何下手。后来在44B0 QQ群里有人指点使用vmware + FC4。Vmware是一款虚拟平台软件,它支持在windows系统中运行linux,就好象cygwin一样,大家都说cygwin很复杂,不是很好用,我也不想去试了。FC4是Fedora Core 4的缩写,是Red Hat Linux平台的一个版本。
到网上下载vmware5,然后在windows下直接安装就可以了。安装后运行vmware,进行FC4的安装,这部分挺简单的,关于这方面的细节可以到网上查一下。注意一点,linux的空间尽量多分一点儿,最好不要小于8G。
到网上下载这三个文件: arm-elf-tools-20030314.sh
uClinux-dist-20040408.tar.gz
uClinux-20040408-ARMSYS.rar
参考下载地址:
http://www.uclinux.org/pub/uClinux/m68k-elf-tools/arm-elf-tools-20030314.sh
http://www.uclinux.org/pub/uClinux/dist/uClinux-dist-20040408.tar.gz
http://www.hzlitai.com.cn/download/uClinux-20040408-ARMSYS.rar
放到同一个文件夹中,例如:uClinux Share
然后就可以在windows上通过vmware启动FC4了,注意,启动之前修改一下linux光盘指向的内容,将光盘设置到VMware\VMware Workstation\linux.iso,这里放的是vmware-tools。然后启动就可以了。一下子就进入到了linux的世界。我以前从没玩过linux,但感觉linux还是很不错的。接下来就是安装vmware-tools,我们用这个工具主要是用于window系统和linux系统文件共享。
让虚拟机运行于窗口状态,不要全屏,按ctrl+alt让鼠标释放出来。在vmware的菜单栏上选择“虚拟机”/"安装虚拟机工具“。然后切换到客户操作系统,即linux。 双击linux的光盘图标进入linux的虚拟光盘,可以看到两个文件,一个是压缩包,一个是rmp包。右键点击rmp包,“用install Packages打开“。(如果不能正常打开虚拟光盘,可以从linux的终端里运行mount /media/cdrom)上述操作完成后,进入/usr/bin目录,查找vmware-config-tools.pl.(ls /usr/bin/*.pl).找到后,运行它。即(./vmware-config-tools.pl)注意,斜杠前有一个点。一路回车即可完成安装。
完成后,我们就可以在/mnt/hgfs中,看到我们刚才在vmware里设置的windows共享文件夹“uClinux Share”。接下来就是搭建uClinux交叉编译环境。
首先,我们安装arm-elf-tools。将arm-elf-tools-20030314.sh拷贝到根目录,运行安装:sh arm-elf-tools-20030314.sh
#ls /usr/local/bin
可以看到arm-elf-gcc已经安装ok.
然后,安装uClinux-dist内核。将uClinux-dist-20040408.tar.gz拷贝到/usr/local/bin 解压 uClinux-dist-20040408.tar.gz 文件到 uClinux-dist 目录:
tar xvzf uClinux-dist-20040408.tar.gz
此时当前工作目录下增加了一个名为 uClinux-dist 的目录。
接着,我们安装patch。将/usr/local/bin/uClinux-dist/vector/Samsung/4510B文件夹重命名成/usr/local/bin/uClinux-dist/vector/Samsung/44B0,将uClinux-20040408-ARMSYS.rar拷贝到uClinux-dist目录下,运行:
tar xvzf uClinux-ARMSYS-20040801.tar.gz
解压补丁包后,生成patch文件uClinux-20040408-ARMSYS.patch。然后,安装patch文件:
patch –p1 < uClinux-20040408-ARMSYS.patch
安装过程中可能会出现一些错误信息,可以手动地按照patch文件的内容在指定的文件处进行修改一下。主要修改对象是uClinux-dist/vector/Samsung/44b0文件夹中的两个文件:Makefile 和 rc。提醒大家注意这两个文件。(建议修改这两个文件之前,进行一次编译)
补丁打好后,我们还要做一些修改:
手动修改uClinux-dist/Makefile
在TFTPDIR = /tftpboot后加上:
LINUXTARGET=bzImage
否则make 不过。 在make image 时,cp命令,报找不到
$(ROOTDIR)/$(LINUXDIR)/arch/armnommu/root/zImage文件。不能生成image.rom文件。
make menuconfig
make dep
make clean
make lib_only
make user_only
make romfs
make image
make
生成image.rom后,通过共享文件夹uClinux Share 将image.rom传递到windows系统下。然后,切换到windows系统,将image.rom通过网线下载(我板子已经修好了)到ram,然后烧录到flash的0x100000位置,运行uclinux 没有反应。
错误在哪里呢?后来在立宇泰的论坛里找到了三个配置文件,(config_main/config_kernel/config_user)这三个文件都是make menuconfig时候用的。重新运行
make menuconfig
进入配置主界面。选中Customize Kernel Settings 和 user config setting(就是第二和第三项,具体记不清了)。退出保存,然后进入Customize Kernel Settings,选LOAD,输入文件所在路径。(例如:/mnt/hgfs/uClinux/config/config_kernel)注意,LOAD完成,此处去掉了USB选项。 保存,退出。 进入user config setting,同样方法LOAD config_user。保存,退出。然后,
make dep
make clean
make lib_only
make user_only
make romfs
make image
make
得到image.ram 和image.rom.。
将两个文件共享到windows下,用上面的方法,程序运行如下:
\>uclinux
Uncompressing Linux........................................................ done, booting the kernel.
Linux version 2.4.24-uc0 (root@localhost) (gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from http://www.snapgear.com/)) #13
Processor: Samsung S3C44B0X revision 0
Architecture: S3C44B0X
On node 0 totalpages: 2048
zone(0): 0 pages.
zone(1): 2048 pages.
zone(2): 0 pages.
Kernel command line: root=/dev/rom0 init=/ lnuxrc
然后就停止了。死机。。。。。。
后来发现这里是我的中断向量表出现了问题,中断地址应该指向uClinux运行的地址空间,即0x0c0000xx。修改之后编译得到boot.bin,烧录到FLASH的零地址。然后再次运行uClinux:
\>uclinux
Uncompressing Linux........................................................ done, booting the kernel.
Linux version 2.4.24-uc0 (root@localhost) (gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from http://www.snapgear.com/)) #23
Processor: Samsung S3C44B0X revision 0
Architecture: S3C44B0X
On node 0 totalpages: 2048
zone(0): 0 pages.
zone(1): 2048 pages.
zone(2): 0 pages.
Kernel command line: root=/dev/rom0 init=/linuxrc
Calibrating delay loop... 31.84 BogoMIPS
Memory: 8MB = 8MB total
Memory: 6252KB available (1591K code, 170K data, 44K init)
Dentry cache hash table entries: 1024 (order: 1, 8192 bytes)
Inode cache hash table entries: 512 (order: 0, 4096 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 2048 (order: 1, 8192 bytes)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Starting kswapd
ttyS0 at I/O 0x1d00000 (irq = 3) is a S3C44B0
ttyS1 at I/O 0x1d04000 (irq = 2) is a S3C44B0
Blkmem copyright 1998,1999 D. Jeff Dionne
Blkmem copyright 1998 Kenneth Albanowski
Blkmem 1 disk images:
0: C700000-CEFFFFF [VIRTUAL C700000-CEFFFFF] (RO)
RAMDISK driver initialized: 16 RAM disks of 1024K size 1024 blocksize
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 512 bind 512)
Kernel panic: VFS: Unable to mount root fs on 1f:00
然后又DOWN掉了。。。。。。。。。
后来找到了问题,问题出在文件系统romfs。
修改:/uClinux-dist/Linux-2.4.x/Driver/Block/blkmem.c
-#ifdef CONFIG_BOARD_SNDS100
+//#ifdef CONFIG_BOARD_SNDS100
extern char romfs_data[];
extern char romfs_data_end[];
-#endif
+//#endif
#ifdef CONFIG_BOARD_MBA44
-{0, 0xc700000, -1}, /*{0, 0x100000, -1}*/
+{0, romfs_data, -1}, /*{0, 0x100000, -1}*/
#endif
修改后
make linux
make
运行结果:
\>uclinux
Uncompressing Linux........................................................ done, booting the kernel.
Linux version 2.4.24-uc0 (root@localhost) (gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from http://www.snapgear.com/)) #23
Processor: Samsung S3C44B0X revision 0
Architecture: S3C44B0X
On node 0 totalpages: 2048
zone(0): 0 pages.
zone(1): 2048 pages.
zone(2): 0 pages.
Kernel command line: root=/dev/rom0 init=/linuxrc
Calibrating delay loop... 31.84 BogoMIPS
Memory: 8MB = 8MB total
Memory: 6252KB available (1591K code, 170K data, 44K init)
Dentry cache hash table entries: 1024 (order: 1, 8192 bytes)
Inode cache hash table entries: 512 (order: 0, 4096 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 2048 (order: 1, 8192 bytes)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Starting kswapd
ttyS0 at I/O 0x1d00000 (irq = 3) is a S3C44B0
ttyS1 at I/O 0x1d04000 (irq = 2) is a S3C44B0
Blkmem copyright 1998,1999 D. Jeff Dionne
Blkmem copyright 1998 Kenneth Albanowski
Blkmem 1 disk images:
0: C0ECCF0-C1A0CEF [VIRTUAL C0ECCF0-C1A0CEF] (RO)
RAMDISK driver initialized: 16 RAM disks of 1024K size 1024 blocksize
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 512 bind 512)
VFS: Mounted root (romfs filesystem) readonly.
Freeing init memory: 44Shell invoked to run file: /etc/rc
Command: hostname Samsung
Command: /bin/expand /etc/ramfs.img /dev/ram0
Command: /bin/expand /etc/ramfs2048.img /dev/ram1
Command: mount -t proc proc /proc
Command: mount -t ext2 /dev/ram0 /var
Command: mount -t ext2 /dev/ram1 /ramdisk
mount failed: No such file or directory
Command: chmod 777 /ramdisk
/ramdisk: No such file or directory
Command: mkdir /var/config
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: ifconfig lo 127.0.0.1
Command: route add -net 127.0.0.0 netmask 255.255.255.0 lo
Command: ifconfig eth0 192.168.168.101 netmask 255.255.255.0 up
SIOCSIFADDR: No such device
eth0: unknown interface: No such device
SIOCSIFNETMASK: No such device
eth0: unknown interface: No such device
pid 12: failed 65280
Command: cat /etc/motd
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|
For further information check:
http://www.uclinux.org/
Execution Finished, Exiting
Sash command shell (version 1.1.1)
/>
长出一口气,终于通了。
接着,我想大家都应该期待helloworld吧。下面开始。
cd /usr/local/bin/uClinux-dist/user
mkdir myapp
然后,在myapp文件夹里新建两个文件:helloworld.c 和 Makefile
helloworld.c文件如下编写:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
printf(“hello world ! \n”);
return 0;
}
Makefile 文件如下编写:
编辑后,保存两个文件。然后修改uClinux-dist/user/Makefile 文件:
dir_$(CONFIG_USER_ZEBRA_RIPD_RIPD) += zebra
dir_$(CONFIG_USER_ZEBRA_ZEBRA_ZEBRA) += zebra
+ dir_$(CONFIG_USER_MYAPP_HELLOWORLD) +=myapp
dir_y += games
all: config
然后修改uClinux-dist/config/config.in 文件:
在文件最后添加:
comment "Debug tools"
bool 'tpt' CONFIG_USER_TIMEPEG_TPT
comment "Debug libraries"
bool 'ccmalloc' CONFIG_LIB_LIBCCMALLOC
endmenu
#############################################################################
+mainmenu_option next_comment
+comment 'My App'
+bool 'helloworld' CONFIG_USER_MYAPP_HELLOWORLD
+bool 'app1' CONFIG_USER_MYAPP_APP1
+ comment 'My App'
+endmenu
保存文件修改。
然后运行:make menuconfig
进入Kernel/library/Defaults Setting
空格键选中Custom Vector/User Setting, 保存退出。
程序自动进入Custom Vector/User Setting:
进入My App
空格选中 helloworld, 保存退出。
make user_only
make romfs
make image
make
得到image.rom 和 image.ram.
将image.rom 烧到板子上,运行结果如下:
\>uclinux
Uncompressing Linux......................................................... done, booting the kernel.
Linux version 2.4.24-uc0 (root@localhost) (gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from http://www.snapgear.com/)) #25
Processor: Samsung S3C44B0X revision 0
Architecture: S3C44B0X
On node 0 totalpages: 2048
zone(0): 0 pages.
zone(1): 2048 pages.
zone(2): 0 pages.
Kernel command line: root=/dev/rom0 init=/linuxrc
Calibrating delay loop... 31.84 BogoMIPS
Memory: 8MB = 8MB total
Memory: 6228KB available (1618K code, 167K data, 44K init)
Dentry cache hash table entries: 1024 (order: 1, 8192 bytes)
Inode cache hash table entries: 512 (order: 0, 4096 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 2048 (order: 1, 8192 bytes)
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Starting kswapd
ttyS0 at I/O 0x1d00000 (irq = 3) is a S3C44B0
ttyS1 at I/O 0x1d04000 (irq = 2) is a S3C44B0
Blkmem copyright 1998,1999 D. Jeff Dionne
Blkmem copyright 1998 Kenneth Albanowski
Blkmem 1 disk images:
0: C0ECCF0-C1A78EF [VIRTUAL C0ECCF0-C1A78EF] (RO)
RAMDISK driver initialized: 16 RAM disks of 1024K size 1024 blocksize
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 512 bind 512)
VFS: Mounted root (romfs filesystem) readonly.
Freeing init memory: 44Shell invoked to run file: /etc/rc
Command: hostname Samsung
Command: /bin/expand /etc/ramfs.img /dev/ram0
Command: /bin/expand /etc/ramfs2048.img /dev/ram1
Command: mount -t proc proc /proc
Command: mount -t ext2 /dev/ram0 /var
Command: mount -t ext2 /dev/ram1 /ramdisk
mount failed: No such file or directory
Command: chmod 777 /ramdisk
/ramdisk: No such file or directory
Command: mkdir /var/config
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: ifconfig lo 127.0.0.1
Command: route add -net 127.0.0.0 netmask 255.255.255.0 lo
Command: ifconfig eth0 192.168.168.101 netmask 255.255.255.0 up
SIOCSIFADDR: No such device
eth0: unknown interface: No such device
SIOCSIFNETMASK: No such device
eth0: unknown interface: No such device
pid 12: failed 65280
Command: cat /etc/motd
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|
For further information check:
http://www.uclinux.org/
Execution Finished, Exiting
Sash command shell (version 1.1.1)
/> ls
bin
dev
etc
home
lib
mnt
proc
sbin
tmp
usr
var
/> cd bin
/bin> ls
arp
boa
expand
helloworld
httpd
ifconfig
inetd
init
ping
portmap
route
sh
snmpd
/bin> helloworld
hello world !