diff mbox

[Branch,~linaro-maintainers/linaro-image-tools/trunk] Rev 290: Merge lp:~lool/linaro-image-tools/efikamx; adds EfikaMX support.

Message ID 20110225132133.11340.73133.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Loïc Minier Feb. 25, 2011, 1:21 p.m. UTC
Merge authors:
  Loïc Minier (lool)
Related merge proposals:
  https://code.launchpad.net/~lool/linaro-image-tools/efikamx/+merge/50151
  proposed by: Loïc Minier (lool)
  review: Approve - Guilherme Salgado (salgado)
------------------------------------------------------------
revno: 290 [merge]
committer: Loïc Minier <lool@dooz.org>
branch nick: linaro-image-tools
timestamp: Fri 2011-02-25 14:19:31 +0100
message:
  Merge lp:~lool/linaro-image-tools/efikamx; adds EfikaMX support.
modified:
  linaro_media_create/boards.py
  linaro_media_create/populate_boot.py
  linaro_media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-maintainers/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_media_create/boards.py'
--- linaro_media_create/boards.py	2011-02-23 00:35:47 +0000
+++ linaro_media_create/boards.py	2011-02-25 13:19:31 +0000
@@ -85,6 +85,8 @@ 
     """The configuration used when building an image for a board."""
     # These attributes may not need to be redefined on some subclasses.
     uboot_flavor = None
+    # whether to copy u-boot to the boot partition
+    uboot_in_boot_part = False
     mmc_option = '0:1'
     mmc_part_offset = 0
     fat_size = 32
@@ -201,6 +203,7 @@ 
 
 
 class OmapConfig(BoardConfig):
+    uboot_in_boot_part = True
 
     # XXX: Here we define these things as dynamic properties because our
     # temporary hack to fix bug 697824 relies on changing the board's
@@ -310,6 +313,7 @@ 
 
 
 class IgepConfig(BeagleConfig):
+    uboot_in_boot_part = False
     uboot_flavor = None
 
     @classmethod
@@ -347,7 +351,7 @@ 
         make_boot_script(boot_cmd, boot_script)
 
 
-class Mx51evkConfig(BoardConfig):
+class Mx5Config(BoardConfig):
     serial_tty = 'ttymxc0'
     extra_serial_opts = 'console=tty0 console=%s,115200n8' % serial_tty
     live_serial_opts = 'serialtty=%s' % serial_tty
@@ -391,16 +395,25 @@ 
     def _make_boot_files(cls, uboot_parts_dir, boot_cmd, chroot_dir,
                          boot_dir, boot_script, boot_device_or_file):
         uboot_file = os.path.join(
-            chroot_dir, 'usr', 'lib', 'u-boot', 'mx51evk', 'u-boot.imx')
-        install_mx51evk_boot_loader(uboot_file, boot_device_or_file)
+            chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor, 'u-boot.imx')
+        install_mx5_boot_loader(uboot_file, boot_device_or_file)
         make_uImage(
             cls.load_addr, uboot_parts_dir, cls.kernel_suffix, boot_dir)
         make_uInitrd(uboot_parts_dir, cls.kernel_suffix, boot_dir)
         make_boot_script(boot_cmd, boot_script)
 
 
+class EfikamxConfig(Mx5Config):
+    uboot_flavor = 'efikamx'
+
+
+class Mx51evkConfig(Mx5Config):
+    uboot_flavor = 'mx51evk'
+
+
 class VexpressConfig(BoardConfig):
     uboot_flavor = 'ca9x4_ct_vxp'
+    uboot_in_boot_part = True
     serial_tty = 'ttyAMA0'
     extra_serial_opts = 'console=tty0 console=%s,38400n8' % serial_tty
     live_serial_opts = 'serialtty=%s' % serial_tty
@@ -427,6 +440,7 @@ 
     'panda': PandaConfig,
     'vexpress': VexpressConfig,
     'ux500': Ux500Config,
+    'efikamx': EfikamxConfig,
     'mx51evk': Mx51evkConfig,
     'overo': OveroConfig,
     }
@@ -492,7 +506,7 @@ 
         'script', '0', '0', 'boot script', tmpfile, boot_script)
 
 
-def install_mx51evk_boot_loader(imx_file, boot_device_or_file):
+def install_mx5_boot_loader(imx_file, boot_device_or_file):
     proc = cmd_runner.run([
         "dd",
         "if=%s" % imx_file,

=== modified file 'linaro_media_create/populate_boot.py'
--- linaro_media_create/populate_boot.py	2011-01-28 19:50:48 +0000
+++ linaro_media_create/populate_boot.py	2011-02-25 12:55:18 +0000
@@ -17,7 +17,6 @@ 
 # You should have received a copy of the GNU General Public License
 # along with Linaro Image Tools.  If not, see <http://www.gnu.org/licenses/>.
 
-import errno
 import os
 
 from linaro_media_create import cmd_runner
@@ -32,17 +31,13 @@ 
         parts_dir = 'casper'
     uboot_parts_dir = os.path.join(chroot_dir, parts_dir)
 
-    try:
-        os.makedirs(boot_disk)
-    except OSError, exc:
-        if exc.errno == errno.EEXIST:
-            pass
-        else:
-            raise
+    cmd_runner.run(['mkdir', '-p', boot_disk]).wait()
     cmd_runner.run(['mount', boot_partition, boot_disk], as_root=True).wait()
 
-    uboot_flavor = board_config.uboot_flavor
-    if uboot_flavor is not None:
+    if board_config.uboot_in_boot_part:
+        uboot_flavor = board_config.uboot_flavor
+        assert uboot_flavor is not None, (
+            "uboot_in_boot_part is set but not uboot_flavor")
         uboot_bin = os.path.join(
             chroot_dir, 'usr', 'lib', 'u-boot', uboot_flavor, 'u-boot.bin')
         cmd_runner.run(

=== modified file 'linaro_media_create/tests/test_media_create.py'
--- linaro_media_create/tests/test_media_create.py	2011-02-23 00:35:47 +0000
+++ linaro_media_create/tests/test_media_create.py	2011-02-25 13:19:31 +0000
@@ -45,8 +45,9 @@ 
 from linaro_media_create.boards import (
     align_up,
     align_partition,
-    BoardConfig,
     board_configs,
+    install_mx5_boot_loader,
+    install_omap_boot_loader,
     make_boot_script,
     make_uImage,
     make_uInitrd,
@@ -75,6 +76,7 @@ 
     get_uuid,
     _parse_blkid_output,
     )
+from linaro_media_create.populate_boot import populate_boot
 from linaro_media_create.rootfs import (
     create_flash_kernel_config,
     has_space_left_for_swap,
@@ -213,6 +215,7 @@ 
             AssertionError, _get_mlo_file, tempdir)
 
 class TestBootSteps(TestCaseWithFixtures):
+
     def setUp(self):
         super(TestBootSteps, self).setUp()
         self.funcs_calls = []
@@ -248,10 +251,10 @@ 
         expected = ['make_uImage', 'make_uInitrd']
         self.assertEqual(expected, self.funcs_calls)
 
-    def test_mx51evk_steps(self):
+    def test_mx5_steps(self):
         self.make_boot_files(boards.Mx51evkConfig)
         expected = [
-            'install_mx51evk_boot_loader', 'make_uImage', 'make_uInitrd',
+            'install_mx5_boot_loader', 'make_uImage', 'make_uInitrd',
             'make_boot_script']
         self.assertEqual(expected, self.funcs_calls)
 
@@ -286,6 +289,7 @@ 
 
 
 class TestAlignPartition(TestCase):
+
     def test_align_up_none(self):
         self.assertEqual(1024, align_up(1024, 1))
 
@@ -322,7 +326,7 @@ 
         self.set_appropriate_serial_tty_called = False
         self.mock_set_appropriate_serial_tty(board_configs['beagle'])
         self.useFixture(MockSomethingFixture(
-            BoardConfig, 'make_boot_files',
+            boards.BoardConfig, 'make_boot_files',
             classmethod(lambda *args: None)))
         # We don't need to worry about what's passed to make_boot_files()
         # because we mock the method which does the real work above and here
@@ -363,10 +367,10 @@ 
             '8192,106496,0x0C,*\n114688,,,-',
             boards.BoardConfig.get_sfdisk_cmd(should_align_boot_part=True))
 
-    def test_mx51evk(self):
+    def test_mx5(self):
         self.assertEqual(
             '1,8191,0xDA\n8192,106496,0x0C,*\n114688,,,-',
-            board_configs['mx51evk'].get_sfdisk_cmd())
+            boards.Mx5Config.get_sfdisk_cmd())
 
 
 class TestGetBootCmd(TestCase):
@@ -382,8 +386,8 @@ 
             "root=UUID=deadbeef rootwait ro'\nboot")
         self.assertEqual(expected, boot_cmd)
 
-    def test_mx51evk(self):
-        boot_cmd = board_configs['mx51evk']._get_boot_cmd(
+    def test_mx5(self):
+        boot_cmd = boards.Mx5Config._get_boot_cmd(
             is_live=False, is_lowmem=False, consoles=[],
             rootfs_uuid="deadbeef")
         expected = (
@@ -550,7 +554,7 @@ 
         self.assertEqual(0, returncode)
 
 
-class TestPopulateBoot(TestCaseWithFixtures):
+class TestBoards(TestCaseWithFixtures):
 
     def _mock_get_file_matching(self):
         self.useFixture(MockSomethingFixture(
@@ -582,6 +586,25 @@ 
             '-d', 'parts_dir/initrd.img-*-sub_arch', 'boot_disk/uInitrd']
         self.assertEqual([expected], fixture.mock.calls)
 
+    def test_install_mx5_boot_loader(self):
+        fixture = self._mock_Popen()
+        install_mx5_boot_loader("imx_file", "boot_device_or_file")
+        expected = [
+            'sudo', 'dd', 'if=imx_file', 'of=boot_device_or_file', 'bs=1024',
+            'seek=1', 'conv=notrunc']
+        self.assertEqual([expected], fixture.mock.calls)
+
+    def test_install_omap_boot_loader(self):
+        fixture = self._mock_Popen()
+        self.useFixture(MockSomethingFixture(
+            boards, '_get_mlo_file',
+            lambda chroot_dir: "%s/MLO" % chroot_dir))
+        install_omap_boot_loader("chroot_dir", "boot_disk")
+        expected = [
+            ['sudo', 'cp', '-v', 'chroot_dir/MLO', 'boot_disk'],
+            ['sync']]
+        self.assertEqual(expected, fixture.mock.calls)
+
     def test_make_boot_script(self):
         self.useFixture(MockSomethingFixture(
             tempfile, 'mkstemp', lambda: (-1, '/tmp/random-abxzr')))
@@ -647,13 +670,12 @@ 
         super(TestCreatePartitions, self).tearDown()
         time.sleep = self.orig_sleep
 
-    def test_create_partitions_for_mx51evk(self):
+    def test_create_partitions_for_mx5(self):
         # For this board we create a one cylinder partition at the beginning.
         popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
         sfdisk_fixture = self.useFixture(MockRunSfdiskCommandsFixture())
 
-        create_partitions(
-            board_configs['mx51evk'], self.media, 255, 63, '')
+        create_partitions(boards.Mx5Config, self.media, 255, 63, '')
 
         self.assertEqual(
             [['sudo', 'parted', '-s', self.media.path, 'mklabel', 'msdos'],
@@ -774,7 +796,7 @@ 
             get_boot_and_root_partitions_for_media(
                 media, board_configs['beagle']))
 
-    def test_get_boot_and_root_partitions_for_media_mx51evk(self):
+    def test_get_boot_and_root_partitions_for_media_mx5(self):
         self.useFixture(MockSomethingFixture(
             partitions, '_get_device_file_for_partition_number',
             lambda dev, partition: '%s%d' % (tempfile, partition)))
@@ -783,8 +805,7 @@ 
         media.is_block_device = True
         self.assertEqual(
             ("%s%d" % (tempfile, 2), "%s%d" % (tempfile, 3)),
-            get_boot_and_root_partitions_for_media(
-                media, board_configs['mx51evk']))
+            get_boot_and_root_partitions_for_media(media, boards.Mx5Config))
 
     def _create_qemu_img_with_partitions(self, sfdisk_commands):
         tempfile = self.createTempFileAsFixture()
@@ -910,6 +931,75 @@ 
             popen_fixture.mock.calls)
 
 
+class TestPopulateBoot(TestCaseWithFixtures):
+
+    expected_args = (
+        'chroot_dir/boot', False, False, [], 'chroot_dir', 'rootfs_uuid',
+        'boot_disk', 'boot_disk/boot_script', 'boot_device_or_file')
+    expected_args_live = (
+        'chroot_dir/casper', True, False, [], 'chroot_dir', 'rootfs_uuid',
+        'boot_disk', 'boot_disk/boot_script', 'boot_device_or_file')
+    expected_calls = [
+            ["mkdir", "-p", "boot_disk"],
+            ["sudo", "mount", "boot_partition", "boot_disk"],
+            ["sync"],
+            ["sudo", "umount", "boot_disk"]]
+
+    def save_args(self, *args):
+        self.saved_args = args
+
+    def prepare_config(self, config):
+        class c(config):
+            pass
+
+        self.config = c
+        self.config.boot_script = 'boot_script'
+        self.popen_fixture = self.useFixture(MockCmdRunnerPopenFixture())
+        self.useFixture(MockSomethingFixture(
+            self.config, 'make_boot_files', self.save_args))
+
+    def call_populate_boot(self, config, is_live=False):
+        populate_boot(
+            config, 'chroot_dir', 'rootfs_uuid', 'boot_partition', 'boot_disk',
+            'boot_device_or_file', is_live, False, [])
+
+    def test_populate_boot_live(self):
+        self.prepare_config(boards.BoardConfig)
+        self.call_populate_boot(self.config, is_live=True)
+        self.assertEquals(self.expected_calls, self.popen_fixture.mock.calls)
+        self.assertEquals(self.expected_args_live, self.saved_args)
+
+    def test_populate_boot_regular(self):
+        self.prepare_config(boards.BoardConfig)
+        self.call_populate_boot(self.config)
+        self.assertEquals(self.expected_calls, self.popen_fixture.mock.calls)
+        self.assertEquals(self.expected_args, self.saved_args)
+
+    def test_populate_boot_uboot_flavor(self):
+        self.prepare_config(boards.BoardConfig)
+        self.config.uboot_flavor = "uboot_flavor"
+        self.call_populate_boot(self.config)
+        self.assertEquals(self.expected_calls, self.popen_fixture.mock.calls)
+        self.assertEquals(self.expected_args, self.saved_args)
+
+    def test_populate_boot_uboot_in_boot_part(self):
+        self.prepare_config(boards.BoardConfig)
+        self.config.uboot_flavor = "uboot_flavor"
+        self.config.uboot_in_boot_part = True
+        self.call_populate_boot(self.config)
+        expected_calls = self.expected_calls[:]
+        expected_calls.insert(2, [
+            "sudo", "cp", "-v",
+            "chroot_dir/usr/lib/u-boot/uboot_flavor/u-boot.bin", "boot_disk"])
+        self.assertEquals(expected_calls, self.popen_fixture.mock.calls)
+        self.assertEquals(self.expected_args, self.saved_args)
+
+    def test_populate_boot_no_uboot_flavor(self):
+        self.prepare_config(boards.BoardConfig)
+        self.config.uboot_in_boot_part = True
+        self.assertRaises(AssertionError, self.call_populate_boot, self.config)
+
+
 class TestPopulateRootFS(TestCaseWithFixtures):
 
     lines_added_to_fstab = None
@@ -1087,7 +1177,9 @@ 
 
 
 class AtExitRegister(object):
+
     funcs = None
+
     def __call__(self, func, *args, **kwargs):
         if self.funcs is None:
             self.funcs = []
@@ -1098,7 +1190,6 @@ 
             func(*args, **kwargs)
 
 
-
 class TestInstallHWPack(TestCaseWithFixtures):
 
     def test_temporarily_overwrite_file_on_dir(self):