diff --git a/.dockerignore b/.dockerignore index 0b73b065..54587589 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,6 @@ machine-emulator-tools-*.ext2 -example/ +rootfs* +.clang-format +.github +.git +*.md diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 21cf96be..b42d277f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,15 +1,27 @@ name: Build on: [push] -env: - TOOLCHAIN_IMAGE: ${{ github.repository_owner }}/toolchain - TOOLCHAIN_TAG: 0.16.0 jobs: tools: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest-8-cores steps: - - uses: actions/checkout@v3 - with: - submodules: recursive + - name: Install libarchive-tools + run: | + export DEBIAN_FRONTEND=noninteractive + sudo apt-get update + sudo apt-get install -y --no-install-recommends build-essential autoconf automake libarchive-dev libarchive-tools + + # Building from source cause the provided debian package is for Debian Bookworm + - name: Download, build and install xgenext2fs + run: | + wget https://github.com/cartesi/genext2fs/archive/refs/tags/v1.5.3.tar.gz + echo "af62ec69916ffc15fa5921b19630c9935e69a0d8b1bf529d7f26cefdc23a5120 v1.5.3.tar.gz" | sha256sum -c - + tar -xzf v1.5.3.tar.gz + cd genext2fs-1.5.3 + ./autogen.sh + ./configure + make + sudo make install + rm -rf genext2fs-1.5.3 v1.5.3.tar.gz - name: Login to GHCR uses: docker/login-action@v2 @@ -24,111 +36,76 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Export makefile variables run: make env >> $GITHUB_ENV - - name: Download and check dependencies - run: make checksum + - name: Create debian package control file + run: make control - name: Buildx setup uses: docker/setup-buildx-action@v2 - - name: Docker meta - id: docker_meta - uses: docker/metadata-action@v4 - with: - images: ${{ secrets.DOCKER_ORGANIZATION }}/machine-emulator-tools - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - - name: Build [${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}] + - name: Build [${{ env.TOOLS_DEB }}] id: docker_build uses: docker/build-push-action@v4 with: context: . builder: ${{ steps.buildx.outputs.name }} - tags: ${{ steps.docker_meta.outputs.tags }} + tags: ${{ env.TOOLS_IMAGE }} push: false load: true build-args: | - MACHINE_EMULATOR_TOOLS_TAR_GZ=${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} - MACHINE_EMULATOR_TOOLS_DEB=${{ env.MACHINE_EMULATOR_TOOLS_DEB }} - MACHINE_EMULATOR_TOOLS_VERSION=${{ env.MACHINE_EMULATOR_TOOLS_VERSION }} - LINUX_SOURCES_VERSION=${{ env.LINUX_SOURCES_VERSION }} - LINUX_SOURCES_FILEPATH=${{ env.LINUX_SOURCES_FILEPATH }} - RNDADDENTROPY_VERSION=${{ env.RNDADDENTROPY_VERSION }} - RNDADDENTROPY_FILEPATH=${{ env.RNDADDENTROPY_FILEPATH }} + TOOLS_DEB=${{ env.TOOLS_DEB }} + IMAGE_KERNEL_VERSION=${{ env.IMAGE_KERNEL_VERSION }} + LINUX_VERSION=${{ env.LINUX_VERSION }} + LINUX_HEADERS_URLPATH=${{ env.LINUX_HEADERS_URLPATH }} cache-from: type=gha,scope=regular,mode=max cache-to: type=gha,scope=regular - name: Retrieve artifacts - run: make copy MACHINE_EMULATOR_TOOLS_IMAGE=`echo "${{ steps.docker_meta.outputs.tags }}" | head -1 | cut -d "," -f 1 | xargs` + run: make copy - - name: Upload [${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}] + - name: Build rootfs + run: make fs + + - name: Upload [${{ env.TOOLS_DEB }}] uses: actions/upload-artifact@v3 with: - name: ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} - path: ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} + path: ${{ env.TOOLS_DEB }} - - name: Upload [${{ env.MACHINE_EMULATOR_TOOLS_DEB }}] + - name: Upload [${{ env.TOOLS_ROOTFS }}] uses: actions/upload-artifact@v3 with: - name: ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} - path: ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} + path: ${{ env.TOOLS_ROOTFS }} - name: Checksum artifacts + if: startsWith(github.ref, 'refs/tags/v') run: | - sha512sum ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} > ${{ env.MACHINE_EMULATOR_TOOLS_DEB }}.sha512 - sha512sum ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} > ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}.sha512 + sha512sum ${{ env.TOOLS_DEB }} > ${{ env.TOOLS_DEB }}.sha512 + sha512sum ${{ env.TOOLS_ROOTFS }} > ${{ env.TOOLS_ROOTFS }}.sha512 - uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/v') with: prerelease: true files: | - ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }} - ${{ env.MACHINE_EMULATOR_TOOLS_TAR_GZ }}.sha512 - ${{ env.MACHINE_EMULATOR_TOOLS_DEB }} - ${{ env.MACHINE_EMULATOR_TOOLS_DEB }}.sha512 + ${{ env.TOOLS_DEB }} + ${{ env.TOOLS_DEB }}.sha512 + ${{ env.TOOLS_ROOTFS }} + ${{ env.TOOLS_ROOTFS }}.sha512 - build: + test-rollup-http-server: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 with: submodules: recursive - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build yield tool - run: cd linux/htif && make toolchain-exec CONTAINER_COMMAND="/usr/bin/make yield.toolchain" - - - name: Build ioctl-echo-loop tool - run: cd linux/rollup/ioctl-echo-loop && make toolchain-exec CONTAINER_COMMAND="/usr/bin/make ioctl-echo-loop.toolchain" - - - name: Build rollup tool - run: cd linux/rollup/rollup && make toolchain-exec CONTAINER_COMMAND="/usr/bin/make rollup.toolchain" - - - name: Build rollup http server - run: cd linux/rollup/http/rollup-http-server && ./build.sh - - - name: Build echo dapp - run: cd linux/rollup/http/echo-dapp && ./build.sh - - name: Test rollup-http-server and echo-dapp client run: | - cd linux/rollup/http/rollup-http-server + cd rollup-http/rollup-http-server USE_ROLLUP_BINDINGS_MOCK=1 cargo test -- --show-output --test-threads=1 diff --git a/.gitignore b/.gitignore index f58abbf3..e5e72fef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ *.ext2 +control machine-emulator-tools-*.tar.gz machine-emulator-tools-*.deb -dep/ +rootfs.* # Prerequisites *.d diff --git a/CHANGELOG.md b/CHANGELOG.md index bd018918..f5b79cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.14.0] - 2023-12-13 +### Changed +- Make rootfs the default target +- Reorganized repository structure +- Use image-kernel Linux headers package +- Cross-compiled sys-utils +- Built rust binaries dependencies in a separate stage +- Cleaned up Dockerfile and Makefile +- Update toolchain to 0.16.0 + +### Added +- Added support for building rootfs.ext2 (breaking change) +- Added dhrystone and whetstone benchmarks on fs +- Added extra packages to rootfs +- Cross-compiled rust application binaries + +### Removed +- Removed example directory + ## [0.13.0] - 2023-10-10 ### Changed - Updated tools version in example -- Update toolchain to 0.16.0 ### Added - Added new init system using init and entrypoint from device tree @@ -109,7 +127,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.13.0...HEAD +[Unreleased]: https://github.com/cartesi/machine-emulator-tools/compare/v0.14.0...HEAD +[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 [0.12.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.12.0 [0.11.0]: https://github.com/cartesi/machine-emulator-tools/releases/tag/v0.11.0 diff --git a/Dockerfile b/Dockerfile index c2911c3c..96fbc75a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,79 +14,123 @@ # limitations under the License. # -FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 as sdk -ARG LINUX_SOURCES_VERSION=5.15.63-ctsi-2 -ARG LINUX_SOURCES_FILEPATH=dep/linux-sources-${LINUX_SOURCES_VERSION}.tar.gz -ARG RNDADDENTROPY_VERSION=3.0.0 -ARG RNDADDENTROPY_FILEPATH=dep/twuewand-$(RNDADDENTROPY_VERSION).tar.gz -ARG BUILD_BASE=/opt/cartesi/ - -# apt -# ------------------------------------------------------------------------------ -RUN DEBIAN_FRONTEND=noninteractive apt update && \ - apt upgrade -y && \ - apt install -y --no-install-recommends \ - build-essential \ - ca-certificates \ - git \ - protobuf-compiler \ - rsync \ - rust-all=1.58.1+dfsg1~ubuntu1-0ubuntu2 \ - && \ - rm -rf /var/lib/apt/lists/* - -# copy & extract kernel headers -# TODO: Fix apt database entry for linux-headers (it is satisfied here) +FROM ubuntu:22.04 as tools-env +ARG IMAGE_KERNEL_VERSION=v0.19.1 +ARG LINUX_VERSION=6.5.9-ctsi-1 +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 + +# Install dependencies # ------------------------------------------------------------------------------ -COPY ${LINUX_SOURCES_FILEPATH} ${BUILD_BASE}${LINUX_SOURCES_FILEPATH} -RUN mkdir -p ${BUILD_BASE}linux-sources && \ - tar xf ${BUILD_BASE}${LINUX_SOURCES_FILEPATH} \ - --strip-components=1 -C ${BUILD_BASE}linux-sources && \ - make -C ${BUILD_BASE}linux-sources headers_install INSTALL_HDR_PATH=/usr && \ - rm ${BUILD_BASE}${LINUX_SOURCES_FILEPATH} +ENV LINUX_HEADERS_FILEPATH=/tmp/linux-libc-dev-riscv64-cross-${LINUX_VERSION}-${IMAGE_KERNEL_VERSION}.deb + +RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + git \ + wget \ + 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 && \ + 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} + +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" -# copy tools -COPY linux/ ${BUILD_BASE}tools/linux/ +FROM tools-env as builder +COPY --chown=developer:developer sys-utils/ ${BUILD_BASE}/tools/sys-utils/ # build C/C++ tools # ------------------------------------------------------------------------------ -RUN make -C ${BUILD_BASE}tools/linux/xhalt/ CROSS_COMPILE="" xhalt.toolchain -RUN make -C ${BUILD_BASE}tools/linux/htif/ CROSS_COMPILE="" yield.toolchain -RUN make -C ${BUILD_BASE}tools/linux/rollup/ioctl-echo-loop/ CROSS_COMPILE="" ioctl-echo-loop.toolchain -RUN make -C ${BUILD_BASE}tools/linux/rollup/rollup/ CROSS_COMPILE="" rollup.toolchain +FROM builder as c-builder +USER developer +RUN make -C ${BUILD_BASE}/tools/sys-utils/ -j$(nproc) all # build rust tools # ------------------------------------------------------------------------------ -# NOTE: cargo update RAM usage keeps going up without this -RUN mkdir -p $HOME/.cargo && \ - echo "[net]" >> $HOME/.cargo/config && \ - echo "git-fetch-with-cli = true" >> $HOME/.cargo/config +FROM tools-env as rust-env +ENV PATH="/home/developer/.cargo/bin:${PATH}" -RUN cd ${BUILD_BASE}tools/linux/rollup/http/echo-dapp && \ - cargo build --release -RUN cd ${BUILD_BASE}tools/linux/rollup/http/rollup-http-server && \ - cargo build --release +USER developer -# pack tools (tar.gz) -# ------------------------------------------------------------------------------ -ARG STAGING_BASE=/tmp/staging/ -ARG STAGING_BIN=${STAGING_BASE}opt/cartesi/bin/ -ARG MACHINE_EMULATOR_TOOLS_TAR_GZ=machine-emulator-tools.tar.gz - -COPY skel/ ${STAGING_BASE} -RUN mkdir -p ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/xhalt/xhalt ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/htif/yield ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/ioctl-echo-loop/ioctl-echo-loop ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/rollup/rollup ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/http/echo-dapp/target/release/echo-dapp ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/rollup/http/rollup-http-server/target/release/rollup-http-server ${STAGING_BIN} && \ - cp ${BUILD_BASE}tools/linux/utils/* ${STAGING_BIN} && \ - tar czf ${BUILD_BASE}${MACHINE_EMULATOR_TOOLS_TAR_GZ} -C ${STAGING_BASE} . +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) # ------------------------------------------------------------------------------ -ARG MACHINE_EMULATOR_TOOLS_DEB=machine-emulator-tools.deb -COPY Makefile . -COPY tools tools -RUN make deb STAGING_BASE=${STAGING_BASE} DESTDIR=${BUILD_BASE}_install PREFIX=/ MACHINE_EMULATOR_TOOLS_DEB=${BUILD_BASE}${MACHINE_EMULATOR_TOOLS_DEB} +FROM tools-env as packer +ARG TOOLS_DEB=machine-emulator-tools.deb +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 + +RUN mkdir -p ${STAGING_DEBIAN} ${STAGING_SBIN} ${STAGING_BIN} ${STAGING_BASE}/etc && \ + echo "cartesi-machine" > ${staging_base}/etc/hostname + +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/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} + +RUN dpkg-deb -Zxz --root-owner-group --build ${STAGING_BASE} ${BUILD_BASE}/${TOOLS_DEB} diff --git a/Makefile b/Makefile index 7f2a74aa..2350b5a8 100644 --- a/Makefile +++ b/Makefile @@ -15,101 +15,114 @@ # MAJOR := 0 -MINOR := 13 +MINOR := 14 PATCH := 0 LABEL := VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL) -MACHINE_EMULATOR_TOOLS_VERSION ?= v$(VERSION) -MACHINE_EMULATOR_TOOLS_TAR_GZ := machine-emulator-tools-$(MACHINE_EMULATOR_TOOLS_VERSION).tar.gz -MACHINE_EMULATOR_TOOLS_DEB := machine-emulator-tools-$(MACHINE_EMULATOR_TOOLS_VERSION).deb -MACHINE_EMULATOR_TOOLS_IMAGE := cartesi/machine-emulator-tools:$(MACHINE_EMULATOR_TOOLS_VERSION) +TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb +TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION) +TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2 -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 +IMAGE_KERNEL_VERSION ?= v0.19.1 +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 -RNDADDENTROPY_VERSION ?= 3.0.0 -RNDADDENTROPY_FILEPATH := dep/twuewand-$(RNDADDENTROPY_VERSION).tar.gz -RNDADDENTROPY_URLPATH := https://www.finnie.org/software/twuewand/twuewand-$(RNDADDENTROPY_VERSION).tar.gz +all: fs -SHASUMFILES := $(LINUX_SOURCES_FILEPATH) $(RNDADDENTROPY_FILEPATH) - -all: build copy - -build: Dockerfile checksum - docker buildx build --platform=linux/riscv64 --load \ - --build-arg MACHINE_EMULATOR_TOOLS_TAR_GZ=$(MACHINE_EMULATOR_TOOLS_TAR_GZ) \ - --build-arg MACHINE_EMULATOR_TOOLS_DEB=$(MACHINE_EMULATOR_TOOLS_DEB) \ - --build-arg LINUX_SOURCES_VERSION=$(LINUX_SOURCES_VERSION) \ - --build-arg LINUX_SOURCES_FILEPATH=$(LINUX_SOURCES_FILEPATH) \ - --build-arg RNDADDENTROPY_VERSION=$(RNDADDENTROPY_VERSION) \ - --build-arg RNDADDENTROPY_FILEPATH=$(RNDADDENTROPY_FILEPATH) \ - -t $(MACHINE_EMULATOR_TOOLS_IMAGE) \ - -f $< \ - . +build: control + @docker buildx build --load \ + --build-arg TOOLS_DEB=$(TOOLS_DEB) \ + --build-arg IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION) \ + --build-arg LINUX_VERSION=$(LINUX_VERSION) \ + --build-arg LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH) \ + -t $(TOOLS_IMAGE) \ + -f Dockerfile \ + . ; + $(MAKE) copy copy: - ID=`docker create --platform=linux/riscv64 $(MACHINE_EMULATOR_TOOLS_IMAGE)` && \ - docker cp $$ID:/opt/cartesi/$(MACHINE_EMULATOR_TOOLS_TAR_GZ) . && \ - docker cp $$ID:/opt/cartesi/$(MACHINE_EMULATOR_TOOLS_DEB) . && \ + @ID=`docker create $(TOOLS_IMAGE)` && \ + docker cp $$ID:/opt/cartesi/$(TOOLS_DEB) . && \ docker rm $$ID -deb: - mkdir -p $(DESTDIR)/DEBIAN - cat tools/template/control.template | sed 's|ARG_VERSION|$(VERSION)|g' > $(DESTDIR)/DEBIAN/control - cp -R $(STAGING_BASE)* $(DESTDIR)$(PREFIX) - dpkg-deb -Zxz --root-owner-group --build $(DESTDIR) $(MACHINE_EMULATOR_TOOLS_DEB) +$(TOOLS_DEB) deb: build -$(LINUX_SOURCES_FILEPATH): - T=`mktemp` && \ - mkdir -p `dirname $@` && \ - wget $(LINUX_SOURCES_URLPATH) -O $$T && \ - mv $$T $@ || (rm $$T && false) +control: Makefile control.template + @sed 's|ARG_VERSION|$(VERSION)|g' control.template > control -$(RNDADDENTROPY_FILEPATH): - T=`mktemp` && \ - mkdir -p `dirname $@` && \ - wget $(RNDADDENTROPY_URLPATH) -O $$T && \ - mv $$T $@ || (rm $$T && false) -shasumfile: $(SHASUMFILES) - shasum -a 256 $^ > $@ - -checksum: $(SHASUMFILES) - @shasum -ca 256 shasumfile +$(TOOLS_ROOTFS) fs: $(TOOLS_DEB) + @docker buildx build --platform=linux/riscv64 \ + --build-arg TOOLS_DEB=$(TOOLS_DEB) \ + --output type=tar,dest=rootfs.tar \ + --file fs/Dockerfile \ + . && \ + bsdtar -cf rootfs.gnutar --format=gnutar @rootfs.tar && \ + xgenext2fs -fzB 4096 -b 25600 -i 4096 -a rootfs.gnutar -L rootfs $(TOOLS_ROOTFS) && \ + rm -f rootfs.gnutar rootfs.tar env: - @echo MACHINE_EMULATOR_TOOLS_TAR_GZ=$(MACHINE_EMULATOR_TOOLS_TAR_GZ) - @echo MACHINE_EMULATOR_TOOLS_DEB=$(MACHINE_EMULATOR_TOOLS_DEB) - @echo MACHINE_EMULATOR_TOOLS_VERSION=$(MACHINE_EMULATOR_TOOLS_VERSION) - @echo LINUX_SOURCES_VERSION=$(LINUX_SOURCES_VERSION) - @echo LINUX_SOURCES_FILEPATH=$(LINUX_SOURCES_FILEPATH) - @echo RNDADDENTROPY_VERSION=$(RNDADDENTROPY_VERSION) - @echo RNDADDENTROPY_FILEPATH=$(RNDADDENTROPY_FILEPATH) + @echo TOOLS_DEB=$(TOOLS_DEB) + @echo TOOLS_ROOTFS=$(TOOLS_ROOTFS) + @echo TOOLS_IMAGE=$(TOOLS_IMAGE) + @echo IMAGE_KERNEL_VERSION=$(IMAGE_KERNEL_VERSION) + @echo LINUX_VERSION=$(LINUX_VERSION) + @echo LINUX_HEADERS_URLPATH=$(LINUX_HEADERS_URLPATH) setup: - docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132 + @docker run --privileged --rm linuxkit/binfmt:bebbae0c1100ebf7bf2ad4dfb9dfd719cf0ef132 setup-required: @echo 'riscv64 buildx setup required:' `docker buildx ls | grep -q riscv64 && echo no || echo yes` +build-tools-env: + docker build --target tools-env -t $(TOOLS_IMAGE)-tools-env -f Dockerfile . + +build-rust-builder-env: + docker build --target rust-builder -t $(TOOLS_IMAGE)-rust-builder -f Dockerfile . + +tools-env: + @docker run --hostname rust-builder -it --rm \ + -e USER=$$(id -u -n) \ + -e GROUP=$$(id -g -n) \ + -e UID=$$(id -u) \ + -e GID=$$(id -g) \ + -v `pwd`:/opt/cartesi/machine-emulator-tools \ + -w /opt/cartesi/machine-emulator-tools \ + $(TOOLS_IMAGE)-tools-env /bin/bash + + +rust-builder-env: + @docker run --hostname rust-builder -it --rm \ + -e USER=$$(id -u -n) \ + -e GROUP=$$(id -g -n) \ + -e UID=$$(id -u) \ + -e GID=$$(id -g) \ + -v `pwd`:/opt/cartesi/machine-emulator-tools \ + -w /opt/cartesi/machine-emulator-tools \ + $(TOOLS_IMAGE)-rust-builder /bin/bash + +clean-image: + @(docker rmi $(TOOLS_IMAGE) > /dev/null 2>&1 || true) + +clean: + @rm -f $(TOOLS_DEB) control rootfs* + @$(MAKE) -C sys-utils clean + +distclean: clean clean-image + +sys-utils: + @$(MAKE) -C sys-utils + help: @echo 'available commands:' + @echo ' deb - build machine-emulator-tools .deb package' + @echo ' fs - build rootfs.ext2' @echo ' setup - setup riscv64 buildx' @echo ' setup-required - check if riscv64 buildx setup is required' - @echo '+ tgz - create "$(MACHINE_EMULATOR_TOOLS_TAR_GZ)" (default)' @echo ' help - list makefile commands' - @echo ' checksum - verify downloaded files' - @echo ' shasumfile - recreate shasumfile of downloaded files' @echo ' env - print useful Makefile variables as a KEY=VALUE list' @echo ' clean - remove the generated artifacts' - @echo ' distclean - clean and remove dependencies' - -clean: - rm -f $(MACHINE_EMULATOR_TOOLS_TAR_GZ) $(MACHINE_EMULATOR_TOOLS_DEB) - -distclean: clean - rm -rf dep -.PHONY: checksum env setup help +.PHONY: build fs deb env setup setup-required help distclean diff --git a/README.md b/README.md index d4a9b104..f94d9969 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,29 @@ # Cartesi Machine Emulator Tools -The Cartesi Machine Emulator Tools a repository that contains a set of tools developed for the RISC-V Linux OS. +The Cartesi Machine Emulator Tools is a repository that contains a set of tools developed for the RISC-V Linux OS. It provides a RISC-V Debian package and a root filesystem for Ubuntu 22.04. ## Getting Started -Users looking to create cartesi-machine applications can use the artifact directly, no need to build this repository themselves. Also check the `example/` folder for the details. +Users looking to create cartesi-machine applications can use the provided Debian package and root filesystem directly from one of the prepackaged [releases](https://github.com/cartesi/machine-emulator-tools/releases), without needing to build this repository themselves. ### Requirements - Docker >= 18.x - GNU Make >= 3.81 +- bsdtar >= 3.7.2 +- xgenext2fs >= 1.5.3 ### Docker buildx setup +To set up riscv64 buildx, use the following command: + ```bash $ make setup ``` ### Building -A `make` invocation will download the dependencies if they are not present, build the ubuntu sdk, all tools and finally create the `machine-emulator-tools-$VERSION.tar.gz` artifact. +Invoking make will build all tools and create the `machine-emulator-tools-$VERSION.deb` Debian package along with the `rootfs-tools-$VERSION.ext2` root filesystem artifacts. ```bash $ make @@ -27,13 +31,16 @@ $ make #### Makefile targets -The following options are available as `make` targets: +The following commands are available as `make` targets: -- **tgz**: create "machine-emulator-tools.tar.gz" -- **setup**: setup riscv64 buildx -- **setup-required**: check if riscv64 buildx setup is required -- **clean**: clean generated artifacts -- **help**: list makefile targets +- **all**: Build Debian package and rootfs (Default) +- **deb**: Build machine-emulator-tools.deb package +- **fs**: Build rootfs.ext2 +- **setup**: Setup riscv64 buildx +- **setup-required**: Check if riscv64 buildx setup is required +- **help**: List Makefile commands +- **env**: Print useful Makefile variables as a KEY=VALUE list +- **clean**: Remove the generated artifacts ## Contributing diff --git a/tools/template/control.template b/control.template similarity index 100% rename from tools/template/control.template rename to control.template diff --git a/example/README.md b/example/README.md deleted file mode 100644 index 98e322df..00000000 --- a/example/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Example: Cartesi root filesystem with machine emulator tools - -The following example demonstrates how to create a bootable root filesystem for the Cartesi Machine based on a Ubuntu RISC-V 64 docker image. It requires the machine-emulator-tools. - -### Requirements - -- Docker >= 18.x -- GNU Make >= 3.81 -- xgenext2fs >= 1.5.3 -- bsdtar >= 3.6.2 -- bc >= 1.06 - -### Building - -```sh -cp ../machine-emulator-tools-v0.13.0.tar.gz . -./build ubuntu-22.04.dockerfile -``` - -After the build is done, the file `ubuntu-22.04.ext2` should be available in the current path. -Assuming you have `cartesi-machine` installed in your environment, -you can then test interactive terminal with it: - -```sh -$ cartesi-machine --flash-drive=label:root,filename:ubuntu-22.04.ext2 -i bash -Running in interactive mode! - - . - / \ - / \ -\---/---\ /----\ - \ X \ - \----/ \---/---\ - \ / CARTESI - \ / MACHINE - ' - -root@cartesi-machine:~# -``` diff --git a/example/build b/example/build deleted file mode 100755 index edd2b8bd..00000000 --- a/example/build +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -set -e - -if [ $# -eq 0 ]; then - echo "no dockerfile supplied" - exit 1 -fi - -NAME=${1%.*} -DOCKERFILE="$NAME.dockerfile" -TOOLS=machine-emulator-tools-v0.13.0.tar.gz - -if [ ! -f "$DOCKERFILE" ]; then - echo "dockerfile \"$DOCKERFILE\" not found" - exit 1 -fi - -if [ ! -f "$TOOLS" ]; then - echo "tools tarball \"$TOOLS\" not found" - exit 1 -fi - -TAR=$(mktemp) && \ -docker buildx build --progress plain \ - --build-arg TOOLS=$TOOLS \ - --output type=tar,dest=$TAR \ - --file $NAME.dockerfile \ - . && \ -GNUTAR=$(mktemp) && \ -bsdtar -cf $GNUTAR --format=gnutar @$TAR -./img-pack $GNUTAR $NAME.ext2 rootfs && (rm -f $TAR $GNUTAR; echo "created $NAME.ext2"; true) || (rm -f $TAR $GNUTAR; false) diff --git a/example/img-pack b/example/img-pack deleted file mode 100755 index feeed659..00000000 --- a/example/img-pack +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -blocksize=4096 -bytes=$(($(wc -c < "$1") +0)) -bcargs="$(cat <<- EOF - define max(a, b) { return (a > b) * a + (a <= b) * b } - max(8, 1.5 * ($bytes + $blocksize - 1) / $blocksize) - EOF -)" -blocks=$(echo "$bcargs" | bc) - -xgenext2fs \ - -fzB $blocksize \ - -b $blocks \ - -i $blocksize \ - -L ${3:-rootfs} \ - -a $1 \ - $2 diff --git a/example/ubuntu-22.04.dockerfile b/example/ubuntu-22.04.dockerfile deleted file mode 100644 index 10ecd658..00000000 --- a/example/ubuntu-22.04.dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 -ARG TOOLS=machine-emulator-tools.tar.gz -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - busybox-static \ - python3 python3-requests && \ - rm -rf /var/lib/apt/lists/* -RUN useradd --create-home --user-group dapp -ADD ${TOOLS} / diff --git a/fs/Dockerfile b/fs/Dockerfile new file mode 100644 index 00000000..768decb9 --- /dev/null +++ b/fs/Dockerfile @@ -0,0 +1,54 @@ +FROM --platform=$BUILDPLATFORM ubuntu:22.04 as cross-builder +ENV BUILD_BASE=/tmp/build-extra + +# Install dependencies +RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + wget \ + crossbuild-essential-riscv64 \ + gcc-12-riscv64-linux-gnu \ + && \ + adduser developer -u 499 --gecos ",,," --disabled-password && \ + mkdir -p ${BUILD_BASE} && chown -R developer:developer ${BUILD_BASE} && \ + rm -rf /var/lib/apt/lists/* + +USER developer +WORKDIR ${BUILD_BASE} + +# Build benchmark binaries +COPY fs/dhrystone.patch ${BUILD_BASE}/ +COPY fs/shasumfile ${BUILD_BASE}/ +RUN mkdir benchmarks && cd benchmarks && \ + wget https://www.netlib.org/benchmark/whetstone.c https://www.netlib.org/benchmark/dhry-c && \ + shasum -ca 256 ../shasumfile &&\ + bash dhry-c && \ + patch -p1 < ../dhrystone.patch && \ + riscv64-linux-gnu-gcc-12 -O2 -o whetstone whetstone.c -lm && \ + riscv64-linux-gnu-gcc-12 -O2 -o dhrystone dhry_1.c dhry_2.c -lm + +# Final image +FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 +ARG TOOLS_DEB=machine-emulator-tools-v0.14.0.deb +ADD ${TOOLS_DEB} /tmp/ +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + busybox-static=1:1.30.1-7ubuntu3 \ + coreutils=8.32-4.1ubuntu1 \ + bash=5.1-6ubuntu1 \ + psmisc=23.4-2build3 \ + bc=1.07.1-3build1 \ + curl=7.81.0-1ubuntu1.15 \ + device-tree-compiler=1.6.1-1 \ + jq=1.6-2.1ubuntu3 \ + lua5.4=5.4.4-1 \ + lua-socket=3.0~rc1+git+ac3201d-6 \ + xxd=2:8.2.3995-1ubuntu2.13 \ + file=1:5.41-3ubuntu0.1 \ + /tmp/${TOOLS_DEB} \ + && \ + useradd --create-home --user-group dapp && \ + rm -rf /var/lib/apt/lists/* /tmp/${TOOLS_DEB} +COPY --chown=root:root --from=cross-builder /tmp/build-extra/benchmarks/whetstone /usr/bin/ +COPY --chown=root:root --from=cross-builder /tmp/build-extra/benchmarks/dhrystone /usr/bin/ diff --git a/fs/dhrystone.patch b/fs/dhrystone.patch new file mode 100644 index 00000000..4a604188 --- /dev/null +++ b/fs/dhrystone.patch @@ -0,0 +1,311 @@ +diff -Nru a/dhry.h b/dhry.h +--- a/dhry.h ++++ b/dhry.h +@@ -345,6 +345,9 @@ + *************************************************************************** + */ + ++#ifndef DHRY_H ++#define DHRY_H ++ + /* Compiler and system dependent definitions: */ + + #ifndef TIME +@@ -359,6 +362,10 @@ + /* for "times" */ + #endif + ++#ifndef HZ ++#include ++#endif ++ + #define Mic_secs_Per_Second 1000000.0 + /* Berkeley UNIX C returns process times in seconds/HZ */ + +@@ -384,6 +391,8 @@ + /* General definitions: */ + + #include ++#include ++#include + /* for strcpy, strcmp */ + + #define Null 0 +@@ -420,4 +429,16 @@ + } variant; + } Rec_Type, *Rec_Pointer; + ++void Proc_1(Rec_Pointer Ptr_Val_Par); ++void Proc_2(One_Fifty *Int_Par_Ref); ++void Proc_3(Rec_Pointer *Ptr_Ref_Par); ++void Proc_4(); ++void Proc_5(); ++void Proc_6(Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par); ++void Proc_7(One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref); ++void Proc_8(Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val); + ++Enumeration Func_1(Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val); ++Boolean Func_2(Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref); ++Boolean Func_3(Enumeration Enum_Par_Val); ++#endif +diff -Nru a/dhry_1.c b/dhry_1.c +--- a/dhry_1.c ++++ b/dhry_1.c +@@ -17,6 +17,8 @@ + + #include "dhry.h" + ++#include ++ + /* Global Variables: */ + + Rec_Pointer Ptr_Glob, +@@ -28,9 +30,6 @@ + int Arr_1_Glob [50]; + int Arr_2_Glob [50] [50]; + +-extern char *malloc (); +-Enumeration Func_1 (); +- /* forward declaration necessary since Enumeration may not simply be int */ + + #ifndef REG + Boolean Reg = false; +@@ -45,13 +44,11 @@ + + #ifdef TIMES + struct tms time_info; +-extern int times (); + /* see library function "times" */ + #define Too_Small_Time 120 + /* Measurements should last at least about 2 seconds */ + #endif + #ifdef TIME +-extern long time(); + /* see library function "time" */ + #define Too_Small_Time 2 + /* Measurements should last at least 2 seconds */ +@@ -65,8 +62,7 @@ + + /* end of variables for time measurement */ + +- +-main () ++int main (int argc, char *argv[]) + /*****/ + + /* main program, corresponds to procedures */ +@@ -101,6 +97,15 @@ + /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */ + /* overflow may occur for this array element. */ + ++ Number_Of_Runs = 0; ++ if (argc == 2) ++ { ++ if (atoi(argv[1]) > 0) ++ { ++ Number_Of_Runs = atoi(argv[1]); ++ } ++ } ++ + printf ("\n"); + printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n"); + printf ("\n"); +@@ -114,13 +119,6 @@ + printf ("Program compiled without 'register' attribute\n"); + printf ("\n"); + } +- printf ("Please give the number of runs through the benchmark: "); +- { +- int n; +- scanf ("%d", &n); +- Number_Of_Runs = n; +- } +- printf ("\n"); + + printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs); + +@@ -211,7 +209,7 @@ + printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]); + printf (" should be: Number_Of_Runs + 10\n"); + printf ("Ptr_Glob->\n"); +- printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp); ++ printf (" Ptr_Comp: %ld\n", (uintptr_t) Ptr_Glob->Ptr_Comp); + printf (" should be: (implementation-dependent)\n"); + printf (" Discr: %d\n", Ptr_Glob->Discr); + printf (" should be: %d\n", 0); +@@ -222,7 +220,7 @@ + printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp); + printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n"); + printf ("Next_Ptr_Glob->\n"); +- printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp); ++ printf (" Ptr_Comp: %ld\n", (uintptr_t) Next_Ptr_Glob->Ptr_Comp); + printf (" should be: (implementation-dependent), same as above\n"); + printf (" Discr: %d\n", Next_Ptr_Glob->Discr); + printf (" should be: %d\n", 0); +@@ -273,15 +271,14 @@ + printf ("%6.1f \n", Dhrystones_Per_Second); + printf ("\n"); + } +- ++ ++ return 0; + } + + +-Proc_1 (Ptr_Val_Par) ++void Proc_1 (REG Rec_Pointer Ptr_Val_Par) + /******************/ +- +-REG Rec_Pointer Ptr_Val_Par; +- /* executed once */ ++/* executed once */ + { + REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp; + /* == Ptr_Glob_Next */ +@@ -311,12 +308,10 @@ + } /* Proc_1 */ + + +-Proc_2 (Int_Par_Ref) ++void Proc_2 (One_Fifty *Int_Par_Ref) + /******************/ + /* executed once */ + /* *Int_Par_Ref == 1, becomes 4 */ +- +-One_Fifty *Int_Par_Ref; + { + One_Fifty Int_Loc; + Enumeration Enum_Loc; +@@ -334,13 +329,10 @@ + } /* Proc_2 */ + + +-Proc_3 (Ptr_Ref_Par) ++void Proc_3 (Rec_Pointer *Ptr_Ref_Par) + /******************/ + /* executed once */ + /* Ptr_Ref_Par becomes Ptr_Glob */ +- +-Rec_Pointer *Ptr_Ref_Par; +- + { + if (Ptr_Glob != Null) + /* then, executed */ +@@ -349,7 +341,7 @@ + } /* Proc_3 */ + + +-Proc_4 () /* without parameters */ ++void Proc_4 () /* without parameters */ + /*******/ + /* executed once */ + { +@@ -361,7 +353,7 @@ + } /* Proc_4 */ + + +-Proc_5 () /* without parameters */ ++void Proc_5 () /* without parameters */ + /*******/ + /* executed once */ + { +diff -Nru a/dhry_2.c b/dhry_2.c +--- a/dhry_2.c ++++ b/dhry_2.c +@@ -27,13 +27,10 @@ + extern char Ch_1_Glob; + + +-Proc_6 (Enum_Val_Par, Enum_Ref_Par) ++void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par) + /*********************************/ + /* executed once */ + /* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */ +- +-Enumeration Enum_Val_Par; +-Enumeration *Enum_Ref_Par; + { + *Enum_Ref_Par = Enum_Val_Par; + if (! Func_3 (Enum_Val_Par)) +@@ -61,7 +58,7 @@ + } /* Proc_6 */ + + +-Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref) ++void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref) + /**********************************************/ + /* executed three times */ + /* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */ +@@ -70,9 +67,6 @@ + /* Int_Par_Ref becomes 17 */ + /* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */ + /* Int_Par_Ref becomes 18 */ +-One_Fifty Int_1_Par_Val; +-One_Fifty Int_2_Par_Val; +-One_Fifty *Int_Par_Ref; + { + One_Fifty Int_Loc; + +@@ -81,15 +75,11 @@ + } /* Proc_7 */ + + +-Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val) ++void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val) + /*********************************************************************/ + /* executed once */ + /* Int_Par_Val_1 == 3 */ + /* Int_Par_Val_2 == 7 */ +-Arr_1_Dim Arr_1_Par_Ref; +-Arr_2_Dim Arr_2_Par_Ref; +-int Int_1_Par_Val; +-int Int_2_Par_Val; + { + REG One_Fifty Int_Index; + REG One_Fifty Int_Loc; +@@ -106,15 +96,12 @@ + } /* Proc_8 */ + + +-Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val) ++Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val) + /*************************************************/ + /* executed three times */ + /* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */ + /* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */ + /* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */ +- +-Capital_Letter Ch_1_Par_Val; +-Capital_Letter Ch_2_Par_Val; + { + Capital_Letter Ch_1_Loc; + Capital_Letter Ch_2_Loc; +@@ -132,14 +119,11 @@ + } /* Func_1 */ + + +-Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref) ++Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref) + /*************************************************/ + /* executed once */ + /* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */ + /* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */ +- +-Str_30 Str_1_Par_Ref; +-Str_30 Str_2_Par_Ref; + { + REG One_Thirty Int_Loc; + Capital_Letter Ch_Loc; +@@ -174,11 +158,10 @@ + } /* Func_2 */ + + +-Boolean Func_3 (Enum_Par_Val) ++Boolean Func_3 (Enumeration Enum_Par_Val) + /***************************/ + /* executed once */ + /* Enum_Par_Val == Ident_3 */ +-Enumeration Enum_Par_Val; + { + Enumeration Enum_Loc; + diff --git a/fs/shasumfile b/fs/shasumfile new file mode 100644 index 00000000..0eb7588a --- /dev/null +++ b/fs/shasumfile @@ -0,0 +1,2 @@ +333e4ceca042c146f63eec605573d16ae8b07166cbc44a17bec1ea97c6f1efbf whetstone.c +038a7e9169787125c3451a6c941f3aca5db2d2f3863871afcdce154ef17f4e3e dhry-c diff --git a/linux/rollup/http/echo-dapp/environment.sh b/linux/rollup/http/echo-dapp/environment.sh deleted file mode 100644 index eaee9fed..00000000 --- a/linux/rollup/http/echo-dapp/environment.sh +++ /dev/null @@ -1,7 +0,0 @@ -#! /bin/sh - -export CC=riscv64-cartesi-linux-gnu-gcc -export CXX=riscv64-cartesi-linux-gnu-g++ -export RISCV_ARCH=rv64gc -export RISCV_ABI=lp64d -export CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI" diff --git a/linux/rollup/http/rollup-http-server/environment.sh b/linux/rollup/http/rollup-http-server/environment.sh deleted file mode 100644 index eaee9fed..00000000 --- a/linux/rollup/http/rollup-http-server/environment.sh +++ /dev/null @@ -1,7 +0,0 @@ -#! /bin/sh - -export CC=riscv64-cartesi-linux-gnu-gcc -export CXX=riscv64-cartesi-linux-gnu-g++ -export RISCV_ARCH=rv64gc -export RISCV_ABI=lp64d -export CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI" diff --git a/rollup-http/.cargo/config.toml b/rollup-http/.cargo/config.toml new file mode 100644 index 00000000..b7f2f7bf --- /dev/null +++ b/rollup-http/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.riscv64gc-unknown-linux-gnu] +linker = "riscv64-linux-gnu-gcc-12" + +[net] +git-fetch-with-cli = true diff --git a/linux/rollup/http/echo-dapp/Cargo.lock b/rollup-http/echo-dapp/Cargo.lock similarity index 100% rename from linux/rollup/http/echo-dapp/Cargo.lock rename to rollup-http/echo-dapp/Cargo.lock diff --git a/linux/rollup/http/echo-dapp/Cargo.toml b/rollup-http/echo-dapp/Cargo.toml similarity index 100% rename from linux/rollup/http/echo-dapp/Cargo.toml rename to rollup-http/echo-dapp/Cargo.toml diff --git a/linux/rollup/http/echo-dapp/README.md b/rollup-http/echo-dapp/README.md similarity index 100% rename from linux/rollup/http/echo-dapp/README.md rename to rollup-http/echo-dapp/README.md diff --git a/linux/rollup/http/echo-dapp/build.sh b/rollup-http/echo-dapp/build-with-toolchain.sh similarity index 87% rename from linux/rollup/http/echo-dapp/build.sh rename to rollup-http/echo-dapp/build-with-toolchain.sh index 709a1028..d984e3ae 100755 --- a/linux/rollup/http/echo-dapp/build.sh +++ b/rollup-http/echo-dapp/build-with-toolchain.sh @@ -8,5 +8,6 @@ CONTAINER_BASE="${CONTAINER_BASE:-/opt/cartesi/tools}" docker run --rm -e USER=`id -u -n` -e GROUP=`id -g -n` -e UID=`id -u` -e GID=`id -g` -v `pwd`/../:$CONTAINER_BASE \ --env CC=riscv64-cartesi-linux-gnu-gcc --env CXX=riscv64-cartesi-linux-gnu-g++ --env CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI" \ +--env CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-cartesi-linux-gnu-gcc \ -w $CONTAINER_BASE/echo-dapp $TOOLCHAIN_IMAGE:$TOOLCHAIN_TAG \ cargo build --target riscv64gc-unknown-linux-gnu --release diff --git a/linux/rollup/http/echo-dapp/src/config.rs b/rollup-http/echo-dapp/src/config.rs similarity index 100% rename from linux/rollup/http/echo-dapp/src/config.rs rename to rollup-http/echo-dapp/src/config.rs diff --git a/linux/rollup/http/echo-dapp/src/main.rs b/rollup-http/echo-dapp/src/main.rs similarity index 100% rename from linux/rollup/http/echo-dapp/src/main.rs rename to rollup-http/echo-dapp/src/main.rs diff --git a/linux/rollup/http/rollup-http-client/.gitignore b/rollup-http/rollup-http-client/.gitignore similarity index 100% rename from linux/rollup/http/rollup-http-client/.gitignore rename to rollup-http/rollup-http-client/.gitignore diff --git a/linux/rollup/http/rollup-http-client/Cargo.toml b/rollup-http/rollup-http-client/Cargo.toml similarity index 100% rename from linux/rollup/http/rollup-http-client/Cargo.toml rename to rollup-http/rollup-http-client/Cargo.toml diff --git a/linux/rollup/http/rollup-http-client/src/client.rs b/rollup-http/rollup-http-client/src/client.rs similarity index 100% rename from linux/rollup/http/rollup-http-client/src/client.rs rename to rollup-http/rollup-http-client/src/client.rs diff --git a/linux/rollup/http/rollup-http-client/src/lib.rs b/rollup-http/rollup-http-client/src/lib.rs similarity index 100% rename from linux/rollup/http/rollup-http-client/src/lib.rs rename to rollup-http/rollup-http-client/src/lib.rs diff --git a/linux/rollup/http/rollup-http-client/src/rollup.rs b/rollup-http/rollup-http-client/src/rollup.rs similarity index 100% rename from linux/rollup/http/rollup-http-client/src/rollup.rs rename to rollup-http/rollup-http-client/src/rollup.rs diff --git a/linux/rollup/http/rollup-http-server/Cargo.lock b/rollup-http/rollup-http-server/Cargo.lock similarity index 100% rename from linux/rollup/http/rollup-http-server/Cargo.lock rename to rollup-http/rollup-http-server/Cargo.lock diff --git a/linux/rollup/http/rollup-http-server/Cargo.toml b/rollup-http/rollup-http-server/Cargo.toml similarity index 100% rename from linux/rollup/http/rollup-http-server/Cargo.toml rename to rollup-http/rollup-http-server/Cargo.toml diff --git a/linux/rollup/http/rollup-http-server/README.md b/rollup-http/rollup-http-server/README.md similarity index 100% rename from linux/rollup/http/rollup-http-server/README.md rename to rollup-http/rollup-http-server/README.md diff --git a/linux/rollup/http/rollup-http-server/build.sh b/rollup-http/rollup-http-server/build-with-toolchain.sh similarity index 87% rename from linux/rollup/http/rollup-http-server/build.sh rename to rollup-http/rollup-http-server/build-with-toolchain.sh index 5f7cbe65..4308d8f9 100755 --- a/linux/rollup/http/rollup-http-server/build.sh +++ b/rollup-http/rollup-http-server/build-with-toolchain.sh @@ -8,5 +8,6 @@ CONTAINER_BASE="${CONTAINER_BASE:-/opt/cartesi/tools}" docker run --rm -e USER=`id -u -n` -e GROUP=`id -g -n` -e UID=`id -u` -e GID=`id -g` -v `pwd`/../:$CONTAINER_BASE \ --env CC=riscv64-cartesi-linux-gnu-gcc --env CXX=riscv64-cartesi-linux-gnu-g++ --env CFLAGS="-march=$RISCV_ARCH -mabi=$RISCV_ABI" \ +--env CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER=riscv64-cartesi-linux-gnu-gcc \ -w $CONTAINER_BASE/rollup-http-server $TOOLCHAIN_IMAGE:$TOOLCHAIN_TAG \ cargo build --target riscv64gc-unknown-linux-gnu --release diff --git a/linux/rollup/http/rollup-http-server/build.rs b/rollup-http/rollup-http-server/build.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/build.rs rename to rollup-http/rollup-http-server/build.rs diff --git a/linux/rollup/http/rollup-http-server/src/config.rs b/rollup-http/rollup-http-server/src/config.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/src/config.rs rename to rollup-http/rollup-http-server/src/config.rs diff --git a/linux/rollup/http/rollup-http-server/src/dapp_process.rs b/rollup-http/rollup-http-server/src/dapp_process.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/src/dapp_process.rs rename to rollup-http/rollup-http-server/src/dapp_process.rs diff --git a/linux/rollup/http/rollup-http-server/src/http_service.rs b/rollup-http/rollup-http-server/src/http_service.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/src/http_service.rs rename to rollup-http/rollup-http-server/src/http_service.rs diff --git a/linux/rollup/http/rollup-http-server/src/lib.rs b/rollup-http/rollup-http-server/src/lib.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/src/lib.rs rename to rollup-http/rollup-http-server/src/lib.rs diff --git a/linux/rollup/http/rollup-http-server/src/main.rs b/rollup-http/rollup-http-server/src/main.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/src/main.rs rename to rollup-http/rollup-http-server/src/main.rs diff --git a/linux/rollup/http/rollup-http-server/src/rollup/bindings.c b/rollup-http/rollup-http-server/src/rollup/bindings.c similarity index 100% rename from linux/rollup/http/rollup-http-server/src/rollup/bindings.c rename to rollup-http/rollup-http-server/src/rollup/bindings.c diff --git a/linux/rollup/http/rollup-http-server/src/rollup/bindings.h b/rollup-http/rollup-http-server/src/rollup/bindings.h similarity index 100% rename from linux/rollup/http/rollup-http-server/src/rollup/bindings.h rename to rollup-http/rollup-http-server/src/rollup/bindings.h diff --git a/linux/rollup/http/rollup-http-server/src/rollup/bindings.rs b/rollup-http/rollup-http-server/src/rollup/bindings.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/src/rollup/bindings.rs rename to rollup-http/rollup-http-server/src/rollup/bindings.rs diff --git a/linux/rollup/http/rollup-http-server/src/rollup/mod.rs b/rollup-http/rollup-http-server/src/rollup/mod.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/src/rollup/mod.rs rename to rollup-http/rollup-http-server/src/rollup/mod.rs diff --git a/linux/rollup/http/rollup-http-server/tests/rollup-http-server-tests.rs b/rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs similarity index 100% rename from linux/rollup/http/rollup-http-server/tests/rollup-http-server-tests.rs rename to rollup-http/rollup-http-server/tests/rollup-http-server-tests.rs diff --git a/linux/rollup/http/rollup-http-server/tests/rollup_test_bindings.c b/rollup-http/rollup-http-server/tests/rollup_test_bindings.c similarity index 100% rename from linux/rollup/http/rollup-http-server/tests/rollup_test_bindings.c rename to rollup-http/rollup-http-server/tests/rollup_test_bindings.c diff --git a/linux/rollup/http/rollup-http-server/tests/rollup_test_bindings.h b/rollup-http/rollup-http-server/tests/rollup_test_bindings.h similarity index 100% rename from linux/rollup/http/rollup-http-server/tests/rollup_test_bindings.h rename to rollup-http/rollup-http-server/tests/rollup_test_bindings.h diff --git a/linux/utils/rollup-init b/rollup-http/rollup-init/rollup-init similarity index 93% rename from linux/utils/rollup-init rename to rollup-http/rollup-init/rollup-init index 2d5e25e1..53b3387b 100755 --- a/linux/utils/rollup-init +++ b/rollup-http/rollup-init/rollup-init @@ -16,7 +16,7 @@ # limitations under the License. # -busybox sh -c "/opt/cartesi/bin/rollup-http-server $*" +busybox sh -c "/usr/bin/rollup-http-server $*" MESSAGE="rollup-http-server exited with $? status" echo "$MESSAGE" echo "{\"payload\": \"$MESSAGE\"}" | rollup exception diff --git a/shasumfile b/shasumfile deleted file mode 100644 index 2f691555..00000000 --- a/shasumfile +++ /dev/null @@ -1,2 +0,0 @@ -e8d4d1882632eac7fd8e433b4eb4db014fd56e645fdad3b89be7d1ca4f20ca07 dep/linux-5.15.63-ctsi-2.tar.gz -cf69d000714d38da51b0eeb6cbc99bea8ccd9becf6d1cd30c64f7297d167afb6 dep/twuewand-3.0.0.tar.gz diff --git a/skel/etc/hostname b/skel/etc/hostname deleted file mode 100644 index 9af48ec4..00000000 --- a/skel/etc/hostname +++ /dev/null @@ -1 +0,0 @@ -cartesi-machine diff --git a/sys-utils/Makefile b/sys-utils/Makefile new file mode 100644 index 00000000..510b60c2 --- /dev/null +++ b/sys-utils/Makefile @@ -0,0 +1,36 @@ +# Copyright Cartesi and individual authors (see AUTHORS) +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +UTILITIES := xhalt yield rollup ioctl-echo-loop +UTILITIES_WITH_TOOLCHAIN := $(addsuffix -with-toolchain,$(UTILITIES)) + +all: $(UTILITIES) + +$(UTILITIES): + @$(MAKE) -C $@ + +with-toolchain: + @$(MAKE) $(UTILITIES_WITH_TOOLCHAIN) + +$(UTILITIES_WITH_TOOLCHAIN): + @$(MAKE) -C $@ with-toolchain + +clean: + @$(foreach utility,$(UTILITIES),$(MAKE) -C $(utility) clean;) + + +.PHONY: all with-toolchain $(UTILITIES) $(UTILITIES_WITH_TOOLCHAIN) diff --git a/skel/opt/cartesi/bin/init b/sys-utils/cartesi-init/cartesi-init similarity index 96% rename from skel/opt/cartesi/bin/init rename to sys-utils/cartesi-init/cartesi-init index a93a0469..c787e036 100755 --- a/skel/opt/cartesi/bin/init +++ b/sys-utils/cartesi-init/cartesi-init @@ -58,8 +58,8 @@ RC=$? # shutdown busybox mount -o ro,remount / busybox umount -af -if [ $RC != 0 ] && [ -x /opt/cartesi/bin/xhalt ]; then - /opt/cartesi/bin/xhalt "$RC" +if [ $RC != 0 ] && [ -x /usr/sbin/xhalt ]; then + /usr/sbin/xhalt "$RC" fi busybox poweroff -f diff --git a/linux/rollup/ioctl-echo-loop/Makefile b/sys-utils/ioctl-echo-loop/Makefile similarity index 82% rename from linux/rollup/ioctl-echo-loop/Makefile rename to sys-utils/ioctl-echo-loop/Makefile index 3c883b7e..be73ff91 100644 --- a/linux/rollup/ioctl-echo-loop/Makefile +++ b/sys-utils/ioctl-echo-loop/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +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) +STRIP = $(TOOLCHAIN_PREFIX)strip CFLAGS :=-Wall -pedantic -O2 -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: ioctl-echo-loop -ioctl-echo-loop: ioctl-echo-loop.c +ioctl-echo-loop.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: ioctl-echo-loop +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -ioctl-echo-loop.toolchain: +ioctl-echo-loop: ioctl-echo-loop.c $(RVCC) $(CFLAGS) -o ioctl-echo-loop ioctl-echo-loop.c $(STRIP) ioctl-echo-loop -extra.ext2.toolchain: +extra.ext2: ioctl-echo-loop mkdir -m 0755 ./extra cp ./ioctl-echo-loop ./extra/ioctl-echo-loop xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf ioctl-echo-loop extra.ext2 extra + @rm -rf ioctl-echo-loop extra.ext2 extra .PHONY: toolchain-exec toolchain-env diff --git a/linux/rollup/ioctl-echo-loop/ioctl-echo-loop.c b/sys-utils/ioctl-echo-loop/ioctl-echo-loop.c similarity index 100% rename from linux/rollup/ioctl-echo-loop/ioctl-echo-loop.c rename to sys-utils/ioctl-echo-loop/ioctl-echo-loop.c diff --git a/linux/utils/flashdrive b/sys-utils/misc/flashdrive similarity index 100% rename from linux/utils/flashdrive rename to sys-utils/misc/flashdrive diff --git a/linux/utils/readbe64 b/sys-utils/misc/readbe64 similarity index 100% rename from linux/utils/readbe64 rename to sys-utils/misc/readbe64 diff --git a/linux/utils/writebe64 b/sys-utils/misc/writebe64 similarity index 100% rename from linux/utils/writebe64 rename to sys-utils/misc/writebe64 diff --git a/linux/rollup/rollup/Makefile b/sys-utils/rollup/Makefile similarity index 82% rename from linux/rollup/rollup/Makefile rename to sys-utils/rollup/Makefile index 020dc685..2b81d6ed 100644 --- a/linux/rollup/rollup/Makefile +++ b/sys-utils/rollup/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +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) +STRIP = $(TOOLCHAIN_PREFIX)strip RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: rollup -rollup: rollup.cpp +rollup.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: rollup +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -rollup.toolchain: +rollup: rollup.cpp $(RVCXX) -std=c++17 -O2 -o rollup rollup.cpp $(STRIP) rollup -extra.ext2.toolchain: +extra.ext2: rollup mkdir -m 0755 ./extra cp ./rollup ./extra/rollup xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf rollup extra.ext2 extra + @rm -rf rollup extra.ext2 extra .PHONY: toolchain-exec toolchain-env diff --git a/linux/rollup/rollup/json.hpp b/sys-utils/rollup/json.hpp similarity index 100% rename from linux/rollup/rollup/json.hpp rename to sys-utils/rollup/json.hpp diff --git a/linux/rollup/rollup/rollup.cpp b/sys-utils/rollup/rollup.cpp similarity index 100% rename from linux/rollup/rollup/rollup.cpp rename to sys-utils/rollup/rollup.cpp diff --git a/linux/xhalt/.gitignore b/sys-utils/xhalt/.gitignore similarity index 100% rename from linux/xhalt/.gitignore rename to sys-utils/xhalt/.gitignore diff --git a/linux/xhalt/Makefile b/sys-utils/xhalt/Makefile similarity index 81% rename from linux/xhalt/Makefile rename to sys-utils/xhalt/Makefile index 0b50052a..7d77156f 100644 --- a/linux/xhalt/Makefile +++ b/sys-utils/xhalt/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +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) +STRIP = $(TOOLCHAIN_PREFIX)strip RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: xhalt -xhalt: xhalt.c +xhalt.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: xhalt +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -xhalt.toolchain: +xhalt: xhalt.c $(RVCC) -O2 -o xhalt xhalt.c $(STRIP) xhalt -extra.ext2.toolchain: +extra.ext2: xhalt mkdir -m 0755 ./extra cp ./xhalt ./extra/xhalt xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf xhalt extra.ext2 extra + @rm -rf xhalt extra.ext2 extra .PHONY: toolchain-exec toolchain-env diff --git a/linux/xhalt/README.md b/sys-utils/xhalt/README.md similarity index 100% rename from linux/xhalt/README.md rename to sys-utils/xhalt/README.md diff --git a/linux/xhalt/xhalt.c b/sys-utils/xhalt/xhalt.c similarity index 100% rename from linux/xhalt/xhalt.c rename to sys-utils/xhalt/xhalt.c diff --git a/linux/htif/.gitignore b/sys-utils/yield/.gitignore similarity index 100% rename from linux/htif/.gitignore rename to sys-utils/yield/.gitignore diff --git a/linux/htif/Makefile b/sys-utils/yield/Makefile similarity index 81% rename from linux/htif/Makefile rename to sys-utils/yield/Makefile index 85b16e55..18e756ae 100644 --- a/linux/htif/Makefile +++ b/sys-utils/yield/Makefile @@ -21,12 +21,14 @@ TOOLCHAIN_TAG ?= 0.16.0 RISCV_ARCH ?= rv64gc RISCV_ABI ?= lp64d -CROSS_COMPILE = riscv64-cartesi-linux-gnu- -RVCC = $(CROSS_COMPILE)gcc -RVCXX = $(CROSS_COMPILE)g++ -RVCOPY = $(CROSS_COMPILE)objcopy -RVDUMP = $(CROSS_COMPILE)objdump -STRIP = $(CROSS_COMPILE)strip +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) +STRIP = $(TOOLCHAIN_PREFIX)strip RISCV_CFLAGS :=-march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) CONTAINER_MAKE := /usr/bin/make @@ -35,17 +37,17 @@ KERNEL_HEADERS_PATH := /opt/riscv/usr/include all: yield -yield: yield.c +yield.with-toolchain with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -extra.ext2: yield +extra.ext2.with-toolchain: $(MAKE) toolchain-exec CONTAINER_COMMAND="$(CONTAINER_MAKE) $@.toolchain" -yield.toolchain: +yield: yield.c $(RVCC) -O2 -o yield yield.c $(STRIP) yield -extra.ext2.toolchain: +extra.ext2: yield mkdir -m 0755 ./extra cp ./yield ./extra/yield xgenext2fs -i 512 -b 8192 -d extra $(basename $@) @@ -72,6 +74,6 @@ toolchain-env: $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) clean: - \rm -rf yield extra.ext2 extra + @rm -rf yield extra.ext2 extra .PHONY: toolchain-exec toolchain-env diff --git a/linux/htif/README.md b/sys-utils/yield/README.md similarity index 100% rename from linux/htif/README.md rename to sys-utils/yield/README.md diff --git a/linux/htif/yield.c b/sys-utils/yield/yield.c similarity index 100% rename from linux/htif/yield.c rename to sys-utils/yield/yield.c