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