在nios II中移植linux系统

发布时间:2014-12-26 21:12:32   来源:文档文库   
字号:

移植全过程

我们采用的方法,是在windows下进行sopc builder的设计,在linux进行uclinux的内核的编译,以及交叉编译环境的建立。从而产生uClinux的镜像文件(机器码流)。

需要准备的文件:Anios2gcc.tar.bz2(交叉编译环境的linux安装文件,可以是其他格式的)

Buclinux-dist20060803uclinux内核文件,可以是别的版本)

Cuclinux-dist20060803-nios2-diff.tar.bz2(目前没有明白为什么要有这个文件,没有还不行)

一:交叉编译环境的建立

1、把nios2gcc.tar.bz2放在目录:/usr/local/src里面,将nios2gcc.tar.bz2解压进/opt/nios2目录下(这个默认的,不用进行目录操作)

[root@localhost src]# tar -jxvf nios2gcc.tar.bz2 -C /

2、设定交叉编译器的路径:

[root@localhost src]# vi ~/.bash_profile

修改bash_profile的內容如下所示,加上/opt/nios2/bin路径

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/opt/nios2/bin

export PATH
unset USERNAME

3、执行下面一条命令,使设置的路径有效

[root@localhost src]# source ~/.bash_profile

注:这里你可以进行一下测试。看看你的交叉编译环境是否已经建成,也可以略过不做。方法:

[root@localhost src]# nios2-linux-uclibc-gcc v

Reading specs from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/specs
Configured with: /root/buildroot/toolchain_build_nios2/gcc-3.4.6/configure --prefix=/opt/nios2 --build=i386-pc-linux-gnu --host=i386-pc-linux-gnu --target=nios2-linux-uclibc --enable-languages=c --enable-shared --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-nls --enable-threads --disable-multilib --enable-cxx-flags=-static
Thread model: posix
gcc version 3.4.6

二:编译uclinux内核

1、 uclinux-dist20060803放进/usr/local/src,解压缩。

[root@localhost src]# tar -zxvf uClinux-dist-20070130.tar.tar

如果你是在linux系统下(意思是指不是虚拟机),硬盘够大的话,就不应该有问题出现。解压缩之后,一般应该接近1.9G大小。

2、 uclinux打补丁

μClinux kernel patch for Nios IIuClinux-dist-20070130-nios2-02.7z/usr/local/src/uClinux-dist
安裝μClinux kernel patch for Nios II

[root@localhost src]# cd uClinux-dist

[root@localhost uClinux-dist]# gunzip -c uClinux-dist-20070130-nios2-02.diff.gz | patch -p0

出现以下的结果就表明,补丁打成功。

patching file vendors/Altera/nios2nommu/config.arch
patching file vendors/Altera/nios2nommu/config.linux-2.6.x
patching file lib/libpng/Makefile
patching file linux-2.6.x/include/asm-nios2nommu/ide.h
patching file linux-2.6.x/include/linux/elf-em.h
patching file linux-2.6.x/usr/Makefile
patching file linux-2.6.x/arch/nios2nommu/kernel/vmlinux.lds.S
patching file linux-2.6.x/arch/nios2nommu/drivers/Kconfig
patching file linux-2.6.x/arch/nios2nommu/drivers/altcf.c
patching file linux-2.6.x/arch/nios2nommu/drivers/pci/Kconfig
patching file linux-2.6.x/arch/nios2nommu/drivers/pci/pci-auto.c
patching file linux-2.6.x/arch/nios2nommu/drivers/pci/pci.c
patching file linux-2.6.x/arch/nios2nommu/drivers/pci/Makefile
patching file linux-2.6.x/arch/nios2nommu/drivers/spi.c
patching file linux-2.6.x/arch/nios2nommu/drivers/Makefile
patching file linux-2.6.x/drivers/mtd/maps/altera.c
patching file linux-2.6.x/drivers/mtd/maps/Kconfig
patching file linux-2.6.x/drivers/net/Kconfig
patching file linux-2.6.x/drivers/net/Makefile
patching file linux-2.6.x/drivers/net/dm9ks.c
patching file linux-2.6.x/drivers/net/open_eth.c
patching file linux-2.6.x/drivers/net/dm9000.c
patching file linux-2.6.x/drivers/net/Space.c
patching file linux-2.6.x/drivers/net/smc91x.c
patching file linux-2.6.x/drivers/net/smc911x.c
patching file linux-2.6.x/drivers/net/mtip1000.c
patching file linux-2.6.x/drivers/usb/Kconfig
patching file linux-2.6.x/drivers/usb/host/Kconfig
patching file linux-2.6.x/drivers/usb/host/isp1362-hcd.c
patching file linux-2.6.x/drivers/usb/host/Makefile
patching file linux-2.6.x/drivers/usb/host/isp1362.h
patching file linux-2.6.x/drivers/usb/Makefile
patching file linux-2.6.x/drivers/ide/ide.c
patching file user/microwin/src/fonts/X6x13.c
patching file user/microwin/src/demos/nxroach/Makefile
patching file user/microwin/src/demos/nanox/nxterm.c
patching file user/microwin/src/demos/nanox/nterm.c
patching file user/microwin/src/demos/nxkbd/keynum.c
patching file user/microwin/src/demos/nxkbd/keyctrl.c
patching file user/microwin/src/demos/nxkbd/keyshft.c
patching file user/microwin/src/Makefile.rules
patching file user/microwin/src/drivers/kbd_ttyscan.c
patching file user/microwin/src/drivers/scr_fb.c
patching file user/microwin/src/drivers/mou_ser.c
patching file user/ftpd/ftpcmd.c
patching file user/ftpd/Makefile

出现的顺序可能不同,出现类似的画面,就应该没有问题。

三、进行内核配置(基本都是默认配置)

需要注意的是:里面的每一步,都应该和界面的配置一致。如果有后面make时,有什么error,最好回来仔细检查一下这些默认配置(这些网上找的)。

[root@localhost uClinux-dist]# make menuconfig


Vendor/Product Selection如下設定


Kernel/Library/Defaults Selection如下設定


最後選存檔


Step 6
SOPC Builder設定檔system_0.ptf複製到/usr/local/src

Step 7
根據DE2硬體配置設定make file

[root@localhost uClinux-dist]# make vendor_hwselect SYSPTF=/usr/local/src/system_0.ptf


最後會有選擇動作,分別選擇 1 (CPU_0)1 (cfi_flash_0)2 (sdram)

--- Please select which CPU you wish to build the kernel against:

(1) cpu_0 - Class: altera_nios2 Type: f Version: 7.071

Selection: 1

--- Please select a device to upload the kernel to:

(1) cfi_flash_0
        Class: altera_avalon_cfi_flash
        Size: 4194304 bytes

Selection: 1

--- Please select a device to execute kernel from:

(1) sram_0
        Class: sram_16bit_512k
        Size: 524288 bytes

(2) sdram_0
        Class: altera_avalon_new_sdram_controller
        Size: 8388608 bytes

(3) epcs_controller
        Class: altera_avalon_epcs_flash_controller
        Size: 2048 bytes

Selection: 2


最後成功的結果如下所示

--- Summary using

PTF: /usr/local/src/system_0.ptf
CPU:                            cpu_0
Device to upload to:            cfi_flash_0
Program memory to execute from: sdram_0

--- Settings written to /usr/local/src/uClinux-dist/linux-2.6.x/arch/nios2nommu/hardware.mk

make[3]: Leaving directory `/usr/local/src/uClinux-dist/linux-2.6.x'
make[2]: Leaving directory `/usr/local/src/uClinux-dist/vendors/Altera/nios2nommu'
make[1]: Leaving directory `/usr/local/src/uClinux-dist/vendors'


Step 8
建立romfs資料夾,過程會有錯誤訊息,可忽略。

[root@localhost uClinux-dist]# make romfs


Step 9
編譯μClinux核心

[root@localhost uClinux-dist]# make


Step 10
產生image

[root@localhost uClinux-dist]# make linux image


最後會在/usr/local/src/uClinux-dist/linux-2.6.x/arch/nios2nommu/boot/下找到zImage
注意:zImage文件是make时,就已经产生,那个只是一个初步的,没有bootloader的文件,如果你想使你的uClinux在硬件上运行,必须进行make linux image这条命令,从而加上bootloader

四:uClinux写入硬件

1、 把你的.ptf文件对应的.sof文件和生成的镜像文件zImage一起放在\altera\72\nios2eds\examples下。

2、 启动alteracommand shell。开始->程序->altera->nios2 EDS->nios2.command shell

3、 先进行硬件配置(注意必须先在quartus中把.sof文件烧进去)

[SOPC Builder]$ nios2-configure-sof DE2_NIOS.sof

执行结果:Searching for SOF file:
in .
  DE2_NIOS.sof

Info: *******************************************************************
Info: Running Quartus II Programmer
Info: Command: quartus_pgm --no_banner --mode=jtag -o p;DE2_NIOS.sof
Info: Using programming cable "USB-Blaster [USB-0]"
Info: Started Programmer operation at Mon Jun 09 03:01:45 2008
Info: Configuring device index 1
Info: Device 1 contains JTAG ID code 0x020B40DD
Info: Configuration succeeded -- 1 device(s) configured
Info: Successfully performed operation(s)
Info: Ended Programmer operation at Mon Jun 09 03:01:46 2008
Info: Quartus II Programmer was successful. 0 errors, 0 warnings
    Info: Allocated 54 megabytes of memory during processing
    Info: Processing ended: Mon Jun 09 03:01:46 2008
    Info: Elapsed time: 00:00:02

4、 zImage下到sdram里面

[SOPC Builder]$ nios2-download -g zImage

执行的结果:Using cable "USB-Blaster [USB-0]", device 1, instance 0x00
Pausing target processor: OK
Initializing CPU cache (if present)
OK
Downloaded 1197KB in 14.4s (83.1KB/s)
Verified OK
Starting processor at address 0x00D00000

5、 启动uClinux

[SOPC Builder]$ nios2-terminal

执行结果:Uncompressing Linux Ok, booting the kernel.
Linux version 2.6.19-uc1 (root@localhost.localdomain) (gcc version 3.4.6) #2 PR
EMPT Sun Jun 8 23:28:30 CST 2008


uClinux/Nios II
Altera Nios II support (C) 2004 Microtronix Datacom Ltd.
Built 1 zonelists.  Total pages: 2032
Kernel command line:
PID hash table entries: 32 (order: 5, 128 bytes)
Dentry cache hash table entries: 1024 (order: 0, 4096 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory available: 5956k/8192k RAM, 0k/0k ROM (1465k kernel code, 680k data)
Mount-cache hash table entries: 512
NET: Registered protocol family 16
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 0, 4096 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
io scheduler noop registered
io scheduler deadline registered (default)
Serial: JTAG UART driver $Revision: 1.3 $
ttyJ0 at MMIO 0x806810f0 (irq = 1) is a jtag_uart
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
Freeing unused kernel memory: 572k freed (0x97a000 - 0xa08000)
Shell invoked to run file: /etc/rc
Command: hostname uClinux
Command: mount -t proc proc /proc
Command: mount -t sysfs sysfs /sys
Command: mount -t usbfs none /proc/bus/usb
mount: Mounting none on /proc/bus/usb failed: No such file or directory
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: mkdir /var/empty
Command: ifconfig lo 127.0.0.1
Command: route add -net 127.0.0.0 netmask 255.0.0.0 lo
Command: cat /etc/motd
Welcome to
          ____ _  _
         /  __| ||_|
    _   _| |  | | _ ____  _   _  _  _
   | | | | |  | || |  _ \| | | |\ \/ /
   | |_| | |__| || | | | | |_| |/    \
   |  ___\____|_||_|_| |_|\____|\_/\_/
   | |
   |_|

For further information check:
http://www.uclinux.org/

Execution Finished, Exiting

Sash command shell (version 1.1.1)
/>

如果你看到上面的结果,表明你的uClinux移植成功了。但是反映在硬件上的效果不明显,这个要看你的具体的linux应用程序了。

本文来源:https://www.2haoxitong.net/k/doc/e668dd2869eae009581becd1.html

《在nios II中移植linux系统.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式