diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 422: Allow Snowball startfiles.cfg to specify full path to each individual startfile. If an absolute p...

Message ID 20110823105313.7654.75265.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Mattias Backman Aug. 23, 2011, 10:53 a.m. UTC
Merge authors:
  Mattias Backman (mabac)
Related merge proposals:
  https://code.launchpad.net/~mabac/linaro-image-tools/bug-829220/+merge/72405
  proposed by: Mattias Backman (mabac)
  review: Approve - Loïc Minier (lool)
------------------------------------------------------------
revno: 422 [merge]
committer: Mattias Backman <mattias.backman@linaro.org>
branch nick: linaro-image-tools
timestamp: Tue 2011-08-23 12:48:46 +0200
message:
  Allow Snowball startfiles.cfg to specify full path to each individual startfile. If an absolute path is not specified, the files are assumed to be in /boot of the chroot.
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
diff mbox

Patch

=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py	2011-08-19 13:59:34 +0000
+++ linaro_image_tools/media_create/boards.py	2011-08-23 08:34:24 +0000
@@ -759,7 +759,7 @@ 
         # Populate created raw partition with TOC and startup files.
         config_files_path = os.path.join(chroot_dir, 'boot')
         _, toc_filename = tempfile.mkstemp()
-        new_files = cls.get_file_info(config_files_path)
+        new_files = cls.get_file_info(chroot_dir)
         with open(toc_filename, 'wb') as toc:
             cls.create_toc(toc, new_files)
         cls.install_snowball_boot_loader(toc_filename, new_files,
@@ -820,19 +820,26 @@ 
             f.write(data)
 
     @classmethod
-    def get_file_info(cls, bin_dir):
+    def get_file_info(cls, chroot_dir):
         ''' Fills in the offsets of files that are located in
         non-absolute memory locations depending on their sizes.'
         Also fills in file sizes'''
         ofs = cls.TOC_SIZE
         files = []
+        bin_dir = os.path.join(chroot_dir, 'boot')
         with open(os.path.join(bin_dir, cls.SNOWBALL_STARTUP_FILES_CONFIG),
                   'r') as info_file:
             for line in info_file:
                 file_data = line.split()
                 if file_data[0][0] == '#':
                     continue
-                filename = os.path.join(bin_dir, file_data[1])
+                if file_data[1].startswith('/'):
+                    filename = os.path.join(chroot_dir,
+                                            file_data[1].lstrip('/'))
+                else:
+                    filename = os.path.join(bin_dir, file_data[1])
+                assert os.path.exists(filename), "File %s does not exist, " \
+                    "please check the startfiles config file." % file_data[1]
                 address = long(file_data[3], 16)
                 if address != 0:
                     ofs = address

=== modified file 'linaro_image_tools/media_create/tests/test_media_create.py'
--- linaro_image_tools/media_create/tests/test_media_create.py	2011-08-10 22:42:02 +0000
+++ linaro_image_tools/media_create/tests/test_media_create.py	2011-08-23 08:34:24 +0000
@@ -716,6 +716,45 @@ 
             i += 1
         return expected
 
+    def test_get_file_info_relative_path(self):
+        # Create a config file
+        cfg_file = os.path.join(self.temp_bootdir_path,
+                      boards.SnowballEmmcConfig.SNOWBALL_STARTUP_FILES_CONFIG)
+        uboot_file = 'u-boot.bin'
+        with open(cfg_file, 'w') as f:
+                f.write('%s %s %i %#x %s\n' % ('NORMAL', uboot_file, 0,
+                                               0xBA0000, '9'))
+        with open(os.path.join(self.temp_bootdir_path, uboot_file), 'w') as f:
+            file_info = boards.SnowballEmmcConfig.get_file_info(
+                self.tempdir)
+        self.assertEquals(file_info[0]['filename'],
+                          os.path.join(self.temp_bootdir_path, uboot_file))
+
+    def test_get_file_info_abs_path(self):
+        # Create a config file
+        cfg_file = os.path.join(self.temp_bootdir_path,
+                      boards.SnowballEmmcConfig.SNOWBALL_STARTUP_FILES_CONFIG)
+        uboot_dir = tempfile.mkdtemp(dir=self.tempdir)
+        uboot_file = os.path.join(uboot_dir, 'u-boot.bin')
+        uboot_relative_file = uboot_file.replace(self.tempdir, '')
+        with open(cfg_file, 'w') as f:
+                f.write('%s %s %i %#x %s\n' % ('NORMAL', uboot_relative_file, 0,
+                                               0xBA0000, '9'))
+        with open(uboot_file, 'w') as f:
+            file_info = boards.SnowballEmmcConfig.get_file_info(
+                self.tempdir)
+        self.assertEquals(file_info[0]['filename'], uboot_file)
+
+    def test_get_file_info_raises(self):
+        # Create a config file
+        cfg_file = os.path.join(self.temp_bootdir_path,
+                      boards.SnowballEmmcConfig.SNOWBALL_STARTUP_FILES_CONFIG)
+        with open(cfg_file, 'w') as f:
+                f.write('%s %s %i %#x %s\n' % ('NORMAL', 'u-boot.bin', 0,
+                                               0xBA0000, '9'))
+        self.assertRaises(AssertionError, boards.SnowballEmmcConfig.get_file_info,
+                          self.tempdir)
+
     def test_file_name_size(self):
         ''' Test using a to large toc file '''
         _, toc_filename = tempfile.mkstemp()
@@ -829,7 +868,7 @@ 
     def test_normal_case(self):
         expected = self.setupFiles()
         actual = boards.SnowballEmmcConfig.get_file_info(
-            self.temp_bootdir_path)
+            self.tempdir)
         self.assertEquals(expected, actual)