diff options
Diffstat (limited to 'classes')
-rw-r--r-- | classes/image_types_ota.bbclass | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/classes/image_types_ota.bbclass b/classes/image_types_ota.bbclass new file mode 100644 index 0000000..a67cc80 --- /dev/null +++ b/classes/image_types_ota.bbclass | |||
@@ -0,0 +1,73 @@ | |||
1 | # Image to use with u-boot as BIOS and OSTree deployment system | ||
2 | |||
3 | inherit image_types | ||
4 | |||
5 | # Boot filesystem size in MiB | ||
6 | # OSTree updates may require some space on boot file system for | ||
7 | # boot scripts, kernel and initramfs images | ||
8 | # | ||
9 | BOOTFS_EXTRA_SIZE ?= "512" | ||
10 | export BOOTFS_EXTRA_SIZE | ||
11 | |||
12 | IMAGE_TYPES += " otaimg" | ||
13 | IMAGE_DEPENDS_ota = "e2fsprogs-native \ | ||
14 | virtual/bootloader \ | ||
15 | virtual/kernel \ | ||
16 | parted-native \ | ||
17 | ${INITRD_IMAGE}" | ||
18 | |||
19 | build_bootfs () { | ||
20 | KERNEL_FILE=${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} | ||
21 | KERNEL_SIZE=`du -Lbs ${KERNEL_FILE} | cut -f 1` | ||
22 | |||
23 | RAMDISK_FILE=${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE}-${MACHINE}.cpio.gz | ||
24 | RAMDISK_SIZE=`du -Lbs ${RAMDISK_FILE} | cut -f 1` | ||
25 | |||
26 | EXTRA_BYTES=$(expr $BOOTFS_EXTRA_SIZE \* 1024 \* 1024) | ||
27 | |||
28 | TOTAL_SIZE=$(expr ${KERNEL_SIZE} \+ ${RAMDISK_SIZE} \+ ${EXTRA_BYTES}) | ||
29 | TOTAL_BLOCKS=$(expr 1 \+ $TOTAL_SIZE / 1024) | ||
30 | |||
31 | dd if=/dev/zero of=$1 bs=1024 count=${TOTAL_BLOCKS} | ||
32 | BOOTTMP=$(mktemp -d mkotaboot-XXX) | ||
33 | cp ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} ${BOOTTMP} | ||
34 | cp ${DEPLOY_DIR_IMAGE}/${INITRD_IMAGE}-${MACHINE}.cpio.gz ${BOOTTMP} | ||
35 | mkfs.ext4 $1 -d ${BOOTTMP} | ||
36 | rm -rf $BOOTTMP | ||
37 | } | ||
38 | |||
39 | IMAGE_CMD_otaimg () { | ||
40 | BOOTIMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaboot.ext4 | ||
41 | rm -f $BOOTIMG | ||
42 | build_bootfs $BOOTIMG | ||
43 | |||
44 | # ext4 image should be already here because of IMAGE_TYPEDEP_otaimg | ||
45 | ROOTIMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext4 | ||
46 | |||
47 | BOOTFSBLOCKS=`du -bks ${BOOTIMG} | cut -f 1` | ||
48 | |||
49 | ROOTFSBLOCKS=`du -bks ${ROOTIMG} | cut -f 1` | ||
50 | TOTALSIZE=`expr $BOOTFSBLOCKS \+ $ROOTFSBLOCKS` | ||
51 | END1=`expr $BOOTFSBLOCKS \* 1024` | ||
52 | END2=`expr $END1 + 512` | ||
53 | END3=`expr \( $ROOTFSBLOCKS \* 1024 \) + $END1` | ||
54 | |||
55 | FULLIMG=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.otaimg | ||
56 | rm -rf ${FULLIMG} | ||
57 | |||
58 | dd if=/dev/zero of=${FULLIMG} bs=1024 seek=${TOTALSIZE} count=1 | ||
59 | parted ${FULLIMG} mklabel msdos | ||
60 | parted ${FULLIMG} mkpart primary ext4 0 ${END1}B | ||
61 | parted ${FULLIMG} unit B mkpart primary ext4 ${END2}B ${END3}B | ||
62 | |||
63 | OFFSET=`expr $END2 / 512` | ||
64 | |||
65 | dd if=${BOOTIMG} of=${FULLIMG} conv=notrunc seek=1 bs=512 | ||
66 | dd if=${ROOTIMG} of=${FULLIMG} conv=notrunc seek=$OFFSET bs=512 | ||
67 | |||
68 | cd ${DEPLOY_DIR_IMAGE} | ||
69 | rm -f ${IMAGE_LINK_NAME}.otaimg | ||
70 | ln -s ${IMAGE_NAME}.otaimg ${IMAGE_LINK_NAME}.otaimg | ||
71 | } | ||
72 | |||
73 | IMAGE_TYPEDEP_otaimg = "ext4" | ||