From 126c719dd250735f1c9517dfb6dcdfe02f347818 Mon Sep 17 00:00:00 2001
From: Rob Landley
Date: Sun, 16 Apr 2023 20:18:02 -0500
Subject: [PATCH] Move mkroot into its own directory.
---
Makefile | 2 +-
{scripts => mkroot}/mkroot.sh | 9 +++++----
{scripts => mkroot}/record-commands | 0
{scripts => mkroot}/root/dropbear | 2 +-
{scripts => mkroot}/root/dynamic | 2 +-
mkroot/root/overlay | 3 +++
{scripts => mkroot}/root/plumbing | 0
{scripts => mkroot}/root/tests | 2 +-
scripts/test_mkroot.sh => mkroot/testroot.sh | 19 +++++++++++++++++--
scripts/root/overlay | 3 ---
www/faq.html | 4 ++--
11 files changed, 31 insertions(+), 15 deletions(-)
rename {scripts => mkroot}/mkroot.sh (98%)
rename {scripts => mkroot}/record-commands (100%)
rename {scripts => mkroot}/root/dropbear (97%)
rename {scripts => mkroot}/root/dynamic (93%)
create mode 100755 mkroot/root/overlay
rename {scripts => mkroot}/root/plumbing (100%)
rename {scripts => mkroot}/root/tests (93%)
rename scripts/test_mkroot.sh => mkroot/testroot.sh (77%)
delete mode 100755 scripts/root/overlay
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/scripts/mkroot.sh b/mkroot/mkroot.sh
similarity index 98%
rename from scripts/mkroot.sh
rename to mkroot/mkroot.sh
index 60433240..0447b386 100755
--- a/scripts/mkroot.sh
+++ b/mkroot/mkroot.sh
@@ -6,6 +6,8 @@
[ -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"; }
@@ -13,9 +15,8 @@ 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}
+: ${AIRLOCK:=$BUILD/airlock} ${CCC:=$PWD/ccc} ${PKGDIR:=$PWD/mkroot/root}
-# define functions
announce() { printf "\033]2;$CROSS $*\007" >/dev/tty; printf "\n=== $*\n";}
die() { echo "$@" >&2; exit 1; }
@@ -80,7 +81,7 @@ if [ -z "$NOLOGPATH" ]; then
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 ||
+ WRAPDIR="$WRAPDIR" CROSS_COMPILE= NOSTRIP=1 source mkroot/record-commands ||
exit 1
fi
@@ -304,5 +305,5 @@ if [ -z "$BUILTIN" ]; then
> "$OUTPUT"/initramfs.cpio.gz || exit 1
fi
-mv "$LOG/$CROSS".{n,y}
+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
similarity index 100%
rename from scripts/record-commands
rename to mkroot/record-commands
diff --git a/scripts/root/dropbear b/mkroot/root/dropbear
similarity index 97%
rename from scripts/root/dropbear
rename to 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
similarity index 93%
rename from scripts/root/dynamic
rename to 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
similarity index 100%
rename from scripts/root/plumbing
rename to mkroot/root/plumbing
diff --git a/scripts/root/tests b/mkroot/root/tests
similarity index 93%
rename from scripts/root/tests
rename to 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
similarity index 77%
rename from scripts/test_mkroot.sh
rename to 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/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/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.
Q: How do you build a working Linux system with toybox?
-A: Toybox has a built-in system builder, with the Makefile target "make
+
A: Toybox has a built-in system builder called "mkroot", with the Makefile target "make
root". To enter the resulting root filesystem, "sudo chroot
root/host/fs /init". Type "exit" to get back out.
@@ -832,7 +832,7 @@ to the build, by calling the script directly and listing packages on
the command line:
-scripts/mkroot.sh CROSS=all LINUX=~/linux dropbear
+mkroot/mkroot.sh CROSS=all LINUX=~/linux dropbear
An example package build script (building the dropbear ssh server, adding a
--
2.39.2