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 |
| 2 | SRCTREECOVEREDTASKS += "do_kernel_link_vmlinux do_kernel_configme do_validate_branches do_kernel_configcheck do_kernel_checkout do_shared_workdir do_fetch do_unpack do_patch" |
| 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 | |
| 173 | if [ "${machine_srcrev}" != "AUTOINC" ]; then |
| 174 | if ! [ "$(git rev-parse --verify ${machine_srcrev}~0)" = "$(git merge-base ${machine_srcrev} HEAD)" ]; then |
| 175 | bberror "SRCREV ${machine_srcrev} was specified, but is not reachable" |
| 176 | bbfatal "Check the BSP description for incorrect branch selection, or other errors." |
| 177 | fi |
| 178 | fi |
| 179 | } |
| 180 | |
| 181 | do_kernel_checkout() { |
| 182 | set +e |
| 183 | |
| 184 | source_dir=`echo ${S} | sed 's%/$%%'` |
| 185 | source_workdir="${WORKDIR}/git" |
| 186 | if [ -d "${WORKDIR}/git/" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 187 | # case: git repository |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 188 | # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree. |
| 189 | if [ "${source_dir}" != "${source_workdir}" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 190 | if [ -d "${source_workdir}/.git" ]; then |
| 191 | # regular git repository with .git |
| 192 | rm -rf ${S} |
| 193 | mv ${WORKDIR}/git ${S} |
| 194 | else |
| 195 | # create source for bare cloned git repository |
| 196 | git clone ${WORKDIR}/git ${S} |
| 197 | rm -rf ${WORKDIR}/git |
| 198 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 199 | fi |
| 200 | cd ${S} |
| 201 | else |
| 202 | # case: we have no git repository at all. |
| 203 | # To support low bandwidth options for building the kernel, we'll just |
| 204 | # convert the tree to a git repo and let the rest of the process work unchanged |
| 205 | |
| 206 | # if ${S} hasn't been set to the proper subdirectory a default of "linux" is |
| 207 | # used, but we can't initialize that empty directory. So check it and throw a |
| 208 | # clear error |
| 209 | |
| 210 | cd ${S} |
| 211 | if [ ! -f "Makefile" ]; then |
| 212 | bberror "S is not set to the linux source directory. Check " |
| 213 | bbfatal "the recipe and set S to the proper extracted subdirectory" |
| 214 | fi |
| 215 | rm -f .gitignore |
| 216 | git init |
| 217 | git add . |
| 218 | git commit -q -m "baseline commit: creating repo for ${PN}-${PV}" |
| 219 | git clean -d -f |
| 220 | fi |
| 221 | |
| 222 | # convert any remote branches to local tracking ones |
| 223 | for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do |
| 224 | b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`; |
| 225 | git show-ref --quiet --verify -- "refs/heads/$b" |
| 226 | if [ $? -ne 0 ]; then |
| 227 | git branch $b $i > /dev/null |
| 228 | fi |
| 229 | done |
| 230 | |
| 231 | # Create a working tree copy of the kernel by checking out a branch |
| 232 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 233 | |
| 234 | # checkout and clobber any unimportant files |
| 235 | git checkout -f ${machine_branch} |
| 236 | } |
| 237 | do_kernel_checkout[dirs] = "${S}" |
| 238 | |
| 239 | addtask kernel_checkout before do_kernel_metadata after do_unpack |
| 240 | addtask kernel_metadata after do_validate_branches do_unpack before do_patch |
| 241 | do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot" |
| 242 | |
| 243 | do_kernel_configme[dirs] += "${S} ${B}" |
| 244 | do_kernel_configme() { |
| 245 | bbnote "kernel configme" |
| 246 | export KMETA=${KMETA} |
| 247 | |
| 248 | if [ -n "${KCONFIG_MODE}" ]; then |
| 249 | configmeflags=${KCONFIG_MODE} |
| 250 | else |
| 251 | # If a defconfig was passed, use =n as the baseline, which is achieved |
| 252 | # via --allnoconfig |
| 253 | if [ -f ${WORKDIR}/defconfig ]; then |
| 254 | configmeflags="--allnoconfig" |
| 255 | fi |
| 256 | fi |
| 257 | |
| 258 | cd ${S} |
| 259 | PATH=${PATH}:${S}/scripts/util |
| 260 | configme ${configmeflags} --reconfig --output ${B} ${LINUX_KERNEL_TYPE} ${KMACHINE} |
| 261 | if [ $? -ne 0 ]; then |
| 262 | bbfatal_log "Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}" |
| 263 | fi |
| 264 | |
| 265 | echo "# Global settings from linux recipe" >> ${B}/.config |
| 266 | echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config |
| 267 | } |
| 268 | |
| 269 | addtask kernel_configme before do_configure after do_patch |
| 270 | |
| 271 | python do_kernel_configcheck() { |
| 272 | import re, string, sys |
| 273 | |
| 274 | # if KMETA isn't set globally by a recipe using this routine, we need to |
| 275 | # set the default to 'meta'. Otherwise, kconf_check is not passed a valid |
| 276 | # meta-series for processing |
| 277 | kmeta = d.getVar( "KMETA", True ) or "meta" |
| 278 | if not os.path.exists(kmeta): |
| 279 | kmeta = "." + kmeta |
| 280 | |
| 281 | pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH', True), "${S}/scripts/util/") |
| 282 | cmd = d.expand("cd ${S}; kconf_check -config %s/meta-series ${S} ${B}" % kmeta) |
| 283 | ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd)) |
| 284 | |
| 285 | config_check_visibility = int(d.getVar( "KCONF_AUDIT_LEVEL", True ) or 0) |
| 286 | bsp_check_visibility = int(d.getVar( "KCONF_BSP_AUDIT_LEVEL", True ) or 0) |
| 287 | |
| 288 | # if config check visibility is non-zero, report dropped configuration values |
| 289 | mismatch_file = "${S}/" + kmeta + "/" + "mismatch.cfg" |
| 290 | if os.path.exists(mismatch_file): |
| 291 | if config_check_visibility: |
| 292 | with open (mismatch_file, "r") as myfile: |
| 293 | results = myfile.read() |
| 294 | bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results) |
| 295 | |
| 296 | # if config check visibility is level 2 or higher, report non-hardware options |
| 297 | nonhw_file = "${S}/" + kmeta + "/" + "nonhw_report.cfg" |
| 298 | if os.path.exists(nonhw_file): |
| 299 | if config_check_visibility > 1: |
| 300 | with open (nonhw_file, "r") as myfile: |
| 301 | results = myfile.read() |
| 302 | bb.warn( "[kernel config]: BSP specified non-hw configuration:\n\n%s" % results) |
| 303 | |
| 304 | bsp_desc = "${S}/" + kmeta + "/" + "top_tgt" |
| 305 | if os.path.exists(bsp_desc) and bsp_check_visibility > 1: |
| 306 | with open (bsp_desc, "r") as myfile: |
| 307 | bsp_tgt = myfile.read() |
| 308 | m = re.match("^(.*)scratch.obj(.*)$", bsp_tgt) |
| 309 | if not m is None: |
| 310 | bb.warn( "[kernel]: An auto generated BSP description was used, this normally indicates a misconfiguration.\n" + |
| 311 | "Check that your machine (%s) has an associated kernel description." % "${MACHINE}" ) |
| 312 | } |
| 313 | |
| 314 | # Ensure that the branches (BSP and meta) are on the locations specified by |
| 315 | # their SRCREV values. If they are NOT on the right commits, the branches |
| 316 | # are corrected to the proper commit. |
| 317 | do_validate_branches() { |
| 318 | set +e |
| 319 | cd ${S} |
| 320 | |
| 321 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 322 | machine_srcrev="${SRCREV_machine}" |
| 323 | |
| 324 | # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to |
| 325 | # check and we can exit early |
| 326 | if [ "${machine_srcrev}" = "AUTOINC" ]; then |
| 327 | bbnote "SRCREV validation is not required for AUTOREV" |
| 328 | elif [ "${machine_srcrev}" = "" ]; then |
| 329 | if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then |
| 330 | # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe |
| 331 | # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In |
| 332 | # this case, we need to reset to the give SRCREV before heading to patching |
| 333 | bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}" |
| 334 | force_srcrev="${SRCREV}" |
| 335 | fi |
| 336 | else |
| 337 | git cat-file -t ${machine_srcrev} > /dev/null |
| 338 | if [ $? -ne 0 ]; then |
| 339 | bberror "${machine_srcrev} is not a valid commit ID." |
| 340 | bbfatal_log "The kernel source tree may be out of sync" |
| 341 | fi |
| 342 | force_srcrev=${machine_srcrev} |
| 343 | fi |
| 344 | |
| 345 | git checkout -q -f ${machine_branch} |
| 346 | if [ -n "${force_srcrev}" ]; then |
| 347 | # see if the branch we are about to patch has been properly reset to the defined |
| 348 | # SRCREV .. if not, we reset it. |
| 349 | branch_head=`git rev-parse HEAD` |
| 350 | if [ "${force_srcrev}" != "${branch_head}" ]; then |
| 351 | current_branch=`git rev-parse --abbrev-ref HEAD` |
| 352 | git branch "$current_branch-orig" |
| 353 | git reset --hard ${force_srcrev} |
| 354 | fi |
| 355 | fi |
| 356 | } |
| 357 | |
| 358 | # Many scripts want to look in arch/$arch/boot for the bootable |
| 359 | # image. This poses a problem for vmlinux based booting. This |
| 360 | # task arranges to have vmlinux appear in the normalized directory |
| 361 | # location. |
| 362 | do_kernel_link_vmlinux() { |
| 363 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then |
| 364 | mkdir ${B}/arch/${ARCH}/boot |
| 365 | fi |
| 366 | cd ${B}/arch/${ARCH}/boot |
| 367 | ln -sf ../../../vmlinux |
| 368 | } |
| 369 | |
| 370 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 371 | KBUILD_OUTPUT = "${B}" |
| 372 | |
| 373 | python () { |
| 374 | # If diffconfig is available, ensure it runs after kernel_configme |
| 375 | if 'do_diffconfig' in d: |
| 376 | bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d) |
| 377 | } |