blob: d809408e1a260239415fcf359a6f6196907e16fa [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001#
2# Copyright (c) 2013-2016 Intel Corporation.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05003#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05005#
6# DESCRIPTION
7# This module provides the OpenEmbedded partition object definitions.
8#
9# AUTHORS
10# Tom Zanussi <tom.zanussi (at] linux.intel.com>
11# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
12
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014import os
Brad Bishop316dfdd2018-06-25 12:45:53 -040015import uuid
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017from wic import WicError
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018from wic.misc import exec_cmd, exec_native_cmd, get_bitbake_var
Brad Bishop6e60e8b2018-02-01 10:27:11 -050019from wic.pluginbase import PluginMgr
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050020
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021logger = logging.getLogger('wic')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022
Patrick Williamsc0f7c042017-02-23 20:41:17 -060023class Partition():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024
25 def __init__(self, args, lineno):
26 self.args = args
27 self.active = args.active
28 self.align = args.align
29 self.disk = args.disk
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 self.device = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050031 self.extra_space = args.extra_space
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 self.exclude_path = args.exclude_path
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050033 self.fsopts = args.fsopts
34 self.fstype = args.fstype
35 self.label = args.label
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080036 self.use_label = args.use_label
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037 self.mkfs_extraopts = args.mkfs_extraopts
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050038 self.mountpoint = args.mountpoint
39 self.no_table = args.no_table
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 self.num = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041 self.overhead_factor = args.overhead_factor
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042 self.part_name = args.part_name
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043 self.part_type = args.part_type
44 self.rootfs_dir = args.rootfs_dir
45 self.size = args.size
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 self.fixed_size = args.fixed_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 self.source = args.source
48 self.sourceparams = args.sourceparams
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049 self.system_id = args.system_id
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050 self.use_uuid = args.use_uuid
51 self.uuid = args.uuid
Brad Bishop316dfdd2018-06-25 12:45:53 -040052 self.fsuuid = args.fsuuid
Brad Bishop08902b02019-08-20 09:16:51 -040053 self.type = args.type
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054
55 self.lineno = lineno
56 self.source_file = ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057
58 def get_extra_block_count(self, current_blocks):
59 """
60 The --size param is reflected in self.size (in kB), and we already
61 have current_blocks (1k) blocks, calculate and return the
62 number of (1k) blocks we need to add to get to --size, 0 if
63 we're already there or beyond.
64 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 logger.debug("Requested partition size for %s: %d",
66 self.mountpoint, self.size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067
68 if not self.size:
69 return 0
70
71 requested_blocks = self.size
72
Brad Bishop6e60e8b2018-02-01 10:27:11 -050073 logger.debug("Requested blocks %d, current_blocks %d",
74 requested_blocks, current_blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050075
76 if requested_blocks > current_blocks:
77 return requested_blocks - current_blocks
78 else:
79 return 0
80
Brad Bishop6e60e8b2018-02-01 10:27:11 -050081 def get_rootfs_size(self, actual_rootfs_size=0):
82 """
83 Calculate the required size of rootfs taking into consideration
84 --size/--fixed-size flags as well as overhead and extra space, as
85 specified in kickstart file. Raises an error if the
86 `actual_rootfs_size` is larger than fixed-size rootfs.
87
88 """
89 if self.fixed_size:
90 rootfs_size = self.fixed_size
91 if actual_rootfs_size > rootfs_size:
92 raise WicError("Actual rootfs size (%d kB) is larger than "
93 "allowed size %d kB" %
94 (actual_rootfs_size, rootfs_size))
95 else:
96 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
97 if extra_blocks < self.extra_space:
98 extra_blocks = self.extra_space
99
100 rootfs_size = actual_rootfs_size + extra_blocks
101 rootfs_size *= self.overhead_factor
102
103 logger.debug("Added %d extra blocks to %s to get to %d total blocks",
104 extra_blocks, self.mountpoint, rootfs_size)
105
106 return rootfs_size
107
108 @property
109 def disk_size(self):
110 """
111 Obtain on-disk size of partition taking into consideration
112 --size/--fixed-size options.
113
114 """
115 return self.fixed_size if self.fixed_size else self.size
116
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500117 def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir,
118 bootimg_dir, kernel_dir, native_sysroot):
119 """
120 Prepare content for individual partitions, depending on
121 partition command parameters.
122 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500123 if not self.source:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124 if not self.size and not self.fixed_size:
125 raise WicError("The %s partition has a size of zero. Please "
126 "specify a non-zero --size/--fixed-size for that "
127 "partition." % self.mountpoint)
128
129 if self.fstype == "swap":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500130 self.prepare_swap_partition(cr_workdir, oe_builddir,
131 native_sysroot)
132 self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 else:
134 if self.fstype == 'squashfs':
135 raise WicError("It's not possible to create empty squashfs "
136 "partition '%s'" % (self.mountpoint))
137
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500138 rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label,
139 self.lineno, self.fstype)
140 if os.path.isfile(rootfs):
141 os.remove(rootfs)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142
143 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
144 method = getattr(self, "prepare_empty_partition_" + prefix)
145 method(rootfs, oe_builddir, native_sysroot)
146 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500147 return
148
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500149 plugins = PluginMgr.get_plugins('source')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500150
151 if self.source not in plugins:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152 raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
153 "See 'wic list source-plugins' for a list of available"
154 " --sources.\n\tSee 'wic help source-plugins' for "
155 "details on adding a new source plugin." %
156 (self.source, self.mountpoint))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500157
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500158 srcparams_dict = {}
159 if self.sourceparams:
160 # Split sourceparams string of the form key1=val1[,key2=val2,...]
161 # into a dict. Also accepts valueless keys i.e. without =
162 splitted = self.sourceparams.split(',')
Brad Bishop19323692019-04-05 15:28:33 -0400163 srcparams_dict = dict(par.split('=', 1) for par in splitted if par)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500164
165 plugin = PluginMgr.get_plugins('source')[self.source]
166 plugin.do_configure_partition(self, srcparams_dict, creator,
167 cr_workdir, oe_builddir, bootimg_dir,
168 kernel_dir, native_sysroot)
169 plugin.do_stage_partition(self, srcparams_dict, creator,
170 cr_workdir, oe_builddir, bootimg_dir,
171 kernel_dir, native_sysroot)
172 plugin.do_prepare_partition(self, srcparams_dict, creator,
173 cr_workdir, oe_builddir, bootimg_dir,
174 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400175 plugin.do_post_partition(self, srcparams_dict, creator,
176 cr_workdir, oe_builddir, bootimg_dir,
177 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500178
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500179 # further processing required Partition.size to be an integer, make
180 # sure that it is one
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 if not isinstance(self.size, int):
182 raise WicError("Partition %s internal size is not an integer. "
183 "This a bug in source plugin %s and needs to be fixed." %
184 (self.mountpoint, self.source))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500185
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 if self.fixed_size and self.size > self.fixed_size:
187 raise WicError("File system image of partition %s is "
188 "larger (%d kB) than its allowed size %d kB" %
189 (self.mountpoint, self.size, self.fixed_size))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500190
191 def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400192 native_sysroot, real_rootfs = True):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500193 """
194 Prepare content for a rootfs partition i.e. create a partition
195 and fill it from a /rootfs dir.
196
Brad Bishop316dfdd2018-06-25 12:45:53 -0400197 Currently handles ext2/3/4, btrfs, vfat and squashfs.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500198 """
199 p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
200 p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800201 "%s/../pseudo" % rootfs_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500202 p_passwd = os.environ.get("PSEUDO_PASSWD", rootfs_dir)
203 p_nosymlinkexp = os.environ.get("PSEUDO_NOSYMLINKEXP", "1")
204 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
205 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % p_localstatedir
206 pseudo += "export PSEUDO_PASSWD=%s;" % p_passwd
207 pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500208 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500209
210 rootfs = "%s/rootfs_%s.%s.%s" % (cr_workdir, self.label,
211 self.lineno, self.fstype)
212 if os.path.isfile(rootfs):
213 os.remove(rootfs)
214
Brad Bishop316dfdd2018-06-25 12:45:53 -0400215 if not self.size and real_rootfs:
Brad Bishop00e122a2019-10-05 11:10:57 -0400216 # The rootfs size is not set in .ks file so try to get it
217 # from bitbake variable
218 rsize_bb = get_bitbake_var('ROOTFS_SIZE')
219 rdir = get_bitbake_var('IMAGE_ROOTFS')
220 if rsize_bb and rdir == rootfs_dir:
221 # Bitbake variable ROOTFS_SIZE is calculated in
222 # Image._get_rootfs_size method from meta/lib/oe/image.py
223 # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT,
224 # IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
225 self.size = int(round(float(rsize_bb)))
226 else:
227 # Bitbake variable ROOTFS_SIZE is not defined so compute it
228 # from the rootfs_dir size using the same logic found in
229 # get_rootfs_size() from meta/classes/image.bbclass
230 du_cmd = "du -ks %s" % rootfs_dir
231 out = exec_cmd(du_cmd)
232 self.size = int(out.split()[0])
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500233
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500234 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
235 method = getattr(self, "prepare_rootfs_" + prefix)
236 method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)
237 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500238
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500239 # get the rootfs size in the right units for kickstart (kB)
240 du_cmd = "du -Lbks %s" % rootfs
241 out = exec_cmd(du_cmd)
242 self.size = int(out.split()[0])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500243
244 def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
245 native_sysroot, pseudo):
246 """
247 Prepare content for an ext2/3/4 rootfs partition.
248 """
249 du_cmd = "du -ks %s" % rootfs_dir
250 out = exec_cmd(du_cmd)
251 actual_rootfs_size = int(out.split()[0])
252
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500253 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500254
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500255 with open(rootfs, 'w') as sparse:
256 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500257
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500258 extraopts = self.mkfs_extraopts or "-F -i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500259
260 label_str = ""
261 if self.label:
262 label_str = "-L %s" % self.label
263
Brad Bishop316dfdd2018-06-25 12:45:53 -0400264 mkfs_cmd = "mkfs.%s %s %s %s -U %s -d %s" % \
265 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500266 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
267
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500268 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500269 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
270
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500271 def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
272 native_sysroot, pseudo):
273 """
274 Prepare content for a btrfs rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500275 """
276 du_cmd = "du -ks %s" % rootfs_dir
277 out = exec_cmd(du_cmd)
278 actual_rootfs_size = int(out.split()[0])
279
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500281
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500282 with open(rootfs, 'w') as sparse:
283 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500284
285 label_str = ""
286 if self.label:
287 label_str = "-L %s" % self.label
288
Brad Bishop316dfdd2018-06-25 12:45:53 -0400289 mkfs_cmd = "mkfs.%s -b %d -r %s %s %s -U %s %s" % \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500290 (self.fstype, rootfs_size * 1024, rootfs_dir, label_str,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400291 self.mkfs_extraopts, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500292 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
293
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500294 def prepare_rootfs_msdos(self, rootfs, oe_builddir, rootfs_dir,
295 native_sysroot, pseudo):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500296 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500297 Prepare content for a msdos/vfat rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500298 """
299 du_cmd = "du -bks %s" % rootfs_dir
300 out = exec_cmd(du_cmd)
301 blocks = int(out.split()[0])
302
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 rootfs_size = self.get_rootfs_size(blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500304
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500305 label_str = "-n boot"
306 if self.label:
307 label_str = "-n %s" % self.label
308
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500309 size_str = ""
310 if self.fstype == 'msdos':
311 size_str = "-F 16" # FAT 16
312
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500313 extraopts = self.mkfs_extraopts or '-S 512'
314
Brad Bishop316dfdd2018-06-25 12:45:53 -0400315 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
316 (label_str, self.fsuuid, size_str, extraopts, rootfs,
Brad Bishopc342db32019-05-15 21:57:59 -0400317 rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500318 exec_native_cmd(dosfs_cmd, native_sysroot)
319
320 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
321 exec_native_cmd(mcopy_cmd, native_sysroot)
322
323 chmod_cmd = "chmod 644 %s" % rootfs
324 exec_cmd(chmod_cmd)
325
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326 prepare_rootfs_vfat = prepare_rootfs_msdos
327
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500328 def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
329 native_sysroot, pseudo):
330 """
331 Prepare content for a squashfs rootfs partition.
332 """
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500333 extraopts = self.mkfs_extraopts or '-noappend'
334 squashfs_cmd = "mksquashfs %s %s %s" % \
335 (rootfs_dir, rootfs, extraopts)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500336 exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
337
338 def prepare_empty_partition_ext(self, rootfs, oe_builddir,
339 native_sysroot):
340 """
341 Prepare an empty ext2/3/4 partition.
342 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500343 size = self.disk_size
344 with open(rootfs, 'w') as sparse:
345 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500346
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500347 extraopts = self.mkfs_extraopts or "-i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500348
349 label_str = ""
350 if self.label:
351 label_str = "-L %s" % self.label
352
Brad Bishop316dfdd2018-06-25 12:45:53 -0400353 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
354 (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500355 exec_native_cmd(mkfs_cmd, native_sysroot)
356
357 def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
358 native_sysroot):
359 """
360 Prepare an empty btrfs partition.
361 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500362 size = self.disk_size
363 with open(rootfs, 'w') as sparse:
364 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500365
366 label_str = ""
367 if self.label:
368 label_str = "-L %s" % self.label
369
Brad Bishop316dfdd2018-06-25 12:45:53 -0400370 mkfs_cmd = "mkfs.%s -b %d %s -U %s %s %s" % \
371 (self.fstype, self.size * 1024, label_str, self.fsuuid,
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500372 self.mkfs_extraopts, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500373 exec_native_cmd(mkfs_cmd, native_sysroot)
374
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500375 def prepare_empty_partition_msdos(self, rootfs, oe_builddir,
376 native_sysroot):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500377 """
378 Prepare an empty vfat partition.
379 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500380 blocks = self.disk_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500381
382 label_str = "-n boot"
383 if self.label:
384 label_str = "-n %s" % self.label
385
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500386 size_str = ""
387 if self.fstype == 'msdos':
388 size_str = "-F 16" # FAT 16
389
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500390 extraopts = self.mkfs_extraopts or '-S 512'
391
Brad Bishop316dfdd2018-06-25 12:45:53 -0400392 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
393 (label_str, self.fsuuid, extraopts, size_str, rootfs,
394 blocks)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500395
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500396 exec_native_cmd(dosfs_cmd, native_sysroot)
397
398 chmod_cmd = "chmod 644 %s" % rootfs
399 exec_cmd(chmod_cmd)
400
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500401 prepare_empty_partition_vfat = prepare_empty_partition_msdos
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500402
403 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
404 """
405 Prepare a swap partition.
406 """
407 path = "%s/fs.%s" % (cr_workdir, self.fstype)
408
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500409 with open(path, 'w') as sparse:
410 os.ftruncate(sparse.fileno(), self.size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500411
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500412 label_str = ""
413 if self.label:
414 label_str = "-L %s" % self.label
Brad Bishop316dfdd2018-06-25 12:45:53 -0400415
416 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, self.fsuuid, path)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500417 exec_native_cmd(mkswap_cmd, native_sysroot)