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

libcmt io hook #35

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
push: false
load: true
build-args: |
CMT_TAR_GZ=${{ env.CMT_TAR_GZ }}
TOOLS_DEB=${{ env.TOOLS_DEB }}
IMAGE_KERNEL_VERSION=${{ env.IMAGE_KERNEL_VERSION }}
LINUX_VERSION=${{ env.LINUX_VERSION }}
Expand Down Expand Up @@ -87,6 +88,7 @@ jobs:
run: |
sha512sum ${{ env.TOOLS_DEB }} > ${{ env.TOOLS_DEB }}.sha512
sha512sum ${{ env.TOOLS_ROOTFS }} > ${{ env.TOOLS_ROOTFS }}.sha512
sha512sum ${{ env.CMT_TAR_GZ }} > ${{ env.CMT_TAR_GZ }}.sha512

- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -97,6 +99,8 @@ jobs:
${{ env.TOOLS_DEB }}.sha512
${{ env.TOOLS_ROOTFS }}
${{ env.TOOLS_ROOTFS }}.sha512
${{ env.CMT_TAR_GZ }}
${{ env.CMT_TAR_GZ }}.sha512

test-rollup-http-server:
runs-on: ubuntu-22.04
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.15.0] - 2024-02-16
### Changed
- Updated linux-sources to v5.6.9-ctsi-2-output-unification-test1
- Added a value field to vouchers
- Tools are now implemented in terms of libcmt
- Added libcmt

## [0.14.1] - 2023-12-18
### Fixed
Expand Down Expand Up @@ -131,7 +137,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [0.2.0]
- [0.1.0]

[Unreleased]: https://github.com/cartesi/machine-emulator-tools/compare/v0.14.1...HEAD
[Unreleased]: https://github.com/cartesi/machine-emulator-tools/compare/v0.15.0...HEAD
[0.15.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.15.0
[0.14.1]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.14.1
[0.14.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.14.0
[0.13.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.13.0
Expand Down
142 changes: 84 additions & 58 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

FROM ubuntu:22.04 as tools-env
ARG IMAGE_KERNEL_VERSION=v0.19.1
ARG LINUX_VERSION=6.5.9-ctsi-1
ARG LINUX_VERSION=6.5.9-ctsi-2-output-unification-test1
ARG LINUX_HEADERS_URLPATH=https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb
ARG BUILD_BASE=/opt/cartesi

Expand All @@ -31,83 +31,107 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
ca-certificates \
git \
wget \
pkg-config \
crossbuild-essential-riscv64 \
gcc-12-riscv64-linux-gnu \
g++-12-riscv64-linux-gnu \
&& \
wget -O ${LINUX_HEADERS_FILEPATH} ${LINUX_HEADERS_URLPATH} && \
echo "efdb2243d9b6828e90c826be0f178110f0cc590cb00e8fa588cb20723126c2a4 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check && \
echo "4ef81562b1d85220bde9fd4ff01d149469a500f22cc319a02c32bfd1c0698ae1 ${LINUX_HEADERS_FILEPATH}" | sha256sum --check && \
apt-get install -y --no-install-recommends ${LINUX_HEADERS_FILEPATH} && \
adduser developer -u 499 --gecos ",,," --disabled-password && \
mkdir -p ${BUILD_BASE}/tools && chown -R developer:developer ${BUILD_BASE}/tools && \
rm -rf /var/lib/apt/lists/* ${LINUX_HEADERS_FILEPATH}

# Setup latest cross compiler as default
# ------------------------------------------------------------------------------
RUN <<EOF
for tool in cpp g++ gcc gcc-ar gcc-nm gcc-ranlib gcov gcov-dump gcov-tool; do
for version in 12; do
update-alternatives --install \
/usr/bin/riscv64-linux-gnu-$tool riscv64-linux-gnu-$tool \
/usr/bin/riscv64-linux-gnu-$tool-$version $version
done
done
EOF

ENV RISCV_ARCH="rv64gc"
ENV RISCV_ABI="lp64d"
ENV CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI"
ENV TOOLCHAIN_PREFIX="riscv64-linux-gnu-"
ENV TOOLCHAIN_SUFFIX="-12"

FROM tools-env as builder
COPY --chown=developer:developer sys-utils/ ${BUILD_BASE}/tools/sys-utils/

# build C/C++ tools
# ------------------------------------------------------------------------------
FROM builder as c-builder
USER developer
RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all

# build rust tools
# ------------------------------------------------------------------------------
FROM tools-env as rust-env
ENV PATH="/home/developer/.cargo/bin:${PATH}"
ARG CMT_BASE=${BUILD_BASE}/tools/sys-utils/libcmt
ARG CMT_TAR_GZ=libcmt-v0.14.1-dev.tar.gz
ARG BUILD_BASE=/opt/cartesi

USER developer
RUN make -C ${CMT_BASE} -j$(nproc) ioctl.build mock.build
USER root
RUN make -C ${CMT_BASE} -j$(nproc) ioctl.install \
TARGET_PREFIX=${CMT_BASE}/install && \
tar czf ${BUILD_BASE}/${CMT_TAR_GZ} -C ${CMT_BASE}/install .
RUN make -C ${BUILD_BASE}/tools/sys-utils/libcmt/ -j$(nproc) ioctl.install mock.install \
PREFIX=/usr/x86_64-linux-gnu TARGET_PREFIX=/usr/riscv64-linux-gnu
USER developer
RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all

RUN cd && \
wget https://github.com/rust-lang/rustup/archive/refs/tags/1.26.0.tar.gz && \
echo "6f20ff98f2f1dbde6886f8d133fe0d7aed24bc76c670ea1fca18eb33baadd808 1.26.0.tar.gz" | sha256sum --check && \
tar -xzf 1.26.0.tar.gz && \
bash rustup-1.26.0/rustup-init.sh \
-y \
--default-toolchain 1.74.0 \
--profile minimal \
--target riscv64gc-unknown-linux-gnu && \
rm -rf rustup-1.26.0 1.26.0.tar.gz

FROM rust-env as rust-builder
COPY --chown=developer:developer rollup-http/rollup-init ${BUILD_BASE}/tools/rollup-http/rollup-init
COPY --chown=developer:developer rollup-http/rollup-http-client ${BUILD_BASE}/tools/rollup-http/rollup-http-client
COPY --chown=developer:developer rollup-http/.cargo ${BUILD_BASE}/tools/rollup-http/.cargo

# build rollup-http-server dependencies
FROM rust-builder as http-server-dep-builder
COPY --chown=developer:developer rollup-http/rollup-http-server/Cargo.toml rollup-http/rollup-http-server/Cargo.lock ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && \
mkdir src/ && \
echo "fn main() {}" > src/main.rs && \
echo "pub fn dummy() {}" > src/lib.rs && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build rollup-http-server
FROM http-server-dep-builder as http-server-builder
COPY --chown=developer:developer rollup-http/rollup-http-server/build.rs ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
COPY --chown=developer:developer rollup-http/rollup-http-server/src ${BUILD_BASE}/tools/rollup-http/rollup-http-server/src
RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && touch build.rs src/* && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build echo-dapp dependencies
FROM rust-builder as echo-dapp-dep-builder
COPY --chown=developer:developer rollup-http/echo-dapp/Cargo.toml rollup-http/echo-dapp/Cargo.lock ${BUILD_BASE}/tools/rollup-http/echo-dapp/
RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && \
mkdir src/ && echo "fn main() {}" > src/main.rs && \
cargo build --target riscv64gc-unknown-linux-gnu --release

# build echo-dapp
FROM echo-dapp-dep-builder as echo-dapp-builder
COPY --chown=developer:developer rollup-http/echo-dapp/src ${BUILD_BASE}/tools/rollup-http/echo-dapp/src
RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && touch src/* && \
cargo build --target riscv64gc-unknown-linux-gnu --release
## build rust tools
## ------------------------------------------------------------------------------
#FROM tools-env as rust-env
#ENV PATH="/home/developer/.cargo/bin:${PATH}"
#
#USER developer
#
#RUN cd && \
# wget https://github.com/rust-lang/rustup/archive/refs/tags/1.26.0.tar.gz && \
# echo "6f20ff98f2f1dbde6886f8d133fe0d7aed24bc76c670ea1fca18eb33baadd808 1.26.0.tar.gz" | sha256sum --check && \
# tar -xzf 1.26.0.tar.gz && \
# bash rustup-1.26.0/rustup-init.sh \
# -y \
# --default-toolchain 1.74.0 \
# --profile minimal \
# --target riscv64gc-unknown-linux-gnu && \
# rm -rf rustup-1.26.0 1.26.0.tar.gz
#
#FROM rust-env as rust-builder
#COPY --chown=developer:developer rollup-http/rollup-init ${BUILD_BASE}/tools/rollup-http/rollup-init
#COPY --chown=developer:developer rollup-http/rollup-http-client ${BUILD_BASE}/tools/rollup-http/rollup-http-client
#COPY --chown=developer:developer rollup-http/.cargo ${BUILD_BASE}/tools/rollup-http/.cargo
#
## build rollup-http-server dependencies
#FROM rust-builder as http-server-dep-builder
#COPY --chown=developer:developer rollup-http/rollup-http-server/Cargo.toml rollup-http/rollup-http-server/Cargo.lock ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
#RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && \
# mkdir src/ && \
# echo "fn main() {}" > src/main.rs && \
# echo "pub fn dummy() {}" > src/lib.rs && \
# cargo build --target riscv64gc-unknown-linux-gnu --release
#
## build rollup-http-server
#FROM http-server-dep-builder as http-server-builder
#COPY --chown=developer:developer rollup-http/rollup-http-server/build.rs ${BUILD_BASE}/tools/rollup-http/rollup-http-server/
#COPY --chown=developer:developer rollup-http/rollup-http-server/src ${BUILD_BASE}/tools/rollup-http/rollup-http-server/src
#RUN cd ${BUILD_BASE}/tools/rollup-http/rollup-http-server && touch build.rs src/* && \
# cargo build --target riscv64gc-unknown-linux-gnu --release
#
## build echo-dapp dependencies
#FROM rust-builder as echo-dapp-dep-builder
#COPY --chown=developer:developer rollup-http/echo-dapp/Cargo.toml rollup-http/echo-dapp/Cargo.lock ${BUILD_BASE}/tools/rollup-http/echo-dapp/
#RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && \
# mkdir src/ && echo "fn main() {}" > src/main.rs && \
# cargo build --target riscv64gc-unknown-linux-gnu --release
#
## build echo-dapp
#FROM echo-dapp-dep-builder as echo-dapp-builder
#COPY --chown=developer:developer rollup-http/echo-dapp/src ${BUILD_BASE}/tools/rollup-http/echo-dapp/src
#RUN cd ${BUILD_BASE}/tools/rollup-http/echo-dapp && touch src/* && \
# cargo build --target riscv64gc-unknown-linux-gnu --release

# pack tools (deb)
# ------------------------------------------------------------------------------
Expand All @@ -117,6 +141,7 @@ ARG STAGING_BASE=${BUILD_BASE}/_install
ARG STAGING_DEBIAN=${STAGING_BASE}/DEBIAN
ARG STAGING_SBIN=${STAGING_BASE}/usr/sbin
ARG STAGING_BIN=${STAGING_BASE}/usr/bin
ARG CMT_TAR_GZ=libcmt-v0.14.1-dev.tar.gz

RUN mkdir -p ${STAGING_DEBIAN} ${STAGING_SBIN} ${STAGING_BIN} ${STAGING_BASE}/etc && \
echo "cartesi-machine" > ${staging_base}/etc/hostname
Expand All @@ -125,12 +150,13 @@ COPY control ${STAGING_DEBIAN}/control

COPY --from=builder ${BUILD_BASE}/tools/sys-utils/cartesi-init/cartesi-init ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/xhalt/xhalt ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/rollup/rollup ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/yield/yield ${STAGING_SBIN}
COPY --from=c-builder ${BUILD_BASE}/tools/sys-utils/misc/* ${STAGING_BIN}
COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_SBIN}
COPY --from=http-server-builder ${BUILD_BASE}/tools/rollup-http/rollup-http-server/target/riscv64gc-unknown-linux-gnu/release/rollup-http-server ${STAGING_BIN}
COPY --from=echo-dapp-builder ${BUILD_BASE}/tools/rollup-http/echo-dapp/target/riscv64gc-unknown-linux-gnu/release/echo-dapp ${STAGING_BIN}
#COPY --from=rust-builder ${BUILD_BASE}/tools/rollup-http/rollup-init/rollup-init ${STAGING_SBIN}
#COPY --from=http-server-builder ${BUILD_BASE}/tools/rollup-http/rollup-http-server/target/riscv64gc-unknown-linux-gnu/release/rollup-http-server ${STAGING_BIN}
#COPY --from=echo-dapp-builder ${BUILD_BASE}/tools/rollup-http/echo-dapp/target/riscv64gc-unknown-linux-gnu/release/echo-dapp ${STAGING_BIN}

RUN dpkg-deb -Zxz --root-owner-group --build ${STAGING_BASE} ${BUILD_BASE}/${TOOLS_DEB}
COPY --from=c-builder ${BUILD_BASE}/${CMT_TAR_GZ} ${BUILD_BASE}/${CMT_TAR_GZ}
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
#

MAJOR := 0
MINOR := 14
PATCH := 1
LABEL :=
MINOR := 15
PATCH := 0
LABEL :=-dev
VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL)

TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb
TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION)
TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2
CMT_TAR_GZ := libcmt-$(VERSION).tar.gz

IMAGE_KERNEL_VERSION ?= v0.19.1
IMAGE_KERNEL_VERSION ?= v0.20.0-output-unification-rc1
LINUX_VERSION ?= 6.5.9-ctsi-1
LINUX_HEADERS_URLPATH := https://github.com/cartesi/image-kernel/releases/download/${IMAGE_KERNEL_VERSION}/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb

Expand All @@ -33,6 +34,7 @@ all: fs
build: control
@docker buildx build --load \
--build-arg TOOLS_DEB=$(TOOLS_DEB) \
--build-arg CMT_TAR_GZ=$(CMT_TAR_GZ) \
--build-arg IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION) \
--build-arg LINUX_VERSION=$(LINUX_VERSION) \
--build-arg LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH) \
Expand All @@ -44,6 +46,7 @@ build: control
copy:
@ID=`docker create $(TOOLS_IMAGE)` && \
docker cp $$ID:/opt/cartesi/$(TOOLS_DEB) . && \
docker cp $$ID:/opt/cartesi/$(CMT_TAR_GZ) . && \
docker rm $$ID

$(TOOLS_DEB) deb: build
Expand All @@ -63,6 +66,7 @@ $(TOOLS_ROOTFS) fs: $(TOOLS_DEB)
rm -f rootfs.gnutar rootfs.tar

env:
@echo CMT_TAR_GZ=$(CMT_TAR_GZ)
@echo TOOLS_DEB=$(TOOLS_DEB)
@echo TOOLS_ROOTFS=$(TOOLS_ROOTFS)
@echo TOOLS_IMAGE=$(TOOLS_IMAGE)
Expand Down
2 changes: 1 addition & 1 deletion fs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RUN mkdir benchmarks && cd benchmarks && \

# Final image
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04
ARG TOOLS_DEB=machine-emulator-tools-v0.14.0.deb
ARG TOOLS_DEB=machine-emulator-tools-v0.14.1-dev.deb
ADD ${TOOLS_DEB} /tmp/
RUN apt-get update && \
apt-get install -y --no-install-recommends \
Expand Down
4 changes: 2 additions & 2 deletions sys-utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ all: $(UTILITIES)
$(UTILITIES):
@$(MAKE) -C $@

with-toolchain:
@$(MAKE) $(UTILITIES_WITH_TOOLCHAIN)
with-toolchain:
@$(MAKE) $(UTILITIES_WITH_TOOLCHAIN)

$(UTILITIES_WITH_TOOLCHAIN):
@$(MAKE) -C $@ with-toolchain
Expand Down
11 changes: 4 additions & 7 deletions sys-utils/cartesi-init/cartesi-init
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ if [ -n "$ENTRYPOINT" ]; then
HOME=$(eval echo ~$USER)
WORKDIR=${WORKDIR:-"$HOME"}

# give user group access to rollup and yield devices
[ -c /dev/rollup ] && \
busybox chown :$(busybox id -g $USER) /dev/rollup && \
busybox chmod g+rw /dev/rollup
[ -c /dev/yield ] &&
busybox chown :$(busybox id -g $USER) /dev/yield && \
busybox chmod g+rw /dev/yield
# give user group access to cmio device
[ -c /dev/cmio ] && \
busybox chown :$(busybox id -g $USER) /dev/cmio && \
busybox chmod g+rw /dev/cmio

# execute entrypoint
(cd $WORKDIR &&
Expand Down
15 changes: 8 additions & 7 deletions sys-utils/ioctl-echo-loop/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ RISCV_ARCH ?= rv64gc
RISCV_ABI ?= lp64d

TOOLCHAIN_PREFIX ?= riscv64-cartesi-linux-gnu-
TOOLCHAIN_SUFFIX ?=

RVCC = $(TOOLCHAIN_PREFIX)gcc$(TOOLCHAIN_SUFFIX)
RVCXX = $(TOOLCHAIN_PREFIX)g++$(TOOLCHAIN_SUFFIX)
RVCOPY = $(TOOLCHAIN_PREFIX)objcopy$(TOOLCHAIN_SUFFIX)
RVDUMP = $(TOOLCHAIN_PREFIX)objdump$(TOOLCHAIN_SUFFIX)
RVCC = $(TOOLCHAIN_PREFIX)gcc
RVCXX = $(TOOLCHAIN_PREFIX)g++
RVCOPY = $(TOOLCHAIN_PREFIX)objcopy
RVDUMP = $(TOOLCHAIN_PREFIX)objdump
STRIP = $(TOOLCHAIN_PREFIX)strip
CFLAGS :=-Wall -pedantic -O2 -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)
CFLAGS +=-Wall -Wextra -pedantic -O2 `pkg-config --cflags libcmt`
LDLIBS += `pkg-config --libs libcmt`

CONTAINER_MAKE := /usr/bin/make
CONTAINER_BASE := /opt/cartesi/tools
Expand All @@ -43,8 +43,9 @@ ioctl-echo-loop.with-toolchain with-toolchain:
extra.ext2.with-toolchain:
$(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) [email protected]"

ioctl-echo-loop: export PKG_CONFIG_PATH ?= /usr/riscv64-linux-gnu/lib/pkgconfig
ioctl-echo-loop: ioctl-echo-loop.c
$(RVCC) $(CFLAGS) -o ioctl-echo-loop ioctl-echo-loop.c
$(RVCC) $(CFLAGS) -o ioctl-echo-loop ioctl-echo-loop.c $(LDLIBS)
$(STRIP) ioctl-echo-loop

extra.ext2: ioctl-echo-loop
Expand Down
Loading
Loading