Welcome, guest ( Login )

WikiHome » OperatingSystems » µClinux » KernelPatches

KernelPatches

Version 21, changed by hippo5329@yahoo.com.tw. 12/16/2007.   Show version history

How to port Linux to Nios II :

You can join the latest developments with us. Please use git (see GitServer).

git clone -n git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
cd linux-2.6
git remote add sopc git://sopc.et.ntust.edu.tw/git/linux-2.6.git
git fetch sopc
git checkout -b v2.6.23-uc sopc/v2.6.23-uc

PS.
We have bandwidth issue with our git server at NTUST. To help reduce the network loading, please don't clone directly from sopc server.




The latest working Nios II kernel is 2.6.20-uc0 , which can be found in the patches attached at the end of this page against uClinux-dist-20070130 and nios2 patches  of UClinuxDist .



linux-2.6.20-uc0

Adding linux-2.6.20 kernel to uClinux-dist-20070130,

cd ~/uClinux-dist/vendors/Altera/nios2nommu
cp config.linux-2.6.x config.linux-2.6.20.x
cd ~/uClinux-dist
tar jxf linux-2.6.20.tar.bz2
mv linux-2.6.20 linux-2.6.20.x
cd linux-2.6.20.x
zcat linux-2.6.20-uc0-big.patch.gz | patch -p1
zcat linux-2.6.20-uc0-nios2-02.diff.gz | patch -p1

# optional, additional patches to sync up to linux-2.6.20.3, or use incr patches .1,.2,.3
bzcat patch-2.6.20.3.bz2 | patch -p1

cd ~/uClinux-dist
make menuconfig   # and select kernel
(linux-2.6.20.x) Kernel Version



These are the steps, which we used to port a new kernel. Since nios2 patches was merge in the uClinux-dist, we don't use this approach now.
  1. download the latest kernel source from kernel.org , and extract.  (eg, 2.6.18.1)
  2. download the uc patches from uclinux.org , and apply the patches. (eg, 2.6.18-uc0)
  3. copy dir arch/nios2nommu and include/asm-nios2nommu from old linux source tree (eg, 2.6.17-uc0) to the new linux source tree (eg, 2.6.18.1-uc0) .
  4. update include/linux/elf.h and include/linux/serial_core.h for nios2
  5. copy drivers/serial/ NIOSserial.[ch] and altera_juart.c , update Kconfig and Makefile   , to enable uart
  6. minimal config, compile kernel and clear any error, mostly header files becuase of kernel struct or API changes.
  7. boot the new kernel, and check run-time error.
  8. if error found either in compilation or run-time, it is very helpful to cross check the source of other arch, such as m68knommu,arm,sh,mips etc.
  9. if everything works fine, then add more nios2 drivers, eg, ethernet,mtd ..


Attached kernel.zip are patches to port Nios II to newer kernels, from 2.6.11 to 2.6.15 .

I had planned the patches when update kernels,

00 the uc0 , get the uc0 patches from uclinux.org

01 the nois2nommu from microtronix's 1.4 pull out, with only uart drivers.

02 fix compile error and runtime error for new kernel to boot

03+ add zImage and all other drivers of dev boards, eg, cfi,epcs,net,usb,i2c,pci...


The attached kernel2.zip is 2.6.16.1 . You should be abel to apply the patches to 2.6.16.11 .

You may follow the BuildrootGuide to install the nios2 linux kernel 2.6.11-uc0 source from release 1.4 of Microtronix.

Jdhar's uClinux SVN Repository opened up to public! SVN Repository located here


Adding a new/different kernel to the uClinux-dist (copy from ucdot.org, becuase the server was down)

Whether tracking 2.6 development, wanting to use an updated uClinux-dist with and older kernel or perhaps slot a vendor kernel into the uClinux-dist, here are two simple options to make it easier. This example will demostrate adding a new kernel patched kernel into the uClinux-dist.
 
Replace existing.

    cd uClinux-dist
    mv linux-2.6.x linux-2.6.x.orig
    tar xvzf linux-2.6.18.tar.gz
    cd linux-2.6.18
    gunzip < linux-2.6.18-uc0.patch.gz | patch -p1
    cd ..
    mv linux-2.6.18 linux-2.6.x

    then run make config etc to select the kernel and build the platform.

Add another kernel to the build options

    cd uClinux-dist
    tar xvzf linux-2.6.18.tar.gz
    cd linux-2.6.18
    gunzip < linux-2.6.18-uc0.patch.gz | patch -p1
    cd ..
    mv linux-2.6.18 linux-2.6.18.x
    cd ../vendors/MYVENDOR/MYPRODUCT
    cp config.linux-2.6.x config.linux-2.6.18.x
    cp config.vendor-2.6.x config.vendor-2.6.18.x
    cd ../../..

    then run make config etc to select the new kernel options and build the platform.

This can be done with 2.0/2.4 and 2.6 kernels, actually, any directory named linux-blah.x will become a kernel option.

linux-2.6.18

To install 2.6.18 source, (NOTE, you must apply the patches ONLY ONCE)
cd ~
tar jxf linux-2.6.18.2.tar.bz2
cd ~/linux-2.6.18.2
zcat linux-2.6.18-uc0.patch.gz | patch -p1
zcat linux-2.6.18-nios2-02.diff.gz | patch -p0

To compile kernel for your project, assume you have rootfs built in ~/uClinux-dist/romfs, (NOTE each make command are one-line, don't break)
mkdir ~/your_project/kernel-2.6.18
cd ~/linux-2.6.18.2
make O=~/your_project/kernel-2.6.18 ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- defconfig hwselect SYSPTF=~/your_project/your_system.ptf
make O=~/your_project/kernel-2.6.18 ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- menuconfig
make O=~/your_project/kernel-2.6.18 ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- zImage

Compressed kernel image will be ~/your_project/kernel-2.6.18/arch/nios2nommu/boot/zImage

If you use modules, install modules to your rootfs,
make O=~/your_project/kernel-2.6.18 ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- INSTALL_MOD_PATH=~/uClinux-dist/romfs modules modules_install
Then use strip to reduce module files size,
ROMFSDIR = ~/uClinux-dist

STRIP = nios2-linux-uclibc-strip
rm -f $(ROMFSDIR)/lib/modules/*/build

rm -f $(ROMFSDIR)/lib/modules/*/source

find $(ROMFSDIR)/lib/modules -type f -name "*o" | xargs -r $(STRIP) -R .comment -R .note -g --strip-unneeded
Finally update the initramfs,
make O=~/your_project/kernel-2.6.18 ARCH=nios2nommu CROSS_COMPILE=nios2-linux-uclibc- zImage





Attachments (7)

  File By Size Attached Ver.
 kernel2.zip guest 337K 04/30/2006 1 Delete attachment
 kernel.zip guest 971K 04/30/2006 1 Delete attachment
 linux-2.6.17.1-nios2-02.diff.gz hippo5329@yahoo.com.tw 4K 06/25/2006 1 Delete attachment
 linux-2.6.18-nios2-02.diff.gz hippo5329@yahoo.com.tw 332K 11/13/2006 3 Delete attachment
 linux-2.6.18_to_2.6.19-nios2.diff.gz atlenissestad 3K 01/18/2007 1 Delete attachment
 linux-2.6.20-uc0-nios2-02.diff.gz hippo5329@yahoo.com.tw 48K 02/12/2007 2 Delete attachment
 linux-2.6.22-uc0-big-nios2-02.diff.gz atlenissestad 10K 10/30/2007 1 Delete attachment