Skip to content

Commit

Permalink
feat: use init and entrypoint from device tree
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Jul 17, 2023
1 parent f64718c commit 2a08055
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions skel/sbin/init
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/busybox sh

# Copyright 2019 Cartesi Pte. Ltd.
# Copyright 2023 Cartesi Pte. Ltd.
#
# 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
Expand All @@ -13,11 +13,6 @@
# the License.
#

# rndaddentropy can be in different places, make sure we can find it
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
Expand All @@ -26,31 +21,27 @@ 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

# 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

# net
[ -f /etc/hostname ] && busybox hostname -F /etc/hostname
busybox ifconfig lo 127.0.0.1

# cmdline application
if [ -n "$*" ]; then
[ -f /etc/environment ] && \
source /etc/environment && \
export PATH=/opt/cartesi/bin:"$PATH" # put it back on PATH
# custom init
if [ -f /proc/device-tree/cartesi/init ]; then
. /proc/device-tree/cartesi/init
fi

# use entrypoint from device tree if not empty, otherwise fallback to cmdline from bootargs
if [ -s /proc/device-tree/cartesi/entrypoint ]; then
ENTRYPOINT=". /proc/device-tree/cartesi/entrypoint"
else
ENTRYPOINT="$*"
fi

# application entrypoint
if [ -n "$ENTRYPOINT" ]; then
[ -f /etc/environment ] && . /etc/environment
# put cartesi tools on PATH
export PATH=/opt/cartesi/bin:"$PATH"

# can login as dapp user?
if [ ! "$single" == "yes" ] && busybox id dapp &> /dev/null; then
Expand All @@ -67,11 +58,11 @@ if [ -n "$*" ]; then
export HOME=~root USER=root LOGNAME=root
fi

# execute cmdline
# execute entrypoint
cd $HOME &&
busybox setsid \
busybox cttyhack \
busybox su -p $USER -c "$*"
busybox su -p $USER -c "$ENTRYPOINT"
else
echo "Nothing to do."
fi
Expand Down

0 comments on commit 2a08055

Please sign in to comment.