君正4750开发板使用日记3-根文件系统、启动文件与helloworld

根文件系统、启动文件与helloworld

 

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触摸屏配置。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值