2 # Spec written for Tizen Mobile, some bits and pieces originate
3 # from MeeGo/Moblin/Fedora
6 %define upstream_version 3.14.14
8 %if !%{defined platform}
9 %define platform default
12 %define variant %{profile}-%{_arch}-%{platform}
13 %define kernel_version %{version}-%{release}
14 %define kernel_full_version %{version}-%{release}-%{variant}
15 %define arch_32bits i386 i586 i686 %{ix86}
17 # Default arch config for tizen per arch (unless overiden after)
18 %define kernel_image bzImage
19 %define defconfig tizen_defconfig
21 %define dtbs_supported 0
22 %define modules_supported 1
23 %define trace_supported 1
24 %define uboot_supported 0
25 %define vdso_supported 1
28 # Overide per configuration
30 %ifarch %{arch_32bits}
31 %define kernel_arch i386
32 %define kernel_arch_subdir arch/x86
33 %define defconfig %{profile}_x86_defconfig
37 %define kernel_arch x86_64
38 %define kernel_arch_subdir arch/x86
39 %define defconfig %{profile}_%{kernel_arch}_defconfig
43 %define kernel_arch arm
44 %define kernel_arch_subdir arch/%{kernel_arch}
45 %define kernel_image zImage
46 %define vdso_supported 0
47 %define modules_supported 0
55 URL: http://www.kernel.org/
56 Version: %{upstream_version}
58 # The below is used when we are on an -rc version
60 #%#define release_ver 0
61 #%#define rc_str %{?rc_num:0.rc%{rc_num}}%{!?rc_num:1}
62 #%if ! 0%{?opensuse_bs}
63 #Release: %{rc_str}.%{release_ver}.0.0
65 #Release: %{rc_str}.%{release_ver}.<CI_CNT>.<B_CNT>
69 BuildRequires: module-init-tools
70 BuildRequires: findutils
71 BuildRequires: libelf-devel
72 BuildRequires: binutils-devel
75 # net-tools provides the 'hostname' utility which kernel build wants
76 BuildRequires: net-tools
77 # The below is required for building perf
80 BuildRequires: libdw-devel
81 BuildRequires: python-devel
82 %if %{uboot_supported}
83 BuildRequires: u-boot-tools
86 ExclusiveArch: %{arch_32bits} x86_64 armv7l
88 Source0: %{name}-%{version}.tar.bz2
91 This package contains the Linux kernel for Tizen.
94 %package -n kernel-%{variant}
97 Provides: kernel-profile-%{profile} = %{version}-%{release}
98 Provides: kernel-uname-r = %{kernel_full_version}
99 Requires(post): /usr/bin/ln
100 Requires(post): /usr/bin/sort
103 # We use 'setup-scripts-bootloader-conf' in post and postun, so ideally we need to
104 # have the below here, but this causes gbs/obs build failures like this:
105 # "have choice for virtual-setup-scripts-bootloader needed by kernel-x86-scripts: setup-extlinux setup-gummiboot"
106 # The reason is that it will try to install the kernel to the build root, and
107 # fail with the above error. To fix it one would need to add 'setup-extlinux'
108 # or 'setup-gummiboot' to 'review.tizen.org/gerrit/scm/meta/build-config'. But
109 # it is probably not worth the trouble, so I commented out the below two lines.
111 #Requires(post): virtual-setup-scripts-bootloader
112 #Requires(postun): virtual-setup-scripts-bootloader
114 #Requires(post): setup-gummiboot
115 #Requires(postun): setup-gummiboot
117 Requires(post): /usr/sbin/depmod
118 Requires(post): /usr/bin/dracut
119 Requires(post): /usr/bin/kmod
121 Requires(postun): /usr/bin/ln
122 Requires(postun): /usr/bin/sed
123 Requires(postun): rpm
125 # We can't let RPM do the dependencies automatic because it'll then pick up
126 # a correct but undesirable perl dependency from the module headers which
127 # isn't required for the kernel proper to function
131 %description -n kernel-%{variant}
132 This package contains the Linux kernel for Tizen (%{profile} profile, architecure %{_arch})
134 %package -n kernel-%{variant}-devel
135 Summary: Development package for building kernel modules
136 Group: Development/System
137 Provides: kernel-devel = %{kernel_full_version}
138 Provides: kernel-devel-uname-r = %{kernel_full_version}
139 Requires(post): /usr/bin/find
140 Requires: %{name} = %{version}-%{release}
143 %description -n kernel-%{variant}-devel
144 This package provides kernel headers and makefiles sufficient to build modules
145 against the %{variant} kernel package.
149 Summary: The 'perf' performance counter tool
151 Provides: perf = %{kernel_full_version}
152 Requires: %{name} = %{version}-%{release}
155 This package provides the "perf" tool that can be used to monitor performance
156 counter events as well as various kernel internal events.
164 # Unpack the kernel tarball
165 %setup -q -n %{name}-%{version}
173 # Make sure EXTRAVERSION says what we want it to say
174 sed -i "s/^EXTRAVERSION.*/EXTRAVERSION = -%{release}-%{variant}/" Makefile
177 make -s -C tools/lib/traceevent ARCH=%{kernel_arch} %{?_smp_mflags}
178 make -s -C tools/perf WERROR=0 ARCH=%{kernel_arch}
180 %if %{defined loadaddr}
181 export LOADADDR=%{loadaddr}
184 # Build kernel and modules
185 make -s ARCH=%{kernel_arch} %{defconfig}
186 make %{?_smp_mflags} %{kernel_image} ARCH=%{kernel_arch}
188 %if %modules_supported
189 make -s ARCH=%{kernel_arch} %{?_smp_mflags} modules
193 make -s ARCH=%{kernel_arch} %{?_smp_mflags} dtbs
202 install -d %{buildroot}/boot
204 install -m 644 .config %{buildroot}/boot/config-%{kernel_full_version}
205 install -m 644 System.map %{buildroot}/boot/System.map-%{kernel_full_version}
206 install -m 755 %{kernel_arch_subdir}/boot/%{kernel_image} %{buildroot}/boot/vmlinuz-%{kernel_full_version}
207 # Dummy initrd, will not be included in the actual package but needed for files
208 touch %{buildroot}/boot/initrd-%{kernel_full_version}.img
210 %if %modules_supported
211 make -s ARCH=%{kernel_arch} INSTALL_MOD_PATH=%{buildroot} modules_install KERNELRELEASE=%{kernel_full_version}
215 make -s ARCH=%{kernel_arch} INSTALL_MOD_PATH=%{buildroot} vdso_install KERNELRELEASE=%{kernel_full_version}
219 install -d "%{buildroot}/boot/"
220 find "arch/%{kernel_arch}/" -iname "*.dtb" -exec install "{}" "%{buildroot}/boot/" \;
223 rm -rf %{buildroot}/lib/firmware
225 # And save the headers/makefiles etc for building modules against
227 # This all looks scary, but the end result is supposed to be:
228 # * all arch relevant include/ files
229 # * all Makefile/Kconfig files
230 # * all script/ files
232 # Remove existing build/source links and create pristine dirs
233 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/build
234 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/source
235 install -d %{buildroot}/lib/modules/%{kernel_full_version}/build
236 ln -fs build %{buildroot}/lib/modules/%{kernel_full_version}/source
239 # First, copy all dirs containing Makefile of Kconfig files
240 cp --parents `find -type f -name "Makefile*" -o -name "Kconfig*"` %{buildroot}/lib/modules/%{kernel_full_version}/build
241 install Module.symvers %{buildroot}/lib/modules/%{kernel_full_version}/build/
242 install System.map %{buildroot}/lib/modules/%{kernel_full_version}/build/
244 # Then, drop all but the needed Makefiles/Kconfig files
245 rm -rf %{buildroot}/lib/modules/%{kernel_full_version}/build/Documentation
246 rm -rf %{buildroot}/lib/modules/%{kernel_full_version}/build/scripts
247 rm -rf %{buildroot}/lib/modules/%{kernel_full_version}/build/include
249 # Copy config and scripts
250 install .config %{buildroot}/lib/modules/%{kernel_full_version}/build/
251 cp -a scripts %{buildroot}/lib/modules/%{kernel_full_version}/build
252 if [ -d %{kernel_arch_subdir}/scripts ]; then
253 cp -a %{kernel_arch_subdir}/scripts %{buildroot}/lib/modules/%{kernel_full_version}/build/%{kernel_arch_subdir}/ || :
255 if [ -f %{kernel_arch_subdir}/*lds ]; then
256 cp -a %{kernel_arch_subdir}/*lds %{buildroot}/lib/modules/%{kernel_full_version}/build/%{kernel_arch_subdir}/ || :
258 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/build/scripts/*.o
259 rm -f %{buildroot}/lib/modules/%{kernel_full_version}/build/scripts/*/*.o
260 cp -a --parents %{kernel_arch_subdir}/include %{buildroot}/lib/modules/%{kernel_full_version}/build
263 mkdir -p %{buildroot}/lib/modules/%{kernel_full_version}/build/include
264 find include/ -mindepth 1 -maxdepth 1 -type d | xargs -I{} cp -a {} %{buildroot}/lib/modules/%{kernel_full_version}/build/include
266 # Save the vmlinux file for kernel debugging into the devel package
267 cp vmlinux %{buildroot}/lib/modules/%{kernel_full_version}
269 # Mark modules executable so that strip-to-file can strip them
270 find %{buildroot}/lib/modules/%{kernel_full_version} -name "*.ko" -type f | xargs --no-run-if-empty chmod 755
272 # Move the devel headers out of the root file system
273 install -d %{buildroot}/usr/src/kernels
274 mv %{buildroot}/lib/modules/%{kernel_full_version}/build %{buildroot}/usr/src/kernels/%{kernel_full_version}
276 ln -sf /usr/src/kernels/%{kernel_full_version} %{buildroot}/lib/modules/%{kernel_full_version}/build
279 install -d %{buildroot}
280 make -s -C tools/perf DESTDIR=%{buildroot} install
281 install -d %{buildroot}%{_bindir}
282 install -d %{buildroot}%{_libexecdir}
283 mv %{buildroot}/bin/* %{buildroot}%{_bindir}
284 mv %{buildroot}/libexec/* %{buildroot}%{_libexecdir}
285 rm %{buildroot}/etc/bash_completion.d/perf
287 # Dont package debug files
288 rm -rf %{buildroot}/usr/lib/debug/.build-id
289 rm -rf %{buildroot}/usr/lib/debug/lib/traceevent/plugins/*.debug
297 %post -n kernel-%{variant}
298 if [ -f "/boot/loader/loader.conf" ]; then
299 # EFI boot with gummiboot
300 INSTALLERFW_MOUNT_PREFIX="/" /usr/sbin/setup-scripts-gummiboot-conf
301 # "/etc/installerfw-environment" does not exist in MIC environment, when it
302 # builds the image. MIC will add boot-loader entries later using the
303 # 'setup-scripts-boot' script.
304 if [ -f "/etc/installerfw-environment" ] && \
305 [ -x "/usr/sbin/setup-scripts-bootloader-conf" ]; then
306 /usr/sbin/setup-scripts-bootloader-conf add -f vmlinuz-%{kernel_full_version}
307 /usr/sbin/setup-scripts-bootloader-conf default -f vmlinuz-%{kernel_full_version}
311 last_installed_ver="$(rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant} | sort -r | sed -e 's/[^:]*: \(.*\)/\1/g' | sed -n -e "1p")"
312 ln -sf vmlinuz-$last_installed_ver-%{variant} /boot/vmlinuz
314 if [ -z "$last_installed_ver" ]; then
315 # Something went wrong, print some diagnostics
316 printf "%s\n" "Error: cannot find kernel version" 1>&2
317 printf "%s\n" "The command was: rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant} | sort -r | sed -e 's/[^:]*: \(.*\)/\1/g' | sed -n -e \"1p\"" 1>&2
318 printf "%s\n" "Output of the \"rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant}\" is:" 1>&2
319 result="$(rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant})"
320 printf "%s\n" "$result" 1>&2
324 %{_bindir}/dracut /boot/initrd-%{kernel_full_version}.img %{kernel_full_version}
326 %post -n kernel-%{variant}-devel
327 if [ -x /usr/sbin/hardlink ]; then
328 cd /usr/src/kernels/%{kernel_full_version}
329 /usr/bin/find . -type f | while read f; do
330 hardlink -c /usr/src/kernels/*/$f $f
334 %postun -n kernel-%{variant}
335 if [ -f "/boot/loader/loader.conf" ]; then
336 # EFI boot with gummiboot
337 INSTALLERFW_MOUNT_PREFIX="/" /usr/sbin/setup-scripts-gummiboot-conf
338 if [ -f "/etc/installerfw-environment" ] && \
339 [ -x "/usr/sbin/setup-scripts-bootloader-conf" ]; then
340 /usr/sbin/setup-scripts-bootloader-conf remove -f vmlinuz-%{kernel_full_version}
344 last_installed_ver="$(rpm -q --qf '%{INSTALLTIME}: %{VERSION}-%{RELEASE}\n' kernel-%{variant} | sort -r | sed -e 's/[^:]*: \(.*\)/\1/g' | sed -n -e "1p")"
345 if [ -n "$last_installed_ver" ]; then
346 ln -sf vmlinuz-$last_installed_ver-%{variant} /boot/vmlinuz
357 %files -n kernel-%{variant}
359 /boot/vmlinuz-%{kernel_full_version}
360 /boot/System.map-%{kernel_full_version}
361 /boot/config-%{kernel_full_version}
362 %if %modules_supported
363 %dir /lib/modules/%{kernel_full_version}
364 /lib/modules/%{kernel_full_version}/kernel
365 /lib/modules/%{kernel_full_version}/modules.*
367 /lib/modules/%{kernel_full_version}/build
368 /lib/modules/%{kernel_full_version}/source
371 /lib/modules/%{kernel_full_version}/vdso
376 %ghost /boot/initrd-%{kernel_full_version}.img
379 %files -n kernel-%{variant}-devel
381 %verify(not mtime) /usr/src/kernels/%{kernel_full_version}
382 /lib/modules/%{kernel_full_version}/vmlinux
388 %{_libexecdir}/perf-core
391 /%{_lib}/traceevent/plugins/*.so