diff --git a/Dockerfile b/Dockerfile index 0f833da3..9109d5ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,18 +45,6 @@ RUN mkdir -p ${BUILD_BASE}linux-sources && \ make -C ${BUILD_BASE}linux-sources headers_install INSTALL_HDR_PATH=/usr && \ rm ${BUILD_BASE}${LINUX_SOURCES_FILEPATH} -# copy & extract rndaddentropy -# ------------------------------------------------------------------------------ -COPY ${RNDADDENTROPY_FILEPATH} ${BUILD_BASE}${RNDADDENTROPY_FILEPATH} -RUN mkdir -p ${BUILD_BASE}/twuewand && \ - tar xf ${BUILD_BASE}${RNDADDENTROPY_FILEPATH} \ - --strip-components=1 -C ${BUILD_BASE}twuewand && \ - rm ${BUILD_BASE}${RNDADDENTROPY_FILEPATH} - -RUN cd ${BUILD_BASE}twuewand/rndaddentropy/ && \ - make all CFLAGS="-O2 -Wno-error" && \ - strip rndaddentropy - # copy tools COPY linux/ ${BUILD_BASE}tools/linux/ @@ -87,7 +75,6 @@ ARG MACHINE_EMULATOR_TOOLS_TAR_GZ=machine-emulator-tools.tar.gz COPY skel/ ${STAGING_BASE} RUN mkdir -p ${STAGING_BIN} && \ - cp ${BUILD_BASE}twuewand/rndaddentropy/rndaddentropy ${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} && \ diff --git a/linux/utils/flashdrive b/linux/utils/flashdrive index e5948cb3..4f217d73 100755 --- a/linux/utils/flashdrive +++ b/linux/utils/flashdrive @@ -16,8 +16,8 @@ # limitations under the License. # -for t in /dev/mtdblock*; do - name=$(busybox cat /sys/block/$(busybox basename $t)/device/name) +for t in /dev/pmem*; do + name=$(busybox cat /run/drive-label/$(busybox basename $t)) if [ "$name" = $1 ]; then echo $t exit 0 diff --git a/skel/opt/cartesi/bin/init b/skel/opt/cartesi/bin/init index 7995d1ee..a056a0d4 100755 --- a/skel/opt/cartesi/bin/init +++ b/skel/opt/cartesi/bin/init @@ -1,85 +1,80 @@ #!/bin/busybox sh -# 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. -# - -export PATH=/opt/cartesi/bin:"$PATH" - -[ ! -f /opt/cartesi/etc/motd -o "$splash" == "no" ] || busybox cat /opt/cartesi/etc/motd - # mount busybox mkdir -p /dev/pts /dev/shm -busybox mount -t proc proc /proc -o nosuid,nodev,noexec -busybox mount -t sysfs sys /sys -o nosuid,nodev,noexec -busybox mount -t devpts devpts /dev/pts -o nosuid,noexec,gid=5,mode=620 -busybox mount -t tmpfs tmpfs /dev/shm -o nosuid,nodev,mode=1777 -#busybox mdev -s +busybox mount -o nosuid,nodev,noexec -t proc proc /proc +busybox mount -o nosuid,noexec,mode=620,gid=5 -t devpts devpts /dev/pts +busybox mount -o nosuid,nodev,mode=1777 -t tmpfs tmpfs /dev/shm +busybox mount -o nosuid,nodev,noexec -t sysfs sys /sys +[ -d /tmp ] && busybox mount -o nosuid,nodev,mode=1777 -t tmpfs tmpfs /tmp +[ -d /run ] && busybox mount -o nosuid,nodev,mode=0755 -t tmpfs tmpfs /run -# rand -if [ -f /opt/cartesi/var/run/random-seed ]; then - rndaddentropy < /opt/cartesi/var/run/random-seed - busybox chmod 600 /opt/cartesi/var/run/random-seed -fi - -# disk -if [ -d /mnt ]; then - (cd /sys/block && for DEV in *; do - [ ! "$DEV" = "mtdblock0" ] && \ - NAME=$(busybox cat /sys/block/"$DEV"/device/name) && \ - busybox mkdir "/mnt/$NAME" && \ - busybox mount "/dev/$DEV" "/mnt/$NAME" - done) -fi +# system config +[ -f /etc/sysctl.conf ] && busybox sysctl -pq # net [ -f /etc/hostname ] && busybox hostname -F /etc/hostname -busybox ifconfig lo 127.0.0.1 +[ -z "$noloopback" ] && busybox ifconfig lo up -# cmdline application -if [ -n "$*" ]; then - [ -f /etc/environment ] && \ - source /etc/environment && \ - export PATH=/opt/cartesi/bin:"$PATH" # put it back on PATH +# source environment +[ -f /etc/environment ] && . /etc/environment +export PATH="$PATH:/opt/cartesi/bin" - # can login as dapp user? - if [ ! "$single" == "yes" ] && busybox id dapp &> /dev/null; then - if [ -c /dev/rollup ]; then - busybox chown root:dapp /dev/rollup - busybox chmod 660 /dev/rollup - fi - if [ -c /dev/yield ]; then - busybox chown root:dapp /dev/yield - busybox chmod 660 /dev/yield - fi - export HOME=~dapp USER=dapp LOGNAME=dapp - else - export HOME=~root USER=root LOGNAME=root - fi +# execute init from device tree when available +[ -f /proc/device-tree/cartesi-machine/init ] && . /proc/device-tree/cartesi-machine/init - # execute cmdline - cd $HOME && +# use entrypoint from device tree when available, otherwise from command line +if [ -s /proc/device-tree/cartesi-machine/entrypoint ]; then + ENTRYPOINT=$(busybox cat /proc/device-tree/cartesi-machine/entrypoint) +elif [ -n "$*" ]; then + ENTRYPOINT="$*" +fi + +# is entrypoint not empty? +if [ -n "$ENTRYPOINT" ]; then + USER=${USER:-root} + 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 + + # execute entrypoint + (cd $WORKDIR && + USER=$USER LOGNAME=$USER HOME="$HOME" \ busybox setsid \ busybox cttyhack \ - busybox su -p $USER -c "$*" - RC=$? + busybox su -p $USER -c "$ENTRYPOINT") else echo "Nothing to do." - RC=0 fi +RC=$? +# shutdown busybox mount -o ro,remount / busybox umount -af -[ $RC == 0 ] && busybox poweroff -f || xhalt "$RC" +if [ $RC != 0 ] && [ -x /opt/cartesi/bin/xhalt ]; then + /opt/cartesi/bin/xhalt "$RC" +fi +busybox poweroff -f + +# 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. +# \ No newline at end of file diff --git a/skel/opt/cartesi/etc/motd b/skel/opt/cartesi/etc/motd deleted file mode 100644 index b4a952fb..00000000 --- a/skel/opt/cartesi/etc/motd +++ /dev/null @@ -1,11 +0,0 @@ - - . - / \ - / \ -\---/---\ /----\ - \ X \ - \----/ \---/---\ - \ / CARTESI - \ / MACHINE - ' - diff --git a/skel/opt/cartesi/var/run/random-seed b/skel/opt/cartesi/var/run/random-seed deleted file mode 100644 index ccc19588..00000000 Binary files a/skel/opt/cartesi/var/run/random-seed and /dev/null differ