在 DE2 平台上构建 uCLinux 开发环境
概述
本文档介绍了如何在 Altera DE2 开发板上构建 NIOS II 软核 + uClinux 的完整开发环境。
背景
NIOS II 是 Altera 公司在 FPGA 器件上的 32 位软核 CPU。虽然 NIOS II IDE 集成了 uC/OS-II 和 LWIP,但:
- 只适合中小规模系统
- 对显示、文件系统支持不足
- 大量开源资源基于 Linux 平台
因此,在 NIOS II 上构建 uClinux 是更好的选择。
一、交叉编译环境建立
1. 主机环境
推荐使用远程 Linux 主机(如 Ubuntu),避免使用 Quartus 自带的 Cygwin(编译速度极慢)。
2. 安装必要软件
sudo apt-get install build-essential3. 获取交叉编译工具链
下载地址:http://nioswiki.jot.com/WikiHome/OperatingSystems/µClinux/BinaryToolchain/nios2gcc.tar.bz2
# 解压到 /opt/nios2
sudo tar jxf nios2gcc.tar.bz2 -C /
# 添加到 PATH
export PATH=$PATH:/opt/nios2/bin
# 验证
nios2-linux-uclibc-gcc -v4. 持久化 PATH 配置
在 ~/.bashrc 中添加:
export PATH=$PATH:/opt/nios2/bin二、在 DE2 上建立 NIOS II SOPC 环境
1. 使用参考设计
- 打开光盘中的
DE2_70_demonstrations/DE2_70_NET - 运行 SOPC Builder
- 进行必要的硬件调整
- 点击 Generate 重新生成
2. 编译和下载
# 在 Quartus 中编译整个工程
# 使用 AS(Active Serial)模式烧写 Flash生成的系统描述文件(如 sys.ptf)将在后续编译 uClinux 时使用。
3. 内存要求
- uClinux 系统至少需要 8MB 内存
- 内核需要不到 2MB FLASH 空间
三、建立、配置和编译 uClinux 内核
1. 下载源码和补丁
- uClinux-dist-20070130.tar.gz
- uClinux-dist-20070130-nios2-02.diff.gz
下载地址:
2. 解压并打补丁
cd /home/nios2/
tar jxf uClinux-dist-20070130.tar.bz2
cd uClinux-dist
zcat ../uClinux-dist-20070130-nios2-02.diff.gz | patch -p03. 配置内核
make menuconfig关键配置选项:
Vendor/Product Selection --->
Select the Vendor you wish to target (Altera)
Select the Product you wish to target (nios2nommu)
Kernel/Library/Defaults Selection --->
(linux-2.6.x) Kernel Version
(None) Libc Version
[*] Customize Kernel Settings
[*] Customize Vendor/User Settings
4. 根据硬件配置
make vendor_hwselect SYSPTF="/home/nios2/sys.ptf"5. 最小化配置示例
General setup ===>
standard kernel features (for small systems)
[*] Enable support for printk
[*] BUG() support
Processor type and features ===>
CPU (NIOS2)
[*] NIOS2
[*] Enable mul instruction (0x0500000)
Executable file formats ===>
[*] Kernel support for flat binaries
Platform (Altera Cyclone Development board support) ===>
[*] Altera Cyclone Development board support
Input device support ===>/Hardware I/O ports ===>/Serial I/O support
Character devices ===>
[*] Altera JTAG UART support (for the nios2-terminal)
OR
[*] Nios serial support
[*] Support for console on Nios UART
File systems ===>
Pseudo filesystems ===>
[*] /proc file system support
[*] sysfs file system support
Network Device support ===>
[*] Networking Support
[*] TCP/IP networking
[*] IP: kernel level autoconfiguration
[*] IP: DHCP support
Ethernet (10 or 100MBit) ===>
[*] Davicom DM9000 10_100 Ethernet chip support
6. 编译
make
make romfs
make linux image编译成功后,在 images/ 目录下生成 zImage。
四、系统下载和运行
1. 下载系统
nios2-download -g zImage2. 启动系统
nios2-terminal成功启动后会显示 Linux 启动信息。
五、Cygwin 下编译说明(不推荐)
如必须在 Cygwin 下编译:
- 下载并编译 ncurses-5.5
- 删除之前 Linux 下生成的 lxdialog 文件
- 编译速度极慢,且不推荐
六、参考资料
- http://nioswiki.jot.com/WikiHome/OperatingSystems/UClinuxDist
- http://famschmid.net/uclinuxtutorial_nios_archive.html