- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does anyone know if the Nios II port of uClinux is available as a simple tarball (i.e. tar.gz or .tgz) that can be downloaded to a Linux machine and configured and built using the nios2-elf-gcc cross compiler?
I am actively attempting to rebuild the nios2-gnutools on my Linux box so I can develop the kernel and user applications on it. I will post the results if I am successful. However, if someone has already accomplished this I would be very interested in getting the source.Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just use the source supplied with the Windows "uClinux 2.6 Distribution for Nios II" posted in the forum.
Remove CRs from the source-files by using dos2unix or stripcr.c included at the end of this mail (have also included a script which calls this prog.). Build instructions: Installdir=/usr/local/nios2-gnutools (or whatever you want) Sourcedir contents: binutils gdb gcc make newlib Get rid of Cygwin inserted CRs: ./stripcr.sh In sourcedir do: [1] Binutils mkdir binutils-build cd binutils-build ../binutils/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install [2] GCC export PATH=$PATH:$Installdir mkdir gcc-build cd gcc-build ../gcc/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir --with-newlib --with-headers=../newlib/newlib/libc/include -v make all make install [3] Make mkdir make-build cd make-build ../make/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install [4] Newlib cp newlib/newlib/configure.host.normalc newlib/newlib/configure.host mkdir newlib-build cd newlib-build ../make/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install [5] GDB mkdir gdb-build cd gdb-build ../make/configure --target=nios2-elf --program-prefix=nios2-elf- --prefix=$Installdir --exec_prefix=$Installdir -v make all make install Hope this is helpful Regards Atle ---------------------------------------------- stripcr: ----------------------------------------------# include <stdio.h># include <string.h># include <errno.h> char strip_tmpfile[]="/tmp/stripCR.tmp"; int custom_copy (const char* in, const char* out, int stripCR); int main (argc, argv) int argc; char* argv[]; { int result; while (--argc > 0) { argv++; result = custom_copy (argv[0], strip_tmpfile, 1); if (result==1) { if (custom_copy (strip_tmpfile, argv[0], 0)) exit(-1); printf(" Stripping CR from file %s\n", argv[0]); }else { if (result!=0) exit(-1); } } return 0; } /* return value: 0: no strip, 1: file stripped, otherwise error */ int custom_copy (const char* in, const char* out, int stripCR) { FILE *ifp; /* input file pointer */ FILE *ofp; /* output file pointer */ char ch; int result=0; ifp = fopen (in, "rb"); ofp = fopen (out, "wb"); if (ifp == NULL) { printf ("Could not open %s for reading\n", in); return 0; } if (ofp == NULL) { printf ("Could not open %s for writing.\n", out); return -1; } while (!feof (ifp)) { if(fread ((void*) &ch, 1, 1, ifp)) { if (stripCR && (ch == (char) 0x0D)) { result=1; continue; } fwrite((void*) &ch, 1, 1, ofp); } } fclose (ifp); fclose (ofp); return result; } ------------------------------------------------------- stripcr.sh: -------------------------------------------------------# !/bin/bash# Strips CRs from all Makefiles and sourcefiles # stripcr binary STRIPCR=$PWD"/stripcr/stripcr" SRCDIR=$PWD"/src/" echo $PWD # Makefiles find $SRCDIR \( -name 'Makefile' -o -name 'Makefile.in' \) -exec $STRIPCR {} \; # Source files find $SRCDIR \( -name '*.c' -o -name '*.h' -o -name '*.S' \) -exec $STRIPCR {} \; # Linker scripts find $SRCDIR \( -name '*.ld' \) -exec $STRIPCR {} \; # Awk, sed and perl scripts find $SRCDIR \( -name '*.awk' -o -name '*.sed' -o -name '*.pl' \) -exec $STRIPCR {} \; # Config find $SRCDIR \( -name 'config.in' -o -name 'configure.in' -o -name 'configure' \) -exec $STRIPCR {} \; # Other find $SRCDIR \( -name '*.md' \) -exec $STRIPCR {} \;- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ooops. Sorry.. the tools are of course included with the Altera Nios kit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am having some level of success following your instructions.
Your stripcr program and script has been very helpful. I did find that I had to change it so that instead of Makefile.in it looks in any Makefile.* and instead of config.in, it looks at any config.*. I also found that throughout the build I would have to run the script again to strip newly generated files of their carriage returns. Currently I am hung up on the newlib configuration/compile. It is having problems with the following directory of the install: nios2-gnutools/src/newlib-build/nios2-elf/mno-hw-mul/newlib/libc/sys/. The Makefile contains no definition for "sys_dir". Apparently this is where the specific system is called out. In looking at the nios2-gnutools/src/newlib/newlib/libc/sys directory, there are several systems listed. None of them are related to nios, but there is one for linux. I have tried to get the Makefile to use this directory, but it still has issues. Were you able to get your newlib/ items to build properly without any tweaking? If so, was your "sys_dir" variable defined? It was not defined in my setup. Thanks again for your help.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have just tried to build the tools, and have not experienced any problems (newlib builds just fine). The only thing I've done different from the HOWTO I posted was to build only C and C++ for gcc by using: --enable-languages=c,c++. As you say you have to run stripcr() on autogenerated files, maybe that CRs is your problem. Here is an updated version of the stripcr.sh script:
# !/bin/bash# Strips CRs (Cygwin ......) from all Makefiles and sourcefiles # stripcr binary STRIPCR="/usr/local/bin/stripcr" SRCDIR=$PWD echo "Stripping CR in "$SRCDIR # Config find $SRCDIR \( -name 'config.*' -o -name 'configure.*' -o -name 'configure' \) -exec $STRIPCR {} \; # Scripts + templates find $SRCDIR \( -name '*.sc' -o -name '*.sh' \) -exec $STRIPCR {} \; # Makefiles find $SRCDIR \( -name 'Makefile' -o -name 'Makefile.*' \) -exec $STRIPCR {} \; # Source files find $SRCDIR \( -name '*.c' -o -name '*.h' -o -name '*.S' -o -name '*.s' \) -exec $STRIPCR {} \; # Linker scripts find $SRCDIR \( -name '*.ld' \) -exec $STRIPCR {} \; # Awk, sed and perl scripts find $SRCDIR \( -name '*.awk' -o -name '*.sed' -o -name '*.pl' \) -exec $STRIPCR {} \; # Other find $SRCDIR \( -name '*.md' \) -exec $STRIPCR {} \;- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks again for your help. I will untar a pristine tarball and try the process over.
I have assumed that for the newlib portion in step 4, you meant to have "../newlib/configure" instead of "../make/configure". Is this correct, or is this why I'm having problems?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Correct, it was just a little typo. And in step 5 it should be ../gdb/configure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Success!
Thank you very much for your help. I followed your lead and used the c,c++ compiler options for newlib. I don't know if this fixed the problem. I tend to think that all along it was just more carriage returns getting in the way. Your new script worked great. I now have the tools all built on my Linux box. The next issue I'm facing is getting compiled programs to run on my nios2 development board. A couple of the programs are: "cpuload" and "uart_send". I've created a few small programs, but when I try to run them on the target I get the following errors: -------------------------------------# ./cpuload & BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) 27# ^ELF@@@^: not found # ./uart_send & BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) BINFMT_FLAT: bad magic/rev (0x10101ff, need 0x4) 29# ^ELF@@@^: not found ------------------------------------ I couldn't copy some of the symbols verbatim. The ^ is actually a triange and the @ is actually a smiley face. Anyway, they are just binary. I am going to try again but this time compile them statically so I'll know if it is a compiler or a library problem.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
After compiling them statically, I just get a "cannot execute" error.
I get this same error if I try to run the program on my development machine. So, it wasn't compiled natively and the nios2-elf-gcc cross-compiler didn't seem build it for the nios2 architecture either. Am I missing something here? Shouldn't I just be able to use "nios2-elf-gcc" to compile a program and have it run on the nios2? I can understand if there are library issues. Perhaps the libraries on my target don't match the libraries for my development environment. But, if I compile the programs statically, it should just come down to a compiler issue.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
<div class='quotetop'>QUOTE </div>
--- Quote Start --- Shouldn't I just be able to use "nios2-elf-gcc" to compile a program and have it run on the nios2?[/b] --- Quote End --- not if you run the program on uClinux. Under uClinux, we are using a FLAT binary format, not ELF (which could not run on uClinux). You need a tool, elf2flt, to convert ELF format to FLAT format. Please check the userland Rules.mak for details. You also need the source code of elf2flt (with Nios II support) so that you can rebuilt it on Linux. Regards, wentao Microtronix.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to know if it is built under RedHat9.
Thanks.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes,
I am building all of these tools under Redhat 9.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
But where can download the nios2-gnutools. And if install successfully, which OS can we use for nios2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have extracted the source code for the elf2flt utility that was part of the Nios II IDE installation.
I found it in the altera/kits/nios2/examples/software/linux/utils directory. I moved this directory over to my Linux machine and ran dos2unix on all the files. I've been trying to get it configured and build properly, but I'm running into a problem with an "undefined reference to '__getreent' " error. The README for the elf2flt utility only discusses the inclusion of the libbfd.a and the libiberty.a libraries. I think I've pointed to the correct location for these, but the __getreent symbol is still not found. The interesting thing is that non of the elf2flt c files actually call the __getreent function. The errors point to the fprintf function. It must be using the __getreent. Does anyone know how to resolve this error?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I successfully compiled the elf2flt utility under Linux.
Now I am having a problem using the elf2flt utility. I have the same problem under my Cygwin environment under Windows. If I use nios2-elf-gcc to compile a simple program (e.g. nios2-elf-gcc hello.c -o hello) and try to use the elf2flt utility to convert the format to flat, it gives me the following error: hello: Input file contains no relocation info The hello file is the executable that was created directly from the nios2-elf-gcc compiler. If I try to run the hello file directly on my uKit Nios II development board, then I get the format errors described a couple replies back. WHAT AM I MISSING HERE?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi trk_golf,
<div class='quotetop'>QUOTE </div> --- Quote Start --- If I use nios2-elf-gcc to compile a simple program (e.g. nios2-elf-gcc hello.c -o hello) and try to use the elf2flt utility to convert the format to flat...[/b] --- Quote End --- If you want to run hello on uClinux, you have to compile it with uClibc, not the default newlib. Therefore, here you must explicitly specify the crt0.o and libc.a from uClibc. (we do this because the tool chain is not built against uclibc, but newlib). You also need to tell the linker to generate relocatable outputs, so that elf2flt can convert them. This is done by passing "-r -d" to the linker. (You could also try "-q" to do a final link and keep the relocation records, but it was broken when I tried about half year ago). For details, please refer to the file Rules.mak for building userland applications on Cygwin. Regards, wentao Microtronix- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for all your advice. I'm moving forward, but I'm still running into problems with converting the file to a flat binary.
I have used the Rules.mak file as a reference. It is located at "altera/kits/nios2/bin/eclipse/plugins/com.microtronix.nios2linux.application_0.1.0/templates" on my Windows machine. I have also tried using the elf2flt.ld linker script located at "com.microtronix.nios2linux.application_0.1.0/scripts". No matter what I try, I keep getting an error from nios2-elf-elf2flt that states "cpuload.elf: Input file contains no relocation info". However, if I perform a "nios2-elf-objdump -f cpuload.elf", then I get the following results: cpuload.elf: file format elf32-littlenios2 architecture: nios2, flags 0x00000011: HAS_RELOC, HAS_SYMS start address 0x00000000 Doesn't the output from objdump indicate that the elf image does indeed have relocation information? Did I compile elf2flt improperly on my Linux machine? Any other suggestions?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It sounds like the elf2flt is not built correctly. In the elf2flt src directory are there some libraries (libbfd.a and libiberty.a), which are from the building of the nios2 toolchain under Cygwin, you are supposed to replace them with those you built under Linux.
I dont know if you have done this. wentao- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm getting closer...
I have rebuilt elf2flt, but I still get an error. Here are the steps I took to rebuild the elf2flt tool: I copied nios2-gnutools/src/binutils-build/bfd/bfd.h nios2-gnutools/src/binutils-build/bfd/libbfd.a nios2-gnutools/src/binutils-build/libiberty/libiberty.a into my elf2flt directory. I then ran the following configure command: ./configure --target=nios2-elf --with-bfd-include-dir=. --with-libbfd=./libbfd.a --with-libiberty=./libiberty.a This configures without errors. I then run make. This succeeds. If I use the resulting elf2flt binary to try and convert the cpuload.elf file I created, it provides the following error? ERROR: text=0xaf0 overlaps data=0x0 ? Does this have something to do with the linker script? I apologize for my ignorance. I've never dealt with an elf image and linkers that much until now. I am grateful for your help.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is the output from nios2-elf-readelf -S cpuload.elf
I see that the .text section has a size of 0x0af0 and is at offset 0x38. That's about all that I can relate to the error. It would appear that this fits in without overlapping anything. Any idea what the error might be related to? <div class='quotetop'>QUOTE </div> --- Quote Start --- There are 27 section headers, starting at offset 0x54d8: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 000038 000af0 00 AX 0 0 8 [ 2] .rela.text RELA 00000000 005910 000318 0c 25 1 4 [ 3] .rodata PROGBITS 00000000 000b28 000010 00 A 0 0 4 [ 4] .data PROGBITS 00000000 000b38 000018 00 WA 0 0 4 [ 5] .sdata PROGBITS 00000000 000b50 000018 00 WAp 0 0 4 [ 6] .sbss NOBITS 00000000 000b68 000004 00 WAp 0 0 4 [ 7] .bss NOBITS 00000000 000b68 000000 00 WA 0 0 1 [ 8] .comment PROGBITS 00000000 000b68 000160 00 0 0 1 [ 9] .debug_aranges PROGBITS 00000000 000cc8 0000c0 00 0 0 1 [10] .rela.debug_arang RELA 00000000 005c28 000090 0c 25 9 4 [11] .debug_pubnames PROGBITS 00000000 000d88 0000ee 00 0 0 1 [12] .rela.debug_pubna RELA 00000000 005cb8 000054 0c 25 b 4 [13] .debug_info PROGBITS 00000000 000e76 0017ca 00 0 0 1 [14] .rela.debug_info RELA 00000000 005d0c 001758 0c 25 d 4 [15] .debug_abbrev PROGBITS 00000000 002640 000a9d 00 0 0 1 [16] .debug_line PROGBITS 00000000 0030dd 000d15 00 0 0 1 [17] .rela.debug_line RELA 00000000 007464 000cc0 0c 25 10 4 [18] .debug_frame PROGBITS 00000000 003df4 0001ec 00 0 0 4 [19] .rela.debug_frame RELA 00000000 008124 0000c0 0c 25 12 4 [20] .debug_str PROGBITS 00000000 003fe0 001322 01 MS 0 0 1 [21] .ctors PROGBITS 00001324 005304 000014 00 WAX 0 0 4 [22] .dtors PROGBITS 00001338 005318 000014 00 WAX 0 0 4 [23] .debug_ranges PROGBITS 0000134c 00532c 0000c8 00 0 0 1 [24] .shstrtab STRTAB 00000000 0053f4 0000e1 00 0 0 1 [25] .symtab SYMTAB 00000000 0081e4 000860 10 26 39 4 [26] .strtab STRTAB 00000000 008a44 0005e1 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific)[/b] --- Quote End ---- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've been looking at the source code for the elf2flt utility.
I also ran it in verbose mode. With the -v option, its output is the following: TEXT -> vma=0x0 len=0xaf0 DATA -> vma=0x0 len=0x18 ERROR: text=0xaf0 overlaps data=0x0 ? I would think that it would us the offset information, not the address to determine if something is overlapping. Isn't this the point in having relocatable code, it uses offsets instead of fixed addresses ? Perhaps I've done something wrong or the linker script isn't correct. I'll keep digging around. If you have any suggestions, feel free to let me know.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page