From patchwork Tue Oct 2 15:27:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milo Casagrande X-Patchwork-Id: 11948 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5482123E54 for ; Tue, 2 Oct 2012 15:27:14 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id DA4DCA1878F for ; Tue, 2 Oct 2012 15:27:13 +0000 (UTC) Received: by ieje10 with SMTP id e10so14423706iej.11 for ; Tue, 02 Oct 2012 08:27:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=Bfs2ogS4b5ed6+jOAopPbuUib7v3pBkxNjcMdVxvxlo=; b=chcLdCKHfbbS2aISG6QjSCs0AN8lPppZqyVDW4CNBlQMIRx4K3K2Rq3OwXv/EVlQX5 328V3exNPhIcCQqTe4m25YnU6XwzBLl9fZi7skKk13nXn7ZkuABWM4hdS8vDMr0bcJsZ kBKHJ+gtr3l1JRDpCEcr+PIqeVVKsIctnKaP3d8F/xDUc4AlmlBFn6a+sBGq5Za+AoOV kP3UnJkQGRKuE13IkTkB8t36r/pY5NydSFf82BZAAllm7CxnJEDVf4DkfECBN+aP/cqX 07k4bHI5Y1zrGeSvBKvsxsqZ6fHqAvI0AZPFhT88HqGii85QMAuaAgT/mzYyr1aAVWJ1 1xTA== Received: by 10.50.160.165 with SMTP id xl5mr9306531igb.0.1349191633293; Tue, 02 Oct 2012 08:27:13 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp88304igc; Tue, 2 Oct 2012 08:27:12 -0700 (PDT) Received: by 10.216.197.104 with SMTP id s82mr9564564wen.62.1349191631469; Tue, 02 Oct 2012 08:27:11 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id r1si2850747wif.4.2012.10.02.08.27.10 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 02 Oct 2012 08:27:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1TJ4NK-00029a-QI for ; Tue, 02 Oct 2012 15:27:10 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id B9FCCE03AD for ; Tue, 2 Oct 2012 15:27:10 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 570 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 570: Fixed how default bootloader is set. Message-Id: <20121002152710.20725.7483.launchpad@ackee.canonical.com> Date: Tue, 02 Oct 2012 15:27:10 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="16061"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: b6a7a1fc59906871fab6a95fa5c813b4ff0c33dd X-Gm-Message-State: ALoCoQmO9M9RGiXK4EX/dMKPV/4b9bYpUEHwFD9TU1TP2ZuOmqNHCyj5GbfJWYVPiAdMZt5E/C4n Merge authors: Milo Casagrande (milo) Related merge proposals: https://code.launchpad.net/~milo/linaro-image-tools/default-bootloader/+merge/127500 proposed by: Milo Casagrande (milo) review: Approve - James Tunnicliffe (dooferlad) ------------------------------------------------------------ revno: 570 [merge] committer: Milo Casagrande branch nick: trunk timestamp: Tue 2012-10-02 17:26:29 +0200 message: Fixed how default bootloader is set. modified: linaro_image_tools/hwpack/config.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 === modified file 'linaro_image_tools/hwpack/config.py' --- linaro_image_tools/hwpack/config.py 2012-09-28 12:07:29 +0000 +++ linaro_image_tools/hwpack/config.py 2012-10-02 15:25:27 +0000 @@ -44,6 +44,7 @@ DD_FIELD, DTB_ADDR_FIELD, DTB_FILE_FIELD, + DEFAULT_BOOTLOADER, DTB_FILES_FIELD, ENV_DD_FIELD, EXTRA_BOOT_OPTIONS_FIELD, @@ -86,6 +87,8 @@ hwpack_v3_layout, ) +import logging + class HwpackConfigError(Exception): pass @@ -153,8 +156,10 @@ # difference to what is returned when querying the object. # # self.allow_unset_bootloader allows for both modes of operation. + self.logger = logging.getLogger('linaro_image_tools') self.allow_unset_bootloader = allow_unset_bootloader self.bootloader = None + obfuscated_e = None obfuscated_yaml_e = "" try: @@ -176,8 +181,10 @@ else: # If YAML parsed OK, we don't have an error. obfuscated_e = None - self.set_board(board) - self.set_bootloader(bootloader) + if board: + self.set_board(board) + if bootloader: + self.set_bootloader(bootloader) if obfuscated_e: # If INI parsing from ConfigParser or YAML parsing failed, @@ -202,8 +209,22 @@ if isinstance(bootloaders, dict): # We have a list of bootloaders in the expected format bootloaders = bootloaders.keys() - if len(bootloaders) == 1: - bootloader = bootloaders[0] + bootloader = bootloaders[0] + if len(bootloaders) > 1: + # We have more than one bootloader, use 'u_boot'. + if DEFAULT_BOOTLOADER in bootloaders: + bootloader = DEFAULT_BOOTLOADER + self.logger.warning('WARNING: no bootloader specified ' + 'on the command line. Defaulting ' + 'to \'%s\'.' % DEFAULT_BOOTLOADER) + self.logger.warning('WARNING: specify another ' + 'bootloader if this is not the ' + 'correct one to use.') + else: + self.logger.warning('Default bootloader \'%s\' not ' + 'found. Will try to use \'%s\'. ' + 'instead.' % (DEFAULT_BOOTLOADER, + bootloader)) self.bootloader = bootloader @@ -247,11 +268,10 @@ if self.format.has_v2_fields: # Check config for all bootloaders if one isn't specified. - if self.bootloader == None and self._is_v3: + if not self.bootloader and self._is_v3: for bootloader in self.get_bootloader_list(): self.set_bootloader(bootloader) self.validate_bootloader_fields() - self.set_bootloader(None) else: self.validate_bootloader_fields() === modified file 'linaro_image_tools/media_create/boards.py' --- linaro_image_tools/media_create/boards.py 2012-10-02 14:53:56 +0000 +++ linaro_image_tools/media_create/boards.py 2012-10-02 15:25:27 +0000 @@ -47,10 +47,6 @@ partition_mounted, SECTOR_SIZE, register_loopback) from StringIO import StringIO -from linaro_image_tools.hwpack.hwpack_fields import ( - DEFAULT_BOOTLOADER, -) - KERNEL_GLOB = 'vmlinuz-*-%(kernel_flavor)s' INITRD_GLOB = 'initrd.img-*-%(kernel_flavor)s' DTB_GLOB = 'dt-*-%(kernel_flavor)s/%(dtb_name)s' @@ -134,6 +130,8 @@ self.bootloader = bootloader self.board = board self.tempdirs = {} + # Used to store the config created from the metadata. + self.config = None class FakeSecHead(object): """ Add a fake section header to the metadata file. @@ -173,18 +171,30 @@ if tempdir is not None and os.path.exists(tempdir): shutil.rmtree(tempdir) + def _get_config_from_metadata(self, metadata): + """ + Retrieves a Config object associated with the metadata. + + :param metadata: The metadata to parse. + :return: A Config instance. + """ + if not self.config: + lines = metadata.readlines() + if re.search("=", lines[0]) and not re.search(":", lines[0]): + # Probably V2 hardware pack without [hwpack] on the first line + lines = ["[hwpack]\n"] + lines + self.config = Config(StringIO("".join(lines))) + self.config.set_board(self.board) + self.config.set_bootloader(self.bootloader) + return self.config + def get_field(self, field, return_keys=False): data = None hwpack_with_data = None keys = None for hwpack_tarfile in self.hwpack_tarfiles: metadata = hwpack_tarfile.extractfile(self.metadata_filename) - lines = metadata.readlines() - if re.search("=", lines[0]) and not re.search(":", lines[0]): - # Probably V2 hardware pack without [hwpack] on the first line - lines = ["[hwpack]\n"] + lines - parser = Config(StringIO("".join(lines)), self.bootloader, - self.board) + parser = self._get_config_from_metadata(metadata) try: new_data = parser.get_option(field) if new_data is not None: @@ -466,14 +476,6 @@ @classmethod def set_metadata(cls, hwpacks, bootloader=None, board=None): - # If not bootloader is specified, we use the default one. - logger = cls._get_logger() - if not bootloader: - logger.warning('WARNING: no bootloader specified on the command ' - 'line. Defaulting to \'%s\'.' % DEFAULT_BOOTLOADER) - logger.warning('WARNING: specify another bootloader if this is ' - 'not the correct one to use.') - bootloader = DEFAULT_BOOTLOADER cls.hardwarepack_handler = HardwarepackHandler(hwpacks, bootloader, board) with cls.hardwarepack_handler: