Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

How to port apps to uClinux

Altera_Forum
Honored Contributor II
1,475 Views

This is about how to port applications to uCLinux on nios2. I will take mtools-3.9.10 as an example. 

If you are a newbie, read the FAQ on www.ucdot.org. 

There is no MMU, so no virtual memory, no fork, and stack size is fixed. 

The exec format is not ELF, but binary flat format, FLT. 

Some apps will run, some will not run. (marc) 

Some will run with small data, but fail with large data. 

 

First, read the INSTALL. 

If it need "./configure", run it. 

A Makefile will be generated. 

You will have to modify the Makefile or Rules.mak. To fixup the cc and libs flags. 

Remove unused items, or that is for PC host. 

 

Then, 

"make" 

"make install" 

The binary and links will be install to $(ROOTS)/usr/local/bin. 

Note, the stack size is specified as "-s 16000" to elf2flt in the ldflags, for about 16KiBytes here. 

You can change it to other value with decimal. Hex is not allowed with it. 

 

copy the mtools.conf to $(ROOTFS)/etc, and set C: for /dev/hda1. 

I try out the binary.# modprobe vfat# mkdir /mnt/v1# PATH=$PATH:/usr/local/bin# fdisk /dev/hda# mformat -t 124 -h 255 -n 63 C: 

Ohhh.., it failed with 

"Allocation of length 8228864 from process 27 failed". 

Rebuild the kernel with 

[*] Allow allocating large blocks (> 1MB) of memory 

and try again with,# mformat -t 2000 -h 16 -n 63 c:# mount -t vfat /dev/hda1 /mnt/v1 

HaHa!! It works.  

Just the (head * sector) can not be too large, (255 * 63) will fail. 

 

The patch to the Makefile for mtools, 

--- Makefile    2006/01/06 06:17:29    1.1 +++ Makefile    2006/01/06 06:38:58 @@ -6,10 +6,14 @@ # a lock method... either -DLOCKF, -DFLOCK, or -DFCNTL and put that # string in the CFLAGS line below. +UCLIBC_PLUGIN = /usr/local/src/nios2/build/uClibc_dev +KERNEL_BUILD_DIRECTORY = /usr/local/src/nios2/linux-2.6.x +ROOTFS = /usr/local/nios2-elf/src/nios2/build/rootfs + # User specified flags -USERCFLAGS = -USERLDFLAGS = -USERLDLIBS = +USERCFLAGS = -nostdinc -I$(UCLIBC_PLUGIN)/include -I$(KERNEL_BUILD_DIRECTORY)/include -funsigned-char -iwithprefix include -Dfork=vfork -D__uClinux__ +USERLDFLAGS = -nostdlib -Wl,-elf2flt="-s 16000" -Wl,-v -Wl,-d -L$(UCLIBC_PLUGIN)/lib $(UCLIBC_PLUGIN)/lib/crt0.o +USERLDLIBS = -lc -lm -lgcc MAKEINFO = makeinfo TEXI2DVI = texi2dvi @@ -26,23 +30,23 @@ srcdir=. -prefix      = /usr/local +prefix      = $(ROOTFS)/usr/local exec_prefix = ${prefix} bindir      = ${exec_prefix}/bin infodir     = ${prefix}/info mandir      = ${prefix}/man sysconfdir  = ${prefix}/etc -CC         = gcc +CC         = nios2-elf-gcc CXX        = @CXX@ MYCFLAGS   = -g -O2 -Wall MYCXXFLAGS = @CXXFLAGS@ CPPFLAGS   = HOST_ID    = -DCPU_i686 -DVENDOR_pc -DOS_linux_gnu -DEFS       = -DHAVE_CONFIG_H -DSYSCONFDIR=\"$(sysconfdir)\" $(HOST_ID) +DEFS       = -DHAVE_CONFIG_H -DSYSCONFDIR=\"$(sysconfdir)\" LDFLAGS     = -LIBS        = -lbsd -lnsl +LIBS        = SHLIB       = MACHDEPLIBS =   LN_S        = ln -s @@ -122,10 +126,10 @@ mlabel mmd mmount mmove mpartition mrd mren mtype mtoolstest mshowfat mbadblocks mzip -X_CFLAGS =  -I/usr/X11R6/include -X_LIBS =  -L/usr/X11R6/lib +X_CFLAGS = +X_LIBS = X_EXTRA_LIBS = -X_PRE_LIBS =  -lSM -lICE +X_PRE_LIBS = CFLAGS = $(CPPFLAGS) $(DEFS) $(MYCFLAGS) -fno-strict-aliasing -I.  -I. $(USERCFLAGS) CXXFLAGS  = $(CPPFLAGS) $(DEFS) $(MYCXXFLAGS) -I.  -I. $(USERCFLAGS) LINK      = $(CC) $(LDFLAGS) $(USERLDFLAGS) @@ -133,7 +137,7 @@ X_LDFLAGS = $(X_EXTRA_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lXau -lX11 $(LIBS) X_CCFLAGS = $(X_CFLAGS) $(CFLAGS) -all:    mtools $(LINKS) mkmanifest floppyd floppyd_installtest +all:    mtools $(LINKS) %.o: %.c  $(CC) $(CFLAGS) -c $< @@ -217,8 +221,7 @@ uninstall-info:  cd $(infodir) && rm -f mtools.info* -install:    $(bindir)/mtools $(bindir)/floppyd $(bindir)/floppyd_installtest install-man install-links -  $(bindir)/mkmanifest install-scripts install-info +install:    $(bindir)/mtools install-links uninstall:    uninstall-bin uninstall-man uninstall-links      uninstall-scripts
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
735 Views

It&#39;s very good.Thank you, hippo!!! 

 

Can you tell me what cross compiler you used? 

 

Is microtronix Nios II Cross Development Kit ? 

 

Alex
0 Kudos
Altera_Forum
Honored Contributor II
735 Views

I built the tools on Linux, as you knew. 

I didn&#39;t try it on Widnows, but the patch can be easily adapted. 

I am not sure if sym-link works on cygwin? 

Maybe some one can try out. 

 

One minor issue in my first post, the crt1.o is for the lastest uClbc snapshot. 

It should be spelled as crt0.o for your case. 

 

If you follow marc&#39;s site to build toolschain, it is even more simple to do the job. 

The nios2-elf-gcc should be spelled as nios2-linux-uClibc-gcc. 

And -nostdinc incdirs and -nostdlib crt0.o libs libdirs can be omited, because they are compiled into uClibc default.
0 Kudos
Altera_Forum
Honored Contributor II
735 Views

thanks hippo. 

 

I want to porting ucd-snmp4.1.2 to nios2 uclinux. 

 

so I must select a cross compiler. I wish Marc&#39;s toolschain can be used.
0 Kudos
Altera_Forum
Honored Contributor II
735 Views

You migh check the net-snmp, (former ucd-snmp), port in buildroot&#39;s apps. 

Or in uClinux-dist&#39;s user. 

But they are more complicated. 

 

For ucd-snmp4.1.2, ./configure and fix up the generated makefiles and config.h.
0 Kudos
Altera_Forum
Honored Contributor II
735 Views

alex824: 

 

Alternatively, you can use marc&#39;s toolchain binaries to build net-snmp from its main source. I was able to do that successfully with some help from hippo. See http://forum.niosforum.com/forum/index.php?showtopic=3186 (http://forum.niosforum.com/forum/index.php?showtopic=3186).
0 Kudos
Altera_Forum
Honored Contributor II
735 Views

TO_BE_DONE

0 Kudos
Reply