Magellan Linux

Contents of /trunk/include/kernel.sminc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 30422 - (show annotations) (download)
Fri Jan 19 09:04:36 2018 UTC (6 years, 9 months ago) by niro
File size: 14904 byte(s)
-always use dracut
1 # kernel global smage functions
2 # $Id$
3
4 # needed extra vars:
5 # ${KERNEL_TYPE}: needed, 'sources', 'headers' or 'image'
6 # ${BRANCH}: needed, style branch of the kernel
7 # ${KERNEL_CONFIG}: optional, needed if you want to override the default
8 # searchpath ${SOURCEDIR}/${PNAME}/config-${PVER}-${BRANCH}-${PBUILD}
9 #
10 # ${PSUBVER}: optional, only needed for 2.6.x.x naming scheme
11 # ${EXTRAVERSION}: optinal, extra version for the kernel name
12 # default setting is ${PSUBVER}-${BRANCH}-${PBUILD}
13 # ${KERNEL_IMAGE_PATH}: override the default KERNEL_IMAGE_PATH (to build xen images for e.g.)
14 # ${COMPRESS_MODULES}: compresses the kernel modules with given compressor (gzip|bzip2|xz)
15 # ${LINUX_FIRMWARE}: remove included firmware bits if requested
16 # set the version here like USE_LINUX_FIRMARE="20110605"
17 # version "internal" keeps the bits too
18 #
19 # ${INCLUDE_KERNELVERSION_FILE}: creates a /boot/kernelversion file (deprecated)
20 # ${USE_KERNEL_SYMLINKS}: creates symlinks to unversioned kernel image files
21 # - kernel-x.x.x.x -> /boot/vmlinuz
22 # - initrd-x.x.x.x -> /boot/initrd
23 # - config-x.x.x.x -> /boot/config
24 # - System.map-x.x.x.x -> /boot/System.map
25
26 sminclude mtools
27
28 # remove me when all distris support this:
29 if [[ ${USE_KERNEL_ARCH_EXTENSION} = true ]]
30 then
31 KERNEL_ARCH_EXTENSION="-${ARCH}"
32 else
33 KERNEL_ARCH_EXTENSION=""
34 fi
35
36 if [[ ! -z ${COMPRESS_MODULES} ]]
37 then
38 case ${COMPRESS_MODULES} in
39 gzip)
40 COMPRESS_MODULES_CMD="gzip -9v"
41 SDEPEND="${SDEPEND}
42 >= app-arch/gzip-1.4"
43 ;;
44 bzip2)
45 COMPRESS_MODULES_CMD="bzip2 -9v"
46 SDEPEND="${SDEPEND}
47 >= app-arch/bzip2-1.0.6"
48 ;;
49 xz)
50 COMPRESS_MODULES_CMD="xz -9v"
51 SDEPEND="${SDEPEND}
52 >= app-arch/xz-5"
53 ;;
54 none)
55 echo "Disabled compressed kernel-modules!"
56 COMPRESS_MODULES_CMD=""
57 ;;
58 *) die "Unkown compression format '${COMPRESS_MODULES}'" ;;
59 esac
60 fi
61
62 # some sane defaults
63 : ${PCAT="sys-kernel"}
64 : ${HOMEPAGE="http://magellan-linux.de/"}
65 : ${TARBALLPVER="${PVER}"}
66 : ${SRCFILE="linux-${TARBALLPVER}.tar.xz"}
67 : ${SRCDIR="${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}"}
68
69 if [[ -z ${SRC_URI[*]} ]]
70 then
71 SRC_URI=(
72 http://www.kernel.org/pub/linux/kernel/v$(echo ${PVER} | cut -d. -f1).x/${SRCFILE}
73 http://ftp.uni-erlangen.de/pub/Linux/MIRROR.kernel/v$(echo ${PVER} | cut -d. -f1).x/${SRCFILE}
74 mirror://kernel-${BRANCH}/${SRCFILE}
75 )
76 case ${KERNEL_TYPE} in
77 image|sources)
78 SRC_URI=(
79 ${SRC_URI[*]}
80 mirror://kernel-${BRANCH}/config-${PVER}-${BRANCH}-${PBUILD}-i686
81 mirror://kernel-${BRANCH}/config-${PVER}-${BRANCH}-${PBUILD}-x86_64
82 )
83 ;;
84 esac
85 fi
86
87 case ${PNAME} in
88 *-lts) _upparam="longterm" ;;
89 *) _upparam="stable" ;;
90 esac
91
92 UP2DATE="updatecmd http://www.kernel.org/ | grep -A1 -i '${_upparam}:' | sed 's/.*:\ \([0-9]\.[0-9].*\)\ [0-9].*/\1/;q'"
93
94 case ${KERNEL_TYPE} in
95 image)
96 : ${PROVIDE="virtual/kernel"}
97 : ${DEPEND=">= virtual/module-tools
98 >= sys-fs/udev-115
99 >= sys-apps/grubby-8.29-r1
100 >= virtual/initramfs-tools
101 >= virtual/initscripts"}
102 if [[ ! -z ${LINUX_FIRMWARE} ]] && [[ ${LINUX_FIRMWARE} != internal ]]
103 then
104 DEPEND="${DEPEND}
105 >= sys-kernel/linux-firmware-${LINUX_FIRMWARE}"
106 fi
107 SDEPEND="${SDEPEND}
108 >= sys-dev/bc-1.06"
109 : ${DESCRIPTION="Kernel image of the '${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}' kernel branch."}
110 ;;
111
112 sources)
113 : ${PROVIDE="virtual/kernel-sources"}
114 : ${DESCRIPTION="Kernel sources of the '${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}' kernel branch."}
115 ;;
116
117 headers)
118 : ${PROVIDE="virtual/kernel-headers"}
119 : ${DESCRIPTION="Sanitized kernel headers for libc."}
120 ;;
121 esac
122
123 EXTRAVERSION="${PSUBVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}"
124 KERNEL_CONFIG="${SOURCEDIR}/${PNAME}/config-${PVER}-${BRANCH}-${PBUILD}-${ARCH}"
125
126 # special vars for mage file only
127 KPVER="${PVER}"
128 KPBUILD="${PBUILD}"
129 KBRANCH="${BRANCH}"
130 SPECIAL_VARS="${SPECIAL_VARS} KPVER KPBUILD KBRANCH USE_KERNEL_SYMLINKS"
131
132 # dummy function to apply kernel patches
133 kernel_apply_patches()
134 {
135 return 0
136 }
137
138 kernel_src_prepare()
139 {
140 munpack ${SRCFILE} || die
141 mv ${BUILDDIR}/linux-${TARBALLPVER} ${SRCDIR} || die
142
143 # fix permissions
144 chown -R 0:0 ${SRCDIR} || die
145 chmod -R a+r-w+X,u+w ${SRCDIR} || die
146
147 cd ${SRCDIR}
148 kernel_apply_patches || die
149
150 # fix permissions after the patchwork
151 # gnu patch doesn't support git-style file mode
152 if [ -e tools/objtool/sync-check.sh ]
153 then
154 chmod +x tools/objtool/sync-check.sh || die
155 fi
156
157 # fixes INSTALL_PATH to /boot and EXTRAVERSION
158 sed -i -e 's:#export\tINSTALL_PATH:export\tINSTALL_PATH:' \
159 -e "s:^\(EXTRAVERSION =\).*:\1 ${EXTRAVERSION}:" Makefile || die
160
161 # fix sublevel version with 3.x kernels and higher
162 local kver=$(echo ${PVER} | sed "s:\.::g")
163 if [[ ${PVER%%.*} -gt 2 ]]
164 then
165 local sublevel="$(echo ${PVER} | cut -d. -f3)"
166 sed -i "s:^\(SUBLEVEL =\).*:\1 ${sublevel}:" Makefile || die
167 fi
168 }
169
170 kernel_src_compile()
171 {
172 cd ${SRCDIR}
173
174 make mrproper || die
175
176 if [[ ${KERNEL_TYPE} = sources ]] || [[ ${KERNEL_TYPE} = image ]]
177 then
178 # inject our kernel config
179 cp ${KERNEL_CONFIG} ${SRCDIR}/.config || die
180 make ARCH=${ARCH/i*86/x86} oldconfig || die
181 fi
182
183 case ${KERNEL_TYPE} in
184 image)
185 mmake ARCH=${ARCH/i*86/x86} || die
186 ;;
187
188 headers)
189 make ARCH=${ARCH/i*86/x86} headers_check || die
190 ;;
191
192 sources)
193 make clean || die
194
195 # needed to compile other programs like iptables
196 make ARCH=${ARCH/i*86/x86} prepare || die
197 # needed to cover >=2.6.14 builds
198 # but deprecated with >=2.6.21, prepare cover all targets there
199 local kver=$(echo ${PVER} | sed "s:\.::g")
200 # honor >=3.0.x; add one zero
201 if [[ ${PVER%%.*} -gt 2 ]]
202 then
203 kver="${kver}0"
204 fi
205 if [[ ${kver} < 2621 ]]
206 then
207 make ARCH=${ARCH/i*86/x86} prepare-all || die
208 fi
209 make ARCH=${ARCH/i*86/x86} scripts || die
210
211 # at least alsa-drivers needs this one ...
212 touch include/linux/autoconf.h || die
213
214 # compat symlink for 3.7.x new version.h location until everything is fixed
215 ;;
216 esac
217 }
218
219 kernel_image_src_install()
220 {
221 cd ${SRCDIR}
222
223 # needed directories
224 minstalldir /boot || die
225
226 # install modules
227 make ARCH=${ARCH/i*86/x86} INSTALL_MOD_PATH=${BINDIR}/usr modules_install || die
228
229 # install kernelimage
230 if [[ -z ${KERNEL_IMAGE_PATH} ]]
231 then
232 local my_arch="${ARCH}"
233 [[ ${my_arch} = i*86 ]] && my_arch=i386
234 minstallfile arch/${my_arch}/boot/bzImage \
235 /boot/kernel-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
236 || die
237 else
238 minstallfile ${KERNEL_IMAGE_PATH} \
239 /boot/kernel-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
240 || die
241 fi
242
243 # install System.map
244 minstallfile System.map \
245 /boot/System.map-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
246 || die
247
248 # install Module.symvers in boot and /usr/src
249 minstallfile Module.symvers \
250 /boot/Module.symvers-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
251 || die
252 minstalldir /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} || die
253 minstallfile Module.symvers \
254 /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} \
255 || die
256
257 if [[ ${INCLUDE_KERNELVERSION_FILE} = true ]]
258 then
259 MCONFIG=/boot/kernelversion
260 # install kernel description
261 mclearconfig || die
262 maddconfig "KRNVER=${BRANCH}-${PVER}-${ARCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}" || die
263 maddconfig "KRNLIB=${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}" || die
264 maddconfig "KRNIMG=kernel-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}" || die
265 maddconfig "KRNINITRD=" || die
266 fi
267
268 # install kernel-config from srcdir
269 minstallfile .config \
270 /boot/config-${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION} \
271 || die
272
273 # fix build symlink
274 if [ -L ${BINDIR}/usr/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/build ]
275 then
276 echo "fixing build symlink"
277 rm ${BINDIR}/usr/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/build || die
278 mlink /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} \
279 /usr/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/build \
280 || die
281 fi
282
283 # and fixing source symlink
284 if [ -L ${BINDIR}/usr/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/source ]
285 then
286 echo "fixing source symlink"
287 rm ${BINDIR}/usr/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/source || die
288 mlink /usr/src/linux-${PVER}-${BRANCH}-${PBUILD} \
289 /usr/lib/modules/${PVER}-${BRANCH}-${PBUILD}${KERNEL_ARCH_EXTENSION}/source \
290 || die
291 fi
292
293 # remove firmware bits if $LINUX_FIRMWARE was set
294 if [[ ! -z ${LINUX_FIRMWARE} ]] && [[ ${LINUX_FIRMWARE} != internal ]]
295 then
296 if [[ -d ${BINDIR}/usr/lib/firmware ]]
297 then
298 rm -rv ${BINDIR}/usr/lib/firmware
299 fi
300 fi
301
302 # compress modules if COMPRESS_MODULES_CMD was set
303 if [[ ! -z ${COMPRESS_MODULES_CMD} ]]
304 then
305 # compress all kernel modules
306 find ${BINDIR} -name \*.ko | xargs ${COMPRESS_MODULES_CMD} || die
307 fi
308 }
309
310 kernel_headers_src_install()
311 {
312 cd ${SRCDIR}
313 make ARCH=${ARCH/i*86/x86} INSTALL_HDR_PATH=${BINDIR}/usr headers_install || die
314
315 # clean-up unnecessary files
316 find ${BINDIR} -name .install -or -name ..install.cmd | xargs --no-run-if-empty rm -f
317 }
318
319 kernel_sources_src_install()
320 {
321 cd ${BUILDDIR}
322
323 echo "Creating linux-${PVER}-${BRANCH}-${PBUILD} sources tarball ... "
324 tar cvjf ${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 $(basename ${SRCDIR}) || die
325
326 echo "Moving linux-${PVER}-${BRANCH}-${PBUILD} tarball to \${BINDIR}/usr/src ... "
327 minstalldir /usr/src || die
328 mv ${BUILDDIR}/linux-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 ${BINDIR}/usr/src || die
329 }
330
331 # installs module-sources path/to/SRCDIR to MODDIR/MODNAME
332 # kernel_external_modules_install path/to/SRCDIR DESTDIRNAME
333 kernel_external_modules_install()
334 {
335 cd ${BUILDDIR}
336
337 local modsrc="$1"
338 local moddest="$2"
339 local moddir="${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}"
340
341 echo "Installing ${modsrc} to ${moddir}/${moddest} ..."
342 install -d ${moddir} || die
343 mv ${modsrc} ${moddir}/${moddest} || die
344 }
345
346 kernel_external_modules_tarball()
347 {
348 cd ${BUILDDIR}
349
350 echo "Creating kernel-modules-${PVER}-${BRANCH}-${PBUILD} sources tarball ... "
351 tar cvjf ${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 \
352 kernel-modules-${PVER}-${BRANCH}-${PBUILD} || die
353
354 echo "Moving kernel-modules-${PVER}-${BRANCH}-${PBUILD} tarball to \${BINDIR}/usr/src ... "
355 minstalldir /usr/src || die
356 mv ${BUILDDIR}/kernel-modules-${PVER}-${BRANCH}-${PBUILD}.tar.bz2 ${BINDIR}/usr/src || die
357 }
358
359 kernel_src_install()
360 {
361 case ${KERNEL_TYPE} in
362 image)
363 kernel_image_src_install || die
364 ;;
365
366 headers)
367 kernel_headers_src_install || die
368 ;;
369
370 sources)
371 kernel_sources_src_install || die
372 ;;
373 esac
374 }
375
376 kernel_major_version()
377 {
378 local ksrc="$@"
379 local kv
380
381 if [[ -z ${ksrc} ]]
382 then
383 kv="$(uname -r|cut -d. -f1-2)"
384 else
385 local version
386 local patchlevel
387
388 # get version from makefile
389 version=$(grep "^VERSION[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
390 # get patchlevel from makefile
391 patchlevel=$(grep "^PATCHLEVEL[[:space:]]*=[[:space:]]*[[:digit:]]" ${ksrc}/Makefile | sed "s/^.*=[[:space:]]*\([[:digit:]]\+\)/\1/g")
392 # kernelversion
393 kv="${version}.${patchlevel}"
394 fi
395
396 echo "${kv}"
397 }
398
399 mod_suffix()
400 {
401 local ksrc="$@"
402 local mod_suffix
403 local kmv
404
405 kmv=$(kernel_major_version ${ksrc})
406 if [[ ${kmv//.} -ge 26 ]]
407 then
408 mod_suffix="ko"
409 else
410 mod_suffix="o"
411 fi
412
413 echo ${mod_suffix}
414 }
415
416 kernel_image_preinstall()
417 {
418 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
419 then
420 mount /boot &> /dev/null
421 fi
422 }
423
424 kernel_image_preremove()
425 {
426 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
427 then
428 mount /boot &> /dev/null
429
430 # remove old image entry from grub
431 new-kernel-pkg -v --rminitrd --rmmoddep --remove ${KPVER}-${KBRANCH}-${KPBUILD}
432 fi
433 }
434
435 kernel_image_postinstall()
436 {
437 [ ! -d ${MROOT}/sys ] && install -d ${MROOT}/sys
438
439 # fixes a small glitch in <=mage-0.3.6-r15 with symlinks
440 [ -f ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD} ] && \
441 rm ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}
442
443 [ -x ${MROOT}/sbin/depmod ] &&
444 ${MROOT}/sbin/depmod -ae \
445 -F /boot/System.map-${KPVER}-${KBRANCH}-${KPBUILD} \
446 ${KPVER}-${KBRANCH}-${KPBUILD}
447
448 # do not run this if ${MROOT} is set !
449 if [[ -z ${MROOT} ]] || [[ ${MROOT} = / ]]
450 then
451 new-kernel-pkg -v --mkinitrd --dracut --make-default --install ${KPVER}-${KBRANCH}-${KPBUILD}
452 fi
453
454 if [[ ${USE_KERNEL_SYMLINKS} = true ]]
455 then
456 # symlink actual kernel to /boot/vmlinuz etc...
457 ln -snf kernel-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/vmlinuz
458 ln -snf System.map-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/System.map
459 ln -snf config-${KPVER}-${KBRANCH}-${KPBUILD} ${MROOT}/boot/config
460 [[ -f ${MROOT}/boot/initrd-${KPVER}-${KBRANCH}-${KPBUILD}.img ]] &&
461 ln -snf initrd-${KPVER}-${KBRANCH}-${KPBUILD}.img ${MROOT}/boot/initrd
462 fi
463 }
464
465 kernel_sources_postinstall()
466 {
467 # check for linux-VERSION/include as the kernel-image installs
468 # the file Modules.symver in the linux-VERSION directory
469 if mqueryfeature "kernelsrcunpack" &&
470 [ ! -d ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}/include ]
471 then
472 echo "Unpacking linux-${KPVER}-${KBRANCH}-${KPBUILD} source tarball ... "
473 tar xvjf ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 -C ${MROOT}/usr/src
474 fi
475
476 if mqueryfeature "kernelsrcunpack" &&
477 [ ! -d ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} ] &&
478 [ -f ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 ]
479 then
480 echo "Unpacking kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} source tarball ... "
481 tar xvjf ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD}.tar.bz2 -C ${MROOT}/usr/src
482 fi
483
484 # create linux symlink
485 if mqueryfeature "linuxsymlink"
486 then
487 echo "Creating linux -> linux-${KPVER}-${KBRANCH}-${KPBUILD} symlink ... "
488 [ ! -d ${MROOT}/usr/src ] && install ${MROOT}/usr/src
489 ln -snf ${MROOT}/usr/src/linux-${KPVER}-${KBRANCH}-${KPBUILD} \
490 ${MROOT}/usr/src/linux || die
491 fi
492
493 # create kernel-modules symlink
494 if mqueryfeature "linuxsymlink" &&
495 [ -d ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} ]
496 then
497 echo "Creating kernel-modules -> kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} symlink ... "
498 [ ! -d ${MROOT}/usr/src ] && install ${MROOT}/usr/src
499 ln -snf ${MROOT}/usr/src/kernel-modules-${KPVER}-${KBRANCH}-${KPBUILD} \
500 ${MROOT}/usr/src/kernel-modules || die
501 fi
502 }
503
504 export_inherits kernel src_prepare src_compile src_install
505
506 # export pre/postinstall functions depending on KERNEL_TYPE
507 case ${KERNEL_TYPE} in
508 image)
509 export_inherits kernel_image preinstall preremove postinstall
510 SPECIAL_FUNCTIONS="${SPECIAL_FUNCTIONS} kernel_image_preinstall kernel_image_preremove kernel_image_postinstall"
511 ;;
512 sources)
513 export_inherits kernel_sources postinstall
514 SPECIAL_FUNCTIONS="${SPECIAL_FUNCTIONS} kernel_sources_postinstall"
515 ;;
516 esac