~mabac/linaro-image-tools/bug-837201

« back to all changes in this revision

Viewing changes to linaro_image_tools/hwpack/config.py

  • Committer: Mattias Backman
  • Date: 2011-08-24 14:05:56 UTC
  • mfrom: (397.3.21 hwpacks-v2-add-vmlinuz)
  • Revision ID: mattias.backman@linaro.org-20110824140556-8oga43g7l1ez4bjb
Add support for more hwpack v2.0 fields.

    kernel_file - path to the installed kernel
    initrd_file - path to the installed initrd
    dtb_file - path to the installed device tree binary
    dtb_addr - device tree address
    extra_boot_options - extra boot arg options
    boot_script - filename relative to /boot where to put boot script
    u_boot_in_boot_part - whether to put the uboot binary in the boot partition
    extra_serial_opts - extra serial options

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import ConfigParser
23
23
import re
 
24
import string
24
25
 
25
26
from linaro_image_tools.hwpack.hardwarepack_format import (
26
27
    HardwarePackFormatV1,
43
44
    PACKAGES_KEY = "packages"
44
45
    PACKAGE_REGEX = NAME_REGEX
45
46
    PATH_REGEX = r"\w[\w+\-./_]+$"
 
47
    GLOB_REGEX = r"\w[\w+\-./_\*]+$"
46
48
    ORIGIN_KEY = "origin"
47
49
    MAINTAINER_KEY = "maintainer"
48
50
    ARCHITECTURES_KEY = "architectures"
53
55
    KERNEL_ADDR_KEY = "kernel_addr"
54
56
    INITRD_ADDR_KEY = "initrd_addr"
55
57
    LOAD_ADDR_KEY = "load_addr"
 
58
    DTB_ADDR_KEY = "dtb_addr"
56
59
    WIRED_INTERFACES_KEY = "wired_interfaces"
57
60
    WIRELESS_INTERFACES_KEY = "wireless_interfaces"
58
61
    PARTITION_LAYOUT_KEY = "partition_layout"
63
66
    LOADER_MIN_SIZE_KEY = "loader_min_size"
64
67
    X_LOADER_PACKAGE_KEY = "x_loader_package"
65
68
    X_LOADER_FILE_KEY = "x_loader_file"
 
69
    VMLINUZ_KEY = "kernel_file"
 
70
    INITRD_KEY = "initrd_file"
 
71
    DTB_FILE_KEY = "dtb_file"
 
72
    EXTRA_BOOT_OPTIONS_KEY = 'extra_boot_options'
 
73
    BOOT_SCRIPT_KEY = 'boot_script'
 
74
    UBOOT_IN_BOOT_PART_KEY = 'u_boot_in_boot_part'
 
75
    EXTRA_SERIAL_OPTS_KEY = 'extra_serial_options'
66
76
 
67
77
    DEFINED_PARTITION_LAYOUTS = [
68
78
        'bootfs16_rootfs',
101
111
            self._validate_kernel_addr()
102
112
            self._validate_initrd_addr()
103
113
            self._validate_load_addr()
 
114
            self._validate_dtb_addr()
104
115
            self._validate_wired_interfaces()
105
116
            self._validate_wireless_interfaces()
106
117
            self._validate_partition_layout()
110
121
            self._validate_loader_min_size()
111
122
            self._validate_x_loader_package()
112
123
            self._validate_x_loader_file()
 
124
            self._validate_vmlinuz()
 
125
            self._validate_initrd()
 
126
            self._validate_dtb_file()
 
127
            self._validate_extra_boot_options()
 
128
            self._validate_boot_script()
 
129
            self._validate_uboot_in_boot_part()
 
130
            self._validate_extra_serial_opts()
113
131
 
114
132
        self._validate_sections()
115
133
 
150
168
        except ConfigParser.NoOptionError:
151
169
            return True
152
170
 
 
171
    @property
 
172
    def uboot_in_boot_part(self):
 
173
        """Whether uboot binary should be put in the boot partition. A str."""
 
174
        return self.parser.get(self.MAIN_SECTION, self.UBOOT_IN_BOOT_PART_KEY)
 
175
 
153
176
    def _get_option_from_main_section(self, key):
154
177
        """Get the value from the main section for the given key.
155
178
 
176
199
        return self._get_option_from_main_section(self.SERIAL_TTY_KEY)
177
200
 
178
201
    @property
 
202
    def extra_boot_options(self):
 
203
        """Extra boot arg options.
 
204
 
 
205
        A str.
 
206
        """
 
207
        return self._get_option_from_main_section(self.EXTRA_BOOT_OPTIONS_KEY)
 
208
 
 
209
    @property
 
210
    def extra_serial_opts(self):
 
211
        """Extra serial options.
 
212
 
 
213
        A str.
 
214
        """
 
215
        return self._get_option_from_main_section(self.EXTRA_SERIAL_OPTS_KEY)
 
216
 
 
217
    @property
 
218
    def boot_script(self):
 
219
        """File name of the target boot script.
 
220
 
 
221
        A str.
 
222
        """
 
223
        return self._get_option_from_main_section(self.BOOT_SCRIPT_KEY)
 
224
 
 
225
    @property
179
226
    def kernel_addr(self):
180
227
        """address where u-boot should load the kernel 
181
228
 
200
247
        return self._get_option_from_main_section(self.LOAD_ADDR_KEY)
201
248
 
202
249
    @property
 
250
    def dtb_addr(self):
 
251
        """address for dtb image generation
 
252
 
 
253
        An int.
 
254
        """
 
255
        return self._get_option_from_main_section(self.DTB_ADDR_KEY)
 
256
 
 
257
    @property
203
258
    def wired_interfaces(self):
204
259
        """The interfaces for wired networks
205
260
 
333
388
        return self._get_option_from_main_section(self.X_LOADER_FILE_KEY)
334
389
 
335
390
    @property
 
391
    def vmlinuz(self):
 
392
        """The path to the vmlinuz kernel.
 
393
 
 
394
        A str.
 
395
        """
 
396
        return self._get_option_from_main_section(self.VMLINUZ_KEY)
 
397
 
 
398
    @property
 
399
    def initrd(self):
 
400
        """The path to initrd
 
401
 
 
402
        A str.
 
403
        """
 
404
        return self._get_option_from_main_section(self.INITRD_KEY)
 
405
 
 
406
    @property
 
407
    def dtb_file(self):
 
408
        """The path to the device tree binary.
 
409
 
 
410
        A str.
 
411
        """
 
412
        return self._get_option_from_main_section(self.DTB_FILE_KEY)
 
413
 
 
414
    @property
336
415
    def architectures(self):
337
416
        """The architectures to build the hwpack for.
338
417
 
399
478
                self.PATH_REGEX, x_loader_file, "Invalid path: %s" % \
400
479
                    x_loader_file)
401
480
 
 
481
    def _validate_vmlinuz(self):
 
482
        vmlinuz = self.vmlinuz
 
483
        if not vmlinuz:
 
484
            raise HwpackConfigError("No kernel_file in the [%s] section" % \
 
485
                                        self.MAIN_SECTION)
 
486
        self._assert_matches_pattern(
 
487
            self.GLOB_REGEX, vmlinuz, "Invalid path: %s" % vmlinuz)
 
488
 
 
489
    def _validate_initrd(self):
 
490
        initrd = self.initrd
 
491
        if not initrd:
 
492
            raise HwpackConfigError("No initrd_file in the [%s] section" % \
 
493
                                        self.MAIN_SECTION)
 
494
        self._assert_matches_pattern(
 
495
            self.GLOB_REGEX, initrd, "Invalid path: %s" % initrd)
 
496
 
 
497
    def _validate_dtb_file(self):
 
498
        dtb_file = self.dtb_file
 
499
        if dtb_file is not None:
 
500
            self._assert_matches_pattern(
 
501
                self.GLOB_REGEX, dtb_file, "Invalid path: %s" % dtb_file)
 
502
        
 
503
    def _validate_extra_boot_options(self):
 
504
        # Optional and tricky to determine a valid pattern.
 
505
        pass
 
506
 
 
507
    def _validate_extra_serial_opts(self):
 
508
        # Optional and tricky to determine a valid pattern.
 
509
        pass
 
510
 
 
511
    def _validate_boot_script(self):
 
512
        boot_script = self.boot_script
 
513
        if not boot_script:
 
514
            raise HwpackConfigError(
 
515
                "No boot_script in the [%s] section" % \
 
516
                    self.MAIN_SECTION)
 
517
        else:
 
518
            self._assert_matches_pattern(
 
519
                self.PATH_REGEX, boot_script, "Invalid path: %s" % boot_script)
 
520
 
402
521
    def _validate_serial_tty(self):
403
522
        serial_tty = self.serial_tty
404
523
        if serial_tty is None:
430
549
        if not self._validate_addr(addr):
431
550
            raise HwpackConfigError("Invalid load address: %s" % addr)
432
551
 
 
552
    def _validate_dtb_addr(self):
 
553
        addr = self.dtb_addr
 
554
        if addr is None:
 
555
            return
 
556
        if not self._validate_addr(addr):
 
557
            raise HwpackConfigError("Invalid dtb address: %s" % addr)
 
558
 
433
559
    def _validate_wired_interfaces(self):
434
560
        pass
435
561
 
491
617
                "Invalid value for include-debs: %s"
492
618
                % self.parser.get("hwpack", "include-debs"))
493
619
 
 
620
    def _validate_uboot_in_boot_part(self):
 
621
        uboot_in_boot_part = self.uboot_in_boot_part
 
622
        if string.lower(uboot_in_boot_part) not in ['yes', 'no']:
 
623
            raise HwpackConfigError(
 
624
                "Invalid value for u_boot_in_boot_part: %s"
 
625
                % self.parser.get("hwpack", "u_boot_in_boot_part"))
 
626
 
494
627
    def _validate_support(self):
495
628
        support = self.support
496
629
        if support not in (None, "supported", "unsupported"):