kernel.bbclass 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. inherit linux-kernel-base kernel-module-split
  7. COMPATIBLE_HOST = ".*-linux"
  8. KERNEL_PACKAGE_NAME ??= "kernel"
  9. KERNEL_DEPLOYSUBDIR ??= "${@ "" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else d.getVar("KERNEL_PACKAGE_NAME") }"
  10. PROVIDES += "virtual/kernel"
  11. DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native bison-native"
  12. DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lzo", "lzop-native", "", d)}"
  13. DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lz4", "lz4-native", "", d)}"
  14. DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.zst", "zstd-native", "", d)}"
  15. PACKAGE_WRITE_DEPS += "depmodwrapper-cross"
  16. do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot gzip-native:do_populate_sysroot"
  17. do_clean[depends] += "make-mod-scripts:do_clean"
  18. CVE_PRODUCT ?= "linux_kernel"
  19. S = "${STAGING_KERNEL_DIR}"
  20. B = "${WORKDIR}/build"
  21. KBUILD_OUTPUT = "${B}"
  22. OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
  23. # we include gcc above, we dont need virtual/libc
  24. INHIBIT_DEFAULT_DEPS = "1"
  25. KERNEL_IMAGETYPE ?= "zImage"
  26. INITRAMFS_IMAGE ?= ""
  27. INITRAMFS_TASK ?= ""
  28. INITRAMFS_IMAGE_BUNDLE ?= ""
  29. INITRAMFS_DEPLOY_DIR_IMAGE ?= "${DEPLOY_DIR_IMAGE}"
  30. INITRAMFS_MULTICONFIG ?= ""
  31. # KERNEL_VERSION is extracted from source code. It is evaluated as
  32. # None for the first parsing, since the code has not been fetched.
  33. # After the code is fetched, it will be evaluated as real version
  34. # number and cause kernel to be rebuilt. To avoid this, make
  35. # KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on
  36. # LINUX_VERSION which is a constant.
  37. KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}"
  38. KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}"
  39. KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
  40. KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
  41. python __anonymous () {
  42. pn = d.getVar("PN")
  43. kpn = d.getVar("KERNEL_PACKAGE_NAME")
  44. # XXX Remove this after bug 11905 is resolved
  45. # FILES:${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly
  46. if kpn == pn:
  47. bb.warn("Some packages (E.g. *-dev) might be missing due to "
  48. "bug 11905 (variable KERNEL_PACKAGE_NAME == PN)")
  49. # The default kernel recipe builds in a shared location defined by
  50. # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR.
  51. # Set these variables to directories under ${WORKDIR} in alternate
  52. # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they
  53. # may build in parallel with the default kernel without clobbering.
  54. if kpn != "kernel":
  55. workdir = d.getVar("WORKDIR")
  56. sourceDir = os.path.join(workdir, 'kernel-source')
  57. artifactsDir = os.path.join(workdir, 'kernel-build-artifacts')
  58. d.setVar("STAGING_KERNEL_DIR", sourceDir)
  59. d.setVar("STAGING_KERNEL_BUILDDIR", artifactsDir)
  60. # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES
  61. type = d.getVar('KERNEL_IMAGETYPE') or ""
  62. alttype = d.getVar('KERNEL_ALT_IMAGETYPE') or ""
  63. types = d.getVar('KERNEL_IMAGETYPES') or ""
  64. if type not in types.split():
  65. types = (type + ' ' + types).strip()
  66. if alttype not in types.split():
  67. types = (alttype + ' ' + types).strip()
  68. d.setVar('KERNEL_IMAGETYPES', types)
  69. # KERNEL_IMAGETYPES may contain a mixture of image types supported directly
  70. # by the kernel build system and types which are created by post-processing
  71. # the output of the kernel build system (e.g. compressing vmlinux ->
  72. # vmlinux.gz in kernel_do_transform_kernel()).
  73. # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported
  74. # directly by the kernel build system.
  75. if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'):
  76. typeformake = set()
  77. for type in types.split():
  78. if type == 'vmlinux.gz':
  79. type = 'vmlinux'
  80. typeformake.add(type)
  81. d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', ' '.join(sorted(typeformake)))
  82. kname = d.getVar('KERNEL_PACKAGE_NAME') or "kernel"
  83. imagedest = d.getVar('KERNEL_IMAGEDEST')
  84. for type in types.split():
  85. if bb.data.inherits_class('nopackages', d):
  86. continue
  87. typelower = type.lower()
  88. d.appendVar('PACKAGES', ' %s-image-%s' % (kname, typelower))
  89. d.setVar('FILES:' + kname + '-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type)
  90. d.appendVar('RDEPENDS:%s-image' % kname, ' %s-image-%s (= ${EXTENDPKGV})' % (kname, typelower))
  91. splitmods = d.getVar("KERNEL_SPLIT_MODULES")
  92. if splitmods != '1':
  93. d.appendVar('RDEPENDS:%s-image' % kname, ' %s-modules (= ${EXTENDPKGV})' % kname)
  94. d.appendVar('RDEPENDS:%s-image-%s' % (kname, typelower), ' %s-modules-${KERNEL_VERSION_PKG_NAME} (= ${EXTENDPKGV})' % kname)
  95. d.setVar('PKG:%s-modules' % kname, '%s-modules-${KERNEL_VERSION_PKG_NAME}' % kname)
  96. d.appendVar('RPROVIDES:%s-modules' % kname, ' %s-modules-${KERNEL_VERSION_PKG_NAME}' % kname)
  97. d.setVar('PKG:%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower))
  98. d.setVar('ALLOW_EMPTY:%s-image-%s' % (kname, typelower), '1')
  99. d.prependVar('pkg_postinst:%s-image-%s' % (kname,typelower), """set +e
  100. if [ -n "$D" ]; then
  101. ln -sf %s-${KERNEL_VERSION} $D/${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
  102. else
  103. ln -sf %s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
  104. if [ $? -ne 0 ]; then
  105. echo "Filesystem on ${KERNEL_IMAGEDEST}/ doesn't support symlinks, falling back to copied image (%s)."
  106. install -m 0644 ${KERNEL_IMAGEDEST}/%s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s
  107. fi
  108. fi
  109. set -e
  110. """ % (type, type, type, type, type, type, type))
  111. d.setVar('pkg_postrm:%s-image-%s' % (kname,typelower), """set +e
  112. if [ -f "${KERNEL_IMAGEDEST}/%s" -o -L "${KERNEL_IMAGEDEST}/%s" ]; then
  113. rm -f ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
  114. fi
  115. set -e
  116. """ % (type, type, type))
  117. image = d.getVar('INITRAMFS_IMAGE')
  118. # If the INTIRAMFS_IMAGE is set but the INITRAMFS_IMAGE_BUNDLE is set to 0,
  119. # the do_bundle_initramfs does nothing, but the INITRAMFS_IMAGE is built
  120. # standalone for use by wic and other tools.
  121. if image:
  122. if d.getVar('INITRAMFS_MULTICONFIG'):
  123. d.appendVarFlag('do_bundle_initramfs', 'mcdepends', ' mc::${INITRAMFS_MULTICONFIG}:${INITRAMFS_IMAGE}:do_image_complete')
  124. else:
  125. d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
  126. if image and bb.utils.to_boolean(d.getVar('INITRAMFS_IMAGE_BUNDLE')):
  127. bb.build.addtask('do_transform_bundled_initramfs', 'do_deploy', 'do_bundle_initramfs', d)
  128. # NOTE: setting INITRAMFS_TASK is for backward compatibility
  129. # The preferred method is to set INITRAMFS_IMAGE, because
  130. # this INITRAMFS_TASK has circular dependency problems
  131. # if the initramfs requires kernel modules
  132. image_task = d.getVar('INITRAMFS_TASK')
  133. if image_task:
  134. d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
  135. }
  136. # Here we pull in all various kernel image types which we support.
  137. #
  138. # In case you're wondering why kernel.bbclass inherits the other image
  139. # types instead of the other way around, the reason for that is to
  140. # maintain compatibility with various currently existing meta-layers.
  141. # By pulling in the various kernel image types here, we retain the
  142. # original behavior of kernel.bbclass, so no meta-layers should get
  143. # broken.
  144. #
  145. # KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this
  146. # used to be the default behavior when only uImage was supported. This
  147. # variable can be appended by users who implement support for new kernel
  148. # image types.
  149. KERNEL_CLASSES ?= " kernel-uimage "
  150. inherit_defer ${KERNEL_CLASSES}
  151. # Old style kernels may set ${S} = ${WORKDIR}/git for example
  152. # We need to move these over to STAGING_KERNEL_DIR. We can't just
  153. # create the symlink in advance as the git fetcher can't cope with
  154. # the symlink.
  155. do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
  156. do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
  157. python do_symlink_kernsrc () {
  158. s = d.getVar("S")
  159. kernsrc = d.getVar("STAGING_KERNEL_DIR")
  160. if s != kernsrc:
  161. bb.utils.mkdirhier(kernsrc)
  162. bb.utils.remove(kernsrc, recurse=True)
  163. if s[-1] == '/':
  164. # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as
  165. # directory name and fail
  166. s = s[:-1]
  167. if d.getVar("EXTERNALSRC"):
  168. # With EXTERNALSRC S will not be wiped so we can symlink to it
  169. os.symlink(s, kernsrc)
  170. else:
  171. import shutil
  172. shutil.move(s, kernsrc)
  173. os.symlink(kernsrc, s)
  174. }
  175. # do_patch is normally ordered before do_configure, but
  176. # externalsrc.bbclass deletes do_patch, breaking the dependency of
  177. # do_configure on do_symlink_kernsrc.
  178. addtask symlink_kernsrc before do_patch do_configure after do_unpack
  179. inherit kernel-arch deploy
  180. PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
  181. PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
  182. PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*"
  183. export OS = "${TARGET_OS}"
  184. export CROSS_COMPILE = "${TARGET_PREFIX}"
  185. KERNEL_RELEASE ?= "${KERNEL_VERSION}"
  186. # The directory where built kernel lies in the kernel tree
  187. KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
  188. KERNEL_IMAGEDEST ?= "boot"
  189. KERNEL_DTBDEST ?= "${KERNEL_IMAGEDEST}"
  190. KERNEL_DTBVENDORED ?= "0"
  191. #
  192. # configuration
  193. #
  194. export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}"
  195. KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
  196. # kernels are generally machine specific
  197. PACKAGE_ARCH = "${MACHINE_ARCH}"
  198. # U-Boot support
  199. UBOOT_ENTRYPOINT ?= "20008000"
  200. UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
  201. # Some Linux kernel configurations need additional parameters on the command line
  202. KERNEL_EXTRA_ARGS ?= ""
  203. EXTRA_OEMAKE += ' CC="${KERNEL_CC}" LD="${KERNEL_LD}" OBJCOPY="${KERNEL_OBJCOPY}" STRIP="${KERNEL_STRIP}"'
  204. EXTRA_OEMAKE += ' HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}"'
  205. EXTRA_OEMAKE += ' HOSTCXX="${BUILD_CXX}" HOSTCXXFLAGS="${BUILD_CXXFLAGS}"'
  206. KERNEL_ALT_IMAGETYPE ??= ""
  207. copy_initramfs() {
  208. echo "Copying initramfs into ./usr ..."
  209. # In case the directory is not created yet from the first pass compile:
  210. mkdir -p ${B}/usr
  211. # Find and use the first initramfs image archive type we find
  212. rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
  213. for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst; do
  214. if [ -e "${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then
  215. cp ${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/.
  216. case $img in
  217. *gz)
  218. echo "gzip decompressing image"
  219. gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
  220. break
  221. ;;
  222. *lz4)
  223. echo "lz4 decompressing image"
  224. lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
  225. break
  226. ;;
  227. *lzo)
  228. echo "lzo decompressing image"
  229. lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
  230. break
  231. ;;
  232. *lzma)
  233. echo "lzma decompressing image"
  234. lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
  235. break
  236. ;;
  237. *xz)
  238. echo "xz decompressing image"
  239. xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
  240. break
  241. ;;
  242. *zst)
  243. echo "zst decompressing image"
  244. zstd -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
  245. break
  246. ;;
  247. esac
  248. break
  249. fi
  250. done
  251. # Verify that the above loop found a initramfs, fail otherwise
  252. [ -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio ] && echo "Finished copy of initramfs into ./usr" || die "Could not find any ${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.cpio{.gz|.lz4|.lzo|.lzma|.xz|.zst) for bundling; INITRAMFS_IMAGE_NAME might be wrong."
  253. }
  254. do_bundle_initramfs () {
  255. if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
  256. echo "Creating a kernel image with a bundled initramfs..."
  257. copy_initramfs
  258. # Backing up kernel image relies on its type(regular file or symbolic link)
  259. tmp_path=""
  260. for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
  261. if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then
  262. linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType`
  263. realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType`
  264. mv -f $realpath $realpath.bak
  265. tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath
  266. elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then
  267. mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak
  268. tmp_path=$tmp_path" "$imageType"##"
  269. fi
  270. done
  271. use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
  272. kernel_do_compile
  273. # Restoring kernel image
  274. for tp in $tmp_path ; do
  275. imageType=`echo $tp|cut -d "#" -f 1`
  276. linkpath=`echo $tp|cut -d "#" -f 2`
  277. realpath=`echo $tp|cut -d "#" -f 3`
  278. if [ -n "$realpath" ]; then
  279. mv -f $realpath $realpath.initramfs
  280. mv -f $realpath.bak $realpath
  281. ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs
  282. else
  283. mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs
  284. mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType
  285. fi
  286. done
  287. fi
  288. }
  289. do_bundle_initramfs[dirs] = "${B}"
  290. kernel_do_transform_bundled_initramfs() {
  291. # vmlinux.gz is not built by kernel
  292. if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
  293. gzip -9cn < ${KERNEL_OUTPUT_DIR}/vmlinux.initramfs > ${KERNEL_OUTPUT_DIR}/vmlinux.gz.initramfs
  294. fi
  295. }
  296. do_transform_bundled_initramfs[dirs] = "${B}"
  297. python do_package:prepend () {
  298. d.setVar('STRIP', d.getVar('KERNEL_STRIP').strip())
  299. }
  300. python do_devshell:prepend () {
  301. os.environ["LDFLAGS"] = ''
  302. }
  303. addtask bundle_initramfs after do_install before do_deploy
  304. KERNEL_DEBUG_TIMESTAMPS ??= "0"
  305. kernel_do_compile() {
  306. unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
  307. # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
  308. export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
  309. export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
  310. export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
  311. export PKG_CONFIG_SYSROOT_DIR=""
  312. # for newer kernels (5.19+) there's a dedicated variable
  313. export HOSTPKG_CONFIG="pkg-config-native"
  314. if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
  315. # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
  316. # be set....
  317. if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
  318. # The source directory is not necessarily a git repository, so we
  319. # specify the git-dir to ensure that git does not query a
  320. # repository in any parent directory.
  321. SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
  322. fi
  323. ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
  324. export KBUILD_BUILD_TIMESTAMP="$ts"
  325. export KCONFIG_NOTIMESTAMP=1
  326. bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
  327. else
  328. ts=`LC_ALL=C date`
  329. export KBUILD_BUILD_TIMESTAMP="$ts"
  330. bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
  331. fi
  332. # The $use_alternate_initrd is only set from
  333. # do_bundle_initramfs() This variable is specifically for the
  334. # case where we are making a second pass at the kernel
  335. # compilation and we want to force the kernel build to use a
  336. # different initramfs image. The way to do that in the kernel
  337. # is to specify:
  338. # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
  339. if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
  340. # The old style way of copying an prebuilt image and building it
  341. # is turned on via INTIRAMFS_TASK != ""
  342. copy_initramfs
  343. use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
  344. fi
  345. for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
  346. oe_runmake ${PARALLEL_MAKE} ${typeformake} ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
  347. done
  348. }
  349. kernel_do_transform_kernel() {
  350. # vmlinux.gz is not built by kernel
  351. if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
  352. mkdir -p "${KERNEL_OUTPUT_DIR}"
  353. gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz"
  354. fi
  355. }
  356. do_transform_kernel[dirs] = "${B}"
  357. addtask transform_kernel after do_compile before do_install
  358. do_compile_kernelmodules() {
  359. unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
  360. if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
  361. # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
  362. # be set....
  363. if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
  364. # The source directory is not necessarily a git repository, so we
  365. # specify the git-dir to ensure that git does not query a
  366. # repository in any parent directory.
  367. SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
  368. fi
  369. ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
  370. export KBUILD_BUILD_TIMESTAMP="$ts"
  371. export KCONFIG_NOTIMESTAMP=1
  372. bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
  373. else
  374. ts=`LC_ALL=C date`
  375. export KBUILD_BUILD_TIMESTAMP="$ts"
  376. bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
  377. fi
  378. if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
  379. oe_runmake -C ${B} ${PARALLEL_MAKE} modules ${KERNEL_EXTRA_ARGS}
  380. # Module.symvers gets updated during the
  381. # building of the kernel modules. We need to
  382. # update this in the shared workdir since some
  383. # external kernel modules has a dependency on
  384. # other kernel modules and will look at this
  385. # file to do symbol lookups
  386. cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
  387. # 5.10+ kernels have module.lds that we need to copy for external module builds
  388. if [ -e "${B}/scripts/module.lds" ]; then
  389. install -Dm 0644 ${B}/scripts/module.lds ${STAGING_KERNEL_BUILDDIR}/scripts/module.lds
  390. fi
  391. else
  392. bbnote "no modules to compile"
  393. fi
  394. }
  395. addtask compile_kernelmodules after do_compile before do_strip
  396. kernel_do_install() {
  397. #
  398. # First install the modules
  399. #
  400. unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
  401. if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
  402. oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
  403. rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
  404. rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
  405. # Remove empty module directories to prevent QA issues
  406. find "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel" -type d -empty -delete
  407. else
  408. bbnote "no modules to install"
  409. fi
  410. #
  411. # Install various kernel output (zImage, map file, config, module support files)
  412. #
  413. install -d ${D}/${KERNEL_IMAGEDEST}
  414. #
  415. # When including an initramfs bundle inside a FIT image, the fitImage is created after the install task
  416. # by do_assemble_fitimage_initramfs.
  417. # This happens after the generation of the initramfs bundle (done by do_bundle_initramfs).
  418. # So, at the level of the install task we should not try to install the fitImage. fitImage is still not
  419. # generated yet.
  420. # After the generation of the fitImage, the deploy task copies the fitImage from the build directory to
  421. # the deploy folder.
  422. #
  423. for imageType in ${KERNEL_IMAGETYPES} ; do
  424. if [ $imageType != "fitImage" ] || [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ] ; then
  425. install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType ${D}/${KERNEL_IMAGEDEST}/$imageType-${KERNEL_VERSION}
  426. fi
  427. done
  428. install -m 0644 System.map ${D}/${KERNEL_IMAGEDEST}/System.map-${KERNEL_VERSION}
  429. install -m 0644 .config ${D}/${KERNEL_IMAGEDEST}/config-${KERNEL_VERSION}
  430. install -m 0644 vmlinux ${D}/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION}
  431. ! [ -e Module.symvers ] || install -m 0644 Module.symvers ${D}/${KERNEL_IMAGEDEST}/Module.symvers-${KERNEL_VERSION}
  432. }
  433. # Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
  434. do_kernel_version_sanity_check() {
  435. if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then
  436. exit 0
  437. fi
  438. # The Makefile determines the kernel version shown at runtime
  439. # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
  440. VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
  441. PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
  442. SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
  443. EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
  444. # Build a string for regex and a plain version string
  445. reg="^${VERSION}\.${PATCHLEVEL}"
  446. vers="${VERSION}.${PATCHLEVEL}"
  447. if [ -n "${SUBLEVEL}" ]; then
  448. # Ignoring a SUBLEVEL of zero is fine
  449. if [ "${SUBLEVEL}" = "0" ]; then
  450. reg="${reg}(\.${SUBLEVEL})?"
  451. else
  452. reg="${reg}\.${SUBLEVEL}"
  453. vers="${vers}.${SUBLEVEL}"
  454. fi
  455. fi
  456. vers="${vers}${EXTRAVERSION}"
  457. reg="${reg}${EXTRAVERSION}"
  458. if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
  459. bbfatal "Package Version (${PV}) does not match of kernel being built (${vers}). Please update the PV variable to match the kernel source or set KERNEL_VERSION_SANITY_SKIP=\"1\" in your recipe."
  460. fi
  461. exit 0
  462. }
  463. addtask shared_workdir after do_compile before do_compile_kernelmodules
  464. addtask shared_workdir_setscene
  465. do_shared_workdir_setscene () {
  466. exit 1
  467. }
  468. emit_depmod_pkgdata() {
  469. # Stash data for depmod
  470. install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/
  471. echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion
  472. cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION}
  473. }
  474. PACKAGEFUNCS += "emit_depmod_pkgdata"
  475. do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
  476. do_shared_workdir () {
  477. cd ${B}
  478. kerneldir=${STAGING_KERNEL_BUILDDIR}
  479. install -d $kerneldir
  480. #
  481. # Store the kernel version in sysroots for module-base.bbclass
  482. #
  483. echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
  484. echo "${KERNEL_LOCALVERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-localversion
  485. # Copy files required for module builds
  486. cp System.map $kerneldir/System.map-${KERNEL_VERSION}
  487. ! [ -e Module.symvers ] || cp Module.symvers $kerneldir/
  488. cp .config $kerneldir/
  489. mkdir -p $kerneldir/include/config
  490. cp include/config/kernel.release $kerneldir/include/config/kernel.release
  491. if [ -e certs/signing_key.x509 ]; then
  492. # The signing_key.* files are stored in the certs/ dir in
  493. # newer Linux kernels
  494. mkdir -p $kerneldir/certs
  495. cp certs/signing_key.* $kerneldir/certs/
  496. elif [ -e signing_key.priv ]; then
  497. cp signing_key.* $kerneldir/
  498. fi
  499. # We can also copy over all the generated files and avoid special cases
  500. # like version.h, but we've opted to keep this small until file creep starts
  501. # to happen
  502. if [ -e include/linux/version.h ]; then
  503. mkdir -p $kerneldir/include/linux
  504. cp include/linux/version.h $kerneldir/include/linux/version.h
  505. fi
  506. # As of Linux kernel version 3.0.1, the clean target removes
  507. # arch/powerpc/lib/crtsavres.o which is present in
  508. # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
  509. if [ ${ARCH} = "powerpc" ]; then
  510. if [ -e arch/powerpc/lib/crtsavres.o ]; then
  511. mkdir -p $kerneldir/arch/powerpc/lib/
  512. cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
  513. fi
  514. fi
  515. if [ -d include/generated ]; then
  516. mkdir -p $kerneldir/include/generated/
  517. cp -fR include/generated/* $kerneldir/include/generated/
  518. fi
  519. if [ -d arch/${ARCH}/include/generated ]; then
  520. mkdir -p $kerneldir/arch/${ARCH}/include/generated/
  521. cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
  522. fi
  523. if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then
  524. # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for
  525. # out-of-tree modules to be able to generate object files.
  526. if [ -x tools/objtool/objtool ]; then
  527. mkdir -p ${kerneldir}/tools/objtool
  528. cp tools/objtool/objtool ${kerneldir}/tools/objtool/
  529. fi
  530. fi
  531. # When building with CONFIG_MODVERSIONS=y and CONFIG_RANDSTRUCT=y we need
  532. # to copy the build assets generated for the randstruct seed to
  533. # STAGING_KERNEL_BUILDDIR, otherwise the out-of-tree modules build will
  534. # generate those assets which will result in a different
  535. # RANDSTRUCT_HASHED_SEED
  536. if [ -d scripts/basic ]; then
  537. mkdir -p ${kerneldir}/scripts
  538. cp -r scripts/basic ${kerneldir}/scripts
  539. fi
  540. if [ -d scripts/gcc-plugins ]; then
  541. mkdir -p ${kerneldir}/scripts
  542. cp -r scripts/gcc-plugins ${kerneldir}/scripts
  543. fi
  544. }
  545. # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
  546. SYSROOT_DIRS = ""
  547. KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} olddefconfig || oe_runmake -C ${S} O=${B} oldnoconfig"
  548. python check_oldest_kernel() {
  549. oldest_kernel = d.getVar('OLDEST_KERNEL')
  550. kernel_version = d.getVar('KERNEL_VERSION')
  551. tclibc = d.getVar('TCLIBC')
  552. if tclibc == 'glibc':
  553. kernel_version = kernel_version.split('-', 1)[0]
  554. if oldest_kernel and kernel_version:
  555. if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
  556. bb.warn('%s: OLDEST_KERNEL is "%s" but the version of the kernel you are building is "%s" - therefore %s as built may not be compatible with this kernel. Either set OLDEST_KERNEL to an older version, or build a newer kernel.' % (d.getVar('PN'), oldest_kernel, kernel_version, tclibc))
  557. }
  558. check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
  559. do_configure[prefuncs] += "check_oldest_kernel"
  560. KERNEL_LOCALVERSION ??= ""
  561. # 6.3+ requires the variable LOCALVERSION to be set to not get a "+" in
  562. # the local version. Having it empty means nothing will be added, and any
  563. # value will be appended to the local kernel version. This replaces the
  564. # use of .scmversion file for setting a localversion without using
  565. # the CONFIG_LOCALVERSION option.
  566. #
  567. # Note: This class saves the value of localversion to a file
  568. # so other recipes like make-mod-scripts can restore it via the
  569. # helper function get_kernellocalversion_file
  570. export LOCALVERSION="${KERNEL_LOCALVERSION}"
  571. kernel_do_configure() {
  572. # fixes extra + in /lib/modules/2.6.37+
  573. # $ scripts/setlocalversion . => +
  574. # $ make kernelversion => 2.6.37
  575. # $ make kernelrelease => 2.6.37+
  576. # See kernel-arch.bbclass for post v6.3 removal of the extra
  577. # + in localversion. .scmversion is no longer used, and the
  578. # variable LOCALVERSION must be used
  579. if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]; then
  580. echo ${KERNEL_LOCALVERSION} > ${B}/.scmversion
  581. echo ${KERNEL_LOCALVERSION} > ${S}/.scmversion
  582. fi
  583. if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
  584. mv "${S}/.config" "${B}/.config"
  585. fi
  586. # Copy defconfig to .config if .config does not exist. This allows
  587. # recipes to manage the .config themselves in do_configure:prepend().
  588. if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
  589. cp "${WORKDIR}/defconfig" "${B}/.config"
  590. fi
  591. ${KERNEL_CONFIG_COMMAND}
  592. }
  593. do_savedefconfig() {
  594. bbplain "Saving defconfig to:\n${B}/defconfig"
  595. oe_runmake -C ${B} savedefconfig
  596. }
  597. do_savedefconfig[nostamp] = "1"
  598. addtask savedefconfig after do_configure
  599. inherit cml1 pkgconfig
  600. # Need LD, HOSTLDFLAGS and more for config operations
  601. KCONFIG_CONFIG_COMMAND:append = " ${EXTRA_OEMAKE}"
  602. EXPORT_FUNCTIONS do_compile do_transform_kernel do_transform_bundled_initramfs do_install do_configure
  603. # kernel-base becomes kernel-${KERNEL_VERSION}
  604. # kernel-image becomes kernel-image-${KERNEL_VERSION}
  605. PACKAGES = "${KERNEL_PACKAGE_NAME} ${KERNEL_PACKAGE_NAME}-base ${KERNEL_PACKAGE_NAME}-vmlinux ${KERNEL_PACKAGE_NAME}-image ${KERNEL_PACKAGE_NAME}-dev ${KERNEL_PACKAGE_NAME}-modules ${KERNEL_PACKAGE_NAME}-dbg"
  606. FILES:${PN} = ""
  607. FILES:${KERNEL_PACKAGE_NAME}-base = "${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.order ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin.modinfo"
  608. FILES:${KERNEL_PACKAGE_NAME}-image = ""
  609. FILES:${KERNEL_PACKAGE_NAME}-dev = "/${KERNEL_IMAGEDEST}/System.map* /${KERNEL_IMAGEDEST}/Module.symvers* /${KERNEL_IMAGEDEST}/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
  610. FILES:${KERNEL_PACKAGE_NAME}-vmlinux = "/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION_NAME}"
  611. FILES:${KERNEL_PACKAGE_NAME}-modules = ""
  612. FILES:${KERNEL_PACKAGE_NAME}-dbg = "/usr/lib/debug /usr/src/debug"
  613. RDEPENDS:${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base (= ${EXTENDPKGV})"
  614. # Allow machines to override this dependency if kernel image files are
  615. # not wanted in images as standard
  616. RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image (= ${EXTENDPKGV})"
  617. PKG:${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
  618. RDEPENDS:${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux (= ${EXTENDPKGV})', '', d)}"
  619. PKG:${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
  620. RPROVIDES:${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}"
  621. ALLOW_EMPTY:${KERNEL_PACKAGE_NAME} = "1"
  622. ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-base = "1"
  623. ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-image = "1"
  624. ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-modules = "1"
  625. DESCRIPTION:${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package"
  626. pkg_postinst:${KERNEL_PACKAGE_NAME}-base () {
  627. if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
  628. mkdir -p $D/lib/modules/${KERNEL_VERSION}
  629. fi
  630. if [ -n "$D" ]; then
  631. depmodwrapper -a -b $D ${KERNEL_VERSION} ${KERNEL_PACKAGE_NAME}
  632. else
  633. depmod -a ${KERNEL_VERSION}
  634. fi
  635. }
  636. PACKAGESPLITFUNCS =+ "split_kernel_packages"
  637. python split_kernel_packages () {
  638. do_split_packages(d, root='${nonarch_base_libdir}/firmware', file_regex=r'^(.*)\.(bin|fw|cis|csp|dsp)$', output_pattern='${KERNEL_PACKAGE_NAME}-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
  639. }
  640. # Many scripts want to look in arch/$arch/boot for the bootable
  641. # image. This poses a problem for vmlinux and vmlinuz based
  642. # booting. This task arranges to have vmlinux and vmlinuz appear
  643. # in the normalized directory location.
  644. do_kernel_link_images() {
  645. if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
  646. mkdir ${B}/arch/${ARCH}/boot
  647. fi
  648. cd ${B}/arch/${ARCH}/boot
  649. ln -sf ../../../vmlinux
  650. if [ -f ../../../vmlinuz ]; then
  651. ln -sf ../../../vmlinuz
  652. fi
  653. if [ -f ../../../vmlinuz.bin ]; then
  654. ln -sf ../../../vmlinuz.bin
  655. fi
  656. if [ -f ../../../vmlinux.64 ]; then
  657. ln -sf ../../../vmlinux.64
  658. fi
  659. }
  660. addtask kernel_link_images after do_compile before do_strip
  661. python do_strip() {
  662. import shutil
  663. strip = d.getVar('KERNEL_STRIP')
  664. extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS')
  665. kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux"
  666. if (extra_sections and kernel_image.find(d.getVar('KERNEL_IMAGEDEST') + '/vmlinux') != -1):
  667. kernel_image_stripped = kernel_image + ".stripped"
  668. shutil.copy2(kernel_image, kernel_image_stripped)
  669. oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections))
  670. bb.debug(1, "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \
  671. extra_sections)
  672. }
  673. do_strip[dirs] = "${B}"
  674. addtask strip before do_sizecheck after do_kernel_link_images
  675. # Support checking the kernel size since some kernels need to reside in partitions
  676. # with a fixed length or there is a limit in transferring the kernel to memory.
  677. # If more than one image type is enabled, warn on any that don't fit but only fail
  678. # if none fit.
  679. do_sizecheck() {
  680. if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
  681. invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
  682. if [ -n "$invalid" ]; then
  683. die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)"
  684. fi
  685. at_least_one_fits=
  686. for imageType in ${KERNEL_IMAGETYPES} ; do
  687. size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'`
  688. if [ $size -gt ${KERNEL_IMAGE_MAXSIZE} ]; then
  689. bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device."
  690. else
  691. at_least_one_fits=y
  692. fi
  693. done
  694. if [ -z "$at_least_one_fits" ]; then
  695. die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular."
  696. fi
  697. fi
  698. }
  699. do_sizecheck[dirs] = "${B}"
  700. addtask sizecheck before do_install after do_strip
  701. inherit kernel-artifact-names
  702. kernel_do_deploy() {
  703. deployDir="${DEPLOYDIR}"
  704. if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then
  705. deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}"
  706. mkdir "$deployDir"
  707. fi
  708. for imageType in ${KERNEL_IMAGETYPES} ; do
  709. baseName=$imageType-${KERNEL_IMAGE_NAME}
  710. if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then
  711. install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
  712. else
  713. install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
  714. fi
  715. if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then
  716. ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
  717. fi
  718. if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then
  719. ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType
  720. fi
  721. done
  722. if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
  723. mkdir -p ${D}${root_prefix}/lib
  724. if [ -n "${SOURCE_DATE_EPOCH}" ]; then
  725. TAR_ARGS="--sort=name --clamp-mtime --mtime=@${SOURCE_DATE_EPOCH}"
  726. else
  727. TAR_ARGS=""
  728. fi
  729. TAR_ARGS="$TAR_ARGS --owner=0 --group=0"
  730. tar $TAR_ARGS -cv -C ${D}${root_prefix} lib | gzip -9n > $deployDir/modules-${MODULE_TARBALL_NAME}.tgz
  731. if [ -n "${MODULE_TARBALL_LINK_NAME}" ] ; then
  732. ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz
  733. fi
  734. fi
  735. if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
  736. for imageType in ${KERNEL_IMAGETYPES} ; do
  737. if [ "$imageType" = "fitImage" ] ; then
  738. continue
  739. fi
  740. initramfsBaseName=$imageType-${INITRAMFS_NAME}
  741. install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.initramfs $deployDir/$initramfsBaseName${KERNEL_IMAGE_BIN_EXT}
  742. if [ -n "${INITRAMFS_LINK_NAME}" ] ; then
  743. ln -sf $initramfsBaseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${INITRAMFS_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
  744. fi
  745. done
  746. fi
  747. }
  748. # We deploy to filenames that include PKGV and PKGR, read the saved data to
  749. # ensure we get the right values for both
  750. do_deploy[prefuncs] += "read_subpackage_metadata"
  751. addtask deploy after do_populate_sysroot do_packagedata
  752. EXPORT_FUNCTIONS do_deploy
  753. # Add using Device Tree support
  754. inherit kernel-devicetree