packages kernel-embedded.spec
      Pages: < 1 >  DOWNLOAD      
# QiLinux 2.6 embedded kernel specfile
# Copyright (C) 2006-2007 by Silvan Calarco <silvan.calarco@...>
# Released under the terms of the GNU GPL License version 2
#
# To build a specific target and platform:
#
# rpm -ba --define="KERNEL_TARGET <target>" --define="KERNEL_PLATFORM <platform>" kernel.spec
#
# Examples:
#
# rpmbuild -ba kernel-embedded.spec --target=i586 \
#    --define="KERNEL_TARGET geode" --define="KERNEL_PLATFORM hurricane"
#
# rpmbuild -ba kernel-embedded.spec --target=arm \
#    --define="KERNEL_TARGET pxa2xx" --define="KERNEL_PLATFORM logicpd_pxa270"
#
# rpmbuild -ba kernel-embedded.spec --target=arm \
#    --define="KERNEL_TARGET pxa2xx" --define="KERNEL_PLATFORM intel_dbpxa250"
#
# currently available targets (platforms):
# geode (hurricane)
# pxa2xx (logicpd_pxa270)
# pxa2xx (intel_dbpxa250)
# pxa2xx (mainstone)

%define        kernel_ver 2.6.20
%define        kernel_pl 0
%define        qilinux_release 1qilnx
%define        USE_DISTCC 0
%define        fbsplash_ver 0.9.2-r5-2.6.19-rc2
%define        vesafb_tng_ver 1.0-rc2-2.6.20-rc2
%define        rt_lsm_ver 0.8.7
%define        suspend2_ver 2.2.9.3-for-2.6.20-rc4
%define        ks88xx_ver 1.0.5

%if "%{USE_DISTCC}" == "1"
   %define        DISTCC CC="ccache distcc" -j 12
%endif

# Build a preempt kernel if no target was specified
%if "%{?KERNEL_TARGET}" == ""
   %define     KERNEL_TARGET geode
%endif

# define short kernel target name for Lilo
%define     KERNEL_TARGET_SHORT %{KERNEL_TARGET}

%if "%{KERNEL_TARGET}" == "smppreempt"
   %define     KERNEL_TARGET_SHORT smppe
%endif

%if "%{_target_cpu}" == "i586"
   %if "%{?KERNEL_PLATFORM}" == ""
      %define     KERNEL_PLATFORM hurricane
   %endif
   %define     KIMAGE arch/i386/boot/bzImage
   %define     KIMAGE_DEST vmlinuz
   %define     DEPMOD /sbin/depmod
%endif

%if "%{_target_cpu}" == "ppc"
   %define     KIMAGE vmlinux
   %define     KIMAGE_DEST vmlinux
   %define     DEPMOD /bin/true
%endif

%if "%{_target_cpu}" == "arm"
   %if "%{?KERNEL_PLATFORM}" == ""
      %define     KERNEL_PLATFORM logicpd_pxa270
   %endif

   %define     KIMAGE arch/arm/boot/zImage
   %define     KIMAGE_DEST vmlinuz
   %define     DEPMOD /bin/true
%endif

%if "%{_target_cpu}" == "i586"
   %define     target_cpu i386
%else
   %define     target_cpu %{_target_cpu}
%endif

Name:          kernel-embedded
Version:       %{kernel_ver}
Release:       %{?kernel_pl}.%{qilinux_release}
Summary:       The Linux Kernel, the operating system core itself
Group:         System/Kernel and Hardware
Vendor:        mambaSoft
Distribution:  QiLinux
Packager:      Silvan Calarco <silvan.calarco@...>
Source0:       ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-%{kernel_ver}.tar.bz2
Source1:       %{name}-geode-hurricane-i586-config
Source2:       %{name}-pxa2xx-logicpd_pxa270-arm-config
Source3:       %{name}-pxa2xx-intel_dbpxa250-arm-config
Source4:       %{name}-pxa2xx-mainstone-arm-config
%if "%{?kernel_pl}" != "0"
Patch0:        http://www.kernel.org/pub/linux/kernel/v2.6/patch-%{kernel_ver}.%{?kernel_pl}.bz2
%endif
Patch15:       kernel-2.6.20-squashfs3.2.patch
Patch16:       http://dev.gentoo.org/~spock/projects/gensplash/archive/fbsplash-%{fbsplash_ver}.patch
Patch17:       http://dev.gentoo.org/~spock/projects/vesafb-tng/archive/vesafb-tng-%{vesafb_tng_ver}.patch
Patch18:       kernel26-2.6.18-bt8xx.patch
Patch20:       suspend2-%{suspend2_ver}.patch.bz2
Patch21:       http://belnet.dl.sourceforge.net/sourceforge/realtime-lsm/rt-lsm-%{rt_lsm_ver}-kernel.patch.gz
# Ks88XX ethernet driver downloaded from:
# ftp://www.micrel.com/ethernet/8842P/KSZ88XX Software Package 1.0.5.zip
Patch22:       ks88xx-%{ks88xx_ver}.patch
Patch23:       kernel-2.6.18-geode-fblx.patch
Patch24:       kernel-embedded-2.6.19pxa2xx-pcmcia.patch
Patch25:       pxafb_fix_params-r2.patch
Patch26:       kernel-2.6.19-usbstorage-disable_delay_use.patch
URL:           http://www.kernel.org
License:       GPL
BuildRequires: /bin/bash /bin/sh /usr/bin/perl
BuildRequires: module-init-tools >= 3.1
%if "%{USE_DISTCC}" == "1"
BuildRequires: distcc ccache
%endif
BuildRoot:     %{_tmppath}/%{name}-%{version}-build

%description
The Linux Kernel, the operating system core itself.
The kernel package contains the Linux kernel (%{KIMAGE_DEST}), the operating system core itself.
The kernel handles the basic functions of the operating system:
memory allocation, process allocation, device input and output, etc.

%package -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}
Group:         System/Kernel
Summary:       The Linux kernel, the operating system core itself
PreReq:        mkinitramfs >= 0.5-1qilnx, module-init-tools >= 3.2.2

%description -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}
This kernel binary package contains a Linux kernel (%{KIMAGE_DEST}), the operating system core itself.
The kernel handles the basic functions of the operating system:
memory allocation, process allocation, device input and output, etc.
This kernel was build for %{_target_cpu} architecture and the following embedded target and platform: %{?KERNEL_TARGET} (%{?KERNEL_PLATFORM}).

%package -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}-modules
Group:         System/Kernel
Summary:       Modules for the Linux kernel, the operating system core itself
PreReq:        kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}

%description -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}-modules
This kernel binary package contains the modules for a Linux kernel that was built for 
%{_target_cpu} architecture and the following embedded target and platform: %{?KERNEL_TARGET} (%{?KERNEL_PLATFORM}).

%package -n kernel-%{KERNEL_TARGET}-%{?KERNEL_PLATFORM}-source
Group:         Development/Kernel
Summary:       The source code for the Linux kernel
Provides:      kernelsource

%description -n kernel-%{KERNEL_TARGET}-%{?KERNEL_PLATFORM}-source
The kernel-source package contains the source code files for the Linux kernel.
The source files can be used to build a custom kernel that is better tuned to your particular hardware, if you are so inclined (and you know what you're doing).
This kernel sources are configured for %{TARGET_CPU} architecture and the following embedded target and platform: %{?KERNEL_TARGET} (%{?KERNEL_PLATFORM}).

%prep
[  "%{buildroot}" != / ] && rm -rf "%{buildroot}"

%if "%{?KERNEL_TARGET}" == ""
   echo "No target specified, aborting."
   exit 1
%else
   echo "I'm going to build a %{KERNEL_TARGET} (%{KERNEL_PLATFORM}) kernel..."
%endif

%setup -q -c -n %{name}-%{kernel_ver}%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM} -D -T
:<< _EOF
mv linux-%{kernel_ver}/* .
rm -r linux-%{kernel_ver}

# add here subrelease patch
%if "%{?kernel_pl}" != "0"
%patch0 -p1
sed -i "s/\(EXTRAVERSION =\).*/\1/" Makefile
%endif

#
# patch and configure STANDARD kernel
#

make mrproper

# create build dirs for each kernel
# and copy proper configuration
%if %{_target_cpu} == i586
   case %{?KERNEL_TARGET} in
      geode)
        case %{?KERNEL_PLATFORM} in
           hurricane)
              kernel_cfg=%{SOURCE1}
              ;;
           *) echo "Error: unknown kernel platform: %{?KERNEL_PLATFORM}. Aborting."; exit 1
              ;;
        esac
        # squashfs patch
        patch -p1 < %{PATCH15}
        # add splash patch
        patch -p1 < %{PATCH16}
        # ks88xx patch
        patch -p1 < %{PATCH22}
        # Geode LX framebuffer patch
        #patch -p1 < %{PATCH23}
        # suspend2 patch
        bunzip2 -c %{PATCH20} | patch -p1
        ;;
      *) echo "Error: unknown kernel target: %{?KERNEL_TARGET}. Aborting."; exit 1 
         ;;
   esac
%endif
%if %{_target_cpu} == arm
   case %{?KERNEL_TARGET} in
      pxa2xx)
        case %{?KERNEL_PLATFORM} in
           logicpd_pxa270)
              kernel_cfg=%{SOURCE2}
              ;;
           intel_dbpxa250) 
              kernel_cfg=%{SOURCE3}
              # fix a build on ohci-sa1111.c
              ln -s `pwd`/include/asm-arm/arch-sa1100/assabet.h include/asm-arm/arch-pxa/assabet.h
              ln -s `pwd`/include/asm-arm/arch-sa1100/badge4.h include/asm-arm/arch-pxa/badge4.h
              ;;
           mainstone)
              kernel_cfg=%{SOURCE4}
              ;;
           *) echo "Error: unknown kernel platform: %{?KERNEL_PLATFORM}. Aborting."; exit 1
              ;;
        esac
        # add splash patch
        patch -p1 < %{PATCH16}
        # ks88xx patch
        patch -p1 < %{PATCH22}
        # pxa pcmcia patch
        patch -p1 < %{PATCH24}
        # pxafb patch
        patch -p1 < %{PATCH25}
        ;;
      *) echo "Error: unknown kernel target: %{?KERNEL_TARGET}. Aborting."; exit 1 
         ;;
   esac
%endif

[ "$kernel_cfg" ] || {
   echo "Error: %{_target_cpu} target CPU is not supported. Aborting."  
   exit 1
}

# vesafb-tng patch
%patch17 -p1

# bt8xx patch
%patch18 -p1

# realtime lsm patch
%patch21 -p1
cp $kernel_cfg ./.config

# usb storage diiisable delay_use patch
%patch26 -p1
_EOF

%build
:<< _EOF
#
# build kernel for given target
#
sed -i 's@/usr/bin/env@/bin/env@' ./arch/ia64/scripts/unwcheck.py
ARCH=%{target_cpu} make oldconfig
cp Makefile Makefile.orig
sed -i "s/\(EXTRAVERSION =\).*/\1 %{?KERNEL_TARGET}/" Makefile
#  sed -i '
#     s/\(.*LINUX_COMPILE_BY \).*/\1"qilinux"/
#     s/\(.*LINUX_COMPILE_HOST \).*/\1"qilinux"/
#     s/\(.*LINUX_COMPILE_DOMAIN \).*/\1"qilinux.it"/' include/linux/compile.h
ARCH=%{target_cpu} make CROSS_COMPILE=%{_target_cpu}-qilinux-linux-gnu- %{?_smp_mflags} %{?DISTCC} all
_EOF

%install
[  "%{buildroot}" != / ] && rm -rf "%{buildroot}"

# create system dirs in install environment
install -d %{buildroot}{/usr/src/,/boot,%{_sysconfdir}/lilo.d/,%{_initrddir},/lib/modules}

ARCH=%{target_cpu} make modules_install INSTALL_MOD_PATH=%{buildroot} DEPMOD=%{DEPMOD}

(cd %{buildroot}/lib/modules/%{version}%{?KERNEL_TARGET}
rm -f build && ln -sf /usr/src/linux-%{version}%{?KERNEL_TARGET} build )

# copy modules to major directory location (e.g. 2.6.11) and create
# a symlink for the current 4 numbers release (e.g. 2.6.11.11) pointing to
# that dir
#if  [ "%{kernel_pl}" ]; then
#   mv %{buildroot}/lib/modules/%{version}%{?KERNEL_TARGET} %{buildroot}/lib/modules/%{kernel_ver}%{?KERNEL_TARGET}
#   ln -s %{kernel_ver}%{?KERNEL_TARGET} %{buildroot}/lib/modules/%{version}%{?KERNEL_TARGET}
#fi

cp %{KIMAGE} %{buildroot}/boot/%{KIMAGE_DEST}-%{version}%{?KERNEL_TARGET}

cp System.map %{buildroot}/boot/System.map-%{version}%{?KERNEL_TARGET}

# recreate kernel sources
cp -R %{_builddir}/%{name}-%{kernel_ver}%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM} %{buildroot}/usr/src/linux-%{version}%{?KERNEL_TARGET}

cd %{buildroot}/usr/src/linux-%{version}%{?KERNEL_TARGET}
make mrproper
%if %{_target_cpu} == i586
   case %{?KERNEL_TARGET} in
      geode) case %{?KERNEL_PLATFORM} in
               hurricane) kernel_cfg=%{SOURCE1} ;;
             esac ;;
   esac
%endif
%if %{_target_cpu} == arm
   case %{?KERNEL_TARGET} in
      pxa2xx)
        case %{?KERNEL_PLATFORM} in
            logicpd_pxa270) kernel_cfg=%{SOURCE2} 
                            ;;
            intel_dbpxa250) kernel_cfg=%{SOURCE3}
                            ;;
            mainstone) kernel_cfg=%{SOURCE4}
                            ;;
        esac 
      ;;
   esac
%endif

cp $kernel_cfg %{buildroot}/usr/src/linux-%{version}%{?KERNEL_TARGET}/.config
cp %{_builddir}/%{name}-%{kernel_ver}%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}/Module.symvers %{buildroot}/usr/src/linux-%{version}%{?KERNEL_TARGET}
ARCH=%{target_cpu} make oldconfig
#cp Makefile Makefile.orig
#sed -i "s/\(EXTRAVERSION =.*\)/\1%{?KERNEL_TARGET}/" Makefile 
%if "%{_target_platform}" == "%{_build}"
make prepare-all scripts
%endif
rm .config.old

#
# lilo configuration
#
cat > %{buildroot}%{_sysconfdir}/lilo.d/QiLinux-%{version}%{?KERNEL_TARGET}-%{release} <<EOF
image=/boot/%{KIMAGE_DEST}-%{version}%{?KERNEL_TARGET}
      label="qilinux-%{KERNEL_TARGET_SHORT}"
      root=
      initrd=/boot/initramfs-%{version}%{?KERNEL_TARGET}.img
      append="resume2= quiet splash=silent,theme:mamba console=tty1 video=vesafb:1024x768-32,ywrap,mtrr"
      read-only
EOF

#
# grub configuration
#
mkdir -p %{buildroot}%{_sysconfdir}/grub/conf.d
cat > %{buildroot}%{_sysconfdir}/grub/conf.d/QiLinux-%{version}%{?KERNEL_TARGET}-%{release} <<EOF
title QiLinux (kernel %{version}%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM})
root
kernel /boot/%{KIMAGE_DEST}-%{version}%{?KERNEL_TARGET} resume2= root= video=vesafb:1024x768-32,ywrap,mtrr quiet splash=silent,theme:mamba console=tty1
initrd /boot/initramfs-%{version}%{?KERNEL_TARGET}.img
EOF

# clean modules files created by depmod
rm -f %{buildroot}/lib/modules/%{version}%{?KERNEL_TARGET}/modules.*

# remove .tmp files if any
rm -f %{buildroot}%{_prefix}/src/linux-%{version}%{?KERNEL_TARGET}/.tmp* || true

# clean a wrong symlink
[ -L %{buildroot}%{_prefix}/src/linux-%{version}%{?KERNEL_TARGET}/arch/ppc/include/asm ] && \
{
   rm -f %{buildroot}%{_prefix}/src/linux-%{version}%{?KERNEL_TARGET}/arch/ppc/include/asm
   ln -sf ../../../include/asm %{buildroot}%{_prefix}/src/linux-%{version}%{?KERNEL_TARGET}/arch/ppc/include/asm
}

%clean
[  "%{buildroot}" != / ] && rm -rf "%{buildroot}"

%pre -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}
if [ $1 -gt 1 ]; then
   # update or downgrade
   %if "%{_target_cpu}" == "i586"
      [ -x /sbin/lilo-config ] &&
         /sbin/lilo-config -q --keep-default --del "QiLinux-%{?KERNEL_TARGET_SHORT}"
   %endif
   %if "%{_target_cpu}" == "ppc"
      /usr/sbin/ybin
   %endif
   :
fi
exit 0

%post -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}
# new install or upgrade
if [ $1 -ge 1 ]; then
   /sbin/depmod -A -F /boot/System.map-%{version}%{?KERNEL_TARGET} \
      %{version}%{?KERNEL_TARGET} &>/dev/null
   /sbin/mkinitramfs -f /boot/initramfs-%{version}%{?KERNEL_TARGET}.img %{version}%{?KERNEL_TARGET}

   swap=`grep swap /etc/fstab | awk '{ print $1 }'`
   [ "$swap" ] && {
      sed -i "s|resume2=|resume2=swap:$swap|" \
         %{_sysconfdir}/lilo.d/QiLinux-%{version}%{?KERNEL_TARGET}-%{release} \
         %{_sysconfdir}/grub/conf.d/QiLinux-%{version}%{?KERNEL_TARGET}-%{release}
   }
   %if "%{_target_cpu}" == "i586"
      if [ -x /sbin/lilo-config ]; then
         /sbin/lilo-config --killdevfs
         /sbin/lilo-config --add \
            %{_sysconfdir}/lilo.d/QiLinux-%{version}%{?KERNEL_TARGET}-%{release}
         /sbin/lilo
      fi
   %endif

   %if "%{_target_cpu}" == "ppc"
      /usr/sbin/ybin
   %endif
fi

if [ $1 -eq 0 ]; then
# uninstalling the rpm package
   %if "%{_target_cpu}" == "i586"
      if [ -x /sbin/lilo-config ]; then
         /sbin/lilo-config -q --del "qilinux-%{?KERNEL_TARGET_SHORT}"
         /sbin/lilo
      fi
   %endif
   :
fi
exit 0

%postun -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}
# erase this package
if [ $1 -eq 0 ]; then
   [ -f /boot/%{KIMAGE_DEST}-%{version}%{?KERNEL_TARGET} ] ||
      rm -f /boot/initramfs-%{version}%{?KERNEL_TARGET}.img
fi
exit 0


%posttrans -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}
# all done, now ring grub-update
%if "%{_target_cpu}" == "i586"
  if [ -x /usr/sbin/grub-update ]; then
     /usr/sbin/grub-update
  fi
%endif
exit 0

%post -n kernel-%{KERNEL_TARGET}-%{?KERNEL_PLATFORM}-source
# touch file so it results up-to-date on make
touch %{_prefix}/src/linux-%{version}%{?KERNEL_TARGET}/include/config/MARKER
exit 0

%files -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}
%defattr (-, root, root)
/boot/System.map-%{version}%{?KERNEL_TARGET}
/boot/%{KIMAGE_DEST}-%{version}%{?KERNEL_TARGET}
%{_sysconfdir}/lilo.d/QiLinux-%{version}%{?KERNEL_TARGET}-%{release}
%{_sysconfdir}/grub/conf.d/QiLinux-%{version}%{?KERNEL_TARGET}-%{release}

%files -n kernel-%{?KERNEL_TARGET}-%{?KERNEL_PLATFORM}-modules
%defattr (-, root, root)
%dir /lib/modules/%{version}%{?KERNEL_TARGET}
/lib/modules/%{kernel_ver}%{?KERNEL_TARGET}/*

%files -n kernel-%{KERNEL_TARGET}-%{?KERNEL_PLATFORM}-source
%defattr(-,root,root)
%dir /usr/src/linux-%{version}%{?KERNEL_TARGET}
/usr/src/linux-%{version}%{?KERNEL_TARGET}/*
/usr/src/linux-%{version}%{?KERNEL_TARGET}/.config

%changelog
* Mon Feb 05 2007 Silvan Calarco <silvan.calarco@...> 2.6.19-2.2qilnx
- update to 2.6.20

* Fri Feb 02 2007 Silvan Calarco <silvan.calarco@...> 2.6.19-2.2qilnx
- patch: remove usb storage detect timeout

* Sat Jan 13 2007 Silvan Calarco <silvan.calarco@...> 2.6.19-2.1qilnx
- update to 2.6.19.2
- add targets pxa2xx(logicpd_pxa270) and pxa2xx(intel_dbpxa255)

* Wed Nov 15 2006 Silvan Calarco <silvan.calarco@...> 2.6.18-2.1qilnx
- update to 2.6.18.2
- remove realtime-preempt patch

* Thu Oct 19 2006 Silvan Calarco <silvan.calarco@...> 2.6.18-1.2qilnx
- build a uniprocessor kernel

* Tue Oct 17 2006 Silvan Calarco <silvan.calarco@...> 2.6.18-1.1qilnx
- first embedded kernel build for the geode (hurricane) target