blob: 01466b258d49dd88b460375fd9378d4baebf960b [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
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050053
54 self.lineno = lineno
55 self.source_file = ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050056
57 def get_extra_block_count(self, current_blocks):
58 """
59 The --size param is reflected in self.size (in kB), and we already
60 have current_blocks (1k) blocks, calculate and return the
61 number of (1k) blocks we need to add to get to --size, 0 if
62 we're already there or beyond.
63 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -050064 logger.debug("Requested partition size for %s: %d",
65 self.mountpoint, self.size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050066
67 if not self.size:
68 return 0
69
70 requested_blocks = self.size
71
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072 logger.debug("Requested blocks %d, current_blocks %d",
73 requested_blocks, current_blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050074
75 if requested_blocks > current_blocks:
76 return requested_blocks - current_blocks
77 else:
78 return 0
79
Brad Bishop6e60e8b2018-02-01 10:27:11 -050080 def get_rootfs_size(self, actual_rootfs_size=0):
81 """
82 Calculate the required size of rootfs taking into consideration
83 --size/--fixed-size flags as well as overhead and extra space, as
84 specified in kickstart file. Raises an error if the
85 `actual_rootfs_size` is larger than fixed-size rootfs.
86
87 """
88 if self.fixed_size:
89 rootfs_size = self.fixed_size
90 if actual_rootfs_size > rootfs_size:
91 raise WicError("Actual rootfs size (%d kB) is larger than "
92 "allowed size %d kB" %
93 (actual_rootfs_size, rootfs_size))
94 else:
95 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
96 if extra_blocks < self.extra_space:
97 extra_blocks = self.extra_space
98
99 rootfs_size = actual_rootfs_size + extra_blocks
100 rootfs_size *= self.overhead_factor
101
102 logger.debug("Added %d extra blocks to %s to get to %d total blocks",
103 extra_blocks, self.mountpoint, rootfs_size)
104
105 return rootfs_size
106
107 @property
108 def disk_size(self):
109 """
110 Obtain on-disk size of partition taking into consideration
111 --size/--fixed-size options.
112
113 """
114 return self.fixed_size if self.fixed_size else self.size
115
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500116 def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir,
117 bootimg_dir, kernel_dir, native_sysroot):
118 """
119 Prepare content for individual partitions, depending on
120 partition command parameters.
121 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500122 if not self.source:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500123 if not self.size and not self.fixed_size:
124 raise WicError("The %s partition has a size of zero. Please "
125 "specify a non-zero --size/--fixed-size for that "
126 "partition." % self.mountpoint)
127
128 if self.fstype == "swap":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500129 self.prepare_swap_partition(cr_workdir, oe_builddir,
130 native_sysroot)
131 self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500132 else:
133 if self.fstype == 'squashfs':
134 raise WicError("It's not possible to create empty squashfs "
135 "partition '%s'" % (self.mountpoint))
136
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500137 rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label,
138 self.lineno, self.fstype)
139 if os.path.isfile(rootfs):
140 os.remove(rootfs)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500141
142 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
143 method = getattr(self, "prepare_empty_partition_" + prefix)
144 method(rootfs, oe_builddir, native_sysroot)
145 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500146 return
147
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500148 plugins = PluginMgr.get_plugins('source')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500149
150 if self.source not in plugins:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500151 raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
152 "See 'wic list source-plugins' for a list of available"
153 " --sources.\n\tSee 'wic help source-plugins' for "
154 "details on adding a new source plugin." %
155 (self.source, self.mountpoint))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500156
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500157 srcparams_dict = {}
158 if self.sourceparams:
159 # Split sourceparams string of the form key1=val1[,key2=val2,...]
160 # into a dict. Also accepts valueless keys i.e. without =
161 splitted = self.sourceparams.split(',')
Brad Bishop19323692019-04-05 15:28:33 -0400162 srcparams_dict = dict(par.split('=', 1) for par in splitted if par)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500163
164 plugin = PluginMgr.get_plugins('source')[self.source]
165 plugin.do_configure_partition(self, srcparams_dict, creator,
166 cr_workdir, oe_builddir, bootimg_dir,
167 kernel_dir, native_sysroot)
168 plugin.do_stage_partition(self, srcparams_dict, creator,
169 cr_workdir, oe_builddir, bootimg_dir,
170 kernel_dir, native_sysroot)
171 plugin.do_prepare_partition(self, srcparams_dict, creator,
172 cr_workdir, oe_builddir, bootimg_dir,
173 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400174 plugin.do_post_partition(self, srcparams_dict, creator,
175 cr_workdir, oe_builddir, bootimg_dir,
176 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500177
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500178 # further processing required Partition.size to be an integer, make
179 # sure that it is one
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500180 if not isinstance(self.size, int):
181 raise WicError("Partition %s internal size is not an integer. "
182 "This a bug in source plugin %s and needs to be fixed." %
183 (self.mountpoint, self.source))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500184
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500185 if self.fixed_size and self.size > self.fixed_size:
186 raise WicError("File system image of partition %s is "
187 "larger (%d kB) than its allowed size %d kB" %
188 (self.mountpoint, self.size, self.fixed_size))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500189
190 def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400191 native_sysroot, real_rootfs = True):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500192 """
193 Prepare content for a rootfs partition i.e. create a partition
194 and fill it from a /rootfs dir.
195
Brad Bishop316dfdd2018-06-25 12:45:53 -0400196 Currently handles ext2/3/4, btrfs, vfat and squashfs.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500197 """
198 p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
199 p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800200 "%s/../pseudo" % rootfs_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500201 p_passwd = os.environ.get("PSEUDO_PASSWD", rootfs_dir)
202 p_nosymlinkexp = os.environ.get("PSEUDO_NOSYMLINKEXP", "1")
203 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
204 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % p_localstatedir
205 pseudo += "export PSEUDO_PASSWD=%s;" % p_passwd
206 pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500207 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500208
209 rootfs = "%s/rootfs_%s.%s.%s" % (cr_workdir, self.label,
210 self.lineno, self.fstype)
211 if os.path.isfile(rootfs):
212 os.remove(rootfs)
213
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500214 # Get rootfs size from bitbake variable if it's not set in .ks file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400215 if not self.size and real_rootfs:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 # Bitbake variable ROOTFS_SIZE is calculated in
217 # Image._get_rootfs_size method from meta/lib/oe/image.py
218 # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT,
219 # IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
220 rsize_bb = get_bitbake_var('ROOTFS_SIZE')
221 if rsize_bb:
222 logger.warning('overhead-factor was specified, but size was not,'
223 ' so bitbake variables will be used for the size.'
224 ' In this case both IMAGE_OVERHEAD_FACTOR and '
225 '--overhead-factor will be applied')
226 self.size = int(round(float(rsize_bb)))
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500227
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500228 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
229 method = getattr(self, "prepare_rootfs_" + prefix)
230 method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)
231 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500232
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500233 # get the rootfs size in the right units for kickstart (kB)
234 du_cmd = "du -Lbks %s" % rootfs
235 out = exec_cmd(du_cmd)
236 self.size = int(out.split()[0])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500237
238 def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
239 native_sysroot, pseudo):
240 """
241 Prepare content for an ext2/3/4 rootfs partition.
242 """
243 du_cmd = "du -ks %s" % rootfs_dir
244 out = exec_cmd(du_cmd)
245 actual_rootfs_size = int(out.split()[0])
246
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500247 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500248
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500249 with open(rootfs, 'w') as sparse:
250 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500251
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500252 extraopts = self.mkfs_extraopts or "-F -i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500253
254 label_str = ""
255 if self.label:
256 label_str = "-L %s" % self.label
257
Brad Bishop316dfdd2018-06-25 12:45:53 -0400258 mkfs_cmd = "mkfs.%s %s %s %s -U %s -d %s" % \
259 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500260 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
261
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500262 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500263 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
264
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500265 def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
266 native_sysroot, pseudo):
267 """
268 Prepare content for a btrfs rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500269 """
270 du_cmd = "du -ks %s" % rootfs_dir
271 out = exec_cmd(du_cmd)
272 actual_rootfs_size = int(out.split()[0])
273
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500274 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500275
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500276 with open(rootfs, 'w') as sparse:
277 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500278
279 label_str = ""
280 if self.label:
281 label_str = "-L %s" % self.label
282
Brad Bishop316dfdd2018-06-25 12:45:53 -0400283 mkfs_cmd = "mkfs.%s -b %d -r %s %s %s -U %s %s" % \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500284 (self.fstype, rootfs_size * 1024, rootfs_dir, label_str,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400285 self.mkfs_extraopts, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500286 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
287
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500288 def prepare_rootfs_msdos(self, rootfs, oe_builddir, rootfs_dir,
289 native_sysroot, pseudo):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500290 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500291 Prepare content for a msdos/vfat rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500292 """
293 du_cmd = "du -bks %s" % rootfs_dir
294 out = exec_cmd(du_cmd)
295 blocks = int(out.split()[0])
296
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500297 rootfs_size = self.get_rootfs_size(blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500298
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500299 label_str = "-n boot"
300 if self.label:
301 label_str = "-n %s" % self.label
302
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 size_str = ""
304 if self.fstype == 'msdos':
305 size_str = "-F 16" # FAT 16
306
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500307 extraopts = self.mkfs_extraopts or '-S 512'
308
Brad Bishop316dfdd2018-06-25 12:45:53 -0400309 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
310 (label_str, self.fsuuid, size_str, extraopts, rootfs,
Brad Bishopc342db32019-05-15 21:57:59 -0400311 rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500312 exec_native_cmd(dosfs_cmd, native_sysroot)
313
314 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
315 exec_native_cmd(mcopy_cmd, native_sysroot)
316
317 chmod_cmd = "chmod 644 %s" % rootfs
318 exec_cmd(chmod_cmd)
319
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500320 prepare_rootfs_vfat = prepare_rootfs_msdos
321
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500322 def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
323 native_sysroot, pseudo):
324 """
325 Prepare content for a squashfs rootfs partition.
326 """
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500327 extraopts = self.mkfs_extraopts or '-noappend'
328 squashfs_cmd = "mksquashfs %s %s %s" % \
329 (rootfs_dir, rootfs, extraopts)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500330 exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
331
332 def prepare_empty_partition_ext(self, rootfs, oe_builddir,
333 native_sysroot):
334 """
335 Prepare an empty ext2/3/4 partition.
336 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500337 size = self.disk_size
338 with open(rootfs, 'w') as sparse:
339 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500340
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500341 extraopts = self.mkfs_extraopts or "-i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500342
343 label_str = ""
344 if self.label:
345 label_str = "-L %s" % self.label
346
Brad Bishop316dfdd2018-06-25 12:45:53 -0400347 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
348 (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500349 exec_native_cmd(mkfs_cmd, native_sysroot)
350
351 def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
352 native_sysroot):
353 """
354 Prepare an empty btrfs partition.
355 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500356 size = self.disk_size
357 with open(rootfs, 'w') as sparse:
358 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500359
360 label_str = ""
361 if self.label:
362 label_str = "-L %s" % self.label
363
Brad Bishop316dfdd2018-06-25 12:45:53 -0400364 mkfs_cmd = "mkfs.%s -b %d %s -U %s %s %s" % \
365 (self.fstype, self.size * 1024, label_str, self.fsuuid,
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500366 self.mkfs_extraopts, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500367 exec_native_cmd(mkfs_cmd, native_sysroot)
368
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500369 def prepare_empty_partition_msdos(self, rootfs, oe_builddir,
370 native_sysroot):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500371 """
372 Prepare an empty vfat partition.
373 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500374 blocks = self.disk_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500375
376 label_str = "-n boot"
377 if self.label:
378 label_str = "-n %s" % self.label
379
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500380 size_str = ""
381 if self.fstype == 'msdos':
382 size_str = "-F 16" # FAT 16
383
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500384 extraopts = self.mkfs_extraopts or '-S 512'
385
Brad Bishop316dfdd2018-06-25 12:45:53 -0400386 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
387 (label_str, self.fsuuid, extraopts, size_str, rootfs,
388 blocks)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500389
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500390 exec_native_cmd(dosfs_cmd, native_sysroot)
391
392 chmod_cmd = "chmod 644 %s" % rootfs
393 exec_cmd(chmod_cmd)
394
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500395 prepare_empty_partition_vfat = prepare_empty_partition_msdos
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500396
397 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
398 """
399 Prepare a swap partition.
400 """
401 path = "%s/fs.%s" % (cr_workdir, self.fstype)
402
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500403 with open(path, 'w') as sparse:
404 os.ftruncate(sparse.fileno(), self.size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500405
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500406 label_str = ""
407 if self.label:
408 label_str = "-L %s" % self.label
Brad Bishop316dfdd2018-06-25 12:45:53 -0400409
410 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, self.fsuuid, path)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500411 exec_native_cmd(mkswap_cmd, native_sysroot)