Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21088 Discussions

buildroot to build toolchain on Linux

Altera_Forum
Honored Contributor II
11,910 Views

TO_BE_DONE

0 Kudos
107 Replies
Altera_Forum
Honored Contributor II
3,226 Views

This guide worked for me. Thanks hippo! initramfs cuts down on my flash memory requirements a lot. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

To others planning to use the above guide, here are some things I ran into: 

 

- Before starting, make sure you have bison, flex, and dos2unix. Bison and flex are probably available as packages for your Linux distribution. dos2unix is a common tool, but amazingly I didn&#39;t have it and my Linux distribution didn&#39;t have a package for it! If it&#39;s the same with you, then the simplest thing to do is to use the two-line perl script for dos2unix that they give here: http://soft.zoneo.net/linux/dos_to_unix.php (http://soft.zoneo.net/linux/dos_to_unix.php). Name the script "dos2unix" (without any extension), make it executable, and put it in your path. (Note: don&#39;t get the fancy dos2unix that converts between DOS, UNIX, and Mac in any direction. It&#39;ll break the build.) 

 

- The build process for elf2flt tries to use a static libc library, which you might not have. If the build for it fails with an error like "ld: cannot find -lc", then that&#39;s probably your problem. However, you can just change the elf2flt build process to use shared libraries. After the build fails due to the error, edit buildroot/toolchain_build_nios2/elf2flt/Makefile and remove the "-static" flag in LDFLAGS. Then run "make" and "make install" in the elf2flt directory to finish it, and then continue the rest of the build process by running "make" in the buildroot directory. 

 

- The build process automatically downloads additional source code from predetermined locations on the web. However, I found that some of the sites it tries to access don&#39;t exist anymore (or at least they were down when I was doing this). If a program called "wget" keeps trying to download from some URL, that&#39;s probably what&#39;s wrong. To fix this, google for the last part of the URL that it&#39;s trying to access (e.g. "gcc-3.4.3.tar.gz"). You should find a working link to that file somewhere on the first page of results. Use your browser&#39;s "Copy Link Location" feature to get the URL of the file. Next, grep the buildroot tree for the URL that wget is using (e.g. grep -R "mirrors\.rcn\.net" ~/buildroot). One of the results should be a line like GCC_SITE=http://mirrors.rcn.net/.../gcc-3.4.3.tar.gz in some makefile or something. Edit that file and change that line to use the URL that you found instead. Then resume the build process by running "make" in the buildroot directory. The wget step should then work. 

 

- If you configured your kernel to not support loadable modules, or if you just don&#39;t need any on your system, then you can skip the two steps labeled "copy module files to rootfs and generate modules.dep" and "rebuild image for initramfs". 

 

As a note, I built buildroot using gcc version 3.4.5.
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

removed. goto post#11 for kernel 2.6.15.2

0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

merged to post# 1 step2.

0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hi hippo! 

 

I created a patch for the 2.6.11 kernel to include support for a timer called watchdog configured as a watchdog in SOPC-builder. I think it&#39;s not specific to 2.6.11 so you could include this in the patch-set if you like. 

The more drivers standard available (or in one patch) the more attractive the Nios2 platform gets! 

Respect for the work you&#39;ve done so far! 

 

Walter Goossens
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

It is easy to compile a simple program, as pointed out by leonqin and tschmelcher. 

nios2-linux-uclibc-gcc hello.c -o hello -elf2flt 

The copy hello to ~/rootfs/bin, and rebuild kernel image for initramfs.
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

You can use "free" to find out the memory usage. 

You can try the following to reduce the memory usage. 

 

1. The default busybox use more options than you will need. 

You can reduce the commands or features supported by busybox, only keep those you will use. 

cd ~/buildroot/build_nios2/busybox 

make menuconfig 

make 

cd ~/buildroot 

make 

 

2. reduce the kernel, reduce unused driver and file system. 

cd ~/linux-2.6.x 

make ...... menuconfig 

make 

 

3. remove unused files and nodes in rootfs/etc and rootfs/dev 

in file ~/buildroot/target/generic/device_table.txt 

in dir ~/buildroot/target/generic/target_skeleton 

 

4. you can delete files at run time when they are no longer in use.
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

hi hippo: 

 

I have compiled the kernel successed ,then got the vmlinux in /linux-2.6.15.1. 

 

But when I exec "made ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- INSTALL_MOD_PATH=/home/alex/rootfs modules_install".I meet a erro. 

 

[root@localhost linux-2.6.15.1]# make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- INSTALL_MOD_PATH=/home/alex/rootfs modules_install 

no emulation specific options. 

 

The present kernel configuration has modules disabled. 

Type &#39;make config&#39; and enable loadable module support. 

Then build a kernel with module support enabled. 

 

So I ececed "make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- menuconfig" 

In "modules support" , I seleced "enable modules...." 

After save, I execed "make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc-" 

 

but make failed. I got following erro information: 

arch/nios2nommu/kernel/setup.c:101:33: warning: "CONFIG_SMC91111" is not definedarch/nios2nommu/kernel/setup.c:101:54: warning: "CONFIG_OPEN_ETH" is not definedarch/nios2nommu/kernel/setup.c:101:75: warning: "CONFIG_MTIP1000_ETH" is not defined 

arch/nios2nommu/kernel/setup.c:101:100: warning: "CONFIG_DM9000_ETH" is not defined 

arch/nios2nommu/kernel/setup.c:200:33: warning: "CONFIG_SMC91111" is not definedarch/nios2nommu/kernel/setup.c:200:54: warning: "CONFIG_OPEN_ETH" is not definedarch/nios2nommu/kernel/setup.c:200:75: warning: "CONFIG_MTIP1000_ETH" is not defined 

arch/nios2nommu/kernel/setup.c:200:100: warning: "CONFIG_DM9000_ETH" is not defined 

kernel/intermodule.c:178: warning: `inter_module_register&#39; is deprecated (declared at kernel/intermodule.c:38) 

kernel/intermodule.c:179: warning: `inter_module_unregister&#39; is deprecated (declared at kernel/intermodule.c:78) 

kernel/intermodule.c:181: warning: `inter_module_put&#39; is deprecated (declared at kernel/intermodule.c:159) 

CC kernel/extable.o 

CC kernel/params.o 

CC kernel/posix-timers.o 

CC kernel/kthread.o 

CC kernel/wait.o 

CC kernel/kfifo.o 

CC kernel/posix-cpu-timers.o 

CC kernel/futex.o 

CC kernel/uid16.o 

CC kernel/module.o 

kernel/module.c: In function `load_module&#39;: 

kernel/module.c:1534: error: `EM_ALTERA_NIOS2&#39; undeclared (first use in this function) 

kernel/module.c:1534: error: (Each undeclared identifier is reported only once 

kernel/module.c:1534: error: for each function it appears in.) 

make[1]: *** [kernel/module.o] &#38169;&#35823; 1 

make: *** [kernel] &#38169;&#35823; 2 

[root@localhost linux-2.6.15.1]# 

 

How can I solve the question? 

Do I must copy modules fills from MX_1.4 source code to ~/rootfs? 

 

Thank you very much! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

The current config for 2.6.15.1 has no module enabled. So you should skip this step. 

And the vmlinux is ready for download and test.
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

I don&#39;t understand how to update the kernel Makefile for modules install 

--- Makefile    2006/01/26 06:13:18    1.1 +++ Makefile    2006/01/26 06:14:23 @@ -894,7 +894,7 @@ ifeq "$(strip $(INSTALL_MOD_PATH))" "" depmod_opts    := else -depmod_opts    := -b $(INSTALL_MOD_PATH)/lib/modules -r +depmod_opts    := -b $(INSTALL_MOD_PATH) -r endif .PHONY: _modinst_post _modinst_post: _modinst_[/b] 

--- Quote End ---  

 

 

That&#39;s a format of diff/patch command. 

 

You can use editor, open Makefile, go to line 897, 

it was,  

depmod_opts := -b $(INSTALL_MOD_PATH)/lib/modules -r 

change it to 

depmod_opts := -b $(INSTALL_MOD_PATH) -r 

 

Do you remember, we have several "patch" commands in the post? 

A patch file is generated with the "diff" command. When we change some files, we can find the differences from what they were before we change. Send only the change to others, and he can update the files with "patch" command. 

 

So if you save the "diff" to a file, Makefile.diff 

you can update without using editor, with the command 

cd ~/linux-2.6.x patch -p0 <Makefile.diff 

 

The parameter "-p0" mean cut zero dir level from file header, ie, the files in diff are in the same directory. Sometime, we use "-p1", we cut one level dir level from file header. eg, "linux-2.6.x/Makefile" with "-p1" will be the same as "Makefile" with "-p0" .
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

UPDATE : merged to post#1 

 

Here come the latest Linux kernel 2.6.15.3 on Nios2. 

I did include most of the drivers in the mx1.4 release. But I did not build and test them, because I did not have any dev boards to test out. Only serial console is tested.
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hey hippo, I&#39;m back (again)! Great thread you started. I have some little snippets of useful info that I would like to add regarding uClinux (common tasks), and I will start posting these on the forum soon. Also, if you need some help putting out these driver sets, I can test out builds for you since I have a whole army of dev boards available http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

I&#39;m not sure if this would be helpful or not (maybe I could get some feedback), but I use SVN for all my internal development. Since I&#39;m constantly rebuilding new toolchains, I could open up my SVN repository that basically combines all this information into one place so users don&#39;t have to keep repatching and checking for version nums etc.. 

 

J
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Jdhar, 

Happy that you&#39;re back. It would be very helpful to test the drivers out with the new kernel. Try it if you have some spare time.  

Those who want to write their own drivers should work on the new kernel. There are still a lot of codes to clean up. Those are problems in the Microtronix&#39;s port. I&#39;m trying to resolve them by cross-checking with other arch, eg sh/h8300/mips.  

I use subversion too. It is very helpful, when I moved from 2.6.11 up, 2.6.12..., step-by-step. Those attached kernel patches were genereated with "svn diff". 

I hope Altera can help to setup the svn/git for the tools/kernel, but putting them on to the upsteams is even better. 

 

Hippo
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hey Hippo, 

why i don&#39;t find bin folder in ~/buildroot/build_nios2/staging_dir? Whether i need use the same as your fedora environment and install compat-gcc or not.  

 

Thanks a lot. 

Sam 

 

mkdir -p /home/samchou/buildroot/toolchain_build_nios2 

bzcat /home/samchou/buildroot/dl/uClibc-20060116.tar.bz2 | tar -C /home/samchou/ buildroot/toolchain_build_nios2 -xf - 

toolchain/patch-kernel.sh /home/samchou/buildroot/toolchain_build_nios2/uClibc toolchain/uClibc/ \*.patch 

touch /home/samchou/buildroot/toolchain_build_nios2/uClibc/.unpacked 

cp toolchain/uClibc/uClibc.config /home/samchou/buildroot/toolchain_build_nios2/uClibc/.config 

/home/samchou/buildroot/toolchain_build_nios2/bin/sed -i -e &#39;s,^CROSS_COMPILER_PREFIX=.*,CROSS_COMPILER_PREFIX="/home/samchou/buildroot/build_nios2/staging_dir/bin/nios2-linux-uclibc-",g&#39;  

-e &#39;s,# TARGET_nios2 is not set,TARGET_nios2=y,g&#39;  

-e &#39;s,^TARGET_ARCH="none",TARGET_ARCH=\"nios2\",g&#39;  

-e &#39;s,^KERNEL_SOURCE=.*,KERNEL_SOURCE=\"/home/samchou/buildroot/toolchain_build_nios2/linux\",g&#39;  

-e &#39;s,^RUNTIME_PREFIX=.*,RUNTIME_PREFIX=\"/\",g&#39;  

-e &#39;s,^DEVEL_PREFIX=.*,DEVEL_PREFIX=\"/usr/\",g&#39;  

-e &#39;s,^SHARED_LIB_LOADER_PREFIX=.*,SHARED_LIB_LOADER_PREFIX=\"/lib\",g&#39;  

/home/samchou/buildroot/toolchain_build_nios2/uClibc/.config 

/home/samchou/buildroot/toolchain_build_nios2/bin/sed -i -e &#39;s,^.*UCLIBC_HAS_LFS.*,UCLIBC_HAS_LFS=y,g&#39; /home/samchou/buildroot/toolchain_build_nios2/uClibc/.config 

/home/samchou/buildroot/toolchain_build_nios2/bin/sed -i -e &#39;s,.*UCLIBC_HAS_WCHAR.*,UCLIBC_HAS_WCHAR=y,g&#39; /home/samchou/buildroot/toolchain_build_nios2/uClibc/.config 

/home/samchou/buildroot/toolchain_build_nios2/bin/sed -i -e &#39;s,# UCLIBC_HAS_THREADS is not set,UCLIBC_HAS_THREADS=y,g&#39; /home/samchou/buildroot/toolchain_build_nios2/uClibc/.config 

/home/samchou/buildroot/toolchain_build_nios2/bin/sed -i -e &#39;s,# PTHREADS_DEBUG_SUPPORT is not set,PTHREADS_DEBUG_SUPPORT=y,g&#39; /home/samchou/buildroot/toolchain_build_nios2/uClibc/.config 

/home/samchou/buildroot/toolchain_build_nios2/bin/sed -i -e &#39;s,# LINUXTHREADS_OLD is not set,LINUXTHREADS_OLD=y,g&#39; /home/samchou/buildroot/toolchain_build_nios2/uClibc/.config 

mkdir -p /home/samchou/buildroot/toolchain_build_nios2/uClibc_dev/usr/include 

mkdir -p /home/samchou/buildroot/toolchain_build_nios2/uClibc_dev/usr/lib 

mkdir -p /home/samchou/buildroot/toolchain_build_nios2/uClibc_dev/lib 

make -C /home/samchou/buildroot/toolchain_build_nios2/uClibc  

PREFIX=/home/samchou/buildroot/toolchain_build_nios2/uClibc_dev/  

DEVEL_PREFIX=/usr/  

RUNTIME_PREFIX=/home/samchou/buildroot/toolchain_build_nios2/uClibc_dev/  

HOSTCC="gcc"  

pregen install_dev; 

make[1]: /home/samchou/buildroot/build_nios2/staging_dir/bin/nios2-linux-uclibc-gcc: Command not found 

make[1]: Entering directory `/home/samchou/buildroot/toolchain_build_nios2/uClibc&#39; 

make[1]: /home/samchou/buildroot/build_nios2/staging_dir/bin/nios2-linux-uclibc-gcc: Command not found 

&#65533;&#65533;&#65533;&#65533;*make -C extra/config conf 

make[2]: /home/samchou/buildroot/build_nios2/staging_dir/bin/nios2-linux-uclibc-gcc: Command not found 

make[2]: Entering directory `/home/samchou/buildroot/toolchain_build_nios2/uClibc/extra/config&#39; 

make[2]: /home/samchou/buildroot/build_nios2/staging_dir/bin/nios2-linux-uclibc-gcc: Command not found 

&#65533;&#65533;&#65533;&#65533;*make[2]: *** No rule to make target `|&#39;, needed by `../../extra/config/conf.o&#39;. Stop. 

make[2]: Leaving directory `/home/samchou/buildroot/toolchain_build_nios2/uClibc/extra/config&#39; 

make[1]: *** [extra/config/conf] Error 2 

make[1]: Leaving directory `/home/samchou/buildroot/toolchain_build_nios2/uClibc&#39; 

make: *** [/home/samchou/buildroot/toolchain_build_nios2/uClibc/.configured] Error 2
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hi all, 

 

thanks Hippo for this post, this is very interesting, however I have 2 questions : 

 

- in the post regarding your port of linux-2.6.15.2, when I try to enable the JTAG uart, I get an error message : 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

  CC      drivers/serial/altera_juart.o 

drivers/serial/altera_juart.c: In function `jtaguart_type&#39;: 

drivers/serial/altera_juart.c:285: error: `PORT_JTAG_UART&#39; undeclared (first use in this function) 

drivers/serial/altera_juart.c:285: error: (Each undeclared identifier is reported only once 

drivers/serial/altera_juart.c:285: error: for each function it appears in.) 

drivers/serial/altera_juart.c: In function `jtaguart_config_port&#39;: 

drivers/serial/altera_juart.c:311: error: `PORT_JTAG_UART&#39; undeclared (first use in this function) 

drivers/serial/altera_juart.c: In function `jtaguart_verify_port&#39;: 

drivers/serial/altera_juart.c:322: error: `PORT_JTAG_UART&#39; undeclared (first use in this function) 

drivers/serial/altera_juart.c: At top level: 

drivers/serial/altera_juart.c:335: warning: initialization from incompatible pointer type 

drivers/serial/altera_juart.c:336: warning: initialization from incompatible pointer type 

make[2]: *** [drivers/serial/altera_juart.o] Error 1 

make[1]: *** [drivers/serial] Error 2 

make: *** [drivers] Error 2[/b] 

--- Quote End ---  

 

 

 

- it seems that I have a problem with the elf2flt : when I try to execute  

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

nios2-linux-uclibc-flthdr build_nios2/busybox-1.1.0/busybox[/b] 

--- Quote End ---  

 

I get an error message : 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

Cannot read header of ../buildroot/build_nios2/busybox-1.1.0/busybox[/b] 

--- Quote End ---  

 

 

and when I run the kernel, I get a bad magic error, which, I think, means that the format of busybox is not flt. 

 

Have you any idea on how to solve this ? 

 

Thanks a lot 

 

Best regards 

 

Pierre-olivier
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hi cetic, 

 

1. missing jtag uart port: add it to include/linux/serial_core.h, download attached kernel2_04.zip 

cd ~/download unzip kernel2_04.zip cd ~/linux-2.6.15.2 patch -p0 <~/download/linux-2.6.15.2-nios2-04.diff 

 

2. missing elf2flt for busybox, download attached busybox_110.zip 

add the elf2flt stuf to busybox Makefile 

cd ~/download unzip busybox_110.zip cd ~/buildroot/build_nios2/busybox-1.1.0 patch -p1 <~/download/busybox-110.diff rm busybox make cd ~/buildroot make 

check again with flthdr. 

then rebuild kernel. 

 

Or you may try post#4, to rebuild toolchain. 

 

Hippo
0 Kudos
Altera_Forum
Honored Contributor II
3,225 Views

Hi hippo, 

 

thanks for the patch for jtag_uart. 

 

The other error is fixed : it can be useful for other : when I first compiled buildroot, I had an error about 2 missing files (ansidecl.h and symcat.h) when compiling elf2flt. To fix this I made a find, and I found them in gcc3 sources, so I made a symlink to them. This is dangerous because it worked with no error, but apparently it was not the right files... I installed binutils-dev (the debian package, which contains those files), and it works correctly now. 

 

Thanks again 

 

Pierre-olivier
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hi Sam, 

 

Which linux distribution do you use? what is your gcc version, try "gcc -v" to find out. 

I have updated with a new build shell script. Please check the update, and let me know if you have any problems. 

 

Hippo
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hi hippo, 

My environment is gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-53). I try your new build shell script but still encounter the same problem which don&#39;t include bin folder in ~/buildroot/build_nios2/staging_dir. Do i need to change my environment or need to modify something? 

 

Thanks a lot.
0 Kudos
Altera_Forum
Honored Contributor II
3,226 Views

Hi Sam, 

 

Your Linux env may be too old. Please try install a fedora core 4. 

Please select "development" pakages when you install the Linux. 

And include compat gcc. 

 

Hippo
0 Kudos
Altera_Forum
Honored Contributor II
3,107 Views

Hi nvs, 

 

The .config is not related to ptf. The ptf is used to create a header file for hardware address. 

When you run,make ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- hwselect SYSPTF=your_system.ptf 

it will ask you some questions, like these. And you should make selections. 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

  no emulation specific options. 

  RUNNING hwselect 

 

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

 

(1) cpu_0 - Class: altera_nios2 Type: f Version: 5.1 

 

Selection: 1 

 

--- Please select a device to upload the kernel to: 

 

(1) cfi_flash_0 

        Class: altera_avalon_cfi_flash 

        Size: 8388608 bytes 

 

Selection: 1 

 

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

 

(1) ddr_sdram_0 

        Class: ddr_sdram_component 

        Size: 67108864 bytes 

 

(2) onchip_memory_0 

        Class: altera_avalon_onchip_memory2 

        Size: 8192 bytes 

 

Selection: 1 

 

--- Summary using 

 

PTF: /home/jack/prog/v1.ptf 

CPU:                            cpu_0 

Device to upload to:            cfi_flash_0 

Program memory to execute from: ddr_sdram_0 

 

--- Settings written to /home/jack/linux-2.6.15.3/arch/nios2nommu/hardware.mk[/b] 

--- Quote End ---  

 

 

You will always need a cfi memory for the hwselect perl script, even when you use EPCS. Just add a dummy cfi flash to a copy of your real ptf and make the hwselect happy. It is for hwselect only. You dont need it for hardware. 

 

That&#39;s what required for hwselect, 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

You should start with a mininal system with only nios2 cpu core,dram,timer,jtag/serial console and a cfi flash, (which can be dummy and removed later). Note, the interrupt vector (ie, execption vector) should be in uClinux program memory.[/b] 

--- Quote End ---  

 

You need a full featured timer.
0 Kudos
Reply