-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: new init system using init and entrypoint from device tree
- Loading branch information
Showing
5 changed files
with
63 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
# |
This file was deleted.
Oops, something went wrong.
Binary file not shown.