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