diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 647: Added checks for dtb_files field and command line options.

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

Commit Message

Milo Casagrande Dec. 10, 2013, 5:35 p.m. UTC
Merge authors:
  Georgy Redkozubov (gesha)
Related merge proposals:
  https://code.launchpad.net/~gesha/linaro-image-tools/1235941/+merge/198406
  proposed by: Georgy Redkozubov (gesha)
  review: Approve - Milo Casagrande (milo)
------------------------------------------------------------
revno: 647 [merge]
author: Georgy Redkozubov <gesha@linaro.org>
committer: Milo Casagrande <milo@ubuntu.com>
branch nick: trunk
timestamp: Tue 2013-12-10 18:34:39 +0100
message:
  Added checks for dtb_files field and command line options.
modified:
  linaro-media-create
  linaro_image_tools/media_create/__init__.py
  linaro_image_tools/media_create/boards.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-media-create'
--- linaro-media-create	2013-08-19 07:39:34 +0000
+++ linaro-media-create	2013-10-24 18:44:58 +0000
@@ -144,7 +144,8 @@ 
     atexit.register(enable_automount)
 
     board_config = get_board_config(args.dev)
-    board_config.set_metadata(args.hwpacks, args.bootloader, args.dev)
+    board_config.set_metadata(args.hwpacks, args.bootloader, args.dev,
+                              args.dtb_file)
     board_config.add_boot_args(args.extra_boot_args)
     board_config.add_boot_args_from_file(args.extra_boot_args_file)
 

=== modified file 'linaro_image_tools/media_create/__init__.py'
--- linaro_image_tools/media_create/__init__.py	2013-02-17 13:53:41 +0000
+++ linaro_image_tools/media_create/__init__.py	2013-10-24 18:44:58 +0000
@@ -174,6 +174,11 @@ 
         help="Select a bootloader from a hardware pack that contains more "
              "than one. If not specified, it will default to '%s'." %
              DEFAULT_BOOTLOADER)
+    parser.add_argument(
+        '--dtb-file',
+        help="Select a DTB file from a hardware pack that contains more "
+             "than one. If not specified, it will default to the first "
+             "entry in 'dtb_files' list.")
 
     add_common_options(parser)
     return parser

=== modified file 'linaro_image_tools/media_create/boards.py'
--- linaro_image_tools/media_create/boards.py	2013-09-23 09:55:03 +0000
+++ linaro_image_tools/media_create/boards.py	2013-10-24 18:44:58 +0000
@@ -257,7 +257,8 @@ 
         data, _ = self.hardwarepack_handler.get_field(field_name)
         return data
 
-    def set_metadata(self, hwpacks, bootloader=None, board=None):
+    def set_metadata(self, hwpacks, bootloader=None, board=None,
+                     dtb_file=None):
         self.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader,
                                                         board)
         with self.hardwarepack_handler:
@@ -310,6 +311,12 @@ 
                 logger.warn("Deprecation warning: use the 'dtb_files' field "
                             "instead of 'dtb_file'.")
             self.dtb_files = self.get_metadata_field(DTB_FILES_FIELD)
+            if dtb_file:
+                dtb_dict = self._find_dtb_dict(dtb_file)
+                if dtb_dict:
+                    self.dtb_files = []
+                    self.dtb_files.append(dtb_dict)
+
             self.extra_boot_args_options = self.get_metadata_field(
                 EXTRA_BOOT_OPTIONS_FIELD)
             self.boot_script = self.get_metadata_field(BOOT_SCRIPT_FIELD)
@@ -873,6 +880,25 @@ 
         if self.dtb_file:
             dtb = _get_file_matching(os.path.join(path, self.dtb_file))
         if not self.dtb_file or not dtb:
+            logger.warn("Could not find a valid dtb file from dtb_file, "
+                        "trying dtb_files...")
+
+        if self.dtb_files:
+            # Use first file from list as a default dtb file.
+            dtb_file = self.dtb_files[0]
+            if dtb_file:
+                if isinstance(dtb_file, dict):
+                    for key, value in dtb_file.iteritems():
+                        # The name of the dtb file.
+                        to_file = os.path.basename(key)
+                        from_file = value
+
+                        # User specified only the directory, without renaming
+                        # the file.
+                        if not to_file:
+                            to_file = os.path.basename(from_file)
+                        dtb = _get_file_matching(os.path.join(path, from_file))
+        if not self.dtb_files or not dtb:
             logger.warn("Could not find a valid dtb file, skipping it.")
 
         logger.info("Will use kernel=%s, initrd=%s, dtb=%s." %
@@ -900,6 +926,16 @@ 
             presence = True
         return presence
 
+    def _find_dtb_dict(self, dtb):
+        """Returns dictionary entry from dt_files containing dtb file."""
+        for dtb_file in self.dtb_files:
+            if isinstance(dtb_file, dict):
+                for key, value in dtb_file.iteritems():
+                    # The name of the dtb file.
+                    if dtb in key:
+                        return dtb_file
+        return None
+
 
 class OmapConfig(BoardConfig):
     def __init__(self):