diff options
Diffstat (limited to 'meta-boot2qt/classes/image_dd.bbclass')
-rw-r--r-- | meta-boot2qt/classes/image_dd.bbclass | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/meta-boot2qt/classes/image_dd.bbclass b/meta-boot2qt/classes/image_dd.bbclass new file mode 100644 index 0000000..e05536b --- /dev/null +++ b/meta-boot2qt/classes/image_dd.bbclass | |||
@@ -0,0 +1,87 @@ | |||
1 | ############################################################################ | ||
2 | ## | ||
3 | ## Copyright (C) 2016 The Qt Company Ltd. | ||
4 | ## Contact: https://www.qt.io/licensing/ | ||
5 | ## | ||
6 | ## This file is part of the Boot to Qt meta layer. | ||
7 | ## | ||
8 | ## $QT_BEGIN_LICENSE:GPL$ | ||
9 | ## Commercial License Usage | ||
10 | ## Licensees holding valid commercial Qt licenses may use this file in | ||
11 | ## accordance with the commercial license agreement provided with the | ||
12 | ## Software or, alternatively, in accordance with the terms contained in | ||
13 | ## a written agreement between you and The Qt Company. For licensing terms | ||
14 | ## and conditions see https://www.qt.io/terms-conditions. For further | ||
15 | ## information use the contact form at https://www.qt.io/contact-us. | ||
16 | ## | ||
17 | ## GNU General Public License Usage | ||
18 | ## Alternatively, this file may be used under the terms of the GNU | ||
19 | ## General Public License version 3 or (at your option) any later version | ||
20 | ## approved by the KDE Free Qt Foundation. The licenses are as published by | ||
21 | ## the Free Software Foundation and appearing in the file LICENSE.GPL3 | ||
22 | ## included in the packaging of this file. Please review the following | ||
23 | ## information to ensure the GNU General Public License requirements will | ||
24 | ## be met: https://www.gnu.org/licenses/gpl-3.0.html. | ||
25 | ## | ||
26 | ## $QT_END_LICENSE$ | ||
27 | ## | ||
28 | ############################################################################ | ||
29 | |||
30 | # This class is based on meta-freescale/classes/image_types_fsl.bbclass::generate_imx_sdcard() | ||
31 | DESCRIPTION = "The base class for building images that can be deployed with GNU coreutils dd tool." | ||
32 | inherit image_types | ||
33 | |||
34 | IMAGE="${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.img" | ||
35 | |||
36 | # Boot partition size [in KiB] | ||
37 | BOOT_SPACE ?= "8192" | ||
38 | |||
39 | # Set alignment to 4MB [in KiB] | ||
40 | IMAGE_ROOTFS_ALIGNMENT = "4096" | ||
41 | |||
42 | # Boot partition volume id | ||
43 | BOOTDD_VOLUME_ID = "boot" | ||
44 | |||
45 | IMAGE_TYPEDEP_dd = "ext3" | ||
46 | IMAGE_DEPENDS_dd = "parted-native:do_populate_sysroot \ | ||
47 | dosfstools-native:do_populate_sysroot \ | ||
48 | mtools-native:do_populate_sysroot" | ||
49 | |||
50 | image_dd_do_populate_boot() { | ||
51 | } | ||
52 | EXPORT_FUNCTIONS do_populate_boot | ||
53 | |||
54 | IMAGE_CMD_dd() { | ||
55 | |||
56 | ROOTFS="${IMGDEPLOYDIR}/${IMAGE_NAME}.rootfs.ext3" | ||
57 | |||
58 | # Align boot partition and calculate total binary image size | ||
59 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1) | ||
60 | BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT}) | ||
61 | IMAGE_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT}) | ||
62 | |||
63 | # Initialize a sparse file | ||
64 | dd if=/dev/zero of=${IMAGE} bs=1 count=0 seek=$(expr 1024 \* ${IMAGE_SIZE}) | ||
65 | |||
66 | # Create partition table | ||
67 | parted -s ${IMAGE} mklabel msdos | ||
68 | parted -s ${IMAGE} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) | ||
69 | parted -s ${IMAGE} unit KiB mkpart primary $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED}) $(expr ${IMAGE_ROOTFS_ALIGNMENT} \+ ${BOOT_SPACE_ALIGNED} \+ $ROOTFS_SIZE) | ||
70 | parted -s ${IMAGE} set 1 boot on | ||
71 | parted ${IMAGE} print | ||
72 | |||
73 | # Create boot partition image | ||
74 | BOOT_BLOCKS=$(LC_ALL=C parted -s ${IMAGE} unit b print \ | ||
75 | | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 1024 }') | ||
76 | rm -f ${WORKDIR}/boot.img | ||
77 | mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS | ||
78 | do_populate_boot | ||
79 | |||
80 | # Burn Partitions | ||
81 | dd if=${WORKDIR}/boot.img of=${IMAGE} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
82 | dd if=${ROOTFS} of=${IMAGE} conv=notrunc seek=1 bs=$(expr ${BOOT_SPACE_ALIGNED} \* 1024 + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync | ||
83 | |||
84 | rm -f ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.img | ||
85 | ln -s ${IMAGE_NAME}.rootfs.img ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.img | ||
86 | } | ||
87 | |||