http://uuu.enseirb.fr/~kadionik/embedded/uclinux/HOWTO_compile_uClinux_for_NIOS.html


HOWTO compile the uClinux kernel for NIOS

A quick and dirty guide v1.1

kadio...@enseirb.fr 2003/12/27 with the uClinux-2.4.x tree

  • v1.0: 2004/03/22 creation
  • v1.1: 2004/03/24 binfmt_flat.c source files from Greg added. Command lines for SREC generation added
  • v2.0: 2004/04/07 a patch file added for the uClinux-20040218 distribution

 

0. You may download a patch file that integrates all the modifications presented below. Perform after:

  • % tar -xvzf uClinux-dist-20040218.tar.gz
  • % patch -p0 < uClinux-dist-20040218-nios-linux-2.4.x.patch
  • % cd uClinux-dist/linux-2.4.x
  • % make xconfig
  • % make dep
  • % make
  • You have a big file named linux...See the end of the document for the SRecord conversion. You just have a compiled µClinux kernel that may not work on your target because you have to feet some nios*.h (point 13) according to your own Altera's Quartus II design. If all is OK, you'll have to face to a kernel panic on the root file system mounting. No "GPL" uClibc support for NIOS at this time...

 

1. Have a ready nios-elf-gcc C compiler under Linux. Please see here if you don't have it.

 

2. All the modifications are relative to the uClinux-2.4.x directory.

Edit Makefile. Uncomment:

# ARCH := niosnommu

and

# CROSS_COMPILE = nios-elf-

Change the CPPFLAGS to:

CPPFLAGS := -D__KERNEL__ -I$(HPATH) -D__nios__ -I/usr/local/nios-elf/lib/gcc-lib/nios-elf/2.9-nios-010801-20030923/include/

I assume that the C cross compiler is installed under /usr/local/nios-elf/ directory.

Add the init/do_mounts.c file compilation:

$(LINUX): include/linux/version.h $(CONFIGURATION) init/main.o init/version.o init/do_mounts.o linuxsubdirs

$(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o init/do_mounts.o \

--start-group \

$(CORE_FILES) \

$(DRIVERS) \

$(NETWORKS) \

...

init/main.o: init/main.c include/config/MARKER

$(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) -c -o $@ $<

init/do_mounts.o: init/do_mounts.c include/config/MARKER

$(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) -c -o $@ $<

Comment the line (line 222) (problem at the linking)

#DRIVERS-y +=drivers/media/media.o

 

3. copy arch/niosnommu/defconfig under .config

cp arch/niosnommu/defconfig .config

 

4. In the Rules.make file, comment the line unexport EXTRA_LDFLAGS:

#unexport EXTRA_LDFLAGS

 

5. Replace the fs/binfmt_flat.c and include/asm-niosnommu/flat.h with those posted by Greg in the µClinux mailing list. binfmt_flat.c and flat.h

 

6. In the include/asm-niosnommu/processor.h file, replace (line 137)

extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);

by

extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);

 

7. In the file arch/niosnommu/kernel/process.c, replace (line 234)

pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)

by

long arch_kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)

 

8. In the file include/asm-niosnommu/system.h, add (line 202)

#define set_mb(var, value) do { var = value; mb(); } while (0)

 

9. make xconfig

unvalidate the IDE support, no cs8900 support

 

10. make dep; make

 

11. Here we are with a big big file named linux (about 30 Mbytes)...to convert into an Srecord file. Try these commands:

#!/bin/sh

flash_base=0x`grep "_nios_flash_start" System.map | sed 's/ .*//'`

kernel_fbase=0x`grep "_kernel_flash_start" System.map | sed 's/ .*//'`

kernel_size=0x`grep "_kernel_footprint" System.map | sed 's/ .*//'`

nios-elf-objcopy -O binary linux linux.bin

nios-elf-ld -Ttext ${kernel_fbase} -Tdata ${kernel_fbase} -e ${kernel_fbase} --o format srec -o linux.srec -b binary linux.bin

 

12. Download the linux.srec file into your board by the serial line.

 

13. BE CAREFULL the include/asm-niosnommu/nios*.h must be changed to fit your hardware design...

 

May this help you...Help is welcome for the GPL NIOS uClinux effort!

Pat.


Reply via email to