diff options
Diffstat (limited to 'meta/classes/kernel-yocto.bbclass')
| -rw-r--r-- | meta/classes/kernel-yocto.bbclass | 438 |
1 files changed, 203 insertions, 235 deletions
diff --git a/meta/classes/kernel-yocto.bbclass b/meta/classes/kernel-yocto.bbclass index 53bc6d443c..50226f6d49 100644 --- a/meta/classes/kernel-yocto.bbclass +++ b/meta/classes/kernel-yocto.bbclass @@ -1,7 +1,7 @@ -S = "${WORKDIR}/linux" - # remove tasks that modify the source tree in case externalsrc is inherited -SRCTREECOVEREDTASKS += "do_kernel_link_vmlinux do_kernel_configme do_validate_branches do_kernel_configcheck do_kernel_checkout do_patch" +SRCTREECOVEREDTASKS += "do_kernel_configme do_validate_branches do_kernel_configcheck do_kernel_checkout do_fetch do_unpack do_patch" +PATCH_GIT_USER_EMAIL ?= "kernel-yocto@oe" +PATCH_GIT_USER_NAME ?= "OpenEmbedded" # returns local (absolute) path names for all valid patches in the # src_uri @@ -35,6 +35,7 @@ def find_kernel_feature_dirs(d): for url in fetch.urls: urldata = fetch.ud[url] parm = urldata.parm + type="" if "type" in parm: type = parm["type"] if "destsuffix" in parm: @@ -53,11 +54,14 @@ def get_machine_branch(d, default): parm = urldata.parm if "branch" in parm: branches = urldata.parm.get("branch").split(',') - return branches[0] + btype = urldata.parm.get("type") + if btype != "kmeta": + return branches[0] return default -do_patch() { +do_kernel_metadata() { + set +e cd ${S} export KMETA=${KMETA} @@ -71,109 +75,147 @@ do_patch() { fi machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" - - # if we have a defined/set meta branch we should not be generating - # any meta data. The passed branch has what we need. - if [ -n "${KMETA}" ]; then - createme_flags="--disable-meta-gen --meta ${KMETA}" + machine_srcrev="${SRCREV_machine}" + if [ -z "${machine_srcrev}" ]; then + # fallback to SRCREV if a non machine_meta tree is being built + machine_srcrev="${SRCREV}" fi - createme ${createme_flags} ${ARCH} ${machine_branch} - if [ $? -ne 0 ]; then - echo "ERROR. Could not create ${machine_branch}" - exit 1 + # In a similar manner to the kernel itself: + # + # defconfig: $(obj)/conf + # ifeq ($(KBUILD_DEFCONFIG),) + # $< --defconfig $(Kconfig) + # else + # @echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'" + # $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig) + # endif + # + # If a defconfig is specified via the KBUILD_DEFCONFIG variable, we copy it + # from the source tree, into a common location and normalized "defconfig" name, + # where the rest of the process will include and incoroporate it into the build + # + # If the fetcher has already placed a defconfig in WORKDIR (from the SRC_URI), + # we don't overwrite it, but instead warn the user that SRC_URI defconfigs take + # precendence. + # + if [ -n "${KBUILD_DEFCONFIG}" ]; then + if [ -f "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" ]; then + if [ -f "${WORKDIR}/defconfig" ]; then + # If the two defconfig's are different, warn that we didn't overwrite the + # one already placed in WORKDIR by the fetcher. + cmp "${WORKDIR}/defconfig" "${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG}" + if [ $? -ne 0 ]; then + bbwarn "defconfig detected in WORKDIR. ${KBUILD_DEFCONFIG} skipped" + fi + else + cp -f ${S}/arch/${ARCH}/configs/${KBUILD_DEFCONFIG} ${WORKDIR}/defconfig + sccs="${WORKDIR}/defconfig" + fi + else + bbfatal "A KBUILD_DECONFIG '${KBUILD_DEFCONFIG}' was specified, but not present in the source tree" + fi fi - sccs="${@" ".join(find_sccs(d))}" + sccs="$sccs ${@" ".join(find_sccs(d))}" patches="${@" ".join(find_patches(d))}" feat_dirs="${@" ".join(find_kernel_feature_dirs(d))}" - set +e - # add any explicitly referenced features onto the end of the feature - # list that is passed to the kernel build scripts. - if [ -n "${KERNEL_FEATURES}" ]; then - for feat in ${KERNEL_FEATURES}; do - addon_features="$addon_features --feature $feat" - done - fi - # check for feature directories/repos/branches that were part of the # SRC_URI. If they were supplied, we convert them into include directives # for the update part of the process - if [ -n "${feat_dirs}" ]; then - for f in ${feat_dirs}; do + for f in ${feat_dirs}; do if [ -d "${WORKDIR}/$f/meta" ]; then - includes="$includes -I${WORKDIR}/$f/meta" - elif [ -d "${WORKDIR}/$f" ]; then - includes="$includes -I${WORKDIR}/$f" + includes="$includes -I${WORKDIR}/$f/kernel-meta" + elif [ -d "${WORKDIR}/$f" ]; then + includes="$includes -I${WORKDIR}/$f" fi - done - fi + done + for s in ${sccs} ${patches}; do + sdir=$(dirname $s) + includes="$includes -I${sdir}" + # if a SRC_URI passed patch or .scc has a subdir of "kernel-meta", + # then we add it to the search path + if [ -d "${sdir}/kernel-meta" ]; then + includes="$includes -I${sdir}/kernel-meta" + fi + done + + # expand kernel features into their full path equivalents + bsp_definition=$(spp ${includes} --find -DKMACHINE=${KMACHINE} -DKTYPE=${LINUX_KERNEL_TYPE}) + meta_dir=$(kgit --meta) - if [ "${machine_branch}" != "${KBRANCH_DEFAULT}" ]; then - updateme_flags="--branch ${machine_branch}" + # run1: pull all the configuration fragments, no matter where they come from + elements="`echo -n ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES}`" + if [ -n "${elements}" ]; then + echo "${bsp_definition}" > ${S}/${meta_dir}/bsp_definition + scc --force -o ${S}/${meta_dir}:cfg,merge,meta ${includes} ${bsp_definition} ${sccs} ${patches} ${KERNEL_FEATURES} + if [ $? -ne 0 ]; then + bbfatal_log "Could not generate configuration queue for ${KMACHINE}." + fi fi - # updates or generates the target description - updateme ${updateme_flags} -DKDESC=${KMACHINE}:${LINUX_KERNEL_TYPE} \ - ${includes} ${addon_features} ${ARCH} ${KMACHINE} ${sccs} ${patches} - if [ $? -ne 0 ]; then - echo "ERROR. Could not update ${machine_branch}" - exit 1 + # run2: only generate patches for elements that have been passed on the SRC_URI + elements="`echo -n ${sccs} ${patches} ${KERNEL_FEATURES}`" + if [ -n "${elements}" ]; then + scc --force -o ${S}/${meta_dir}:patch --cmds patch ${includes} ${sccs} ${patches} ${KERNEL_FEATURES} + if [ $? -ne 0 ]; then + bbfatal_log "Could not generate configuration queue for ${KMACHINE}." + fi fi +} - # executes and modifies the source tree as required - patchme ${KMACHINE} - if [ $? -ne 0 ]; then - echo "ERROR. Could not apply patches for ${KMACHINE}." - echo " Patch failures can be resolved in the devshell (bitbake -c devshell ${PN})" - exit 1 +do_patch() { + set +e + cd ${S} + + check_git_config + meta_dir=$(kgit --meta) + (cd ${meta_dir}; ln -sf patch.queue series) + if [ -f "${meta_dir}/series" ]; then + kgit-s2q --gen -v --patches .kernel-meta/ + if [ $? -ne 0 ]; then + bberror "Could not apply patches for ${KMACHINE}." + bbfatal_log "Patch failures can be resolved in the linux source directory ${S})" + fi fi - # Perform a final check. If something other than the default kernel - # branch was requested, and that's not where we ended up, then we - # should thrown an error, since we aren't building what was expected - final_branch="$(git symbolic-ref HEAD 2>/dev/null)" - final_branch=${final_branch##refs/heads/} - if [ "${machine_branch}" != "${KBRANCH_DEFAULT}" ] && - [ "${final_branch}" != "${machine_branch}" ]; then - echo "ERROR: branch ${machine_branch} was requested, but was not properly" - echo " configured to be built. The current branch is ${final_branch}" - exit 1 + if [ -f "${meta_dir}/merge.queue" ]; then + # we need to merge all these branches + for b in $(cat ${meta_dir}/merge.queue); do + git show-ref --verify --quiet refs/heads/${b} + if [ $? -eq 0 ]; then + bbnote "Merging branch ${b}" + git merge -q --no-ff -m "Merge branch ${b}" ${b} + else + bbfatal "branch ${b} does not exist, cannot merge" + fi + done fi } do_kernel_checkout() { set +e - # A linux yocto SRC_URI should use the bareclone option. That - # ensures that all the branches are available in the WORKDIR version - # of the repository. source_dir=`echo ${S} | sed 's%/$%%'` source_workdir="${WORKDIR}/git" - if [ -d "${WORKDIR}/git/" ] && [ -d "${WORKDIR}/git/.git" ]; then - # case2: the repository is a non-bare clone - + if [ -d "${WORKDIR}/git/" ]; then + # case: git repository # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree. if [ "${source_dir}" != "${source_workdir}" ]; then - rm -rf ${S} - mv ${WORKDIR}/git ${S} + if [ -d "${source_workdir}/.git" ]; then + # regular git repository with .git + rm -rf ${S} + mv ${WORKDIR}/git ${S} + else + # create source for bare cloned git repository + git clone ${WORKDIR}/git ${S} + rm -rf ${WORKDIR}/git + fi fi cd ${S} - elif [ -d "${WORKDIR}/git/" ] && [ ! -d "${WORKDIR}/git/.git" ]; then - # case2: the repository is a bare clone - - # if S is WORKDIR/git, then we shouldn't be moving or deleting the tree. - if [ "${source_dir}" != "${source_workdir}" ]; then - rm -rf ${S} - mkdir -p ${S}/.git - mv ${WORKDIR}/git/* ${S}/.git - rm -rf ${WORKDIR}/git/ - fi - cd ${S} - git config core.bare false else - # case 3: we have no git repository at all. + # case: we have no git repository at all. # To support low bandwidth options for building the kernel, we'll just # convert the tree to a git repo and let the rest of the process work unchanged @@ -183,34 +225,14 @@ do_kernel_checkout() { cd ${S} if [ ! -f "Makefile" ]; then - echo "[ERROR]: S is not set to the linux source directory. Check " - echo " the recipe and set S to the proper extracted subdirectory" - exit 1 + bberror "S is not set to the linux source directory. Check " + bbfatal "the recipe and set S to the proper extracted subdirectory" fi + rm -f .gitignore git init git add . git commit -q -m "baseline commit: creating repo for ${PN}-${PV}" - fi - # end debare - - # If KMETA is defined, the branch must exist, but a machine branch - # can be missing since it may be created later by the tools. - if [ -n "${KMETA}" ]; then - git branch -a --no-color | grep -q ${KMETA} - if [ $? -ne 0 ]; then - echo "ERROR. The branch '${KMETA}' is required and was not" - echo "found. Ensure that the SRC_URI points to a valid linux-yocto" - echo "kernel repository" - exit 1 - fi - fi - - machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" - - if [ "${KBRANCH}" != "${machine_branch}" ]; then - echo "WARNING: The SRC_URI machine branch and KBRANCH are not the same." - echo " KBRANCH will be adjusted to match, but this typically is a" - echo " misconfiguration and should be checked." + git clean -d -f fi # convert any remote branches to local tracking ones @@ -223,190 +245,136 @@ do_kernel_checkout() { done # Create a working tree copy of the kernel by checking out a branch - git show-ref --quiet --verify -- "refs/heads/${machine_branch}" - if [ $? -eq 0 ]; then - # checkout and clobber any unimportant files - git checkout -f ${machine_branch} - else - echo "Not checking out ${machine_branch}, it will be created later" - git checkout -f master - fi + machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" + + # checkout and clobber any unimportant files + git checkout -f ${machine_branch} } do_kernel_checkout[dirs] = "${S}" -addtask kernel_checkout before do_patch after do_unpack +addtask kernel_checkout before do_kernel_metadata after do_unpack +addtask kernel_metadata after do_validate_branches do_unpack before do_patch +do_kernel_metadata[depends] = "kern-tools-native:do_populate_sysroot" +do_validate_branches[depends] = "kern-tools-native:do_populate_sysroot" do_kernel_configme[dirs] += "${S} ${B}" do_kernel_configme() { - echo "[INFO] doing kernel configme" - export KMETA=${KMETA} + set +e - if [ -n ${KCONFIG_MODE} ]; then - configmeflags=${KCONFIG_MODE} - else - # If a defconfig was passed, use =n as the baseline, which is achieved - # via --allnoconfig + # translate the kconfig_mode into something that merge_config.sh + # understands + case ${KCONFIG_MODE} in + *allnoconfig) + config_flags="-n" + ;; + *alldefconfig) + config_flags="" + ;; + *) if [ -f ${WORKDIR}/defconfig ]; then - configmeflags="--allnoconfig" + config_flags="-n" fi - fi + ;; + esac cd ${S} - PATH=${PATH}:${S}/scripts/util - configme ${configmeflags} --reconfig --output ${B} ${LINUX_KERNEL_TYPE} ${KMACHINE} + + meta_dir=$(kgit --meta) + configs="$(scc --configs -o ${meta_dir})" + if [ -z "${configs}" ]; then + bbfatal_log "Could not find configuration queue (${meta_dir}/config.queue)" + fi + + CFLAGS="${CFLAGS} ${TOOLCHAIN_OPTIONS}" ARCH=${ARCH} merge_config.sh -O ${B} ${config_flags} ${configs} > ${meta_dir}/cfg/merge_config_build.log 2>&1 if [ $? -ne 0 ]; then - echo "ERROR. Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}" - exit 1 + bbfatal_log "Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}" fi - + echo "# Global settings from linux recipe" >> ${B}/.config echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config } -addtask kernel_configme after do_patch +addtask kernel_configme before do_configure after do_patch python do_kernel_configcheck() { import re, string, sys - bb.plain("NOTE: validating kernel config, see log.do_kernel_configcheck for details") - # if KMETA isn't set globally by a recipe using this routine, we need to # set the default to 'meta'. Otherwise, kconf_check is not passed a valid # meta-series for processing - kmeta = d.getVar( "KMETA", True ) or "meta" + kmeta = d.getVar("KMETA") or "meta" if not os.path.exists(kmeta): kmeta = "." + kmeta - pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH', True), "${S}/scripts/util/") - cmd = d.expand("cd ${S}; kconf_check -config- %s/meta-series ${S} ${B}" % kmeta) + pathprefix = "export PATH=%s:%s; " % (d.getVar('PATH'), "${S}/scripts/util/") + + cmd = d.expand("scc --configs -o ${S}/.kernel-meta") + ret, configs = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd)) + + cmd = d.expand("cd ${S}; kconf_check --report -o ${S}/%s/cfg/ ${B}/.config ${S} %s" % (kmeta,configs)) ret, result = oe.utils.getstatusoutput("%s%s" % (pathprefix, cmd)) - config_check_visibility = d.getVar( "KCONF_AUDIT_LEVEL", True ) or 1 - if config_check_visibility == 1: - bb.debug( 1, "%s" % result ) - else: - bb.note( "%s" % result ) + config_check_visibility = int(d.getVar("KCONF_AUDIT_LEVEL") or 0) + bsp_check_visibility = int(d.getVar("KCONF_BSP_AUDIT_LEVEL") or 0) + + # if config check visibility is non-zero, report dropped configuration values + mismatch_file = d.expand("${S}/%s/cfg/mismatch.txt" % kmeta) + if os.path.exists(mismatch_file): + if config_check_visibility: + with open (mismatch_file, "r") as myfile: + results = myfile.read() + bb.warn( "[kernel config]: specified values did not make it into the kernel's final configuration:\n\n%s" % results) } # Ensure that the branches (BSP and meta) are on the locations specified by # their SRCREV values. If they are NOT on the right commits, the branches # are corrected to the proper commit. do_validate_branches() { + set +e cd ${S} - export KMETA=${KMETA} machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}" + machine_srcrev="${SRCREV_machine}" - set +e # if SRCREV is AUTOREV it shows up as AUTOINC there's nothing to # check and we can exit early - if [ "${SRCREV_machine}" = "AUTOINC" ] || [ "${SRCREV_machine}" = "INVALID" ] || - [ "${SRCREV_machine}" = "" ]; then - return - fi - - # If something other than the default branch was requested, it must - # exist in the tree, and it's a hard error if it wasn't - git show-ref --quiet --verify -- "refs/heads/${machine_branch}" - if [ $? -eq 1 ]; then - if [ -n "${KBRANCH_DEFAULT}" ] && - [ "${machine_branch}" != "${KBRANCH_DEFAULT}" ]; then - echo "ERROR: branch ${machine_branch} was set for kernel compilation, " - echo " but it does not exist in the kernel repository." - echo " Check the value of KBRANCH and ensure that it describes" - echo " a valid banch in the source kernel repository" - exit 1 + if [ "${machine_srcrev}" = "AUTOINC" ]; then + bbnote "SRCREV validation is not required for AUTOREV" + elif [ "${machine_srcrev}" = "" ]; then + if [ "${SRCREV}" != "AUTOINC" ] && [ "${SRCREV}" != "INVALID" ]; then + # SRCREV_machine_<MACHINE> was not set. This means that a custom recipe + # that doesn't use the SRCREV_FORMAT "machine_meta" is being built. In + # this case, we need to reset to the give SRCREV before heading to patching + bbnote "custom recipe is being built, forcing SRCREV to ${SRCREV}" + force_srcrev="${SRCREV}" fi - fi - - if [ -z "${SRCREV_machine}" ]; then - target_branch_head="${SRCREV}" else - target_branch_head="${SRCREV_machine}" - fi - - # $SRCREV could have also been AUTOINC, so check again - if [ "${target_branch_head}" = "AUTOINC" ]; then - return - fi - - ref=`git show ${target_branch_head} 2>&1 | head -n1 || true` - if [ "$ref" = "fatal: bad object ${target_meta_head}" ]; then - echo "ERROR ${target_branch_head} is not a valid commit ID." - echo "The kernel source tree may be out of sync" - exit 1 - fi - - containing_branches=`git branch --contains $target_branch_head | sed 's/^..//'` - if [ -z "$containing_branches" ]; then - echo "ERROR: SRCREV was set to \"$target_branch_head\", but no branches" - echo " contain this commit" - exit 1 - fi - - # force the SRCREV in each branch that contains the specified - # SRCREV (if it isn't the current HEAD of that branch) - git checkout -q master - for b in $containing_branches; do - branch_head=`git show-ref -s --heads ${b}` - if [ "$branch_head" != "$target_branch_head" ]; then - echo "[INFO] Setting branch $b to ${target_branch_head}" - if [ "$b" = "master" ]; then - git reset --hard $target_branch_head > /dev/null - else - git branch -D $b > /dev/null - git branch $b $target_branch_head > /dev/null - fi - fi - done - - ## KMETA branch validation. - ## We do validation if the meta branch exists, and AUTOREV hasn't been set - meta_head=`git show-ref -s --heads ${KMETA}` - target_meta_head="${SRCREV_meta}" - git show-ref --quiet --verify -- "refs/heads/${KMETA}" - if [ $? -eq 0 ] && [ "${target_meta_head}" != "AUTOINC" ]; then - if [ "$meta_head" != "$target_meta_head" ]; then - ref=`git show ${target_meta_head} 2>&1 | head -n1 || true` - if [ "$ref" = "fatal: bad object ${target_meta_head}" ]; then - echo "ERROR ${target_meta_head} is not a valid commit ID" - echo "The kernel source tree may be out of sync" - exit 1 - else - echo "[INFO] Setting branch ${KMETA} to ${target_meta_head}" - git branch -m ${KMETA} ${KMETA}-orig - git checkout -q -b ${KMETA} ${target_meta_head} - if [ $? -ne 0 ];then - echo "ERROR: could not checkout ${KMETA} branch from known hash ${target_meta_head}" - exit 1 - fi - fi + git cat-file -t ${machine_srcrev} > /dev/null + if [ $? -ne 0 ]; then + bberror "${machine_srcrev} is not a valid commit ID." + bbfatal_log "The kernel source tree may be out of sync" fi + force_srcrev=${machine_srcrev} fi - git show-ref --quiet --verify -- "refs/heads/${machine_branch}" - if [ $? -eq 0 ]; then - # restore the branch for builds - git checkout -q -f ${machine_branch} - else - git checkout -q master - fi -} - -# Many scripts want to look in arch/$arch/boot for the bootable -# image. This poses a problem for vmlinux based booting. This -# task arranges to have vmlinux appear in the normalized directory -# location. -do_kernel_link_vmlinux() { - if [ ! -d "${B}/arch/${ARCH}/boot" ]; then - mkdir ${B}/arch/${ARCH}/boot + git checkout -q -f ${machine_branch} + if [ -n "${force_srcrev}" ]; then + # see if the branch we are about to patch has been properly reset to the defined + # SRCREV .. if not, we reset it. + branch_head=`git rev-parse HEAD` + if [ "${force_srcrev}" != "${branch_head}" ]; then + current_branch=`git rev-parse --abbrev-ref HEAD` + git branch "$current_branch-orig" + git reset --hard ${force_srcrev} + # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check + # so the patches are applied as expected otherwise no patching + # would be done in some corner cases. + kgit-s2q --clean + fi fi - cd ${B}/arch/${ARCH}/boot - ln -sf ../../../vmlinux } -OE_TERMINAL_EXPORTS += "GUILT_BASE KBUILD_OUTPUT" -GUILT_BASE = "meta" +OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" KBUILD_OUTPUT = "${B}" python () { |
