]> code.ossystems Code Review - openembedded-core.git/commitdiff
image-live.bbclass/image-vm.bbclass: remove duplicated code
authorRobert Yang <liezhi.yang@windriver.com>
Wed, 30 Mar 2016 07:23:11 +0000 (00:23 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 31 Mar 2016 12:22:55 +0000 (13:22 +0100)
Move the common code to live_vm_common.bbclass and remove duplicated ones.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/image-live.bbclass
meta/classes/image-vm.bbclass
meta/classes/image.bbclass
meta/classes/live-vm-common.bbclass [new file with mode: 0644]

index a08715cd83ffe9eef8f20da98f5fedce820e6274..c837fbfc92f6fd82c41ab661e899e503f25abb16 100644 (file)
@@ -25,6 +25,8 @@
 # ${HDDIMG_ID} - FAT image volume-id
 # ${ROOTFS} - indicates a filesystem image to include as the root filesystem (optional)
 
+inherit live-vm-common
+
 do_bootimg[depends] += "dosfstools-native:do_populate_sysroot \
                         mtools-native:do_populate_sysroot \
                         cdrtools-native:do_populate_sysroot \
@@ -71,52 +73,11 @@ MKISOFS_OPTIONS = "-no-emul-boot -boot-load-size 4 -boot-info-table"
 BOOTIMG_VOLUME_ID   ?= "boot"
 BOOTIMG_EXTRA_SPACE ?= "512"
 
-EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
-EFI_PROVIDER ?= "grub-efi"
-EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
-
-KERNEL_IMAGETYPE ??= "bzImage"
-
-# Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
-# contain "efi". This way legacy is supported by default if neither is
-# specified, maintaining the original behavior.
-def pcbios(d):
-    pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
-    if pcbios == "0":
-        pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d)
-    return pcbios
-
-PCBIOS = "${@pcbios(d)}"
-PCBIOS_CLASS = "${@['','syslinux'][d.getVar('PCBIOS', True) == '1']}"
-
-inherit ${EFI_CLASS}
-inherit ${PCBIOS_CLASS}
-
-populate() {
-       DEST=$1
-       install -d ${DEST}
-
-       # Install kernel, initrd, and rootfs.img in DEST for all loaders to use.
-       install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ${DEST}/vmlinuz
-
-       # initrd is made of concatenation of multiple filesystem images
-       if [ -n "${INITRD}" ]; then
-               rm -f ${DEST}/initrd
-               for fs in ${INITRD}
-               do
-                       if [ -s "${fs}" ]; then
-                               cat ${fs} >> ${DEST}/initrd
-                       else
-                               bbfatal "${fs} is invalid. initrd image creation failed."
-                       fi
-               done
-               chmod 0644 ${DEST}/initrd
-       fi
-
-       if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
-               install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
+populate_live() {
+    populate_kernel $1
+       if [ -s "${ROOTFS}" ]; then
+               install -m 0644 ${ROOTFS} $1/rootfs.img
        fi
-
 }
 
 build_iso() {
@@ -128,14 +89,13 @@ build_iso() {
        # ${INITRD} is a list of multiple filesystem images
        for fs in ${INITRD}
        do
-               if [ ! -s "${fs}" ]; then
-                       bbnote "ISO image will not be created. ${fs} is invalid."
+               if [ ! -s "$fs" ]; then
+                       bbnote "ISO image will not be created. $fs is invalid."
                        return
                fi
        done
 
-
-       populate ${ISODIR}
+       populate_live ${ISODIR}
 
        if [ "${PCBIOS}" = "1" ]; then
                syslinux_iso_populate ${ISODIR}
@@ -275,7 +235,7 @@ build_fat_img() {
 build_hddimg() {
        # Create an HDD image
        if [ "${NOHDD}" != "1" ] ; then
-               populate ${HDDDIR}
+               populate_live ${HDDDIR}
 
                if [ "${PCBIOS}" = "1" ]; then
                        syslinux_hddimg_populate ${HDDDIR}
index ced8eac4d9b89500a4a792b93dd139dc75758ffd..66712a62ff5d61d4609d24991fc828e9ec5cce01 100644 (file)
@@ -15,6 +15,8 @@
 # We have to push the msdos parition table size > 16MB so fat 16 is used as parted
 # won't touch fat12 partitions.
 
+inherit live-vm-common
+
 do_bootdirectdisk[depends] += "dosfstools-native:do_populate_sysroot \
                                virtual/kernel:do_deploy \
                                syslinux:do_populate_sysroot \
@@ -43,63 +45,14 @@ do_bootdirectdisk[depends] += "${@'${INITRD_IMAGE_VM}:do_image_complete' if '${I
 BOOTDD_VOLUME_ID   ?= "boot"
 BOOTDD_EXTRA_SPACE ?= "16384"
 
-EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
-EFI_PROVIDER ?= "grub-efi"
-EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
-
-# Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
-# contain "efi". This way legacy is supported by default if neither is
-# specified, maintaining the original behavior.
-def pcbios(d):
-    pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
-    if pcbios == "0":
-        pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d)
-    return pcbios
-
-def pcbios_class(d):
-    if d.getVar("PCBIOS", True) == "1":
-        return "syslinux"
-    return ""
-
-PCBIOS = "${@pcbios(d)}"
-PCBIOS_CLASS = "${@pcbios_class(d)}"
-
-# Get the build_syslinux_cfg() function from the syslinux class
-inherit ${PCBIOS_CLASS}
-inherit ${EFI_CLASS}
-
 DISK_SIGNATURE ?= "${DISK_SIGNATURE_GENERATED}"
 
-boot_direct_populate() {
-       dest=$1
-       install -d $dest
-
-       # Install bzImage, initrd, and rootfs.img in DEST for all loaders to use.
-       if [ -e ${DEPLOY_DIR_IMAGE}/bzImage ]; then
-               install -m 0644 ${DEPLOY_DIR_IMAGE}/bzImage $dest/vmlinuz
-       fi
-
-       # initrd is made of concatenation of multiple filesystem images
-       if [ -n "${INITRD}" ]; then
-               rm -f $dest/initrd
-               for fs in ${INITRD}
-               do
-                       if [ -s "${fs}" ]; then
-                               cat ${fs} >> $dest/initrd
-                       else
-                               bbfatal "${fs} is invalid. initrd image creation failed."
-                       fi
-               done
-               chmod 0644 $dest/initrd
-       fi
-}
-
 build_boot_dd() {
        HDDDIR="${S}/hdd/boot"
        HDDIMG="${S}/hdd.image"
        IMAGE=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hdddirect
 
-       boot_direct_populate $HDDDIR
+       populate_kernel $HDDDIR
 
        if [ "${PCBIOS}" = "1" ]; then
                syslinux_hddimg_populate $HDDDIR
index 894ff993cc939c408f83fc7c09cb5b4ff2b0b876..d9c16106c26124ec6780917e0dc8ddf28944ed06 100644 (file)
@@ -544,15 +544,3 @@ do_bundle_initramfs () {
 }
 addtask bundle_initramfs after do_image_complete
 
-# Some of the vars for vm and live image are conflicted, this function
-# is used for fixing the problem.
-def set_live_vm_vars(d, suffix):
-    vars = ['GRUB_CFG', 'SYSLINUX_CFG', 'ROOT', 'LABELS', 'INITRD']
-    for var in vars:
-        var_with_suffix = var + '_' + suffix
-        if d.getVar(var, True):
-            bb.warn('Found potential conflicted var %s, please use %s rather than %s' % \
-                (var, var_with_suffix, var))
-        elif d.getVar(var_with_suffix, True):
-            d.setVar(var, d.getVar(var_with_suffix, True))
-
diff --git a/meta/classes/live-vm-common.bbclass b/meta/classes/live-vm-common.bbclass
new file mode 100644 (file)
index 0000000..c751385
--- /dev/null
@@ -0,0 +1,58 @@
+# Some of the vars for vm and live image are conflicted, this function
+# is used for fixing the problem.
+def set_live_vm_vars(d, suffix):
+    vars = ['GRUB_CFG', 'SYSLINUX_CFG', 'ROOT', 'LABELS', 'INITRD']
+    for var in vars:
+        var_with_suffix = var + '_' + suffix
+        if d.getVar(var, True):
+            bb.warn('Found potential conflicted var %s, please use %s rather than %s' % \
+                (var, var_with_suffix, var))
+        elif d.getVar(var_with_suffix, True):
+            d.setVar(var, d.getVar(var_with_suffix, True))
+
+
+EFI = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "1", "0", d)}"
+EFI_PROVIDER ?= "grub-efi"
+EFI_CLASS = "${@bb.utils.contains("MACHINE_FEATURES", "efi", "${EFI_PROVIDER}", "", d)}"
+
+# Include legacy boot if MACHINE_FEATURES includes "pcbios" or if it does not
+# contain "efi". This way legacy is supported by default if neither is
+# specified, maintaining the original behavior.
+def pcbios(d):
+    pcbios = bb.utils.contains("MACHINE_FEATURES", "pcbios", "1", "0", d)
+    if pcbios == "0":
+        pcbios = bb.utils.contains("MACHINE_FEATURES", "efi", "0", "1", d)
+    return pcbios
+
+PCBIOS = "${@pcbios(d)}"
+PCBIOS_CLASS = "${@['','syslinux'][d.getVar('PCBIOS', True) == '1']}"
+
+inherit ${EFI_CLASS}
+inherit ${PCBIOS_CLASS}
+
+KERNEL_IMAGETYPE ??= "bzImage"
+
+populate_kernel() {
+       dest=$1
+       install -d $dest
+
+       # Install bzImage, initrd, and rootfs.img in DEST for all loaders to use.
+       if [ -e ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ]; then
+               install -m 0644 ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} $dest/vmlinuz
+       fi
+
+       # initrd is made of concatenation of multiple filesystem images
+       if [ -n "${INITRD}" ]; then
+               rm -f $dest/initrd
+               for fs in ${INITRD}
+               do
+                       if [ -s "$fs" ]; then
+                               cat $fs >> $dest/initrd
+                       else
+                               bbfatal "$fs is invalid. initrd image creation failed."
+                       fi
+               done
+               chmod 0644 $dest/initrd
+       fi
+}
+