buildroot to build toolchain on Linux
上一篇 / 下一篇 2006-06-25 16:08:27 / 天气: 晴朗 / 心情: 高兴 / 个人分类:Backup
This post is moved to Nios Wiki,
|V)cy3RJXH0I don't recommend the buildroot approach to newbie now.
a%bn0X$Dvmy0Please go to the nios wiki, http://nioswiki.jot.com/WikiHome/Operating...ms/%C2%B5Clinux
'_|(H1]C8r y0try out the prebuilt zImge if you have altera nios dev board,
#VDJ qS0install binary toolchain, and follow the uClinux-dist to build kernel and apps.
3iH)u-cc3S0EDA中国门户网站 geO Rg&p
EDA中国门户网站.B
l'@T_;m
--Please note, this thread is getting too long, please post your question/discussion as a new topic over the uClinux forum. It will be easier to follow.EDA中国门户网站HlW7W x-t(x/v
EDA中国门户网站%iY/q0Z+Dbm5[u0U
This is a guide to nios2 uClinux. We build tools, compile kernel and port applications for nios2 uclinux on a Linux platform.
0fl!V(EO7Mnb6M2J0Why build the tools when you have the IDE on Windows?
w.f4Kf*wdk5B/x'E0The IDE on Windows are not good for kernel/apps development. The IDE's compiler default to newlib, while we would use uClibc in uClinux.EDA中国门户网站M0H%fEmm
The tools run much faster and less trouble on Linux. You will feel IDE moves like turtle after you use Linux.EDA中国门户网站GhX
V s
If you want uClinux, you should work on Linux and learn Linux. You can learn a lot when working on Linux, and the "Linux know-how" is the key to success on nios2 uClinux.EDA中国门户网站#n"N{n1c2K5JI
You can find links to major linux distributions,EDA中国门户网站dv8dB+E&L
http://distrowatch.com/dwres.php?resource=major
%Qp5R rrh0yj _5o0
2d4x)Zd4l0Just add a PC to run Linux. You can use quartusII and nios2 on Windows to design hardware, then build sofware on Linux. You DON'T have to run quartusII on Linux. You can setup a samba server or client on Linux, so that they can share files. Always update your tools to the latest ones, ie, quartusII v6.0, niosII v6.0, ddr 3.4.0 at this moment.EDA中国门户网站k h+N1k.} }&Bj
EDA中国门户网站*NrW5Ig+MF
If you are new to uClinux, it is very helpful to read the FAQ on the www.ucdot.org.EDA中国门户网站U4LZmR!{ FFy
You should start with a mininal system with only nios2 cpu core,sdram,full featured timer,jtag/serial console and a cfi flash, (cfi flash can be dummy and removed later). Note, the interrupt vector (ie, execption vector) should be in uClinux program memory, ie sdram.EDA中国门户网站\7n"C*y1BY^
Note in Linux, irq 0 used to be auto-detected and that is not supported in Nios II, so you should not use irq 0 for your devices. Only timer_0 may use irq 0.EDA中国门户网站gU]GrG/n!\*q
#_7_'L
dN+G*^y0There is no MMU on current nios2, so no virtual memory,no shared objs/libs, no fork, and stack size is fixed.EDA中国门户网站${X
Rdfnvt:Q p7b
The app exec format on uClinux is not ELF, but binary flat format, FLT.
JC7S_|1dD8|:Y0
6ep`/NV0We will use initramfs (which is quite new to uClinux), instead of romfs. The initramfs is compressed. The rootfs (initrd) image can be linked into the kernel, and make the booting easier. You don't need other devices, such as MTD,CF/IDE,NFS for rootfs to start up your nios2 uClinux. As they may be not available for a new custom board. You can mount other devices or filesystem later,eg jffs2, in user space.
/|"ezMoM B0
n`S4Ew&F}8MT
i0Let's start it step by step.
Afaz+_!y w0I0You should use gcc3 to build this cross-compiler. the gcc4 has problem on binutils-2.15.
_f&{~an&AE?0If you use Fedora core 5, you should select development packages during installation, and run "yum update" after installation. (redhat 9 is too old, that make failed)
3r g
}9TR4W,r0There is compat-gcc-32 package.EDA中国门户网站%hO0I_4a(VF&@%{
yum install compat-gcc-32EDA中国门户网站uH \ M,NRO|*T
cd /usr/bin
dZ!z8U!AL0mv gcc gcc4EDA中国门户网站0W"^2Ef],|W&O
ln -s gcc32 gcc
*s/S4q,B4L\4JK0exit
EDA中国门户网站 qD0Us!sLO)M
1U$Vn0M*Fr0If you have a working buildroot toolchain, there is no need to rebuild all each time. You should edit the build script and update only what is needed. During the build, if you fail (or too slow) when downloading (wget) some files, you can use your browser to search and download them from other sites into ~/download dir. Then you can edit the build script, and restart from the middle.
ItTxp0If you have old builds, and you want a fresh build from begin, you must remove all old build dirs. uncomment line1 of the build script, which will remove all old build dirs. EDA中国门户网站MHn7w-[a5z2_
(Please NOTE, the latest buildroot/uClibc/busybox snapshot may still have problems on nios2, so we will download -20060320, the last known good shot, and save them as -snapshot instead in the build script.)EDA中国门户网站:_/L6nXN7ua?+Z
U-SxJ5f1px'HO0During the build, you can cut the command lines in this guide with your brower, and paste in the shell console or save to a script. So that you can save some typing and errors.EDA中国门户网站?jAd pb
EDA中国门户网站"`.s D3I`].r
b
1. login with a user account, eg, jack. do not use root account.EDA中国门户网站fJ f8h"kK:o\
your home dir will be /home/jack, or in short ~/
;H_4Q Ahs2O
\9u0
AdP%R-B)kJ02. download microtronix's port of nios2 linux from the forum into the ~/download dir,EDA中国门户网站q#l t;FLOu`
http://forum.niosforum.com/downloads/1_4/nios2linux-1.4.zipEDA中国门户网站!ZS'bSE-^[!^(C
&D5gx%zK03. download http://hungryhippo.jot.com/WikiHome/build.zip , into dir ~/download
F^;]~C(o%R9H0
unzip build.zip
g&\v(c'jm;^0./build
#n"Q8T&Wct*w0EDA中国门户网站Ei2p"[u\q0l
The build script will download (using wget) the 20060320 snapshot ,untar, patch and make.
&IB:k*maN5y0(The configs are binutils-2.15,gcc-3.4.6,uClibc-0.9.29-pre,busybox-1.1.1-pre0 and kernel header 2.6.11.)EDA中国门户网站w$KPM$K1[8P;Xn(O K
The c++ and libstdc++ will be built, too. (but they still have problems to run)
Qy3^h&t TP+V%Q+K^0The ~/rootfs dir will be created. The kenel will use this dir and ~/download/rootfs_list file to generate initramfs image.EDA中国门户网站4I}$G2i.u_
You may edit the ~/download/rootfs_list file, to add or remove dev nodes.
-d+n3Q0[:M|_o(aV ~0There is a minimal .config file.
'i:ZZOoY0B0The uClinux-dist will be prepared in ~/uClinux-dist.EDA中国门户网站~'j4LT*[*F"]]
The apps ported by microtronix will be in ~/apps .EDA中国门户网站Q s&g/S6jS0lJ
And the 2.6.11-uc0 kernel will be in ~/linux-2.6.x , with zImage, EPCS MTD,avalon watchdog drivers added.
'Vd |Lj,o7gb!eX0
^;p?V)Hk:y04. You should include this PATH to use the cross gcc after it is built
v(V3tLR0
EDA中国门户网站wH
g(a
W:m8U
Or you can update the path of the cross gcc in file ~/.bash_profile
*Jp\O)P_$Y0
*^X!NuE]'i0so that it will be in the PATH when you login Linux.
O$VZvil*qcn0
uN;pQ'w+gXax Z2}0Run this to verify that you have it in your command search path,EDA中国门户网站e+B#f)_.dw:\
4zv:y(h&y,{$Y0EDA中国门户网站Y-NM4y
E
Run this to verify that you have the proper busybox in FLT format,EDA中国门户网站JYG[{ ~$g
EDA中国门户网站5A-K}/b6{9w-i
it should display the FLT header like this,
JbdMS
g.z|;f0
Magic: bFLTEDA中国门户网站X$n \3H(m [6vv
Rev: 4EDA中国门户网站 K6JSCI
Build Date: Mon Mar 27 13:55:05 2006EDA中国门户网站 i(@yL uos'K4P'O
Entry: 0x40
.Cac\tZ0 Data Start: 0x632c8EDA中国门户网站\6Y;G{`Q M&GZ
Data End: 0x7bb80
(q[Zfl0 BSS End: 0x96750EDA中国门户网站^Khhy
Stack Size: 0x3e80
v@"B HW3g'N:|Gi0 Reloc Start: 0x7bb80
Q4?^p!^&E0Mq ]:S0 Reloc Count: 0x344dEDA中国门户网站 xw'p;qT{)n9RH!|
Flags: 0x1 ( Load-to-Ram )
$a#HO`dfMG0EDA中国门户网站.FDP u5MNS
A'[QYi,ct{V05. Then config and compile kernel.EDA中国门户网站{@Ml9K
RPTh
gBgd:CrC2j0# generate nios2_system.h from ptfEDA中国门户网站}i8k6AA%L
make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- hwselect SYSPTF=your_system.ptf
EDA中国门户网站1n5_bxT
If you use Altera CycloneII NIOS dev board with 2C35, the ptf file is altera/kits/nios2/examples/verilog/niosII_cycloneII_2c35/standard/ std_2C35.ptf,EDA中国门户网站"XR4FF~
and the sof is standard.sof . The ptf must match your board.EDA中国门户网站z/lj'p"X5z
Here is the hwselect of std_2C35.ptf,
wAt/fy:N6H0
(1) cpu - Class: altera_nios2 Type: s Version: 5.11EDA中国门户网站3Z9Cy2mzy!\5p
Selection: 1
(Sk6k!Ie5an3pcIv0--- Please select a device to upload the kernel to:
!X!Pho.C.Iv \}-QB0(1) ext_flash
l^ M rl;@9g0 Class: altera_avalon_cfi_flashEDA中国门户网站!j$`Ss"{hDQD
Size: 16777216 bytesEDA中国门户网站PjD0b:U.I
Selection: 1
-Y2~(f%Zzr0--- Please select a device to execute kernel from:
9iiE'Wwg0(1) ext_ssram
z-Nz ~%NHK4Bm0 Class: altera_avalon_cy7c1380_ssramEDA中国门户网站%M S^wmCF
Size: 2097152 bytes
!@ t6oH)]/z Q+{4b @0(2) ddr_sdramEDA中国门户网站jc$r#}Y]
Class: ddr_sdram_componentEDA中国门户网站9UL(iVT8t0qI
Size: 33554432 bytesEDA中国门户网站X;Jyd)I*P.a m| C-s6x
(3) epcs_controller
#MZ? l-BGp ri0 Class: altera_avalon_epcs_flash_controller
UQ@)U MIO#byF0 Size: 2048 bytes
?BC&Wr:}9Kw0Selection: 2
EDA中国门户网站
\j$\K|R0]^YG
make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- menuconfig
EDA中国门户网站#] Wb L.q!|X6A
In menuconfig, you should select your serial or jtag console in menu,EDA中国门户网站Rh9ET1o/C'Tk5Q f"N
|8fkit3P.H0If your user id and group id on Linux are not 500, change these to your id instead,EDA中国门户网站9kU%o4hB%`:l
1p;A3S G N^CM)A)O0OREDA中国门户网站U&?\C `/Fe&u
Device Drivers --> Block devices --> (for 2.6.11-uc0)EDA中国门户网站[+rVL.`
(500) User ID to map to 0 (user root)
*Ic-yNb0 (500) Group ID to map to 0 (group root)
EDA中国门户网站;Mh.[ k|O:M-~3P
If you use DEII with 8M sdram, change the link address of the uncompress loader,
5z8^j&Y{%k)H0
cQQ X6mgZ0Then
0Y^n L"N/EP+L0make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- zImage
EDA中国门户网站f!W
Y,Z'`H#G~
Whenever you update the ~/rootfs, you have to compile the kernel and update the initramfs.
YU_*zf8`JC5g!_0
CPIO usr/initramfs_data.cpioEDA中国门户网站&G#L$t!r*Xd6g
GZIP usr/initramfs_data.cpio.gzEDA中国门户网站J.A^+U(x+il^
AS usr/initramfs_data.oEDA中国门户网站z Y*|^#}takt{b
LD usr/built-in.o
EDA中国门户网站9|CF(mpp]E4\Y
If you didn't see the "CPIO" and "GZIP" in compile message, the initramfs is not updated. You will have to remove the file usr/initramfs_list in kernel dir, and compile again to force the update of initramfs.EDA中国门户网站DcJ9C2^8P
$M Xd5mp0EDA中国门户网站+n8H;r8U&QD*M1\W#mqx
6. Now the compressed kernel image is ready, arch/nios2nommu/boot/zImage .
B(a+U&? @)Zr(?Q0you can run it on windows,
"mP&K"K_d R0First, download the sof of your hardware to your board with quartusII programmer,EDA中国门户网站*r^/s+vXK&H"x({
Then open a nios2 sdk shell,EDA中国门户网站7K$C3ApA2_v
f
EDA中国门户网站I5Z8E4ww9L3w^UU6\/q
Note the drives mapping in nios2 sdk shell,
l @5wE$~0drive c: is /cygdrive/c/
$f#C7XeG&|
QW0if you map your linux home to h: on windows with samba server,EDA中国门户网站9hB(F*U+bT*v'F
then drive h: is /cygdrive/h/EDA中国门户网站C hJ n~ O&K|S
so the image file is
8z(t*r/m%M,LF'bF!qG"~0/cygdrive/h/linux-2.6.x/arch/nios2nommu/boot/zImage
n:u)X3e({r!l0EDA中国门户网站)?(x
G7N\z$M9sA
nios2-download -g zImageEDA中国门户网站xB g7K%zz_,Y
nios2-terminal
E8Mz.^W(e(Z0Here is the boot message on my custom board,EDA中国门户网站Yj!R8f"j{8|
Linux version 2.6.16 (jack@localhost) (gcc version 3.4.6) #1 PREEMPT Wed Mar 22 11:48:33 CST 2006EDA中国门户网站N E5J T#D J
uClinux/Nios II
*bcXX$LhKK z6I0Altera Nios II support © 2004 Microtronix Datacom Ltd.EDA中国门户网站7]4\zK!z5Vq
Built 1 zonelists
/at*xO;A.~7x0Kernel command line:EDA中国门户网站B-etQY
PID hash table entries: 512 (order: 9, 8192 bytes)EDA中国门户网站4k(lmB&W\N:Vv
Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
O9c r vu8TL0Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)EDA中国门户网站Trd|5Y
Memory available: 63616k/65536k RAM, 0k/0k ROM (733k kernel code, 546k data)EDA中国门户网站G3ZX*hfy-x9hX
Mount-cache hash table entries: 512EDA中国门户网站w4O%~ B#A_)cs
io scheduler noop registered
|"U4G%K5l8La#Z0io scheduler deadline registered (default)
Zr-p `-Gv0NIOS serial driver version 0.0EDA中国门户网站F`/QZRN6p
ttyS0 (irq = 1) is a builtin NIOS UART
o&Z.B X[`}e0Freeing unused kernel memory: 468k freed (0xc0000 - 0x134000)
] e`tq-~nh2U0init started: BusyBox v1.1.1-pre0 (2006.03.20-07:53+0000) multi-call binaryEDA中国门户网站-n)_F}8@M
BusyBox v1.1.1-pre0 (2006.03.20-07:53+0000) Built-in shell (msh)
dI3\\0f&\.^0Enter 'help' for a list of built-in commands.
pPJ m2g0#
EDA中国门户网站nW^!}(]Jv
(Note, don't use jtag uart in production, it will not run without a nios2-terminal connection)
)SZA9Mp0P%^!S2h0
vRY#t!VVP_ swv07. After you have tested the uClinux from sdram, you may want to program the flash.
#a J.S0kW m_'O0
)xJ%Cy'@/S0If you use EPCS flash, find out and change the sof path and epcs base below.
Tvwb!q$A0on nios2 sdk shell,EDA中国门户网站A;_%p%u
P
# Creating .flash file for the FPGA configurationEDA中国门户网站3vu:_%F&s D
sof2flash --epcs --input=$SOPC_KIT_NIOS2/examples/verilog/niosII_cycloneII_2c35/standard/standard.sof --output=standard.flash
^~ N.x1xV&s0# Programming flash with the FPGA configurationEDA中国门户网站{ W%e V+{Pl'V
nios2-flash-programmer --epcs --base=0x02200000 standard.flash
#YW~z2l8J2Z@0# Creating .flash file for the projectEDA中国门户网站PGnf A'gc
elf2flash --epcs --after=standard.flash --input=zImage --output=epcs_controller.flash --boot=$SOPC_KIT_NIOS2/components/altera_nios2/boot_loader_epcs.srec
p9wna2L8AkYA1}h0# Programming flash with the project
&|(](l Tx;o4Hz0nios2-flash-programmer --epcs --base=0x02200000 epcs_controller.flash
EDA中国门户网站6G;gF*A4@?n3V
k8_by0G&k