Skip to content

Commit

Permalink
feat: add libdriver
Browse files Browse the repository at this point in the history
mock: components can be compiled natively:
1. make mock tests

ioctl: require the cartesi headers and a riscv compiler:
1. Build or download a compatible kernel and `.deb` headers
2. Setup a cross compilation debian environment by running the setup[1]
   script.
3. `make ioctl CROSS_COMPILE=riscv64-linux-gnu-`

[1] setup.sh
```
apt update && \
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends --allow-downgrades -y \
  bc \
  bison \
  build-essential \
  flex \
  genext2fs \
  rsync \
  gcc-riscv64-linux-gnu \
  libc6-dev-riscv64-cross \
  ./linux-libc-dev-riscv64-cross-6.5.9-ctsi-1-v0.0.0.deb
```
  • Loading branch information
mpolitzer committed Nov 10, 2023
1 parent 063d6d3 commit efc8b50
Show file tree
Hide file tree
Showing 44 changed files with 5,886 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ RUN cd ${BUILD_BASE}twuewand/rndaddentropy/ && \
# copy tools
COPY linux/ ${BUILD_BASE}tools/linux/

# build C/C++ libs
# ------------------------------------------------------------------------------
RUN make -C ${BUILD_BASE}tools/linux/libdriver/ CROSS_COMPILE=""

# build C/C++ tools
# ------------------------------------------------------------------------------
RUN make -C ${BUILD_BASE}tools/linux/xhalt/ CROSS_COMPILE="" xhalt.toolchain
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ MACHINE_EMULATOR_TOOLS_TAR_GZ := machine-emulator-tools-$(MACHINE_EMULATOR_TOOL
MACHINE_EMULATOR_TOOLS_DEB := machine-emulator-tools-$(MACHINE_EMULATOR_TOOLS_VERSION).deb
MACHINE_EMULATOR_TOOLS_IMAGE := cartesi/machine-emulator-tools:$(MACHINE_EMULATOR_TOOLS_VERSION)

LINUX_SOURCES_VERSION ?= 5.15.63-ctsi-2
LINUX_SOURCES_FILEPATH := dep/linux-$(LINUX_SOURCES_VERSION).tar.gz
LINUX_SOURCES_URLPATH := https://github.com/cartesi/linux/archive/refs/tags/v$(LINUX_SOURCES_VERSION).tar.gz
LINUX_SOURCES_VERSION ?= rollup-rework
LINUX_SOURCES_FILEPATH := dep/$(LINUX_SOURCES_VERSION).tar.gz
LINUX_SOURCES_URLPATH := https://github.com/cartesi/linux/archive/refs/heads/feature/$(LINUX_SOURCES_VERSION).tar.gz

RNDADDENTROPY_VERSION ?= 3.0.0
RNDADDENTROPY_FILEPATH := dep/twuewand-$(RNDADDENTROPY_VERSION).tar.gz
Expand Down
5 changes: 3 additions & 2 deletions linux/htif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ RVCXX = $(CROSS_COMPILE)g++
RVCOPY = $(CROSS_COMPILE)objcopy
RVDUMP = $(CROSS_COMPILE)objdump
STRIP = $(CROSS_COMPILE)strip
RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)
CFLAGS := -O2 -Wall -pedantic -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -I../libdriver/ioctl
LDLIBS := -L../libdriver -ldriver

CONTAINER_MAKE := /usr/bin/make
CONTAINER_BASE := /opt/cartesi/tools
Expand All @@ -42,7 +43,7 @@ extra.ext2: yield
$(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain"

yield.toolchain:
$(RVCC) -O2 -o yield yield.c
$(RVCC) $(CFLAGS) -o yield yield.c $(LDLIBS)
$(STRIP) yield

extra.ext2.toolchain:
Expand Down
103 changes: 103 additions & 0 deletions linux/libdriver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
CFLAGS := -O2 -g -Wall -pedantic

#all: mock tests
#mock: libmock.a $(mock_BINS)
#ioctl: libioctl.a $(ioctl_BINS)
#tests: tests/abi tests/keccak tests/merkle
#tools: tools/merkle-zero-table tools/funsel

help:
@echo "Cleaning targets:"
@echo " clean - remove the binaries and objects."
@echo " mock - build a reference mock library and examples for running in host mode."
@echo " ioctl - build the actual ioctl library and examples."
@echo " tools - build additional utilities for development."
@echo " with CROSS_COMPILE="

mock: libmock.a mock/yield mock/rollup-driver mock/rollup
ioctl: libioctl.a ioctl/yield ioctl/rollup-driver ioctl/rollup
tests: tests/abi tests/keccak tests/merkle
tests/abi
tests/keccak
tests/merkle

base_SRC := \
base/buf.c \
base/abi.c \
base/keccak.c \
base/merkle.c \
base/rollup.c

libmock_SRC := \
mock/rollup-driver.c \
mock/yield-driver.c \
$(base_SRC)

libioctl_SRC := \
ioctl/rollup-driver.c \
ioctl/yield-driver.c \
$(base_SRC)

libmock_OBJDIR := build/libmock/
libioctl_OBJDIR := build/libioctl/

libmock_OBJ := $(patsubst %.c,$(libmock_OBJDIR)%.o,$(libmock_SRC))
libioctl_OBJ := $(patsubst %.c,$(libioctl_OBJDIR)%.o,$(libioctl_SRC))

OBJ := $(libmock_OBJ) $(libioctl_OBJ)

$(libmock_OBJ): $(libmock_OBJDIR)%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -Imock -MT $@ -MMD -MP -MF $(@:.o=.d) -c -o $@ $<

$(libioctl_OBJ): $(libioctl_OBJDIR)%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -Iioctl -MT $@ -MMD -MP -MF $(@:.o=.d) -c -o $@ $<

libmock.a: $(libmock_OBJ)
$(AR) rcs $@ $^

libioctl.a: $(libioctl_OBJ)
$(AR) rcs $@ $^

ioctl/yield-driver: examples/yield-driver.c libioctl.a
$(CC) $(CFLAGS) -Iioctl -o $@ $^
ioctl/merkle: examples/merkle.c libmock.a
$(CC) $(CFLAGS) -Iioctl -o $@ $^
ioctl/rollup-driver: examples/rollup-driver.c libioctl.a
$(CC) $(CFLAGS) -Iioctl -o $@ $^

mock/yield-driver: examples/yield-driver.c libmock.a
$(CC) $(CFLAGS) -Imock -o $@ $^
mock/rollup-driver: examples/rollup-driver.c libmock.a
$(CC) $(CFLAGS) -Imock -o $@ $^
mock/rollup: examples/rollup.c libmock.a
$(CC) $(CFLAGS) -Imock -o $@ $^

tests/abi: tests/abi.c libmock.a
$(CC) $(CFLAGS) -Imock -o $@ $^
tests/keccak: tests/keccak.c libmock.a
$(CC) $(CFLAGS) -Imock -o $@ $^
tests/merkle: tests/merkle.c libmock.a
$(CC) $(CFLAGS) -Imock -o $@ $^

tools/merkle-zero-table: tools/merkle-zero-table.c base/keccak.o
$(CC) $(CFLAGS) -Imock -o $@ $^
tools/funsel: tools/funsel.c base/keccak.o
$(CC) $(CFLAGS) -Imock -o $@ $^

doc: doc/theme
doxygen doc/Doxyfile
doc/theme:
git clone --depth=1 --branch=v2.2.1 \
[email protected]:jothepro/doxygen-awesome-css.git $@
clean:
rm -f libmock.a $(mock_BINS) libioctl.a $(ioctl_BINS) $(OBJ) $(OBJ:%.o=%.d)
rm -rf doc/html
distclean:
rm -rf doc/theme
.PHONY: doc

-include $(OBJ:%.o=%.d)
16 changes: 16 additions & 0 deletions linux/libdriver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Utility functions for rollup interaction.

- @ref libevm\_rollup
- @ref libevm\_abi
- @ref libevm\_buf
- @ref libevm\_keccak
- @ref libevm\_merkle

Thin wrappers to the cartesi kernel drivers

- @ref rollup\_driver
- @ref yield\_driver

# Getting Started

Download the static library from [cartesi tools](https://github.com/cartesi/machine-emulator-tools/).
Loading

0 comments on commit efc8b50

Please sign in to comment.