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