Altera_Forum
Honored Contributor
20 years agoHow to port apps to uClinux
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