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 | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 2 | SRCTREECOVEREDTASKS += "do_kernel_configme do_validate_branches do_kernel_configcheck do_kernel_checkout do_shared_workdir do_fetch do_unpack do_patch" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 3 | |
| 4 | # returns local (absolute) path names for all valid patches in the |
| 5 | # src_uri |
| 6 | def find_patches(d): |
| 7 | patches = src_patches(d) |
| 8 | patch_list=[] |
| 9 | for p in patches: |
| 10 | _, _, local, _, _, _ = bb.fetch.decodeurl(p) |
| 11 | patch_list.append(local) |
| 12 | |
| 13 | return patch_list |
| 14 | |
| 15 | # returns all the elements from the src uri that are .scc files |
| 16 | def find_sccs(d): |
| 17 | sources=src_patches(d, True) |
| 18 | sources_list=[] |
| 19 | for s in sources: |
| 20 | base, ext = os.path.splitext(os.path.basename(s)) |
| 21 | if ext and ext in [".scc", ".cfg"]: |
| 22 | sources_list.append(s) |
| 23 | elif base and base in 'defconfig': |
| 24 | sources_list.append(s) |
| 25 | |
| 26 | return sources_list |
| 27 | |
| 28 | # check the SRC_URI for "kmeta" type'd git repositories. Return the name of |
| 29 | # the repository as it will be found in WORKDIR |
| 30 | def find_kernel_feature_dirs(d): |
| 31 | feature_dirs=[] |
| 32 | fetch = bb.fetch2.Fetch([], d) |
| 33 | for url in fetch.urls: |
| 34 | urldata = fetch.ud[url] |
| 35 | parm = urldata.parm |
| 36 | type="" |
| 37 | if "type" in parm: |
| 38 | type = parm["type"] |
| 39 | if "destsuffix" in parm: |
| 40 | destdir = parm["destsuffix"] |
| 41 | if type == "kmeta": |
| 42 | feature_dirs.append(destdir) |
| 43 | |
| 44 | return feature_dirs |
| 45 | |
| 46 | # find the master/machine source branch. In the same way that the fetcher proceses |
| 47 | # git repositories in the SRC_URI we take the first repo found, first branch. |
| 48 | def get_machine_branch(d, default): |
| 49 | fetch = bb.fetch2.Fetch([], d) |
| 50 | for url in fetch.urls: |
| 51 | urldata = fetch.ud[url] |
| 52 | parm = urldata.parm |
| 53 | if "branch" in parm: |
| 54 | branches = urldata.parm.get("branch").split(',') |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 55 | btype = urldata.parm.get("type") |
| 56 | if btype != "kmeta": |
| 57 | return branches[0] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | |
| 59 | return default |
| 60 | |
| 61 | do_kernel_metadata() { |
| 62 | set +e |
| 63 | cd ${S} |
| 64 | export KMETA=${KMETA} |
| 65 | |
| 66 | # if kernel tools are available in-tree, they are preferred |
| 67 | # and are placed on the path before any external tools. Unless |
| 68 | # the external tools flag is set, in that case we do nothing. |
| 69 | if [ -f "${S}/scripts/util/configme" ]; then |
| 70 | if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then |
| 71 | PATH=${S}/scripts/util:${PATH} |
| 72 | fi |
| 73 | fi |
| 74 | |
| 75 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 76 | machine_srcrev="${SRCREV_machine}" |
| 77 | if [ -z "${machine_srcrev}" ]; then |
| 78 | # fallback to SRCREV if a non machine_meta tree is being built |
| 79 | machine_srcrev="${SRCREV}" |
| 80 | fi |
| 81 | |
| 82 | # In a similar manner to the kernel itself: |
| 83 | # |
| 84 | # defconfig: $(obj)/conf |
| 85 | # ifeq ($(KBUILD_DEFCONFIG),) |
| 86 | # $< --defconfig $(Kconfig) |
| 87 | # else |
| 88 | # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'" |
| 89 | # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig) |
| 90 | # endif |
| 91 | # |
| 92 | # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it |
| 93 | # from the source tree, into a common location and normalized "defconfig" name, |
| 94 | # where the rest of the process will include and incoroporate it into the build |
| 95 | # |
| 96 | # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI), |
| 97 | # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take |
| 98 | # precendence. |
| 99 | # |
| 100 | if [ -n "${KBUILD_DEFCONFIG}" ]; then |
| 101 | if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then |
| 102 | if [ -f "${WORKDIR}/defconfig" ]; then |
| 103 | # If the two defconfig's are different, warn that we didn't overwrite the |
| 104 | # one already placed in WORKDIR by the fetcher. |
| 105 | cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" |
| 106 | if [ $? -ne 0 ]; then |
| 107 | bbwarn "defconfig detected in WORKDIR. ${KBUILD_DEFCONFIG} skipped" |
| 108 | fi |
| 109 | else |
| 110 | cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig |
| 111 | sccs="${WORKDIR}/defconfig" |
| 112 | fi |
| 113 | else |
| 114 | bbfatal "A KBUILD_DECONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree" |
| 115 | fi |
| 116 | fi |
| 117 | |
| 118 | sccs="$sccs ${@" ".join(find_sccs(d))}" |
| 119 | patches="${@" ".join(find_patches(d))}" |
| 120 | feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}" |
| 121 | |
| 122 | # add any explicitly referenced features onto the end of the feature |
| 123 | # list that is passed to the kernel build scripts. |
| 124 | if [ -n "${KERNEL_FEATURES}" ]; then |
| 125 | for feat in ${KERNEL_FEATURES}; do |
| 126 | addon_features="$addon_features --feature $feat" |
| 127 | done |
| 128 | fi |
| 129 | |
| 130 | # check for feature directories/repos/branches that were part of the |
| 131 | # SRC_URI. If they were supplied, we convert them into include directives |
| 132 | # for the update part of the process |
| 133 | if [ -n "${feat_dirs}" ]; then |
| 134 | for f in ${feat_dirs}; do |
| 135 | if [ -d "${WORKDIR}/$f/meta" ]; then |
| 136 | includes="$includes -I${WORKDIR}/$f/meta" |
| 137 | elif [ -d "${WORKDIR}/$f" ]; then |
| 138 | includes="$includes -I${WORKDIR}/$f" |
| 139 | fi |
| 140 | done |
| 141 | fi |
| 142 | |
| 143 | # updates or generates the target description |
| 144 | updateme ${updateme_flags} -DKDESC=${KMACHINE}:${LINUX_KERNEL_TYPE} \ |
| 145 | ${includes} ${addon_features} ${ARCH} ${KMACHINE} ${sccs} ${patches} |
| 146 | if [ $? -ne 0 ]; then |
| 147 | bbfatal_log "Could not update ${machine_branch}" |
| 148 | fi |
| 149 | } |
| 150 | |
| 151 | do_patch() { |
| 152 | cd ${S} |
| 153 | |
| 154 | # executes and modifies the source tree as required |
| 155 | patchme ${KMACHINE} |
| 156 | if [ $? -ne 0 ]; then |
| 157 | bberror "Could not apply patches for ${KMACHINE}." |
| 158 | bbfatal_log "Patch failures can be resolved in the linux source directory ${S})" |
| 159 | fi |
| 160 | |
| 161 | # check to see if the specified SRCREV is reachable from the final branch. |
| 162 | # if it wasn't something wrong has happened, and we should error. |
| 163 | machine_srcrev="${SRCREV_machine}" |
| 164 | if [ -z "${machine_srcrev}" ]; then |
| 165 | # fallback to SRCREV if a non machine_meta tree is being built |
| 166 | machine_srcrev="${SRCREV}" |
| 167 | # if SRCREV cannot be reached something is wrong. |
| 168 | if [ -z "${machine_srcrev}" ]; then |
| 169 | bbfatal "Neither SRCREV_machine or SRCREV was specified!" |
| 170 | fi |
| 171 | fi |
| 172 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 173 | current_branch=`git rev-parse --abbrev-ref HEAD` |
| 174 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 175 | if [ "${current_branch}" != "${machine_branch}" ]; then |
| 176 | bbwarn "After meta data application, the kernel tree branch is ${current_branch}. The" |
| 177 | bbwarn "SRC_URI specified branch ${machine_branch}. The branch will be forced to ${machine_branch}," |
| 178 | bbwarn "but this means the board meta data (.scc files) do not match the SRC_URI specification." |
| 179 | bbwarn "The meta data and branch ${machine_branch} should be inspected to ensure the proper" |
| 180 | bbwarn "kernel is being built." |
| 181 | git checkout -f ${machine_branch} |
| 182 | fi |
| 183 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | if [ "${machine_srcrev}" != "AUTOINC" ]; then |
| 185 | if ! [ "$(git rev-parse --verify ${machine_srcrev}~0)" = "$(git merge-base ${machine_srcrev} HEAD)" ]; then |
| 186 | bberror "SRCREV ${machine_srcrev} was specified, but is not reachable" |
| 187 | bbfatal "Check the BSP description for incorrect branch selection, or other errors." |
| 188 | fi |
| 189 | fi |
| 190 | } |
| 191 | |
| 192 | do_kernel_checkout() { |
| 193 | set +e |
| 194 | |
| 195 | source_dir=`echo ${S} | sed 's%/$%%'` |
| 196 | source_workdir="${WORKDIR}/git" |
| 197 | if [ -d "${WORKDIR}/git/" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 198 | # case: git repository |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree. |
| 200 | if [ "${source_dir}" != "${source_workdir}" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 201 | if [ -d "${source_workdir}/.git" ]; then |
| 202 | # regular git repository with .git |
| 203 | rm -rf ${S} |
| 204 | mv ${WORKDIR}/git ${S} |
| 205 | else |
| 206 | # create source for bare cloned git repository |
| 207 | git clone ${WORKDIR}/git ${S} |
| 208 | rm -rf ${WORKDIR}/git |
| 209 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 210 | fi |
| 211 | cd ${S} |
| 212 | else |
| 213 | # case: we have no git repository at all. |
| 214 | # To support low bandwidth options for building the kernel, we'll just |
| 215 | # convert the tree to a git repo and let the rest of the process work unchanged |
| 216 | |
| 217 | # if ${S} hasn't been set to the proper subdirectory a default of "linux" is |
| 218 | # used, but we can't initialize that empty directory. So check it and throw a |
| 219 | # clear error |
| 220 | |
| 221 | cd ${S} |
| 222 | if [ ! -f "Makefile" ]; then |
| 223 | bberror "S is not set to the linux source directory. Check " |
| 224 | bbfatal "the recipe and set S to the proper extracted subdirectory" |
| 225 | fi |
| 226 | rm -f .gitignore |
| 227 | git init |
| 228 | git add . |
| 229 | git commit -q -m "baseline commit: creating repo for ${PN}-${PV}" |
| 230 | git clean -d -f |
| 231 | fi |
| 232 | |
| 233 | # convert any remote branches to local tracking ones |
| 234 | for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do |
| 235 | b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`; |
| 236 | git show-ref --quiet --verify -- "refs/heads/$b" |
| 237 | if [ $? -ne 0 ]; then |
| 238 | git branch $b $i > /dev/null |
| 239 | fi |
| 240 | done |
| 241 | |
| 242 | # Create a working tree copy of the kernel by checking out a branch |
| 243 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 244 | |
| 245 | # checkout and clobber any unimportant files |
| 246 | git checkout -f ${machine_branch} |
| 247 | } |
| 248 | do_kernel_checkout[dirs] = "${S}" |
| 249 | |
| 250 | addtask kernel_checkout before do_kernel_metadata after do_unpack |
| 251 | addtask kernel_metadata after do_validate_branches do_unpack before do_patch |
| 252 | do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot" |
| 253 | |
| 254 | do_kernel_configme[dirs] += "${S} ${B}" |
| 255 | do_kernel_configme() { |
| 256 | bbnote "kernel configme" |
| 257 | export KMETA=${KMETA} |
| 258 | |
| 259 | if [ -n "${KCONFIG_MODE}" ]; then |
| 260 | configmeflags=${KCONFIG_MODE} |
| 261 | else |
| 262 | # If a defconfig was passed, use =n as the baseline, which is achieved |
| 263 | # via --allnoconfig |
| 264 | if [ -f ${WORKDIR}/defconfig ]; then |
| 265 | configmeflags="--allnoconfig" |
| 266 | fi |
| 267 | fi |
| 268 | |
| 269 | cd ${S} |
| 270 | PATH=${PATH}:${S}/scripts/util |
| 271 | configme ${configmeflags} --reconfig --output ${B} ${LINUX_KERNEL_TYPE} ${KMACHINE} |
| 272 | if [ $? -ne 0 ]; then |
| 273 | bbfatal_log "Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}" |
| 274 | fi |
| 275 | |
| 276 | echo "# Global settings from linux recipe" >> ${B}/.config |
| 277 | echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config |
| 278 | } |
| 279 | |
| 280 | addtask kernel_configme before do_configure after do_patch |
| 281 | |
| 282 | python do_kernel_configcheck() { |
| 283 | import re, string, sys |
| 284 | |
| 285 | # if KMETA isn't set globally by a recipe using this routine, we need to |
| 286 | # set the default to 'meta'. Otherwise, kconf_check is not passed a valid |
| 287 | # meta-series for processing |
| 288 | kmeta = d.getVar( "KMETA", True ) or "meta" |
| 289 | if not os.path.exists(kmeta): |
| 290 | kmeta = "." + kmeta |
| 291 | |
| 292 | pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH', True), "${S}/scripts/util/") |
| 293 | cmd = d.expand("cd ${S}; kconf_check -config %s/meta-series ${S} ${B}" % kmeta) |
| 294 | ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd)) |
| 295 | |
| 296 | config_check_visibility = int(d.getVar( "KCONF_AUDIT_LEVEL", True ) or 0) |
| 297 | bsp_check_visibility = int(d.getVar( "KCONF_BSP_AUDIT_LEVEL", True ) or 0) |
| 298 | |
| 299 | # if config check visibility is non-zero, report dropped configuration values |
| 300 | mismatch_file = "${S}/" + kmeta + "/" + "mismatch.cfg" |
| 301 | if os.path.exists(mismatch_file): |
| 302 | if config_check_visibility: |
| 303 | with open (mismatch_file, "r") as myfile: |
| 304 | results = myfile.read() |
| 305 | bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results) |
| 306 | |
| 307 | # if config check visibility is level 2 or higher, report non-hardware options |
| 308 | nonhw_file = "${S}/" + kmeta + "/" + "nonhw_report.cfg" |
| 309 | if os.path.exists(nonhw_file): |
| 310 | if config_check_visibility > 1: |
| 311 | with open (nonhw_file, "r") as myfile: |
| 312 | results = myfile.read() |
| 313 | bb.warn( "[kernel config]: BSP specified non-hw configuration:\n\n%s" % results) |
| 314 | |
| 315 | bsp_desc = "${S}/" + kmeta + "/" + "top_tgt" |
| 316 | if os.path.exists(bsp_desc) and bsp_check_visibility > 1: |
| 317 | with open (bsp_desc, "r") as myfile: |
| 318 | bsp_tgt = myfile.read() |
| 319 | m = re.match("^(.*)scratch.obj(.*)$", bsp_tgt) |
| 320 | if not m is None: |
| 321 | bb.warn( "[kernel]: An auto generated BSP description was used, this normally indicates a misconfiguration.\n" + |
| 322 | "Check that your machine (%s) has an associated kernel description." % "${MACHINE}" ) |
| 323 | } |
| 324 | |
| 325 | # Ensure that the branches (BSP and meta) are on the locations specified by |
| 326 | # their SRCREV values. If they are NOT on the right commits, the branches |
| 327 | # are corrected to the proper commit. |
| 328 | do_validate_branches() { |
| 329 | set +e |
| 330 | cd ${S} |
| 331 | |
| 332 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 333 | machine_srcrev="${SRCREV_machine}" |
| 334 | |
| 335 | # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to |
| 336 | # check and we can exit early |
| 337 | if [ "${machine_srcrev}" = "AUTOINC" ]; then |
| 338 | bbnote "SRCREV validation is not required for AUTOREV" |
| 339 | elif [ "${machine_srcrev}" = "" ]; then |
| 340 | if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then |
| 341 | # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe |
| 342 | # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In |
| 343 | # this case, we need to reset to the give SRCREV before heading to patching |
| 344 | bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}" |
| 345 | force_srcrev="${SRCREV}" |
| 346 | fi |
| 347 | else |
| 348 | git cat-file -t ${machine_srcrev} > /dev/null |
| 349 | if [ $? -ne 0 ]; then |
| 350 | bberror "${machine_srcrev} is not a valid commit ID." |
| 351 | bbfatal_log "The kernel source tree may be out of sync" |
| 352 | fi |
| 353 | force_srcrev=${machine_srcrev} |
| 354 | fi |
| 355 | |
| 356 | git checkout -q -f ${machine_branch} |
| 357 | if [ -n "${force_srcrev}" ]; then |
| 358 | # see if the branch we are about to patch has been properly reset to the defined |
| 359 | # SRCREV .. if not, we reset it. |
| 360 | branch_head=`git rev-parse HEAD` |
| 361 | if [ "${force_srcrev}" != "${branch_head}" ]; then |
| 362 | current_branch=`git rev-parse --abbrev-ref HEAD` |
| 363 | git branch "$current_branch-orig" |
| 364 | git reset --hard ${force_srcrev} |
| 365 | fi |
| 366 | fi |
| 367 | } |
| 368 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 369 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 370 | KBUILD_OUTPUT = "${B}" |
| 371 | |
| 372 | python () { |
| 373 | # If diffconfig is available, ensure it runs after kernel_configme |
| 374 | if 'do_diffconfig' in d: |
| 375 | bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d) |
| 376 | } |