Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ChipWhisperer CW310 #47

Merged
merged 4 commits into from
Aug 5, 2021
Merged

Enable ChipWhisperer CW310 #47

merged 4 commits into from
Aug 5, 2021

Conversation

vogelpi
Copy link
Collaborator

@vogelpi vogelpi commented Jul 22, 2021

This PR contains the required changes to enable SCA for OpenTitan on the ChipWhisperer CW310 FPGA board. The most notable changes are:

  • Capture related parameters that need to be changed frequently (based on board and bitstream) like scope gain and number of samples we want to capture are moved to the yaml config file. Previously, we had them hardcoded in the sources.
  • spiflash.py is replaced by the version from the OpenTitan repo. This version also supports both the CW305 and CW310 and contains some bugfixes. It is now vendored into ot-sca using the OpenTitan vendor tool.
  • Enable support for the CW310. Currently we detect the board version based on the selected bitstream inside the yaml config file. Under the hood, the ChipWhisperer API uses the CW305 class for the CW310. This allows to reuse most of the code for the CW305. What currently doesn't work is the feature to detect if the bitstream had already been programmed. This is not dramatic but since the FPGA is much larger, loading the bitstream takes around 15 seconds which is not so nice.

I've tested these changes both on the CW305 (using the bitstreams and binaries in the tree) and the CW310. I will push a PR hopefully tomorrow to make the necessary changes in OpenTitan.

Below you can see two plots of 200 AES traces with DOM masking. Top is the CW310, bottom is the CW305. It doesn't look too bad here but when considering more traces, one sees that there is massive "background" activity that completely buries the AES traces. There will be some work needed to reduce the background noise. Disabling the entropy complex already helped a bit.

cw310
cw305

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
The scope gain and number of samples per trace often needs to be changed
together with the bitstream/firmware. It's better to have all the
corresponding knobs in the same config file.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
Copy link
Contributor

@alphan alphan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vogelpi. Just some nits.

cw/cw305/vendor/lowrisc_opentitan_util.vendor.hjson Outdated Show resolved Hide resolved
force_programming = False
print('Connecting and loading FPGA... ', end='')
if board == 'CW310':
fpga = cw.target(None, cw.capture.targets.CW310, slurp=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What currently doesn't work is the feature to detect if the bitstream had already been programmed. This is not dramatic but since the FPGA is much larger, loading the bitstream takes around 15 seconds which is not so nice.

Could you try if fpga = cw.capture.targets.CW310() works and can you add a comment if it doesn't?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it doesn't work either. Created an issue here #48. But I've switched to fpga = cw.capture.targets.CW310().

Comment on lines 24 to 27
if re.search('cw310', device_cfg['fpga_bitstream']):
board = 'CW310'
else:
board = 'CW305'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think board should ideally be an enum, can you add a TODO for that?

Also:

Suggested change
if re.search('cw310', device_cfg['fpga_bitstream']):
board = 'CW310'
else:
board = 'CW305'
m = re.search('cw305|cw310', device_cfg['fpga_bitstream'])
if m:
if m.group() == 'cw305':
board = 'CW305'
else:
assert m.group() == 'cw310'
board = 'CW310'
else:
raise ValueError('Could not infer target board type from bitstream name')

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue, and switched to your suggested code. Thanks for your review @alphan !

The version from OpenTitan contains some bug fixes, is lint clean and
most importantly also supports the ChipWhisperer CW310 FPGA board.

Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
@vogelpi vogelpi merged commit 50756a6 into lowRISC:master Aug 5, 2021
@vogelpi vogelpi deleted the cw310-enable branch August 5, 2021 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants