Skip to content

Commit 2b58f12

Browse files
gautschimiRazer6
authored andcommitted
[hw/prim] Addition of prim_sdc_example for constraints checking
The module prim_sdc_example has been added to the prim repository. The functionality of this block is irrelevant. It is only needed to run a basic synthesis on a simplified design such that it can be verified that all important synthesis constraints to preserve instances and prevent logic optimization across preserved instances are applied correctly. Signed-off-by: Michael Gautschi <[email protected]>
1 parent b4070d7 commit 2b58f12

File tree

3 files changed

+785
-1
lines changed

3 files changed

+785
-1
lines changed

hw/ip/prim/README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ To create a technology library follow these steps:
247247
`mytech` will be used as a placeholder name in the examples.
248248
2. Create a directory in `hw/ip` with the prefix `prim_` followed by the name of your technology library.
249249
3. Copy `hw/ip/prim_generic/prim_generic.core` into the new directory renaming it to match your primitive library, e.g. `hw/ip/prim_mytech/prim_mytech.core`
250-
Change the vendor and name in this file, e.g. `lowrisc:prim_generic` would become `partner:mytech` where your organisation's name can be used in the place of 'partner'.
250+
Change the vendor and name in this file, e.g. `lowrisc:prim_generic` would become `partner:prim_mytech` where your organisation's name can be used in the place of 'partner'.
251251
Also, edit the description to better describe the specific implementation.
252252
4. For every primitive implemented by your library:
253253
1. Copy across the generic implementation into your library, e.g. `cp hw/ip/prim_generic/rtl/prim_flop.sv hw/ip/prim_mytech/rtl/prim_flop.sv`.
@@ -310,3 +310,59 @@ fusesoc \
310310
--mapping partner:prim_mytech:all \ # Select alternate implementation via mappings
311311
lowrisc:systems:chip_earlgrey_asic
312312
```
313+
### prim_asap7 example
314+
315+
[ASAP7](https://github.com/The-OpenROAD-Project/asap7) is an open-source standard-cell library.
316+
It serves as an example for partners to integrate their own technology specific prim library.
317+
318+
The steps in [creating a tech library](#creating-a-technology-library) were followed to create this prim library.
319+
320+
Each standard-cell instance name is prefixed with a `u_size_only_` such that these instances can be easily identified during synthesis and preserved.
321+
322+
### Important synthesis constraints to keep important redundant constructs
323+
324+
The basic prim instances cannot be removed or merged with other cells through logic optimization or constant propagation as this would remove important security countermeasures from the design.
325+
326+
All instantiated basic gates (`buf`, `mux2`, `inv`, `clock_gating`, `and2`, `xor2`, `xnor2`, `flop`) should be instantiated with a name prefix of `u_size_only_` such that preserve attributes can be set during synthesis.
327+
The syntax to set a preserved attribute varies across tool providers.
328+
To make sure the right constraints are applied, a simple example design (`prim_sdc_example`) is provided.
329+
This design can be synthesized, and its netlist can be analyzed to verify that the correct constraints are applied and all important cells are preserved.
330+
331+
The required files for synthesis can be generated with the following command:
332+
333+
```shell
334+
fusesoc --cores-root . \
335+
run \
336+
--target=syn \
337+
--flag fileset_partner \
338+
--mapping lowrisc:prim_asap7:all \
339+
--setup \
340+
--build-root build lowrisc:prim:sdc_example
341+
```
342+
343+
By setting the `fileset_partner` flag, the generic prim implementation is not used, and the one provided through the mapping argument is used instead.
344+
Please note, on designs with other technology dependent files, the `fileset_partner` flag also selects other technology specific implementations (e.g. OTP, Flash, JTAG, AST, pads).
345+
If those are not used, they can be mapped to the generic implementations.
346+
347+
#### Checks on the generated netlist
348+
349+
After synthesizing the top module `prim_sdc_example` the following checks should be performed on the netlist:
350+
351+
1. In the synthesized netlist, the following number of size_only instances must be present:
352+
353+
| cell names | buf | and2 | xor | xnor | flop | clock_mux2 | clock_gating |
354+
| -----------| ---- |------|----- |------ |------|------------|--------------|
355+
| #instances | 328 | 56 | 120 | 56 | 252 | 2 | 2 |
356+
357+
2. None of the test_*_o signals can be driven by a constant 0 or 1.
358+
The instantiated `size_only` instances must prevent logic optimizations and keep the output comparators.
359+
This can be checked with the synthesis tool, e.g. `check_design -constant`
360+
361+
3. None of the buffers or flip flops in this example design are unloaded if constraints are applied correctly.
362+
This can be checked by the synthesis tool, e.g. `check_design -unloaded_comb/-unloaded_seqs`
363+
364+
4. `lc_en_o`, `mubi_o` signals cannot be driven to a constant value because optimization or constant propagation across preserved instances is not allowed.
365+
366+
5. `lc_en_i`, `mubi_i` signals can only be connected to variables, or legal values (`MuBi4True`, `MuBi4False`, `On`, `Off`)
367+
368+
If all checks are successful, the same constraints can be applied to the full design.

hw/ip/prim/prim_sdc_example.core

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CAPI=2:
2+
# Copyright lowRISC contributors (OpenTitan project).
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
name: "lowrisc:prim:sdc_example"
7+
description: "Example module to verify constraints to keep redundant security features. This module is only used for synthesis"
8+
filesets:
9+
files_rtl:
10+
depend:
11+
- lowrisc:prim:all
12+
- lowrisc:ip:lc_ctrl_pkg
13+
- lowrisc:prim:clock_gating
14+
- lowrisc:prim:lc_sender
15+
- lowrisc:prim:lc_sync
16+
files:
17+
- rtl/prim_sdc_example.sv
18+
file_type: systemVerilogSource
19+
20+
parameters:
21+
SYNTHESIS:
22+
datatype: bool
23+
paramtype: vlogdefine
24+
25+
targets:
26+
default: &default_target
27+
filesets:
28+
- files_rtl
29+
syn:
30+
<<: *default_target
31+
default_tool: icarus
32+
parameters:
33+
- SYNTHESIS=true
34+
toplevel: prim_sdc_example

0 commit comments

Comments
 (0)