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" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 21 | KMETA_AUDIT_WERROR ?= "" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 22 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | # returns local (absolute) path names for all valid patches in the |
| 24 | # src_uri |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 25 | def find_patches(d,subdir): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | patches = src_patches(d) |
| 27 | patch_list=[] |
| 28 | for p in patches: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 29 | _, _, local, _, _, parm = bb.fetch.decodeurl(p) |
| 30 | # if patchdir has been passed, we won't be able to apply it so skip |
| 31 | # the patch for now, and special processing happens later |
| 32 | patchdir = '' |
| 33 | if "patchdir" in parm: |
| 34 | patchdir = parm["patchdir"] |
| 35 | if subdir: |
| 36 | if subdir == patchdir: |
| 37 | patch_list.append(local) |
| 38 | else: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame^] | 39 | # skip the patch if a patchdir was supplied, it won't be handled |
| 40 | # properly |
| 41 | if not patchdir: |
| 42 | patch_list.append(local) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | |
| 44 | return patch_list |
| 45 | |
| 46 | # returns all the elements from the src uri that are .scc files |
| 47 | def find_sccs(d): |
| 48 | sources=src_patches(d, True) |
| 49 | sources_list=[] |
| 50 | for s in sources: |
| 51 | base, ext = os.path.splitext(os.path.basename(s)) |
| 52 | if ext and ext in [".scc", ".cfg"]: |
| 53 | sources_list.append(s) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 54 | elif base and 'defconfig' in base: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | sources_list.append(s) |
| 56 | |
| 57 | return sources_list |
| 58 | |
| 59 | # check the SRC_URI for "kmeta" type'd git repositories. Return the name of |
| 60 | # the repository as it will be found in WORKDIR |
| 61 | def find_kernel_feature_dirs(d): |
| 62 | feature_dirs=[] |
| 63 | fetch = bb.fetch2.Fetch([], d) |
| 64 | for url in fetch.urls: |
| 65 | urldata = fetch.ud[url] |
| 66 | parm = urldata.parm |
| 67 | type="" |
| 68 | if "type" in parm: |
| 69 | type = parm["type"] |
| 70 | if "destsuffix" in parm: |
| 71 | destdir = parm["destsuffix"] |
| 72 | if type == "kmeta": |
| 73 | feature_dirs.append(destdir) |
| 74 | |
| 75 | return feature_dirs |
| 76 | |
| 77 | # find the master/machine source branch. In the same way that the fetcher proceses |
| 78 | # git repositories in the SRC_URI we take the first repo found, first branch. |
| 79 | def get_machine_branch(d, default): |
| 80 | fetch = bb.fetch2.Fetch([], d) |
| 81 | for url in fetch.urls: |
| 82 | urldata = fetch.ud[url] |
| 83 | parm = urldata.parm |
| 84 | if "branch" in parm: |
| 85 | branches = urldata.parm.get("branch").split(',') |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 86 | btype = urldata.parm.get("type") |
| 87 | if btype != "kmeta": |
| 88 | return branches[0] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | |
| 90 | return default |
| 91 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 92 | # returns a list of all directories that are on FILESEXTRAPATHS (and |
| 93 | # hence available to the build) that contain .scc or .cfg files |
| 94 | def get_dirs_with_fragments(d): |
| 95 | extrapaths = [] |
| 96 | extrafiles = [] |
| 97 | extrapathsvalue = (d.getVar("FILESEXTRAPATHS") or "") |
| 98 | # Remove default flag which was used for checking |
| 99 | extrapathsvalue = extrapathsvalue.replace("__default:", "") |
| 100 | extrapaths = extrapathsvalue.split(":") |
| 101 | for path in extrapaths: |
| 102 | if path + ":True" not in extrafiles: |
| 103 | extrafiles.append(path + ":" + str(os.path.exists(path))) |
| 104 | |
| 105 | return " ".join(extrafiles) |
| 106 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | do_kernel_metadata() { |
| 108 | set +e |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 109 | |
| 110 | if [ -n "$1" ]; then |
| 111 | mode="$1" |
| 112 | else |
| 113 | mode="patch" |
| 114 | fi |
| 115 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | cd ${S} |
| 117 | export KMETA=${KMETA} |
| 118 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 119 | bbnote "do_kernel_metadata: for summary/debug, set KCONF_AUDIT_LEVEL > 0" |
| 120 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | # if kernel tools are available in-tree, they are preferred |
| 122 | # and are placed on the path before any external tools. Unless |
| 123 | # the external tools flag is set, in that case we do nothing. |
| 124 | if [ -f "${S}/scripts/util/configme" ]; then |
| 125 | if [ -z "${EXTERNAL_KERNEL_TOOLS}" ]; then |
| 126 | PATH=${S}/scripts/util:${PATH} |
| 127 | fi |
| 128 | fi |
| 129 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | # In a similar manner to the kernel itself: |
| 131 | # |
| 132 | # defconfig: $(obj)/conf |
| 133 | # ifeq ($(KBUILD_DEFCONFIG),) |
| 134 | # $< --defconfig $(Kconfig) |
| 135 | # else |
| 136 | # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'" |
| 137 | # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig) |
| 138 | # endif |
| 139 | # |
| 140 | # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it |
| 141 | # from the source tree, into a common location and normalized "defconfig" name, |
| 142 | # where the rest of the process will include and incoroporate it into the build |
| 143 | # |
| 144 | # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI), |
| 145 | # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take |
| 146 | # precendence. |
| 147 | # |
| 148 | if [ -n "${KBUILD_DEFCONFIG}" ]; then |
| 149 | if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then |
| 150 | if [ -f "${WORKDIR}/defconfig" ]; then |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 151 | # If the two defconfig's are different, warn that we overwrote the |
| 152 | # one already placed in WORKDIR |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 153 | cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" |
| 154 | if [ $? -ne 0 ]; then |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 155 | bbdebug 1 "detected SRC_URI or unpatched defconfig in WORKDIR. ${KBUILD_DEFCONFIG} copied over it" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 156 | fi |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 157 | cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 158 | else |
| 159 | cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | fi |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 161 | in_tree_defconfig="${WORKDIR}/defconfig" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 162 | else |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 163 | bbfatal "A KBUILD_DEFCONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree (${S}/arch/${ARCH}/configs/)" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | fi |
| 165 | fi |
| 166 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 167 | if [ "$mode" = "patch" ]; then |
| 168 | # was anyone trying to patch the kernel meta data ?, we need to do |
| 169 | # this here, since the scc commands migrate the .cfg fragments to the |
| 170 | # kernel source tree, where they'll be used later. |
| 171 | check_git_config |
| 172 | patches="${@" ".join(find_patches(d,'kernel-meta'))}" |
| 173 | for p in $patches; do |
| 174 | ( |
| 175 | cd ${WORKDIR}/kernel-meta |
| 176 | git am -s $p |
| 177 | ) |
| 178 | done |
| 179 | fi |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 180 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 181 | sccs_from_src_uri="${@" ".join(find_sccs(d))}" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 182 | patches="${@" ".join(find_patches(d,''))}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}" |
| 184 | |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 185 | # a quick check to make sure we don't have duplicate defconfigs If |
| 186 | # there's a defconfig in the SRC_URI, did we also have one from the |
| 187 | # KBUILD_DEFCONFIG processing above ? |
| 188 | src_uri_defconfig=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") != 0) { print $0 }' RS=' ') |
| 189 | # drop and defconfig's from the src_uri variable, we captured it just above here if it existed |
| 190 | sccs_from_src_uri=$(echo $sccs_from_src_uri | awk '(match($0, "defconfig") == 0) { print $0 }' RS=' ') |
| 191 | |
| 192 | if [ -n "$in_tree_defconfig" ]; then |
| 193 | sccs_defconfig=$in_tree_defconfig |
| 194 | if [ -n "$src_uri_defconfig" ]; then |
| 195 | bbwarn "[NOTE]: defconfig was supplied both via KBUILD_DEFCONFIG and SRC_URI. Dropping SRC_URI defconfig" |
| 196 | fi |
| 197 | else |
| 198 | # if we didn't have an in-tree one, make our defconfig the one |
| 199 | # from the src_uri. Note: there may not have been one from the |
| 200 | # src_uri, so this can be an empty variable. |
| 201 | sccs_defconfig=$src_uri_defconfig |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 202 | fi |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 203 | sccs="$sccs_from_src_uri" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 204 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 205 | # check for feature directories/repos/branches that were part of the |
| 206 | # SRC_URI. If they were supplied, we convert them into include directives |
| 207 | # for the update part of the process |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 208 | for f in ${feat_dirs}; do |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | if [ -d "${WORKDIR}/$f/meta" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 210 | includes="$includes -I${WORKDIR}/$f/kernel-meta" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 211 | elif [ -d "${WORKDIR}/../oe-local-files/$f" ]; then |
| 212 | includes="$includes -I${WORKDIR}/../oe-local-files/$f" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 213 | elif [ -d "${WORKDIR}/$f" ]; then |
| 214 | includes="$includes -I${WORKDIR}/$f" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 215 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 216 | done |
| 217 | for s in ${sccs} ${patches}; do |
| 218 | sdir=$(dirname $s) |
| 219 | includes="$includes -I${sdir}" |
| 220 | # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta", |
| 221 | # then we add it to the search path |
| 222 | if [ -d "${sdir}/kernel-meta" ]; then |
| 223 | includes="$includes -I${sdir}/kernel-meta" |
| 224 | fi |
| 225 | done |
| 226 | |
| 227 | # expand kernel features into their full path equivalents |
| 228 | bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE}) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 229 | if [ -z "$bsp_definition" ]; then |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 230 | if [ -z "$sccs_defconfig" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 231 | bbfatal_log "Could not locate BSP definition for ${KMACHINE}/${LINUX_KERNEL_TYPE} and no defconfig was provided" |
| 232 | fi |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 233 | else |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 234 | # if the bsp definition has "define KMETA_EXTERNAL_BSP t", |
| 235 | # then we need to set a flag that will instruct the next |
| 236 | # steps to use the BSP as both configuration and patches. |
| 237 | grep -q KMETA_EXTERNAL_BSP $bsp_definition |
| 238 | if [ $? -eq 0 ]; then |
| 239 | KMETA_EXTERNAL_BSPS="t" |
| 240 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 241 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 242 | meta_dir=$(kgit --meta) |
| 243 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 244 | KERNEL_FEATURES_FINAL="" |
| 245 | if [ -n "${KERNEL_FEATURES}" ]; then |
| 246 | for feature in ${KERNEL_FEATURES}; do |
| 247 | feature_found=f |
| 248 | for d in $includes; do |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 249 | path_to_check=$(echo $d | sed 's/^-I//') |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 250 | if [ "$feature_found" = "f" ] && [ -e "$path_to_check/$feature" ]; then |
| 251 | feature_found=t |
| 252 | fi |
| 253 | done |
| 254 | if [ "$feature_found" = "f" ]; then |
| 255 | if [ -n "${KERNEL_DANGLING_FEATURES_WARN_ONLY}" ]; then |
| 256 | bbwarn "Feature '$feature' not found, but KERNEL_DANGLING_FEATURES_WARN_ONLY is set" |
| 257 | bbwarn "This may cause runtime issues, dropping feature and allowing configuration to continue" |
| 258 | else |
| 259 | bberror "Feature '$feature' not found, this will cause configuration failures." |
| 260 | bberror "Check the SRC_URI for meta-data repositories or directories that may be missing" |
| 261 | bbfatal_log "Set KERNEL_DANGLING_FEATURES_WARN_ONLY to ignore this issue" |
| 262 | fi |
| 263 | else |
| 264 | KERNEL_FEATURES_FINAL="$KERNEL_FEATURES_FINAL $feature" |
| 265 | fi |
| 266 | done |
| 267 | fi |
| 268 | |
| 269 | if [ "$mode" = "config" ]; then |
| 270 | # run1: pull all the configuration fragments, no matter where they come from |
| 271 | elements="`echo -n ${bsp_definition} $sccs_defconfig ${sccs} ${patches} $KERNEL_FEATURES_FINAL`" |
| 272 | if [ -n "${elements}" ]; then |
| 273 | echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition |
| 274 | scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} $sccs_defconfig $bsp_definition $sccs $patches $KERNEL_FEATURES_FINAL |
| 275 | if [ $? -ne 0 ]; then |
| 276 | bbfatal_log "Could not generate configuration queue for ${KMACHINE}." |
| 277 | fi |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 278 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 | fi |
| 280 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 281 | # if KMETA_EXTERNAL_BSPS has been set, or it has been detected from |
| 282 | # the bsp definition, then we inject the bsp_definition into the |
| 283 | # patch phase below. we'll piggy back on the sccs variable. |
| 284 | if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then |
| 285 | sccs="${bsp_definition} ${sccs}" |
| 286 | fi |
| 287 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 288 | if [ "$mode" = "patch" ]; then |
| 289 | # run2: only generate patches for elements that have been passed on the SRC_URI |
| 290 | elements="`echo -n ${sccs} ${patches} $KERNEL_FEATURES_FINAL`" |
| 291 | if [ -n "${elements}" ]; then |
| 292 | scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} $KERNEL_FEATURES_FINAL |
| 293 | if [ $? -ne 0 ]; then |
| 294 | bbfatal_log "Could not generate configuration queue for ${KMACHINE}." |
| 295 | fi |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 296 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 297 | fi |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 298 | |
| 299 | if [ ${KCONF_AUDIT_LEVEL} -gt 0 ]; then |
| 300 | bbnote "kernel meta data summary for ${KMACHINE} (${LINUX_KERNEL_TYPE}):" |
| 301 | bbnote "======================================================================" |
| 302 | if [ -n "${KMETA_EXTERNAL_BSPS}" ]; then |
| 303 | bbnote "Non kernel-cache (external) bsp" |
| 304 | fi |
| 305 | bbnote "BSP entry point / definition: $bsp_definition" |
| 306 | if [ -n "$in_tree_defconfig" ]; then |
| 307 | bbnote "KBUILD_DEFCONFIG: ${KBUILD_DEFCONFIG}" |
| 308 | fi |
| 309 | bbnote "Fragments from SRC_URI: $sccs_from_src_uri" |
| 310 | bbnote "KERNEL_FEATURES: $KERNEL_FEATURES_FINAL" |
| 311 | bbnote "Final scc/cfg list: $sccs_defconfig $bsp_definition $sccs $KERNEL_FEATURES_FINAL" |
| 312 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | do_patch() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 316 | set +e |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 317 | cd ${S} |
| 318 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 319 | check_git_config |
| 320 | meta_dir=$(kgit --meta) |
| 321 | (cd ${meta_dir}; ln -sf patch.queue series) |
| 322 | if [ -f "${meta_dir}/series" ]; then |
| 323 | kgit-s2q --gen -v --patches .kernel-meta/ |
| 324 | if [ $? -ne 0 ]; then |
| 325 | bberror "Could not apply patches for ${KMACHINE}." |
| 326 | 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] | 327 | fi |
| 328 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 329 | |
| 330 | if [ -f "${meta_dir}/merge.queue" ]; then |
| 331 | # we need to merge all these branches |
| 332 | for b in $(cat ${meta_dir}/merge.queue); do |
| 333 | git show-ref --verify --quiet refs/heads/${b} |
| 334 | if [ $? -eq 0 ]; then |
| 335 | bbnote "Merging branch ${b}" |
| 336 | git merge -q --no-ff -m "Merge branch ${b}" ${b} |
| 337 | else |
| 338 | bbfatal "branch ${b} does not exist, cannot merge" |
| 339 | fi |
| 340 | done |
| 341 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | do_kernel_checkout() { |
| 345 | set +e |
| 346 | |
| 347 | source_dir=`echo ${S} | sed 's%/$%%'` |
| 348 | source_workdir="${WORKDIR}/git" |
| 349 | if [ -d "${WORKDIR}/git/" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 350 | # case: git repository |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree. |
| 352 | if [ "${source_dir}" != "${source_workdir}" ]; then |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 353 | if [ -d "${source_workdir}/.git" ]; then |
| 354 | # regular git repository with .git |
| 355 | rm -rf ${S} |
| 356 | mv ${WORKDIR}/git ${S} |
| 357 | else |
| 358 | # create source for bare cloned git repository |
| 359 | git clone ${WORKDIR}/git ${S} |
| 360 | rm -rf ${WORKDIR}/git |
| 361 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 362 | fi |
| 363 | cd ${S} |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 364 | |
| 365 | # convert any remote branches to local tracking ones |
| 366 | for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do |
| 367 | b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`; |
| 368 | git show-ref --quiet --verify -- "refs/heads/$b" |
| 369 | if [ $? -ne 0 ]; then |
| 370 | git branch $b $i > /dev/null |
| 371 | fi |
| 372 | done |
| 373 | |
| 374 | # Create a working tree copy of the kernel by checking out a branch |
| 375 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 376 | |
| 377 | # checkout and clobber any unimportant files |
| 378 | git checkout -f ${machine_branch} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 379 | else |
| 380 | # case: we have no git repository at all. |
| 381 | # To support low bandwidth options for building the kernel, we'll just |
| 382 | # convert the tree to a git repo and let the rest of the process work unchanged |
| 383 | |
| 384 | # if ${S} hasn't been set to the proper subdirectory a default of "linux" is |
| 385 | # used, but we can't initialize that empty directory. So check it and throw a |
| 386 | # clear error |
| 387 | |
| 388 | cd ${S} |
| 389 | if [ ! -f "Makefile" ]; then |
| 390 | bberror "S is not set to the linux source directory. Check " |
| 391 | bbfatal "the recipe and set S to the proper extracted subdirectory" |
| 392 | fi |
| 393 | rm -f .gitignore |
| 394 | git init |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 395 | check_git_config |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 396 | git add . |
| 397 | git commit -q -m "baseline commit: creating repo for ${PN}-${PV}" |
| 398 | git clean -d -f |
| 399 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 400 | } |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 401 | do_kernel_checkout[dirs] = "${S} ${WORKDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 402 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 403 | addtask kernel_checkout before do_kernel_metadata after do_symlink_kernsrc |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 404 | addtask kernel_metadata after do_validate_branches do_unpack before do_patch |
| 405 | do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 406 | do_kernel_metadata[file-checksums] = " ${@get_dirs_with_fragments(d)}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 407 | do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 408 | |
William A. Kennington III | 47649fa | 2018-06-28 12:34:29 -0700 | [diff] [blame] | 409 | do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}binutils:do_populate_sysroot" |
| 410 | do_kernel_configme[depends] += "virtual/${TARGET_PREFIX}gcc:do_populate_sysroot" |
| 411 | 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] | 412 | do_kernel_configme[depends] += "kern-tools-native:do_populate_sysroot" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 413 | do_kernel_configme[dirs] += "${S} ${B}" |
| 414 | do_kernel_configme() { |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 415 | do_kernel_metadata config |
| 416 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 417 | # translate the kconfig_mode into something that merge_config.sh |
| 418 | # understands |
| 419 | case ${KCONFIG_MODE} in |
| 420 | *allnoconfig) |
| 421 | config_flags="-n" |
| 422 | ;; |
| 423 | *alldefconfig) |
| 424 | config_flags="" |
| 425 | ;; |
Andrew Geissler | 3b8a17c | 2021-04-15 15:55:55 -0500 | [diff] [blame] | 426 | *) |
| 427 | if [ -f ${WORKDIR}/defconfig ]; then |
| 428 | config_flags="-n" |
| 429 | fi |
| 430 | ;; |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 431 | esac |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 432 | |
| 433 | cd ${S} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 434 | |
| 435 | meta_dir=$(kgit --meta) |
| 436 | configs="$(scc --configs -o ${meta_dir})" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 437 | if [ $? -ne 0 ]; then |
| 438 | bberror "${configs}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 439 | bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)" |
| 440 | fi |
| 441 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 442 | 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 |
| 443 | if [ $? -ne 0 -o ! -f ${B}/.config ]; then |
| 444 | bberror "Could not generate a .config for ${KMACHINE}-${LINUX_KERNEL_TYPE}" |
| 445 | if [ ${KCONF_AUDIT_LEVEL} -gt 1 ]; then |
| 446 | bbfatal_log "`cat ${meta_dir}/cfg/merge_config_build.log`" |
| 447 | else |
| 448 | bbfatal_log "Details can be found at: ${S}/${meta_dir}/cfg/merge_config_build.log" |
| 449 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 450 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 451 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 452 | if [ ! -z "${LINUX_VERSION_EXTENSION}" ]; then |
| 453 | echo "# Global settings from linux recipe" >> ${B}/.config |
| 454 | echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config |
| 455 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | addtask kernel_configme before do_configure after do_patch |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 459 | addtask config_analysis |
| 460 | |
| 461 | do_config_analysis[depends] = "virtual/kernel:do_configure" |
| 462 | do_config_analysis[depends] += "kern-tools-native:do_populate_sysroot" |
| 463 | |
| 464 | CONFIG_AUDIT_FILE ?= "${WORKDIR}/config-audit.txt" |
| 465 | CONFIG_ANALYSIS_FILE ?= "${WORKDIR}/config-analysis.txt" |
| 466 | |
| 467 | python do_config_analysis() { |
| 468 | import re, string, sys, subprocess |
| 469 | |
| 470 | s = d.getVar('S') |
| 471 | |
| 472 | env = os.environ.copy() |
| 473 | env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/") |
| 474 | env['LD'] = d.getVar('KERNEL_LD') |
| 475 | env['CC'] = d.getVar('KERNEL_CC') |
| 476 | env['ARCH'] = d.getVar('ARCH') |
| 477 | env['srctree'] = s |
| 478 | |
| 479 | # read specific symbols from the kernel recipe or from local.conf |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 480 | # i.e.: CONFIG_ANALYSIS:pn-linux-yocto-dev = 'NF_CONNTRACK LOCALVERSION' |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 481 | config = d.getVar( 'CONFIG_ANALYSIS' ) |
| 482 | if not config: |
| 483 | config = [ "" ] |
| 484 | else: |
| 485 | config = config.split() |
| 486 | |
| 487 | for c in config: |
| 488 | for action in ["analysis","audit"]: |
| 489 | if action == "analysis": |
| 490 | try: |
| 491 | analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--blame', c], cwd=s, env=env ).decode('utf-8') |
| 492 | except subprocess.CalledProcessError as e: |
| 493 | bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8')) |
| 494 | |
| 495 | outfile = d.getVar( 'CONFIG_ANALYSIS_FILE' ) |
| 496 | |
| 497 | if action == "audit": |
| 498 | try: |
| 499 | analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--summary', '--extended', '--sanity', c], cwd=s, env=env ).decode('utf-8') |
| 500 | except subprocess.CalledProcessError as e: |
| 501 | bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8')) |
| 502 | |
| 503 | outfile = d.getVar( 'CONFIG_AUDIT_FILE' ) |
| 504 | |
| 505 | if c: |
| 506 | outdir = os.path.dirname( outfile ) |
| 507 | outname = os.path.basename( outfile ) |
| 508 | outfile = outdir + '/'+ c + '-' + outname |
| 509 | |
| 510 | if config and os.path.isfile(outfile): |
| 511 | os.remove(outfile) |
| 512 | |
| 513 | with open(outfile, 'w+') as f: |
| 514 | f.write( analysis ) |
| 515 | |
| 516 | bb.warn( "Configuration {} executed, see: {} for details".format(action,outfile )) |
| 517 | if c: |
| 518 | bb.warn( analysis ) |
| 519 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 520 | |
| 521 | python do_kernel_configcheck() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 522 | import re, string, sys, subprocess |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 523 | |
| 524 | # if KMETA isn't set globally by a recipe using this routine, we need to |
| 525 | # set the default to 'meta'. Otherwise, kconf_check is not passed a valid |
| 526 | # meta-series for processing |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 527 | kmeta = d.getVar("KMETA") or "meta" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 528 | if not os.path.exists(kmeta): |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 529 | kmeta = subprocess.check_output(['kgit', '--meta'], cwd=d.getVar('S')).decode('utf-8').rstrip() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 530 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 531 | s = d.getVar('S') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 532 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 533 | env = os.environ.copy() |
| 534 | env['PATH'] = "%s:%s%s" % (d.getVar('PATH'), s, "/scripts/util/") |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 535 | env['LD'] = d.getVar('KERNEL_LD') |
| 536 | env['CC'] = d.getVar('KERNEL_CC') |
| 537 | env['ARCH'] = d.getVar('ARCH') |
| 538 | env['srctree'] = s |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 539 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 540 | try: |
| 541 | configs = subprocess.check_output(['scc', '--configs', '-o', s + '/.kernel-meta'], env=env).decode('utf-8') |
| 542 | except subprocess.CalledProcessError as e: |
| 543 | bb.fatal( "Cannot gather config fragments for audit: %s" % e.output.decode("utf-8") ) |
| 544 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 545 | config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0) |
| 546 | bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 547 | kmeta_audit_werror = d.getVar("KMETA_AUDIT_WERROR") or "" |
| 548 | warnings_detected = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 549 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 550 | # if config check visibility is "1", that's the lowest level of audit. So |
| 551 | # we add the --classify option to the run, since classification will |
| 552 | # streamline the output to only report options that could be boot issues, |
| 553 | # or are otherwise required for proper operation. |
| 554 | extra_params = "" |
| 555 | if config_check_visibility == 1: |
| 556 | extra_params = "--classify" |
| 557 | |
| 558 | # category #1: mismatches |
| 559 | try: |
| 560 | analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--mismatches', extra_params], cwd=s, env=env ).decode('utf-8') |
| 561 | except subprocess.CalledProcessError as e: |
| 562 | bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8')) |
| 563 | |
| 564 | if analysis: |
| 565 | outfile = "{}/{}/cfg/mismatch.txt".format( s, kmeta ) |
| 566 | if os.path.isfile(outfile): |
| 567 | os.remove(outfile) |
| 568 | with open(outfile, 'w+') as f: |
| 569 | f.write( analysis ) |
| 570 | |
| 571 | if config_check_visibility and os.stat(outfile).st_size > 0: |
| 572 | with open (outfile, "r") as myfile: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 573 | results = myfile.read() |
| 574 | bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 575 | warnings_detected = True |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 576 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 577 | # category #2: invalid fragment elements |
| 578 | extra_params = "" |
| 579 | if bsp_check_visibility > 1: |
| 580 | extra_params = "--strict" |
| 581 | try: |
| 582 | analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--invalid', extra_params], cwd=s, env=env ).decode('utf-8') |
| 583 | except subprocess.CalledProcessError as e: |
| 584 | bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8')) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 585 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 586 | if analysis: |
| 587 | outfile = "{}/{}/cfg/invalid.txt".format(s,kmeta) |
| 588 | if os.path.isfile(outfile): |
| 589 | os.remove(outfile) |
| 590 | with open(outfile, 'w+') as f: |
| 591 | f.write( analysis ) |
| 592 | |
| 593 | if bsp_check_visibility and os.stat(outfile).st_size > 0: |
| 594 | with open (outfile, "r") as myfile: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 595 | results = myfile.read() |
| 596 | bb.warn( "[kernel config]: This BSP contains fragments with warnings:\n\n%s" % results) |
| 597 | warnings_detected = True |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 598 | |
| 599 | # category #3: redefined options (this is pretty verbose and is debug only) |
| 600 | try: |
| 601 | analysis = subprocess.check_output(['symbol_why.py', '--dotconfig', '{}'.format( d.getVar('B') + '/.config' ), '--sanity'], cwd=s, env=env ).decode('utf-8') |
| 602 | except subprocess.CalledProcessError as e: |
| 603 | bb.fatal( "config analysis failed: %s" % e.output.decode('utf-8')) |
| 604 | |
| 605 | if analysis: |
| 606 | outfile = "{}/{}/cfg/redefinition.txt".format(s,kmeta) |
| 607 | if os.path.isfile(outfile): |
| 608 | os.remove(outfile) |
| 609 | with open(outfile, 'w+') as f: |
| 610 | f.write( analysis ) |
| 611 | |
| 612 | # if the audit level is greater than two, we report if a fragment has overriden |
| 613 | # a value from a base fragment. This is really only used for new kernel introduction |
| 614 | if bsp_check_visibility > 2 and os.stat(outfile).st_size > 0: |
| 615 | with open (outfile, "r") as myfile: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 616 | results = myfile.read() |
| 617 | bb.warn( "[kernel config]: This BSP has configuration options defined in more than one config, with differing values:\n\n%s" % results) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 618 | warnings_detected = True |
| 619 | |
| 620 | if warnings_detected and kmeta_audit_werror: |
| 621 | bb.fatal( "configuration warnings detected, werror is set, promoting to fatal" ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | # Ensure that the branches (BSP and meta) are on the locations specified by |
| 625 | # their SRCREV values. If they are NOT on the right commits, the branches |
| 626 | # are corrected to the proper commit. |
| 627 | do_validate_branches() { |
| 628 | set +e |
| 629 | cd ${S} |
| 630 | |
| 631 | machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" |
| 632 | machine_srcrev="${SRCREV_machine}" |
| 633 | |
| 634 | # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to |
| 635 | # check and we can exit early |
| 636 | if [ "${machine_srcrev}" = "AUTOINC" ]; then |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 637 | linux_yocto_dev='${@oe.utils.conditional("PREFERRED_PROVIDER_virtual/kernel", "linux-yocto-dev", "1", "", d)}' |
| 638 | if [ -n "$linux_yocto_dev" ]; then |
| 639 | git checkout -q -f ${machine_branch} |
| 640 | ver=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//) |
| 641 | patchlevel=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//) |
| 642 | sublevel=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//) |
| 643 | kver="$ver.$patchlevel" |
| 644 | bbnote "dev kernel: performing version -> branch -> SRCREV validation" |
| 645 | bbnote "dev kernel: recipe version ${LINUX_VERSION}, src version: $kver" |
| 646 | echo "${LINUX_VERSION}" | grep -q $kver |
| 647 | if [ $? -ne 0 ]; then |
| 648 | version="$(echo ${LINUX_VERSION} | sed 's/\+.*$//g')" |
| 649 | versioned_branch="v$version/$machine_branch" |
| 650 | |
| 651 | machine_branch=$versioned_branch |
| 652 | force_srcrev="$(git rev-parse $machine_branch 2> /dev/null)" |
| 653 | if [ $? -ne 0 ]; then |
| 654 | bbfatal "kernel version mismatch detected, and no valid branch $machine_branch detected" |
| 655 | fi |
| 656 | |
| 657 | bbnote "dev kernel: adjusting branch to $machine_branch, srcrev to: $force_srcrev" |
| 658 | fi |
| 659 | else |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 660 | bbnote "SRCREV validation is not required for AUTOREV" |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 661 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 662 | elif [ "${machine_srcrev}" = "" ]; then |
| 663 | if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then |
| 664 | # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe |
| 665 | # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In |
| 666 | # this case, we need to reset to the give SRCREV before heading to patching |
| 667 | bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}" |
| 668 | force_srcrev="${SRCREV}" |
| 669 | fi |
| 670 | else |
| 671 | git cat-file -t ${machine_srcrev} > /dev/null |
| 672 | if [ $? -ne 0 ]; then |
| 673 | bberror "${machine_srcrev} is not a valid commit ID." |
| 674 | bbfatal_log "The kernel source tree may be out of sync" |
| 675 | fi |
| 676 | force_srcrev=${machine_srcrev} |
| 677 | fi |
| 678 | |
| 679 | git checkout -q -f ${machine_branch} |
| 680 | if [ -n "${force_srcrev}" ]; then |
| 681 | # see if the branch we are about to patch has been properly reset to the defined |
| 682 | # SRCREV .. if not, we reset it. |
| 683 | branch_head=`git rev-parse HEAD` |
| 684 | if [ "${force_srcrev}" != "${branch_head}" ]; then |
| 685 | current_branch=`git rev-parse --abbrev-ref HEAD` |
| 686 | git branch "$current_branch-orig" |
| 687 | git reset --hard ${force_srcrev} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 688 | # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check |
| 689 | # so the patches are applied as expected otherwise no patching |
| 690 | # would be done in some corner cases. |
| 691 | kgit-s2q --clean |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 692 | fi |
| 693 | fi |
| 694 | } |
| 695 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 696 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 697 | KBUILD_OUTPUT = "${B}" |
| 698 | |
| 699 | python () { |
| 700 | # If diffconfig is available, ensure it runs after kernel_configme |
| 701 | if 'do_diffconfig' in d: |
| 702 | bb.build.addtask('do_diffconfig', None, 'do_kernel_configme', d) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 703 | |
| 704 | externalsrc = d.getVar('EXTERNALSRC') |
| 705 | if externalsrc: |
| 706 | # If we deltask do_patch, do_kernel_configme is left without |
| 707 | # dependencies and runs too early |
| 708 | 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] | 709 | } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 710 | |
| 711 | # extra tasks |
| 712 | addtask kernel_version_sanity_check after do_kernel_metadata do_kernel_checkout before do_compile |
| 713 | addtask validate_branches before do_patch after do_kernel_checkout |
| 714 | addtask kernel_configcheck after do_configure before do_compile |