[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 362: Use the new name for the SPL for the smdkv310 if the old one isn't present.

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

Commit Message

James Westby June 23, 2011, 3:13 p.m.
Merge authors:
  Angus Ainslie (angus-akkea)
Related merge proposals:
  https://code.launchpad.net/~linaro-landing-team-samsung/linaro-image-tools/v310-spl-name-fix/+merge/65599
  proposed by: Angus Ainslie (angus-akkea)
------------------------------------------------------------
revno: 362 [merge]
committer: James Westby <james.westby@linaro.org>
branch nick: trunk
timestamp: Thu 2011-06-23 11:12:13 -0400
message:
  Use the new name for the SPL for the smdkv310 if the old one isn't present.
modified:
  linaro_image_tools/media_create/boards.py
  linaro_image_tools/media_create/tests/test_media_create.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/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-image-tools/linaro-image-tools/trunk/+edit-subscription

Patch

=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py	2011-06-23 13:08:29 +0000
+++ linaro_image_tools/media_create/boards.py	2011-06-23 15:12:13 +0000
@@ -800,19 +800,7 @@ 
     def _make_boot_files(cls, boot_env, chroot_dir, boot_dir,
                          boot_device_or_file, k_img_data, i_img_data,
                          d_img_data):
-        spl_file = os.path.join(
-            chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor,
-            'v310_mmc_spl.bin')
-        # XXX need to check that the length of spl_file is smaller than
-        # SAMSUNG_V310_BL1_LEN
-        _dd(spl_file, boot_device_or_file, seek=SAMSUNG_V310_BL1_START)
-
-        uboot_file = os.path.join(
-            chroot_dir, 'usr', 'lib', 'u-boot', cls.uboot_flavor, 'u-boot.bin')
-        # XXX need to check that the length of uboot_file is smaller than
-        # SAMSUNG_V310_BL2_LEN
-        _dd(uboot_file, boot_device_or_file, seek=SAMSUNG_V310_BL2_START)
-
+        install_smdk_boot_loader(chroot_dir, boot_device_or_file, cls.uboot_flavor)
         env_size = SAMSUNG_V310_ENV_LEN * SECTOR_SIZE
         env_file = make_flashable_env(boot_env, env_size)
         _dd(env_file, boot_device_or_file, seek=SAMSUNG_V310_ENV_START)
@@ -1009,3 +997,38 @@ 
         as_root=True)
     proc.wait()
 
+
+def _get_smdk_spl(chroot_dir, uboot_flavor):
+    spl_dir = os.path.join(
+        chroot_dir, 'usr', 'lib', 'u-boot', uboot_flavor)
+    old_spl_path = os.path.join(spl_dir, 'v310_mmc_spl.bin')
+    new_spl_path = os.path.join(spl_dir, 'u-boot-mmc-spl.bin')
+
+    spl_file = old_spl_path
+    # The new upstream u-boot filename has changed
+    if not os.path.exists(spl_file):
+        spl_file = new_spl_path
+
+    if not os.path.exists(spl_file):
+        # missing SPL loader
+        raise AssertionError("Couldn't find the SPL file, tried %s and %s"
+            % (old_spl_path, new_spl_path))
+    return spl_file
+
+
+def _get_smdk_uboot(chroot_dir, uboot_flavor):
+    uboot_file = os.path.join(
+        chroot_dir, 'usr', 'lib', 'u-boot', uboot_flavor, 'u-boot.bin')
+    return uboot_file
+
+
+def install_smdk_boot_loader(chroot_dir, boot_device_or_file, uboot_flavor):
+    spl_file = _get_smdk_spl(chroot_dir, uboot_flavor)
+    # XXX need to check that the length of spl_file is smaller than
+    # SAMSUNG_V310_BL1_LEN
+    _dd(spl_file, boot_device_or_file, seek=SAMSUNG_V310_BL1_START)
+
+    uboot_file = _get_smdk_uboot(chroot_dir, uboot_flavor)
+    # XXX need to check that the length of uboot_file is smaller than
+    # SAMSUNG_V310_BL2_LEN
+    _dd(uboot_file, boot_device_or_file, seek=SAMSUNG_V310_BL2_START)

=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py	2011-06-23 13:55:09 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2011-06-23 15:12:13 +0000
@@ -41,6 +41,8 @@ 
     )
 from linaro_image_tools.media_create.boards import (
     LOADER_MIN_SIZE_S,
+    SAMSUNG_V310_BL1_START,
+    SAMSUNG_V310_BL2_START,
     SECTOR_SIZE,
     align_up,
     align_partition,
@@ -49,12 +51,15 @@ 
     make_flashable_env,
     install_mx5_boot_loader,
     install_omap_boot_loader,
+    install_smdk_boot_loader,
     make_boot_script,
     make_uImage,
     make_uInitrd,
     make_dtb,
     _get_file_matching,
     _get_mlo_file,
+    _get_smdk_spl,
+    _get_smdk_uboot,
     _run_mkimage,
     )
 from linaro_image_tools.media_create.android_boards import (
@@ -153,6 +158,54 @@ 
             AssertionError, _get_mlo_file, tempdir)
 
 
+class TestGetSMDKSPL(TestCaseWithFixtures):
+
+    def test_no_file_present(self):
+        tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
+        uboot_flavor = "some_uboot_flavour"
+        self.assertRaises(
+            AssertionError, _get_smdk_spl, tempdir, uboot_flavor)
+
+    def test_old_file_present(self):
+        tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
+        uboot_flavor = "some_uboot_flavour"
+        path = os.path.join(tempdir, 'usr', 'lib', 'u-boot', uboot_flavor)
+        os.makedirs(path)
+        spl_path = os.path.join(path, 'v310_mmc_spl.bin')
+        open(spl_path, 'w').close()
+        self.assertEquals(spl_path, _get_smdk_spl(tempdir, uboot_flavor))
+
+    def test_new_file_present(self):
+        tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
+        uboot_flavor = "some_uboot_flavour"
+        path = os.path.join(tempdir, 'usr', 'lib', 'u-boot', uboot_flavor)
+        os.makedirs(path)
+        spl_path = os.path.join(path, 'u-boot-mmc-spl.bin')
+        open(spl_path, 'w').close()
+        self.assertEquals(spl_path, _get_smdk_spl(tempdir, uboot_flavor))
+
+    def test_prefers_old_path(self):
+        tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
+        uboot_flavor = "some_uboot_flavour"
+        path = os.path.join(tempdir, 'usr', 'lib', 'u-boot', uboot_flavor)
+        os.makedirs(path)
+        old_spl_path = os.path.join(path, 'v310_mmc_spl.bin')
+        new_spl_path = os.path.join(path, 'u-boot-mmc-spl.bin')
+        open(old_spl_path, 'w').close()
+        open(new_spl_path, 'w').close()
+        self.assertEquals(old_spl_path, _get_smdk_spl(tempdir, uboot_flavor))
+
+
+class TestGetSMDKUboot(TestCaseWithFixtures):
+
+    def test_uses_uboot_flavour(self):
+        chroot_dir = "chroot"
+        uboot_flavor = "some_uboot_flavour"
+        uboot_file = os.path.join(chroot_dir, 'usr', 'lib', 'u-boot', uboot_flavor,
+            'u-boot.bin')
+        self.assertEquals(uboot_file, _get_smdk_uboot(chroot_dir, uboot_flavor))
+
+
 class TestBootSteps(TestCaseWithFixtures):
 
     def setUp(self):
@@ -211,7 +264,7 @@ 
     def test_smdkv310_steps(self):
         self.make_boot_files(boards.SMDKV310Config)
         expected = [
-            '_dd', '_dd', 'make_flashable_env', '_dd', 'make_uImage',
+            'install_smdk_boot_loader', 'make_flashable_env', '_dd', 'make_uImage',
             'make_uInitrd', 'make_boot_script']
         self.assertEqual(expected, self.funcs_calls)
 
@@ -653,6 +706,23 @@ 
             '%s cp -v chroot_dir/MLO boot_disk' % sudo_args, 'sync']
         self.assertEqual(expected, fixture.mock.commands_executed)
 
+    def test_install_smdk_u_boot(self):
+        fixture = self._mock_Popen()
+        uboot_flavor = "some_u_boot_flavour"
+        self.useFixture(MockSomethingFixture(
+            boards, '_get_smdk_spl',
+            lambda chroot_dir, uboot_flavor: "%s/%s/SPL" % (chroot_dir, uboot_flavor)))
+        self.useFixture(MockSomethingFixture(
+            boards, '_get_smdk_uboot',
+            lambda chroot_dir, uboot_flavor: "%s/%s/uboot" % (chroot_dir, uboot_flavor)))
+        install_smdk_boot_loader("chroot_dir", "boot_disk", uboot_flavor)
+        expected = [
+            '%s dd if=chroot_dir/%s/SPL of=boot_disk bs=512 conv=notrunc '
+            'seek=%d' % (sudo_args, uboot_flavor, SAMSUNG_V310_BL1_START),
+            '%s dd if=chroot_dir/%s/uboot of=boot_disk bs=512 conv=notrunc '
+            'seek=%d' % (sudo_args, uboot_flavor, SAMSUNG_V310_BL2_START)]
+        self.assertEqual(expected, fixture.mock.commands_executed)
+
     def test_get_plain_boot_script_contents(self):
         boot_env = {'bootargs': 'mybootargs', 'bootcmd': 'mybootcmd'}
         boot_script_data = get_plain_boot_script_contents(boot_env)