Merge lp:~salgado/linaro-image-tools/mx51evk-code-cleanup into lp:linaro-image-tools/11.11

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 260
Proposed branch: lp:~salgado/linaro-image-tools/mx51evk-code-cleanup
Merge into: lp:linaro-image-tools/11.11
Diff against target: 211 lines (+56/-34)
4 files modified
linaro-media-create (+2/-3)
linaro_media_create/boards.py (+21/-0)
linaro_media_create/partitions.py (+10/-24)
linaro_media_create/tests/test_media_create.py (+23/-7)
To merge this branch: bzr merge lp:~salgado/linaro-image-tools/mx51evk-code-cleanup
Reviewer Review Type Date Requested Status
Loïc Minier (community) Approve
James Westby (community) Approve
Review via email: mp+47456@code.launchpad.net

Description of the change

Get rid of the mx51evk-specific code in create_partitions

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
review: Approve
Revision history for this message
Loïc Minier (lool) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-media-create'
2--- linaro-media-create 2011-01-25 12:51:19 +0000
3+++ linaro-media-create 2011-01-25 20:07:57 +0000
4@@ -104,9 +104,8 @@
5 install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks)
6
7 boot_partition, root_partition = setup_partitions(
8- args.board, media, board_config.fat_size, args.image_size,
9- args.boot_label, args.rfs_label, args.rootfs, ROOTFS_UUID,
10- args.should_create_partitions,
11+ board_config, media, args.image_size, args.boot_label, args.rfs_label,
12+ args.rootfs, ROOTFS_UUID, args.should_create_partitions,
13 args.should_format_bootfs, args.should_format_rootfs)
14
15 if args.should_format_bootfs:
16
17=== modified file 'linaro_media_create/boards.py'
18--- linaro_media_create/boards.py 2011-01-25 12:02:38 +0000
19+++ linaro_media_create/boards.py 2011-01-25 20:07:57 +0000
20@@ -35,6 +35,19 @@
21 boot_script = None
22
23 @classmethod
24+ def get_sfdisk_cmd(cls):
25+ """Return the sfdisk command to partition the media."""
26+ if cls.fat_size == 32:
27+ partition_type = '0x0C'
28+ else:
29+ partition_type = '0x0E'
30+
31+ # This will create a partition of the given type, containing 9
32+ # cylinders (74027520 bytes, ~70 MiB), followed by a Linux-type
33+ # partition containing the rest of the free space.
34+ return ',9,%s,*\n,,,-' % partition_type
35+
36+ @classmethod
37 def _get_boot_cmd(cls, is_live, is_lowmem, consoles):
38 """Get the boot command for this board.
39
40@@ -195,6 +208,14 @@
41 mmc_option = '0:2'
42
43 @classmethod
44+ def get_sfdisk_cmd(cls):
45+ # Create a one cylinder partition for fixed-offset bootloader data at
46+ # the beginning of the image (size is one cylinder, so 8224768 bytes
47+ # with the first sector for MBR).
48+ sfdisk_cmd = super(Mx51evkConfig, cls).get_sfdisk_cmd()
49+ return ',1,0xDA\n%s' % sfdisk_cmd
50+
51+ @classmethod
52 def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir,
53 boot_dir, boot_script, boot_device_or_file):
54 uboot_file = os.path.join(
55
56=== modified file 'linaro_media_create/partitions.py'
57--- linaro_media_create/partitions.py 2011-01-24 19:39:45 +0000
58+++ linaro_media_create/partitions.py 2011-01-25 20:07:57 +0000
59@@ -24,15 +24,14 @@
60 # the appropriate function for the given type of device? I think it's still
61 # small enough that there's not much benefit in doing that, but if it grows we
62 # might want to do it.
63-def setup_partitions(board, media, fat_size, image_size,
64- bootfs_label, rootfs_label, rootfs_type, rootfs_uuid,
65+def setup_partitions(board_config, media, image_size, bootfs_label,
66+ rootfs_label, rootfs_type, rootfs_uuid,
67 should_create_partitions, should_format_bootfs,
68 should_format_rootfs):
69 """Make sure the given device is partitioned to boot the given board.
70
71- :param board: The board's name, as a string.
72+ :param board_config: A BoardConfig class.
73 :param media: The Media we should partition.
74- :param fat_size: The FAT size (16 or 32) for the boot partition.
75 :param image_size: The size of the image file, in case we're setting up a
76 QEMU image.
77 :param should_create_partitions: Whether or not we should erase existing
78@@ -49,7 +48,8 @@
79 proc.wait()
80
81 if should_create_partitions:
82- create_partitions(board, media, fat_size, HEADS, SECTORS, cylinders)
83+ create_partitions(
84+ board_config, media, HEADS, SECTORS, cylinders)
85
86 if media.is_block_device:
87 bootfs, rootfs = get_boot_and_root_partitions_for_media(media)
88@@ -63,7 +63,8 @@
89 # filesystem.
90 ensure_partition_is_not_mounted(bootfs)
91 proc = cmd_runner.run(
92- ['mkfs.vfat', '-F', str(fat_size), bootfs, '-n', bootfs_label],
93+ ['mkfs.vfat', '-F', str(board_config.fat_size), bootfs, '-n',
94+ bootfs_label],
95 as_root=True)
96 proc.wait()
97
98@@ -272,12 +273,11 @@
99 return proc.communicate("%s\n" % commands)
100
101
102-def create_partitions(board, media, fat_size, heads, sectors, cylinders=None):
103+def create_partitions(board_config, media, heads, sectors, cylinders=None):
104 """Partition the given media according to the board requirements.
105
106- :param board: A string with the board type (e.g. beagle, panda, etc)
107+ :param board_config: A BoardConfig class.
108 :param media: A setup_partitions.Media object to partition.
109- :param fat_size: The type of FATs used in the boot partition (16 or 32).
110 :param heads: Number of heads to use in the disk geometry of
111 partitions.
112 :param sectors: Number of sectors to use in the disk geometry of
113@@ -291,21 +291,7 @@
114 ['parted', '-s', media.path, 'mklabel', 'msdos'], as_root=True)
115 proc.wait()
116
117- if fat_size == 32:
118- partition_type = '0x0C'
119- else:
120- partition_type = '0x0E'
121-
122- sfdisk_cmd = ',9,%s,*\n,,,-' % partition_type
123- if board == 'mx51evk':
124- # Create a one cylinder partition for fixed-offset bootloader data at
125- # the beginning of the image (size is one cylinder, so 8224768 bytes
126- # with the first sector for MBR).
127- sfdisk_cmd = ',1,0xDA\n%s' % sfdisk_cmd
128-
129- # Create a VFAT or FAT16 partition of 9 cylinders (74027520 bytes, ~70
130- # MiB), followed by a Linux-type partition containing the rest of the free
131- # space.
132+ sfdisk_cmd = board_config.get_sfdisk_cmd()
133 run_sfdisk_commands(sfdisk_cmd, heads, sectors, cylinders, media.path)
134
135 # Sync and sleep to wait for the partition to settle.
136
137=== modified file 'linaro_media_create/tests/test_media_create.py'
138--- linaro_media_create/tests/test_media_create.py 2011-01-25 13:44:16 +0000
139+++ linaro_media_create/tests/test_media_create.py 2011-01-25 20:07:57 +0000
140@@ -218,6 +218,19 @@
141 'make_boot_script', 'make_boot_ini']
142 self.assertEqual(expected, self.funcs_calls)
143
144+
145+class TestGetSfdiskCmd(TestCase):
146+
147+ def test_default(self):
148+ self.assertEquals(
149+ ',9,0x0C,*\n,,,-', boards.BoardConfig.get_sfdisk_cmd())
150+
151+ def test_mx51evk(self):
152+ self.assertEquals(
153+ ',1,0xDA\n,9,0x0C,*\n,,,-',
154+ board_configs['mx51evk'].get_sfdisk_cmd())
155+
156+
157 class TestGetBootCmd(TestCase):
158
159 def test_vexpress(self):
160@@ -447,7 +460,8 @@
161 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
162 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
163
164- create_partitions('mx51evk', self.media, 32, 255, 63, '')
165+ create_partitions(
166+ board_configs['mx51evk'], self.media, 255, 63, '')
167
168 self.assertEqual(
169 [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'],
170@@ -464,7 +478,8 @@
171 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
172 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
173
174- create_partitions('beagle', self.media, 32, 255, 63, '')
175+ create_partitions(
176+ board_configs['beagle'], self.media, 255, 63, '')
177
178 self.assertEqual(
179 [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'],
180@@ -479,7 +494,8 @@
181 sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
182
183 tempfile = self.createTempFileAsFixture()
184- create_partitions('beagle', Media(tempfile), 32, 255, 63, '')
185+ create_partitions(
186+ board_configs['beagle'], Media(tempfile), 255, 63, '')
187
188 # Unlike the test for partitioning of a regular block device, in this
189 # case parted was not called as there's no existing partition table
190@@ -648,8 +664,8 @@
191 lambda image: ('/dev/loop99', '/dev/loop98')))
192 uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
193 bootfs_dev, rootfs_dev = setup_partitions(
194- 'beagle', Media(tempfile), 32, '2G', 'boot', 'root', 'ext3',
195- uuid, True, True, True)
196+ board_configs['beagle'], Media(tempfile), '2G', 'boot',
197+ 'root', 'ext3', uuid, True, True, True)
198 self.assertEqual(
199 # This is the call that would create the image file.
200 [['qemu-img', 'create', '-f', 'raw', tempfile, '2G'],
201@@ -680,8 +696,8 @@
202 popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
203 uuid = '2e82008e-1af3-4699-8521-3bf5bac1e67a'
204 bootfs_dev, rootfs_dev = setup_partitions(
205- 'beagle', media, 32, '2G', 'boot', 'root', 'ext3', uuid, True,
206- True, True)
207+ board_configs['beagle'], media, '2G', 'boot', 'root', 'ext3',
208+ uuid, True, True, True)
209 self.assertEqual(
210 [['sudo', 'parted', '-s', tempfile, 'mklabel', 'msdos'],
211 ['sudo', 'sfdisk', '-D', '-H', '255', '-S', '63', tempfile],

Subscribers

People subscribed via source and target branches