Browse Source

toybox: add init and toysh configuration for testing

Waldemar Brodkorb 3 weeks ago
parent
commit
7be4de653c

+ 4 - 0
mk/image.mk

@@ -13,6 +13,8 @@ ifeq (${ADK_BINSH_ASH},y)
 BINSH:=ash
 else ifeq (${ADK_BINSH_BASH},y)
 BINSH:=bash
+else ifeq (${ADK_BINSH_TOYSH},y)
+BINSH:=toysh
 else ifeq (${ADK_BINSH_SASH},y)
 BINSH:=sash
 else ifeq (${ADK_BINSH_HUSH},y)
@@ -30,6 +32,8 @@ ifeq (${ADK_ROOTSH_ASH},y)
 ROOTSH:=/bin/ash
 else ifeq (${ADK_ROOTSH_BASH},y)
 ROOTSH:=/bin/bash
+else ifeq (${ADK_ROOTSH_TOYSH},y)
+ROOTSH:=/bin/toysh
 else ifeq (${ADK_ROOTSH_SASH},y)
 ROOTSH:=/bin/sash
 else ifeq (${ADK_ROOTSH_HUSH},y)

+ 1 - 0
package/sash/Makefile

@@ -16,6 +16,7 @@ include ${ADK_TOPDIR}/mk/package.mk
 
 $(eval $(call PKG_template,SASH,sash,${PKG_VERSION}-${PKG_RELEASE},${PKG_DEPENDS},${PKG_DESCR},${PKG_SECTION}))
 
+#TARGET_CFLAGS:=		-Wno-incompatible-pointer-types
 CONFIG_STYLE:=		manual
 INSTALL_STYLE:=		manual
 

+ 6 - 1
package/toybox/Makefile

@@ -24,11 +24,16 @@ XAKE_FLAGS+=		CC="gcc" V=1 PREFIX="$(WRKINST)"
 
 do-configure:
 	-rm $(WRKBUILD)/toys/other/swap*.c
+	-rm $(WRKBUILD)/toys/other/gpiod.c
+	-rm $(WRKBUILD)/toys/other/lsattr.c
+	-rm $(WRKBUILD)/toys/other/nsenter.c
 	-rm $(WRKBUILD)/toys/posix/getconf.c
 	-rm $(WRKBUILD)/toys/posix/iconv.c
-	cd $(WRKBUILD); CC="gcc" PATH='$(HOST_PATH)' $(MAKE) defconfig
+	cp ./files/config $(WRKBUILD)/.config
 
 toybox-install:
 	$(CP) $(WRKINST)/* $(IDIR_TOYBOX)/
+	$(INSTALL_DIR) $(IDIR_TOYBOX)/etc
+	$(CP) ./files/inittab $(IDIR_TOYBOX)/etc
 
 include $(ADK_TOPDIR)/mk/pkg-bottom.mk

+ 393 - 0
package/toybox/files/config

@@ -0,0 +1,393 @@
+#
+# Automatically generated make config: don't edit
+# ToyBox version: KCONFIG_VERSION
+# Tue Apr  8 13:12:22 2025
+#
+# CONFIG_TOYBOX_ON_ANDROID is not set
+# CONFIG_TOYBOX_FORK is not set
+
+#
+# Posix commands
+#
+CONFIG_BASENAME=y
+# CONFIG_CAL is not set
+CONFIG_CAT=y
+CONFIG_CHGRP=y
+CONFIG_CHOWN=y
+CONFIG_CHMOD=y
+# CONFIG_CKSUM is not set
+# CONFIG_CRC32 is not set
+# CONFIG_CMP is not set
+# CONFIG_COMM is not set
+CONFIG_CP=y
+CONFIG_MV=y
+# CONFIG_INSTALL is not set
+# CONFIG_CPIO is not set
+# CONFIG_CUT is not set
+CONFIG_DATE=y
+CONFIG_DD=y
+CONFIG_DF=y
+# CONFIG_DIRNAME is not set
+CONFIG_DU=y
+CONFIG_ECHO=y
+CONFIG_ENV=y
+# CONFIG_EXPAND is not set
+# CONFIG_FALSE is not set
+# CONFIG_FILE is not set
+# CONFIG_FIND is not set
+# CONFIG_FOLD is not set
+# CONFIG_GETCONF is not set
+# CONFIG_GREP is not set
+# CONFIG_EGREP is not set
+# CONFIG_FGREP is not set
+# CONFIG_HEAD is not set
+# CONFIG_ICONV is not set
+# CONFIG_ID is not set
+# CONFIG_ID_Z is not set
+# CONFIG_GROUPS is not set
+# CONFIG_LOGNAME is not set
+# CONFIG_WHOAMI is not set
+CONFIG_KILL=y
+# CONFIG_KILLALL5 is not set
+# CONFIG_LINK is not set
+CONFIG_LN=y
+# CONFIG_LOGGER is not set
+CONFIG_LS=y
+CONFIG_MKDIR=y
+# CONFIG_MKDIR_Z is not set
+# CONFIG_MKFIFO is not set
+# CONFIG_MKFIFO_Z is not set
+# CONFIG_NICE is not set
+# CONFIG_NL is not set
+# CONFIG_NOHUP is not set
+# CONFIG_OD is not set
+# CONFIG_PASTE is not set
+# CONFIG_PATCH is not set
+# CONFIG_PRINTF is not set
+CONFIG_PS=y
+CONFIG_TOP=y
+# CONFIG_IOTOP is not set
+# CONFIG_PGREP is not set
+# CONFIG_PKILL is not set
+CONFIG_PWD=y
+# CONFIG_RENICE is not set
+CONFIG_RM=y
+CONFIG_RMDIR=y
+# CONFIG_SED is not set
+# CONFIG_SLEEP is not set
+# CONFIG_SORT is not set
+CONFIG_SORT_FLOAT=y
+# CONFIG_SPLIT is not set
+# CONFIG_STRINGS is not set
+# CONFIG_TAIL is not set
+# CONFIG_TAR is not set
+# CONFIG_TEE is not set
+# CONFIG_TEST is not set
+CONFIG_TEST_GLUE=y
+# CONFIG_TIME is not set
+# CONFIG_TOUCH is not set
+# CONFIG_TRUE is not set
+# CONFIG_TSORT is not set
+# CONFIG_TTY is not set
+# CONFIG_ULIMIT is not set
+# CONFIG_ARCH is not set
+CONFIG_UNAME=y
+# CONFIG_UNIQ is not set
+# CONFIG_UNLINK is not set
+# CONFIG_UUDECODE is not set
+# CONFIG_UUENCODE is not set
+# CONFIG_WC is not set
+# CONFIG_WHO is not set
+CONFIG_XARGS=y
+
+#
+# Pending (unfinished) commands
+#
+# CONFIG_ARP is not set
+# CONFIG_ARPING is not set
+# CONFIG_AWK is not set
+# CONFIG_BC is not set
+# CONFIG_BOOTCHARTD is not set
+# CONFIG_BRCTL is not set
+# CONFIG_CHSH is not set
+# CONFIG_CROND is not set
+# CONFIG_CRONTAB is not set
+# CONFIG_CSPLIT is not set
+# CONFIG_DHCP is not set
+# CONFIG_DHCP6 is not set
+# CONFIG_DHCPD is not set
+# CONFIG_DEBUG_DHCP is not set
+# CONFIG_DIFF is not set
+# CONFIG_DUMPLEASES is not set
+# CONFIG_EXPR is not set
+# CONFIG_FDISK is not set
+# CONFIG_FSCK is not set
+# CONFIG_GETFATTR is not set
+CONFIG_GETTY=y
+# CONFIG_GITCOMPAT is not set
+# CONFIG_GITCLONE is not set
+# CONFIG_GITINIT is not set
+# CONFIG_GITREMOTE is not set
+# CONFIG_GITFETCH is not set
+# CONFIG_GITCHECKOUT is not set
+# CONFIG_GROUPADD is not set
+# CONFIG_GROUPDEL is not set
+# CONFIG_HEXDUMP is not set
+# CONFIG_HD is not set
+CONFIG_INIT=y
+# CONFIG_IP is not set
+# CONFIG_IPCRM is not set
+# CONFIG_IPCS is not set
+# CONFIG_KLOGD is not set
+# CONFIG_LAST is not set
+# CONFIG_LSOF is not set
+# CONFIG_MAN is not set
+# CONFIG_MDEV is not set
+# CONFIG_MDEV_CONF is not set
+# CONFIG_MODPROBE is not set
+# CONFIG_MORE is not set
+# CONFIG_ROUTE is not set
+CONFIG_SH=y
+# CONFIG_BREAK is not set
+# CONFIG_CD is not set
+# CONFIG_CONTINUE is not set
+# CONFIG_DECLARE is not set
+# CONFIG_EXIT is not set
+# CONFIG_SET is not set
+# CONFIG_UNSET is not set
+# CONFIG_EVAL is not set
+# CONFIG_EXEC is not set
+# CONFIG_EXPORT is not set
+# CONFIG_JOBS is not set
+# CONFIG_LOCAL is not set
+# CONFIG_RETURN is not set
+# CONFIG_SHIFT is not set
+# CONFIG_SOURCE is not set
+# CONFIG_WAIT is not set
+# CONFIG_STRACE is not set
+# CONFIG_STTY is not set
+# CONFIG_SULOGIN is not set
+# CONFIG_SYSLOGD is not set
+# CONFIG_TCPSVD is not set
+# CONFIG_TELNET is not set
+# CONFIG_TELNETD is not set
+# CONFIG_TFTP is not set
+# CONFIG_TFTPD is not set
+# CONFIG_TR is not set
+# CONFIG_TRACEROUTE is not set
+# CONFIG_USERADD is not set
+# CONFIG_USERDEL is not set
+# CONFIG_VI is not set
+# CONFIG_XZCAT is not set
+
+#
+# Other commands
+#
+# CONFIG_ACPI is not set
+# CONFIG_ASCII is not set
+# CONFIG_UNICODE is not set
+# CONFIG_BASE64 is not set
+# CONFIG_BASE32 is not set
+# CONFIG_BLKDISCARD is not set
+# CONFIG_BLKID is not set
+# CONFIG_FSTYPE is not set
+# CONFIG_BLOCKDEV is not set
+# CONFIG_BUNZIP2 is not set
+# CONFIG_BZCAT is not set
+# CONFIG_CHCON is not set
+# CONFIG_CHROOT is not set
+# CONFIG_CHRT is not set
+CONFIG_CLEAR=y
+# CONFIG_COUNT is not set
+# CONFIG_DEVMEM is not set
+# CONFIG_DOS2UNIX is not set
+# CONFIG_UNIX2DOS is not set
+# CONFIG_EJECT is not set
+# CONFIG_FACTOR is not set
+# CONFIG_FALLOCATE is not set
+# CONFIG_FLOCK is not set
+# CONFIG_FMT is not set
+CONFIG_FREE=y
+# CONFIG_FREERAMDISK is not set
+# CONFIG_FSFREEZE is not set
+# CONFIG_FSYNC is not set
+# CONFIG_GETOPT is not set
+# CONFIG_GPIODETECT is not set
+# CONFIG_GPIOFIND is not set
+# CONFIG_GPIOINFO is not set
+# CONFIG_GPIOGET is not set
+# CONFIG_GPIOSET is not set
+# CONFIG_HELP is not set
+# CONFIG_HEXEDIT is not set
+# CONFIG_HWCLOCK is not set
+# CONFIG_I2CDETECT is not set
+# CONFIG_I2CDUMP is not set
+# CONFIG_I2CGET is not set
+# CONFIG_I2CSET is not set
+# CONFIG_I2CTRANSFER is not set
+# CONFIG_INOTIFYD is not set
+# CONFIG_INSMOD is not set
+# CONFIG_IONICE is not set
+# CONFIG_IORENICE is not set
+# CONFIG_LINUX32 is not set
+# CONFIG_LOGIN is not set
+# CONFIG_LOSETUP is not set
+# CONFIG_LSATTR is not set
+# CONFIG_CHATTR is not set
+# CONFIG_LSMOD is not set
+# CONFIG_LSPCI is not set
+# CONFIG_LSUSB is not set
+# CONFIG_MAKEDEVS is not set
+# CONFIG_MCOOKIE is not set
+# CONFIG_MEMEATER is not set
+# CONFIG_MIX is not set
+# CONFIG_MKPASSWD is not set
+# CONFIG_MKSWAP is not set
+# CONFIG_MODINFO is not set
+# CONFIG_MOUNTPOINT is not set
+# CONFIG_NBD_CLIENT is not set
+# CONFIG_NBD_SERVER is not set
+# CONFIG_UNSHARE is not set
+# CONFIG_NSENTER is not set
+# CONFIG_ONEIT is not set
+# CONFIG_OPENVT is not set
+# CONFIG_CHVT is not set
+# CONFIG_DEALLOCVT is not set
+# CONFIG_PARTPROBE is not set
+# CONFIG_PIVOT_ROOT is not set
+# CONFIG_PMAP is not set
+# CONFIG_PRINTENV is not set
+# CONFIG_PWDX is not set
+# CONFIG_PWGEN is not set
+# CONFIG_READAHEAD is not set
+# CONFIG_READELF is not set
+# CONFIG_READLINK is not set
+# CONFIG_REALPATH is not set
+CONFIG_REBOOT=y
+# CONFIG_RESET is not set
+# CONFIG_REV is not set
+# CONFIG_RMMOD is not set
+# CONFIG_RTCWAKE is not set
+# CONFIG_SETFATTR is not set
+# CONFIG_SETSID is not set
+# CONFIG_SHA3SUM is not set
+# CONFIG_SHRED is not set
+# CONFIG_SHUF is not set
+CONFIG_STAT=y
+# CONFIG_SWAPOFF is not set
+# CONFIG_SWAPON is not set
+# CONFIG_SWITCH_ROOT is not set
+# CONFIG_SYSCTL is not set
+# CONFIG_TAC is not set
+# CONFIG_NPROC is not set
+# CONFIG_TASKSET is not set
+# CONFIG_TIMEOUT is not set
+# CONFIG_TRUNCATE is not set
+# CONFIG_TS is not set
+# CONFIG_UCLAMPSET is not set
+CONFIG_UPTIME=y
+# CONFIG_USLEEP is not set
+# CONFIG_UUIDGEN is not set
+# CONFIG_VCONFIG is not set
+# CONFIG_VMSTAT is not set
+# CONFIG_W is not set
+# CONFIG_WATCH is not set
+# CONFIG_WATCHDOG is not set
+# CONFIG_WHICH is not set
+# CONFIG_XXD is not set
+# CONFIG_YES is not set
+
+#
+# Networking commands
+#
+# CONFIG_FTPGET is not set
+# CONFIG_FTPPUT is not set
+# CONFIG_HOST is not set
+# CONFIG_HTTPD is not set
+CONFIG_IFCONFIG=y
+# CONFIG_MICROCOM is not set
+# CONFIG_NETCAT is not set
+CONFIG_NETSTAT=y
+CONFIG_PING=y
+# CONFIG_RFKILL is not set
+# CONFIG_SNTP is not set
+# CONFIG_TUNCTL is not set
+# CONFIG_WGET is not set
+# CONFIG_WGET_LIBTLS is not set
+
+#
+# Linux Standard Base commands
+#
+CONFIG_DMESG=y
+# CONFIG_GZIP is not set
+# CONFIG_GUNZIP is not set
+# CONFIG_ZCAT is not set
+CONFIG_HOSTNAME=y
+# CONFIG_DNSDOMAINNAME is not set
+# CONFIG_KILLALL is not set
+# CONFIG_MD5SUM is not set
+# CONFIG_SHA1SUM is not set
+# CONFIG_SHA224SUM is not set
+# CONFIG_SHA256SUM is not set
+# CONFIG_SHA384SUM is not set
+# CONFIG_SHA512SUM is not set
+# CONFIG_MKNOD is not set
+# CONFIG_MKNOD_Z is not set
+# CONFIG_MKTEMP is not set
+CONFIG_MOUNT=y
+# CONFIG_PASSWD is not set
+# CONFIG_PASSWD_SAD is not set
+# CONFIG_PIDOF is not set
+# CONFIG_SEQ is not set
+# CONFIG_SU is not set
+CONFIG_SYNC=y
+CONFIG_UMOUNT=y
+
+#
+# Example commands
+#
+# CONFIG_DEMO_MANY_OPTIONS is not set
+# CONFIG_DEMO_NUMBER is not set
+# CONFIG_DEMO_SCANKEY is not set
+# CONFIG_DEMO_UTF8TOWC is not set
+# CONFIG_HELLO is not set
+# CONFIG_HOSTID is not set
+# CONFIG_LOGPATH is not set
+# CONFIG_SKELETON is not set
+# CONFIG_SKELETON_ALIAS is not set
+
+#
+# Android commands
+#
+# CONFIG_GETENFORCE is not set
+# CONFIG_LOAD_POLICY is not set
+# CONFIG_LOG is not set
+# CONFIG_RESTORECON is not set
+# CONFIG_RUNCON is not set
+# CONFIG_SENDEVENT is not set
+# CONFIG_SETENFORCE is not set
+
+#
+# 
+#
+
+#
+# Toybox global settings
+#
+CONFIG_TOYBOX=y
+CONFIG_TOYBOX_SUID=y
+CONFIG_TOYBOX_LSM_NONE=y
+# CONFIG_TOYBOX_SELINUX is not set
+# CONFIG_TOYBOX_SMACK is not set
+# CONFIG_TOYBOX_LIBCRYPTO is not set
+# CONFIG_TOYBOX_LIBZ is not set
+CONFIG_TOYBOX_FLOAT=y
+CONFIG_TOYBOX_HELP=y
+CONFIG_TOYBOX_HELP_DASHDASH=y
+CONFIG_TOYBOX_ZHELP=y
+# CONFIG_TOYBOX_FREE is not set
+# CONFIG_TOYBOX_NORECURSE is not set
+# CONFIG_TOYBOX_DEBUG is not set
+CONFIG_TOYBOX_UID_SYS=100
+CONFIG_TOYBOX_UID_USR=500
+CONFIG_TOYBOX_FORCE_NOMMU=y

+ 1 - 0
package/toybox/files/inittab

@@ -0,0 +1 @@
+/dev/ttySC2::askfirst:-/bin/sh

+ 16 - 0
package/toybox/patches/patch-main_c

@@ -0,0 +1,16 @@
+--- toybox-0.8.12.orig/main.c	2025-01-18 21:20:33.000000000 +0100
++++ toybox-0.8.12/main.c	2025-04-07 09:40:53.646935573 +0200
+@@ -179,13 +179,6 @@ void toy_singleinit(struct toy_list *whi
+     toys.old_umask = umask(0);
+     if (!(which->flags & TOYFLAG_UMASK)) umask(toys.old_umask);
+ 
+-    // Try user's locale, but if that isn't UTF-8 merge in a UTF-8 locale's
+-    // character type data. (Fall back to en_US for MacOS.)
+-    setlocale(LC_CTYPE, "");
+-    if (strcmp("UTF-8", nl_langinfo(CODESET)))
+-      uselocale(newlocale(LC_CTYPE_MASK, "C.UTF-8", 0) ? :
+-        newlocale(LC_CTYPE_MASK, "en_US.UTF-8", 0));
+-
+     if (which->flags & TOYFLAG_LINEBUF) btype = _IOLBF;
+     else if (which->flags & TOYFLAG_NOBUF) btype = _IONBF;
+     else buf = xmalloc(4096);

+ 12 - 0
package/toybox/patches/patch-toys_pending_init_c

@@ -0,0 +1,12 @@
+--- toybox-0.8.12.orig/toys/pending/init.c	2025-01-18 21:20:33.000000000 +0100
++++ toybox-0.8.12/toys/pending/init.c	2025-04-07 15:31:14.276281021 +0200
+@@ -246,8 +246,7 @@ static pid_t final_run(struct action_lis
+ 
+   sigfillset(&signal_set);
+   sigprocmask(SIG_BLOCK, &signal_set, NULL);
+-  if (x->action & ASKFIRST) pid = fork();
+-  else pid = vfork();
++  pid = vfork();
+ 
+   if (pid > 0) {
+     //parent process or error

+ 29 - 0
package/toybox/patches/patch-toys_pending_sh_c

@@ -0,0 +1,29 @@
+--- toybox-0.8.12.orig/toys/pending/sh.c	2025-01-18 21:20:33.000000000 +0100
++++ toybox-0.8.12/toys/pending/sh.c	2025-04-07 16:43:09.861935892 +0200
+@@ -1398,18 +1398,6 @@ static int run_subshell(char *str, int l
+   pid_t pid;
+ //dprintf(2, "%d run_subshell %.*s\n", getpid(), len, str); debug_show_fds();
+   // The with-mmu path is significantly faster.
+-  if (CFG_TOYBOX_FORK) {
+-    if ((pid = fork())<0) perror_msg("fork");
+-    else if (!pid) {
+-      call_function()->pp = (void *)1;
+-      if (str) {
+-        TT.ff->source = fmemopen(str, len, "r");
+-        longjmp(TT.forkchild, 1);
+-      }
+-    }
+-
+-  // On nommu vfork, exec /proc/self/exe, and pipe state data to ourselves.
+-  } else {
+     int pipes[2];
+     unsigned i;
+     char **oldenv = environ, *ss = str ? : pl2str(TT.ff->pl->next, 0);
+@@ -1446,7 +1434,6 @@ static int run_subshell(char *str, int l
+     dprintf(pipes[1], "0 0\n%.*s\n", len, ss);
+     if (!str) free(ss);
+     close(pipes[1]);
+-  }
+ 
+   return pid;
+ }

+ 16 - 0
target/config/Config.in.runtime

@@ -22,6 +22,10 @@ config ADK_RUNTIME_INIT_SYSV
 	depends on ADK_PACKAGE_BUSYBOX && \
 		   !ADK_TARGET_SYSTEM_SIPEED_MAIX_BIT
 
+config ADK_RUNTIME_INIT_TOYBOX
+	bool "Use toybox init"
+	select ADK_PACKAGE_TOYBOX
+
 config ADK_RUNTIME_INIT_SIMPLEINIT
 	bool "Use a very simple init"
 	select ADK_PACKAGE_SIMPLEINIT
@@ -421,6 +425,12 @@ config ADK_ROOTSH_HUSH
 	help
 	  hush shell from busybox.
 
+config ADK_ROOTSH_TOYSH
+	bool "toysh (Shell compatible with non-MMU systems)"
+	select ADK_PACKAGE_TOYBOX if !ADK_APPLIANCE_TOOLCHAIN
+	help
+	  ToyBox shell.
+
 config ADK_ROOTSH_SASH
 	bool "sash (Shell compatible with non-MMU systems)"
 	select ADK_PACKAGE_SASH if !ADK_APPLIANCE_TOOLCHAIN
@@ -480,6 +490,12 @@ config ADK_BINSH_HUSH
 	help
 	  hush shell.
 
+config ADK_BINSH_TOYSH
+	bool "toysh (toybox Shell)"
+	select ADK_PACKAGE_TOYBOX if !ADK_APPLIANCE_TOOLCHAIN
+	help
+	  sash shell.
+
 config ADK_BINSH_SASH
 	bool "sash (Standalone Shell)"
 	select ADK_PACKAGE_SASH if !ADK_APPLIANCE_TOOLCHAIN