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