~tobetter/+junk/master

« back to all changes in this revision

Viewing changes to linaro_image_tools/media_create/partitions.py

  • Committer: Dongjin Kim
  • Author(s): Fathi Boudra
  • Date: 2016-06-17 01:58:26 UTC
  • Revision ID: git-v1:865376cbfb6f37cae0c2b66a1b5ff3adf62d4696
Add support for sfdisk 2.26+

Since version 2.26, sfdisk does not provide the --DOS,  --cylinders, --heads,
--sectors options.

Get rid of the deprecated options used by linaro-media-create and update
the test suite accordingly.

Fix https://bugs.linaro.org/show_bug.cgi?id=1838

Change-Id: Ib4f61d20f1b28f795175f23c1c97a4ac240b2aae
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
def setup_android_partitions(board_config, media, image_size, bootfs_label,
57
57
                             should_create_partitions,
58
58
                             should_align_boot_part=False):
59
 
    cylinders = None
60
59
    if not media.is_block_device:
61
60
        image_size_in_bytes = get_partition_size_in_bytes(image_size)
62
 
        cylinders = image_size_in_bytes / CYLINDER_SIZE
63
61
        proc = cmd_runner.run(
64
62
            ['dd', 'of=%s' % media.path,
65
63
             'bs=1', 'seek=%s' % image_size_in_bytes, 'count=0'],
68
66
 
69
67
    if should_create_partitions:
70
68
        create_partitions(
71
 
            board_config, media, HEADS, SECTORS, cylinders,
72
 
            should_align_boot_part=should_align_boot_part)
 
69
            board_config, media, should_align_boot_part=should_align_boot_part)
73
70
 
74
71
    if media.is_block_device:
75
72
        bootfs, system, cache, data, sdcard = \
137
134
    :param should_align_boot_part: Whether to align the boot partition too.
138
135
    :param part_table: Type of partition table, either 'mbr' or 'gpt'.
139
136
    """
140
 
    cylinders = None
141
137
    if not media.is_block_device:
142
138
        image_size_in_bytes = get_partition_size_in_bytes(image_size)
143
 
        cylinders = image_size_in_bytes / CYLINDER_SIZE
144
139
        proc = cmd_runner.run(
145
140
            ['dd', 'of=%s' % media.path,
146
141
             'bs=1', 'seek=%s' % image_size_in_bytes, 'count=0'],
149
144
 
150
145
    if should_create_partitions:
151
146
        create_partitions(
152
 
            board_config, media, HEADS, SECTORS, cylinders,
153
 
            should_align_boot_part=should_align_boot_part,
 
147
            board_config, media, should_align_boot_part=should_align_boot_part,
154
148
            part_table=part_table)
155
149
 
156
150
    if media.is_block_device:
527
521
    return size
528
522
 
529
523
 
530
 
def run_sfdisk_commands(commands, heads, sectors, cylinders, device,
531
 
                        as_root=True, stderr=None):
 
524
def run_sfdisk_commands(commands, device, as_root=True, stderr=None):
532
525
    """Run the given commands under sfdisk.
533
526
 
534
527
    Every time sfdisk is invoked it will repartition the device so to create
541
534
    # --force is unfortunate, but a consequence of having partitions not
542
535
    # starting on cylinder boundaries: sfdisk will abort with "Warning:
543
536
    # partition 2 does not start at a cylinder boundary"
544
 
    args = ['sfdisk',
545
 
            '--force',
546
 
            '-D',
547
 
            '-uS',
548
 
            '-H', str(heads),
549
 
            '-S', str(sectors)]
550
 
    if cylinders is not None:
551
 
        args.extend(['-C', str(cylinders)])
 
537
    args = ['sfdisk', '--force', '-uS']
552
538
    args.append(device)
553
539
    proc = cmd_runner.run(
554
540
        args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr,
563
549
    proc.wait()
564
550
 
565
551
 
566
 
def create_partitions(board_config, media, heads, sectors, cylinders=None,
567
 
                      should_align_boot_part=False, part_table="mbr"):
 
552
def create_partitions(board_config, media, should_align_boot_part=False,
 
553
                      part_table="mbr"):
568
554
    """Partition the given media according to the board requirements.
569
555
 
570
556
    :param board_config: A BoardConfig class.
571
557
    :param media: A setup_partitions.Media object to partition.
572
 
    :param heads: Number of heads to use in the disk geometry of
573
 
        partitions.
574
 
    :param sectors: Number of sectors to use in the disk geometry of
575
 
        partitions.
576
 
    :param cylinders: The number of cylinders to pass to sfdisk's -C argument.
577
 
        If None the -C argument is not passed.
578
558
    :param should_align_boot_part: Whether to align the boot partition too.
579
559
    :param part_table Type of partition table, either 'mbr' or 'gpt'.
580
560
    """
599
579
        sfdisk_cmd = board_config.get_sfdisk_cmd(
600
580
            should_align_boot_part=should_align_boot_part)
601
581
 
602
 
        run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path)
 
582
        run_sfdisk_commands(sfdisk_cmd, media.path)
603
583
 
604
584
    # sleep to wait for the partition to settle.
605
585
    wait_partition_to_settle(media, part_table)