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

Added Versat, crypto software implementations and versat implementations as well. Added tests and they all pass #82

Merged
merged 24 commits into from
Mar 4, 2024

Conversation

zettasticks
Copy link
Contributor

There is some warnings when simulating from versat on icarus but nothing serious.

Tests for SHA, AES and McEliece all pass. They only run during fpga-run since they take too long to sim.

default.nix had to change from a simple link to a real file in order to add the "(callPackage ./submodules/VERSAT/versat.nix { })" line.

@jjts
Copy link
Contributor

jjts commented Feb 27, 2024

Is this failing because the MEM_NO_READ_ON_WRITE macro is not being read?

Copy link
Contributor

@P-Miranda P-Miranda left a comment

Choose a reason for hiding this comment

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

  • I added some comments with recomendations/sugestions

  • cyclonev synthesis fails fit step

Comment on lines 1 to 9

#Lines below were auto generated by iob_soc_utils.py
UTARGETS+=iob_eth_rmac.h
EMUL_HDR+=iob_eth_rmac.h
iob_eth_rmac.h:
echo "#define ETH_RMAC_ADDR 0x$(RMAC_ADDR)" > $@

CONSOLE_CMD ?=rm -f soc2cnsl cnsl2soc; $(IOB_CONSOLE_PYTHON_ENV) $(PYTHON_DIR)/console_ethernet.py -L -c $(PYTHON_DIR)/console.py -m "$(RMAC_ADDR)"

Copy link
Contributor

Choose a reason for hiding this comment

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

as stated in the comment:
these lines are added automatically by iob_soc_utils.py script during setup if
iob_soc_opencryptolinux.conf has USE_ETHERNET

so we can discard this addition

Suggested change
#Lines below were auto generated by iob_soc_utils.py
UTARGETS+=iob_eth_rmac.h
EMUL_HDR+=iob_eth_rmac.h
iob_eth_rmac.h:
echo "#define ETH_RMAC_ADDR 0x$(RMAC_ADDR)" > $@
CONSOLE_CMD ?=rm -f soc2cnsl cnsl2soc; $(IOB_CONSOLE_PYTHON_ENV) $(PYTHON_DIR)/console_ethernet.py -L -c $(PYTHON_DIR)/console.py -m "$(RMAC_ADDR)"

Comment on lines 25 to 28
VERSAT_SPEC = "versatSpec.txt"
VERSAT_EXTRA_UNITS = os.path.realpath(
os.path.join(os.path.dirname(__file__), "hardware/src/units")
)
Copy link
Contributor

Choose a reason for hiding this comment

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

why set global variables that are only used once?

Suggested change
VERSAT_SPEC = "versatSpec.txt"
VERSAT_EXTRA_UNITS = os.path.realpath(
os.path.join(os.path.dirname(__file__), "hardware/src/units")
)

@@ -86,6 +98,11 @@ def _create_instances(cls):
@classmethod
def _create_submodules_list(cls, extra_submodules=[]):
"""Create submodules list with dependencies of this module"""

Copy link
Contributor

Choose a reason for hiding this comment

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

set variables here:

Suggested change
VERSAT_SPEC = "versatSpec.txt"
VERSAT_EXTRA_UNITS = os.path.realpath(
os.path.join(os.path.dirname(__file__), "hardware/src/units")
)

Comment on lines 142 to 145
# OpenCrypts testcases
shutil.copytree(
f"{cls.setup_dir}/tests", f"{cls.build_dir}/tests", dirs_exist_ok=True
)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just place tests under ./software/src/tests and they are automatically copied to BUILD_DIR?

or add to ./software/versat/tests and add versatSpec.txt to ./software/versat/versatSpec.txt for versat-specific files

Comment on lines 84 to 89
# NOTE(Ruben): To speed up simulation, the following files can be commented out to greatly reduce filesize from around ~120Kb to ~20Kb.
IOB_SOC_OPENCRYPTOLINUX_FW_SRC+=src/versat_crypto.c
IOB_SOC_OPENCRYPTOLINUX_FW_SRC+=src/versat_crypto_tests.c
IOB_SOC_OPENCRYPTOLINUX_FW_SRC+=src/crypto/aes.c
IOB_SOC_OPENCRYPTOLINUX_FW_SRC+=$(wildcard src/crypto/McEliece/*.c)
IOB_SOC_OPENCRYPTOLINUX_FW_SRC+=$(wildcard src/crypto/McEliece/common/*.c)
Copy link
Contributor

@P-Miranda P-Miranda Feb 27, 2024

Choose a reason for hiding this comment

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

sugestion: add only to sw_build.mk if we are using versat? Use a setup like USE_ETHERNET?
or skip sources for simulation flows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did everything except this part. How do I approach this in the correct python setup approach? I do not see any variable inside the Makefile that indicates we are simulating vs running fpga. Also do not see any direct way of telling on the python side, so cannot conditionally insert the lines in sw_build because cannot know if doing setup to sim or doing setup to run fpga.

Copy link
Contributor

Choose a reason for hiding this comment

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

An ideal solution would be to remove unused code from compilation.
After some search, it seems that adding the compilation and linking flags: -fdata-sections -ffunction-sections -Wl,--gc-sections would remove unused functions.
But it yields an elf without sections:

riscv64-unknown-elf-objcopy: error: the input file 'iob_soc_opencryptolinux_boot.elf' has no sections

I think we should just keep this as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

sugestion: add only to sw_build.mk if we are using versat? Use a setup like USE_ETHERNET? or skip sources for simulation flows

I've added a way to skip sources for simulation in a suggestion below, but I have not tried to run it, so it may break compilation if the firmware requires those functions to be present.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: new commit not present in upstream repository.
PR iob-versat changes to iobundle/iob-versat

@zettasticks
Copy link
Contributor Author

Checks are failing because the timeout for cyclonev was too low, with Versat compilation takes more time and CycloneV was timing out in the middle of running Linux. Baremetal check was working in previous commit.

Copy link
Contributor

@arturum1 arturum1 left a comment

Choose a reason for hiding this comment

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

Changes seem good. I have not reviewed crypto-related software code.

However, I've added a suggestion for a better implementation of the default.nix file.

I also included some suggestions about preventing inclusion of sources in the sw_build.mk file during simulation.

default.nix Outdated Show resolved Hide resolved
software/sw_build.mk Show resolved Hide resolved
@@ -63,14 +64,23 @@ TEMPLATE_LDS=src/[email protected]

IOB_SOC_OPENCRYPTOLINUX_CFLAGS ?=-Os -nostdlib -march=rv32imac -mabi=ilp32 --specs=nano.specs -Wcast-align=strict

IOB_SOC_OPENCRYPTOLINUX_INCLUDES=-I. -Isrc
IOB_SOC_OPENCRYPTOLINUX_INCLUDES=-I. -Isrc -Isrc/crypto/McEliece -Isrc/crypto/McEliece/common
Copy link
Contributor

Choose a reason for hiding this comment

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

We can include some sources only if running on the FPGA:

Suggested change
IOB_SOC_OPENCRYPTOLINUX_INCLUDES=-I. -Isrc -Isrc/crypto/McEliece -Isrc/crypto/McEliece/common
IOB_SOC_OPENCRYPTOLINUX_INCLUDES=-I. -Isrc
ifneq ($(SIMULATION),1)
IOB_SOC_OPENCRYPTOLINUX_INCLUDES+=-Isrc/crypto/McEliece -Isrc/crypto/McEliece/common
endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not do this because the includes in gcc is for header lookups and stuff. None of which actually adds code so it's not a problem if they get added regardless.

software/sw_build.mk Outdated Show resolved Hide resolved
@jjts jjts merged commit 4bbab72 into IObundle:master Mar 4, 2024
5 checks passed
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.

4 participants