kernel.bbclass 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. inherit linux-kernel-base module_strip
  2. PROVIDES += "virtual/kernel"
  3. DEPENDS += "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}depmod-${@get_kernelmajorversion('${PV}')} virtual/${TARGET_PREFIX}gcc${KERNEL_CCSUFFIX} update-modules"
  4. # we include gcc above, we dont need virtual/libc
  5. INHIBIT_DEFAULT_DEPS = "1"
  6. KERNEL_IMAGETYPE ?= "zImage"
  7. python __anonymous () {
  8. kerneltype = bb.data.getVar('KERNEL_IMAGETYPE', d, 1) or ''
  9. if kerneltype == 'uImage':
  10. depends = bb.data.getVar("DEPENDS", d, 1)
  11. depends = "%s u-boot-mkimage-native" % depends
  12. bb.data.setVar("DEPENDS", depends, d)
  13. image = bb.data.getVar('INITRAMFS_IMAGE', d, True)
  14. if image != '' and image is not None:
  15. bb.data.setVar('INITRAMFS_TASK', '${INITRAMFS_IMAGE}:do_rootfs', d)
  16. machine_kernel_pr = bb.data.getVar('MACHINE_KERNEL_PR', d, True)
  17. if machine_kernel_pr:
  18. bb.data.setVar('PR', machine_kernel_pr, d)
  19. }
  20. INITRAMFS_IMAGE ?= ""
  21. INITRAMFS_TASK ?= ""
  22. inherit kernel-arch deploy
  23. PACKAGES_DYNAMIC += "kernel-module-*"
  24. PACKAGES_DYNAMIC += "kernel-image-*"
  25. PACKAGES_DYNAMIC += "kernel-firmware-*"
  26. export OS = "${TARGET_OS}"
  27. export CROSS_COMPILE = "${TARGET_PREFIX}"
  28. KERNEL_PRIORITY = "${@bb.data.getVar('PV',d,1).split('-')[0].split('.')[-1]}"
  29. KERNEL_RELEASE ?= "${KERNEL_VERSION}"
  30. KERNEL_CCSUFFIX ?= ""
  31. KERNEL_LDSUFFIX ?= ""
  32. # Set TARGET_??_KERNEL_ARCH in the machine .conf to set architecture
  33. # specific options necessary for building the kernel and modules.
  34. #FIXME: should be this: TARGET_CC_KERNEL_ARCH ?= "${TARGET_CC_ARCH}"
  35. TARGET_CC_KERNEL_ARCH ?= ""
  36. HOST_CC_KERNEL_ARCH ?= "${TARGET_CC_KERNEL_ARCH}"
  37. TARGET_LD_KERNEL_ARCH ?= ""
  38. HOST_LD_KERNEL_ARCH ?= "${TARGET_LD_KERNEL_ARCH}"
  39. KERNEL_CC = "${CCACHE}${HOST_PREFIX}gcc${KERNEL_CCSUFFIX} ${HOST_CC_KERNEL_ARCH}${TOOLCHAIN_OPTIONS}"
  40. KERNEL_LD = "${LD}${KERNEL_LDSUFFIX} ${HOST_LD_KERNEL_ARCH}${TOOLCHAIN_OPTIONS}"
  41. # Where built kernel lies in the kernel tree
  42. KERNEL_OUTPUT ?= "arch/${ARCH}/boot/${KERNEL_IMAGETYPE}"
  43. KERNEL_IMAGEDEST = "boot"
  44. #
  45. # configuration
  46. #
  47. export CMDLINE_CONSOLE = "console=${@bb.data.getVar("KERNEL_CONSOLE",d,1) or "ttyS0"}"
  48. KERNEL_VERSION = "${@get_kernelversion('${B}')}"
  49. KERNEL_MAJOR_VERSION = "${@get_kernelmajorversion('${KERNEL_VERSION}')}"
  50. KERNEL_LOCALVERSION ?= ""
  51. # kernels are generally machine specific
  52. PACKAGE_ARCH = "${MACHINE_ARCH}"
  53. # U-Boot support
  54. UBOOT_ENTRYPOINT ?= "20008000"
  55. UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
  56. # For the kernel, we don't want the '-e MAKEFLAGS=' in EXTRA_OEMAKE.
  57. # We don't want to override kernel Makefile variables from the environment
  58. EXTRA_OEMAKE = ""
  59. KERNEL_ALT_IMAGETYPE ??= ""
  60. kernel_do_compile() {
  61. unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
  62. oe_runmake include/linux/version.h CC="${KERNEL_CC}" LD="${KERNEL_LD}"
  63. if [ "${KERNEL_MAJOR_VERSION}" != "2.6" ]; then
  64. oe_runmake dep CC="${KERNEL_CC}" LD="${KERNEL_LD}"
  65. fi
  66. oe_runmake ${KERNEL_IMAGETYPE} ${KERNEL_ALT_IMAGETYPE} CC="${KERNEL_CC}" LD="${KERNEL_LD}"
  67. }
  68. do_compile_kernelmodules() {
  69. unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
  70. if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
  71. oe_runmake modules CC="${KERNEL_CC}" LD="${KERNEL_LD}"
  72. else
  73. oenote "no modules to compile"
  74. fi
  75. }
  76. addtask compile_kernelmodules after do_compile before do_install
  77. kernel_do_install() {
  78. #
  79. # First install the modules
  80. #
  81. unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
  82. if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
  83. oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install
  84. else
  85. oenote "no modules to install"
  86. fi
  87. #
  88. # Install various kernel output (zImage, map file, config, module support files)
  89. #
  90. install -d ${D}/${KERNEL_IMAGEDEST}
  91. install -d ${D}/boot
  92. install -m 0644 ${KERNEL_OUTPUT} ${D}/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}
  93. install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
  94. install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
  95. install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
  96. [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
  97. install -d ${D}/etc/modutils
  98. if [ "${KERNEL_MAJOR_VERSION}" = "2.6" ]; then
  99. install -d ${D}/etc/modprobe.d
  100. fi
  101. #
  102. # Support for external module building - create a minimal copy of the kernel source tree
  103. #
  104. kerneldir=${D}/kernel/
  105. # Take care of arch specific headers
  106. # Kernel 2.6.27 moved headers from includes/asm-${ARCH} to arch/${ARCH}/include/asm
  107. if [ -e arch/${ARCH}/include/asm/ ] ; then
  108. install -d $kerneldir/arch/${ARCH}/
  109. cp -fR arch/${ARCH}/* $kerneldir/arch/${ARCH}/
  110. # Check for arch/x86 on i386
  111. elif [ -d arch/x86/include/asm/ ]; then
  112. if [ -e include/asm ] ; then
  113. install -d $kerneldir/include/asm/
  114. cp -fR arch/x86/include/asm/* $kerneldir/include/asm/
  115. fi
  116. install -d $kerneldir/arch/x86/include
  117. cp -fR arch/x86/* $kerneldir/arch/x86/
  118. fi
  119. # Take care of the rest of the main directories we need
  120. for entry in drivers/crypto drivers/media include scripts; do
  121. if [ -d $entry ]; then
  122. mkdir -p $kerneldir/$entry
  123. cp -fR $entry/* $kerneldir/$entry/
  124. fi
  125. done
  126. install -m 0644 .config $kerneldir/config-${KERNEL_VERSION}
  127. ln -sf config-${KERNEL_VERSION} $kerneldir/.config
  128. ln -sf config-${KERNEL_VERSION} $kerneldir/kernel-config
  129. echo "${KERNEL_VERSION}" >$kerneldir/kernel-abiversion
  130. echo "${S}" >$kerneldir/kernel-source
  131. echo "${KERNEL_CCSUFFIX}" >$kerneldir/kernel-ccsuffix
  132. echo "${KERNEL_LDSUFFIX}" >$kerneldir/kernel-ldsuffix
  133. [ -e vmlinux ] && install -m 0644 vmlinux $kerneldir/
  134. install -m 0644 ${KERNEL_OUTPUT} $kerneldir/${KERNEL_IMAGETYPE}
  135. install -m 0644 System.map $kerneldir/System.map-${KERNEL_VERSION}
  136. [ -e Module.symvers ] && install -m 0644 Module.symvers $kerneldir/
  137. # Copy over the main Makefiles
  138. [ -e Rules.make ] && install -m 0644 Rules.make $kerneldir/
  139. [ -e Makefile ] && install -m 0644 Makefile $kerneldir/
  140. # Check if arch/${ARCH}/Makefile exists and install it
  141. if [ -e arch/${ARCH}/Makefile ]; then
  142. install -d $kerneldir/arch/${ARCH}
  143. install -m 0644 arch/${ARCH}/Makefile* $kerneldir/arch/${ARCH}
  144. # Otherwise check arch/x86/Makefile for i386 and x86_64 on kernels >= 2.6.24
  145. elif [ -e arch/x86/Makefile ]; then
  146. install -d $kerneldir/arch/x86
  147. install -m 0644 arch/x86/Makefile* $kerneldir/arch/x86
  148. fi
  149. # Remove the following binaries which cause strip errors
  150. # during do_package for cross-compiled platforms
  151. bin_files="arch/powerpc/boot/addnote arch/powerpc/boot/hack-coff \
  152. arch/powerpc/boot/mktree scripts/bin2c scripts/conmakehash \
  153. scripts/ihex2fw scripts/kallsyms scripts/pnmtologo scripts/basic/docproc \
  154. scripts/basic/fixdep scripts/basic/hash scripts/dtc/dtc \
  155. scripts/genksyms/genksyms scripts/kconfig/conf scripts/mod/mk_elfconfig \
  156. scripts/mod/modpost scripts/recordmcount"
  157. rm -rf $kerneldir/scripts/*.o
  158. rm -rf $kerneldir/scripts/basic/*.o
  159. rm -rf $kerneldir/scripts/kconfig/*.o
  160. rm -rf $kerneldir/scripts/mod/*.o
  161. rm -rf $kerneldir/scripts/dtc/*.o
  162. for entry in $bin_files; do
  163. rm -f $kerneldir/$entry
  164. done
  165. }
  166. sysroot_stage_all_append() {
  167. sysroot_stage_dir ${D}/kernel ${SYSROOT_DESTDIR}/kernel
  168. }
  169. kernel_do_configure() {
  170. # Copy defconfig to .config if .config does not exist. This allows
  171. # recipes to manage the .config themselves in do_configure_prepend().
  172. if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${S}/.config" ]; then
  173. cp "${WORKDIR}/defconfig" "${S}/.config"
  174. fi
  175. yes '' | oe_runmake oldconfig
  176. if [ ! -z "${INITRAMFS_IMAGE}" ]; then
  177. for img in cpio.gz cpio.lzo cpio.lzma; do
  178. if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img" ]; then
  179. cp "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img" initramfs.$img
  180. fi
  181. done
  182. fi
  183. }
  184. kernel_do_configure[depends] += "${INITRAMFS_TASK}"
  185. do_menuconfig() {
  186. export DISPLAY='${DISPLAY}'
  187. export DBUS_SESSION_BUS_ADDRESS='${DBUS_SESSION_BUS_ADDRESS}'
  188. export XAUTHORITY='${XAUTHORITY}'
  189. export TERMWINDOWTITLE="${PN} Kernel Configuration"
  190. export SHELLCMDS="make menuconfig"
  191. ${TERMCMDRUN}
  192. if [ $? -ne 0 ]; then
  193. echo "Fatal: '${TERMCMD}' not found. Check TERMCMD variable."
  194. exit 1
  195. fi
  196. }
  197. do_menuconfig[nostamp] = "1"
  198. addtask menuconfig after do_patch
  199. pkg_postinst_kernel () {
  200. cd /${KERNEL_IMAGEDEST}; update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true
  201. }
  202. pkg_postrm_kernel () {
  203. cd /${KERNEL_IMAGEDEST}; update-alternatives --remove ${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE}-${KERNEL_VERSION} || true
  204. }
  205. inherit cml1
  206. EXPORT_FUNCTIONS do_compile do_install do_configure
  207. # kernel-base becomes kernel-${KERNEL_VERSION}
  208. # kernel-image becomes kernel-image-${KERNEL_VERISON}
  209. PACKAGES = "kernel kernel-base kernel-image kernel-dev kernel-vmlinux kernel-misc"
  210. FILES = ""
  211. FILES_kernel-image = "/boot/${KERNEL_IMAGETYPE}*"
  212. FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config*"
  213. FILES_kernel-vmlinux = "/boot/vmlinux*"
  214. # misc is a package to contain files we need in staging
  215. FILES_kernel-misc = "/kernel/include/config /kernel/scripts /kernel/drivers/crypto /kernel/drivers/media"
  216. RDEPENDS_kernel = "kernel-base"
  217. # Allow machines to override this dependency if kernel image files are
  218. # not wanted in images as standard
  219. RDEPENDS_kernel-base ?= "kernel-image"
  220. PKG_kernel-image = "kernel-image-${KERNEL_VERSION}"
  221. PKG_kernel-base = "kernel-${KERNEL_VERSION}"
  222. ALLOW_EMPTY_kernel = "1"
  223. ALLOW_EMPTY_kernel-base = "1"
  224. ALLOW_EMPTY_kernel-image = "1"
  225. # Userspace workarounds for kernel modules issues
  226. # This is shame, fix the kernel instead!
  227. DEPENDS_kernel-module-dtl1-cs = "bluez-dtl1-workaround"
  228. RDEPENDS_kernel-module-dtl1-cs = "bluez-dtl1-workaround"
  229. pkg_postinst_kernel-image () {
  230. if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
  231. mkdir -p $D/lib/modules/${KERNEL_VERSION}
  232. fi
  233. if [ -n "$D" ]; then
  234. ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_VERSION} ${KERNEL_VERSION}
  235. else
  236. depmod -a
  237. fi
  238. }
  239. pkg_postinst_modules () {
  240. if [ -n "$D" ]; then
  241. ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_VERSION} ${KERNEL_VERSION}
  242. else
  243. depmod -a
  244. update-modules || true
  245. fi
  246. }
  247. pkg_postrm_modules () {
  248. update-modules || true
  249. }
  250. autoload_postinst_fragment() {
  251. if [ x"$D" = "x" ]; then
  252. modprobe %s || true
  253. fi
  254. }
  255. # autoload defaults (alphabetically sorted)
  256. module_autoload_hidp = "hidp"
  257. module_autoload_ipv6 = "ipv6"
  258. module_autoload_ipsec = "ipsec"
  259. module_autoload_ircomm-tty = "ircomm-tty"
  260. module_autoload_rfcomm = "rfcomm"
  261. module_autoload_sa1100-rtc = "sa1100-rtc"
  262. # sa1100-rtc was renamed in 2.6.23 onwards
  263. module_autoload_rtc-sa1100 = "rtc-sa1100"
  264. # alias defaults (alphabetically sorted)
  265. module_conf_af_packet = "alias net-pf-17 af_packet"
  266. module_conf_bluez = "alias net-pf-31 bluez"
  267. module_conf_bnep = "alias bt-proto-4 bnep"
  268. module_conf_hci_uart = "alias tty-ldisc-15 hci_uart"
  269. module_conf_l2cap = "alias bt-proto-0 l2cap"
  270. module_conf_sco = "alias bt-proto-2 sco"
  271. module_conf_rfcomm = "alias bt-proto-3 rfcomm"
  272. python populate_packages_prepend () {
  273. def extract_modinfo(file):
  274. import tempfile, re
  275. tempfile.tempdir = bb.data.getVar("WORKDIR", d, 1)
  276. tf = tempfile.mkstemp()
  277. tmpfile = tf[1]
  278. cmd = "PATH=\"%s\" %sobjcopy -j .modinfo -O binary %s %s" % (bb.data.getVar("PATH", d, 1), bb.data.getVar("HOST_PREFIX", d, 1) or "", file, tmpfile)
  279. os.system(cmd)
  280. f = open(tmpfile)
  281. l = f.read().split("\000")
  282. f.close()
  283. os.close(tf[0])
  284. os.unlink(tmpfile)
  285. exp = re.compile("([^=]+)=(.*)")
  286. vals = {}
  287. for i in l:
  288. m = exp.match(i)
  289. if not m:
  290. continue
  291. vals[m.group(1)] = m.group(2)
  292. return vals
  293. def parse_depmod():
  294. import re
  295. dvar = bb.data.getVar('PKGD', d, 1)
  296. if not dvar:
  297. bb.error("PKGD not defined")
  298. return
  299. kernelver = bb.data.getVar('KERNEL_VERSION', d, 1)
  300. kernelver_stripped = kernelver
  301. m = re.match('^(.*-hh.*)[\.\+].*$', kernelver)
  302. if m:
  303. kernelver_stripped = m.group(1)
  304. path = bb.data.getVar("PATH", d, 1)
  305. host_prefix = bb.data.getVar("HOST_PREFIX", d, 1) or ""
  306. major_version = bb.data.getVar('KERNEL_MAJOR_VERSION', d, 1)
  307. cmd = "PATH=\"%s\" %sdepmod-%s -n -a -r -b %s -F %s/boot/System.map-%s %s" % (path, host_prefix, major_version, dvar, dvar, kernelver, kernelver_stripped)
  308. f = os.popen(cmd, 'r')
  309. deps = {}
  310. pattern0 = "^(.*\.k?o):..*$"
  311. pattern1 = "^(.*\.k?o):\s*(.*\.k?o)\s*$"
  312. pattern2 = "^(.*\.k?o):\s*(.*\.k?o)\s*\\\$"
  313. pattern3 = "^\t(.*\.k?o)\s*\\\$"
  314. pattern4 = "^\t(.*\.k?o)\s*$"
  315. line = f.readline()
  316. while line:
  317. if not re.match(pattern0, line):
  318. line = f.readline()
  319. continue
  320. m1 = re.match(pattern1, line)
  321. if m1:
  322. deps[m1.group(1)] = m1.group(2).split()
  323. else:
  324. m2 = re.match(pattern2, line)
  325. if m2:
  326. deps[m2.group(1)] = m2.group(2).split()
  327. line = f.readline()
  328. m3 = re.match(pattern3, line)
  329. while m3:
  330. deps[m2.group(1)].extend(m3.group(1).split())
  331. line = f.readline()
  332. m3 = re.match(pattern3, line)
  333. m4 = re.match(pattern4, line)
  334. deps[m2.group(1)].extend(m4.group(1).split())
  335. line = f.readline()
  336. f.close()
  337. return deps
  338. def get_dependencies(file, pattern, format):
  339. # file no longer includes PKGD
  340. file = file.replace(bb.data.getVar('PKGD', d, 1) or '', '', 1)
  341. # instead is prefixed with /lib/modules/${KERNEL_VERSION}
  342. file = file.replace("/lib/modules/%s/" % bb.data.getVar('KERNEL_VERSION', d, 1) or '', '', 1)
  343. if module_deps.has_key(file):
  344. import re
  345. dependencies = []
  346. for i in module_deps[file]:
  347. m = re.match(pattern, os.path.basename(i))
  348. if not m:
  349. continue
  350. on = legitimize_package_name(m.group(1))
  351. dependency_pkg = format % on
  352. dependencies.append(dependency_pkg)
  353. return dependencies
  354. return []
  355. def frob_metadata(file, pkg, pattern, format, basename):
  356. import re
  357. vals = extract_modinfo(file)
  358. dvar = bb.data.getVar('PKGD', d, 1)
  359. # If autoloading is requested, output /etc/modutils/<name> and append
  360. # appropriate modprobe commands to the postinst
  361. autoload = bb.data.getVar('module_autoload_%s' % basename, d, 1)
  362. if autoload:
  363. name = '%s/etc/modutils/%s' % (dvar, basename)
  364. f = open(name, 'w')
  365. for m in autoload.split():
  366. f.write('%s\n' % m)
  367. f.close()
  368. postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1)
  369. if not postinst:
  370. bb.fatal("pkg_postinst_%s not defined" % pkg)
  371. postinst += bb.data.getVar('autoload_postinst_fragment', d, 1) % autoload
  372. bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
  373. # Write out any modconf fragment
  374. modconf = bb.data.getVar('module_conf_%s' % basename, d, 1)
  375. if modconf:
  376. if bb.data.getVar("KERNEL_MAJOR_VERSION", d, 1) == "2.6":
  377. name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename)
  378. else:
  379. name = '%s/etc/modutils/%s.conf' % (dvar, basename)
  380. f = open(name, 'w')
  381. f.write("%s\n" % modconf)
  382. f.close()
  383. files = bb.data.getVar('FILES_%s' % pkg, d, 1)
  384. files = "%s /etc/modutils/%s /etc/modutils/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename, basename)
  385. bb.data.setVar('FILES_%s' % pkg, files, d)
  386. if vals.has_key("description"):
  387. old_desc = bb.data.getVar('DESCRIPTION_' + pkg, d, 1) or ""
  388. bb.data.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"], d)
  389. rdepends_str = bb.data.getVar('RDEPENDS_' + pkg, d, 1)
  390. if rdepends_str:
  391. rdepends = rdepends_str.split()
  392. else:
  393. rdepends = []
  394. rdepends.extend(get_dependencies(file, pattern, format))
  395. bb.data.setVar('RDEPENDS_' + pkg, ' '.join(rdepends), d)
  396. module_deps = parse_depmod()
  397. module_regex = '^(.*)\.k?o$'
  398. module_pattern = 'kernel-module-%s'
  399. postinst = bb.data.getVar('pkg_postinst_modules', d, 1)
  400. postrm = bb.data.getVar('pkg_postrm_modules', d, 1)
  401. do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.bin$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
  402. do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.fw$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
  403. do_split_packages(d, root='/lib/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='update-modules kernel-%s' % bb.data.getVar("KERNEL_VERSION", d, 1))
  404. import re
  405. metapkg = "kernel-modules"
  406. bb.data.setVar('ALLOW_EMPTY_' + metapkg, "1", d)
  407. bb.data.setVar('FILES_' + metapkg, "", d)
  408. blacklist = [ 'kernel-dev', 'kernel-image', 'kernel-base', 'kernel-vmlinux', 'perf' ]
  409. for l in module_deps.values():
  410. for i in l:
  411. pkg = module_pattern % legitimize_package_name(re.match(module_regex, os.path.basename(i)).group(1))
  412. blacklist.append(pkg)
  413. metapkg_rdepends = []
  414. packages = bb.data.getVar('PACKAGES', d, 1).split()
  415. for pkg in packages[1:]:
  416. if not pkg in blacklist and not pkg in metapkg_rdepends:
  417. metapkg_rdepends.append(pkg)
  418. bb.data.setVar('RDEPENDS_' + metapkg, ' '.join(metapkg_rdepends), d)
  419. bb.data.setVar('DESCRIPTION_' + metapkg, 'Kernel modules meta package', d)
  420. packages.append(metapkg)
  421. bb.data.setVar('PACKAGES', ' '.join(packages), d)
  422. }
  423. # Support checking the kernel size since some kernels need to reside in partitions
  424. # with a fixed length or there is a limit in transferring the kernel to memory
  425. do_sizecheck() {
  426. if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
  427. size=`ls -l arch/${ARCH}/boot/${KERNEL_IMAGETYPE} | awk '{ print $5}'`
  428. if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then
  429. rm arch/${ARCH}/boot/${KERNEL_IMAGETYPE}
  430. die "This kernel (size=$size > ${KERNEL_IMAGE_MAXSIZE}) is too big for your device. Please reduce the size of the kernel by making more of it modular."
  431. fi
  432. fi
  433. }
  434. addtask sizecheck before do_install after do_compile
  435. do_uboot_mkimage() {
  436. if test "x${KERNEL_IMAGETYPE}" = "xuImage" ; then
  437. ENTRYPOINT=${UBOOT_ENTRYPOINT}
  438. if test -n "${UBOOT_ENTRYSYMBOL}"; then
  439. ENTRYPOINT=`${HOST_PREFIX}nm ${S}/vmlinux | \
  440. awk '$3=="${UBOOT_ENTRYSYMBOL}" {print $1}'`
  441. fi
  442. if test -e arch/${ARCH}/boot/compressed/vmlinux ; then
  443. ${OBJCOPY} -O binary -R .note -R .comment -S arch/${ARCH}/boot/compressed/vmlinux linux.bin
  444. uboot-mkimage -A ${UBOOT_ARCH} -O linux -T kernel -C none -a ${UBOOT_LOADADDRESS} -e $ENTRYPOINT -n "${DISTRO_NAME}/${PV}/${MACHINE}" -d linux.bin arch/${ARCH}/boot/uImage
  445. rm -f linux.bin
  446. else
  447. ${OBJCOPY} -O binary -R .note -R .comment -S vmlinux linux.bin
  448. rm -f linux.bin.gz
  449. gzip -9 linux.bin
  450. uboot-mkimage -A ${UBOOT_ARCH} -O linux -T kernel -C gzip -a ${UBOOT_LOADADDRESS} -e $ENTRYPOINT -n "${DISTRO_NAME}/${PV}/${MACHINE}" -d linux.bin.gz arch/${ARCH}/boot/uImage
  451. rm -f linux.bin.gz
  452. fi
  453. fi
  454. }
  455. addtask uboot_mkimage before do_install after do_compile
  456. KERNEL_IMAGE_BASE_NAME ?= "${KERNEL_IMAGETYPE}-${PV}-${PR}-${MACHINE}-${DATETIME}"
  457. # Don't include the DATETIME variable in the sstate package signatures
  458. KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME"
  459. KERNEL_IMAGE_SYMLINK_NAME ?= "${KERNEL_IMAGETYPE}-${MACHINE}"
  460. kernel_do_deploy() {
  461. install -m 0644 arch/${ARCH}/boot/${KERNEL_IMAGETYPE} ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.bin
  462. if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
  463. tar -cvzf ${DEPLOYDIR}/modules-${KERNEL_VERSION}-${PR}-${MACHINE}.tgz -C ${D} lib
  464. fi
  465. cd ${DEPLOYDIR}
  466. rm -f ${KERNEL_IMAGE_SYMLINK_NAME}.bin
  467. ln -sf ${KERNEL_IMAGE_BASE_NAME}.bin ${KERNEL_IMAGE_SYMLINK_NAME}.bin
  468. }
  469. do_deploy[dirs] = "${DEPLOYDIR} ${B}"
  470. addtask deploy before do_package after do_install
  471. EXPORT_FUNCTIONS do_deploy
  472. # perf must be enabled in individual kernel recipes
  473. PACKAGES =+ "perf"
  474. FILES_perf = "${bindir}/* \
  475. ${libexecdir}"