compulab-pxa270 2.6.16: add task to create a kernel image file.
authorCliff Brake <cbrake@bec-systems.com>
Mon, 23 Apr 2007 21:42:22 +0000 (21:42 +0000)
committerCliff Brake <cbrake@bec-systems.com>
Mon, 23 Apr 2007 21:42:22 +0000 (21:42 +0000)
The cm-x270 bootloader requires kernel image files in a special
format and this addition adds that.

packages/linux/compulab-pxa270_2.6.16.bb

index 6e09281..043fc22 100644 (file)
@@ -1,7 +1,7 @@
 SECTION = "kernel"
 DESCRIPTION = "Linux kernel for the Compulab PXA270 system"
 LICENSE = "GPL"
-PR = "r3"
+PR = "r4"
 
 # Note, the compulab package contains a binary NAND driver that is not
 # EABI compatible
@@ -32,25 +32,38 @@ do_deploy() {
        KNAME=${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}.bin
         install -d ${DEPLOY_DIR_IMAGE}
         install -m 0644 arch/${ARCH}/boot/${KERNEL_IMAGETYPE} ${KNAME}
-       # Create an image file that has the size prepended (used by cm-x270 BL)
-       # The following can only be done on a little endian machine
-       # the following does not work on all computers as it requires a recent
-       # version of coreutils (>= 6.0).  We will eventually replace the following
-       # with python code.
-       #size=$(stat --printf=%s ${KNAME})
-       #size_=$(printf '\%03o'\
-       #$((size & 0x000000FF))\
-       #$((size>>8 & 0x000000FF))\
-       #$((size>>16 & 0x000000FF))\
-       #$((size>>24 & 0x000000FF)))
-       #size_=${size_}'\c'
-       #echo -e $size_ > ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}-${DATETIME}.img
-       #cat ${KNAME} >> ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${MACHINE}-${DATETIME}.img
 }
 
+python do_compulab_image() {
+       import os
+       import os.path
+       import struct
+
+       deploy_dir = bb.data.getVar('DEPLOY_DIR_IMAGE', d, 1)
+       kernel_name = os.path.join(deploy_dir, bb.data.expand('${KERNEL_IMAGETYPE}-${MACHINE}.bin', d))
+
+       img_file = os.path.join(deploy_dir, 'zImage-compulab-pxa270.img')
+
+       fo = open(img_file, 'wb')
+
+       image_data = open(kernel_name, 'rb').read()
+
+       # first write size into first 4 bytes
+       size_s = struct.pack('i', len(image_data))
+
+       # truncate size if we are running on a 64-bit host
+       size_s = size_s[:4]
+
+       fo.write(size_s)
+       fo.write(image_data)
+       fo.close()
+}
+
+
 do_deploy[dirs] = "${S}"
 
 addtask deploy before do_build after do_compile
+addtask compulab_image before do_build after do_deploy
 
 COMPATIBLE_MACHINE = "compulab-pxa270"