diff --git a/build/scripts/Targets/TargetDescriptionFiles/RiscV/Services/ValidationService.php b/build/scripts/Targets/TargetDescriptionFiles/RiscV/Services/ValidationService.php index 1bf4126a..1c2a289c 100644 --- a/build/scripts/Targets/TargetDescriptionFiles/RiscV/Services/ValidationService.php +++ b/build/scripts/Targets/TargetDescriptionFiles/RiscV/Services/ValidationService.php @@ -57,19 +57,66 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat } else { if ( $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'; } if ( $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'; } } + $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) { $failures[] = 'Missing "trigger_count" property'; } diff --git a/build/scripts/Targets/TargetDescriptionFiles/Services/ValidationService.php b/build/scripts/Targets/TargetDescriptionFiles/Services/ValidationService.php index eee5e313..c533a8c7 100644 --- a/build/scripts/Targets/TargetDescriptionFiles/Services/ValidationService.php +++ b/build/scripts/Targets/TargetDescriptionFiles/Services/ValidationService.php @@ -358,12 +358,12 @@ class ValidationService } if ($segment->pageSize !== null) { - if (($segment->addressRange->startAddress % $segment->pageSize) !== 0) { - $failures[] = 'Start address is not a multiple of the page size'; + if (!$this->alignsWith($segment->addressRange->startAddress, $segment->pageSize)) { + $failures[] = 'Start address does not align with the page size'; } - if ($segment->size() !== null && ($segment->size() % $segment->pageSize) !== 0) { - $failures[] = 'Size (' . $segment->size() . ') is not a multiple of the page size (' + if ($segment->size() !== null && !$this->alignsWith($segment->size(), $segment->pageSize)) { + $failures[] = 'Size (' . $segment->size() . ') does not align with the page size (' . $segment->pageSize . ')'; } } @@ -1165,4 +1165,9 @@ class ValidationService $failures ); } + + protected function alignsWith(int $value, int $alignTo): bool + { + return ($value % $alignTo) === 0; + } }