[otbn] Split up JSON dumping/loading in otbn-rig

This is a bit verbose, because we're properly parsing JSON data back
to ProgInsn objects, so have to do various sanity checks on the way to
make sure all the types match up.

The core of the patch is in the otbn-rig script, where we change the
command line to have two subcommands: 'gen' and 'asm'. Running 'gen'
will generate some JSON that describes the snippets in a random
instruction stream. Feeding that JSON to 'asm' generates assembly code
that can be assembled into a binary for testing.

This isn't quite so handy to use if you "just want to generate a darn
asm file!", but it's the shape we're going to use in the future and
running things in two stages like this will spot any silly mistakes in
the JSON parsing.

Here's an example of how to run it to generate a small example:

    hw/ip/otbn/util/otbn-rig gen --size 10 -o tst.json
    hw/ip/otbn/util/otbn-rig asm -o tst tst.json

This example can be assembled and linked with:

    hw/ip/otbn/util/otbn-as tst.S -o tst.o
    hw/ip/otbn/util/otbn-ld -o tst -T tst.ld tst.o

If you just want to see some assembly, the 'gen' phase will print its
JSON to stdout if not given an '-o' argument, the 'asm' phase will
read from stdin if not given a JSON file, and will print just the
assembly to stdout. So you can run:

    hw/ip/otbn/util/otbn-rig gen --size 10 | \
      hw/ip/otbn/util/otbn-rig asm

Of course, this doesn't generate a linker script, so this is only
useful for quick checks. Chaining like this does:

    hw/ip/otbn/util/otbn-rig gen --size 10 | \
      hw/ip/otbn/util/otbn-rig asm -o tst

(but you no longer get to keep the JSON intermediate file).

Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
4 files changed
tree: 387e80e7afc4897c88fb8c0667351b741abd44a3
  1. .github/
  2. ci/
  3. doc/
  4. hw/
  5. site/
  6. sw/
  7. test/
  8. util/
  9. .clang-format
  10. .dockerignore
  11. .flake8
  12. .gitignore
  13. .style.yapf
  14. _index.md
  15. apt-requirements.txt
  16. azure-pipelines.yml
  17. check_tool_requirements.core
  18. CLA
  19. COMMITTERS
  20. CONTRIBUTING.md
  21. LICENSE
  22. meson.build
  23. meson_init.sh
  24. meson_options.txt
  25. python-requirements.txt
  26. README.md
  27. tool_requirements.py
  28. toolchain.txt
README.md

OpenTitan

OpenTitan logo

About the project

OpenTitan is an open source silicon Root of Trust (RoT) project. OpenTitan will make the silicon RoT design and implementation more transparent, trustworthy, and secure for enterprises, platform providers, and chip manufacturers. OpenTitan is administered by lowRISC CIC as a collaborative project to produce high quality, open IP for instantiation as a full-featured product. See the OpenTitan site and OpenTitan docs for more information about the project.

About this repository

This repository contains hardware, software and utilities written as part of the OpenTitan project. It is structured as monolithic repository, or “monorepo”, where all components live in one repository. It exists to enable collaboration across partners participating in the OpenTitan project.

Documentation

The project contains comprehensive documentation of all IPs and tools. You can access it online at docs.opentitan.org.

How to contribute

Have a look at CONTRIBUTING for guidelines on how to contribute code to this repository.

Licensing

Unless otherwise noted, everything in this repository is covered by the Apache License, Version 2.0 (see LICENSE for full text).