blob: 3fe5c4e26c427fcbfa632cb5595757d794ed3e7e [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# Copyright (c) 2013-2016 Intel Corporation.
5# All rights reserved.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# DESCRIPTION
21# This module provides the OpenEmbedded partition object definitions.
22#
23# AUTHORS
24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
25# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
26
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028import os
Brad Bishop316dfdd2018-06-25 12:45:53 -040029import uuid
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050030
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031from wic import WicError
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032from wic.misc import exec_cmd, exec_native_cmd, get_bitbake_var
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033from wic.pluginbase import PluginMgr
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050034
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035logger = logging.getLogger('wic')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050036
Patrick Williamsc0f7c042017-02-23 20:41:17 -060037class Partition():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050038
39 def __init__(self, args, lineno):
40 self.args = args
41 self.active = args.active
42 self.align = args.align
43 self.disk = args.disk
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 self.device = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050045 self.extra_space = args.extra_space
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 self.exclude_path = args.exclude_path
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 self.fsopts = args.fsopts
48 self.fstype = args.fstype
49 self.label = args.label
Brad Bishopd7bf8c12018-02-25 22:55:05 -050050 self.mkfs_extraopts = args.mkfs_extraopts
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050051 self.mountpoint = args.mountpoint
52 self.no_table = args.no_table
Brad Bishop6e60e8b2018-02-01 10:27:11 -050053 self.num = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054 self.overhead_factor = args.overhead_factor
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055 self.part_name = args.part_name
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050056 self.part_type = args.part_type
57 self.rootfs_dir = args.rootfs_dir
58 self.size = args.size
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 self.fixed_size = args.fixed_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060 self.source = args.source
61 self.sourceparams = args.sourceparams
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062 self.system_id = args.system_id
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063 self.use_uuid = args.use_uuid
64 self.uuid = args.uuid
Brad Bishop316dfdd2018-06-25 12:45:53 -040065 self.fsuuid = args.fsuuid
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050066
67 self.lineno = lineno
68 self.source_file = ""
69 self.sourceparams_dict = {}
70
71 def get_extra_block_count(self, current_blocks):
72 """
73 The --size param is reflected in self.size (in kB), and we already
74 have current_blocks (1k) blocks, calculate and return the
75 number of (1k) blocks we need to add to get to --size, 0 if
76 we're already there or beyond.
77 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -050078 logger.debug("Requested partition size for %s: %d",
79 self.mountpoint, self.size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050080
81 if not self.size:
82 return 0
83
84 requested_blocks = self.size
85
Brad Bishop6e60e8b2018-02-01 10:27:11 -050086 logger.debug("Requested blocks %d, current_blocks %d",
87 requested_blocks, current_blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050088
89 if requested_blocks > current_blocks:
90 return requested_blocks - current_blocks
91 else:
92 return 0
93
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 def get_rootfs_size(self, actual_rootfs_size=0):
95 """
96 Calculate the required size of rootfs taking into consideration
97 --size/--fixed-size flags as well as overhead and extra space, as
98 specified in kickstart file. Raises an error if the
99 `actual_rootfs_size` is larger than fixed-size rootfs.
100
101 """
102 if self.fixed_size:
103 rootfs_size = self.fixed_size
104 if actual_rootfs_size > rootfs_size:
105 raise WicError("Actual rootfs size (%d kB) is larger than "
106 "allowed size %d kB" %
107 (actual_rootfs_size, rootfs_size))
108 else:
109 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
110 if extra_blocks < self.extra_space:
111 extra_blocks = self.extra_space
112
113 rootfs_size = actual_rootfs_size + extra_blocks
114 rootfs_size *= self.overhead_factor
115
116 logger.debug("Added %d extra blocks to %s to get to %d total blocks",
117 extra_blocks, self.mountpoint, rootfs_size)
118
119 return rootfs_size
120
121 @property
122 def disk_size(self):
123 """
124 Obtain on-disk size of partition taking into consideration
125 --size/--fixed-size options.
126
127 """
128 return self.fixed_size if self.fixed_size else self.size
129
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500130 def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir,
131 bootimg_dir, kernel_dir, native_sysroot):
132 """
133 Prepare content for individual partitions, depending on
134 partition command parameters.
135 """
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500136 if not self.source:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500137 if not self.size and not self.fixed_size:
138 raise WicError("The %s partition has a size of zero. Please "
139 "specify a non-zero --size/--fixed-size for that "
140 "partition." % self.mountpoint)
141
142 if self.fstype == "swap":
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500143 self.prepare_swap_partition(cr_workdir, oe_builddir,
144 native_sysroot)
145 self.source_file = "%s/fs.%s" % (cr_workdir, self.fstype)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146 else:
147 if self.fstype == 'squashfs':
148 raise WicError("It's not possible to create empty squashfs "
149 "partition '%s'" % (self.mountpoint))
150
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500151 rootfs = "%s/fs_%s.%s.%s" % (cr_workdir, self.label,
152 self.lineno, self.fstype)
153 if os.path.isfile(rootfs):
154 os.remove(rootfs)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500155
156 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
157 method = getattr(self, "prepare_empty_partition_" + prefix)
158 method(rootfs, oe_builddir, native_sysroot)
159 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500160 return
161
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500162 plugins = PluginMgr.get_plugins('source')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500163
164 if self.source not in plugins:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500165 raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
166 "See 'wic list source-plugins' for a list of available"
167 " --sources.\n\tSee 'wic help source-plugins' for "
168 "details on adding a new source plugin." %
169 (self.source, self.mountpoint))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500170
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500171 srcparams_dict = {}
172 if self.sourceparams:
173 # Split sourceparams string of the form key1=val1[,key2=val2,...]
174 # into a dict. Also accepts valueless keys i.e. without =
175 splitted = self.sourceparams.split(',')
176 srcparams_dict = dict(par.split('=') for par in splitted if par)
177
178 plugin = PluginMgr.get_plugins('source')[self.source]
179 plugin.do_configure_partition(self, srcparams_dict, creator,
180 cr_workdir, oe_builddir, bootimg_dir,
181 kernel_dir, native_sysroot)
182 plugin.do_stage_partition(self, srcparams_dict, creator,
183 cr_workdir, oe_builddir, bootimg_dir,
184 kernel_dir, native_sysroot)
185 plugin.do_prepare_partition(self, srcparams_dict, creator,
186 cr_workdir, oe_builddir, bootimg_dir,
187 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400188 plugin.do_post_partition(self, srcparams_dict, creator,
189 cr_workdir, oe_builddir, bootimg_dir,
190 kernel_dir, rootfs_dir, native_sysroot)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500191
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500192 # further processing required Partition.size to be an integer, make
193 # sure that it is one
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500194 if not isinstance(self.size, int):
195 raise WicError("Partition %s internal size is not an integer. "
196 "This a bug in source plugin %s and needs to be fixed." %
197 (self.mountpoint, self.source))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500198
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500199 if self.fixed_size and self.size > self.fixed_size:
200 raise WicError("File system image of partition %s is "
201 "larger (%d kB) than its allowed size %d kB" %
202 (self.mountpoint, self.size, self.fixed_size))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500203
204 def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400205 native_sysroot, real_rootfs = True):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500206 """
207 Prepare content for a rootfs partition i.e. create a partition
208 and fill it from a /rootfs dir.
209
Brad Bishop316dfdd2018-06-25 12:45:53 -0400210 Currently handles ext2/3/4, btrfs, vfat and squashfs.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500211 """
212 p_prefix = os.environ.get("PSEUDO_PREFIX", "%s/usr" % native_sysroot)
213 p_localstatedir = os.environ.get("PSEUDO_LOCALSTATEDIR",
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500214 "%s/../pseudo" % get_bitbake_var("IMAGE_ROOTFS"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500215 p_passwd = os.environ.get("PSEUDO_PASSWD", rootfs_dir)
216 p_nosymlinkexp = os.environ.get("PSEUDO_NOSYMLINKEXP", "1")
217 pseudo = "export PSEUDO_PREFIX=%s;" % p_prefix
218 pseudo += "export PSEUDO_LOCALSTATEDIR=%s;" % p_localstatedir
219 pseudo += "export PSEUDO_PASSWD=%s;" % p_passwd
220 pseudo += "export PSEUDO_NOSYMLINKEXP=%s;" % p_nosymlinkexp
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500221 pseudo += "%s " % get_bitbake_var("FAKEROOTCMD")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500222
223 rootfs = "%s/rootfs_%s.%s.%s" % (cr_workdir, self.label,
224 self.lineno, self.fstype)
225 if os.path.isfile(rootfs):
226 os.remove(rootfs)
227
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500228 # Get rootfs size from bitbake variable if it's not set in .ks file
Brad Bishop316dfdd2018-06-25 12:45:53 -0400229 if not self.size and real_rootfs:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500230 # Bitbake variable ROOTFS_SIZE is calculated in
231 # Image._get_rootfs_size method from meta/lib/oe/image.py
232 # using IMAGE_ROOTFS_SIZE, IMAGE_ROOTFS_ALIGNMENT,
233 # IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
234 rsize_bb = get_bitbake_var('ROOTFS_SIZE')
235 if rsize_bb:
236 logger.warning('overhead-factor was specified, but size was not,'
237 ' so bitbake variables will be used for the size.'
238 ' In this case both IMAGE_OVERHEAD_FACTOR and '
239 '--overhead-factor will be applied')
240 self.size = int(round(float(rsize_bb)))
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500241
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500242 prefix = "ext" if self.fstype.startswith("ext") else self.fstype
243 method = getattr(self, "prepare_rootfs_" + prefix)
244 method(rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo)
245 self.source_file = rootfs
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500246
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500247 # get the rootfs size in the right units for kickstart (kB)
248 du_cmd = "du -Lbks %s" % rootfs
249 out = exec_cmd(du_cmd)
250 self.size = int(out.split()[0])
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500251
252 def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir,
253 native_sysroot, pseudo):
254 """
255 Prepare content for an ext2/3/4 rootfs partition.
256 """
257 du_cmd = "du -ks %s" % rootfs_dir
258 out = exec_cmd(du_cmd)
259 actual_rootfs_size = int(out.split()[0])
260
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500261 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500262
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500263 with open(rootfs, 'w') as sparse:
264 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500265
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500266 extraopts = self.mkfs_extraopts or "-F -i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500267
268 label_str = ""
269 if self.label:
270 label_str = "-L %s" % self.label
271
Brad Bishop316dfdd2018-06-25 12:45:53 -0400272 mkfs_cmd = "mkfs.%s %s %s %s -U %s -d %s" % \
273 (self.fstype, extraopts, rootfs, label_str, self.fsuuid, rootfs_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500274 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
275
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500276 mkfs_cmd = "fsck.%s -pvfD %s" % (self.fstype, rootfs)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500277 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
278
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500279 def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir,
280 native_sysroot, pseudo):
281 """
282 Prepare content for a btrfs rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500283 """
284 du_cmd = "du -ks %s" % rootfs_dir
285 out = exec_cmd(du_cmd)
286 actual_rootfs_size = int(out.split()[0])
287
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500288 rootfs_size = self.get_rootfs_size(actual_rootfs_size)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500289
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500290 with open(rootfs, 'w') as sparse:
291 os.ftruncate(sparse.fileno(), rootfs_size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500292
293 label_str = ""
294 if self.label:
295 label_str = "-L %s" % self.label
296
Brad Bishop316dfdd2018-06-25 12:45:53 -0400297 mkfs_cmd = "mkfs.%s -b %d -r %s %s %s -U %s %s" % \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500298 (self.fstype, rootfs_size * 1024, rootfs_dir, label_str,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400299 self.mkfs_extraopts, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500300 exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
301
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500302 def prepare_rootfs_msdos(self, rootfs, oe_builddir, rootfs_dir,
303 native_sysroot, pseudo):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500304 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500305 Prepare content for a msdos/vfat rootfs partition.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500306 """
307 du_cmd = "du -bks %s" % rootfs_dir
308 out = exec_cmd(du_cmd)
309 blocks = int(out.split()[0])
310
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500311 rootfs_size = self.get_rootfs_size(blocks)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500312
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500313 label_str = "-n boot"
314 if self.label:
315 label_str = "-n %s" % self.label
316
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500317 size_str = ""
318 if self.fstype == 'msdos':
319 size_str = "-F 16" # FAT 16
320
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500321 extraopts = self.mkfs_extraopts or '-S 512'
322
Brad Bishop316dfdd2018-06-25 12:45:53 -0400323 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
324 (label_str, self.fsuuid, size_str, extraopts, rootfs,
325 max(8250, rootfs_size))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500326 exec_native_cmd(dosfs_cmd, native_sysroot)
327
328 mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir)
329 exec_native_cmd(mcopy_cmd, native_sysroot)
330
331 chmod_cmd = "chmod 644 %s" % rootfs
332 exec_cmd(chmod_cmd)
333
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500334 prepare_rootfs_vfat = prepare_rootfs_msdos
335
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500336 def prepare_rootfs_squashfs(self, rootfs, oe_builddir, rootfs_dir,
337 native_sysroot, pseudo):
338 """
339 Prepare content for a squashfs rootfs partition.
340 """
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500341 extraopts = self.mkfs_extraopts or '-noappend'
342 squashfs_cmd = "mksquashfs %s %s %s" % \
343 (rootfs_dir, rootfs, extraopts)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500344 exec_native_cmd(squashfs_cmd, native_sysroot, pseudo=pseudo)
345
346 def prepare_empty_partition_ext(self, rootfs, oe_builddir,
347 native_sysroot):
348 """
349 Prepare an empty ext2/3/4 partition.
350 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500351 size = self.disk_size
352 with open(rootfs, 'w') as sparse:
353 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500354
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500355 extraopts = self.mkfs_extraopts or "-i 8192"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500356
357 label_str = ""
358 if self.label:
359 label_str = "-L %s" % self.label
360
Brad Bishop316dfdd2018-06-25 12:45:53 -0400361 mkfs_cmd = "mkfs.%s -F %s %s -U %s %s" % \
362 (self.fstype, extraopts, label_str, self.fsuuid, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500363 exec_native_cmd(mkfs_cmd, native_sysroot)
364
365 def prepare_empty_partition_btrfs(self, rootfs, oe_builddir,
366 native_sysroot):
367 """
368 Prepare an empty btrfs partition.
369 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500370 size = self.disk_size
371 with open(rootfs, 'w') as sparse:
372 os.ftruncate(sparse.fileno(), size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500373
374 label_str = ""
375 if self.label:
376 label_str = "-L %s" % self.label
377
Brad Bishop316dfdd2018-06-25 12:45:53 -0400378 mkfs_cmd = "mkfs.%s -b %d %s -U %s %s %s" % \
379 (self.fstype, self.size * 1024, label_str, self.fsuuid,
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500380 self.mkfs_extraopts, rootfs)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500381 exec_native_cmd(mkfs_cmd, native_sysroot)
382
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500383 def prepare_empty_partition_msdos(self, rootfs, oe_builddir,
384 native_sysroot):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500385 """
386 Prepare an empty vfat partition.
387 """
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500388 blocks = self.disk_size
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500389
390 label_str = "-n boot"
391 if self.label:
392 label_str = "-n %s" % self.label
393
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500394 size_str = ""
395 if self.fstype == 'msdos':
396 size_str = "-F 16" # FAT 16
397
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500398 extraopts = self.mkfs_extraopts or '-S 512'
399
Brad Bishop316dfdd2018-06-25 12:45:53 -0400400 dosfs_cmd = "mkdosfs %s -i %s %s %s -C %s %d" % \
401 (label_str, self.fsuuid, extraopts, size_str, rootfs,
402 blocks)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500403
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500404 exec_native_cmd(dosfs_cmd, native_sysroot)
405
406 chmod_cmd = "chmod 644 %s" % rootfs
407 exec_cmd(chmod_cmd)
408
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500409 prepare_empty_partition_vfat = prepare_empty_partition_msdos
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500410
411 def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot):
412 """
413 Prepare a swap partition.
414 """
415 path = "%s/fs.%s" % (cr_workdir, self.fstype)
416
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500417 with open(path, 'w') as sparse:
418 os.ftruncate(sparse.fileno(), self.size * 1024)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500419
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500420 label_str = ""
421 if self.label:
422 label_str = "-L %s" % self.label
Brad Bishop316dfdd2018-06-25 12:45:53 -0400423
424 mkswap_cmd = "mkswap %s -U %s %s" % (label_str, self.fsuuid, path)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500425 exec_native_cmd(mkswap_cmd, native_sysroot)