|
28 | 28 | MIN_PARTITION_SUBTYPE_APP_OTA = 0x10
|
29 | 29 | NUM_PARTITION_SUBTYPE_APP_OTA = 16
|
30 | 30 |
|
| 31 | +SECURE_NONE = None |
| 32 | +SECURE_V1 = 'v1' |
| 33 | +SECURE_V2 = 'v2' |
| 34 | + |
31 | 35 | __version__ = '1.2'
|
32 | 36 |
|
33 | 37 | APP_TYPE = 0x00
|
@@ -91,13 +95,26 @@ def get_subtype_as_int(ptype, subtype):
|
91 | 95 | STRICT_DATA_ALIGNMENT = 0x1000
|
92 | 96 |
|
93 | 97 |
|
94 |
| -def get_alignment_for_type(ptype): |
| 98 | +def get_alignment_offset_for_type(ptype): |
95 | 99 | return ALIGNMENT.get(ptype, ALIGNMENT[DATA_TYPE])
|
96 | 100 |
|
97 | 101 |
|
| 102 | +def get_alignment_size_for_type(ptype): |
| 103 | + if ptype == APP_TYPE and secure == SECURE_V1: |
| 104 | + # For secure boot v1 case, app partition must be 64K aligned |
| 105 | + # signature block (68 bytes) lies at the very end of 64K block |
| 106 | + return 0x10000 |
| 107 | + if ptype == APP_TYPE and secure == SECURE_V2: |
| 108 | + # For secure boot v2 case, app partition must be 4K aligned |
| 109 | + # signature block (4K) is kept after padding the unsigned image to 64K boundary |
| 110 | + return 0x1000 |
| 111 | + # No specific size alignement requirement as such |
| 112 | + return 0x1 |
| 113 | + |
| 114 | + |
98 | 115 | quiet = False
|
99 | 116 | md5sum = True
|
100 |
| -secure = False |
| 117 | +secure = SECURE_NONE |
101 | 118 | offset_part_table = 0
|
102 | 119 |
|
103 | 120 |
|
@@ -164,7 +181,7 @@ def expand_vars(f):
|
164 | 181 | raise InputError('CSV Error: Partitions overlap. Partition at line %d sets offset 0x%x. Previous partition ends 0x%x'
|
165 | 182 | % (e.line_no, e.offset, last_end))
|
166 | 183 | if e.offset is None:
|
167 |
| - pad_to = get_alignment_for_type(e.type) |
| 184 | + pad_to = get_alignment_offset_for_type(e.type) |
168 | 185 | if last_end % pad_to != 0:
|
169 | 186 | last_end += pad_to - (last_end % pad_to)
|
170 | 187 | e.offset = last_end
|
@@ -397,18 +414,20 @@ def verify(self):
|
397 | 414 | raise ValidationError(self, 'Subtype field is not set')
|
398 | 415 | if self.offset is None:
|
399 | 416 | raise ValidationError(self, 'Offset field is not set')
|
400 |
| - align = get_alignment_for_type(self.type) |
401 |
| - if self.offset % align: |
402 |
| - raise ValidationError(self, 'Offset 0x%x is not aligned to 0x%x' % (self.offset, align)) |
| 417 | + if self.size is None: |
| 418 | + raise ValidationError(self, 'Size field is not set') |
| 419 | + offset_align = get_alignment_offset_for_type(self.type) |
| 420 | + if self.offset % offset_align: |
| 421 | + raise ValidationError(self, 'Offset 0x%x is not aligned to 0x%x' % (self.offset, offset_align)) |
403 | 422 | # The alignment requirement for non-app partition is 4 bytes, but it should be 4 kB.
|
404 | 423 | # Print a warning for now, make it an error in IDF 5.0 (IDF-3742).
|
405 | 424 | if self.type != APP_TYPE and self.offset % STRICT_DATA_ALIGNMENT:
|
406 | 425 | critical('WARNING: Partition %s not aligned to 0x%x.'
|
407 | 426 | 'This is deprecated and will be considered an error in the future release.' % (self.name, STRICT_DATA_ALIGNMENT))
|
408 |
| - if self.size % align and secure and self.type == APP_TYPE: |
409 |
| - raise ValidationError(self, 'Size 0x%x is not aligned to 0x%x' % (self.size, align)) |
410 |
| - if self.size is None: |
411 |
| - raise ValidationError(self, 'Size field is not set') |
| 427 | + if self.type == APP_TYPE and secure is not SECURE_NONE: |
| 428 | + size_align = get_alignment_size_for_type(self.type) |
| 429 | + if self.size % size_align: |
| 430 | + raise ValidationError(self, 'Size 0x%x is not aligned to 0x%x' % (self.size, size_align)) |
412 | 431 |
|
413 | 432 | if self.name in TYPES and TYPES.get(self.name, '') != self.type:
|
414 | 433 | critical("WARNING: Partition has name '%s' which is a partition type, but does not match this partition's "
|
@@ -513,7 +532,7 @@ def main():
|
513 | 532 | 'enabled by default and this flag does nothing.', action='store_true')
|
514 | 533 | parser.add_argument('--quiet', '-q', help="Don't print non-critical status messages to stderr", action='store_true')
|
515 | 534 | parser.add_argument('--offset', '-o', help='Set offset partition table', default='0x8000')
|
516 |
| - parser.add_argument('--secure', help='Require app partitions to be suitable for secure boot', action='store_true') |
| 535 | + parser.add_argument('--secure', help='Require app partitions to be suitable for secure boot', nargs='?', const=SECURE_V1, choices=[SECURE_V1, SECURE_V2]) |
517 | 536 | parser.add_argument('input', help='Path to CSV or binary file to parse.', type=argparse.FileType('rb'))
|
518 | 537 | parser.add_argument('output', help='Path to output converted binary or CSV file. Will use stdout if omitted.',
|
519 | 538 | nargs='?', default='-')
|
|
0 commit comments