Merge branch 'master' of git://dev.doredevelopment.dk/oe-micro into org.openembedded.dev
[vuplus_openembedded] / recipes / linux / ixp4xx-kernel.inc
1 # ixp4xx-kernel.inc
2 #
3 # Standard definitions for any IXP4xx Linux kernel.
4 # Include this file in a .bb which specifies, at least,
5 # PN,PV,PR for the desired kernel
6 #
7 # Define the following *before* including this file as
8 # required:
9 #
10 # IXP4XX_PATCHES - full list of patches to apply, to add files
11 #   generate a patch against /dev/null
12 #
13 # DEFAULT_PREFERENCE is set automagically in this file as
14 # follows:
15 #
16 #  10  For *released* kernels
17 #   8  For mm or ac patched versions of released kernels
18 #   6  For rc patched kernels (release candidates)
19 #   4  For mm or ac patched rc (release candidate) kernels
20 #   2  For pre or bk versions
21 #   0  For mm or ac patched pre or bk versions
22 #
23 # --------------------------------------------------------------
24 #
25 SECTION = "kernel"
26 DESCRIPTION = "Linux kernel for the Intel IXP4xx device"
27 LICENSE = "GPL"
28
29 DEPENDS = "arm-kernel-shim devio-native"
30
31 # Linux kernel source has the general form linux-X.Y.Z-patchP,
32 # X.Y is the major version number, Z (which may have multiple
33 # parts) is a sub-version and 'patch' is something like 'mm' or
34 # 'ac' with a patch version.  The original bz2 archive will be
35 # in a directory/file vX.Y/linux-X.Y.Z.tar.bz2.  The unpacked
36 # source will be in the directory linux-X.Y.Z and this directory
37 # name corresponds to the module directory (in /lib/modules).
38 #
39 # The corresponding .bb file should be called:
40 #
41 #       package_X.Y.Z-patchP
42 #
43 # Giving PN=package PV=X.Y.Z-patchP (and PR is set in the .bb
44 # file).  Files, including the all important defconfig, are
45 # searched for in the following directories (last one first):
46 #
47 #       ixp4xx-kernel/files
48 #       ixp4xx-kernel/X.Y
49 #       ixp4xx-kernel/X.Y.Z
50 #       ixp4xx-kernel/X.Y.Z-patch
51 #       ixp4xx-kernel/X.Y.Z-patchP
52 #       package-X.Y.Z-patchP
53 #
54 # This allows sharing of patch files and other useful source!
55 # To share a file or patch with an earlier version put it in
56 # the shared directory - e.g. to use foo.patch on 2.6.11.2 and
57 # 2.6.11.4 it should be in directory ixp4xx-kernel/2.6.11.
58 #
59 # Note that when there are multiple patches the X.Y.Z-patch form
60 # uses base-patch (e.g. 2.6.12-mm) whereas X.Y.Z-patchP has the
61 # full form, for example 2.6.12-rc3-mm1 (in the same case).
62
63 #PN=package-name
64 #PV=package-version (full)
65
66 # The patch has the general form (rcN|preN|acN|mmN|bkN)* with the
67 # separate patch items being separated by '-' characters.  The
68 # rc patch is first and has the important property that it
69 # requires the *preceding* kernel base version and that this
70 # will be the source directory name.
71 python () {
72     # The patches list may be empty.  This code starts with the base
73     # kernel version and steps through the patches.  Because the rc and
74     # pre patches actually require the *preceding* kernel version the code
75     # fixes that up appropriately.
76     pv = bb.data.getVar("PV",d,1).split('-')
77     if pv[0].count('+'):
78         prev = pv[0].split('+')
79         pv[0] = prev[1];
80     kernel = pv[0].split('.')
81     base = pv[0]
82     name = [base]
83     major = '.'.join(name[0].split('.')[0:2])
84     minor = '.'.join(name[0].split('.')[0:3])
85     patch_uri = [ None ]
86     filedir = "${FILE_DIRNAME}/ixp4xx-kernel/%s"
87     # This entry will become the last one (everything is inserted before it)
88     filepath = [ filedir % "files" ]
89     pref = 10
90     mmac = 0
91     for patch in pv[1:]:
92         name.append(patch)
93         pname = '-'.join(name)
94         if patch[0:2] == "rc" or patch[0:3] == "pre":
95             patch_uri.append("${KERNELORG_MIRROR}/pub/linux/kernel/v%s/testing/patch-%s.bz2;patch=1;pname=%s" % (major, pname, pname))
96             kernel[-1] = str(int(kernel[-1]) - 1)
97             if patch[0:2] == "rc" and pref == 10:
98                 pref = 6
99                 filepath[0:0] = [ filedir % name[0] ]
100                 filepath[0:0] = [ filedir % (name[0] + "-rc") ]
101             else:
102                 pref = 2
103         elif patch[0:2] == "bk" or patch[0:3] == "git":
104             patch_uri.append("${KERNELORG_MIRROR}/pub/linux/kernel/v%s/snapshots/patch-%s.bz2;patch=1;pname=%s" % (major, pname, pname))
105             pref = 2
106         elif patch[0:2] == "ac":
107             patch_uri.append("${KERNELORG_MIRROR}/pub/linux/kernel/people/alan/linux-%s/%s/patch-%s" % (major, base, pname))
108             mmac = 2
109             filepath[0:0] = [ filedir % (name[0] + "-ac") ]
110         elif patch[0:2] == "mm":
111             patch_uri.append("${KERNELORG_MIRROR}/pub/linux/kernel/people/akpm/patches/%s/%s/%s/%s.bz2;patch=1;pname=%s" % (major, base, pname, pname, pname))
112             mmac = 2
113             filepath[0:0] = [ filedir % (name[0] + "-mm") ]
114         else:
115             raise bb.build.FuncFailed("ixp4xx-kernel: patch %s not recognized in %s" % (patch, '-'.join(pv)))
116             filepath[0:0] = [ filedir % pname ]
117         base = pname
118
119     base = '.'.join(kernel)
120     patch_uri[0] = "${KERNELORG_MIRROR}/pub/linux/kernel/v%s/linux-%s.tar.bz2" % (major, base)
121     filepath[-1:-1] = [ filedir % base ]
122     if base != minor:
123         filepath[-1:-1] = [ filedir % minor ]
124     filepath[-1:-1] = [ filedir % major ]
125
126     bb.data.setVar("IXP4XX_SRCMAJ", major, d)
127     # bb.note("IXP4XX_SRCMAJ := %s" % major)
128     bb.data.setVar("IXP4XX_SRCVER", base, d)
129     # bb.note("IXP4XX_SRCVER := %s" % base)
130     bb.data.setVar("IXP4XX_SRCURI", ' '.join(patch_uri), d)
131     # bb.note("IXP4XX_SRCURI := %s" % ' '.join(patch_uri))
132     bb.data.setVar("IXP4XX_FILESPATH", ':'.join(filepath), d)
133     # bb.note("IXP4XX_FILESPATH := %s" % ' '.join(filepath))
134     bb.data.setVar("DEFAULT_PREFERENCE", pref-mmac, d)
135     # bb.note("DEFAULT_PREFERENCE := %s" % (pref-mmac))
136 }
137
138 # FILESPATH: this list is in order last-searched-first, therefore
139 # the first entry is the *latest* and/or most specific
140 FILESPATH = "${FILE_DIRNAME}/${P}:${IXP4XX_FILESPATH}"
141
142 # The working directory will be the 'base' version (which may not be the
143 # same as implied by the PV variable because it corresponds to the prior
144 # minor version for rc and pre patched versions).
145 S = "${WORKDIR}/linux-${IXP4XX_SRCVER}"
146
147 # IXP4XX_PATCHES is the list of patches.
148 IXP4XX_PATCHES ?= ""
149
150 SRC_URI  = "${IXP4XX_SRCURI}"
151 SRC_URI += "${IXP4XX_PATCHES}"
152
153 COMPATIBLE_HOST = 'arm.*-linux.*'
154 COMPATIBLE_MACHINE = '(ixp4xx|nslu2|fsg3)'
155
156 inherit kernel
157
158 ARCH = "arm"
159
160 # To specify the console set KERNEL_CONSOLE in the .bb file.
161 # CMDLINE_ROOT contains the boot options, these will be
162 # appended to the build in boot options (so it is only necessary
163 # to override stuff in the kernel source).
164
165 # CMDLINE_ROOT: machine specific boot options - should not be set on a
166 #  generic kernel!
167 CMDLINE_ROOT ?= ""
168
169 # CMDLINE_DEBUG: debug options such as noirqdebug, defaults to empty
170 # override in local.conf etc
171 CMDLINE_DEBUG ?= ""
172
173 CMDLINE  = "${CMDLINE_ROOT}"
174 CMDLINE += "${CMDLINE_DEBUG}"
175 CMDLINE += "${CMDLINE_CONSOLE}"
176
177 # Set EXTRAVERSION and LOCALVERSION to "" so that the kernel version
178 # remains pinned to the x.y.z form, also turn off the directory
179 # printing which provides almost all the output of an incremental build.
180 EXTRA_OEMAKE += "EXTRAVERSION="
181 EXTRA_OEMAKE += "LOCALVERSION="
182 EXTRA_OEMAKE += "MAKEFLAGS='--no-print-directory'"
183
184 # Set the correct CONFIG_CPU_xxx_ENDIAN and CONFIG_CMDLINE at the head
185 # of the .config file and remove any settings in defconfig then append
186 # defconfig to .config
187 do_configure_prepend() {
188         rm -f ${S}/.config
189         echo "CONFIG_CMDLINE=\"${CMDLINE}\"" >>'${S}/.config'
190         if test '${SITEINFO_ENDIANESS}' = be
191         then
192                 echo 'CONFIG_CPU_BIG_ENDIAN=y' >>'${S}/.config'
193         fi
194
195         if [ "${TARGET_OS}" == "linux-gnueabi" -o  "${TARGET_OS}" == "linux-uclibcgnueabi" ]; then               
196                 echo "CONFIG_AEABI=y"                   >> ${S}/.config               
197                 echo "CONFIG_OABI_COMPAT=y"             >> ${S}/.config       
198         else
199                 echo "# CONFIG_AEABI is not set"        >> ${S}/.config
200                 echo "# CONFIG_OABI_COMPAT is not set"  >> ${S}/.config
201         fi      
202
203         sed     -e '/CONFIG_CPU_BIG_ENDIAN/d' \
204                 -e '/CONFIG_CMDLINE=/d' \
205                 -e '/CONFIG_AEABI/d' \
206                 -e '/CONFIG_OABI_COMPAT=/d' \
207                 '${WORKDIR}/defconfig' >>'${S}/.config'
208         rm -rf ${S}/include/asm-arm/arch ${S}/include/asm-arm/proc \
209                ${S}/include/asm-arm/.proc ${S}/include/asm-arm/.arch
210
211 }
212
213
214 # Kernel module dependencies
215
216 DEPENDS += "zd1211-firmware"
217 RDEPENDS_kernel-module-zd1211rw += "zd1211-firmware"
218
219
220 # MACHID and LE handling
221 #
222 # This mach_fixup function adds the required prefix to the image to
223 # force the machine id in the kernel to be a particular value.  For
224 # LE builds it also forces the CPU into LE mode - this is actually
225 # harmless even if the CPU is already in LE mode.  This deals with
226 # two known problems on some boards:
227 #
228 # 1) The machine type set by the boot loader is wrong - e.g. the type
229 #    for an ixdp425, not the actual board type.  Prefix the code with
230 #    two instructions:
231 #        e3a01c<hh> e38110<ll>
232 #    Where the machine ID is 0xhhll
233 # 2) For LE kernels it is necessary to prefix change-to-le code to
234 #    the kernel image if the boot loader runs with the CPU in BE
235 #    (which is normal for IXP4XX boards):
236 #        ee110f10 e3c00080 ee010f10
237 #    and to byte swap the (LE) image to match the BE flash layout
238 #
239 # (2) is not required with an LE boot loader (neither the prefix
240 #  nor the byte swapping) so this is controlled by a separate flag,
241 #  however if the boot loader is LE it expects and LE image so the
242 #  instructions written for the machine id must be LE.
243 #
244 # The argument to the function is the destination directory
245
246 # The generic package only includes the generic image, the other
247 # packages are made below (they are kernel-image packages but
248 # with a different ARCH).
249 FILES_kernel-image = "/boot/${KERNEL_IMAGETYPE}-${MACHINE_ARCH}-${KERNEL_VERSION}"
250
251 # MACHINE DEFINITIONS: one block for each machine
252
253 # The correct settings for the NSLU2 board:
254 nslu2_MACHID = "597"
255 PACKAGES += "kernel-image-nslu2"
256 PKG_kernel-image-nslu2 = "kernel-image-${KERNEL_VERSION}"
257 PACKAGE_ARCH_kernel-image-nslu2 = "nslu2${SITEINFO_ENDIANESS}"
258 DESCRIPTION_kernel-image-nslu2 = "Linux kernel for the LinkSys NSLU2"
259 FILES_kernel-image-nslu2 = "/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-nslu2${SITEINFO_ENDIANESS}-${KERNEL_VERSION}"
260 pkg_postinst_kernel-image-nslu2 () {
261         update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-nslu2${SITEINFO_ENDIANESS}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true
262 }
263 pkg_postrm_kernel-image-nslu2 () {
264         update-alternatives --remove ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-nslu2${SITEINFO_ENDIANESS}-${KERNEL_VERSION} || true
265 }
266
267 # The correct settings for the NAS100D board:
268 nas100d_MACHID = "865"
269 PACKAGES += "kernel-image-nas100d"
270 PKG_kernel-image-nas100d = "kernel-image-${KERNEL_VERSION}"
271 PACKAGE_ARCH_kernel-image-nas100d = "nas100d${SITEINFO_ENDIANESS}"
272 DESCRIPTION_kernel-image-nas100d = "Linux kernel for the IOMega NAS100D"
273 FILES_kernel-image-nas100d = "/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-nas100d${SITEINFO_ENDIANESS}-${KERNEL_VERSION}"
274 pkg_postinst_kernel-image-nas100d () {
275         update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-nas100d${SITEINFO_ENDIANESS}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true
276 }
277 pkg_postrm_kernel-image-nas100d () {
278         update-alternatives --remove ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-nas100d${SITEINFO_ENDIANESS}-${KERNEL_VERSION} || true
279 }
280
281 # The correct settings for the DSMG600 board:
282 dsmg600_MACHID = "964"
283 PACKAGES += "kernel-image-dsmg600"
284 PKG_kernel-image-dsmg600 = "kernel-image-${KERNEL_VERSION}"
285 PACKAGE_ARCH_kernel-image-dsmg600 = "dsmg600${SITEINFO_ENDIANESS}"
286 DESCRIPTION_kernel-image-dsmg600 = "Linux kernel for the D-Link DSM-G600"
287 FILES_kernel-image-dsmg600 = "/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-dsmg600${SITEINFO_ENDIANESS}-${KERNEL_VERSION}"
288 pkg_postinst_kernel-image-dsmg600 () {
289         update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-dsmg600${SITEINFO_ENDIANESS}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true
290 }
291 pkg_postrm_kernel-image-dsmg600 () {
292         update-alternatives --remove ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-dsmg600${SITEINFO_ENDIANESS}-${KERNEL_VERSION} || true
293 }
294
295 # The correct settings for the FSG-3 board:
296 fsg3_MACHID = "1091"
297 PACKAGES += "kernel-image-fsg3"
298 PKG_kernel-image-fsg3 = "kernel-image-${KERNEL_VERSION}"
299 PACKAGE_ARCH_kernel-image-fsg3 = "fsg3${SITEINFO_ENDIANESS}"
300 DESCRIPTION_kernel-image-fsg3 = "Linux kernel for the Freecom FSG-3"
301 FILES_kernel-image-fsg3 = "/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-fsg3${SITEINFO_ENDIANESS}-${KERNEL_VERSION}"
302 pkg_postinst_kernel-image-fsg3 () {
303         update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-fsg3${SITEINFO_ENDIANESS}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true
304 }
305 pkg_postrm_kernel-image-fsg3 () {
306         update-alternatives --remove ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-fsg3${SITEINFO_ENDIANESS}-${KERNEL_VERSION} || true
307 }
308
309 BYTESWAP_armeb = "cp$"
310 BYTESWAP_arm   = "xp $,4"
311
312 # We need the alternatives to happen in the kernel-image packages, not in
313 # the kernel package, because only the images know the name of the kernel.
314 pkg_postinst_kernel () {
315 }
316 pkg_postrm_kernel () {
317 }
318
319 # copy_image <dest> <machine>
320 #       copy the zImage and append the appropriate shim
321 #  dest:       where to copy to
322 #  machine:    machine shim to prepend, empty for none
323 copy_image() {
324         local shim
325
326         shim="/dev/null"
327         test -n "$2" && shim="${STAGING_LOADER_DIR}/arm-kernel-shim-$2.bin"
328
329         rm -f "$1".new "$1".shimmed
330         cat $shim ${KERNEL_OUTPUT} > "$1".shimmed
331         devio '<<'"$1"'.shimmed' >"$1".new '${BYTESWAP}' || {
332                 echo 'ERROR: ${KERNEL_OUTPUT}: failed to copy zImage' >&2
333                 return 1
334         }
335         rm -f "$1".shimmed
336         mv "$1".new "$1"
337 }
338
339 install_image() {
340         copy_image '${D}/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-'"$1"'-${KERNEL_VERSION}' "$2"
341 }
342
343 do_install_append() {
344         # Overwrite the unshimmed generic image with a shimmed one (but without
345         # any command line or machine id override).
346         rm -f '${D}/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}'
347         install_image '${MACHINE_ARCH}'
348
349         # Add the machine specific images, with appropriate suffixes
350         install_image 'nslu2${SITEINFO_ENDIANESS}' 'nslu2'
351         install_image 'nas100d${SITEINFO_ENDIANESS}' 'nas100d'
352         install_image 'dsmg600${SITEINFO_ENDIANESS}' 'dsmg600'
353         install_image 'fsg3${SITEINFO_ENDIANESS}' 'fsg3'
354 }
355
356 deploy_image() {
357         copy_image '${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-'"$1" "$2"
358 }
359
360 do_deploy() {
361         install -d ${DEPLOY_DIR_IMAGE}
362         deploy_image '${MACHINE_ARCH}'
363
364         # And the machine specific images
365         deploy_image 'nslu2${SITEINFO_ENDIANESS}' 'nslu2'
366         deploy_image 'nas100d${SITEINFO_ENDIANESS}' 'nas100d'
367         deploy_image 'dsmg600${SITEINFO_ENDIANESS}' 'dsmg600'
368         deploy_image 'fsg3${SITEINFO_ENDIANESS}' 'fsg3'
369 }