def do_install_disk(cls, disk, disk_name, cr, workdir, oe_builddir,
                        bootimg_dir, kernel_dir, native_sysroot):
        """
        Called after all partitions have been prepared and assembled into a
        disk image.  In this case, we insert/modify the MBR using isohybrid
        utility for booting via BIOS from disk storage devices.
        """

        full_path = cr._full_path(workdir, disk_name, "direct")
        iso_img = "%s.p1" % full_path
        full_path_iso = cr._full_path(workdir, disk_name, "iso")

        isohybrid_cmd = "isohybrid -u %s" % iso_img
        msger.debug("running command: %s" % \
                    isohybrid_cmd)
        exec_native_cmd(isohybrid_cmd, native_sysroot)

        # Replace the image created by direct plugin with the one created by
        # mkisofs command. This is necessary because the iso image created by
        # mkisofs has a very specific MBR is system area of the ISO image, and
        # direct plugin adds and configures an another MBR.
        msger.debug("Replaceing the image created by direct plugin\n")
        os.remove(full_path)
        shutil.copy2(iso_img, full_path_iso)
        shutil.copy2(full_path_iso, full_path)

        # Remove temporary ISO file
        os.remove(iso_img)
Esempio n. 2
0
    def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
                             native_sysroot, pseudo):
        """
        Prepare content for a btrfs rootfs partition.

        Currently handles ext2/3/4 and btrfs.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(actual_rootfs_size)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        rootfs_size = actual_rootfs_size + extra_blocks
        rootfs_size *= self.overhead_factor

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, rootfs_size))

        dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
            (rootfs, rootfs_size)
        exec_cmd(dd_cmd)

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \
            (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 3
0
    def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
                           native_sysroot, pseudo):
        """
        Prepare content for an ext2/3/4 rootfs partition.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(actual_rootfs_size)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        rootfs_size = actual_rootfs_size + extra_blocks
        rootfs_size *= self.overhead_factor

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, rootfs_size))

        dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \
            (rootfs, rootfs_size)
        exec_cmd(dd_cmd)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \
            (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 4
0
    def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
                                         native_sysroot):
        """
        Prepare an empty squashfs partition.
        """
        msger.warning("Creating of an empty squashfs %s partition was attempted. " \
                      "Proceeding as requested." % self.mountpoint)

        path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
        os.path.isfile(path) and os.remove(path)

        # it is not possible to create a squashfs without source data,
        # thus prepare an empty temp dir that is used as source
        tmpdir = tempfile.mkdtemp()

        squashfs_cmd = "mksquashfs %s %s -noappend" % \
                       (tmpdir, path)
        exec_native_cmd(squashfs_cmd, native_sysroot)

        os.rmdir(tmpdir)

        # get the rootfs size in the right units for kickstart (kB)
        du_cmd = "du -Lbks %s" % path
        out = exec_cmd(du_cmd)
        fs_size = out.split()[0]

        self.size = fs_size
Esempio n. 5
0
    def finalize(self):
        """
        Finalize the disk image.

        For example, prepare the image to be bootable by e.g.
        creating and installing a bootloader configuration.

        """
        source_plugin = self.get_default_source_plugin()
        if source_plugin:
            self._source_methods = pluginmgr.get_source_plugin_methods(source_plugin, disk_methods)
            for disk_name, disk in self.__image.disks.items():
                self._source_methods["do_install_disk"](disk, disk_name, self,
                                                        self.workdir,
                                                        self.oe_builddir,
                                                        self.bootimg_dir,
                                                        self.kernel_dir,
                                                        self.native_sysroot)

        for disk_name, disk in self.__image.disks.items():
            full_path = self._full_path(self.__imgdir, disk_name, "direct")
            # Generate .bmap
            if self.bmap:
                msger.debug("Generating bmap file for %s" % disk_name)
                exec_native_cmd("bmaptool create %s -o %s.bmap" % (full_path, full_path),
                                self.native_sysroot)
            # Compress the image
            if self.compressor:
                msger.debug("Compressing disk %s with %s" % (disk_name, self.compressor))
                exec_cmd("%s %s" % (self.compressor, full_path))
Esempio n. 6
0
    def finalize(self):
        """
        Finalize the disk image.

        For example, prepare the image to be bootable by e.g.
        creating and installing a bootloader configuration.

        """
        source_plugin = self.get_default_source_plugin()
        if source_plugin:
            self._source_methods = pluginmgr.get_source_plugin_methods(
                source_plugin, disk_methods)
            for disk_name, disk in self.__image.disks.items():
                self._source_methods["do_install_disk"](
                    disk, disk_name, self, self.workdir, self.oe_builddir,
                    self.bootimg_dir, self.kernel_dir, self.native_sysroot)

        for disk_name, disk in self.__image.disks.items():
            full_path = self._full_path(self.__imgdir, disk_name, "direct")
            # Generate .bmap
            if self.bmap:
                msger.debug("Generating bmap file for %s" % disk_name)
                exec_native_cmd(
                    "bmaptool create %s -o %s.bmap" % (full_path, full_path),
                    self.native_sysroot)
            # Compress the image
            if self.compressor:
                msger.debug("Compressing disk %s with %s" %
                            (disk_name, self.compressor))
                exec_cmd("%s %s" % (self.compressor, full_path))
Esempio n. 7
0
    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
                            native_sysroot, pseudo):
        """
        Prepare content for a vfat rootfs partition.
        """
        du_cmd = "du -bks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(blocks)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, blocks))

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 8
0
    def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
                           native_sysroot, pseudo):
        """
        Prepare content for an ext2/3/4 rootfs partition.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(actual_rootfs_size)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        rootfs_size = actual_rootfs_size + extra_blocks
        rootfs_size *= self.overhead_factor

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, rootfs_size))

        exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \
            (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)

        mkfs_cmd = "fsck.%s -pvfD %s || [ $? -le 3 ]" % (self.fstype, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 9
0
    def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
                           native_sysroot, pseudo):
        """
        Prepare content for an ext2/3/4 rootfs partition.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(actual_rootfs_size)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        rootfs_size = actual_rootfs_size + extra_blocks
        rootfs_size *= self.overhead_factor

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, rootfs_size))

        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), rootfs_size * 1024)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \
            (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 10
0
    def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
                             native_sysroot, pseudo):
        """
        Prepare content for a btrfs rootfs partition.

        Currently handles ext2/3/4 and btrfs.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(actual_rootfs_size)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        rootfs_size = actual_rootfs_size + extra_blocks
        rootfs_size *= self.overhead_factor

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, rootfs_size))

        exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024))

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \
            (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 11
0
    def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
                        bootimg_dir, kernel_dir, native_sysroot):
        """
        Called after all partitions have been prepared and assembled into a
        disk image.  In this case, we insert/modify the MBR using isohybrid
        utility for booting via BIOS from disk storage devices.
        """

        full_path = creator._full_path(workdir, disk_name, "direct")
        iso_img = "%s.p1" % full_path
        full_path_iso = creator._full_path(workdir, disk_name, "iso")

        isohybrid_cmd = "isohybrid -u %s" % iso_img
        msger.debug("running command: %s" % \
                    isohybrid_cmd)
        exec_native_cmd(isohybrid_cmd, native_sysroot)

        # Replace the image created by direct plugin with the one created by
        # mkisofs command. This is necessary because the iso image created by
        # mkisofs has a very specific MBR is system area of the ISO image, and
        # direct plugin adds and configures an another MBR.
        msger.debug("Replaceing the image created by direct plugin\n")
        os.remove(full_path)
        shutil.copy2(iso_img, full_path_iso)
        shutil.copy2(full_path_iso, full_path)

        # Remove temporary ISO file
        os.remove(iso_img)
Esempio n. 12
0
    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
                            native_sysroot, pseudo):
        """
        Prepare content for a vfat rootfs partition.
        """
        du_cmd = "du -bks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(blocks)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, blocks))

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 13
0
    def prepare_empty_partition_squashfs(self, cr_workdir, oe_builddir,
                                         native_sysroot):
        """
        Prepare an empty squashfs partition.
        """
        msger.warning("Creating of an empty squashfs %s partition was attempted. " \
                      "Proceeding as requested." % self.mountpoint)

        path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
        os.path.isfile(path) and os.remove(path)

        # it is not possible to create a squashfs without source data,
        # thus prepare an empty temp dir that is used as source
        tmpdir = tempfile.mkdtemp()

        squashfs_cmd = "mksquashfs %s %s -noappend" % \
                       (tmpdir, path)
        exec_native_cmd(squashfs_cmd, native_sysroot)

        os.rmdir(tmpdir)

        # get the rootfs size in the right units for kickstart (kB)
        du_cmd = "du -Lbks %s" % path
        out = exec_cmd(du_cmd)
        fs_size = out.split()[0]

        self.size = fs_size
Esempio n. 14
0
 def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
                             native_sysroot, pseudo):
     """
     Prepare content for a squashfs rootfs partition.
     """
     squashfs_cmd = "mksquashfs %s %s -noappend" % \
                    (rootfs_dir, rootfs)
     exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 15
0
 def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
                             native_sysroot, pseudo):
     """
     Prepare content for a squashfs rootfs partition.
     """
     squashfs_cmd = "mksquashfs %s %s -noappend" % \
                    (rootfs_dir, rootfs)
     exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 16
0
    def prepare_empty_partition_btrfs(self, rootfs, oe_builddir, native_sysroot):
        """
        Prepare an empty btrfs partition.
        """
        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % (rootfs, self.size)
        exec_cmd(dd_cmd)

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d %s %s" % (self.fstype, self.size * 1024, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 17
0
    def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
                                      native_sysroot):
        """
        Prepare an empty btrfs partition.
        """
        exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d %s %s" % \
            (self.fstype, self.size * 1024, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 18
0
    def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
        """
        Prepare a swap partition.
        """
        path = "%s/fs.%s" % (cr_workdir, self.fstype)

        exec_cmd("truncate %s -s %d" % (path, self.size * 1024))

        import uuid
        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label
        mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
        exec_native_cmd(mkswap_cmd, native_sysroot)
Esempio n. 19
0
    def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
                                      native_sysroot):
        """
        Prepare an empty btrfs partition.
        """
        exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d %s %s" % \
            (self.fstype, self.size * 1024, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 20
0
    def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
        """
        Prepare a swap partition.
        """
        path = "%s/fs.%s" % (cr_workdir, self.fstype)

        exec_cmd("truncate %s -s %d" % (path, self.size * 1024))

        import uuid
        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label
        mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
        exec_native_cmd(mkswap_cmd, native_sysroot)
Esempio n. 21
0
    def prepare_empty_partition_vfat(self, rootfs, oe_builddir, native_sysroot):
        """
        Prepare an empty vfat partition.
        """
        blocks = self.size

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 22
0
    def prepare_empty_partition_ext(self, rootfs, oe_builddir, native_sysroot):
        """
        Prepare an empty ext2/3/4 partition.
        """
        exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s" % \
            (self.fstype, extra_imagecmd, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 23
0
    def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
                                      native_sysroot):
        """
        Prepare an empty btrfs partition.
        """
        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), rootfs_size * 1024)

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d %s %s" % \
            (self.fstype, self.size * 1024, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 24
0
    def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
        """
        Prepare a swap partition.
        """
        path = "%s/fs.%s" % (cr_workdir, self.fstype)

        with open(path, 'w') as sparse:
            os.ftruncate(sparse.fileno(), self.size * 1024)

        import uuid
        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label
        mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
        exec_native_cmd(mkswap_cmd, native_sysroot)
Esempio n. 25
0
    def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
        """
        Prepare a swap partition.
        """
        path = "%s/fs.%s" % (cr_workdir, self.fstype)

        with open(path, 'w') as sparse:
            os.ftruncate(sparse.fileno(), self.size * 1024)

        import uuid
        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label
        mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
        exec_native_cmd(mkswap_cmd, native_sysroot)
Esempio n. 26
0
    def prepare_empty_partition_ext(self, rootfs, oe_builddir, native_sysroot):
        """
        Prepare an empty ext2/3/4 partition.
        """
        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % (rootfs, self.size)
        exec_cmd(dd_cmd)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s" % (self.fstype, extra_imagecmd, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 27
0
    def prepare_empty_partition_ext(self, rootfs, oe_builddir,
                                    native_sysroot):
        """
        Prepare an empty ext2/3/4 partition.
        """
        exec_cmd("truncate %s -s %d" % (rootfs, self.size * 1024))

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s" % \
            (self.fstype, extra_imagecmd, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 28
0
    def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
        """
        Prepare a swap partition.
        """
        path = "%s/fs.%s" % (cr_workdir, self.fstype)

        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
            (path, self.size)
        exec_cmd(dd_cmd)

        import uuid
        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label
        mkswap_cmd = "mkswap %s -U %s %s" % (label_str, str(uuid.uuid1()), path)
        exec_native_cmd(mkswap_cmd, native_sysroot)
Esempio n. 29
0
    def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
                                      native_sysroot):
        """
        Prepare an empty btrfs partition.
        """
        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
            (rootfs, self.size)
        exec_cmd(dd_cmd)

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d %s %s" % \
            (self.fstype, self.size * 1024, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 30
0
    def prepare_empty_partition_vfat(self, rootfs, oe_builddir,
                                     native_sysroot):
        """
        Prepare an empty vfat partition.
        """
        blocks = self.size

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 31
0
    def do_prepare_partition(cls, part, source_params, image_creator,
                             image_creator_workdir, oe_builddir, bootimg_dir,
                             kernel_dir, krootfs_dir, native_sysroot):
        """
        Creates partition out of rootfs directory

        Prepare content for a rootfs partition i.e. create a partition
        and fill it from a /rootfs dir.
        Install syslinux bootloader into root partition image file
        """
        def is_exe(exepath):
            """Verify exepath is an executable file"""
            return os.path.isfile(exepath) and os.access(exepath, os.X_OK)

        # Make sure syslinux-nomtools is available in native sysroot or fail
        native_syslinux_nomtools = os.path.join(native_sysroot,
                                                "usr/bin/syslinux-nomtools")
        if not is_exe(native_syslinux_nomtools):
            msger.info("building syslinux-native...")
            misc.exec_cmd("bitbake syslinux-native")
        if not is_exe(native_syslinux_nomtools):
            msger.error("Couldn't find syslinux-nomtools (%s), exiting\n" %
                        native_syslinux_nomtools)

        if part.rootfs is None:
            if 'ROOTFS_DIR' not in krootfs_dir:
                msger.error("Couldn't find --rootfs-dir, exiting")
            rootfs_dir = krootfs_dir['ROOTFS_DIR']
        else:
            if part.rootfs in krootfs_dir:
                rootfs_dir = krootfs_dir[part.rootfs]
            elif part.rootfs:
                rootfs_dir = part.rootfs
            else:
                msg = "Couldn't find --rootfs-dir=%s connection"
                msg += " or it is not a valid path, exiting"
                msger.error(msg % part.rootfs)

        real_rootfs_dir = cls._get_rootfs_dir(rootfs_dir)

        part.set_rootfs(real_rootfs_dir)
        part.prepare_rootfs(image_creator_workdir, oe_builddir,
                            real_rootfs_dir, native_sysroot)

        # install syslinux into rootfs partition
        syslinux_cmd = "syslinux-nomtools -d /boot -i %s" % part.source_file
        misc.exec_native_cmd(syslinux_cmd, native_sysroot)
Esempio n. 32
0
    def prepare_empty_partition_ext(self, rootfs, oe_builddir, native_sysroot):
        """
        Prepare an empty ext2/3/4 partition.
        """
        size = self.disk_size
        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), size * 1024)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s" % \
            (self.fstype, extra_imagecmd, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 33
0
    def prepare_empty_partition_ext(self, rootfs, oe_builddir, native_sysroot):
        """
        Prepare an empty ext2/3/4 partition.
        """
        dd_cmd = "dd if=/dev/zero of=%s bs=1k seek=%d count=0" % \
            (rootfs, self.size)
        exec_cmd(dd_cmd)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s" % \
            (self.fstype, extra_imagecmd, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
Esempio n. 34
0
    def prepare_empty_partition_ext(self, rootfs, oe_builddir,
                                    native_sysroot):
        """
        Prepare an empty ext2/3/4 partition.
        """
        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), rootfs_size * 1024)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s" % \
            (self.fstype, extra_imagecmd, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot)
    def do_prepare_partition(cls, part, source_params, image_creator,
                             image_creator_workdir, oe_builddir, bootimg_dir,
                             kernel_dir, krootfs_dir, native_sysroot):
        """
        Creates partition out of rootfs directory

        Prepare content for a rootfs partition i.e. create a partition
        and fill it from a /rootfs dir.
        Install syslinux bootloader into root partition image file
        """
        def is_exe(exepath):
            """Verify exepath is an executable file"""
            return os.path.isfile(exepath) and os.access(exepath, os.X_OK)

        # Make sure syslinux-nomtools is available in native sysroot or fail
        native_syslinux_nomtools = os.path.join(native_sysroot, "usr/bin/syslinux-nomtools")
        if not is_exe(native_syslinux_nomtools):
            msger.info("building syslinux-native...")
            misc.exec_cmd("bitbake syslinux-native")
        if not is_exe(native_syslinux_nomtools):
            msger.error("Couldn't find syslinux-nomtools (%s), exiting\n" %
                        native_syslinux_nomtools)

        if part.rootfs is None:
            if 'ROOTFS_DIR' not in krootfs_dir:
                msger.error("Couldn't find --rootfs-dir, exiting")
            rootfs_dir = krootfs_dir['ROOTFS_DIR']
        else:
            if part.rootfs in krootfs_dir:
                rootfs_dir = krootfs_dir[part.rootfs]
            elif part.rootfs:
                rootfs_dir = part.rootfs
            else:
                msg = "Couldn't find --rootfs-dir=%s connection"
                msg += " or it is not a valid path, exiting"
                msger.error(msg % part.rootfs)

        real_rootfs_dir = cls._get_rootfs_dir(rootfs_dir)

        part.set_rootfs(real_rootfs_dir)
        part.prepare_rootfs(image_creator_workdir, oe_builddir, real_rootfs_dir, native_sysroot)

        # install syslinux into rootfs partition
        syslinux_cmd = "syslinux-nomtools -d /boot -i %s" % part.source_file
        misc.exec_native_cmd(syslinux_cmd, native_sysroot)
Esempio n. 36
0
    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
                            native_sysroot, pseudo):
        """
        Prepare content for a vfat rootfs partition.
        """
        du_cmd = "du -bks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(blocks)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, blocks))

        # Ensure total sectors is an integral number of sectors per
        # track or mcopy will complain. Sectors are 512 bytes, and we
        # generate images with 32 sectors per track. This calculation
        # is done in blocks, thus the mod by 16 instead of 32. Apply
        # sector count fix only when needed.
        if blocks % 16 != 0:
            blocks += (16 - (blocks % 16))

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 37
0
    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
                            native_sysroot, pseudo):
        """
        Prepare content for a vfat rootfs partition.
        """
        du_cmd = "du -bks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = self.get_extra_block_count(blocks)
        if extra_blocks < self.extra_space:
            extra_blocks = self.extra_space

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, self.mountpoint, blocks))

        # Ensure total sectors is an integral number of sectors per
        # track or mcopy will complain. Sectors are 512 bytes, and we
        # generate images with 32 sectors per track. This calculation
        # is done in blocks, thus the mod by 16 instead of 32. Apply
        # sector count fix only when needed.
        if blocks % 16 != 0:
            blocks += (16 - (blocks % 16))

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 38
0
    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
                            native_sysroot, pseudo):
        """
        Prepare content for a vfat rootfs partition.
        """
        du_cmd = "du -bks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        rootfs_size = self.get_rootfs_size(blocks)

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, rootfs_size)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 39
0
    def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
                             native_sysroot, pseudo):
        """
        Prepare content for a btrfs rootfs partition.

        Currently handles ext2/3/4 and btrfs.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        rootfs_size = self.get_rootfs_size(actual_rootfs_size)

        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), rootfs_size * 1024)

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \
            (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
    def __create_partition(self, device, parttype, fstype, start, size):
        """ Create a partition on an image described by the 'device' object. """

        # Start is included to the size so we need to substract one from the end.
        end = start + size - 1
        msger.debug("Added '%s' partition, sectors %d-%d, size %d sectors" %
                    (parttype, start, end, size))

        cmd = "parted -s %s unit s mkpart %s" % (device, parttype)
        if fstype:
            cmd += " %s" % fstype
        cmd += " %d %d" % (start, end)

        return exec_native_cmd(cmd, self.native_sysroot)
Esempio n. 41
0
    def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir,
                            native_sysroot, pseudo):
        """
        Prepare content for a vfat rootfs partition.
        """
        du_cmd = "du -bks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        rootfs_size = self.get_rootfs_size(blocks)

        label_str = "-n boot"
        if self.label:
            label_str = "-n %s" % self.label

        dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, rootfs_size)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % rootfs
        exec_cmd(chmod_cmd)
Esempio n. 42
0
    def __create_partition(self, device, parttype, fstype, start, size):
        """ Create a partition on an image described by the 'device' object. """

        # Start is included to the size so we need to substract one from the end.
        end = start + size - 1
        msger.debug("Added '%s' partition, sectors %d-%d, size %d sectors" %
                    (parttype, start, end, size))

        cmd = "parted -s %s unit s mkpart %s" % (device, parttype)
        if fstype:
            cmd += " %s" % fstype
        cmd += " %d %d" % (start, end)

        return exec_native_cmd(cmd, self.native_sysroot)
Esempio n. 43
0
    def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
                             native_sysroot, pseudo):
        """
        Prepare content for a btrfs rootfs partition.

        Currently handles ext2/3/4 and btrfs.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        rootfs_size = self.get_rootfs_size(actual_rootfs_size)

        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), rootfs_size * 1024)

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \
            (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 44
0
    def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
                           native_sysroot, pseudo):
        """
        Prepare content for an ext2/3/4 rootfs partition.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        rootfs_size = self.get_rootfs_size(actual_rootfs_size)

        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), rootfs_size * 1024)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \
            (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 45
0
    def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
                           native_sysroot, pseudo):
        """
        Prepare content for an ext2/3/4 rootfs partition.
        """
        du_cmd = "du -ks %s" % rootfs_dir
        out = exec_cmd(du_cmd)
        actual_rootfs_size = int(out.split()[0])

        rootfs_size = self.get_rootfs_size(actual_rootfs_size)

        with open(rootfs, 'w') as sparse:
            os.ftruncate(sparse.fileno(), rootfs_size * 1024)

        extra_imagecmd = "-i 8192"

        label_str = ""
        if self.label:
            label_str = "-L %s" % self.label

        mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \
            (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir)
        exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
Esempio n. 46
0
    def __run_parted(self, args):
        """ Run parted with arguments specified in the 'args' list. """

        args.insert(0, "parted")
        args = ' '.join(args)
        msger.debug(args)

        rc, out = exec_native_cmd(args, self.native_sysroot)

        if out:
            msger.debug('"parted" output: %s' % out)

        if rc != 0:
            # We don't throw exception when return code is not 0, because
            # parted always fails to reload part table with loop devices. This
            # prevents us from distinguishing real errors based on return
            # code.
            msger.error("WARNING: parted returned '%s' instead of 0 (use --debug for details)" % rc)
Esempio n. 47
0
    def __run_parted(self, args):
        """ Run parted with arguments specified in the 'args' list. """

        args.insert(0, "parted")
        args = ' '.join(args)
        msger.debug(args)

        rc, out = exec_native_cmd(args, self.native_sysroot)

        if out:
            msger.debug('"parted" output: %s' % out)

        if rc != 0:
            # We don't throw exception when return code is not 0, because
            # parted always fails to reload part table with loop devices. This
            # prevents us from distinguishing real errors based on return
            # code.
            msger.error(
                "WARNING: parted returned '%s' instead of 0 (use --debug for details)"
                % rc)
    def __format_disks(self):
        self.layout_partitions()

        for dev in self.disks.keys():
            d = self.disks[dev]
            msger.debug("Initializing partition table for %s" % \
                        (d['disk'].device))
            exec_native_cmd("parted -s %s mklabel %s" % \
                            (d['disk'].device, d['ptable_format']),
                            self.native_sysroot)

        msger.debug("Creating partitions")

        for p in self.partitions:
            if p['num'] == 0:
                continue

            d = self.disks[p['disk_name']]
            if d['ptable_format'] == "msdos" and p['num'] == 5:
                # Create an extended partition (note: extended
                # partition is described in MBR and contains all
                # logical partitions). The logical partitions save a
                # sector for an EBR just before the start of a
                # partition. The extended partition must start one
                # sector before the start of the first logical
                # partition. This way the first EBR is inside of the
                # extended partition. Since the extended partitions
                # starts a sector before the first logical partition,
                # add a sector at the back, so that there is enough
                # room for all logical partitions.
                self.__create_partition(d['disk'].device, "extended",
                                        None, p['start'] - 1,
                                        d['offset'] - p['start'] + 1)

            if p['fstype'] == "swap":
                parted_fs_type = "linux-swap"
            elif p['fstype'] == "vfat":
                parted_fs_type = "fat32"
            elif p['fstype'] == "msdos":
                parted_fs_type = "fat16"
            elif p['fstype'] == "ontrackdm6aux3":
                parted_fs_type = "ontrackdm6aux3"
            else:
                # Type for ext2/ext3/ext4/btrfs
                parted_fs_type = "ext2"

            # Boot ROM of OMAP boards require vfat boot partition to have an
            # even number of sectors.
            if p['mountpoint'] == "/boot" and p['fstype'] in ["vfat", "msdos"] \
               and p['size'] % 2:
                msger.debug("Substracting one sector from '%s' partition to " \
                            "get even number of sectors for the partition" % \
                            p['mountpoint'])
                p['size'] -= 1

            self.__create_partition(d['disk'].device, p['type'],
                                    parted_fs_type, p['start'], p['size'])

            if p['part_type']:
                msger.debug("partition %d: set type UID to %s" % \
                            (p['num'], p['part_type']))
                exec_native_cmd("sgdisk --typecode=%d:%s %s" % \
                                         (p['num'], p['part_type'],
                                          d['disk'].device), self.native_sysroot)

            if p['uuid']:
                msger.debug("partition %d: set UUID to %s" % \
                            (p['num'], p['uuid']))
                exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \
                                         (p['num'], p['uuid'],
                                          d['disk'].device),
                                        self.native_sysroot)

            if p['boot']:
                flag_name = "legacy_boot" if d['ptable_format'] == 'gpt' else "boot"
                msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \
                            (flag_name, p['num'], d['disk'].device))
                exec_native_cmd("parted -s %s set %d %s on" % \
                                (d['disk'].device, p['num'], flag_name),
                                self.native_sysroot)

            # Parted defaults to enabling the lba flag for fat16 partitions,
            # which causes compatibility issues with some firmware (and really
            # isn't necessary).
            if parted_fs_type == "fat16":
                if d['ptable_format'] == 'msdos':
                    msger.debug("Disable 'lba' flag for partition '%s' on disk '%s'" % \
                                (p['num'], d['disk'].device))
                    exec_native_cmd("parted -s %s set %d lba off" % \
                                    (d['disk'].device, p['num']),
                                    self.native_sysroot)
Esempio n. 49
0
    def do_prepare_partition(cls, part, source_params, cr, cr_workdir,
                             oe_builddir, bootimg_dir, kernel_dir, rootfs_dir,
                             native_sysroot):
        """
        Called to do the actual content population for a partition i.e. it
        'prepares' the partition to be incorporated into the image.
        In this case, prepare content for legacy bios boot partition.
        """
        def _has_syslinux(dir):
            if dir:
                syslinux = "%s/syslinux" % dir
                if os.path.exists(syslinux):
                    return True
            return False

        if not _has_syslinux(bootimg_dir):
            bootimg_dir = get_bitbake_var("STAGING_DATADIR")
            if not bootimg_dir:
                msger.error("Couldn't find STAGING_DATADIR, exiting\n")
            if not _has_syslinux(bootimg_dir):
                msger.error("Please build syslinux first\n")
            # just so the result notes display it
            cr.set_bootimg_dir(bootimg_dir)

        staging_kernel_dir = kernel_dir

        hdddir = "%s/hdd/boot" % cr_workdir

        install_cmd = "install -m 0644 %s/bzImage %s/vmlinuz" \
            % (staging_kernel_dir, hdddir)
        exec_cmd(install_cmd)

        install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \
            % (bootimg_dir, hdddir)
        exec_cmd(install_cmd)

        du_cmd = "du -bks %s" % hdddir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = part.get_extra_block_count(blocks)

        if extra_blocks < BOOTDD_EXTRA_SPACE:
            extra_blocks = BOOTDD_EXTRA_SPACE

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, part.mountpoint, blocks))

        # Ensure total sectors is an integral number of sectors per
        # track or mcopy will complain. Sectors are 512 bytes, and we
        # generate images with 32 sectors per track. This calculation is
        # done in blocks, thus the mod by 16 instead of 32.
        blocks += (16 - (blocks % 16))

        # dosfs image, created by mkdosfs
        bootimg = "%s/boot.img" % cr_workdir

        dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        syslinux_cmd = "syslinux %s" % bootimg
        exec_native_cmd(syslinux_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % bootimg
        exec_cmd(chmod_cmd)

        du_cmd = "du -Lbks %s" % bootimg
        out = exec_cmd(du_cmd)
        bootimg_size = out.split()[0]

        part.set_size(bootimg_size)
        part.set_source_file(bootimg)
Esempio n. 50
0
    def __format_disks(self):
        self.layout_partitions()

        for dev in self.disks:
            disk = self.disks[dev]
            msger.debug("Initializing partition table for %s" % \
                        (disk['disk'].device))
            exec_native_cmd("parted -s %s mklabel %s" % \
                            (disk['disk'].device, disk['ptable_format']),
                            self.native_sysroot)

            if disk['identifier']:
                msger.debug("Set disk identifier %x" % disk['identifier'])
                with open(disk['disk'].device, 'r+b') as img:
                    img.seek(0x1B8)
                    img.write(disk['identifier'].to_bytes(4, 'little'))

        msger.debug("Creating partitions")

        for part in self.partitions:
            if part['num'] == 0:
                continue

            disk = self.disks[part['disk_name']]
            if disk['ptable_format'] == "msdos" and part['num'] == 5:
                # Create an extended partition (note: extended
                # partition is described in MBR and contains all
                # logical partitions). The logical partitions save a
                # sector for an EBR just before the start of a
                # partition. The extended partition must start one
                # sector before the start of the first logical
                # partition. This way the first EBR is inside of the
                # extended partition. Since the extended partitions
                # starts a sector before the first logical partition,
                # add a sector at the back, so that there is enough
                # room for all logical partitions.
                self.__create_partition(disk['disk'].device, "extended", None,
                                        part['start'] - 1,
                                        disk['offset'] - part['start'] + 1)

            if part['fstype'] == "swap":
                parted_fs_type = "linux-swap"
            elif part['fstype'] == "vfat":
                parted_fs_type = "fat32"
            elif part['fstype'] == "msdos":
                parted_fs_type = "fat16"
            elif part['fstype'] == "ontrackdm6aux3":
                parted_fs_type = "ontrackdm6aux3"
            else:
                # Type for ext2/ext3/ext4/btrfs
                parted_fs_type = "ext2"

            # Boot ROM of OMAP boards require vfat boot partition to have an
            # even number of sectors.
            if part['mountpoint'] == "/boot" and part['fstype'] in ["vfat", "msdos"] \
               and part['size'] % 2:
                msger.debug("Subtracting one sector from '%s' partition to " \
                            "get even number of sectors for the partition" % \
                            part['mountpoint'])
                part['size'] -= 1

            self.__create_partition(disk['disk'].device, part['type'],
                                    parted_fs_type, part['start'],
                                    part['size'])

            if part['part_type']:
                msger.debug("partition %d: set type UID to %s" % \
                            (part['num'], part['part_type']))
                exec_native_cmd("sgdisk --typecode=%d:%s %s" % \
                                         (part['num'], part['part_type'],
                                          disk['disk'].device), self.native_sysroot)

            if part['uuid'] and disk['ptable_format'] == "gpt":
                msger.debug("partition %d: set UUID to %s" % \
                            (part['num'], part['uuid']))
                exec_native_cmd("sgdisk --partition-guid=%d:%s %s" % \
                                (part['num'], part['uuid'], disk['disk'].device),
                                self.native_sysroot)

            if part['boot']:
                flag_name = "legacy_boot" if disk[
                    'ptable_format'] == 'gpt' else "boot"
                msger.debug("Set '%s' flag for partition '%s' on disk '%s'" % \
                            (flag_name, part['num'], disk['disk'].device))
                exec_native_cmd("parted -s %s set %d %s on" % \
                                (disk['disk'].device, part['num'], flag_name),
                                self.native_sysroot)
            if part['system_id']:
                exec_native_cmd("sfdisk --part-type %s %s %s" % \
                                (disk['disk'].device, part['num'], part['system_id']),
                                self.native_sysroot)

            # Parted defaults to enabling the lba flag for fat16 partitions,
            # which causes compatibility issues with some firmware (and really
            # isn't necessary).
            if parted_fs_type == "fat16":
                if disk['ptable_format'] == 'msdos':
                    msger.debug("Disable 'lba' flag for partition '%s' on disk '%s'" % \
                                (part['num'], disk['disk'].device))
                    exec_native_cmd("parted -s %s set %d lba off" % \
                                    (disk['disk'].device, part['num']),
                                    self.native_sysroot)
Esempio n. 51
0
    def do_prepare_partition(self, part, source_params, cr, cr_workdir,
                             oe_builddir, bootimg_dir, kernel_dir, rootfs_dir,
                             native_sysroot):
        """
        Called to do the actual content population for a partition i.e. it
        'prepares' the partition to be incorporated into the image.
        In this case, prepare content for an EFI (grub) boot partition.
        """
        if not bootimg_dir:
            bootimg_dir = get_bitbake_var("HDDDIR")
            if not bootimg_dir:
                msger.error("Couldn't find HDDDIR, exiting\n")
            # just so the result notes display it
            cr.set_bootimg_dir(bootimg_dir)

        staging_kernel_dir = kernel_dir

        hdddir = "%s/hdd/boot" % cr_workdir

        install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
            (staging_kernel_dir, hdddir)
        exec_cmd(install_cmd)

        try:
            if source_params['loader'] == 'grub-efi':
                shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir,
                                "%s/grub.cfg" % cr_workdir)
                cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir)
                exec_cmd(cp_cmd, True)
                shutil.move("%s/grub.cfg" % cr_workdir,
                            "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir)
            elif source_params['loader'] == 'gummiboot':
                cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir)
                exec_cmd(cp_cmd, True)
            else:
                msger.error("unrecognized bootimg-efi loader: %s" %
                            source_params['loader'])
        except KeyError:
            msger.error("bootimg-efi requires a loader, none specified")

        du_cmd = "du -bks %s" % hdddir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = part.get_extra_block_count(blocks)

        if extra_blocks < BOOTDD_EXTRA_SPACE:
            extra_blocks = BOOTDD_EXTRA_SPACE

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, part.mountpoint, blocks))

        # Ensure total sectors is an integral number of sectors per
        # track or mcopy will complain. Sectors are 512 bytes, and we
        # generate images with 32 sectors per track. This calculation is
        # done in blocks, thus the mod by 16 instead of 32.
        blocks += (16 - (blocks % 16))

        # dosfs image, created by mkdosfs
        bootimg = "%s/boot.img" % cr_workdir

        dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % bootimg
        exec_cmd(chmod_cmd)

        du_cmd = "du -Lbks %s" % bootimg
        out = exec_cmd(du_cmd)
        bootimg_size = out.split()[0]

        part.set_size(bootimg_size)
        part.set_source_file(bootimg)
    def do_prepare_partition(cls, part, source_params, cr, cr_workdir,
                             oe_builddir, bootimg_dir, kernel_dir, rootfs_dir,
                             native_sysroot):
        """
        Called to do the actual content population for a partition i.e. it
        'prepares' the partition to be incorporated into the image.
        In this case, prepare content for a bootable ISO image.
        """

        isodir = "%s/ISO" % cr_workdir

        if part.rootfs is None:
            if not 'ROOTFS_DIR' in rootfs_dir:
                msger.error("Couldn't find --rootfs-dir, exiting.\n")
            rootfs_dir = rootfs_dir['ROOTFS_DIR']
        else:
            if part.rootfs in rootfs_dir:
                rootfs_dir = rootfs_dir[part.rootfs]
            elif part.rootfs:
                rootfs_dir = part.rootfs
            else:
                msg = "Couldn't find --rootfs-dir=%s connection "
                msg += "or it is not a valid path, exiting.\n"
                msger.error(msg % part.rootfs)

        if not os.path.isdir(rootfs_dir):
            rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
        if not os.path.isdir(rootfs_dir):
            msger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")

        part.set_rootfs(rootfs_dir)

        # Prepare rootfs.img
        hdd_dir = get_bitbake_var("HDDDIR")
        img_iso_dir = get_bitbake_var("ISODIR")

        rootfs_img = "%s/rootfs.img" % hdd_dir
        if not os.path.isfile(rootfs_img):
            rootfs_img = "%s/rootfs.img" % img_iso_dir
        if not os.path.isfile(rootfs_img):
            # check if rootfs.img is in deploydir
            deploy_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
            image_name = get_bitbake_var("IMAGE_LINK_NAME")
            rootfs_img = "%s/%s.%s" \
                % (deploy_dir, image_name, part.fstype)

        if not os.path.isfile(rootfs_img):
            # create image file with type specified by --fstype
            # which contains rootfs
            du_cmd = "du -bks %s" % rootfs_dir
            out = exec_cmd(du_cmd)
            part.set_size(int(out.split()[0]))
            part.extra_space = 0
            part.overhead_factor = 1.2
            part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, \
                                native_sysroot)
            rootfs_img = part.source_file

        install_cmd = "install -m 0644 %s %s/rootfs.img" \
            % (rootfs_img, isodir)
        exec_cmd(install_cmd)

        # Remove the temporary file created by part.prepare_rootfs()
        if os.path.isfile(part.source_file):
            os.remove(part.source_file)

        # Prepare initial ramdisk
        initrd = "%s/initrd" % hdd_dir
        if not os.path.isfile(initrd):
            initrd = "%s/initrd" % img_iso_dir
        if not os.path.isfile(initrd):
            initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir)

        install_cmd = "install -m 0644 %s %s/initrd" \
            % (initrd, isodir)
        exec_cmd(install_cmd)

        # Remove the temporary file created by _build_initramfs_path function
        if os.path.isfile("%s/initrd.cpio.gz" % cr_workdir):
            os.remove("%s/initrd.cpio.gz" % cr_workdir)

        # Install bzImage
        install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
            (kernel_dir, isodir)
        exec_cmd(install_cmd)

        #Create bootloader for efi boot
        try:
            if source_params['loader'] == 'grub-efi':
                # Builds grub.cfg if ISODIR didn't exist or
                # didn't contains grub.cfg
                bootimg_dir = img_iso_dir
                if not os.path.exists("%s/EFI/BOOT" % bootimg_dir):
                    bootimg_dir = "%s/bootimg" % cr_workdir
                    if os.path.exists(bootimg_dir):
                        shutil.rmtree(bootimg_dir)
                    install_cmd = "install -d %s/EFI/BOOT" % bootimg_dir
                    exec_cmd(install_cmd)

                if not os.path.isfile("%s/EFI/BOOT/boot.cfg" % bootimg_dir):
                    cls.do_configure_grubefi(part, cr, bootimg_dir)

                # Builds bootx64.efi/bootia32.efi if ISODIR didn't exist or
                # didn't contains it
                target_arch = get_bitbake_var("TARGET_SYS")
                if not target_arch:
                    msger.error("Coludn't find target architecture\n")

                if re.match("x86_64", target_arch):
                    grub_target = 'x86_64-efi'
                    grub_image = "bootx64.efi"
                elif re.match('i.86', target_arch):
                    grub_target = 'i386-efi'
                    grub_image = "bootia32.efi"
                else:
                    msger.error("grub-efi is incompatible with target %s\n" \
                                % target_arch)

                if not os.path.isfile("%s/EFI/BOOT/%s" \
                                % (bootimg_dir, grub_image)):
                    grub_path = get_bitbake_var("STAGING_LIBDIR")
                    if not grub_path:
                        msger.error("Couldn't find STAGING_LIBDIR, exiting.\n")

                    grub_core = "%s/grub/%s" % (grub_path, grub_target)
                    if not os.path.exists(grub_core):
                        msger.info("Building grub-efi...\n")
                        exec_cmd("bitbake grub-efi")
                    if not os.path.exists(grub_core):
                        msger.error("Please build grub-efi first\n")

                    grub_cmd = "grub-mkimage -p '/EFI/BOOT' "
                    grub_cmd += "-d %s " % grub_core
                    grub_cmd += "-O %s -o %s/EFI/BOOT/%s " \
                                % (grub_target, bootimg_dir, grub_image)
                    grub_cmd += "part_gpt part_msdos ntfs ntfscomp fat ext2 "
                    grub_cmd += "normal chain boot configfile linux multiboot "
                    grub_cmd += "search efi_gop efi_uga font gfxterm gfxmenu "
                    grub_cmd += "terminal minicmd test iorw loadenv echo help "
                    grub_cmd += "reboot serial terminfo iso9660 loopback tar "
                    grub_cmd += "memdisk ls search_fs_uuid udf btrfs xfs lvm "
                    grub_cmd += "reiserfs ata "
                    exec_native_cmd(grub_cmd, native_sysroot)

            else:
                # TODO: insert gummiboot stuff
                msger.error("unrecognized bootimg-efi loader: %s" \
                            % source_params['loader'])
        except KeyError:
            msger.error("bootimg-efi requires a loader, none specified")

        if os.path.exists("%s/EFI/BOOT" % isodir):
            shutil.rmtree("%s/EFI/BOOT" % isodir)

        shutil.copytree(bootimg_dir + "/EFI/BOOT", isodir + "/EFI/BOOT")

        # If exists, remove cr_workdir/bootimg temporary folder
        if os.path.exists("%s/bootimg" % cr_workdir):
            shutil.rmtree("%s/bootimg" % cr_workdir)

        # Create efi.img that contains bootloader files for EFI booting
        # if ISODIR didn't exist or didn't contains it
        if os.path.isfile("%s/efi.img" % img_iso_dir):
            install_cmd = "install -m 0644 %s/efi.img %s/efi.img" % \
                (img_iso_dir, isodir)
            exec_cmd(install_cmd)
        else:
            du_cmd = "du -bks %s/EFI" % isodir
            out = exec_cmd(du_cmd)
            blocks = int(out.split()[0])
            # Add some extra space for file system overhead
            blocks += 100
            msg = "Added 100 extra blocks to %s to get to %d total blocks" \
                    % (part.mountpoint, blocks)
            msger.debug(msg)

            # Ensure total sectors is an integral number of sectors per
            # track or mcopy will complain. Sectors are 512 bytes, and we
            # generate images with 32 sectors per track. This calculation is
            # done in blocks, thus the mod by 16 instead of 32.
            blocks += (16 - (blocks % 16))

            # dosfs image for EFI boot
            bootimg = "%s/efi.img" % isodir

            dosfs_cmd = 'mkfs.vfat -n "EFIimg" -S 512 -C %s %d' \
                        % (bootimg, blocks)
            exec_native_cmd(dosfs_cmd, native_sysroot)

            mmd_cmd = "mmd -i %s ::/EFI" % bootimg
            exec_native_cmd(mmd_cmd, native_sysroot)

            mcopy_cmd = "mcopy -i %s -s %s/EFI/* ::/EFI/" \
                        % (bootimg, isodir)
            exec_native_cmd(mcopy_cmd, native_sysroot)

            chmod_cmd = "chmod 644 %s" % bootimg
            exec_cmd(chmod_cmd)

        # Prepare files for legacy boot
        syslinux_dir = get_bitbake_var("STAGING_DATADIR")
        if not syslinux_dir:
            msger.error("Couldn't find STAGING_DATADIR, exiting.\n")

        if os.path.exists("%s/isolinux" % isodir):
            shutil.rmtree("%s/isolinux" % isodir)

        install_cmd = "install -d %s/isolinux" % isodir
        exec_cmd(install_cmd)

        cls.do_configure_syslinux(cr, cr_workdir)

        install_cmd = "install -m 444 %s/syslinux/ldlinux.sys " % syslinux_dir
        install_cmd += "%s/isolinux/ldlinux.sys" % isodir
        exec_cmd(install_cmd)

        install_cmd = "install -m 444 %s/syslinux/isohdpfx.bin " % syslinux_dir
        install_cmd += "%s/isolinux/isohdpfx.bin" % isodir
        exec_cmd(install_cmd)

        install_cmd = "install -m 644 %s/syslinux/isolinux.bin " % syslinux_dir
        install_cmd += "%s/isolinux/isolinux.bin" % isodir
        exec_cmd(install_cmd)

        install_cmd = "install -m 644 %s/syslinux/ldlinux.c32 " % syslinux_dir
        install_cmd += "%s/isolinux/ldlinux.c32" % isodir
        exec_cmd(install_cmd)

        #create ISO image
        iso_img = "%s/tempiso_img.iso" % cr_workdir
        iso_bootimg = "isolinux/isolinux.bin"
        iso_bootcat = "isolinux/boot.cat"
        efi_img = "efi.img"

        mkisofs_cmd = "mkisofs -V %s " % part.label
        mkisofs_cmd += "-o %s -U " % iso_img
        mkisofs_cmd += "-J -joliet-long -r -iso-level 2 -b %s " % iso_bootimg
        mkisofs_cmd += "-c %s -no-emul-boot -boot-load-size 4 " % iso_bootcat
        mkisofs_cmd += "-boot-info-table -eltorito-alt-boot "
        mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img
        mkisofs_cmd += "-no-emul-boot %s " % isodir

        msger.debug("running command: %s" % mkisofs_cmd)
        exec_native_cmd(mkisofs_cmd, native_sysroot)

        shutil.rmtree(isodir)

        du_cmd = "du -Lbks %s" % iso_img
        out = exec_cmd(du_cmd)
        isoimg_size = int(out.split()[0])

        part.set_size(isoimg_size)
        part.set_source_file(iso_img)
Esempio n. 53
0
    def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
                             oe_builddir, bootimg_dir, kernel_dir,
                             rootfs_dir, native_sysroot):
        """
        Called to do the actual content population for a partition i.e. it
        'prepares' the partition to be incorporated into the image.
        In this case, prepare content for an EFI (grub) boot partition.
        """
        if not bootimg_dir:
            bootimg_dir = get_bitbake_var("HDDDIR")
            if not bootimg_dir:
                msger.error("Couldn't find HDDDIR, exiting\n")
            # just so the result notes display it
            creator.set_bootimg_dir(bootimg_dir)

        staging_kernel_dir = kernel_dir

        hdddir = "%s/hdd/boot" % cr_workdir

        install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
            (staging_kernel_dir, hdddir)
        exec_cmd(install_cmd)

        try:
            if source_params['loader'] == 'grub-efi':
                shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir,
                                "%s/grub.cfg" % cr_workdir)
                cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir)
                exec_cmd(cp_cmd, True)
                shutil.move("%s/grub.cfg" % cr_workdir,
                            "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir)
            elif source_params['loader'] == 'systemd-boot':
                cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir)
                exec_cmd(cp_cmd, True)
            else:
                msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader'])
        except KeyError:
            msger.error("bootimg-efi requires a loader, none specified")

        startup = os.path.join(bootimg_dir, "startup.nsh")
        if os.path.exists(startup):
            cp_cmd = "cp %s %s/" % (startup, hdddir)
            exec_cmd(cp_cmd, True)

        du_cmd = "du -bks %s" % hdddir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = part.get_extra_block_count(blocks)

        if extra_blocks < BOOTDD_EXTRA_SPACE:
            extra_blocks = BOOTDD_EXTRA_SPACE

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, part.mountpoint, blocks))

        # dosfs image, created by mkdosfs
        bootimg = "%s/boot.img" % cr_workdir

        dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % bootimg
        exec_cmd(chmod_cmd)

        du_cmd = "du -Lbks %s" % bootimg
        out = exec_cmd(du_cmd)
        bootimg_size = out.split()[0]

        part.size = int(bootimg_size)
        part.source_file = bootimg
Esempio n. 54
0
    def do_prepare_partition(self, part, source_params, cr, cr_workdir,
                             oe_builddir, bootimg_dir, kernel_dir,
                             rootfs_dir, native_sysroot):
        """
        Called to do the actual content population for a partition i.e. it
        'prepares' the partition to be incorporated into the image.
        In this case, prepare content for an EFI (grub) boot partition.
        """
        if not bootimg_dir:
            bootimg_dir = get_bitbake_var("HDDDIR")
            if not bootimg_dir:
                msger.error("Couldn't find HDDDIR, exiting\n")
            # just so the result notes display it
            cr.set_bootimg_dir(bootimg_dir)

        staging_kernel_dir = kernel_dir

        hdddir = "%s/hdd/boot" % cr_workdir

        install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
            (staging_kernel_dir, hdddir)
        exec_cmd(install_cmd)

        try:
            if source_params['loader'] == 'grub-efi':
                shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir,
                                "%s/grub.cfg" % cr_workdir)
                cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir)
                exec_cmd(cp_cmd, True)
                shutil.move("%s/grub.cfg" % cr_workdir,
                            "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir)
            elif source_params['loader'] == 'gummiboot':
                cp_cmd = "cp %s/EFI/BOOT/* %s/EFI/BOOT" % (bootimg_dir, hdddir)
                exec_cmd(cp_cmd, True)
            else:
                msger.error("unrecognized bootimg-efi loader: %s" % source_params['loader'])
        except KeyError:
            msger.error("bootimg-efi requires a loader, none specified")

        du_cmd = "du -bks %s" % hdddir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = part.get_extra_block_count(blocks)

        if extra_blocks < BOOTDD_EXTRA_SPACE:
            extra_blocks = BOOTDD_EXTRA_SPACE

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, part.mountpoint, blocks))

        # Ensure total sectors is an integral number of sectors per
        # track or mcopy will complain. Sectors are 512 bytes, and we
        # generate images with 32 sectors per track. This calculation is
        # done in blocks, thus the mod by 16 instead of 32.
        blocks += (16 - (blocks % 16))

        # dosfs image, created by mkdosfs
        bootimg = "%s/boot.img" % cr_workdir

        dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % bootimg
        exec_cmd(chmod_cmd)

        du_cmd = "du -Lbks %s" % bootimg
        out = exec_cmd(du_cmd)
        bootimg_size = out.split()[0]

        part.set_size(bootimg_size)
        part.set_source_file(bootimg)
Esempio n. 55
0
    def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
                             oe_builddir, bootimg_dir, kernel_dir,
                             rootfs_dir, native_sysroot):
        """
        Called to do the actual content population for a partition i.e. it
        'prepares' the partition to be incorporated into the image.
        In this case, prepare content for a bootable ISO image.
        """

        isodir = "%s/ISO" % cr_workdir

        if part.rootfs_dir is None:
            if not 'ROOTFS_DIR' in rootfs_dir:
                msger.error("Couldn't find --rootfs-dir, exiting.\n")
            rootfs_dir = rootfs_dir['ROOTFS_DIR']
        else:
            if part.rootfs_dir in rootfs_dir:
                rootfs_dir = rootfs_dir[part.rootfs_dir]
            elif part.rootfs_dir:
                rootfs_dir = part.rootfs_dir
            else:
                msg = "Couldn't find --rootfs-dir=%s connection "
                msg += "or it is not a valid path, exiting.\n"
                msger.error(msg % part.rootfs_dir)

        if not os.path.isdir(rootfs_dir):
            rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
        if not os.path.isdir(rootfs_dir):
            msger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")

        part.rootfs_dir = rootfs_dir

        # Prepare rootfs.img
        hdd_dir = get_bitbake_var("HDDDIR")
        img_iso_dir = get_bitbake_var("ISODIR")

        rootfs_img = "%s/rootfs.img" % hdd_dir
        if not os.path.isfile(rootfs_img):
            rootfs_img = "%s/rootfs.img" % img_iso_dir
        if not os.path.isfile(rootfs_img):
            # check if rootfs.img is in deploydir
            deploy_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
            image_name = get_bitbake_var("IMAGE_LINK_NAME")
            rootfs_img = "%s/%s.%s" \
                % (deploy_dir, image_name, part.fstype)

        if not os.path.isfile(rootfs_img):
            # create image file with type specified by --fstype
            # which contains rootfs
            du_cmd = "du -bks %s" % rootfs_dir
            out = exec_cmd(du_cmd)
            part.size = int(out.split()[0])
            part.extra_space = 0
            part.overhead_factor = 1.2
            part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, \
                                native_sysroot)
            rootfs_img = part.source_file

        install_cmd = "install -m 0644 %s %s/rootfs.img" \
            % (rootfs_img, isodir)
        exec_cmd(install_cmd)

        # Remove the temporary file created by part.prepare_rootfs()
        if os.path.isfile(part.source_file):
            os.remove(part.source_file)

        # Prepare initial ramdisk
        initrd = "%s/initrd" % hdd_dir
        if not os.path.isfile(initrd):
            initrd = "%s/initrd" % img_iso_dir
        if not os.path.isfile(initrd):
            initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir)

        install_cmd = "install -m 0644 %s %s/initrd" \
            % (initrd, isodir)
        exec_cmd(install_cmd)

        # Remove the temporary file created by _build_initramfs_path function
        if os.path.isfile("%s/initrd.cpio.gz" % cr_workdir):
            os.remove("%s/initrd.cpio.gz" % cr_workdir)

        # Install bzImage
        install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
            (kernel_dir, isodir)
        exec_cmd(install_cmd)

        #Create bootloader for efi boot
        try:
            if source_params['loader'] == 'grub-efi':
                # Builds grub.cfg if ISODIR didn't exist or
                # didn't contains grub.cfg
                bootimg_dir = img_iso_dir
                if not os.path.exists("%s/EFI/BOOT" % bootimg_dir):
                    bootimg_dir = "%s/bootimg" % cr_workdir
                    if os.path.exists(bootimg_dir):
                        shutil.rmtree(bootimg_dir)
                    install_cmd = "install -d %s/EFI/BOOT" % bootimg_dir
                    exec_cmd(install_cmd)

                if not os.path.isfile("%s/EFI/BOOT/boot.cfg" % bootimg_dir):
                    cls.do_configure_grubefi(part, creator, bootimg_dir)

                # Builds bootx64.efi/bootia32.efi if ISODIR didn't exist or
                # didn't contains it
                target_arch = get_bitbake_var("TARGET_SYS")
                if not target_arch:
                    msger.error("Coludn't find target architecture\n")

                if re.match("x86_64", target_arch):
                    grub_target = 'x86_64-efi'
                    grub_image = "bootx64.efi"
                elif re.match('i.86', target_arch):
                    grub_target = 'i386-efi'
                    grub_image = "bootia32.efi"
                else:
                    msger.error("grub-efi is incompatible with target %s\n" \
                                % target_arch)

                if not os.path.isfile("%s/EFI/BOOT/%s" \
                                % (bootimg_dir, grub_image)):
                    grub_path = get_bitbake_var("STAGING_LIBDIR")
                    if not grub_path:
                        msger.error("Couldn't find STAGING_LIBDIR, exiting.\n")

                    grub_core = "%s/grub/%s" % (grub_path, grub_target)
                    if not os.path.exists(grub_core):
                        msger.info("Building grub-efi...\n")
                        exec_cmd("bitbake grub-efi")
                    if not os.path.exists(grub_core):
                        msger.error("Please build grub-efi first\n")

                    grub_cmd = "grub-mkimage -p '/EFI/BOOT' "
                    grub_cmd += "-d %s "  % grub_core
                    grub_cmd += "-O %s -o %s/EFI/BOOT/%s " \
                                % (grub_target, bootimg_dir, grub_image)
                    grub_cmd += "part_gpt part_msdos ntfs ntfscomp fat ext2 "
                    grub_cmd += "normal chain boot configfile linux multiboot "
                    grub_cmd += "search efi_gop efi_uga font gfxterm gfxmenu "
                    grub_cmd += "terminal minicmd test iorw loadenv echo help "
                    grub_cmd += "reboot serial terminfo iso9660 loopback tar "
                    grub_cmd += "memdisk ls search_fs_uuid udf btrfs xfs lvm "
                    grub_cmd += "reiserfs ata "
                    exec_native_cmd(grub_cmd, native_sysroot)

            else:
                # TODO: insert gummiboot stuff
                msger.error("unrecognized bootimg-efi loader: %s" \
                            % source_params['loader'])
        except KeyError:
            msger.error("bootimg-efi requires a loader, none specified")

        if os.path.exists("%s/EFI/BOOT" % isodir):
            shutil.rmtree("%s/EFI/BOOT" % isodir)

        shutil.copytree(bootimg_dir+"/EFI/BOOT", isodir+"/EFI/BOOT")

        # If exists, remove cr_workdir/bootimg temporary folder
        if os.path.exists("%s/bootimg" % cr_workdir):
            shutil.rmtree("%s/bootimg" % cr_workdir)

        # Create efi.img that contains bootloader files for EFI booting
        # if ISODIR didn't exist or didn't contains it
        if os.path.isfile("%s/efi.img" % img_iso_dir):
            install_cmd = "install -m 0644 %s/efi.img %s/efi.img" % \
                (img_iso_dir, isodir)
            exec_cmd(install_cmd)
        else:
            du_cmd = "du -bks %s/EFI" % isodir
            out = exec_cmd(du_cmd)
            blocks = int(out.split()[0])
            # Add some extra space for file system overhead
            blocks += 100
            msg = "Added 100 extra blocks to %s to get to %d total blocks" \
                    % (part.mountpoint, blocks)
            msger.debug(msg)

            # Ensure total sectors is an integral number of sectors per
            # track or mcopy will complain. Sectors are 512 bytes, and we
            # generate images with 32 sectors per track. This calculation is
            # done in blocks, thus the mod by 16 instead of 32.
            blocks += (16 - (blocks % 16))

            # dosfs image for EFI boot
            bootimg = "%s/efi.img" % isodir

            dosfs_cmd = 'mkfs.vfat -n "EFIimg" -S 512 -C %s %d' \
                        % (bootimg, blocks)
            exec_native_cmd(dosfs_cmd, native_sysroot)

            mmd_cmd = "mmd -i %s ::/EFI" % bootimg
            exec_native_cmd(mmd_cmd, native_sysroot)

            mcopy_cmd = "mcopy -i %s -s %s/EFI/* ::/EFI/" \
                        % (bootimg, isodir)
            exec_native_cmd(mcopy_cmd, native_sysroot)

            chmod_cmd = "chmod 644 %s" % bootimg
            exec_cmd(chmod_cmd)

        # Prepare files for legacy boot
        syslinux_dir = get_bitbake_var("STAGING_DATADIR")
        if not syslinux_dir:
            msger.error("Couldn't find STAGING_DATADIR, exiting.\n")

        if os.path.exists("%s/isolinux" % isodir):
            shutil.rmtree("%s/isolinux" % isodir)

        install_cmd = "install -d %s/isolinux" % isodir
        exec_cmd(install_cmd)

        cls.do_configure_syslinux(creator, cr_workdir)

        install_cmd = "install -m 444 %s/syslinux/ldlinux.sys " % syslinux_dir
        install_cmd += "%s/isolinux/ldlinux.sys" % isodir
        exec_cmd(install_cmd)

        install_cmd = "install -m 444 %s/syslinux/isohdpfx.bin " % syslinux_dir
        install_cmd += "%s/isolinux/isohdpfx.bin" % isodir
        exec_cmd(install_cmd)

        install_cmd = "install -m 644 %s/syslinux/isolinux.bin " % syslinux_dir
        install_cmd += "%s/isolinux/isolinux.bin" % isodir
        exec_cmd(install_cmd)

        install_cmd = "install -m 644 %s/syslinux/ldlinux.c32 " % syslinux_dir
        install_cmd += "%s/isolinux/ldlinux.c32" % isodir
        exec_cmd(install_cmd)

        #create ISO image
        iso_img = "%s/tempiso_img.iso" % cr_workdir
        iso_bootimg = "isolinux/isolinux.bin"
        iso_bootcat = "isolinux/boot.cat"
        efi_img = "efi.img"

        mkisofs_cmd = "mkisofs -V %s " % part.label
        mkisofs_cmd += "-o %s -U " % iso_img
        mkisofs_cmd += "-J -joliet-long -r -iso-level 2 -b %s " % iso_bootimg
        mkisofs_cmd += "-c %s -no-emul-boot -boot-load-size 4 " % iso_bootcat
        mkisofs_cmd += "-boot-info-table -eltorito-alt-boot "
        mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img
        mkisofs_cmd += "-no-emul-boot %s " % isodir

        msger.debug("running command: %s" % mkisofs_cmd)
        exec_native_cmd(mkisofs_cmd, native_sysroot)

        shutil.rmtree(isodir)

        du_cmd = "du -Lbks %s" % iso_img
        out = exec_cmd(du_cmd)
        isoimg_size = int(out.split()[0])

        part.size = isoimg_size
        part.source_file = iso_img
    def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
                             oe_builddir, bootimg_dir, kernel_dir,
                             rootfs_dir, native_sysroot):
        """
        Called to do the actual content population for a partition i.e. it
        'prepares' the partition to be incorporated into the image.
        In this case, prepare content for legacy bios boot partition.
        """
        def _has_syslinux(dirname):
            if dirname:
                syslinux = "%s/syslinux" % dirname
                if os.path.exists(syslinux):
                    return True
            return False

        if not _has_syslinux(bootimg_dir):
            bootimg_dir = get_bitbake_var("STAGING_DATADIR")
            if not bootimg_dir:
                msger.error("Couldn't find STAGING_DATADIR, exiting\n")
            if not _has_syslinux(bootimg_dir):
                msger.error("Please build syslinux first\n")
            # just so the result notes display it
            creator.set_bootimg_dir(bootimg_dir)

        staging_kernel_dir = kernel_dir

        hdddir = "%s/hdd/boot" % cr_workdir

        install_cmd = "install -m 0644 %s/bzImage-initramfs-genericx86-64.bin %s/vmlinuz" \
            % (staging_kernel_dir, hdddir)
        exec_cmd(install_cmd)

        install_cmd = "install -m 444 %s/syslinux/ldlinux.sys %s/ldlinux.sys" \
            % (bootimg_dir, hdddir)
        exec_cmd(install_cmd)

        du_cmd = "du -bks %s" % hdddir
        out = exec_cmd(du_cmd)
        blocks = int(out.split()[0])

        extra_blocks = part.get_extra_block_count(blocks)

        if extra_blocks < BOOTDD_EXTRA_SPACE:
            extra_blocks = BOOTDD_EXTRA_SPACE

        blocks += extra_blocks

        msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \
                    (extra_blocks, part.mountpoint, blocks))

        # Ensure total sectors is an integral number of sectors per
        # track or mcopy will complain. Sectors are 512 bytes, and we
        # generate images with 32 sectors per track. This calculation is
        # done in blocks, thus the mod by 16 instead of 32.
        blocks += (16 - (blocks % 16))

        # dosfs image, created by mkdosfs
        bootimg = "%s/boot.img" % cr_workdir

        dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (bootimg, blocks)
        exec_native_cmd(dosfs_cmd, native_sysroot)

        mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir)
        exec_native_cmd(mcopy_cmd, native_sysroot)

        syslinux_cmd = "syslinux %s" % bootimg
        exec_native_cmd(syslinux_cmd, native_sysroot)

        chmod_cmd = "chmod 644 %s" % bootimg
        exec_cmd(chmod_cmd)

        du_cmd = "du -Lbks %s" % bootimg
        out = exec_cmd(du_cmd)
        bootimg_size = out.split()[0]

        part.set_size(bootimg_size)
        part.set_source_file(bootimg)