aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2023-04-18 14:46:32 -0700
committerYifan Hong <elsk@google.com>2023-04-18 14:46:32 -0700
commitcf4e1d149f4fde8109847a5026657b0f3c6848ca (patch)
tree356995ea5897a67cdbb616848faf101614325f63
parentabfa1d892f699cadb8951eeb03efc3e69d39f405 (diff)
parent827dfe3fe1bc9da2c215f54a5124fb0edcc9321c (diff)
downloadtoybox-cf4e1d149f4fde8109847a5026657b0f3c6848ca.tar.gz
Upgrade toybox to 827dfe3fe1bc9da2c215f54a5124fb0edcc9321c
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update toybox For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: I9ab0bb64ac3c18fe9aba35862ca6e73d2eb15597
-rw-r--r--METADATA4
-rw-r--r--Makefile2
-rw-r--r--android/device/generated/help.h2
-rw-r--r--android/linux/generated/help.h2
-rw-r--r--android/mac/generated/help.h2
-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/posix/tar.c3
-rw-r--r--toys/posix/test.c3
-rwxr-xr-xwww/faq.html4
18 files changed, 345 insertions, 326 deletions
diff --git a/METADATA b/METADATA
index 70204fac..727a0aef 100644
--- a/METADATA
+++ b/METADATA
@@ -13,11 +13,11 @@ third_party {
type: GIT
value: "https://github.com/landley/toybox"
}
- version: "8626a6ac7dff93bf97f754c93c3e426ee5c6b1e0"
+ version: "827dfe3fe1bc9da2c215f54a5124fb0edcc9321c"
license_type: UNENCUMBERED
last_upgrade_date {
year: 2023
month: 4
- day: 17
+ day: 18
}
}
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/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/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/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/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/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