From 37e3f43686d9a82c9709435ad0105ecd21749c41 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 14 Jul 2023 12:29:23 -0300 Subject: [PATCH] feat!: new init system using init and entrypoint from device tree --- Dockerfile | 13 --- linux/utils/flashdrive | 4 +- skel/opt/cartesi/bin/init | 127 +++++++++++++-------------- skel/opt/cartesi/etc/motd | 11 --- skel/opt/cartesi/var/run/random-seed | Bin 4096 -> 0 bytes 5 files changed, 63 insertions(+), 92 deletions(-) delete mode 100644 skel/opt/cartesi/etc/motd delete mode 100644 skel/opt/cartesi/var/run/random-seed 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 ccc19588fe6a87786fa38ec72c6390c652364817..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmV+b5dZ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