From 2a080556b3416def90a6719d15573eb4015f03a9 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 14 Jul 2023 12:29:23 -0300 Subject: [PATCH] feat: use init and entrypoint from device tree --- skel/sbin/init | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/skel/sbin/init b/skel/sbin/init index 422b06ad..9d98adba 100755 --- a/skel/sbin/init +++ b/skel/sbin/init @@ -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 @@ -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 @@ -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 @@ -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