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