diff options
Diffstat (limited to 'meta/classes')
| -rw-r--r-- | meta/classes/kernel-yocto.bbclass | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/meta/classes/kernel-yocto.bbclass b/meta/classes/kernel-yocto.bbclass new file mode 100644 index 0000000000..8e820122ec --- /dev/null +++ b/meta/classes/kernel-yocto.bbclass | |||
| @@ -0,0 +1,202 @@ | |||
| 1 | S = "${WORKDIR}/linux" | ||
| 2 | |||
| 3 | # Determine which branch to fetch and build. Not all branches are in the | ||
| 4 | # upstream repo (but will be locally created after the fetchers run) so | ||
| 5 | # a fallback branch needs to be chosen. | ||
| 6 | # | ||
| 7 | # The default machine 'UNDEFINED'. If the machine is not set to a specific | ||
| 8 | # branch in this recipe or in a recipe extension, then we fallback to a | ||
| 9 | # branch that is always present 'standard'. This sets the KBRANCH variable | ||
| 10 | # and is used in the SRC_URI. The machine is then set back to ${MACHINE}, | ||
| 11 | # since futher processing will use that to create local branches | ||
| 12 | python __anonymous () { | ||
| 13 | import bb, re | ||
| 14 | |||
| 15 | version = bb.data.getVar("LINUX_VERSION", d, 1) | ||
| 16 | # 2.6.34 signifies the old-style tree, so we need some temporary | ||
| 17 | # conditional processing based on the kernel version. | ||
| 18 | if version == "2.6.34": | ||
| 19 | bb.data.setVar("KBRANCH", "${KMACHINE}-${LINUX_KERNEL_TYPE}", d) | ||
| 20 | bb.data.setVar("KMETA", "wrs_meta", d) | ||
| 21 | mach = bb.data.getVar("KMACHINE", d, 1) | ||
| 22 | if mach == "UNDEFINED": | ||
| 23 | bb.data.setVar("KBRANCH", "standard", d) | ||
| 24 | bb.data.setVar("KMACHINE", "${MACHINE}", d) | ||
| 25 | # track the global configuration on a bootstrapped BSP | ||
| 26 | bb.data.setVar("SRCREV_machine", "${SRCREV_meta}", d) | ||
| 27 | bb.data.setVar("BOOTSTRAP", "t", d) | ||
| 28 | else: | ||
| 29 | # The branch for a build is: | ||
| 30 | # yocto/<kernel type>/${KMACHINE} or | ||
| 31 | # yocto/<kernel type>/${KMACHINE}/base | ||
| 32 | bb.data.setVar("KBRANCH", bb.data.expand("yocto/${LINUX_KERNEL_TYPE}/${KMACHINE}",d), d) | ||
| 33 | bb.data.setVar("KMETA", "meta", d) | ||
| 34 | |||
| 35 | mach = bb.data.getVar("KMACHINE", d, 1) | ||
| 36 | # drop the "/base" if it was on the KMACHINE | ||
| 37 | kmachine = mach.replace('/base','') | ||
| 38 | # and then write KMACHINE back | ||
| 39 | bb.data.setVar('KMACHINE_' + bb.data.expand("${MACHINE}",d), kmachine, d) | ||
| 40 | |||
| 41 | if mach == "UNDEFINED": | ||
| 42 | bb.data.setVar("KBRANCH", "yocto/standard/base", d) | ||
| 43 | bb.data.setVar('KMACHINE_' + bb.data.expand("${MACHINE}",d), bb.data.expand("${MACHINE}",d), d) | ||
| 44 | bb.data.setVar("SRCREV_machine", "standard", d) | ||
| 45 | bb.data.setVar("BOOTSTRAP", "t", d) | ||
| 46 | } | ||
| 47 | |||
| 48 | do_patch() { | ||
| 49 | cd ${S} | ||
| 50 | if [ -f ${WORKDIR}/defconfig ]; then | ||
| 51 | defconfig=${WORKDIR}/defconfig | ||
| 52 | fi | ||
| 53 | |||
| 54 | if [ -n "${BOOTSTRAP}" ]; then | ||
| 55 | kbranch="yocto/${LINUX_KERNEL_TYPE}/${KMACHINE}" | ||
| 56 | else | ||
| 57 | kbranch=${KBRANCH} | ||
| 58 | fi | ||
| 59 | |||
| 60 | # simply ensures that a branch of the right name has been created | ||
| 61 | createme ${ARCH} ${kbranch} ${defconfig} | ||
| 62 | if [ $? -ne 0 ]; then | ||
| 63 | echo "ERROR. Could not create ${kbranch}" | ||
| 64 | exit 1 | ||
| 65 | fi | ||
| 66 | |||
| 67 | # updates or generates the target description | ||
| 68 | if [ -n "${KERNEL_FEATURES}" ]; then | ||
| 69 | addon_features="--features ${KERNEL_FEATURES}" | ||
| 70 | fi | ||
| 71 | updateme ${addon_features} ${ARCH} ${WORKDIR} | ||
| 72 | if [ $? -ne 0 ]; then | ||
| 73 | echo "ERROR. Could not update ${kbranch}" | ||
| 74 | exit 1 | ||
| 75 | fi | ||
| 76 | |||
| 77 | # executes and modifies the source tree as required | ||
| 78 | patchme ${kbranch} | ||
| 79 | if [ $? -ne 0 ]; then | ||
| 80 | echo "ERROR. Could not modify ${kbranch}" | ||
| 81 | exit 1 | ||
| 82 | fi | ||
| 83 | } | ||
| 84 | |||
| 85 | do_kernel_checkout() { | ||
| 86 | if [ -d ${WORKDIR}/.git/refs/remotes/origin ]; then | ||
| 87 | echo "Fixing up git directory for ${LINUX_KERNEL_TYPE}/${KMACHINE}" | ||
| 88 | rm -rf ${S} | ||
| 89 | mkdir ${S} | ||
| 90 | mv ${WORKDIR}/.git ${S} | ||
| 91 | |||
| 92 | if [ -e ${S}/.git/packed-refs ]; then | ||
| 93 | cd ${S} | ||
| 94 | rm -f .git/refs/remotes/origin/HEAD | ||
| 95 | IFS=' | ||
| 96 | '; | ||
| 97 | for r in `git show-ref | grep remotes`; do | ||
| 98 | ref=`echo $r | cut -d' ' -f1`; | ||
| 99 | b=`echo $r | cut -d' ' -f2 | sed 's%refs/remotes/origin/%%'`; | ||
| 100 | dir=`dirname $b` | ||
| 101 | mkdir -p .git/refs/heads/$dir | ||
| 102 | echo $ref > .git/refs/heads/$b | ||
| 103 | done | ||
| 104 | cd .. | ||
| 105 | else | ||
| 106 | cp -r ${S}/.git/refs/remotes/origin/* ${S}/.git/refs/heads | ||
| 107 | rmdir ${S}/.git/refs/remotes/origin | ||
| 108 | fi | ||
| 109 | fi | ||
| 110 | cd ${S} | ||
| 111 | |||
| 112 | # checkout and clobber and unimportant files | ||
| 113 | git checkout -f ${KBRANCH} | ||
| 114 | } | ||
| 115 | do_kernel_checkout[dirs] = "${S}" | ||
| 116 | |||
| 117 | addtask kernel_checkout before do_patch after do_unpack | ||
| 118 | |||
| 119 | do_kernel_configme() { | ||
| 120 | echo "[INFO] doing kernel configme" | ||
| 121 | |||
| 122 | cd ${S} | ||
| 123 | configme --reconfig | ||
| 124 | if [ $? -ne 0 ]; then | ||
| 125 | echo "ERROR. Could not configure ${KMACHINE}-${LINUX_KERNEL_TYPE}" | ||
| 126 | exit 1 | ||
| 127 | fi | ||
| 128 | |||
| 129 | echo "# Global settings from linux recipe" >> ${B}/.config | ||
| 130 | echo "CONFIG_LOCALVERSION="\"${LINUX_VERSION_EXTENSION}\" >> ${B}/.config | ||
| 131 | } | ||
| 132 | |||
| 133 | do_kernel_configcheck() { | ||
| 134 | echo "[INFO] validating kernel configuration" | ||
| 135 | cd ${B}/.. | ||
| 136 | kconf_check ${B}/.config ${B} ${S} ${B} ${LINUX_VERSION} ${KMACHINE}-${LINUX_KERNEL_TYPE} | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 | # Ensure that the branches (BSP and meta) are on the locatios specified by | ||
| 141 | # their SRCREV values. If they are NOT on the right commits, the branches | ||
| 142 | # are reset to the correct commit. | ||
| 143 | do_validate_branches() { | ||
| 144 | cd ${S} | ||
| 145 | branch_head=`git show-ref -s --heads ${KBRANCH}` | ||
| 146 | meta_head=`git show-ref -s --heads ${KMETA}` | ||
| 147 | target_branch_head="${SRCREV_machine}" | ||
| 148 | target_meta_head="${SRCREV_meta}" | ||
| 149 | |||
| 150 | # nothing to do if bootstrapping | ||
| 151 | if [ -n "${BOOTSTRAP}" ]; then | ||
| 152 | return | ||
| 153 | fi | ||
| 154 | |||
| 155 | current=`git branch |grep \*|sed 's/^\* //'` | ||
| 156 | if [ -n "$target_branch_head" ] && [ "$branch_head" != "$target_branch_head" ]; then | ||
| 157 | if [ -n "${KERNEL_REVISION_CHECKING}" ]; then | ||
| 158 | git show ${target_branch_head} > /dev/null 2>&1 | ||
| 159 | if [ $? -eq 0 ]; then | ||
| 160 | echo "Forcing branch $current to ${target_branch_head}" | ||
| 161 | git branch -m $current $current-orig | ||
| 162 | git checkout -b $current ${target_branch_head} | ||
| 163 | else | ||
| 164 | echo "ERROR ${target_branch_head} is not a valid commit ID." | ||
| 165 | echo "The kernel source tree may be out of sync" | ||
| 166 | exit 1 | ||
| 167 | fi | ||
| 168 | fi | ||
| 169 | fi | ||
| 170 | |||
| 171 | if [ "$meta_head" != "$target_meta_head" ]; then | ||
| 172 | if [ -n "${KERNEL_REVISION_CHECKING}" ]; then | ||
| 173 | git show ${target_meta_head} > /dev/null 2>&1 | ||
| 174 | if [ $? -eq 0 ]; then | ||
| 175 | echo "Forcing branch meta to ${target_meta_head}" | ||
| 176 | git branch -m ${KMETA} ${KMETA}-orig | ||
| 177 | git checkout -b ${KMETA} ${target_meta_head} | ||
| 178 | else | ||
| 179 | echo "ERROR ${target_meta_head} is not a valid commit ID" | ||
| 180 | echo "The kernel source tree may be out of sync" | ||
| 181 | exit 1 | ||
| 182 | fi | ||
| 183 | fi | ||
| 184 | fi | ||
| 185 | |||
| 186 | # restore the branch for builds | ||
| 187 | git checkout -f ${KBRANCH} | ||
| 188 | } | ||
| 189 | |||
| 190 | # Many scripts want to look in arch/$arch/boot for the bootable | ||
| 191 | # image. This poses a problem for vmlinux based booting. This | ||
| 192 | # task arranges to have vmlinux appear in the normalized directory | ||
| 193 | # location. | ||
| 194 | do_kernel_link_vmlinux() { | ||
| 195 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then | ||
| 196 | mkdir ${B}/arch/${ARCH}/boot | ||
| 197 | fi | ||
| 198 | cd ${B}/arch/${ARCH}/boot | ||
| 199 | ln -sf ../../../vmlinux | ||
| 200 | } | ||
| 201 | |||
| 202 | |||
