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'
67
77
DEFINED_PARTITION_LAYOUTS = [
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()
114
132
self._validate_sections()
150
168
except ConfigParser.NoOptionError:
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)
153
176
def _get_option_from_main_section(self, key):
154
177
"""Get the value from the main section for the given key.
176
199
return self._get_option_from_main_section(self.SERIAL_TTY_KEY)
202
def extra_boot_options(self):
203
"""Extra boot arg options.
207
return self._get_option_from_main_section(self.EXTRA_BOOT_OPTIONS_KEY)
210
def extra_serial_opts(self):
211
"""Extra serial options.
215
return self._get_option_from_main_section(self.EXTRA_SERIAL_OPTS_KEY)
218
def boot_script(self):
219
"""File name of the target boot script.
223
return self._get_option_from_main_section(self.BOOT_SCRIPT_KEY)
179
226
def kernel_addr(self):
180
227
"""address where u-boot should load the kernel
200
247
return self._get_option_from_main_section(self.LOAD_ADDR_KEY)
251
"""address for dtb image generation
255
return self._get_option_from_main_section(self.DTB_ADDR_KEY)
203
258
def wired_interfaces(self):
204
259
"""The interfaces for wired networks
333
388
return self._get_option_from_main_section(self.X_LOADER_FILE_KEY)
392
"""The path to the vmlinuz kernel.
396
return self._get_option_from_main_section(self.VMLINUZ_KEY)
400
"""The path to initrd
404
return self._get_option_from_main_section(self.INITRD_KEY)
408
"""The path to the device tree binary.
412
return self._get_option_from_main_section(self.DTB_FILE_KEY)
336
415
def architectures(self):
337
416
"""The architectures to build the hwpack for.
399
478
self.PATH_REGEX, x_loader_file, "Invalid path: %s" % \
481
def _validate_vmlinuz(self):
482
vmlinuz = self.vmlinuz
484
raise HwpackConfigError("No kernel_file in the [%s] section" % \
486
self._assert_matches_pattern(
487
self.GLOB_REGEX, vmlinuz, "Invalid path: %s" % vmlinuz)
489
def _validate_initrd(self):
492
raise HwpackConfigError("No initrd_file in the [%s] section" % \
494
self._assert_matches_pattern(
495
self.GLOB_REGEX, initrd, "Invalid path: %s" % initrd)
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)
503
def _validate_extra_boot_options(self):
504
# Optional and tricky to determine a valid pattern.
507
def _validate_extra_serial_opts(self):
508
# Optional and tricky to determine a valid pattern.
511
def _validate_boot_script(self):
512
boot_script = self.boot_script
514
raise HwpackConfigError(
515
"No boot_script in the [%s] section" % \
518
self._assert_matches_pattern(
519
self.PATH_REGEX, boot_script, "Invalid path: %s" % boot_script)
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)
552
def _validate_dtb_addr(self):
556
if not self._validate_addr(addr):
557
raise HwpackConfigError("Invalid dtb address: %s" % addr)
433
559
def _validate_wired_interfaces(self):
491
617
"Invalid value for include-debs: %s"
492
618
% self.parser.get("hwpack", "include-debs"))
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"))
494
627
def _validate_support(self):
495
628
support = self.support
496
629
if support not in (None, "supported", "unsupported"):