Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # remove tasks that modify the source tree in case externalsrc is inherited |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | SRCTREECOVEREDTASKS += "do_validate_branches do_kernel_configcheck do_kernel_checkout do_fetch do_unpack do_patch" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 3 | PATCH_GIT_USER_EMAIL ?= "kernel-yocto@oe" |
| 4 | PATCH_GIT_USER_NAME ?= "OpenEmbedded" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 6 | # The distro or local.conf should set this, but if nobody cares... |
| 7 | LINUX_KERNEL_TYPE ??= "standard" |
| 8 | |
| 9 | # KMETA ?= "" |
| 10 | KBRANCH ?= "master" |
| 11 | KMACHINE ?= "${MACHINE}" |
| 12 | SRCREV_FORMAT ?= "meta_machine" |
| 13 | |
| 14 | # LEVELS: |
| 15 | # 0: no reporting |
| 16 | # 1: report options that are specified, but not in the final config |
| 17 | # 2: report options that are not hardware related, but set by a BSP |
| 18 | KCONF_AUDIT_LEVEL ?= "1" |
| 19 | KCONF_BSP_AUDIT_LEVEL ?= "0" |
| 20 | KMETA_AUDIT ?= "yes" |
| 21 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | # returns local (absolute) path names for all valid patches in the |
| 23 | # src_uri |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 24 | def find_patches(d,subdir): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | patches = src_patches(d) |
| 26 | patch_list=[] |
| 27 | for p in patches: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 28 | _, _, local, _, _, parm = bb.fetch.decodeurl(p) |
| 29 | # if patchdir has been passed, we won't be able to apply it so skip |
| 30 | # the patch for now, and special processing happens later |
| 31 | patchdir = '' |
| 32 | if "patchdir" in parm: |
| 33 | patchdir = parm["patchdir"] |
| 34 | if subdir: |
| 35 | if subdir == patchdir: |
| 36 | patch_list.append(local) |
| 37 | else: |
| 38 | patch_list.append(local) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | |
| 40 | return patch_list |
| 41 | |
| 42 | # returns all the elements from the src uri that are .scc files |
| 43 | def find_sccs(d): |
| 44 | sources=src_patches(d, True) |
| 45 | sources_list=[] |
| 46 | for s in sources: |
| 47 | base, ext = os.path.splitext(os.path.basename(s)) |
| 48 | if ext and ext in [".scc", ".cfg"]: |
| 49 | sources_list.append(s) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 50 | elif base and 'defconfig' in base: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | sources_list.append(s) |
| 52 | |
| 53 | return sources_list |
| 54 | |
| 55 | # check the SRC_URI for "kmeta" type'd git repositories. Return the name of |
| 56 | # the repository as it will be found in WORKDIR |
| 57 | def find_kernel_feature_dirs(d): |
| 58 | feature_dirs=[] |
| 59 | fetch = bb.fetch2.Fetch([], d) |
| 60 | for url in fetch.urls: |
| 61 | urldata = fetch.ud[url] |
| 62 | parm = urldata.parm |
| 63 | type="" |
| 64 | if "type" in parm: |
| 65 | type = parm["type"] |
| 66 | if "destsuffix" in parm: |
| 67 | destdir = parm["destsuffix"] |
| 68 | if type == "kmeta": |
| 69 | feature_dirs.append(destdir) |
| 70 | |
| 71 | return feature_dirs |
| 72 | |
| 73 | # find the master/machine source branch. In the same way that the fetcher proceses |
| 74 | # git repositories in the SRC_URI we take the first repo found, first branch. |
| 75 | def get_machine_branch(d, default): |
| 76 | fetch = bb.fetch2.Fetch([], d) |
| 77 | for url in fetch.urls: |
| 78 | urldata = fetch.ud[url] |
| 79 | parm = urldata.parm |
| 80 | if "branch" in parm: |
| 81 | branches = urldata.parm.get("branch").split(',') |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 82 | btype = urldata.parm.get("type") |
| 83 | if btype != "kmeta": |
| 84 | return branches[0] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | |
| 86 | return default |
| 87 | |
| 88 | do_kernel_metadata() { |
| 89 | set +e |
| 90 | cd ${S} |
| 91 | export KMETA=${KMETA} |
| 92 | |
| 93 | # if kernel tools are available in-tree, they are preferred |
| 94 | # and are placed on the path before any external tools. Unless |
| 95 | # the external tools flag is set, in that case we do nothing. |
| 96 | if [ -f "${S}/scripts/util/configme" ]; then |
| 97 | if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then |
| 98 | PATH=${S}/scripts/util:${PATH} |
| 99 | fi |
| 100 | fi |
| 101 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | # In a similar manner to the kernel itself: |
| 103 | # |
| 104 | # defconfig: $(obj)/conf |
| 105 | # ifeq ($(KBUILD_DEFCONFIG),) |
| 106 | # $< --defconfig $(Kconfig) |
| 107 | # else |
| 108 | # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'" |
| 109 | # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig) |
| 110 | # endif |
| 111 | # |
| 112 | # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it |
| 113 | # from the source tree, into a common location and normalized "defconfig" name, |
| 114 | # where the rest of the process will include and incoroporate it into the build |
| 115 | # |
| 116 | # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI), |
| 117 | # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take |
| 118 | # precendence. |
| 119 | # |
| 120 | if [ -n "${KBUILD_DEFCONFIG}" ]; then |
| 121 | if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then |
| 122 | if [ -f "${WORKDIR}/defconfig" ]; then |
| 123 | # If the two defconfig's are different, warn that we didn't overwrite the |
| 124 | # one already placed in WORKDIR by the fetcher. |
| 125 | cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" |
| 126 | if [ $? -ne 0 ]; then |
| 127 | bbwarn "defconfig detected in WORKDIR. ${KBUILD_DEFCONFIG} skipped" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 128 | else |
| 129 | cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | fi |
| 131 | else |
| 132 | cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 134 | sccs="${WORKDIR}/defconfig" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | else |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 136 | bbfatal "A KBUILD_DEFCONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | fi |
| 138 | fi |
| 139 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 140 | # was anyone trying to patch the kernel meta data ?, we need to do |
| 141 | # this here, since the scc commands migrate the .cfg fragments to the |
| 142 | # kernel source tree, where they'll be used later. |
| 143 | check_git_config |
| 144 | patches="${@" ".join(find_patches(d,'kernel-meta'))}" |
| 145 | for p in $patches; do |
| 146 | ( |
| 147 | cd ${WORKDIR}/kernel-meta |
| 148 | git am -s $p |
| 149 | ) |
| 150 | done |
| 151 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 152 | sccs_from_src_uri="${@" ".join(find_sccs(d))}" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 153 | patches="${@" ".join(find_patches(d,''))}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}" |
| 155 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 156 | # a quick check to make sure we don't have duplicate defconfigs |
| 157 | # If there's a defconfig in the SRC_URI, did we also have one from |
| 158 | # the KBUILD_DEFCONFIG processing above ? |
| 159 | if [ -n "$sccs" ]; then |
| 160 | # we did have a defconfig from above. remove any that might be in the src_uri |
| 161 | sccs_from_src_uri=$(echo $sccs_from_src_uri | awk '{ if ($0!="defconfig") { print $0 } }' RS=' ') |
| 162 | fi |
| 163 | sccs="$sccs $sccs_from_src_uri" |
| 164 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | # check for feature directories/repos/branches that were part of the |
| 166 | # SRC_URI. If they were supplied, we convert them into include directives |
| 167 | # for the update part of the process |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 168 | for f in ${feat_dirs}; do |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 169 | if [ -d "${WORKDIR}/$f/meta" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 170 | includes="$includes -I${WORKDIR}/$f/kernel-meta" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 171 | elif [ -d "${WORKDIR}/../oe-local-files/$f" ]; then |
| 172 | includes="$includes -I${WORKDIR}/../oe-local-files/$f" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 173 | elif [ -d "${WORKDIR}/$f" ]; then |
| 174 | includes="$includes -I${WORKDIR}/$f" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 175 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 176 | done |
| 177 | for s in ${sccs} ${patches}; do |
| 178 | sdir=$(dirname $s) |
| 179 | includes="$includes -I${sdir}" |
| 180 | # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta", |
| 181 | # then we add it to the search path |
| 182 | if [ -d "${sdir}/kernel-meta" ]; then |
| 183 | includes="$includes -I${sdir}/kernel-meta" |
| 184 | fi |
| 185 | done |
| 186 | |
| 187 | # expand kernel features into their full path equivalents |
| 188 | bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE}) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 189 | if [ -z "$bsp_definition" ]; then |
| 190 | echo "$sccs" | grep -q defconfig |
| 191 | if [ $? -ne 0 ]; then |
| 192 | bbfatal_log "Could not locate BSP definition for ${KMACHINE}/${LINUX_KERNEL_TYPE} and no defconfig was provided" |
| 193 | fi |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 194 | |
| 195 | # if the bsp definition has "define KMETA_EXTERNAL_BSP t", |
| 196 | # then we need to set a flag that will instruct the next |
| 197 | # steps to use the BSP as both configuration and patches. |
| 198 | grep -q KMETA_EXTERNAL_BSP $bsp_definition |
| 199 | if [ $? -eq 0 ]; then |
| 200 | KMETA_EXTERNAL_BSPS="t" |
| 201 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 202 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 203 | meta_dir=$(kgit --meta) |
| 204 | |
| 205 | # run1: pull all the configuration fragments, no matter where they come from |
| 206 | elements="`echo -n ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES}`" |
| 207 | if [ -n "${elements}" ]; then |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 208 | echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition |
| 209 | scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES} |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 210 | if [ $? -ne 0 ]; then |
| 211 | bbfatal_log "Could not generate configuration queue for ${KMACHINE}." |
| 212 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 213 | fi |
| 214 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 215 | # if KMETA_EXTERNAL_BSPS has been set, or it has been detected from |
| 216 | # the bsp definition, then we inject the bsp_definition into the |
| 217 | # patch phase below. we'll piggy back on the sccs variable. |
| 218 | if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then |
| 219 | sccs="${bsp_definition} ${sccs}" |
| 220 | fi |
| 221 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 222 | # run2: only generate patches for elements that have been passed on the SRC_URI |
| 223 | elements="`echo -n ${sccs} ${patches} ${KERNEL_FEATURES}`" |
| 224 | if [ -n "${elements}" ]; then |
| 225 | scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} ${KERNEL_FEATURES} |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 226 | if [ $? -ne 0 ]; then |
| 227 | bbfatal_log "Could not generate configuration queue for ${KMACHINE}." |
| 228 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | fi |
| 230 | } |
| 231 | |
| 232 | do_patch() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 233 | set +e |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | cd ${S} |
| 235 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 236 | check_git_config |
| 237 | meta_dir=$(kgit --meta) |
| 238 | (cd ${meta_dir}; ln -sf patch.queue series) |
| 239 | if [ -f "${meta_dir}/series" ]; then |
| 240 | kgit-s2q --gen -v --patches .kernel-meta/ |
| 241 | if [ $? -ne 0 ]; then |
| 242 | bberror "Could not apply patches for ${KMACHINE}." |
| 243 | bbfatal_log "Patch failures can be resolved in the linux source directory ${S})" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | fi |
| 245 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 246 | |
| 247 | if [ -f "${meta_dir}/merge.queue" ]; then |
| 248 | # we need to merge all these branches |
| 249 | for b in $(cat ${meta_dir}/merge.queue); do |
| 250 | git show-ref --verify --quiet refs/heads/${b} |
| 251 | if [ $? -eq 0 ]; then |
| 252 | bbnote "Merging branch ${b}" |
| 253 | git merge -q --no-ff -m "Merge branch ${b}" ${b} |
| 254 | else |
| 255 | bbfatal "branch ${b} does not exist, cannot merge" |
| 256 | fi |
| 257 | done |
| 258 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | do_kernel_checkout() { |
| 262 | set +e |
| 263 | |
| 264 | source_dir=`echo ${S} | sed 's%/$%%'` |
| 265 | source_workdir="${WORKDIR}/git" |
| 266 | if [ -d "${WORKDIR}/git/" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 267 | # case: git repository |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 268 | # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree. |
| 269 | if [ "${source_dir}" != "${source_workdir}" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 270 | if [ -d "${source_workdir}/.git" ]; then |
| 271 | # regular git repository with .git |
| 272 | rm -rf ${S} |
| 273 | mv ${WORKDIR}/git ${S} |
| 274 | else |
| 275 | # create source for bare cloned git repository |
| 276 | git clone ${WORKDIR}/git ${S} |
| 277 | rm -rf ${WORKDIR}/git |
| 278 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 | fi |
| 280 | cd ${S} |
| 281 | else |
| 282 | # case: we have no git repository at all. |
| 283 | # To support low bandwidth options for building the kernel, we'll just |
| 284 | # convert the tree to a git repo and let the rest of the process work unchanged |
| 285 | |
| 286 | # if ${S} hasn't been set to the proper subdirectory a default of "linux" is |
| 287 | # used, but we can't initialize that empty directory. So check it and throw a |
| 288 | # clear error |
| 289 | |
| 290 | cd ${S} |
| 291 | if [ ! -f "Makefile" ]; then |
| 292 | bberror "S is not set to the linux source directory. Check " |
| 293 | bbfatal "the recipe and set S to the proper extracted subdirectory" |
| 294 | fi |
| 295 | rm -f .gitignore |
| 296 | git init |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 297 | check_git_config |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 298 | git add . |
| 299 | git commit -q -m "baseline commit: creating repo for ${PN}-${PV}" |
| 300 | git clean -d -f |
| 301 | fi |
| 302 | |
| 303 | # convert any remote branches to local tracking ones |
| 304 | for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do |
| 305 | b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`; |
| 306 | git show-ref --quiet --verify -- "refs/heads/$b" |
| 307 | if [ $? -ne 0 ]; then |
| 308 | git branch $b $i > /dev/null |
| 309 | fi |
| 310 | done |
| 311 | |
| 312 | # Create a working tree copy of the kernel by checking out a branch |
| 313 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 314 | |
| 315 | # checkout and clobber any unimportant files |
| 316 | git checkout -f ${machine_branch} |
| 317 | } |
| 318 | do_kernel_checkout[dirs] = "${S}" |
| 319 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 320 | addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 321 | addtask kernel_metadata after do_validate_branches do_unpack before do_patch |
| 322 | do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 323 | do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 324 | |
William A. Kennington III | 47649fa | 2018-06-28 12:34:29 -0700 | [diff] [blame] | 325 | do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}binutils:do_populate_sysroot" |
| 326 | do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}gcc:do_populate_sysroot" |
| 327 | do_kernel_configme[depends] += "bc-native:do_populate_sysroot bison-native:do_populate_sysroot" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 328 | do_kernel_configme[depends] += "kern-tools-native:do_populate_sysroot" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 329 | do_kernel_configme[dirs] += "${S} ${B}" |
| 330 | do_kernel_configme() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 331 | # translate the kconfig_mode into something that merge_config.sh |
| 332 | # understands |
| 333 | case ${KCONFIG_MODE} in |
| 334 | *allnoconfig) |
| 335 | config_flags="-n" |
| 336 | ;; |
| 337 | *alldefconfig) |
| 338 | config_flags="" |
| 339 | ;; |
| 340 | *) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 341 | if [ -f ${WORKDIR}/defconfig ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 342 | config_flags="-n" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 344 | ;; |
| 345 | esac |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 346 | |
| 347 | cd ${S} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 348 | |
| 349 | meta_dir=$(kgit --meta) |
| 350 | configs="$(scc --configs -o ${meta_dir})" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 351 | if [ $? -ne 0 ]; then |
| 352 | bberror "${configs}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 353 | bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)" |
| 354 | fi |
| 355 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 356 | CFLAGS="${CFLAGS} ${TOOLCHAIN_OPTIONS}" HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}" CC="${KERNEL_CC}" LD="${KERNEL_LD}" ARCH=${ARCH} merge_config.sh -O ${B} ${config_flags} ${configs} > ${meta_dir}/cfg/merge_config_build.log 2>&1 |
| 357 | if [ $? -ne 0 -o ! -f ${B}/.config ]; then |
| 358 | bberror "Could not generate a .config for ${KMACHINE}-${LINUX_KERNEL_TYPE}" |
| 359 | if [ ${KCONF_AUDIT_LEVEL} -gt 1 ]; then |
| 360 | bbfatal_log "`cat ${meta_dir}/cfg/merge_config_build.log`" |
| 361 | else |
| 362 | bbfatal_log "Details can be found at: ${S}/${meta_dir}/cfg/merge_config_build.log" |
| 363 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 364 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 365 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 366 | if [ ! -z "${LINUX_VERSION_EXTENSION}" ]; then |
| 367 | echo "# Global settings from linux recipe" >> ${B}/.config |
| 368 | echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config |
| 369 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | addtask kernel_configme before do_configure after do_patch |
| 373 | |
| 374 | python do_kernel_configcheck() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 375 | import re, string, sys, subprocess |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | |
| 377 | # if KMETA isn't set globally by a recipe using this routine, we need to |
| 378 | # set the default to 'meta'. Otherwise, kconf_check is not passed a valid |
| 379 | # meta-series for processing |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 380 | kmeta = d.getVar("KMETA") or "meta" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 381 | if not os.path.exists(kmeta): |
| 382 | kmeta = "." + kmeta |
| 383 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 384 | s = d.getVar('S') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 385 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 386 | env = os.environ.copy() |
| 387 | env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/") |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 388 | env['LD'] = "${KERNEL_LD}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 389 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 390 | try: |
| 391 | configs = subprocess.check_output(['scc', '--configs', '-o', s + '/.kernel-meta'], env=env).decode('utf-8') |
| 392 | except subprocess.CalledProcessError as e: |
| 393 | bb.fatal( "Cannot gather config fragments for audit: %s" % e.output.decode("utf-8") ) |
| 394 | |
| 395 | try: |
| 396 | subprocess.check_call(['kconf_check', '--report', '-o', |
| 397 | '%s/%s/cfg' % (s, kmeta), d.getVar('B') + '/.config', s, configs], cwd=s, env=env) |
| 398 | except subprocess.CalledProcessError: |
| 399 | # The configuration gathering can return different exit codes, but |
| 400 | # we interpret them based on the KCONF_AUDIT_LEVEL variable, so we catch |
| 401 | # everything here, and let the run continue. |
| 402 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 403 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 404 | config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0) |
| 405 | bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 406 | |
| 407 | # if config check visibility is non-zero, report dropped configuration values |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 408 | mismatch_file = d.expand("${S}/%s/cfg/mismatch.txt" % kmeta) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 409 | if os.path.exists(mismatch_file): |
| 410 | if config_check_visibility: |
| 411 | with open (mismatch_file, "r") as myfile: |
| 412 | results = myfile.read() |
| 413 | bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 414 | |
| 415 | if bsp_check_visibility: |
| 416 | invalid_file = d.expand("${S}/%s/cfg/invalid.cfg" % kmeta) |
| 417 | if os.path.exists(invalid_file) and os.stat(invalid_file).st_size > 0: |
| 418 | with open (invalid_file, "r") as myfile: |
| 419 | results = myfile.read() |
| 420 | bb.warn( "[kernel config]: This BSP sets config options that are not offered anywhere within this kernel:\n\n%s" % results) |
| 421 | errors_file = d.expand("${S}/%s/cfg/fragment_errors.txt" % kmeta) |
| 422 | if os.path.exists(errors_file) and os.stat(errors_file).st_size > 0: |
| 423 | with open (errors_file, "r") as myfile: |
| 424 | results = myfile.read() |
| 425 | bb.warn( "[kernel config]: This BSP contains fragments with errors:\n\n%s" % results) |
| 426 | |
| 427 | # if the audit level is greater than two, we report if a fragment has overriden |
| 428 | # a value from a base fragment. This is really only used for new kernel introduction |
| 429 | if bsp_check_visibility > 2: |
| 430 | redefinition_file = d.expand("${S}/%s/cfg/redefinition.txt" % kmeta) |
| 431 | if os.path.exists(redefinition_file) and os.stat(redefinition_file).st_size > 0: |
| 432 | with open (redefinition_file, "r") as myfile: |
| 433 | results = myfile.read() |
| 434 | bb.warn( "[kernel config]: This BSP has configuration options defined in more than one config, with differing values:\n\n%s" % results) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | # Ensure that the branches (BSP and meta) are on the locations specified by |
| 438 | # their SRCREV values. If they are NOT on the right commits, the branches |
| 439 | # are corrected to the proper commit. |
| 440 | do_validate_branches() { |
| 441 | set +e |
| 442 | cd ${S} |
| 443 | |
| 444 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 445 | machine_srcrev="${SRCREV_machine}" |
| 446 | |
| 447 | # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to |
| 448 | # check and we can exit early |
| 449 | if [ "${machine_srcrev}" = "AUTOINC" ]; then |
| 450 | bbnote "SRCREV validation is not required for AUTOREV" |
| 451 | elif [ "${machine_srcrev}" = "" ]; then |
| 452 | if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then |
| 453 | # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe |
| 454 | # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In |
| 455 | # this case, we need to reset to the give SRCREV before heading to patching |
| 456 | bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}" |
| 457 | force_srcrev="${SRCREV}" |
| 458 | fi |
| 459 | else |
| 460 | git cat-file -t ${machine_srcrev} > /dev/null |
| 461 | if [ $? -ne 0 ]; then |
| 462 | bberror "${machine_srcrev} is not a valid commit ID." |
| 463 | bbfatal_log "The kernel source tree may be out of sync" |
| 464 | fi |
| 465 | force_srcrev=${machine_srcrev} |
| 466 | fi |
| 467 | |
| 468 | git checkout -q -f ${machine_branch} |
| 469 | if [ -n "${force_srcrev}" ]; then |
| 470 | # see if the branch we are about to patch has been properly reset to the defined |
| 471 | # SRCREV .. if not, we reset it. |
| 472 | branch_head=`git rev-parse HEAD` |
| 473 | if [ "${force_srcrev}" != "${branch_head}" ]; then |
| 474 | current_branch=`git rev-parse --abbrev-ref HEAD` |
| 475 | git branch "$current_branch-orig" |
| 476 | git reset --hard ${force_srcrev} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 477 | # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check |
| 478 | # so the patches are applied as expected otherwise no patching |
| 479 | # would be done in some corner cases. |
| 480 | kgit-s2q --clean |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 481 | fi |
| 482 | fi |
| 483 | } |
| 484 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 485 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 486 | KBUILD_OUTPUT = "${B}" |
| 487 | |
| 488 | python () { |
| 489 | # If diffconfig is available, ensure it runs after kernel_configme |
| 490 | if 'do_diffconfig' in d: |
| 491 | bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 492 | |
| 493 | externalsrc = d.getVar('EXTERNALSRC') |
| 494 | if externalsrc: |
| 495 | # If we deltask do_patch, do_kernel_configme is left without |
| 496 | # dependencies and runs too early |
| 497 | d.setVarFlag('do_kernel_configme', 'deps', (d.getVarFlag('do_kernel_configme', 'deps', False) or []) + ['do_unpack']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 498 | } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 499 | |
| 500 | # extra tasks |
| 501 | addtask kernel_version_sanity_check after do_kernel_metadata do_kernel_checkout before do_compile |
| 502 | addtask validate_branches before do_patch after do_kernel_checkout |
| 503 | addtask kernel_configcheck after do_configure before do_compile |