前言:目前的教程主要有两个问题:out of date; no details. 造成困扰很多。这里参考了
sopc.et.ntust.edu.tw
Alterawiki AND alteraforum
http://www.youtube.com/watch?v=RxlyezOf0Rs
uuoc.org/uClinux_nios2_custom_hardware.pdf
我想下一步应当转战:
http://www.rocketboards.org/foswiki/Documentation/NiosIILinuxUserManual
1. 环境
在Linux下,或至少 windows + vmware player,不建议直接使用 Windows(懒得尝试)。
使用 Linux 哪个 Distro 不重要,编译环境能成功即可。本文使用的是 Archlinux。和 Windows 共享等问题本文不涉及。所有操作都是在 Archlinux 下进行。
Quartus II 使用 13.1。硬件采用通用一些的 DE2-115。
2. NIOS II 硬件
必要部分 NIOS II/f ,硬件乘法器(hard multiplier)。本文使用了MMU(只有下载的toolchain-mmu可直接用)。SDRAM,按DE2-115来的。
altpll,c0->100MHz,c1->100MHz, phase delay:-2ns
Interval timer,full featured, 1ms, irq 0
jtag uart, irq, 1 (be told: should not be 0 for linux, very important)
onchip memory,1024 Bytes,Dual-port access
3. Nios2 Linux Tarball
$ mkdir tars$ cd tars
$ wget ftp://ftp.altera.com/outgoing/nios2-linux/20120802/* # git://sopc.et.ntust.edu.tw/git 已经没有uClinux-dist.git了
$ cd ..
$ md5sum --check tars/files.md5sum
$ for i in $(ls tars/nios2-linux-*.tgz); do tar -xzvf $i;done
## For mmu-less nios2 uCLinux, download the precompiled toolchain as well
## wget ftp://ftp.altera.com/outgoing/nios2-linux/nios2gcc-20080203.tar.bz2
## this extracts to nios2-linux/opt
## tar -xvf nios2gcc-20080203.tar.bz2
$ cd nios2-linux
$ ls
$ ./checkout
实际上我这次只用了linux-2.6.tgz, uClinux-dist.tgz, uClibc.tgz, toolschain-mmu.tgz.
sopc使用ptf做hardware selector,已经被替换成了qsys的devicetree。sopc2dts需要更新,这里延误了1 week。
git clone git://sopc.et.ntust.edu.tw/git/tools.git (太慢了!!!以至于没法更新其他内容)
4. Toolchain
考虑下载中包含toolchain-mmu;跳过。
# yum install git-all git-gui make gcc ncurses-devel bison byacc flex gawk gettext ccache zlib-devel gtk2-devel lzo-devel pax-utils libglade2-devel uboot-tools #fedoraalterawiki上说使用gcc 4.1.2, 4.4有错,然后改到linux-2.6的test branch尝试的。这部分若有成功不断补充吧。
需要详细排查问题。
$ cd toolchain-build
$ git clean -f -x -d
$ patch ../gcc3/gcc/c-parse.y # 编译c-parse.c出错
1650c1650
< { $$ = start_struct (RECORD_TYPE, $2);
---
> { $<ttype>$ = start_struct (RECORD_TYPE, $2);
1661c1661
< { $$ = start_struct (UNION_TYPE, $2); }
---
> { $<ttype>$ = start_struct (UNION_TYPE, $2); }
1670c1670
< { $$ = start_enum ($2); }
---
> { $<ttype>$ = start_enum ($2); }
1675c1675
< { $$ = start_enum (NULL_TREE); }
---
> { $<ttype>$ = start_enum (NULL_TREE); }
$ patch # gcc 版本太高的缘故??!!
$ setarch i386 make gcc elf2flt gdb-host
to be continued...
5. Check the correct branches are used
可以跳过吧
$ cd uClinux-dist/
$ git branch
* trunk
$ cd ../toolchain-mmu/
$ git branch
* master
$ cd ../linux-2.6/
$ git branch
* nios2
6. Prepare dts
$ cd nios2-linux/tools/sopc2dts #更新!!我采用的是20140403版本,旧版cpu信息不全,延误
nios2-linux/tools/sopc2dts$ make
$ java -jar path/to/sopc2dts.jar -i path/to/de2_115_spoc.sopcinfo -o path/to/de2_115.dts
新版虽然cpu的信息很全,但altpll component的conduit部分编译出错(应当是uClinux-dist编译不支持),因此简化altpll部分:
altpll: clock@0x0 {修改debug console
compatible = "ALTR,pll-13.1", "ALTR,pll-1.0";
#clock-cells = < 1 >;
}; //end clock@0x0 (altpll)
bootargs = "debug console=ttyJ0,115200";
7. Make uClinux kernel
$ PATH=$PATH:~/nios2-linux/toolchain-mmu/x86-linux2/bin
$ export PATH
$ cd uClinux-dist/
$ make menuconfig
如果 mconf: cannot execute binary file
$ file config/kconfig/mconf
64-bit
#mv mconf mconf.x86-64
如果 cannot find exec.h
$ cp ../linux-2.6/arch/nios2/include/generated/asm/exec.h ../linux-2.6/arch/nios2/include/asm/exec.h
再次
# make menuconfig
直到
uClinux Distribution v4.0 Configuration
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^
@^^@^@^@^@^@^@^@^@^@^ uClinux Distribution Configuration @^@^@^@^@^@^@^@^@^@^
^@ Arrow keys navigate the menu. <Enter> selects submenus --->.
^@ Highlighted letters are hotkeys. Pressing <Y> includes, <N> excludes,
^@ <M> modularizes features. Press <Esc><Esc> to exit, <?> for Help, </>
^@ for Search. Legend: [*] built-in [ ] excluded <M> module < >
^@^@^@^^@^@^@^@@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^
@^^ Vendor/Product Selection ---> ^@
^@^ Kernel/Library/Defaults Selection ---> ^@
^@^ --- ^@
^@^ Load an Alternate Configuration File ^@
^@^ Save an Alternate Configuration File ^@
^@^@ ^@
^@^@ ^@
^@^@ ^@
^@^@ ^@
^@^@ ^@
^@^@^@^^@^@^@^@@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^
@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@@^@^@^
@^@^@^@^@^@^@^@^@^@^@<Select>^@^@< Exit >^@^@< Help >^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^
Vendor/Product Selection --->
@^^ --- Select the Vendor you wish to target ^@
^@^ Vendor (Altera) ---> ^@
^@^ --- Select the Product you wish to target ^@
^@^ Altera Products (nios2) --->
Kernel/Library/Defaults Selection --->
@^^ --- Kernel is linux-2.6.x ^@ ^@^ --- Libc is None ^@ ^@^ [ ] Default all settings (lose changes) ^@ ^@^ [*] Customize Kernel SettingsAlterawiki说第一次一定选Default all settings,我想目的主要是将设定都改回默认值。
接下来的配置,主要有:
Kernel features --->
Timer frequency (1000 HZ) ---> (应当是和timer对应的)
Platform options --->
*** Memory settings ***
(0x08000000) Memory base address
*** Device tree ***
[ ] DTB at physical address
[*] Compile and link device tree into kernel image
(/home/stephen/de2-uclinux/de2_115.dts) Device tree source file
Processor type and features --->
[*] Default bootloader kernel arguments
(debug console=ttyJ0,115200) Default kernel command string
Device Drivers --->
Character devices --->
Serial drivers --->
<*> Altera JTAG UART support
[*] Altera JTAG UART console support
[*] Bypass output when no connection
< > Altera UART support
我的pc没有串口,也懒得用usb-uart!
exit, save
$ make
生成romfs出错,修改: ./vendors/Altera/nios2/Makefile
12c12
< passwd profile rc TZ nsswitch.conf
---
> passwd profile rc TZ nsswitch.conf syslog.conf sc.cfg
那个common路径下,没有syslog.conf sc.cfg文件。
这样,启动uclinux后有一些命令错误。
或者找到对应版本copy进去
$ make # 还可能还有没有记录的问题吧
5分钟后很高兴被通知
Kernel: arch/nios2/boot/zImage is ready
Run
$ /opt/altera/nios2eds/nios2_command_shell.sh
$ jtagconfig
1) USB-Blaster [2-1.5]
020F70DD EP3C120/EP4CE115
$ nios2-configure-sof ./output_files/uclinux.sof
$ nios2-download -g ./nios2-linux/uClinux-dist/image/zImage && nios2-terminal
贴上内容留念:(http://www.alterawiki.com/wiki/UClinuxDist#Next_Steps)
Linux version 3.5.0-rc4-01329-ga227997 (stephen@ARCH) (gcc versiobio: create slab <bio-0> at 0
Switching to clocksource timer
NET: Registered protocol family 2
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
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
msgmni has been set to 239
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 0x10001460 (irq = 1) is a Altera JTAG UART
console [ttyJ0] enabled, bootconsole disabled
console [ttyJ0] enabled, bootconsole disabled
Generic platform RAM MTD, (c) 2004 Simtec Electronics
spi_altera 10001400.spi: master is unqueued, this is deprecated
spi_altera 10001400.spi: base f0001400, irq 2
Fixed MDIO Bus: probed
tun: Universal TUN/TAP device driver, 1.6
tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>
mousedev: PS/2 mouse device common for all mice
TCP: cubic registered
NET: Registered protocol family 17
Freeing unused kernel memory: 4148k freed (0xc8298000 - 0xc86a5000)
ifconfig: SIOCSIFADDR: No such device
ifconfig: SIOCSIFADDR: No such device
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|
Symmetricom Demo
cp: can't stat '/etc/sc.cfg': No such file or directory
insmod: can't insert '/usr/sbin/fpga.ko': No such file or directory
BusyBox v1.18.4 (2014-04-11 14:07:12 CST) multi-call binary.
Usage: mknod [-m MODE] NAME TYPE MAJOR MINOR
sh: can't execute 'rsyslogd': No such file or directory
BusyBox v1.18.4 (2014-04-11 14:07:12 CST) hush - the humble shell
Enter 'help' for a list of built-in commands.
root:/>