移植全过程
我们采用的方法,是在windows下进行sopc builder的设计,在linux进行uclinux的内核的编译,以及交叉编译环境的建立。从而产生uClinux的镜像文件(机器码流)。
需要准备的文件:A、nios2gcc.tar.bz2(交叉编译环境的linux安装文件,可以是其他格式的)。
B、uclinux-dist20060803(uclinux内核文件,可以是别的版本)
C、uclinux-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 functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/bin:/opt/nios2/binexport PATHunset 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/specsConfigured 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=-staticThread model: posixgcc 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 II:uClinux-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.archpatching file vendors/Altera/nios2nommu/config.linux-2.6.xpatching file lib/libpng/Makefilepatching file linux-2.6.x/include/asm-nios2nommu/ide.hpatching file linux-2.6.x/include/linux/elf-em.hpatching file linux-2.6.x/usr/Makefilepatching file linux-2.6.x/arch/nios2nommu/kernel/vmlinux.lds.Spatching file linux-2.6.x/arch/nios2nommu/drivers/Kconfigpatching file linux-2.6.x/arch/nios2nommu/drivers/altcf.cpatching file linux-2.6.x/arch/nios2nommu/drivers/pci/Kconfigpatching file linux-2.6.x/arch/nios2nommu/drivers/pci/pci-auto.cpatching file linux-2.6.x/arch/nios2nommu/drivers/pci/pci.cpatching file linux-2.6.x/arch/nios2nommu/drivers/pci/Makefilepatching file linux-2.6.x/arch/nios2nommu/drivers/spi.cpatching file linux-2.6.x/arch/nios2nommu/drivers/Makefilepatching file linux-2.6.x/drivers/mtd/maps/altera.cpatching file linux-2.6.x/drivers/mtd/maps/Kconfigpatching file linux-2.6.x/drivers/net/Kconfigpatching file linux-2.6.x/drivers/net/Makefilepatching file linux-2.6.x/drivers/net/dm9ks.cpatching file linux-2.6.x/drivers/net/open_eth.cpatching file linux-2.6.x/drivers/net/dm9000.cpatching file linux-2.6.x/drivers/net/Space.cpatching file linux-2.6.x/drivers/net/smc91x.cpatching file linux-2.6.x/drivers/net/smc911x.cpatching file linux-2.6.x/drivers/net/mtip1000.cpatching file linux-2.6.x/drivers/usb/Kconfigpatching file linux-2.6.x/drivers/usb/host/Kconfigpatching file linux-2.6.x/drivers/usb/host/isp1362-hcd.cpatching file linux-2.6.x/drivers/usb/host/Makefilepatching file linux-2.6.x/drivers/usb/host/isp1362.hpatching file linux-2.6.x/drivers/usb/Makefilepatching file linux-2.6.x/drivers/ide/ide.cpatching file user/microwin/src/fonts/X6x13.cpatching file user/microwin/src/demos/nxroach/Makefilepatching file user/microwin/src/demos/nanox/nxterm.cpatching file user/microwin/src/demos/nanox/nterm.cpatching file user/microwin/src/demos/nxkbd/keynum.cpatching file user/microwin/src/demos/nxkbd/keyctrl.cpatching file user/microwin/src/demos/nxkbd/keyshft.cpatching file user/microwin/src/Makefile.rulespatching file user/microwin/src/drivers/kbd_ttyscan.cpatching file user/microwin/src/drivers/scr_fb.cpatching file user/microwin/src/drivers/mou_ser.cpatching file user/ftpd/ftpcmd.cpatching 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/srcStep 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.071Selection: 1--- Please select a device to upload the kernel to:(1) cfi_flash_0 Class: altera_avalon_cfi_flash Size: 4194304 bytesSelection: 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 bytesSelection: 2
最後成功的結果如下所示
--- Summary usingPTF: /usr/local/src/system_0.ptfCPU: cpu_0Device to upload to: cfi_flash_0Program memory to execute from: sdram_0--- Settings written to /usr/local/src/uClinux-dist/linux-2.6.x/arch/nios2nommu/hardware.mkmake[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、 启动altera的command 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.sofInfo: *******************************************************************Info: Running Quartus II ProgrammerInfo: Command: quartus_pgm --no_banner --mode=jtag -o p;DE2_NIOS.sofInfo: Using programming cable "USB-Blaster [USB-0]"Info: Started Programmer operation at Mon Jun 09 03:01:45 2008Info: Configuring device index 1Info: Device 1 contains JTAG ID code 0x020B40DDInfo: Configuration succeeded -- 1 device(s) configuredInfo: Successfully performed operation(s)Info: Ended Programmer operation at Mon Jun 09 03:01:46 2008Info: 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 0x00Pausing target processor: OKInitializing CPU cache (if present)OKDownloaded 1197KB in 14.4s (83.1KB/s)Verified OKStarting 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 PREMPT Sun Jun 8 23:28:30 CST 2008uClinux/Nios IIAltera Nios II support (C) 2004 Microtronix Datacom Ltd.Built 1 zonelists. Total pages: 2032Kernel 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: 512NET: Registered protocol family 16NET: Registered protocol family 2IP 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 registeredio scheduler noop registeredio scheduler deadline registered (default)Serial: JTAG UART driver $Revision: 1.3 $ttyJ0 at MMIO 0x806810f0 (irq = 1) is a jtag_uartTCP cubic registeredNET: Registered protocol family 1NET: Registered protocol family 17Freeing unused kernel memory: 572k freed (0x97a000 - 0xa08000)Shell invoked to run file: /etc/rcCommand: hostname uClinuxCommand: mount -t proc proc /procCommand: mount -t sysfs sysfs /sysCommand: mount -t usbfs none /proc/bus/usbmount: Mounting none on /proc/bus/usb failed: No such file or directoryCommand: mkdir /var/tmpCommand: mkdir /var/logCommand: mkdir /var/runCommand: mkdir /var/lockCommand: mkdir /var/emptyCommand: ifconfig lo 127.0.0.1Command: route add -net 127.0.0.0 netmask 255.0.0.0 loCommand: cat /etc/motdWelcome to ____ _ _ / __| ||_| _ _| | | | _ ____ _ _ _ _ | | | | | | || | _ \| | | |\ \/ / | |_| | |__| || | | | | |_| |/ \ | ___\____|_||_|_| |_|\____|\_/\_/ | | |_|For further information check:http://www.uclinux.org/Execution Finished, ExitingSash command shell (version 1.1.1)/>
如果你看到上面的结果,表明你的uClinux移植成功了。但是反映在硬件上的效果不明显,这个要看你的具体的linux应用程序了。
本文来源:https://www.2haoxitong.net/k/doc/e668dd2869eae009581becd1.html
文档为doc格式