Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1149264
  • 博文数量: 173
  • 博客积分: 4048
  • 博客等级:
  • 技术积分: 2679
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-12 18:53
文章分类

全部博文(173)

文章存档

2018年(1)

2016年(1)

2013年(1)

2012年(118)

2011年(52)

分类: 嵌入式

2012-03-27 09:55:34

参考


一、编译环境搭建(安装无mmuuclinux

VMware上安装Ubuntu10.04*1

默认情况下,Ubuntu中的vi编辑器并不好用,左右键不正常,需先安装vim-full,但ubuntu-10.04-desk-i386.iso中的默认的源无法访问了。由于无法直接在WINDOWSVmware中直接传递大型的文件(尽管已经安装Vmware Tools),所以必须进行SAMBA服务器的配置。

二、配置SAMBA

  1. 使用sudo apt-get install samba安装samba软件包

  2. 修改SAMBA配置文件/etc/samba/smb.conf:

[share]

guest ok = yes

writeable = yes

browseable = yes

path = /home/share

3)激活配置文件source smb.conf

4)更改path中文件的权限:sudo chmod 777 /home/share.如果不进行更改:windows中出现以下错误:

  1. InstallNios2Linux

1)安装或下载源码和编译工具。

sudo apt-get install git-core git-gui make gcc ncurses-dev bison flex gawk \ gettext ccache zlib1g-dev libx11-dev texinfo liblzo2-dev pax-utils uboot-mkimage corkscrew


在编译工具链之前,先安装以上这些工具。如若不安装完全,在后面的编译工具链和编制内核的时候可能出现错, Ncurses是一个能提供基于文本终端窗口功能的动态库。在Ubuntu安装的时候应注意,安装ncurses-dev库时可能会显示 “无法找到软件包ncurses-dev,如下图:

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

E: 无法找到软件包ncurses-dev

注意,选取libncurses5-dev而非ncurses-dev


2).sudo apt-get insatll libncurses5-dev

3). 在完成了上述库的安装后,可按下一条命令检查是否安装完全。

sudo apt-get install git-core git-gui make gcc libncurses5-dev bison flex gawk gettext ccache zliblg-dev texinfo liblzo2-dev paxutils uboot-mkimage corkscrew

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

git-core已经是最新的版本了。

git-gui已经是最新的版本了。

make已经是最新的版本了。

gcc已经是最新的版本了。

libncurses5-dev已经是最新的版本了。

bison已经是最新的版本了。

flex已经是最新的版本了。

gawk已经是最新的版本了。

gettext已经是最新的版本了。

ccache已经是最新的版本了。


4).检查默认的shell是否是bash

ls -l /bin/sh

lrwxrwxrwx 1 root root 4 2010-09-03 19:22 /bin/sh -> dash

6).如若不是,需改成bash

sudo rm /bin/sh

sudo ln -s bash /bin/sh

lrwxrwxrwx 1 root root 4 2010-09-03 19:23 /bin/sh -> bash

7).注销重新登录,检查cc’是否链接向了gcc’

which gcc

/usr/bin/gcc

tlinux@tlinux-desktop:uClinux-dist$ gcc -v

Using built-in specs.

Target: i486-linux-gnu

Configured with: ../src/configure -v—with-pkgversion=’Ubuntu 4.4.3-4ubuntu5’—with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs—enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr—enable-shared—enable-multiarch—enable-linker-build-id—with-system-zlib—libexecdir=/usr/lib—without-included-gettext—enable-threads=posix—with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls—enable-clocale=gnu—enable-libstdcxx-debug—enable-plugin—enable-objc-gc—enable-targets=all—disable-werror—with-arch-32=i486 --with-tune=generic—enable-checking=release—build=i486-linux-gnu—host=i486-linux-gnu—target=i486-linux-gnu

Thread model: posix

gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

tlinux@tlinux-desktop:uClinux-dist$ which cc

/usr/bin/cc

tlinux@tlinux-desktop:uClinux-dist$ cc -v

Using built-in specs.

Target: i486-linux-gnu

Configured with: ../src/configure -v—with-pkgversion=’Ubuntu 4.4.3-4ubuntu5’—with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs—enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr—enable-shared—enable-multiarch—enable-linker-build-id—with-system-zlib—libexecdir=/usr/lib—without-included-gettext—enable-threads=posix—with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls—enable-clocale=gnu—enable-libstdcxx-debug—enable-plugin—enable-objc-gc—enable-targets=all—disable-werror—with-arch-32=i486 --with-tune=generic—enable-checking=release—build=i486-linux-gnu—host=i486-linux-gnu—target=i486-linux-gnu

Thread model: posix

gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

如若不是,则需修改:

cd /usr/bin

ln –s gcc cc

8)、下载nios2-linux软件包。这里是最新的nios2-linux-20100621.tar

9)、校验工具包

10)、解压工具包并checkout

tlinux@tlinux-desktop:share$ tar xf nios2-linux-20100621.tar

tlinux@tlinux-desktop:share$ cd nios2-linux/

tlinux@tlinux-desktop:nios2-linux$ ./checkout

Checking out files: 100% (20582/20582), done.

Checking out files: 100% (32524/32524), done.

Checking out files: 100% (9577/9577), done.

Checking out files: 100% (8238/8238), done.

Checking out files: 100% (186060/186060), done.

11)、编译工具链tools chain或者下载编译好的工具链并且修改PATH

tar jxvf nios2gcc-20080203.tar.bz2


~/.bashrc 中修改


PATH=$PATH:/opt/nios2/bin


增加命令的搜寻路径


检查成功安装工具链


lulin@lulinVMware:/home/niosPrj/nios2-linux/linux-2.6$ nios2-linux-uclibc-gcc -v

Reading specs f

rom /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-language


s=c,c++ --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-shared --disabl


e-nls --enable-threads --enable-multilib


Thread model: posix


gcc version 3.4.6


更新配置

tlinux@tlinux-desktop:uClinux-dist$ Source ~/.bashrc

12)、查看分支

tlinux@tlinux-desktop:nios2-linux$ cd uClinux-dist/

tlinux@tlinux-desktop:uClinux-dist$ git branch -a

test-nios2

trunk

remotes/origin/HEAD -> origin/test-nios2

remotes/origin/test-nios2

remotes/origin/trunk

remotes/origin/unstable

tlinux@tlinux-desktop:uClinux-dist$ git checkout test-nios2

Checking out files: 100% (150861/150861), done.

Switched to branch ‘test-nios2’

tlinux@tlinux-desktop:nios2-linux$ cd linux-2.6

git branch -a

nios2mmu

test-nios2

remotes/origin/HEAD -> origin/test-nios2

remotes/origin/master

remotes/origin/nios2-mmu-nommu-merge

remotes/origin/nios2mmu

remotes/origin/test-lm32

remotes/origin/test-nios2

remotes/origin/unstable

remotes/origin/unstable-nios2mmu

remotes/origin/v2.6.21-nios2mmu

git checkout test-nios2

Checking out files: 100% (21499/21499), done.

Switched to branch ‘test-nios2’

13)、默认情况下编译一次验证开发包的正确性

tlinux@tlinux-desktop:uClinux-dist$ :make menuconfig

屏幕过小出现问题:





扩大窗口

重新make menuconfig

--- Select the Vendor you wish to target

Vendor (Altera) --->

--- Select the Product you wish to target

Altera Products (nios2) --->

--- Kernel is linux-2.6.x

Libc Version (None) --->

[*] Default all settings (lose changes)

[ ] Customize Kernel Settings (NEW)

[ ] Customize Application/Library Settings (NEW)

[ ] Update Default Vendor Settings (NEW)

Do you wish to save your new kernel configuration?

to continue.

< Yes > < No >

结果可能出现一个[Y/N]的选择,直接按回车即可。



选择quartus设计文件

make vendor_hwselect SYSPTF=

system.ptfquartus工程文件

选择linux系统运行的硬件

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




(1) cpu - Class: altera_nios2 Type: f Version: 7.08100




Selection: 1




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




(1) onchip_mem


Class: altera_avalon_onchip_memory2


Size: 4096 bytes




(2) altmemddr


Class: ddr2_high_perf


Size: 1073741824 bytes




Selection: 2





保存配置后make

root@tlinux-desktop:/home/nios2-linux/uClinux-dist# make

最后出现提示表明开发包正确。

cp /home/nios2-linux/uClinux-dist/linux-2.6.x/arch/nios2/boot/zImage /home/nios2-linux/uClinux-dist/images/zImage.initramfs.gz

cp /home/nios2-linux/uClinux-dist/linux-2.6.x/System.map /home/nios2-linux/uClinux-dist/images/System.map.initramfs.gz

cp /home/nios2-linux/uClinux-dist/linux-2.6.x/vmlinux /home/nios2-linux/uClinux-dist/images/linux.initramfs.gz

nios2-linux-gnu-strip -g /home/nios2-linux/uClinux-dist/images/linux.initramfs.gz

ln -sf zImage.initramfs.gz /home/nios2-linux/uClinux-dist/images/zImage

nios2-linux-gnu-strip -g /home/nios2-linux/uClinux-dist/images/zImage.initramfs.gz

make[4]:正在离开目录 ‘/home/nios2-linux/uClinux-dist/vendors/Altera/nios2’

make[3]:正在离开目录 ‘/home/nios2-linux/uClinux-dist/vendors/Altera/nios2’

make[2]:正在离开目录 ‘/home/nios2-linux/uClinux-dist/vendors/Altera/nios2’

make[1]:正在离开目录 ‘/home/nios2-linux/uClinux-dist/vendors’


四、定制开发板

Create a Nios II design with MMU

The low memory, which kernel can access without TLB, is 0x0-0x1fffffff physical address (512MB span). Divide this by 2 gives 256MB. In order to run a single kernel image on different hardware using fdt, we should setup a hardware design guide line that sdram base should be at 0x10000000 physical address. All other components, such as flash, serial and ethernet, should be placed in 0x00000000-0x0fffffff (256MB span).

1. Add a 512B or 1KB dual-port tightly coupled memory. Connect one port to tightly_coupled_instruction_master, and the other port to tightly_coupled_data_master. Both ports must be located at the same address.

tcm6.png

tcm5.png

tcm3.png

2. Include MMU to your Nios II processor using SOPC builder. Assign "Fast TLB Miss Exception Vector" to the tightly coupled memory. You may use default MMU setting.

tcm4.png

Board layer

The kernel and uClinux-dist support boards definition.

1add a new board to kernel using neek as a template

linux-2.6uClinux-dist两个目录下,分支均为默认。

linux-2.6分支为nios2mmu

cd nios2-linux/linux-2.6

git checkout nios2mmu

uClinux-dist分支为trunk

cd nios2-linux/uClinux-dist

git checkout trunk

编译工具链(移植带mmulinux系统必须编译安装完整的工具链)

lulin@lulinVMware:/home/niosPrj/nios2-linux$ cd toolchain-build

lulin@lulinVMware:/home/niosPrj/nios2-linux/ toolchain-build $git clean –f –x –d

lulin@lulinVMware:/home/niosPrj/nios2-linux/ toolchain-build $ make gcc elf2flt gdb-host

编译时可能会出错,但只要生成了nios2-linux-gnu-gcc等核心程序就可以了。再修改PATH环境变量。

复制板设置

cd nios2-linux/linux-2.6/arch/nios2/boards/

cp -a 3c120 my_nios2

Edit Kconfig in boards dir to include your board.

menu “NiosII board configuration”

choice

prompt “board configuration”

config 3C120

bool “3C120 dev board”

help

The Altera 3C120 dev board support.

config NEEK

bool “Nios Embedded Evaluation Kit”

help

The Altera Nios Embedded Evaluation Kit support.

config MY_NIOS2

bool “My Nios2 Custom Board”

help

My Nios2 Cusotm Board support.

endchoice

source “arch/nios2/boards/3c120/Kconfig”

source “arch/nios2/boards/neek/Kconfig”

source “arch/nios2/boards/my_nios2/Kconfig”



endmenu

Edit Makefile in boards dir to include your board.

board-$(CONFIG_3C120) := 3c120

board-$(CONFIG_NEEK) := neek

board-$(CONFIG_MY_NIOS2) := my_nios2

BOARD := $(board-y)

export BOARD



ifneq ($(board-y),)

core-y += arch/$(ARCH)/boards/$(BOARD)/

KBUILD_AFLAGS += -Iarch/$(ARCH)/boards/$(BOARD)/include

KBUILD_CPPFLAGS += -Iarch/$(ARCH)/boards/$(BOARD)/include

KBUILD_CFLAGS += -Iarch/$(ARCH)/boards/$(BOARD)/include

endif





Edit Kconfig in boards/my_nios2 dir.

if MY_NIOS2

choice

prompt “FPGA configuration”

config MY_NIOS2_FPGA

bool “MY_NIOS2_FPGA”

help

Adapt the kernel to custom FPGA configuration. You will

need to generate a header file for your desgin using the

sopc-create-header-files” scripts provided by Altera.

The file “include/asm-nios2/my_nios2_fpga.h” will be used.

endchoice

endif

生成内核头文件

The new kernel doesn't use hwselect script, it uses sopc generated header instead.

Run this in your quartus project dir (with quartus 8.1 or later),





sopc-create-header-files --single my_nios2_fpga.h

sopc-create-header-files: Using SOPC design file ./DE3_SOPC.sopcinfo found in . swinfo2header: Creating macro file ‘my_nios2_fpga.h’ for module ‘cpu’

sopc-create-header-filesquartus/sopc_builder/bin/

my_nios2_fpga.h复制到linux系统nios2nios2-linux/linux-2.6/arch/nios2/boards/my_niso2/include/asm



配置nios2-linux/linux-2.6/arch/nios2/boards/my_niso2/config.c

根据生成的my_nios2_fpga.h配置相应的结构,在我的实验中修改:

#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)

static struct mtd_partition nios2_partitions[]

//This following is added by lulin.

#if defined(CONFIG_USB_ISP1760_HCD) || defined(CONFIG_USB_ISP1760_HCD_MODULE)



#ifdef CONFIG_GENERIC_GPIO



struct altera_pio_port altera_pio_ports[] = {

{PIO_LED_BASE},

{PIO_BUTTON_BASE} //my_nios2_fpga.h对应

};

还要删除其中一些板上没有的项,主要是flashtse相关项。

否则make编译时会出错,根据出错的地方直接删除即可,可以参考文件夹中的config.c文件。



修改nios2-linux/linux-2.6/arch/nios2/boards/my_niso2/include/asm/nios.h

#ifndef _ASM_NIOS2_H__

#define _ASM_NIOS2_H__



#if defined(CONFIG_MY_NIOS2_FPGA)

#include



/* Added compability mode with macro names from "old" design...

* FIXME: we should really fix drivers instead. but this makes it

* easier to switch between old and new design...

*/

/*#define CONFIG_ALTERA_CYCLONE_III*/

#define DDR2_TOP_BASE ALTMEMDDR_BASE

#define DDR2_TOP_SPAN ALTMEMDDR_SPAN

#define TIMER_1MS_FREQ TIMER_FREQ

#define TIMER_1MS_BASE TIMER_BASE

#define TIMER_1MS_SPAN TIMER_SPAN

#define TIMER_1MS_IRQ TIMER_IRQ //my_nios2_fpga.h头文件对应

/* value of GPIO_LED1 is identify the number of LED on the board*/

#define GPIO_LED1 2



#else

#error "No FPGA configuration selected"

#endif

上述修改项与生成的my_nios2_fpga.h头文件对应。

重新配置内核

--- Kernel is linux-2.6.x

--- Libc is None [ ] Default all settings (lose changes) [*] Customize Kernel Settings [ ] Customize Application/Library Settings (NEW) [ ] Update Default Vendor Settings


选择my_nios2配置

make menuconfig

进入kernel config->niosII configure->board configuration

选择my nios2 custom board


root@tlinux-desktop:/home/nios2-linux/uClinux-dist# make

生成内核镜像,将/nios2-linux/uClinux-dist/image中的linux.initramfs.gz复制到C:\altera\91\nios2edsexample中。

下载内核并运行

运行C:\altera\91\nios2eds中的Nios II Command Shell.bat下载sof文件:[NiosII EDS]$ nios2-configure-sof DE3_DDR2_time_limited.sof

下载镜像文件到DDR2 SDRAM:

[NiosII EDS]$ nios2-download -g linux.initramfs.gz

下载完成后,打开nios终端:

[NiosII EDS]$ nios2-terminal

nios2-terminal: connected to hardware target using JTAG UART on cable

nios2-terminal: “USB-Blaster [USB-0]”, device 1, instance 0

nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)



Linux version 2.6.34-00692-g5bc7853-dirty (root@tlinux-desktop) (gcc version 4.1

.2) #47 Fri Sep 3 09:04:35 CST 2010

bootconsole [early0] enabled

early_console initialized at 0xe8000068





Linux/Nios II-MMU

init_bootmem_node(?,0x4c6, 0x0, 0x8000)

free_bootmem(0x4c6000, 0x7b3a000)

reserve_bootmem(0x4c6000, 0x1000)

Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512

Kernel command line:

PID hash table entries: 512 (order: -1, 2048 bytes)

Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)

Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)

We have 32768 pages of RAM

Memory available: 125048k/4884k RAM, 0k/0k ROM (1684k kernel code, 3199k data)

Hierarchical RCU implementation.

NR_IRQS:32

Calibrating delay loop... 65.74 BogoMIPS (lpj=328704)

Mount-cache hash table entries: 512

NET: Registered protocol family 16

init_BSP(): registering device resources

bio: create slab at 0

SCSI subsystem initialized

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

Switching to clocksource timer

JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.

msgmni has been set to 244

Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)

io scheduler noop registered

io scheduler deadline registered

io scheduler cfq registered (default)

ttyJ0 at MMIO 0x8000068 (irq = 3) is a Altera JTAG UART

console [ttyJ0] enabled, bootconsole disabled

console [ttyJ0] enabled, bootconsole disabled

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

Freeing unused kernel memory: 2716k freed (0xc01a6000 - 0xc044c000)

ifconfig: socket: Address family not supported by protocol

Welcome to

____ _ _

/ __| ||_|

_ _| | | | _ ____ _ _ _ _

| | | | | | || | _ \| | | |\ \/ /

| |_| | |__| || | | | | |_| |/ \

| ___\____|_||_|_| |_|\____|\_/\_/

| |

|_|



For further information check:





BusyBox v1.16.2 (2010-08-26 19:16:26 CST) hush - the humble shell

Enter ‘help’ for a list of built-in commands.

root:/>

阅读(3822) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

李世荣2013-11-28 22:37:44

楼主 请问你有关于DE3的资料吗?