aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-04-28 01:26:38 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-04-28 01:26:38 +0000
commitac71f40ce651f777701e1a59d71e4d37bc029e6e (patch)
tree5dbbb5fd7edc0e5025ee19f52aea2a52fee72b1c
parentd75fcfe11695b891bc7907561408a449602e9564 (diff)
parent45cea8a8382aeb40108db5f841d52b3163624fa1 (diff)
downloadtoybox-ac71f40ce651f777701e1a59d71e4d37bc029e6e.tar.gz
Change-Id: Iefe3f138dbaf79c991c0b7932f98ca21c18d0365
-rw-r--r--.config-linux2
-rw-r--r--.config-mac2
-rw-r--r--Android.bp2
-rw-r--r--METADATA4
-rw-r--r--Makefile2
-rw-r--r--android/device/generated/flags.h4
-rw-r--r--android/device/generated/help.h2
-rw-r--r--android/device/generated/newtoys.h2
-rw-r--r--android/linux/generated/config.h4
-rw-r--r--android/linux/generated/flags.h14
-rw-r--r--android/linux/generated/help.h2
-rw-r--r--android/linux/generated/newtoys.h2
-rw-r--r--android/mac/generated/config.h4
-rw-r--r--android/mac/generated/flags.h14
-rw-r--r--android/mac/generated/help.h2
-rw-r--r--android/mac/generated/newtoys.h2
-rw-r--r--lib/deflate.c7
-rwxr-xr-xmkroot/mkroot.sh309
-rwxr-xr-xmkroot/record-commands (renamed from scripts/record-commands)0
-rwxr-xr-xmkroot/root/dropbear (renamed from scripts/root/dropbear)2
-rwxr-xr-xmkroot/root/dynamic (renamed from scripts/root/dynamic)2
-rwxr-xr-xmkroot/root/overlay3
-rwxr-xr-xmkroot/root/plumbing (renamed from scripts/root/plumbing)0
-rwxr-xr-xmkroot/root/tests (renamed from scripts/root/tests)2
-rwxr-xr-xmkroot/testroot.sh (renamed from scripts/test_mkroot.sh)19
-rwxr-xr-xscripts/mkroot.sh309
-rwxr-xr-xscripts/root/overlay3
-rw-r--r--toys/other/oneit.c15
-rw-r--r--toys/other/vmstat.c117
-rw-r--r--toys/posix/ls.c2
-rw-r--r--toys/posix/tar.c3
-rw-r--r--toys/posix/test.c3
-rwxr-xr-xwww/faq.html4
-rw-r--r--www/roadmap.html23
34 files changed, 453 insertions, 434 deletions
diff --git a/.config-linux b/.config-linux
index e5e2e3da..73e55ac9 100644
--- a/.config-linux
+++ b/.config-linux
@@ -99,7 +99,7 @@ CONFIG_EXPR=y
# CONFIG_FALSE is not set
# CONFIG_FDISK is not set
CONFIG_FGREP=y
-# CONFIG_FILE is not set
+CONFIG_FILE=y
CONFIG_FIND=y
# CONFIG_FLOCK is not set
# CONFIG_FMT is not set
diff --git a/.config-mac b/.config-mac
index 95c9df13..6ff9493a 100644
--- a/.config-mac
+++ b/.config-mac
@@ -99,7 +99,7 @@ CONFIG_EXPR=y
# CONFIG_FALSE is not set
# CONFIG_FDISK is not set
CONFIG_FGREP=y
-# CONFIG_FILE is not set
+CONFIG_FILE=y
CONFIG_FIND=y
# CONFIG_FLOCK is not set
# CONFIG_FMT is not set
diff --git a/Android.bp b/Android.bp
index 9912fe86..f6a06108 100644
--- a/Android.bp
+++ b/Android.bp
@@ -98,6 +98,7 @@ all_srcs = [
"toys/posix/du.c",
"toys/posix/echo.c",
"toys/posix/env.c",
+ "toys/posix/file.c",
"toys/posix/find.c",
"toys/posix/getconf.c",
"toys/posix/grep.c",
@@ -223,7 +224,6 @@ device_srcs = [
"toys/posix/df.c",
"toys/posix/expand.c",
"toys/posix/false.c",
- "toys/posix/file.c",
"toys/posix/iconv.c",
"toys/posix/kill.c",
"toys/posix/logger.c",
diff --git a/METADATA b/METADATA
index 16647e4b..0f8e19e8 100644
--- a/METADATA
+++ b/METADATA
@@ -13,11 +13,11 @@ third_party {
type: GIT
value: "https://github.com/landley/toybox"
}
- version: "704278e45d0441c5a13777af727e4159f2ebffd9"
+ version: "d45ee3a2bc6271110312f01be867a9b6b91dd07f"
license_type: UNENCUMBERED
last_upgrade_date {
year: 2023
month: 4
- day: 10
+ day: 19
}
}
diff --git a/Makefile b/Makefile
index f51cd48c..52f0851c 100644
--- a/Makefile
+++ b/Makefile
@@ -77,7 +77,7 @@ tests: toybox
scripts/test.sh
root:
- scripts/mkroot.sh $(MAKEFLAGS)
+ mkroot/mkroot.sh $(MAKEFLAGS)
run_root:
cd root/"$${CROSS:-host}" && ./run-qemu.sh
diff --git a/android/device/generated/flags.h b/android/device/generated/flags.h
index 55672500..ef9fc67a 100644
--- a/android/device/generated/flags.h
+++ b/android/device/generated/flags.h
@@ -1824,9 +1824,9 @@
#undef FLAG_S
#endif
-// ls (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]
+// ls (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]
#undef OPTSTR_ls
-#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]"
+#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]"
#ifdef CLEANUP_ls
#undef CLEANUP_ls
#undef FOR_ls
diff --git a/android/device/generated/help.h b/android/device/generated/help.h
index d771c2f7..72a74f50 100644
--- a/android/device/generated/help.h
+++ b/android/device/generated/help.h
@@ -538,7 +538,7 @@
#define HELP_time "usage: time [-pv] COMMAND...\n\nRun command line and report real, user, and system time elapsed in seconds.\n(real = clock on the wall, user = cpu used by command's code,\nsystem = cpu used by OS on behalf of command.)\n\n-p POSIX format output\n-v Verbose"
-#define HELP_test "usage: test [-bcdefghLPrSsuwx PATH] [-nz STRING] [-t FD] [X ?? Y]\n\nReturn true or false by performing tests. No arguments is false, one argument\nis true if not empty string.\n\n--- Tests with a single argument (after the option):\nPATH is/has:\n -b block device -f regular file -p fifo -u setuid bit\n -c char device -g setgid -r readable -w writable\n -d directory -h symlink -S socket -x executable\n -e exists -L symlink -s nonzero size -k sticky bit\nSTRING is:\n -n nonzero size -z zero size\nFD (integer file descriptor) is:\n -t a TTY\n\n--- Tests with one argument on each side of an operator:\nTwo strings:\n = are identical != differ =~ string matches regex\nAlphabetical sort:\n < first is lower > first higher\nTwo integers:\n -eq equal -gt first > second -lt first < second\n -ne not equal -ge first >= second -le first <= second\n\n--- Modify or combine tests:\n ! EXPR not (swap true/false) EXPR -a EXPR and (are both true)\n ( EXPR ) evaluate this first EXPR -o EXPR or (is either true)"
+#define HELP_test "usage: test [-bcdefghLPrSsuwx PATH] [-nz STRING] [-t FD] [X ?? Y]\n\nReturn true or false by performing tests. No arguments is false, one argument\nis true if not empty string.\n\n--- Tests with a single argument (after the option):\nPATH is/has:\n -b block device -f regular file -p fifo -u setuid bit\n -c char device -g setgid -r readable -w writable\n -d directory -h symlink -S socket -x executable\n -e exists -L symlink -s nonzero size -k sticky bit\nSTRING is:\n -n nonzero size -z zero size\nFD (integer file descriptor) is:\n -t a TTY -T open\n\n--- Tests with one argument on each side of an operator:\nTwo strings:\n = are identical != differ =~ string matches regex\nAlphabetical sort:\n < first is lower > first higher\nTwo integers:\n -eq equal -gt first > second -lt first < second\n -ne not equal -ge first >= second -le first <= second\n\n--- Modify or combine tests:\n ! EXPR not (swap true/false) EXPR -a EXPR and (are both true)\n ( EXPR ) evaluate this first EXPR -o EXPR or (is either true)"
#define HELP_tee "usage: tee [-ai] [FILE...]\n\nCopy stdin to each listed file, and also to stdout.\nFilename \"-\" is a synonym for stdout.\n\n-a Append to files\n-i Ignore SIGINT"
diff --git a/android/device/generated/newtoys.h b/android/device/generated/newtoys.h
index 72091791..0680e5d9 100644
--- a/android/device/generated/newtoys.h
+++ b/android/device/generated/newtoys.h
@@ -169,7 +169,7 @@ USE_LOGIN(NEWTOY(login, ">1f:ph:", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_USR|TOYFLAG_BIN))
USE_LOGPATH(NEWTOY(logpath, 0, TOYFLAG_NOHELP|TOYFLAG_USR|TOYFLAG_BIN))
USE_LOSETUP(NEWTOY(losetup, ">2S(sizelimit)#s(show)ro#j:fdcaD[!afj]", TOYFLAG_SBIN))
-USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN))
USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN))
USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/android/linux/generated/config.h b/android/linux/generated/config.h
index dd4eac50..a1d03da5 100644
--- a/android/linux/generated/config.h
+++ b/android/linux/generated/config.h
@@ -172,8 +172,8 @@
#define USE_FDISK(...)
#define CFG_FGREP 1
#define USE_FGREP(...) __VA_ARGS__
-#define CFG_FILE 0
-#define USE_FILE(...)
+#define CFG_FILE 1
+#define USE_FILE(...) __VA_ARGS__
#define CFG_FIND 1
#define USE_FIND(...) __VA_ARGS__
#define CFG_FLOCK 0
diff --git a/android/linux/generated/flags.h b/android/linux/generated/flags.h
index f0a29d93..3e550a7e 100644
--- a/android/linux/generated/flags.h
+++ b/android/linux/generated/flags.h
@@ -934,7 +934,7 @@
#undef FLAG_C
#endif
-// file <1b(brief)hLs[!hL]
+// file <1b(brief)hLs[!hL] <1b(brief)hLs[!hL]
#undef OPTSTR_file
#define OPTSTR_file "<1b(brief)hLs[!hL]"
#ifdef CLEANUP_file
@@ -1824,9 +1824,9 @@
#undef FLAG_S
#endif
-// ls (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]
+// ls (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]
#undef OPTSTR_ls
-#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]"
+#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]"
#ifdef CLEANUP_ls
#undef CLEANUP_ls
#undef FOR_ls
@@ -4716,10 +4716,10 @@
#ifndef TT
#define TT this.file
#endif
-#define FLAG_s (FORCED_FLAG<<0)
-#define FLAG_L (FORCED_FLAG<<1)
-#define FLAG_h (FORCED_FLAG<<2)
-#define FLAG_b (FORCED_FLAG<<3)
+#define FLAG_s (1LL<<0)
+#define FLAG_L (1LL<<1)
+#define FLAG_h (1LL<<2)
+#define FLAG_b (1LL<<3)
#endif
#ifdef FOR_find
diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h
index c95b74a1..aef88284 100644
--- a/android/linux/generated/help.h
+++ b/android/linux/generated/help.h
@@ -540,7 +540,7 @@
#define HELP_time "usage: time [-pv] COMMAND...\n\nRun command line and report real, user, and system time elapsed in seconds.\n(real = clock on the wall, user = cpu used by command's code,\nsystem = cpu used by OS on behalf of command.)\n\n-p POSIX format output\n-v Verbose"
-#define HELP_test "usage: test [-bcdefghLPrSsuwx PATH] [-nz STRING] [-t FD] [X ?? Y]\n\nReturn true or false by performing tests. No arguments is false, one argument\nis true if not empty string.\n\n--- Tests with a single argument (after the option):\nPATH is/has:\n -b block device -f regular file -p fifo -u setuid bit\n -c char device -g setgid -r readable -w writable\n -d directory -h symlink -S socket -x executable\n -e exists -L symlink -s nonzero size -k sticky bit\nSTRING is:\n -n nonzero size -z zero size\nFD (integer file descriptor) is:\n -t a TTY\n\n--- Tests with one argument on each side of an operator:\nTwo strings:\n = are identical != differ =~ string matches regex\nAlphabetical sort:\n < first is lower > first higher\nTwo integers:\n -eq equal -gt first > second -lt first < second\n -ne not equal -ge first >= second -le first <= second\n\n--- Modify or combine tests:\n ! EXPR not (swap true/false) EXPR -a EXPR and (are both true)\n ( EXPR ) evaluate this first EXPR -o EXPR or (is either true)"
+#define HELP_test "usage: test [-bcdefghLPrSsuwx PATH] [-nz STRING] [-t FD] [X ?? Y]\n\nReturn true or false by performing tests. No arguments is false, one argument\nis true if not empty string.\n\n--- Tests with a single argument (after the option):\nPATH is/has:\n -b block device -f regular file -p fifo -u setuid bit\n -c char device -g setgid -r readable -w writable\n -d directory -h symlink -S socket -x executable\n -e exists -L symlink -s nonzero size -k sticky bit\nSTRING is:\n -n nonzero size -z zero size\nFD (integer file descriptor) is:\n -t a TTY -T open\n\n--- Tests with one argument on each side of an operator:\nTwo strings:\n = are identical != differ =~ string matches regex\nAlphabetical sort:\n < first is lower > first higher\nTwo integers:\n -eq equal -gt first > second -lt first < second\n -ne not equal -ge first >= second -le first <= second\n\n--- Modify or combine tests:\n ! EXPR not (swap true/false) EXPR -a EXPR and (are both true)\n ( EXPR ) evaluate this first EXPR -o EXPR or (is either true)"
#define HELP_tee "usage: tee [-ai] [FILE...]\n\nCopy stdin to each listed file, and also to stdout.\nFilename \"-\" is a synonym for stdout.\n\n-a Append to files\n-i Ignore SIGINT"
diff --git a/android/linux/generated/newtoys.h b/android/linux/generated/newtoys.h
index 72091791..0680e5d9 100644
--- a/android/linux/generated/newtoys.h
+++ b/android/linux/generated/newtoys.h
@@ -169,7 +169,7 @@ USE_LOGIN(NEWTOY(login, ">1f:ph:", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_USR|TOYFLAG_BIN))
USE_LOGPATH(NEWTOY(logpath, 0, TOYFLAG_NOHELP|TOYFLAG_USR|TOYFLAG_BIN))
USE_LOSETUP(NEWTOY(losetup, ">2S(sizelimit)#s(show)ro#j:fdcaD[!afj]", TOYFLAG_SBIN))
-USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN))
USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN))
USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/android/mac/generated/config.h b/android/mac/generated/config.h
index 5c19a594..bd4c09b7 100644
--- a/android/mac/generated/config.h
+++ b/android/mac/generated/config.h
@@ -172,8 +172,8 @@
#define USE_FDISK(...)
#define CFG_FGREP 1
#define USE_FGREP(...) __VA_ARGS__
-#define CFG_FILE 0
-#define USE_FILE(...)
+#define CFG_FILE 1
+#define USE_FILE(...) __VA_ARGS__
#define CFG_FIND 1
#define USE_FIND(...) __VA_ARGS__
#define CFG_FLOCK 0
diff --git a/android/mac/generated/flags.h b/android/mac/generated/flags.h
index 8993979c..0cb1833c 100644
--- a/android/mac/generated/flags.h
+++ b/android/mac/generated/flags.h
@@ -934,7 +934,7 @@
#undef FLAG_C
#endif
-// file <1b(brief)hLs[!hL]
+// file <1b(brief)hLs[!hL] <1b(brief)hLs[!hL]
#undef OPTSTR_file
#define OPTSTR_file "<1b(brief)hLs[!hL]"
#ifdef CLEANUP_file
@@ -1824,9 +1824,9 @@
#undef FLAG_S
#endif
-// ls (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]
+// ls (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]
#undef OPTSTR_ls
-#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]"
+#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]"
#ifdef CLEANUP_ls
#undef CLEANUP_ls
#undef FOR_ls
@@ -4716,10 +4716,10 @@
#ifndef TT
#define TT this.file
#endif
-#define FLAG_s (FORCED_FLAG<<0)
-#define FLAG_L (FORCED_FLAG<<1)
-#define FLAG_h (FORCED_FLAG<<2)
-#define FLAG_b (FORCED_FLAG<<3)
+#define FLAG_s (1LL<<0)
+#define FLAG_L (1LL<<1)
+#define FLAG_h (1LL<<2)
+#define FLAG_b (1LL<<3)
#endif
#ifdef FOR_find
diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h
index c95b74a1..aef88284 100644
--- a/android/mac/generated/help.h
+++ b/android/mac/generated/help.h
@@ -540,7 +540,7 @@
#define HELP_time "usage: time [-pv] COMMAND...\n\nRun command line and report real, user, and system time elapsed in seconds.\n(real = clock on the wall, user = cpu used by command's code,\nsystem = cpu used by OS on behalf of command.)\n\n-p POSIX format output\n-v Verbose"
-#define HELP_test "usage: test [-bcdefghLPrSsuwx PATH] [-nz STRING] [-t FD] [X ?? Y]\n\nReturn true or false by performing tests. No arguments is false, one argument\nis true if not empty string.\n\n--- Tests with a single argument (after the option):\nPATH is/has:\n -b block device -f regular file -p fifo -u setuid bit\n -c char device -g setgid -r readable -w writable\n -d directory -h symlink -S socket -x executable\n -e exists -L symlink -s nonzero size -k sticky bit\nSTRING is:\n -n nonzero size -z zero size\nFD (integer file descriptor) is:\n -t a TTY\n\n--- Tests with one argument on each side of an operator:\nTwo strings:\n = are identical != differ =~ string matches regex\nAlphabetical sort:\n < first is lower > first higher\nTwo integers:\n -eq equal -gt first > second -lt first < second\n -ne not equal -ge first >= second -le first <= second\n\n--- Modify or combine tests:\n ! EXPR not (swap true/false) EXPR -a EXPR and (are both true)\n ( EXPR ) evaluate this first EXPR -o EXPR or (is either true)"
+#define HELP_test "usage: test [-bcdefghLPrSsuwx PATH] [-nz STRING] [-t FD] [X ?? Y]\n\nReturn true or false by performing tests. No arguments is false, one argument\nis true if not empty string.\n\n--- Tests with a single argument (after the option):\nPATH is/has:\n -b block device -f regular file -p fifo -u setuid bit\n -c char device -g setgid -r readable -w writable\n -d directory -h symlink -S socket -x executable\n -e exists -L symlink -s nonzero size -k sticky bit\nSTRING is:\n -n nonzero size -z zero size\nFD (integer file descriptor) is:\n -t a TTY -T open\n\n--- Tests with one argument on each side of an operator:\nTwo strings:\n = are identical != differ =~ string matches regex\nAlphabetical sort:\n < first is lower > first higher\nTwo integers:\n -eq equal -gt first > second -lt first < second\n -ne not equal -ge first >= second -le first <= second\n\n--- Modify or combine tests:\n ! EXPR not (swap true/false) EXPR -a EXPR and (are both true)\n ( EXPR ) evaluate this first EXPR -o EXPR or (is either true)"
#define HELP_tee "usage: tee [-ai] [FILE...]\n\nCopy stdin to each listed file, and also to stdout.\nFilename \"-\" is a synonym for stdout.\n\n-a Append to files\n-i Ignore SIGINT"
diff --git a/android/mac/generated/newtoys.h b/android/mac/generated/newtoys.h
index 72091791..0680e5d9 100644
--- a/android/mac/generated/newtoys.h
+++ b/android/mac/generated/newtoys.h
@@ -169,7 +169,7 @@ USE_LOGIN(NEWTOY(login, ">1f:ph:", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_USR|TOYFLAG_BIN))
USE_LOGPATH(NEWTOY(logpath, 0, TOYFLAG_NOHELP|TOYFLAG_USR|TOYFLAG_BIN))
USE_LOSETUP(NEWTOY(losetup, ">2S(sizelimit)#s(show)ro#j:fdcaD[!afj]", TOYFLAG_SBIN))
-USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN))
USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN))
USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/lib/deflate.c b/lib/deflate.c
index 06d61e97..a418c21c 100644
--- a/lib/deflate.c
+++ b/lib/deflate.c
@@ -433,16 +433,17 @@ static void gzip_crc(struct deflate *dd, char *data, unsigned len)
/*
// Start with crc = 1, or pass in last crc to append more data
+// Deferred modulus good for paged size inputs (can't overflow for ~5500 bytes)
unsigned adler32(char *buf, unsigned len, unsigned crc)
{
unsigned aa = crc&((1<<16)-1), bb = crc>>16;
while (len--) {
- aa = (aa+*buf)%65521;
- bb = (bb+aa)%65521;
+ aa += *buf++;
+ bb += aa;
}
- return (bb<16)+aa;
+ return ((bb%65521)<<16)+aa%65521;
}
*/
diff --git a/mkroot/mkroot.sh b/mkroot/mkroot.sh
new file mode 100755
index 00000000..0447b386
--- /dev/null
+++ b/mkroot/mkroot.sh
@@ -0,0 +1,309 @@
+#!/bin/bash
+
+# ------------------------------ Part 1: Setup -------------------------------
+
+# Clear environment variables by restarting script w/bare minimum passed through
+[ -z "$NOCLEAR" ] && exec env -i NOCLEAR=1 HOME="$HOME" PATH="$PATH" \
+ LINUX="$LINUX" CROSS="$CROSS" CROSS_COMPILE="$CROSS_COMPILE" "$0" "$@"
+
+! [ -d mkroot ] && echo "Run mkroot/mkroot.sh from toybox source dir." && exit 1
+
+# assign command line NAME=VALUE args to env vars, the rest are packages
+for i in "$@"; do
+ [ "${i/=/}" != "$i" ] && export "$i" || { [ "$i" != -- ] && PKG="$PKG $i"; }
+done
+
+# Set default directory locations (overrideable from command line)
+: ${TOP:=$PWD/root} ${BUILD:=$TOP/build} ${LOG:=$BUILD/log}
+: ${AIRLOCK:=$BUILD/airlock} ${CCC:=$PWD/ccc} ${PKGDIR:=$PWD/mkroot/root}
+
+announce() { printf "\033]2;$CROSS $*\007" >/dev/tty; printf "\n=== $*\n";}
+die() { echo "$@" >&2; exit 1; }
+
+# ----- Are we cross compiling (via CROSS_COMPILE= or CROSS=)
+
+if [ -n "$CROSS_COMPILE" ]; then
+ # airlock needs absolute path
+ [ -z "${X:=$(command -v "$CROSS_COMPILE"cc)}" ] && die "no ${CROSS_COMPILE}cc"
+ CROSS_COMPILE="$(realpath -s "${X%cc}")"
+ [ -z "$CROSS" ] && CROSS=${CROSS_COMPILE/*\//} CROSS=${CROSS/-*/}
+
+elif [ -n "$CROSS" ]; then # CROSS=all/allnonstop/$ARCH else list known $ARCHes
+ [ ! -d "$CCC" ] && die "No ccc symlink to compiler directory."
+ TARGETS="$(ls "$CCC" | sed -n 's/-.*//p' | sort -u)"
+
+ if [ "${CROSS::3}" == all ]; then # loop calling ourselves for each target
+ for i in $TARGETS; do
+ "$0" "$@" CROSS=$i || [ "$CROSS" == allnonstop ] || exit 1
+ done; exit
+
+ else # Find matching cross compiler under ccc/ else list available targets
+ CROSS_COMPILE="$(echo "$CCC/$CROSS"-*cross/bin/"$CROSS"*-cc)" # wildcard
+ [ ! -e "$CROSS_COMPILE" ] && echo $TARGETS && exit # list available targets
+ CROSS_COMPILE="${CROSS_COMPILE%cc}" # trim to prefix for cc/ld/as/nm/strip
+ fi
+fi
+
+# Set per-target output directory (using "host" if not cross-compiling)
+: ${CROSS:=host} ${OUTPUT:=$TOP/$CROSS}
+
+# Verify selected compiler works
+${CROSS_COMPILE}cc --static -xc - -o /dev/null <<< "int main(void){return 0;}"||
+ die "${CROSS_COMPILE}cc can't create static binaries"
+
+# ----- Create hermetic build environment
+
+if [ -z "$NOAIRLOCK"] && [ -n "$CROSS_COMPILE" ]; then
+ # When cross compiling set host $PATH to binaries with known behavior by
+ # - building a host toybox later builds use as their command line
+ # - cherry-picking specific commands from old path via symlink
+ if [ ! -e "$AIRLOCK/toybox" ]; then
+ announce "airlock" &&
+ PREFIX="$AIRLOCK" KCONFIG_CONFIG=.singleconfig_airlock CROSS_COMPILE= \
+ make clean defconfig toybox install_airlock && # see scripts/install.sh
+ rm .singleconfig_airlock || exit 1
+ fi
+ export PATH="$AIRLOCK"
+ CPIO_OPTS+=--no-preserve-owner
+fi
+
+# Create per-target work directories
+TEMP="$BUILD/${CROSS}-tmp" && rm -rf "$TEMP" &&
+mkdir -p "$TEMP" "$OUTPUT" "$LOG" || exit 1
+[ -z "$ROOT" ] && ROOT="$OUTPUT/fs" && rm -rf "$ROOT"
+
+# ----- log build output
+
+# Install command line recording wrapper, logs all commands run from $PATH
+if [ -z "$NOLOGPATH" ]; then
+ # Move cross compiler into $PATH so calls to it get logged
+ [ -n "$CROSS_COMPILE" ] && PATH="${CROSS_COMPILE%/*}:$PATH" &&
+ CROSS_COMPILE=${CROSS_COMPILE##*/}
+ export WRAPDIR="$BUILD/record-commands" LOGPATH="$LOG/$CROSS-commands.txt"
+ rm -rf "$WRAPDIR" "$LOGPATH" generated/obj &&
+ WRAPDIR="$WRAPDIR" CROSS_COMPILE= NOSTRIP=1 source mkroot/record-commands ||
+ exit 1
+fi
+
+# Start logging stdout/stderr
+rm -f "$LOG/$CROSS".{n,y} || exit 1
+[ -z "$NOLOG" ] && exec > >(tee "$LOG/$CROSS.n") 2>&1
+echo "Building for $CROSS"
+
+# ---------------------- Part 2: Create root filesystem -----------------------
+
+# ----- Create new root filesystem's directory layout.
+
+# FHS wants boot media opt srv usr/{local,share}, stuff under /var...
+mkdir -p "$ROOT"/{dev,etc/rc,home,mnt,proc,root,sys,tmp/run,usr/{bin,sbin,lib},var} &&
+chmod a+rwxt "$ROOT"/tmp && ln -s usr/{bin,sbin,lib} tmp/run "$ROOT" || exit 1
+
+# Write init script. Runs as pid 1 from initramfs to set up and hand off system.
+cat > "$ROOT"/init << 'EOF' &&
+#!/bin/sh
+
+export HOME=/home PATH=/bin:/sbin
+
+if ! mountpoint -q dev; then
+ mount -t devtmpfs dev dev
+ [ $$ -eq 1 ] && exec 0<>/dev/console 1>&0 2>&1
+ for i in ,fd /0,stdin /1,stdout /2,stderr
+ do ln -sf /proc/self/fd${i/,*/} dev/${i/*,/}; done
+ mkdir -p dev/shm
+ chmod +t /dev/shm
+fi
+mountpoint -q dev/pts || { mkdir -p dev/pts && mount -t devpts dev/pts dev/pts;}
+mountpoint -q proc || mount -t proc proc proc
+mountpoint -q sys || mount -t sysfs sys sys
+echo 0 99999 > /proc/sys/net/ipv4/ping_group_range
+
+if [ $$ -eq 1 ]; then # Setup networking for QEMU (needs /proc)
+ mountpoint -q mnt || [ -e /dev/?da ] && mount /dev/?da /mnt
+ ifconfig lo 127.0.0.1
+ ifconfig eth0 10.0.2.15
+ route add default gw 10.0.2.2
+ [ "$(date +%s)" -lt 1000 ] && timeout 2 sntp -sq 10.0.2.2 # Ask host
+ [ "$(date +%s)" -lt 10000000 ] && sntp -sq time.google.com
+
+ # Run package scripts (if any)
+ for i in $(ls -1 /etc/rc 2>/dev/null | sort); do . /etc/rc/"$i"; done
+
+ [ -z "$HANDOFF" ] && [ -e /mnt/init ] && HANDOFF=/mnt/init
+ [ -z "$HANDOFF" ] && HANDOFF=/bin/sh && echo -e '\e[?7hType exit when done.'
+ echo 3 > /proc/sys/kernel/printk
+ exec oneit $HANDOFF
+else # for chroot
+ /bin/sh
+ umount /dev/pts /dev /sys /proc
+fi
+EOF
+chmod +x "$ROOT"/init &&
+
+# Google's nameserver, passwd+group with special (root/nobody) accounts + guest
+echo "nameserver 8.8.8.8" > "$ROOT"/etc/resolv.conf &&
+cat > "$ROOT"/etc/passwd << 'EOF' &&
+root:x:0:0:root:/root:/bin/sh
+guest:x:500:500:guest:/home/guest:/bin/sh
+nobody:x:65534:65534:nobody:/proc/self:/dev/null
+EOF
+echo -e 'root:x:0:\nguest:x:500:\nnobody:x:65534:' > "$ROOT"/etc/group || exit 1
+
+# Build any packages listed on command line
+for i in ${PKG:+plumbing $PKG}; do
+ pushd .
+ announce "$i"; PATH="$PKGDIR:$PATH" source $i || die $i
+ popd
+done
+
+# Build static toybox with existing .config if there is one, else defconfig+sh
+announce toybox
+[ -n "$PENDING" ] && rm -f .config
+[ -e .config ] && CONF=silentoldconfig || unset CONF
+for i in $PENDING sh route; do XX="$XX"$'\n'CONFIG_${i^^?}=y; done
+[ -e "$ROOT"/lib/libc.so ] || export LDFLAGS=--static
+PREFIX="$ROOT" make clean \
+ ${CONF:-defconfig KCONFIG_ALLCONFIG=<(echo "$XX")} toybox install || exit 1
+unset LDFLAGS
+
+# ------------------ Part 3: Build + package bootable system ------------------
+
+# Convert comma separated values in $1 to CONFIG=$2 lines
+csv2cfg() { sed -E '/^$/d;s/([^,]*)($|,)/CONFIG_\1='"$2"'\n/g' <<< "$1"; }
+
+# ----- Build kernel for target
+
+if [ -z "$LINUX" ] || [ ! -d "$LINUX/kernel" ]; then
+ echo 'No $LINUX directory, kernel build skipped.'
+else
+ # Which architecture are we building a kernel for?
+ LINUX="$(realpath "$LINUX")"
+ [ -z "$TARGET" ] &&
+ { [ "$CROSS" == host ] && TARGET="$(uname -m)" || TARGET="$CROSS"; }
+
+ # Target-specific info in an (alphabetical order) if/else staircase
+ # Each target needs board config, serial console, RTC, ethernet, block device.
+
+ if [ "$TARGET" == armv5l ]; then
+ # This could use the same VIRT board as armv7, but let's demonstrate a
+ # different one requiring a separate device tree binary.
+ QEMU="arm -M versatilepb -net nic,model=rtl8139 -net user"
+ KARCH=arm KARGS=ttyAMA0 VMLINUX=arch/arm/boot/zImage
+ KCONF=CPU_ARM926T,MMU,VFP,ARM_THUMB,AEABI,ARCH_VERSATILE,ATAGS,DEPRECATED_PARAM_STRUCT,ARM_ATAG_DTB_COMPAT,ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND,SERIAL_AMBA_PL011,SERIAL_AMBA_PL011_CONSOLE,RTC_CLASS,RTC_DRV_PL031,RTC_HCTOSYS,PCI,PCI_VERSATILE,BLK_DEV_SD,SCSI,SCSI_LOWLEVEL,SCSI_SYM53C8XX_2,SCSI_SYM53C8XX_MMIO,NET_VENDOR_REALTEK,8139CP
+ KERNEL_CONFIG="CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE=0"
+ DTB=arch/arm/boot/dts/versatile-pb.dtb
+ elif [ "$TARGET" == armv7l ] || [ "$TARGET" == aarch64 ]; then
+ if [ "$TARGET" == aarch64 ]; then
+ QEMU="aarch64 -M virt -cpu cortex-a57"
+ KARCH=arm64 VMLINUX=arch/arm64/boot/Image
+ else
+ QEMU="arm -M virt" KARCH=arm VMLINUX=arch/arm/boot/zImage
+ fi
+ KARGS=ttyAMA0
+ KCONF=MMU,ARCH_MULTI_V7,ARCH_VIRT,SOC_DRA7XX,ARCH_OMAP2PLUS_TYPICAL,ARCH_ALPINE,ARM_THUMB,VDSO,CPU_IDLE,ARM_CPUIDLE,KERNEL_MODE_NEON,SERIAL_AMBA_PL011,SERIAL_AMBA_PL011_CONSOLE,RTC_CLASS,RTC_HCTOSYS,RTC_DRV_PL031,NET_CORE,VIRTIO_MENU,VIRTIO_NET,PCI,PCI_HOST_GENERIC,VIRTIO_BLK,VIRTIO_PCI,VIRTIO_MMIO,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,PATA_PLATFORM,PATA_OF_PLATFORM,ATA_GENERIC,ARM_LPAE
+ elif [ "$TARGET" == hexagon ]; then
+ QEMU="hexagon -M comet" KARGS=ttyS0 VMLINUX=vmlinux
+ KARCH="hexagon LLVM_IAS=1" KCONF=SPI,SPI_BITBANG,IOMMU_SUPPORT
+ elif [ "$TARGET" == i486 ] || [ "$TARGET" == i686 ] ||
+ [ "$TARGET" == x86_64 ] || [ "$TARGET" == x32 ]; then
+ if [ "$TARGET" == i486 ]; then
+ QEMU="i386 -cpu 486 -global fw_cfg.dma_enabled=false" KCONF=M486
+ elif [ "$TARGET" == i686 ]; then
+ QEMU="i386 -cpu pentium3" KCONF=MPENTIUMII
+ else
+ QEMU=x86_64 KCONF=64BIT
+ [ "$TARGET" == x32 ] && KCONF=X86_X32
+ fi
+ KARCH=x86 KARGS=ttyS0 VMLINUX=arch/x86/boot/bzImage
+ KCONF=$KCONF,UNWINDER_FRAME_POINTER,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,NET_VENDOR_INTEL,E1000,SERIAL_8250,SERIAL_8250_CONSOLE,RTC_CLASS
+ elif [ "$TARGET" == m68k ]; then
+ QEMU="m68k -M q800" KARCH=m68k KARGS=ttyS0 VMLINUX=vmlinux
+ KCONF=MMU,M68040,M68KFPU_EMU,MAC,SCSI,SCSI_LOWLEVEL,BLK_DEV_SD,SCSI_MAC_ESP,MACINTOSH_DRIVERS,NET_CORE,NET_VENDOR_NATSEMI,MACSONIC,SERIAL_PMACZILOG,SERIAL_PMACZILOG_TTYS,SERIAL_PMACZILOG_CONSOLE
+ elif [ "$TARGET" == mips ] || [ "$TARGET" == mipsel ]; then
+ QEMU="mips -M malta" KARCH=mips KARGS=ttyS0 VMLINUX=vmlinux
+ KCONF=MIPS_MALTA,CPU_MIPS32_R2,SERIAL_8250,SERIAL_8250_CONSOLE,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,NET_VENDOR_AMD,PCNET32,POWER_RESET,POWER_RESET_SYSCON
+ [ "$TARGET" == mipsel ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN &&
+ QEMU="mipsel -M malta"
+ elif [ "$TARGET" == powerpc ]; then
+ KARCH=powerpc QEMU="ppc -M g3beige" KARGS=ttyS0 VMLINUX=vmlinux
+ KCONF=ALTIVEC,PPC_PMAC,PPC_OF_BOOT_TRAMPOLINE,ATA,ATA_SFF,ATA_BMDMA,PATA_MACIO,BLK_DEV_SD,MACINTOSH_DRIVERS,ADB,ADB_CUDA,NET_VENDOR_NATSEMI,NET_VENDOR_8390,NE2K_PCI,SERIO,SERIAL_PMACZILOG,SERIAL_PMACZILOG_TTYS,SERIAL_PMACZILOG_CONSOLE,BOOTX_TEXT
+ elif [ "$TARGET" == powerpc64 ] || [ "$TARGET" == powerpc64le ]; then
+ KARCH=powerpc QEMU="ppc64 -M pseries -vga none" KARGS=hvc0
+ VMLINUX=vmlinux
+ KCONF=PPC64,PPC_PSERIES,PPC_OF_BOOT_TRAMPOLINE,BLK_DEV_SD,SCSI_LOWLEVEL,SCSI_IBMVSCSI,ATA,NET_VENDOR_IBM,IBMVETH,HVC_CONSOLE,PPC_TRANSACTIONAL_MEM,PPC_DISABLE_WERROR,SECTION_MISMATCH_WARN_ONLY
+ [ "$TARGET" == powerpc64le ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN
+ elif [ "$TARGET" = s390x ]; then
+ QEMU="s390x" KARCH=s390 VMLINUX=arch/s390/boot/bzImage
+ KCONF=MARCH_Z900,PACK_STACK,NET_CORE,VIRTIO_NET,VIRTIO_BLK,SCLP_TTY,SCLP_CONSOLE,SCLP_VT220_TTY,SCLP_VT220_CONSOLE,S390_GUEST
+ elif [ "$TARGET" == sh2eb ]; then
+ BUILTIN=1 KARCH=sh VMLINUX=vmlinux
+ KERNEL_CONFIG=$'CONFIG_MEMORY_START=0x10000000\nCONFIG_CMDLINE="console=ttyUL0 earlycon"'
+ KCONF=CPU_SUBTYPE_J2,CPU_BIG_ENDIAN,SH_JCORE_SOC,SMP,BINFMT_ELF_FDPIC,JCORE_EMAC,SERIAL_UARTLITE,SERIAL_UARTLITE_CONSOLE,HZ_100,CMDLINE_OVERWRITE,SPI,SPI_JCORE,MMC,PWRSEQ_SIMPLE,MMC_BLOCK,MMC_SPI
+ elif [ "$TARGET" == sh4 ]; then
+ QEMU="sh4 -M r2d -serial null -serial mon:stdio" KARCH=sh
+ KARGS="ttySC1 noiotrap" VMLINUX=arch/sh/boot/zImage
+ KERNEL_CONFIG="CONFIG_MEMORY_START=0x0c000000"
+ KCONF=CPU_SUBTYPE_SH7751R,MMU,VSYSCALL,SH_FPU,SH_RTS7751R2D,RTS7751R2D_PLUS,SERIAL_SH_SCI,SERIAL_SH_SCI_CONSOLE,PCI,NET_VENDOR_REALTEK,8139CP,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,PATA_PLATFORM,BINFMT_ELF_FDPIC,BINFMT_FLAT
+#see also SPI SPI_SH_SCI MFD_SM501 RTC_CLASS RTC_DRV_R9701 RTC_DRV_SH RTC_HCTOSYS
+ else die "Unknown \$TARGET $TARGET"
+ fi
+
+ # Write the qemu launch script
+ if [ -n "$QEMU" ]; then
+ [ -z "$BUILTIN" ] && INITRD="-initrd initramfs.cpio.gz"
+ { echo qemu-system-"$QEMU" '"$@"' $QEMU_MORE -nographic -no-reboot -m 256 \
+ -kernel linux-kernel $INITRD ${DTB:+-dtb linux.dtb} \
+ "-append \"panic=1 HOST=$TARGET console=$KARGS \$KARGS\"" &&
+ echo "echo -e '\\e[?7h'"
+ } > "$OUTPUT"/run-qemu.sh &&
+ chmod +x "$OUTPUT"/run-qemu.sh || exit 1
+ fi
+
+ announce "linux-$KARCH"
+ pushd "$LINUX" && make distclean && popd &&
+ cp -sfR "$LINUX" "$TEMP/linux" && pushd "$TEMP/linux" &&
+
+ # Write linux-miniconfig
+ { echo "# make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG=linux-miniconfig"
+ echo -e "# make ARCH=$KARCH -j \$(nproc)\n# boot $VMLINUX\n\n"
+
+ # Expand list of =y symbols, first generic then architecture-specific
+ for i in BINFMT_ELF,BINFMT_SCRIPT,NO_HZ,HIGH_RES_TIMERS,BLK_DEV,BLK_DEV_INITRD,RD_GZIP,BLK_DEV_LOOP,EXT4_FS,EXT4_USE_FOR_EXT2,VFAT_FS,FAT_DEFAULT_UTF8,MISC_FILESYSTEMS,SQUASHFS,SQUASHFS_XATTR,SQUASHFS_ZLIB,DEVTMPFS,DEVTMPFS_MOUNT,TMPFS,TMPFS_POSIX_ACL,NET,PACKET,UNIX,INET,IPV6,NETDEVICES,NET_CORE,NETCONSOLE,ETHERNET,COMPAT_32BIT_TIME,EARLY_PRINTK,IKCONFIG,IKCONFIG_PROC $KCONF $KEXTRA ; do
+ echo "# architecture ${X:-independent}"
+ csv2cfg "$i" y
+ X=specific
+ done
+ [ -n "$BUILTIN" ] && echo -e CONFIG_INITRAMFS_SOURCE="\"$OUTPUT/fs\""
+ for i in $MODULES; do csv2cfg "$i" m; done
+ echo "$KERNEL_CONFIG"
+ } > "$OUTPUT/linux-miniconfig" &&
+ make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG="$OUTPUT/linux-miniconfig" &&
+
+ # Second config pass to remove stupid kernel defaults
+ # See http://lkml.iu.edu/hypermail/linux/kernel/1912.3/03493.html
+ sed -e 's/# CONFIG_EXPERT .*/CONFIG_EXPERT=y/' -e "$(sed -E -e '/^$/d' \
+ -e 's@([^,]*)($|,)@/^CONFIG_\1=y/d;$a# CONFIG_\1 is not set\n@g' \
+ <<< VT,SCHED_DEBUG,DEBUG_MISC,X86_DEBUG_FPU)" -i .config &&
+ yes "" | make ARCH=$KARCH oldconfig > /dev/null &&
+ cp .config "$OUTPUT/linux-fullconfig" &&
+
+ # Build kernel. Copy config, device tree binary, and kernel binary to output
+ make ARCH=$KARCH CROSS_COMPILE="$CROSS_COMPILE" -j $(nproc) all || exit 1
+ [ -n "$DTB" ] && { cp "$DTB" "$OUTPUT/linux.dtb" || exit 1 ;}
+ if [ -n "$MODULES" ]; then
+ make ARCH=$KARCH INSTALL_MOD_PATH=modz modules_install &&
+ (cd modz && find lib/modules | cpio -o -H newc $CPIO_OPTS ) | gzip \
+ > "$OUTPUT/modules.cpio.gz" || exit 1
+ fi
+ cp "$VMLINUX" "$OUTPUT"/linux-kernel && cd .. && rm -rf linux && popd ||exit 1
+fi
+
+# clean up and package root filesystem for initramfs.
+if [ -z "$BUILTIN" ]; then
+ announce initramfs
+ { (cd "$ROOT" && find . | cpio -o -H newc $CPIO_OPTS ) || exit 1
+ ! test -e "$OUTPUT/modules.cpio.gz" || zcat $_;} | gzip \
+ > "$OUTPUT"/initramfs.cpio.gz || exit 1
+fi
+
+mv "$LOG/$CROSS".{n,y} && echo "Output is in $OUTPUT"
+rmdir "$TEMP" "$BUILD" 2>/dev/null || exit 0 # remove if empty, not an error
diff --git a/scripts/record-commands b/mkroot/record-commands
index d2b779fa..d2b779fa 100755
--- a/scripts/record-commands
+++ b/mkroot/record-commands
diff --git a/scripts/root/dropbear b/mkroot/root/dropbear
index cd0b1578..9a4adcb8 100755
--- a/scripts/root/dropbear
+++ b/mkroot/root/dropbear
@@ -1,4 +1,4 @@
-#!/bin/echo Try "scripts/mkroot.sh dropbear"
+#!/bin/echo Try "mkroot/mkroot.sh dropbear"
# Example overlay file, adding dropbear (which requires zlib)
diff --git a/scripts/root/dynamic b/mkroot/root/dynamic
index c82b1ddb..2ecfbdaa 100755
--- a/scripts/root/dynamic
+++ b/mkroot/root/dynamic
@@ -1,4 +1,4 @@
-#!/bin/echo Try "scripts/mkroot.sh dynamic"
+#!/bin/echo Try "mkroot/mkroot.sh dynamic"
# Copy dynamic libraries from cross compiler
diff --git a/mkroot/root/overlay b/mkroot/root/overlay
new file mode 100755
index 00000000..be0aaede
--- /dev/null
+++ b/mkroot/root/overlay
@@ -0,0 +1,3 @@
+#!/bin/echo Try "mkroot/mkroot.sh overlay"
+
+cp -a "${OVERLAY:=overlay}"/. "$ROOT"/.
diff --git a/scripts/root/plumbing b/mkroot/root/plumbing
index e72247c0..e72247c0 100755
--- a/scripts/root/plumbing
+++ b/mkroot/root/plumbing
diff --git a/scripts/root/tests b/mkroot/root/tests
index 89186d83..bca3b40c 100755
--- a/scripts/root/tests
+++ b/mkroot/root/tests
@@ -1,4 +1,4 @@
-#!/bin/echo Try "scripts/mkroot.sh $0"
+#!/bin/echo Try "mkroot/mkroot.sh $0"
# Alas http://www.linux-usb.org/usb.ids is not versioned, so...
download 36d4e16755502fbc684be75e56841e1014e4a94a \
diff --git a/scripts/test_mkroot.sh b/mkroot/testroot.sh
index e2679b1d..0e3f4494 100755
--- a/scripts/test_mkroot.sh
+++ b/mkroot/testroot.sh
@@ -1,5 +1,20 @@
#!/bin/bash
+# usage: mkroot/testroot.sh [TARGET...]
+#
+# Test system image(s) (by booting qemu with -hda test.img providing /mnt/init)
+# and check that:
+#
+# A) it boots and runs our code (which means /dev/hda works)
+# B) the clock is set sanely ("make" is unhappy when source newer than output)
+# C) it can talk to the virtual network
+#
+# Each successful test prints a === line, and all 3 means it passed.
+# Writes result into root/build/test/$TARGET-test.txt
+#
+# With arguments, tests those targets (verbosely). With no arguments, tests
+# each target with a linux-kernel (in parallel) and prints pass/fail summary.
+
die() { echo "$@"; exit 1; }
[ -n "$(which toybox)" -a -n "$(which mksquashfs)" ] ||
@@ -7,7 +22,7 @@ die() { echo "$@"; exit 1; }
mkdir -p "${TEST:=$PWD/root/build/test}" &&
-# Setup test filesystem
+# Setup test filesystem and package it into a squashfs.
cat > "$TEST"/init << 'EOF' &&
#!/bin/sh
@@ -21,7 +36,7 @@ chmod +x "$TEST"/init &&
mksquashfs "$TEST"/init configure scripts/ tests/ "$TEST"/init.sqf -noappend -all-root >/dev/null &&
-# Setup for network smoke test
+# Setup server on host's loopback for network smoke test
echo === net ok > "$TEST"/index.html || die "smoketest setup"
toybox netcat -p 65432 -s 127.0.0.1 -L toybox httpd "$TEST" &
trap "kill $!" EXIT
diff --git a/scripts/mkroot.sh b/scripts/mkroot.sh
index 60433240..2ac634bc 100755
--- a/scripts/mkroot.sh
+++ b/scripts/mkroot.sh
@@ -1,308 +1 @@
-#!/bin/bash
-
-# ------------------------------ Part 1: Setup -------------------------------
-
-# Clear environment variables by restarting script w/bare minimum passed through
-[ -z "$NOCLEAR" ] && exec env -i NOCLEAR=1 HOME="$HOME" PATH="$PATH" \
- LINUX="$LINUX" CROSS="$CROSS" CROSS_COMPILE="$CROSS_COMPILE" "$0" "$@"
-
-# assign command line NAME=VALUE args to env vars, the rest are packages
-for i in "$@"; do
- [ "${i/=/}" != "$i" ] && export "$i" || { [ "$i" != -- ] && PKG="$PKG $i"; }
-done
-
-# Set default directory locations (overrideable from command line)
-: ${TOP:=$PWD/root} ${BUILD:=$TOP/build} ${LOG:=$BUILD/log}
-: ${AIRLOCK:=$BUILD/airlock} ${CCC:=$PWD/ccc} ${PKGDIR:=$PWD/scripts/root}
-
-# define functions
-announce() { printf "\033]2;$CROSS $*\007" >/dev/tty; printf "\n=== $*\n";}
-die() { echo "$@" >&2; exit 1; }
-
-# ----- Are we cross compiling (via CROSS_COMPILE= or CROSS=)
-
-if [ -n "$CROSS_COMPILE" ]; then
- # airlock needs absolute path
- [ -z "${X:=$(command -v "$CROSS_COMPILE"cc)}" ] && die "no ${CROSS_COMPILE}cc"
- CROSS_COMPILE="$(realpath -s "${X%cc}")"
- [ -z "$CROSS" ] && CROSS=${CROSS_COMPILE/*\//} CROSS=${CROSS/-*/}
-
-elif [ -n "$CROSS" ]; then # CROSS=all/allnonstop/$ARCH else list known $ARCHes
- [ ! -d "$CCC" ] && die "No ccc symlink to compiler directory."
- TARGETS="$(ls "$CCC" | sed -n 's/-.*//p' | sort -u)"
-
- if [ "${CROSS::3}" == all ]; then # loop calling ourselves for each target
- for i in $TARGETS; do
- "$0" "$@" CROSS=$i || [ "$CROSS" == allnonstop ] || exit 1
- done; exit
-
- else # Find matching cross compiler under ccc/ else list available targets
- CROSS_COMPILE="$(echo "$CCC/$CROSS"-*cross/bin/"$CROSS"*-cc)" # wildcard
- [ ! -e "$CROSS_COMPILE" ] && echo $TARGETS && exit # list available targets
- CROSS_COMPILE="${CROSS_COMPILE%cc}" # trim to prefix for cc/ld/as/nm/strip
- fi
-fi
-
-# Set per-target output directory (using "host" if not cross-compiling)
-: ${CROSS:=host} ${OUTPUT:=$TOP/$CROSS}
-
-# Verify selected compiler works
-${CROSS_COMPILE}cc --static -xc - -o /dev/null <<< "int main(void){return 0;}"||
- die "${CROSS_COMPILE}cc can't create static binaries"
-
-# ----- Create hermetic build environment
-
-if [ -z "$NOAIRLOCK"] && [ -n "$CROSS_COMPILE" ]; then
- # When cross compiling set host $PATH to binaries with known behavior by
- # - building a host toybox later builds use as their command line
- # - cherry-picking specific commands from old path via symlink
- if [ ! -e "$AIRLOCK/toybox" ]; then
- announce "airlock" &&
- PREFIX="$AIRLOCK" KCONFIG_CONFIG=.singleconfig_airlock CROSS_COMPILE= \
- make clean defconfig toybox install_airlock && # see scripts/install.sh
- rm .singleconfig_airlock || exit 1
- fi
- export PATH="$AIRLOCK"
- CPIO_OPTS+=--no-preserve-owner
-fi
-
-# Create per-target work directories
-TEMP="$BUILD/${CROSS}-tmp" && rm -rf "$TEMP" &&
-mkdir -p "$TEMP" "$OUTPUT" "$LOG" || exit 1
-[ -z "$ROOT" ] && ROOT="$OUTPUT/fs" && rm -rf "$ROOT"
-
-# ----- log build output
-
-# Install command line recording wrapper, logs all commands run from $PATH
-if [ -z "$NOLOGPATH" ]; then
- # Move cross compiler into $PATH so calls to it get logged
- [ -n "$CROSS_COMPILE" ] && PATH="${CROSS_COMPILE%/*}:$PATH" &&
- CROSS_COMPILE=${CROSS_COMPILE##*/}
- export WRAPDIR="$BUILD/record-commands" LOGPATH="$LOG/$CROSS-commands.txt"
- rm -rf "$WRAPDIR" "$LOGPATH" generated/obj &&
- WRAPDIR="$WRAPDIR" CROSS_COMPILE= NOSTRIP=1 source scripts/record-commands ||
- exit 1
-fi
-
-# Start logging stdout/stderr
-rm -f "$LOG/$CROSS".{n,y} || exit 1
-[ -z "$NOLOG" ] && exec > >(tee "$LOG/$CROSS.n") 2>&1
-echo "Building for $CROSS"
-
-# ---------------------- Part 2: Create root filesystem -----------------------
-
-# ----- Create new root filesystem's directory layout.
-
-# FHS wants boot media opt srv usr/{local,share}, stuff under /var...
-mkdir -p "$ROOT"/{dev,etc/rc,home,mnt,proc,root,sys,tmp/run,usr/{bin,sbin,lib},var} &&
-chmod a+rwxt "$ROOT"/tmp && ln -s usr/{bin,sbin,lib} tmp/run "$ROOT" || exit 1
-
-# Write init script. Runs as pid 1 from initramfs to set up and hand off system.
-cat > "$ROOT"/init << 'EOF' &&
-#!/bin/sh
-
-export HOME=/home PATH=/bin:/sbin
-
-if ! mountpoint -q dev; then
- mount -t devtmpfs dev dev
- [ $$ -eq 1 ] && exec 0<>/dev/console 1>&0 2>&1
- for i in ,fd /0,stdin /1,stdout /2,stderr
- do ln -sf /proc/self/fd${i/,*/} dev/${i/*,/}; done
- mkdir -p dev/shm
- chmod +t /dev/shm
-fi
-mountpoint -q dev/pts || { mkdir -p dev/pts && mount -t devpts dev/pts dev/pts;}
-mountpoint -q proc || mount -t proc proc proc
-mountpoint -q sys || mount -t sysfs sys sys
-echo 0 99999 > /proc/sys/net/ipv4/ping_group_range
-
-if [ $$ -eq 1 ]; then # Setup networking for QEMU (needs /proc)
- mountpoint -q mnt || [ -e /dev/?da ] && mount /dev/?da /mnt
- ifconfig lo 127.0.0.1
- ifconfig eth0 10.0.2.15
- route add default gw 10.0.2.2
- [ "$(date +%s)" -lt 1000 ] && timeout 2 sntp -sq 10.0.2.2 # Ask host
- [ "$(date +%s)" -lt 10000000 ] && sntp -sq time.google.com
-
- # Run package scripts (if any)
- for i in $(ls -1 /etc/rc 2>/dev/null | sort); do . /etc/rc/"$i"; done
-
- [ -z "$HANDOFF" ] && [ -e /mnt/init ] && HANDOFF=/mnt/init
- [ -z "$HANDOFF" ] && HANDOFF=/bin/sh && echo -e '\e[?7hType exit when done.'
- echo 3 > /proc/sys/kernel/printk
- exec oneit $HANDOFF
-else # for chroot
- /bin/sh
- umount /dev/pts /dev /sys /proc
-fi
-EOF
-chmod +x "$ROOT"/init &&
-
-# Google's nameserver, passwd+group with special (root/nobody) accounts + guest
-echo "nameserver 8.8.8.8" > "$ROOT"/etc/resolv.conf &&
-cat > "$ROOT"/etc/passwd << 'EOF' &&
-root:x:0:0:root:/root:/bin/sh
-guest:x:500:500:guest:/home/guest:/bin/sh
-nobody:x:65534:65534:nobody:/proc/self:/dev/null
-EOF
-echo -e 'root:x:0:\nguest:x:500:\nnobody:x:65534:' > "$ROOT"/etc/group || exit 1
-
-# Build any packages listed on command line
-for i in ${PKG:+plumbing $PKG}; do
- pushd .
- announce "$i"; PATH="$PKGDIR:$PATH" source $i || die $i
- popd
-done
-
-# Build static toybox with existing .config if there is one, else defconfig+sh
-announce toybox
-[ -n "$PENDING" ] && rm -f .config
-[ -e .config ] && CONF=silentoldconfig || unset CONF
-for i in $PENDING sh route; do XX="$XX"$'\n'CONFIG_${i^^?}=y; done
-[ -e "$ROOT"/lib/libc.so ] || export LDFLAGS=--static
-PREFIX="$ROOT" make clean \
- ${CONF:-defconfig KCONFIG_ALLCONFIG=<(echo "$XX")} toybox install || exit 1
-unset LDFLAGS
-
-# ------------------ Part 3: Build + package bootable system ------------------
-
-# Convert comma separated values in $1 to CONFIG=$2 lines
-csv2cfg() { sed -E '/^$/d;s/([^,]*)($|,)/CONFIG_\1='"$2"'\n/g' <<< "$1"; }
-
-# ----- Build kernel for target
-
-if [ -z "$LINUX" ] || [ ! -d "$LINUX/kernel" ]; then
- echo 'No $LINUX directory, kernel build skipped.'
-else
- # Which architecture are we building a kernel for?
- LINUX="$(realpath "$LINUX")"
- [ -z "$TARGET" ] &&
- { [ "$CROSS" == host ] && TARGET="$(uname -m)" || TARGET="$CROSS"; }
-
- # Target-specific info in an (alphabetical order) if/else staircase
- # Each target needs board config, serial console, RTC, ethernet, block device.
-
- if [ "$TARGET" == armv5l ]; then
- # This could use the same VIRT board as armv7, but let's demonstrate a
- # different one requiring a separate device tree binary.
- QEMU="arm -M versatilepb -net nic,model=rtl8139 -net user"
- KARCH=arm KARGS=ttyAMA0 VMLINUX=arch/arm/boot/zImage
- KCONF=CPU_ARM926T,MMU,VFP,ARM_THUMB,AEABI,ARCH_VERSATILE,ATAGS,DEPRECATED_PARAM_STRUCT,ARM_ATAG_DTB_COMPAT,ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND,SERIAL_AMBA_PL011,SERIAL_AMBA_PL011_CONSOLE,RTC_CLASS,RTC_DRV_PL031,RTC_HCTOSYS,PCI,PCI_VERSATILE,BLK_DEV_SD,SCSI,SCSI_LOWLEVEL,SCSI_SYM53C8XX_2,SCSI_SYM53C8XX_MMIO,NET_VENDOR_REALTEK,8139CP
- KERNEL_CONFIG="CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE=0"
- DTB=arch/arm/boot/dts/versatile-pb.dtb
- elif [ "$TARGET" == armv7l ] || [ "$TARGET" == aarch64 ]; then
- if [ "$TARGET" == aarch64 ]; then
- QEMU="aarch64 -M virt -cpu cortex-a57"
- KARCH=arm64 VMLINUX=arch/arm64/boot/Image
- else
- QEMU="arm -M virt" KARCH=arm VMLINUX=arch/arm/boot/zImage
- fi
- KARGS=ttyAMA0
- KCONF=MMU,ARCH_MULTI_V7,ARCH_VIRT,SOC_DRA7XX,ARCH_OMAP2PLUS_TYPICAL,ARCH_ALPINE,ARM_THUMB,VDSO,CPU_IDLE,ARM_CPUIDLE,KERNEL_MODE_NEON,SERIAL_AMBA_PL011,SERIAL_AMBA_PL011_CONSOLE,RTC_CLASS,RTC_HCTOSYS,RTC_DRV_PL031,NET_CORE,VIRTIO_MENU,VIRTIO_NET,PCI,PCI_HOST_GENERIC,VIRTIO_BLK,VIRTIO_PCI,VIRTIO_MMIO,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,PATA_PLATFORM,PATA_OF_PLATFORM,ATA_GENERIC,ARM_LPAE
- elif [ "$TARGET" == hexagon ]; then
- QEMU="hexagon -M comet" KARGS=ttyS0 VMLINUX=vmlinux
- KARCH="hexagon LLVM_IAS=1" KCONF=SPI,SPI_BITBANG,IOMMU_SUPPORT
- elif [ "$TARGET" == i486 ] || [ "$TARGET" == i686 ] ||
- [ "$TARGET" == x86_64 ] || [ "$TARGET" == x32 ]; then
- if [ "$TARGET" == i486 ]; then
- QEMU="i386 -cpu 486 -global fw_cfg.dma_enabled=false" KCONF=M486
- elif [ "$TARGET" == i686 ]; then
- QEMU="i386 -cpu pentium3" KCONF=MPENTIUMII
- else
- QEMU=x86_64 KCONF=64BIT
- [ "$TARGET" == x32 ] && KCONF=X86_X32
- fi
- KARCH=x86 KARGS=ttyS0 VMLINUX=arch/x86/boot/bzImage
- KCONF=$KCONF,UNWINDER_FRAME_POINTER,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,NET_VENDOR_INTEL,E1000,SERIAL_8250,SERIAL_8250_CONSOLE,RTC_CLASS
- elif [ "$TARGET" == m68k ]; then
- QEMU="m68k -M q800" KARCH=m68k KARGS=ttyS0 VMLINUX=vmlinux
- KCONF=MMU,M68040,M68KFPU_EMU,MAC,SCSI,SCSI_LOWLEVEL,BLK_DEV_SD,SCSI_MAC_ESP,MACINTOSH_DRIVERS,NET_CORE,NET_VENDOR_NATSEMI,MACSONIC,SERIAL_PMACZILOG,SERIAL_PMACZILOG_TTYS,SERIAL_PMACZILOG_CONSOLE
- elif [ "$TARGET" == mips ] || [ "$TARGET" == mipsel ]; then
- QEMU="mips -M malta" KARCH=mips KARGS=ttyS0 VMLINUX=vmlinux
- KCONF=MIPS_MALTA,CPU_MIPS32_R2,SERIAL_8250,SERIAL_8250_CONSOLE,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,ATA_PIIX,NET_VENDOR_AMD,PCNET32,POWER_RESET,POWER_RESET_SYSCON
- [ "$TARGET" == mipsel ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN &&
- QEMU="mipsel -M malta"
- elif [ "$TARGET" == powerpc ]; then
- KARCH=powerpc QEMU="ppc -M g3beige" KARGS=ttyS0 VMLINUX=vmlinux
- KCONF=ALTIVEC,PPC_PMAC,PPC_OF_BOOT_TRAMPOLINE,ATA,ATA_SFF,ATA_BMDMA,PATA_MACIO,BLK_DEV_SD,MACINTOSH_DRIVERS,ADB,ADB_CUDA,NET_VENDOR_NATSEMI,NET_VENDOR_8390,NE2K_PCI,SERIO,SERIAL_PMACZILOG,SERIAL_PMACZILOG_TTYS,SERIAL_PMACZILOG_CONSOLE,BOOTX_TEXT
- elif [ "$TARGET" == powerpc64 ] || [ "$TARGET" == powerpc64le ]; then
- KARCH=powerpc QEMU="ppc64 -M pseries -vga none" KARGS=hvc0
- VMLINUX=vmlinux
- KCONF=PPC64,PPC_PSERIES,PPC_OF_BOOT_TRAMPOLINE,BLK_DEV_SD,SCSI_LOWLEVEL,SCSI_IBMVSCSI,ATA,NET_VENDOR_IBM,IBMVETH,HVC_CONSOLE,PPC_TRANSACTIONAL_MEM,PPC_DISABLE_WERROR,SECTION_MISMATCH_WARN_ONLY
- [ "$TARGET" == powerpc64le ] && KCONF=$KCONF,CPU_LITTLE_ENDIAN
- elif [ "$TARGET" = s390x ]; then
- QEMU="s390x" KARCH=s390 VMLINUX=arch/s390/boot/bzImage
- KCONF=MARCH_Z900,PACK_STACK,NET_CORE,VIRTIO_NET,VIRTIO_BLK,SCLP_TTY,SCLP_CONSOLE,SCLP_VT220_TTY,SCLP_VT220_CONSOLE,S390_GUEST
- elif [ "$TARGET" == sh2eb ]; then
- BUILTIN=1 KARCH=sh VMLINUX=vmlinux
- KERNEL_CONFIG=$'CONFIG_MEMORY_START=0x10000000\nCONFIG_CMDLINE="console=ttyUL0 earlycon"'
- KCONF=CPU_SUBTYPE_J2,CPU_BIG_ENDIAN,SH_JCORE_SOC,SMP,BINFMT_ELF_FDPIC,JCORE_EMAC,SERIAL_UARTLITE,SERIAL_UARTLITE_CONSOLE,HZ_100,CMDLINE_OVERWRITE,SPI,SPI_JCORE,MMC,PWRSEQ_SIMPLE,MMC_BLOCK,MMC_SPI
- elif [ "$TARGET" == sh4 ]; then
- QEMU="sh4 -M r2d -serial null -serial mon:stdio" KARCH=sh
- KARGS="ttySC1 noiotrap" VMLINUX=arch/sh/boot/zImage
- KERNEL_CONFIG="CONFIG_MEMORY_START=0x0c000000"
- KCONF=CPU_SUBTYPE_SH7751R,MMU,VSYSCALL,SH_FPU,SH_RTS7751R2D,RTS7751R2D_PLUS,SERIAL_SH_SCI,SERIAL_SH_SCI_CONSOLE,PCI,NET_VENDOR_REALTEK,8139CP,PCI,BLK_DEV_SD,ATA,ATA_SFF,ATA_BMDMA,PATA_PLATFORM,BINFMT_ELF_FDPIC,BINFMT_FLAT
-#see also SPI SPI_SH_SCI MFD_SM501 RTC_CLASS RTC_DRV_R9701 RTC_DRV_SH RTC_HCTOSYS
- else die "Unknown \$TARGET $TARGET"
- fi
-
- # Write the qemu launch script
- if [ -n "$QEMU" ]; then
- [ -z "$BUILTIN" ] && INITRD="-initrd initramfs.cpio.gz"
- { echo qemu-system-"$QEMU" '"$@"' $QEMU_MORE -nographic -no-reboot -m 256 \
- -kernel linux-kernel $INITRD ${DTB:+-dtb linux.dtb} \
- "-append \"panic=1 HOST=$TARGET console=$KARGS \$KARGS\"" &&
- echo "echo -e '\\e[?7h'"
- } > "$OUTPUT"/run-qemu.sh &&
- chmod +x "$OUTPUT"/run-qemu.sh || exit 1
- fi
-
- announce "linux-$KARCH"
- pushd "$LINUX" && make distclean && popd &&
- cp -sfR "$LINUX" "$TEMP/linux" && pushd "$TEMP/linux" &&
-
- # Write linux-miniconfig
- { echo "# make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG=linux-miniconfig"
- echo -e "# make ARCH=$KARCH -j \$(nproc)\n# boot $VMLINUX\n\n"
-
- # Expand list of =y symbols, first generic then architecture-specific
- for i in BINFMT_ELF,BINFMT_SCRIPT,NO_HZ,HIGH_RES_TIMERS,BLK_DEV,BLK_DEV_INITRD,RD_GZIP,BLK_DEV_LOOP,EXT4_FS,EXT4_USE_FOR_EXT2,VFAT_FS,FAT_DEFAULT_UTF8,MISC_FILESYSTEMS,SQUASHFS,SQUASHFS_XATTR,SQUASHFS_ZLIB,DEVTMPFS,DEVTMPFS_MOUNT,TMPFS,TMPFS_POSIX_ACL,NET,PACKET,UNIX,INET,IPV6,NETDEVICES,NET_CORE,NETCONSOLE,ETHERNET,COMPAT_32BIT_TIME,EARLY_PRINTK,IKCONFIG,IKCONFIG_PROC $KCONF $KEXTRA ; do
- echo "# architecture ${X:-independent}"
- csv2cfg "$i" y
- X=specific
- done
- [ -n "$BUILTIN" ] && echo -e CONFIG_INITRAMFS_SOURCE="\"$OUTPUT/fs\""
- for i in $MODULES; do csv2cfg "$i" m; done
- echo "$KERNEL_CONFIG"
- } > "$OUTPUT/linux-miniconfig" &&
- make ARCH=$KARCH allnoconfig KCONFIG_ALLCONFIG="$OUTPUT/linux-miniconfig" &&
-
- # Second config pass to remove stupid kernel defaults
- # See http://lkml.iu.edu/hypermail/linux/kernel/1912.3/03493.html
- sed -e 's/# CONFIG_EXPERT .*/CONFIG_EXPERT=y/' -e "$(sed -E -e '/^$/d' \
- -e 's@([^,]*)($|,)@/^CONFIG_\1=y/d;$a# CONFIG_\1 is not set\n@g' \
- <<< VT,SCHED_DEBUG,DEBUG_MISC,X86_DEBUG_FPU)" -i .config &&
- yes "" | make ARCH=$KARCH oldconfig > /dev/null &&
- cp .config "$OUTPUT/linux-fullconfig" &&
-
- # Build kernel. Copy config, device tree binary, and kernel binary to output
- make ARCH=$KARCH CROSS_COMPILE="$CROSS_COMPILE" -j $(nproc) all || exit 1
- [ -n "$DTB" ] && { cp "$DTB" "$OUTPUT/linux.dtb" || exit 1 ;}
- if [ -n "$MODULES" ]; then
- make ARCH=$KARCH INSTALL_MOD_PATH=modz modules_install &&
- (cd modz && find lib/modules | cpio -o -H newc $CPIO_OPTS ) | gzip \
- > "$OUTPUT/modules.cpio.gz" || exit 1
- fi
- cp "$VMLINUX" "$OUTPUT"/linux-kernel && cd .. && rm -rf linux && popd ||exit 1
-fi
-
-# clean up and package root filesystem for initramfs.
-if [ -z "$BUILTIN" ]; then
- announce initramfs
- { (cd "$ROOT" && find . | cpio -o -H newc $CPIO_OPTS ) || exit 1
- ! test -e "$OUTPUT/modules.cpio.gz" || zcat $_;} | gzip \
- > "$OUTPUT"/initramfs.cpio.gz || exit 1
-fi
-
-mv "$LOG/$CROSS".{n,y}
-rmdir "$TEMP" "$BUILD" 2>/dev/null || exit 0 # remove if empty, not an error
+#!/usr/bin/printf Moved to mkroot/mkroot.sh\n\c%s
diff --git a/scripts/root/overlay b/scripts/root/overlay
deleted file mode 100755
index f02f3db0..00000000
--- a/scripts/root/overlay
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/echo Try "scripts/mkroot.sh overlay"
-
-cp -a "${OVERLAY:=overlay}"/. "$ROOT"/.
diff --git a/toys/other/oneit.c b/toys/other/oneit.c
index d154f582..c0b0c09d 100644
--- a/toys/other/oneit.c
+++ b/toys/other/oneit.c
@@ -72,14 +72,15 @@ void oneit_main(void)
// Autodetect console from sysfs if no -c
memcpy(toybuf, "/dev/", 5);
- if (!TT.c && (TT.c = readfile("/sys/class/tty/console/active", ss, 4096))) {
- // Remove null terminator, take last entry
- for (;;) {
- if (!(ss = strchr(TT.c, '\n'))) break;
- if (!ss[1]) *ss = 0;
- else TT.c = ++ss;
+ i = sizeof(toybuf)-6;
+ if (!TT.c && (TT.c = readfile("/sys/class/tty/console/active", ss, i))) {
+ // Take last entry, remove newline terminator
+ while (TT.c[i = strcspn(TT.c, " \n")]) {
+ TT.c[i++] = 0;
+ if (TT.c[i]) TT.c += i;
+ else break;
}
- // Ensure /dev prefix
+ // Ensure exactly one /dev prefix
strstart(&TT.c, "/dev/");
memmove(toybuf+5, TT.c, strlen(TT.c));
TT.c = toybuf;
diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c
index d5cf5691..94502f1f 100644
--- a/toys/other/vmstat.c
+++ b/toys/other/vmstat.c
@@ -29,125 +29,124 @@ config VMSTAT
#include "toys.h"
struct vmstat_proc {
- // From /proc/stat (jiffies)
- uint64_t user, nice, sys, idle, wait, irq, sirq, intr, ctxt, running, blocked;
- // From /proc/meminfo (units are kb)
- uint64_t memfree, buffers, cached, swapfree, swaptotal;
- // From /proc/vmstat (units are kb)
- uint64_t io_in, io_out;
- // From /proc/vmstat (units are pages)
- uint64_t swap_in, swap_out;
+ unsigned long long
+ // From /proc/stat (jiffies) 0-10
+ user, nice, sys, idle, wait, irq, sirq, intr, ctxt, running, blocked,
+ // From /proc/meminfo (units are kb) 11-16
+ memfree, buffers, cached, swapfree, swaptotal, reclaimable,
+ // From /proc/vmstat (units are kb) 17-18
+ io_in, io_out,
+ // From /proc/vmstat (units are pages) 19-20
+ swap_in, swap_out;
};
// All the elements of vmstat_proc are the same size, so we can populate it as
// a big array, then read the elements back out by name
-static void get_vmstat_proc(struct vmstat_proc *vmstat_proc)
+static void get_vmstat_proc(struct vmstat_proc *vmsp)
{
- char *vmstuff[] = { "/proc/stat", "cpu ", 0, 0, 0, 0, 0, 0,
- "intr ", "ctxt ", "procs_running ", "procs_blocked ", "/proc/meminfo",
- "MemFree: ", "Buffers: ", "Cached: ", "SwapFree: ", "SwapTotal: ",
+ char *vmstuff[] = { "/proc/stat", "cpu ", 0, 0, 0, 0, 0, 0, "intr ", "ctxt ",
+ "procs_running ", "procs_blocked ", "/proc/meminfo", "MemFree:",
+ "Buffers:", "Cached:", "SwapFree:", "SwapTotal:", "SReclaimable:",
"/proc/vmstat", "pgpgin ", "pgpgout ", "pswpin ", "pswpout " };
- uint64_t *new = (uint64_t *)vmstat_proc;
- char *p = p, *name = name, *file = NULL;
+ unsigned long long *new = (void *)vmsp;
+ char *p = 0, *name = name, *file = 0;
int i, j;
- // We use vmstuff to fill out vmstat_proc as an array of uint64_t:
+ // We use vmstuff to fill out vmstat_proc as an array of long long:
// Strings starting with / are the file to find next entries in
// Any other string is a key to search for, with decimal value right after
// 0 means parse another value on same line as last key
- for (i = 0; i<ARRAY_LEN(vmstuff); i++) {
- if (!vmstuff[i]) p++;
+ memset(new, 0, sizeof(struct vmstat_proc));
+ for (i = j = 0; i<ARRAY_LEN(vmstuff); i++) {
+ if (!vmstuff[i]) p++; // Read next entry on same line
else if (*vmstuff[i] == '/') {
- // /proc/stat for a 48-core machine doesn't fit in toybuf.
free(file);
file = xreadfile(name = vmstuff[i], 0, 0);
continue;
- } else p = strafter(file, vmstuff[i]);
- if (!p || 1!=sscanf(p, "%"PRIu64"%n", new++, &j))
- error_exit("Bad %sin %s: %s", vmstuff[i], name, p ? p : "");
- p += j;
+ } else if (file && !(p = strafter(file, vmstuff[i]))) {
+ free(file);
+ file = 0;
+ }
+ if (!file) new++;
+ else if (1==sscanf(p, "%llu%n", new++, &j)) p += j;
}
free(file);
+
+ // combine some fields we display as aggregates
+ vmsp->running--; // Don't include ourselves
+ vmsp->user += vmsp->nice;
+ vmsp->sys += vmsp->irq + vmsp->sirq;
+ vmsp->swaptotal -= vmsp->swapfree;
+ vmsp->cached += vmsp->reclaimable;
}
void vmstat_main(void)
{
- struct vmstat_proc top[2];
int i, loop_delay = 0, loop_max = 0;
unsigned loop, rows = 25, page_kb = sysconf(_SC_PAGESIZE)/1024;
- char *headers="r\0b\0swpd\0free\0buff\0cache\0si\0so\0bi\0bo\0in\0cs\0us\0"
- "sy\0id\0wa", lengths[] = {2,2,7,7,6,7,5,5,5,5,5,5,2,2,2,2};
+ unsigned long long units, total_hz, *ptr, *oldptr;
+ char *headers = "r\0b\0swpd\0free\0buff\0cache\0si\0so\0bi\0bo\0in\0cs\0us\0"
+ "sy\0id\0wa", lengths[] = {2,2,7,7,6,7,4,4,5,5,4,4,2,2,2,2};
- memset(top, 0, sizeof(top));
if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX);
- if (toys.optc > 1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX);
+ if (toys.optc>1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX);
+
+ xreadfile("/proc/uptime", toybuf, sizeof(toybuf));
+ sscanf(toybuf, "%*s %llu", &units);
- for (loop = 0; !loop_max || loop < loop_max; loop++) {
- unsigned idx = loop&1, offset = 0, expected = 0;
- uint64_t units, total_hz, *ptr = (uint64_t *)(top+idx),
- *oldptr = (uint64_t *)(top+!idx);
+ for (loop = 0; !loop_max || loop<loop_max; loop++) {
+ unsigned offset = 0, expected = 0;
if (loop && loop_delay) sleep(loop_delay);
+ ptr = oldptr = (void *)toybuf;
+ *((loop&1) ? &ptr : &oldptr) += sizeof(struct vmstat_proc);
+ get_vmstat_proc((void *)ptr);
+
// Print headers
if (rows>3 && !(loop % (rows-3))) {
char *header = headers;
- if (!(toys.optflags&FLAG_n) && isatty(1)) terminal_size(0, &rows);
+ if (!FLAG(n) && isatty(1)) terminal_size(0, &rows);
else rows = 0;
- printf("procs ------------memory------------ ----swap--- -----io---- ---system-- ----cpu----\n");
- for (i=0; i<sizeof(lengths); i++) {
+ printf("procs ------------memory------------ ---swap-- -----io---- --system- ----cpu----\n");
+ for (i = 0; i<sizeof(lengths); i++) {
printf(" %*s"+!i, lengths[i], header);
header += strlen(header)+1;
}
xputc('\n');
}
- // Read data and combine some fields we display as aggregates
- get_vmstat_proc(top+idx);
- top[idx].running--; // Don't include ourselves
- top[idx].user += top[idx].nice;
- top[idx].sys += top[idx].irq + top[idx].sirq;
- top[idx].swaptotal -= top[idx].swapfree;
-
- // Collect unit adjustments (outside the inner loop to save time)
-
- if (!loop) {
- char *s = toybuf;
-
- xreadfile("/proc/uptime", toybuf, sizeof(toybuf));
- while (*(s++) > ' ');
- sscanf(s, "%"PRIu64, &units);
- } else units = loop_delay;
+ if (loop) units = loop_delay;
// add up user, sys, idle, and wait time used since last time
// (Already appended nice to user)
- total_hz = 0;
- for (i=0; i<4; i++) total_hz += ptr[i+!!i] - oldptr[i+!!i];
+ for (i = total_hz = 0; i<4; i++) total_hz += ptr[i+!!i] - oldptr[i+!!i];
// Output values in order[]: running, blocked, swaptotal, memfree, buffers,
- // cache, swap_in, swap_out, io_in, io_out, sirq, ctxt, user, sys, idle,wait
+ // cache, swap_in, swap_out, io_in, io_out, intr, ctxt, user, sys, idle,wait
for (i=0; i<sizeof(lengths); i++) {
- char order[] = {9, 10, 15, 11, 12, 13, 18, 19, 16, 17, 6, 8, 0, 2, 3, 4};
- uint64_t out = ptr[order[i]];
+ char order[] = {9, 10, 15, 11, 12, 13, 19, 20, 17, 18, 7, 8, 0, 2, 3, 4};
+ unsigned long long out = ptr[order[i]];
int len;
// Adjust rate and units
if (i>5) out -= oldptr[order[i]];
if (order[i]<7) out = ((out*100) + (total_hz/2)) / total_hz;
- else if (order[i]>17) out = ((out * page_kb)+(units-1))/units;
- else if (order[i]>15) out = ((out)+(units-1))/units;
- else if (order[i]<9) out = (out+(units-1)) / units;
+ else if (order[i]>16) {
+ if (order[i]>18) out *= page_kb;
+ out = (out*page_kb+(units-1))/units;
+ } else if (order[i]<9) out = (out+(units-1)) / units;
// If a field was too big to fit in its slot, try to compensate later
expected += lengths[i] + !!i;
len = expected - offset - !!i;
if (len < 0) len = 0;
- offset += printf(" %*"PRIu64+!i, len, out);
+ offset += printf(" %*llu"+!i, len, out);
}
xputc('\n');
diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index fc5b5f6f..56d5c638 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -13,7 +13,7 @@
* and we do --time-style=long-iso instead
* ignore -k because we default to 1024 byte blocks
-USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE))
config LS
bool "ls"
diff --git a/toys/posix/tar.c b/toys/posix/tar.c
index 5af32db8..ea8edbf7 100644
--- a/toys/posix/tar.c
+++ b/toys/posix/tar.c
@@ -1147,7 +1147,7 @@ void tar_main(void)
if (FLAG(j)||FLAG(z)||FLAG(I)||FLAG(J)) {
int pipefd[2] = {-1, TT.fd};
- xpopen_both((char *[]){get_archiver(), 0}, pipefd);
+ TT.pid = xpopen_both((char *[]){get_archiver(), 0}, pipefd);
close(TT.fd);
TT.fd = pipefd[0];
}
@@ -1159,6 +1159,7 @@ void tar_main(void)
} while (TT.incl != (dl = dl->next));
writeall(TT.fd, toybuf, 1024);
+ close(TT.fd);
}
if (TT.pid) {
TT.pid = xpclose_both(TT.pid, 0);
diff --git a/toys/posix/test.c b/toys/posix/test.c
index f9a2bbbb..cdb13e2a 100644
--- a/toys/posix/test.c
+++ b/toys/posix/test.c
@@ -28,7 +28,7 @@ config TEST
STRING is:
-n nonzero size -z zero size
FD (integer file descriptor) is:
- -t a TTY
+ -t a TTY -T open
--- Tests with one argument on each side of an operator:
Two strings:
@@ -109,6 +109,7 @@ static int do_test(char **args, int *count)
} else if (c == 'z') return !*args[1];
else if (c == 'n') return *args[1];
else if (c == 't') return isatty(atolx(args[1]));
+ else if (c == 'T') return -1 != fcntl(atolx(args[1]), F_GETFL);
}
return *count = 0;
}
diff --git a/www/faq.html b/www/faq.html
index 79200550..d166bad5 100755
--- a/www/faq.html
+++ b/www/faq.html
@@ -759,7 +759,7 @@ auditable version of the cmdline portion of that base.</p>
<hr /><h2><a name="mkroot" />Q: How do you build a working Linux system with toybox?</h2>
-<p>A: Toybox has a built-in <a href=https://github.com/landley/toybox/blob/master/scripts/mkroot.sh>system builder</a>, with the Makefile target "<b>make
+<p>A: Toybox has a built-in <a href=https://github.com/landley/toybox/blob/master/mkroot/mkroot.sh>system builder</a> called "<a href=https://github.com/landley/toybox/blob/master/mkroot/README>mkroot</a>", with the Makefile target "<b>make
root</b>". To enter the resulting root filesystem, "<b>sudo chroot
root/host/fs /init</b>". Type "exit" to get back out.</p>
@@ -832,7 +832,7 @@ to the build, by calling the script directly and listing packages on
the command line:</p>
<blockquote>
-<p><b>scripts/mkroot.sh CROSS=all LINUX=~/linux dropbear</b></p>
+<p><b>mkroot/mkroot.sh CROSS=all LINUX=~/linux dropbear</b></p>
</blockquote>
<p>An example package build script (building the dropbear ssh server, adding a
diff --git a/www/roadmap.html b/www/roadmap.html
index e10ebd49..7c32b2a7 100644
--- a/www/roadmap.html
+++ b/www/roadmap.html
@@ -488,37 +488,36 @@ echo egrep env expr find fuser getconf getopt git grep gzip head hexdump
hostname id jar java javap ln ls lsof m4 make md5sum mkdir mktemp mv od openssl
paste patch pgrep pkill ps pstree pwd python python2.7 python3 readlink
realpath rm rmdir rsync sed setsid sh sha1sum sha256sum sha512sum
-sleep sort stat tar tail tee todos touch tr true uname uniq unix2dos unzip
+sleep sort stat tar tail tee touch tr true uname uniq unix2dos unzip
wc which whoami xargs xxd xz zip zipinfo
</b></blockquote>
<p>The following are already in the tree and will be used directly:</p>
<blockquote><b>
-awk bzip2 jar java javap m4 make python python2.7 python3 xz
+awk bc bzip2 jar java javap m4 make python python2.7 python3 xz
</b></blockquote>
<p>Subtracting what's already in toybox (including the following toybox toys
-that are still in pending: <code>bc dd diff expr gzip lsof tar tr</code>),
+that are still in pending: <code>dd diff expr getopt gzip lsof tr</code>),
that leaves:</p>
<blockquote><b>
-bash fuser getopt git hexdump openssl pstree rsync sh todos unzip zip zipinfo
+bash dlv fuser git hexdump openssl pstree rsync sh unzip zip zipinfo
</b></blockquote>
-<p>For AOSP, zip/zipinfo/unzip are likely to be libziparchive based. The
-todos callers will use unix2dos instead if it's available. git/openssl
-seem like they should just be brought in to the tree. rsync is used to
-work around a Mac <code>cp -Rf</code> bug with broken symbolic links. That
-leaves:</p>
+<p>For AOSP, zip/zipinfo/unzip are likely to be libziparchive based.
+git/openssl seem like they should just be brought in to the tree. rsync is
+used to work around a Mac <code>cp -Rf</code> bug with broken symbolic links.
+That leaves:</p>
<blockquote><b>
-bash fuser getopt hexdump pstree
+bash fuser hexdump pstree
</b></blockquote>
<p>(Why are fuser and pstree used during the AOSP build? They're used for
-diagnostics if something goes wrong. So it's really just bash, getopt,
-and hexdump that are actually used to build.)</p>
+diagnostics if something goes wrong. So it's really just bash and hexdump
+that are actually used to build.)</p>
<hr />
<h2><a name=tizen /><a href="#tizen">Use case: Tizen Core</a></h2>