/
image-partitions.bbclass
96 lines (89 loc) · 4.02 KB
/
image-partitions.bbclass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
python () {
deps = bb.data.getVarFlag('do_rootfs', 'depends', d) or ""
for partition in d.getVar("PARTITIONS", True).split():
filesystems = d.getVar("PARTITION_%s_FS" % partition, True) or ""
for fs in filesystems.split():
for dep in (d.getVar("IMAGE_DEPENDS_%s" % fs, True) or "").split():
deps += " %s:do_populate_sysroot" % dep
for dep in (bb.data.getVar('EXTRA_IMAGEDEPENDS', d, True) or "").split():
deps += " %s:do_populate_sysroot" % dep
bb.data.setVarFlag('do_rootfs', 'depends', deps, d)
}
PARTITIONS ?= "base"
PARTITION_base_PATH = "/"
PARTITION_base_FS ?= "${IMAGE_FSTYPES}"
def get_splitcmds(d):
cmds = []
partitions = d.getVar("PARTITIONS", True) or ""
for partition in partitions.split():
if partition == "base":
continue
cmds.append("rm -rf ${IMAGE_ROOTFS}-%s;" % partition)
cmds.append("mv ${IMAGE_ROOTFS}/${PARTITION_%s_PATH} ${IMAGE_ROOTFS}-%s;" % (partition, partition))
cmds.append("mkdir ${IMAGE_ROOTFS}/${PARTITION_%s_PATH};" % partition)
return ' '.join(cmds)
def get_partitioncmds(d):
cmds = []
localdata = bb.data.createCopy(d)
baserootfssize=localdata.getVar("IMAGE_ROOTFS_SIZE",True)
rootfs=localdata.getVar("IMAGE_ROOTFS", True)
imagename=localdata.getVar("IMAGE_NAME", True)
imagenamelink=localdata.getVar("IMAGE_LINK_NAME", True)
partitions = d.getVar("PARTITIONS", True) or ""
for partition in partitions.split():
rootfssize=baserootfssize
partitionname = partition
if partition == "base":
continue
localdata.setVar("IMAGE_FSTYPES", localdata.getVar("PARTITION_%s_FS" % partition, True) or localdata.getVar("IMAGE_FSTYPES", True))
localdata.setVar("IMAGE_ROOTFS", "%s-%s" % (rootfs,partition))
localdata.setVar("IMAGE_NAME", "%s-%s" % (imagename,partition))
localdata.setVar("IMAGE_LINK_NAME", "%s-%s" % (imagenamelink,partition))
partsize=localdata.getVar("PARTITION_%s_SIZE" % partition, True)
if partsize:
rootfssize="${PARTITION_%s_SIZE}" % (partition)
localdata.setVar("IMAGE_ROOTFS_SIZE", rootfssize)
localdata.setVar("IMAGE_LINK_NAME", "%s-%s" % (imagenamelink,partition))
cmds += ["\trm -f ${DEPLOY_DIR_IMAGE}/%s-%s.*" % (imagenamelink,partition)]
cmds += [get_imagecmds(localdata)]
return ' \n '.join(cmds)
def get_update_fstab_cmds(d):
cmds = []
for partition in d.getVar("PARTITIONS", True).split():
if partition == "base":
continue
cmds.append("add_update_fstab '%s' '%s' '%s'" % ((d.getVar("PARTITION_%s_FS" % partition, True) or "").split()[0], d.getVar("PARTITION_%s_PATH" % partition, True), d.getVar("PARTITION_%s_DEVICE" % partition, True) or ""))
return '\n'.join(cmds)
munge_fstype_fstab () {
if [ -f ${IMAGE_ROOTFS}${sysconfdir}/fstab ]; then
sed -i s/ext2\.gz/ext2/g ${IMAGE_ROOTFS}${sysconfdir}/fstab
sed -i s/ext3\.gz/ext3/g ${IMAGE_ROOTFS}${sysconfdir}/fstab
fi
}
add_update_fstab () {
if [ -z "$3" ]; then
_device="/dev/FIXME"
else
_device="$3"
fi
found=
cat ${IMAGE_ROOTFS}${sysconfdir}/fstab | while read device mount fs opts dump pass; do
if [ "$mount" = "$2" ]; then
found=1
echo "$device $mount $1 $opts $dump $pass"
else
echo "$device $mount $fs $opts $dump $pass"
fi
done > ${IMAGE_ROOTFS}${sysconfdir}/fstab.new
if [ -z "$found" ]; then
echo "$_device $2 $1 defaults 0 0" >> ${IMAGE_ROOTFS}${sysconfdir}/fstab.new
fi
mv ${IMAGE_ROOTFS}${sysconfdir}/fstab.new ${IMAGE_ROOTFS}${sysconfdir}/fstab
}
split_partitions () {
${@get_splitcmds(d)}
${@get_partitioncmds(d)}
${@get_update_fstab_cmds(d)}
munge_fstype_fstab
}
IMAGE_PREPROCESS_COMMAND:append ="split_partitions;"