[opentitantool] Introduce serializable TransportError

Introducing a serializable TransportError, and convenience
transport::{bail, ensure, Result}, to be used instead of anyhow::Result
on all methods of the Transport trait and its delegate traits.

This change allows propagation of error messages from implementation
of the Transport trait across the proposed proxy protocol to a client
calling a stub implementation of the same Transport trait on another
machine.

Many underlying libraries used by the various structs implementing the
Transport trait use other error enums and anyhow.  A convenience
method is provided to assist in converting such errors into
TransportError.

If a transport implementation previously made a call such as this:
serialport::available_ports()?;

It will now have to be replaced with:
use crate::transport::WrapInTransportError;
serialport::available_ports().wrap(UartError::EnumarationError)?;

This will cause e.g. an Err(io::Error(kind: PermissionDenied)) result
to be converted into Err(TransportError::UartError(EnumerationError,
"Permission denied"), in such a way that it collects the additional
context.  To the end user, the error message will look like this:

UART error: Enumerating: Permission denied

My hope is that in addition to allowing Transport errors to be sent
across RPC calls, the messages will also become more useful to end
users.

It can be debated how deep into the libraries and helper classes used
by Transport implementations methods should be converted to
exclusively use TransportError.

A consequence of this change is that errors must own the data they
carry, that is, any fields of the type `&'static str` will have to be
replaced with `String`, as the remote receiver may not have all the
same strings in its executable.

This marks the first step on issue: #10889

Smaller tangentially related changes also in this CL:
*) Merge hyperdebug/uart.rs and cw310/uart.rs into common/uart.rs,
   as both implementations used the same serialport library.
*) Clarified convention of Uart::read_timeout() such that timeout
   is always indicated by Ok(0), and serious errors with Err(_).

Signed-off-by: Jes B. Klinke <jbk@chromium.org>
Change-Id: I027189d44ee01e2bc83b8baac3f6d968e5586c34
33 files changed
tree: 96ccbd21715edbf75e5b5aa8d83497428e65022c
  1. .github/
  2. ci/
  3. doc/
  4. hw/
  5. rules/
  6. site/
  7. sw/
  8. test/
  9. third_party/
  10. util/
  11. .bazelignore
  12. .bazelrc
  13. .bazelversion
  14. .clang-format
  15. .dockerignore
  16. .flake8
  17. .gitignore
  18. .style.yapf
  19. .svlint.toml
  20. .svls.toml
  21. _index.md
  22. apt-requirements.txt
  23. azure-pipelines.yml
  24. BUILD
  25. check_tool_requirements.core
  26. CLA
  27. COMMITTERS
  28. CONTRIBUTING.md
  29. LICENSE
  30. meson-config.txt
  31. meson.build
  32. meson_init.sh
  33. meson_options.txt
  34. python-requirements.txt
  35. README.md
  36. tool_requirements.py
  37. toolchain.txt
  38. topgen-reg-only.core
  39. topgen.core
  40. WORKSPACE
  41. yum-requirements.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 and our documentation on project organization and processes 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).