Community
cancel
Showing results for 
Search instead for 
Did you mean: 

Kernel Patches

Kernel Patches



How to port Linux to Nios II :

The development branch of Linux is maintained by Linus Torvalds. We pull the updates from Linus' git repository.


First, add Linus' git url as remote,

cd nios2-linux/linux-2.6

git remote add linus <a rel="freelink" href="git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git" >git://git.kernel.org/pub/scm/linux/k.../linux-2.6.git


Then pull updates for each -rc and stable release,

git pull linus master


Each -rc usually takes one or two week. Eg,

...2.6.26, 

2.6.27-rc1, 2.6.27-rc2....2.6.27-rc9, 2.6.27,

2.6.28-rc1,...


Most changes come with -rc1. A lot of things might break. And the merge might fail due to conflict. This is the most difficult part. But we can look at the other archs&apos; patches. Eg, m68knommu,arm,sh,blackfin,x86 etc.

gitk arch/m68knommu


Study their patches, and possibly make the same change to nios2. After -rc1, all other updates move easily. Sometimes, we have to search the Linux kernel mailing list to find out how/why to make the changes.


At last, after enough tests, push the patches up to our sopc server.




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 <a href="http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.tar.bz2" >linux-2.6.20.tar.bz2

mv linux-2.6.20 linux-2.6.20.x

cd linux-2.6.20.x

zcat <a href="http://www.uclinux.org/pub/uClinux/uClinux-2.6.x/linux-2.6.20-uc0-big.patch.gz" >linux-2.6.20-uc0-big.patch.gz | patch -p1

zcat <a href="/@api/deki/files/91/=linux-2.6.20-uc0-nios2-02.diff.gz">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 <a href="http://www.kernel.org/pub/linux/kernel/v2.6/patch-2.6.20.3.bz2" >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&apos;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&apos;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 <a href="/OperatingSystems/UClinux/BuildrootGuide">BuildrootGuide to install the nios2 linux kernel 2.6.11-uc0 source from release 1.4 of Microtronix.

Jdhar&apos;s uClinux SVN Repository opened up to public! <a href="http://via.fps-tech.org/svn" >SVN Repository located here


<a href="http://www.ucdot.org/articles/06/10/19/2250248.shtml" >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 <a href="http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.2.tar.bz2" >linux-2.6.18.2.tar.bz2

cd ~/linux-2.6.18.2

zcat <a href="http://www.uclinux.org/pub/uClinux/uClinux-2.6.x/linux-2.6.18-uc0.patch.gz" >linux-2.6.18-uc0.patch.gz | patch -p1

zcat <a href="/@api/deki/files/90/=linux-2.6.18-nios2-02.diff.gz">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&apos;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 

     

write my essay

Version history
Revision #:
1 of 1
Last update:
‎06-24-2019 08:08 PM
Updated by:
 
Contributors