aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/linux-qcom-bootimg.inc
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/linux/linux-qcom-bootimg.inc')
-rw-r--r--recipes-kernel/linux/linux-qcom-bootimg.inc179
1 files changed, 138 insertions, 41 deletions
diff --git a/recipes-kernel/linux/linux-qcom-bootimg.inc b/recipes-kernel/linux/linux-qcom-bootimg.inc
index 8a8a407..9e3fef9 100644
--- a/recipes-kernel/linux/linux-qcom-bootimg.inc
+++ b/recipes-kernel/linux/linux-qcom-bootimg.inc
@@ -1,49 +1,146 @@
-DEPENDS += "skales-native"
-
-QCOM_BOOTIMG_ROOTFS ?= "undefined"
-SD_QCOM_BOOTIMG_ROOTFS ?= "undefined"
-
-# set output file names
-BOOT_IMAGE_BASE_NAME = "boot-${KERNEL_IMAGE_NAME}"
-BOOT_IMAGE_SYMLINK_NAME = "boot-${KERNEL_IMAGE_LINK_NAME}"
-SD_BOOT_IMAGE_BASE_NAME = "boot-sd${KERNEL_IMAGE_NAME}"
-SD_BOOT_IMAGE_SYMLINK_NAME = "boot-sd-${KERNEL_IMAGE_LINK_NAME}"
-KERNEL_CMDLINE = "root=${1} rw rootwait console=${ttydev},${baudrate}n8"
-KERNEL_CMDLINE_append_dragonboard-845c = " clk_ignore_unused pd_ignore_unused"
-KERNEL_CMDLINE_append_qrb5165-rb5 = " pcie_pme=nomsi"
-
-# param ${1} partition where rootfs is located
-# param ${2} output boot image file name
-priv_make_image() {
- ${STAGING_BINDIR_NATIVE}/skales/mkbootimg --kernel ${B}/arch/${ARCH}/boot/${KERNEL_IMAGETYPE} \
- --ramdisk ${B}/initrd.img \
- --output ${DEPLOYDIR}/${2}.img \
- --pagesize ${QCOM_BOOTIMG_PAGE_SIZE} \
- --base ${QCOM_BOOTIMG_KERNEL_BASE} \
- --cmdline "${KERNEL_CMDLINE}"
+QIMG_DEPLOYDIR = "${WORKDIR}/qcom_deploy-${PN}"
+
+# Define INITRAMFS_IMAGE to create kernel+initramfs Android boot images in
+# addition to default boot images. For example add the following line to your
+# conf/local.conf:
+#
+# INITRAMFS_IMAGE = "initramfs-kerneltest-image"
+#
+
+python __anonymous () {
+ if d.getVar('INITRAMFS_IMAGE') != '':
+ d.appendVarFlag('do_qcom_img_deploy', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
}
-do_deploy_append() {
+python do_qcom_img_deploy() {
+ import shutil
+ import subprocess
+
+ subdir = d.getVar("KERNEL_DEPLOYSUBDIR")
+ if subdir is not None:
+ qcom_deploy_dir = os.path.join(d.getVar("QIMG_DEPLOYDIR"), subdir)
+ image_dir = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), subdir)
+ else:
+ qcom_deploy_dir = d.getVar("QIMG_DEPLOYDIR")
+ image_dir = d.getVar("DEPLOY_DIR_IMAGE")
+
+ initrd = None
+ if d.getVar('INITRAMFS_IMAGE') != '':
+ initrd_image_name = d.getVar("INITRAMFS_IMAGE_NAME")
+ baseinitrd = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), initrd_image_name)
+ for img in (".cpio.gz", ".cpio.lz4", ".cpio.lzo", ".cpio.lzma", ".cpio.xz", ".cpio"):
+ if os.path.exists(baseinitrd + img):
+ initrd = baseinitrd + img
+ break
+ if not initrd:
+ bb.fatal("Could not find initramfs image %s for bundling" % d.getVar("INITRAMFS_IMAGE"))
+
+ B = d.getVar("B")
+ D = d.getVar("D")
+ kernel_output_dir = d.getVar("KERNEL_OUTPUT_DIR")
+ kernel_imagedest = d.getVar("KERNEL_IMAGEDEST")
+ kernel = os.path.join(B, "kernel-dtb")
+ definitrd = os.path.join(B, "initrd.img")
+ mkbootimg = os.path.join(d.getVar("STAGING_BINDIR_NATIVE"), "skales", "mkbootimg")
+ kernel_image_name = d.getVar("KERNEL_IMAGE_NAME")
+ kernel_link_name = d.getVar("KERNEL_IMAGE_LINK_NAME")
+ output_img = os.path.join(qcom_deploy_dir, "boot-%s.img" % (kernel_link_name))
+ output_sd_img = os.path.join(qcom_deploy_dir, "boot-sd-%s.img" % (kernel_link_name))
+
+ arch = d.getVar("ARCH")
+ if arch is "arm":
+ kernel_name = "zImage"
+ elif arch is "arm64":
+ kernel_name = "Image.gz"
+ else:
+ bb.fatal("Unuspported ARCH %s" % arch)
+
+ if os.path.exists(output_img):
+ os.unlink(output_img)
+ if os.path.exists(output_sd_img):
+ os.unlink(output_sd_img)
+
+ with open(definitrd, "w") as f:
+ f.write("This is not an initrd\n")
+
+ for dtbf in d.getVar("KERNEL_DEVICETREE").split():
+ dtb = os.path.basename(dtbf)
+ dtb_name = dtb.rsplit('.', 1)[0]
+
+ def getVarDTB(name):
+ return d.getVarFlag(name, dtb_name) or d.getVar(name)
- tmp="${SERIAL_CONSOLES}"
- baudrate=`echo $tmp | sed 's/\;.*//'`
- ttydev=`echo $tmp | sed -e 's/^[0-9]*\;//' -e 's/\s.*//' -e 's/\;.*//'`
+ def make_image_internal(output, output_link, rootfs, initrd = definitrd):
+ subprocess.check_call([mkbootimg,
+ "--kernel", kernel,
+ "--ramdisk", initrd,
+ "--output", output,
+ "--pagesize", getVarDTB("QCOM_BOOTIMG_PAGE_SIZE"),
+ "--base", getVarDTB("QCOM_BOOTIMG_KERNEL_BASE"),
+ "--cmdline", "root=%s rw rootwait %s %s" % (rootfs, consoles, getVarDTB("KERNEL_CMDLINE_EXTRA") or "")])
+ if os.path.exists(output_link):
+ os.unlink(output_link)
+ os.symlink(os.path.basename(output), output_link)
+
+ def make_image(template, rootfs):
+ output = os.path.join(qcom_deploy_dir, template % (dtb_name, kernel_image_name))
+ output_link = os.path.join(qcom_deploy_dir, template % (dtb_name, kernel_link_name))
+ make_image_internal(output, output_link, rootfs)
+ return output
+
+ def make_initramfs_image(template, rootfs, initrd, initrd_image_name):
+ output = os.path.join(qcom_deploy_dir, template % (initrd_image_name, dtb_name, kernel_image_name))
+ output_link = os.path.join(qcom_deploy_dir, template % (initrd_image_name, dtb_name, kernel_link_name))
+ make_image_internal(output, output_link, rootfs, initrd)
+ output_link = os.path.join(qcom_deploy_dir, template % ("initramfs", dtb_name, kernel_link_name))
+ if os.path.exists(output_link):
+ os.unlink(output_link)
+ os.symlink(os.path.basename(output), output_link)
+ return output
+
+ consoles = ' '.join(map(lambda c: "console=%(tty)s,%(rate)sn8" % dict(zip(("rate", "tty"), c.split(';'))), getVarDTB("SERIAL_CONSOLES").split()))
+
+ # prepare kernel image with appended dtb
+ with open(kernel, 'wb') as wfd:
+ with open(os.path.join(kernel_output_dir, kernel_name), 'rb') as rfd:
+ shutil.copyfileobj(rfd, wfd)
+ with open(os.path.join(D, kernel_imagedest, dtb), 'rb') as rfd:
+ shutil.copyfileobj(rfd, wfd)
+
+ rootfs = getVarDTB("QCOM_BOOTIMG_ROOTFS")
+ if not rootfs or rootfs is "":
+ bb.fatal("QCOM_BOOTIMG_ROOTFS is undefined")
+
+ output = make_image("boot-%s-%s.img", rootfs)
+ if not os.path.exists(output_img):
+ os.symlink(os.path.basename(output), output_img)
+
+ if initrd:
+ make_initramfs_image("boot-%s-%s-%s.img", rootfs, initrd, d.getVar("INITRAMFS_IMAGE"))
+
+ sd_rootfs = getVarDTB("SD_QCOM_BOOTIMG_ROOTFS")
+ if sd_rootfs:
+ output = make_image("boot-sd-%s-%s.img", sd_rootfs)
+ if not os.path.exists(output_sd_img):
+ os.symlink(os.path.basename(output), output_sd_img)
+
+ if initrd:
+ make_initramfs_image("boot-sd-%s-%s-%s.img", rootfs, initrd, d.getVar("INITRAMFS_IMAGE"))
+}
- # mkbootimg requires an initrd file, make fake one that will be ignored
- # during boot
- echo "This is not an initrd" > ${B}/initrd.img
+do_qcom_img_deploy[depends] += "skales-native:do_populate_sysroot"
- # don't build bootimg if rootfs partition is not defined
- if [ "${QCOM_BOOTIMG_ROOTFS}" = "undefined" ]; then
- bbfatal "Rootfs partition must be defined"
- fi
+addtask qcom_img_deploy after do_populate_sysroot do_packagedata bundle_initramfs before do_deploy
- priv_make_image ${QCOM_BOOTIMG_ROOTFS} ${BOOT_IMAGE_BASE_NAME}
- ln -sf ${BOOT_IMAGE_BASE_NAME}.img ${DEPLOYDIR}/${BOOT_IMAGE_SYMLINK_NAME}.img
+# Setup sstate, see deploy.bbclass
+SSTATETASKS += "do_qcom_img_deploy"
+do_qcom_img_deploy[sstate-inputdirs] = "${QIMG_DEPLOYDIR}"
+do_qcom_img_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
- # build sd boot image only for machines supporting it.
- if [ "${SD_QCOM_BOOTIMG_ROOTFS}" != "undefined" ]; then
- priv_make_image ${SD_QCOM_BOOTIMG_ROOTFS} ${SD_BOOT_IMAGE_BASE_NAME}
- ln -sf ${SD_BOOT_IMAGE_BASE_NAME}.img ${DEPLOYDIR}/${SD_BOOT_IMAGE_SYMLINK_NAME}.img
- fi
+python do_qcom_img_deploy_setscene () {
+ sstate_setscene(d)
}
+addtask do_qcom_img_deploy_setscene
+do_qcom_img_deploy[dirs] = "${QIMG_DEPLOYDIR} ${B}"
+do_qcom_img_deploy[cleandirs] = "${QIMG_DEPLOYDIR}"
+do_qcom_img_deploy[stamp-extra-info] = "${MACHINE_ARCH}"