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:
ioctl: require the cartesi headers and a riscv compiler:
  • Loading branch information
mpolitzer committed Dec 6, 2023
1 parent 132cfe4 commit 45510a1
Show file tree
Hide file tree
Showing 46 changed files with 6,501 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ RUN mkdir -p ${BUILD_BASE}linux-sources && \
# 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
8 changes: 8 additions & 0 deletions linux/libcmt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build/
doc/theme
doc/html
*.o
*.d

tools/funsel
tools/merkle-table
179 changes: 179 additions & 0 deletions linux/libcmt/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# paths
PREFIX = /usr
TARGET_PREFIX ?= $(PREFIX)

TARGET_CC := $(CROSS_COMPILE)gcc
TARGET_AR := $(CROSS_COMPILE)ar
TARGET_CFLAGS := -Wvla -O2 -g -Wall -pedantic -Wextra -Iinclude -Iinclude/libcmt/ioctl
CFLAGS := -Wvla -O2 -g -Wall -pedantic -Wextra -fsanitize=address,undefined -Iinclude -Iinclude/libcmt/mock

mock_BINS := build/libcmt_mock/yield-driver \
build/libcmt_mock/rollup-driver \
build/libcmt_mock/rollup \
build/libcmt_mock/merkle-state \
libcmt_mock.a

ioctl_BINS := build/libcmt/yield-driver \
build/libcmt/rollup-driver \
build/libcmt/rollup \
libcmt.a

tests_BINS := build/libcmt_mock/abi \
build/libcmt_mock/keccak \
build/libcmt_mock/merkle

tools_BINS := tools/funsel \
tools/merkle-table

all: mock.build ioctl.build tools.build examples.build
help:
@echo "Cleaning targets: (default: '*')"
@echo " clean - remove the binaries and objects."
@echo "* mock.build - build the reference mock library and examples for running in host mode."
@echo " mock.install - install the reference mock library."
@echo "* ioctl.build - build the riscv ioctl library and examples."
@echo " (needs the cartesi linux headers. accepts the 'CROSS_COMPILE=' variable)"
@echo " ioctl.install - install the riscv ioctl library."
@echo " tests.build - build host mode tests."
@echo " tests.run - run host mode tests."
@echo "* tools.build - development tools and utilities."
@echo " doc.build - build the doxygen documentation."
@echo " examples.build - build the documentation code."

base_SRC := \
src/buf.c \
src/abi.c \
src/keccak.c \
src/merkle.c \
src/rollup.c \
src/merkle-table.c

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

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

examples_SRC := \
examples/abi_decode_000.c \
examples/abi_decode_001.c \
examples/abi_encode_000.c \
examples/abi_encode_001.c \
examples/abi_encode_002.c \
examples/abi_get.c \
examples/abi_multi.c \
examples/rollup-driver.c \
examples/rollup.c \
examples/yield-driver.c

libcmt_mock_OBJDIR := build/libcmt_mock/
libcmt_OBJDIR := build/libcmt/
examples_OBJDIR := build/examples/

libcmt_mock_OBJ := $(patsubst %.c,$(libcmt_mock_OBJDIR)%.o,$(libcmt_mock_SRC))
libcmt_OBJ := $(patsubst %.c,$(libcmt_OBJDIR)%.o,$(libcmt_SRC))
examples_OBJ := $(patsubst %.c,$(examples_OBJDIR)%.o,$(examples_SRC))

OBJ := $(libcmt_mock_OBJ) $(libcmt_OBJ) $(examples_OBJ)

mock.build: libcmt_mock.a $(mock_BINS)
ioctl.build: libcmt.a $(ioctl_BINS)
tests.build: $(tests_BINS)
tools.build: $(tools_BINS)
tests.run: tests.build
$(foreach test,$(tests_BINS),$(test) &&) true
examples.build: $(examples_OBJ)

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

$(libcmt_OBJ): $(libcmt_OBJDIR)%.o: %.c
@mkdir -p $(@D)
$(TARGET_CC) $(TARGET_CFLAGS) -MT $@ -MMD -MP -MF $(@:.o=.d) -c -o $@ $<

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

libcmt_mock.a: $(libcmt_mock_OBJ)
$(AR) rcs $@ $^

libcmt.a: $(libcmt_OBJ)
$(TARGET_AR) rcs $@ $^

build/libcmt/yield-driver: examples/yield-driver.c libcmt.a
$(TARGET_CC) $(TARGET_CFLAGS) -o $@ $^
build/libcmt/rollup-driver: examples/rollup-driver.c libcmt.a
$(TARGET_CC) $(TARGET_CFLAGS) -o $@ $^
build/libcmt/rollup: examples/rollup.c libcmt.a
$(TARGET_CC) $(TARGET_CFLAGS) -o $@ $^

build/libcmt_mock/yield-driver: examples/yield-driver.c libcmt_mock.a
$(CC) $(CFLAGS) -o $@ $^
build/libcmt_mock/rollup-driver: examples/rollup-driver.c libcmt_mock.a
$(CC) $(CFLAGS) -o $@ $^
build/libcmt_mock/rollup: examples/rollup.c libcmt_mock.a
$(CC) $(CFLAGS) -o $@ $^
build/libcmt_mock/merkle-state: examples/merkle-state.c libcmt_mock.a
$(CC) $(CFLAGS) -o $@ $^

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

src/merkle.c: src/merkle-table.c
src/merkle-table.c: tools/merkle-table
$< > $@

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

doc/theme:
git clone [email protected]:jothepro/doxygen-awesome-css.git $@
git -C doc/theme checkout 8cea9a073ecd50a5b2c0958a3df100292d6c7374

doc.build: examples.build doc/theme
doxygen doc/Doxyfile

ioctl.install: libcmt.a
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
cp -f $< $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
cp -f include/libcmt/*.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
cp -f include/libcmt/ioctl/*.h $(TARGET_DESTDIR)$(TARGET_PREFIX)/include/libcmt/
mkdir -p $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig
sed 's|ARG_PREFIX|$(TARGET_PREFIX)|g' tools/templates/libcmt.pc \
> $(TARGET_DESTDIR)$(TARGET_PREFIX)/lib/pkgconfig/libcmt.pc

mock.install: libcmt_mock.a
mkdir -p $(DESTDIR)$(PREFIX)/lib
cp -f $< $(DESTDIR)$(PREFIX)/lib
mkdir -p $(DESTDIR)$(PREFIX)/include/libcmt/mock
cp -f include/libcmt/*.h $(DESTDIR)$(PREFIX)/include/libcmt/
cp -f include/libcmt/mock/*.h $(DESTDIR)$(PREFIX)/include/libcmt/mock/
mkdir -p $(DESTDIR)$(PREFIX)/lib/pkgconfig
sed 's|ARG_PREFIX|$(PREFIX)|g' tools/templates/libcmt_mock.pc \
> $(DESTDIR)$(PREFIX)/lib/pkgconfig/libcmt_mock.pc

doc.install: doc.build
mkdir -p $(DESTDIR)$(PREFIX)/share/libcmt/html
cp -f doc/html $(DESTDIR)$(PREFIX)/share/libcmt/html

clean:
rm -f $(mock_BINS) $(ioctl_BINS) $(tests_BINS) $(tools_BINS) $(OBJ) $(OBJ:%.o=%.d)
rm -rf doc/html
distclean:
rm -rf doc/theme
.PHONY: examples.build doc

-include $(OBJ:%.o=%.d)
19 changes: 19 additions & 0 deletions linux/libcmt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
High level rollup API

- @ref libcmt\_rollup

Utility functions for rollup interaction.

- @ref libcmt\_abi
- @ref libcmt\_buf
- @ref libcmt\_keccak
- @ref libcmt\_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 45510a1

Please sign in to comment.