Additional alignment checks in TDF validation

This commit is contained in:
Nav
2025-01-28 00:04:24 +00:00
parent 05938ce0ac
commit 3c1916a0c9
2 changed files with 58 additions and 6 deletions

View File

@@ -57,19 +57,66 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
} else { } else {
if ( if (
$mainProgramSegment !== null $mainProgramSegment !== null
&& ($mainProgramSegment->addressRange->startAddress % (int)$programmingBlockSize) !== 0 && !$this->alignsWith($mainProgramSegment->addressRange->startAddress, (int)$programmingBlockSize)
) { ) {
$failures[] = 'Main program memory segment start address does not align with programming block size'; $failures[] = 'Main program memory segment start address does not align with programming block size';
} }
if ( if (
$bootProgramSegment !== null $bootProgramSegment !== null
&& ($bootProgramSegment->addressRange->startAddress % (int)$programmingBlockSize) !== 0 && !$this->alignsWith($bootProgramSegment->addressRange->startAddress, (int)$programmingBlockSize)
) { ) {
$failures[] = 'Boot program memory segment start address does not align with programming block size'; $failures[] = 'Boot program memory segment start address does not align with programming block size';
} }
} }
$wchLinkPartialWriteAlignmentSize = 2;
if ($mainProgramSegment !== null) {
if (
!$this->alignsWith(
$mainProgramSegment->addressRange->startAddress,
$wchLinkPartialWriteAlignmentSize
)
) {
$failures[] = 'Main program memory segment start address does not align with partial write alignment '
. 'size';
}
if (!$this->alignsWith($mainProgramSegment->addressRange->size(), $wchLinkPartialWriteAlignmentSize)) {
$failures[] = 'Main program memory segment size does not align with partial write alignment size';
}
if ($mainProgramSegment->pageSize === null) {
$failures[] = 'Missing page size in main program memory segment';
} elseif (!$this->alignsWith($mainProgramSegment->pageSize, $wchLinkPartialWriteAlignmentSize)) {
$failures[] = 'Main program memory segment page size does not align with partial write alignment size';
}
}
if ($bootProgramSegment !== null) {
if (
!$this->alignsWith(
$bootProgramSegment->addressRange->startAddress,
$wchLinkPartialWriteAlignmentSize
)
) {
$failures[] = 'Boot program memory segment start address does not align with partial write alignment '
. 'size';
}
if (!$this->alignsWith($bootProgramSegment->addressRange->size(), $wchLinkPartialWriteAlignmentSize)) {
$failures[] = 'Boot program memory segment size does not align with partial write alignment size';
}
if ($bootProgramSegment->pageSize === null) {
$failures[] = 'Missing page size in boot program memory segment';
} elseif (!$this->alignsWith($bootProgramSegment->pageSize, $wchLinkPartialWriteAlignmentSize)) {
$failures[] = 'Boot program memory segment page size does not align with partial write alignment size';
}
}
if ($tdf->getProperty('riscv_debug_module', 'trigger_count') === null) { if ($tdf->getProperty('riscv_debug_module', 'trigger_count') === null) {
$failures[] = 'Missing "trigger_count" property'; $failures[] = 'Missing "trigger_count" property';
} }

View File

@@ -358,12 +358,12 @@ class ValidationService
} }
if ($segment->pageSize !== null) { if ($segment->pageSize !== null) {
if (($segment->addressRange->startAddress % $segment->pageSize) !== 0) { if (!$this->alignsWith($segment->addressRange->startAddress, $segment->pageSize)) {
$failures[] = 'Start address is not a multiple of the page size'; $failures[] = 'Start address does not align with the page size';
} }
if ($segment->size() !== null && ($segment->size() % $segment->pageSize) !== 0) { if ($segment->size() !== null && !$this->alignsWith($segment->size(), $segment->pageSize)) {
$failures[] = 'Size (' . $segment->size() . ') is not a multiple of the page size (' $failures[] = 'Size (' . $segment->size() . ') does not align with the page size ('
. $segment->pageSize . ')'; . $segment->pageSize . ')';
} }
} }
@@ -1165,4 +1165,9 @@ class ValidationService
$failures $failures
); );
} }
protected function alignsWith(int $value, int $alignTo): bool
{
return ($value % $alignTo) === 0;
}
} }