aboutsummaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
authorBjørn Mork <bjorn@mork.no>2015-05-15 10:20:47 +0200
committerBjørn Mork <bjorn@mork.no>2015-05-15 10:20:47 +0200
commit73b16af8feec390afbabd9356d6e5e83c0390838 (patch)
tree3730020ba2f9caeb9d7815a975af51830b51ce11 /applets
busybox: imported from http://www.busybox.net/downloads/busybox-1.13.3.tar.bz2busybox-1.13.3
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Diffstat (limited to 'applets')
-rw-r--r--applets/Kbuild34
-rw-r--r--applets/applet_tables.c126
-rw-r--r--applets/applets.c18
-rwxr-xr-xapplets/busybox.mkll24
-rw-r--r--applets/individual.c24
-rwxr-xr-xapplets/install.sh110
-rw-r--r--applets/usage.c29
-rwxr-xr-xapplets/usage_compressed34
8 files changed, 399 insertions, 0 deletions
diff --git a/applets/Kbuild b/applets/Kbuild
new file mode 100644
index 0000000..2969e79
--- /dev/null
+++ b/applets/Kbuild
@@ -0,0 +1,34 @@
+# Makefile for busybox
+#
+# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org>
+#
+# Licensed under the GPL v2, see the file LICENSE in this tarball.
+
+obj-y :=
+obj-y += applets.o
+
+hostprogs-y:=
+hostprogs-y += usage applet_tables
+
+always:= $(hostprogs-y)
+
+# Generated files need additional love
+
+HOSTCFLAGS_usage.o = -I$(srctree)/include
+
+applets/applets.o: include/usage_compressed.h include/applet_tables.h
+
+applets/usage: .config $(srctree)/applets/usage_compressed
+applets/applet_tables: .config
+
+quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
+ cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
+
+include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
+ $(call cmd,gen_usage_compressed)
+
+quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
+ cmd_gen_applet_tables = applets/applet_tables include/applet_tables.h
+
+include/applet_tables.h: applets/applet_tables
+ $(call cmd,gen_applet_tables)
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
new file mode 100644
index 0000000..17135dd
--- /dev/null
+++ b/applets/applet_tables.c
@@ -0,0 +1,126 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Applet table generator.
+ * Runs on host and produces include/applet_tables.h
+ *
+ * Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
+ *
+ * Licensed under GPLv2, see file License in this tarball for details.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "../include/autoconf.h"
+#include "../include/busybox.h"
+
+struct bb_applet {
+ const char *name;
+ const char *main;
+ enum bb_install_loc_t install_loc;
+ enum bb_suid_t need_suid;
+ /* true if instead of fork(); exec("applet"); waitpid();
+ * one can do fork(); exit(applet_main(argc,argv)); waitpid(); */
+ unsigned char noexec;
+ /* Even nicer */
+ /* true if instead of fork(); exec("applet"); waitpid();
+ * one can simply call applet_main(argc,argv); */
+ unsigned char nofork;
+};
+
+/* Define struct bb_applet applets[] */
+#include "../include/applets.h"
+
+enum { NUM_APPLETS = ARRAY_SIZE(applets) };
+
+static int offset[NUM_APPLETS];
+
+static int cmp_name(const void *a, const void *b)
+{
+ const struct bb_applet *aa = a;
+ const struct bb_applet *bb = b;
+ return strcmp(aa->name, bb->name);
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+ int ofs;
+ unsigned MAX_APPLET_NAME_LEN = 1;
+
+ qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
+
+ ofs = 0;
+ for (i = 0; i < NUM_APPLETS; i++) {
+ offset[i] = ofs;
+ ofs += strlen(applets[i].name) + 1;
+ }
+ /* We reuse 4 high-order bits of offset array for other purposes,
+ * so if they are indeed needed, refuse to proceed */
+ if (ofs > 0xfff)
+ return 1;
+ if (!argv[1])
+ return 1;
+
+ i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
+ if (i < 0)
+ return 1;
+ dup2(i, 1);
+
+ /* Keep in sync with include/busybox.h! */
+
+ puts("/* This is a generated file, don't edit */\n");
+
+ printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
+ if (NUM_APPLETS == 1) {
+ printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
+ printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
+ }
+
+ puts("\nconst char applet_names[] ALIGN1 = \"\"");
+ for (i = 0; i < NUM_APPLETS; i++) {
+ printf("\"%s\" \"\\0\"\n", applets[i].name);
+ if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
+ MAX_APPLET_NAME_LEN = strlen(applets[i].name);
+ }
+ puts(";");
+
+ puts("\nint (*const applet_main[])(int argc, char **argv) = {");
+ for (i = 0; i < NUM_APPLETS; i++) {
+ printf("%s_main,\n", applets[i].main);
+ }
+ puts("};");
+
+ puts("const uint16_t applet_nameofs[] ALIGN2 = {");
+ for (i = 0; i < NUM_APPLETS; i++) {
+ printf("0x%04x,\n",
+ offset[i]
+#if ENABLE_FEATURE_PREFER_APPLETS
+ + (applets[i].nofork << 12)
+ + (applets[i].noexec << 13)
+#endif
+#if ENABLE_FEATURE_SUID
+ + (applets[i].need_suid << 14) /* 2 bits */
+#endif
+ );
+ }
+ puts("};");
+
+#if ENABLE_FEATURE_INSTALLER
+ puts("const uint8_t applet_install_loc[] ALIGN1 = {");
+ i = 0;
+ while (i < NUM_APPLETS) {
+ int v = applets[i].install_loc; /* 3 bits */
+ if (++i < NUM_APPLETS)
+ v |= applets[i].install_loc << 4; /* 3 bits */
+ printf("0x%02x,\n", v);
+ i++;
+ }
+ puts("};\n");
+#endif
+
+ printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
+
+ return 0;
+}
diff --git a/applets/applets.c b/applets/applets.c
new file mode 100644
index 0000000..133a215
--- /dev/null
+++ b/applets/applets.c
@@ -0,0 +1,18 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Stub for linking busybox binary against libbusybox.
+ *
+ * Copyright (C) 2007 Denys Vlasenko <vda.linux@googlemail.com>
+ *
+ * Licensed under GPLv2, see file License in this tarball for details.
+ */
+
+#include <assert.h>
+#include "busybox.h"
+
+#if ENABLE_BUILD_LIBBUSYBOX
+int main(int argc UNUSED_PARAM, char **argv)
+{
+ return lbb_main(argv);
+}
+#endif
diff --git a/applets/busybox.mkll b/applets/busybox.mkll
new file mode 100755
index 0000000..6d61f7e
--- /dev/null
+++ b/applets/busybox.mkll
@@ -0,0 +1,24 @@
+#!/bin/sh
+# Make busybox links list file.
+
+# input $1: full path to Config.h
+# input $2: full path to applets.h
+# output (stdout): list of pathnames that should be linked to busybox
+
+# Maintainer: Larry Doolittle <ldoolitt@recycle.lbl.gov>
+
+export LC_ALL=POSIX
+export LC_CTYPE=POSIX
+
+CONFIG_H=${1:-include/autoconf.h}
+APPLETS_H=${2:-include/applets.h}
+$HOSTCC -E -DMAKE_LINKS -include $CONFIG_H $APPLETS_H |
+ awk '/^[ \t]*LINK/{
+ dir=substr($2,8)
+ gsub("_","/",dir)
+ if(dir=="/ROOT") dir=""
+ file=$3
+ gsub("\"","",file)
+ if (file=="busybox") next
+ print tolower(dir) "/" file
+ }'
diff --git a/applets/individual.c b/applets/individual.c
new file mode 100644
index 0000000..341f4d1
--- /dev/null
+++ b/applets/individual.c
@@ -0,0 +1,24 @@
+/* Minimal wrapper to build an individual busybox applet.
+ *
+ * Copyright 2005 Rob Landley <rob@landley.net
+ *
+ * Licensed under GPL version 2, see file LICENSE in this tarball for details
+ */
+
+const char *applet_name;
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "usage.h"
+
+int main(int argc, char **argv)
+{
+ applet_name = argv[0];
+ return APPLET_main(argc,argv);
+}
+
+void bb_show_usage(void)
+{
+ fputs(APPLET_full_usage "\n", stdout);
+ exit(EXIT_FAILURE);
+}
diff --git a/applets/install.sh b/applets/install.sh
new file mode 100755
index 0000000..32049b1
--- /dev/null
+++ b/applets/install.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+export LC_ALL=POSIX
+export LC_CTYPE=POSIX
+
+prefix=${1}
+if [ -z "$prefix" ]; then
+ echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
+ exit 1;
+fi
+h=`sort busybox.links | uniq`
+scriptwrapper="n"
+cleanup="0"
+noclobber="0"
+case "$2" in
+ --hardlinks) linkopts="-f";;
+ --symlinks) linkopts="-fs";;
+ --scriptwrapper) scriptwrapper="y";swrapall="y";;
+ --sw-sh-hard) scriptwrapper="y";linkopts="-f";;
+ --sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
+ --cleanup) cleanup="1";;
+ --noclobber) noclobber="1";;
+ "") h="";;
+ *) echo "Unknown install option: $2"; exit 1;;
+esac
+
+if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
+ # get the target dir for the libs
+ # assume it starts with lib
+ libdir=$($CC -print-file-name=libc.so | \
+ sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
+ if test -z "$libdir"; then
+ libdir=/lib
+ fi
+
+ mkdir -p $prefix/$libdir || exit 1
+ for i in $DO_INSTALL_LIBS; do
+ rm -f $prefix/$libdir/$i || exit 1
+ if [ -f $i ]; then
+ cp -pPR $i $prefix/$libdir/ || exit 1
+ chmod 0644 $prefix/$libdir/$i || exit 1
+ fi
+ done
+fi
+
+if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
+ inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
+ sub_shell_it=`
+ cd "$prefix"
+ for d in usr/sbin usr/bin sbin bin; do
+ pd=$PWD
+ if [ -d "$d" ]; then
+ cd $d
+ ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
+ fi
+ cd "$pd"
+ done
+ `
+ exit 0
+fi
+
+rm -f $prefix/bin/busybox || exit 1
+mkdir -p $prefix/bin || exit 1
+install -m 755 busybox $prefix/bin/busybox || exit 1
+
+for i in $h; do
+ appdir=`dirname $i`
+ mkdir -p $prefix/$appdir || exit 1
+ if [ "$scriptwrapper" = "y" ]; then
+ if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
+ ln $linkopts busybox $prefix$i || exit 1
+ else
+ rm -f $prefix$i
+ echo "#!/bin/busybox" > $prefix$i
+ chmod +x $prefix/$i
+ fi
+ echo " $prefix$i"
+ else
+ if [ "$2" = "--hardlinks" ]; then
+ bb_path="$prefix/bin/busybox"
+ else
+ case "$appdir" in
+ /)
+ bb_path="bin/busybox"
+ ;;
+ /bin)
+ bb_path="busybox"
+ ;;
+ /sbin)
+ bb_path="../bin/busybox"
+ ;;
+ /usr/bin|/usr/sbin)
+ bb_path="../../bin/busybox"
+ ;;
+ *)
+ echo "Unknown installation directory: $appdir"
+ exit 1
+ ;;
+ esac
+ fi
+ if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
+ echo " $prefix$i -> $bb_path"
+ ln $linkopts $bb_path $prefix$i || exit 1
+ else
+ echo " $prefix$i already exists"
+ fi
+ fi
+done
+
+exit 0
diff --git a/applets/usage.c b/applets/usage.c
new file mode 100644
index 0000000..a35817f
--- /dev/null
+++ b/applets/usage.c
@@ -0,0 +1,29 @@
+/* vi: set sw=4 ts=4: */
+#include <unistd.h>
+
+/* Just #include "autoconf.h" doesn't work for builds in separate
+ * object directory */
+#include "../include/autoconf.h"
+
+/* Since we can't use platform.h, have to do this again by hand: */
+#if ENABLE_NOMMU
+#define BB_MMU 0
+#define USE_FOR_NOMMU(...) __VA_ARGS__
+#define USE_FOR_MMU(...)
+#else
+#define BB_MMU 1
+#define USE_FOR_NOMMU(...)
+#define USE_FOR_MMU(...) __VA_ARGS__
+#endif
+
+static const char usage_messages[] = ""
+#define MAKE_USAGE
+#include "usage.h"
+#include "applets.h"
+;
+
+int main(void)
+{
+ write(STDOUT_FILENO, usage_messages, sizeof(usage_messages));
+ return 0;
+}
diff --git a/applets/usage_compressed b/applets/usage_compressed
new file mode 100755
index 0000000..c30bcfa
--- /dev/null
+++ b/applets/usage_compressed
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+target="$1"
+loc="$2"
+
+test "$target" || exit 1
+test "$loc" || loc=.
+test -x "$loc/usage" || exit 1
+test "$SED" || SED=sed
+
+sz=`"$loc/usage" | wc -c` || exit 1
+
+exec >"$target"
+
+echo 'static const char packed_usage[] ALIGN1 = {'
+
+## Breaks on big-endian systems!
+## # Extra effort to avoid using "od -t x1": -t is not available
+## # in non-CONFIG_DESKTOPed busybox od
+##
+## "$loc/usage" | bzip2 -1 | od -v -x \
+## | $SED -e 's/^[^ ]*//' \
+## | $SED -e 's/ //g' \
+## | grep -v '^$' \
+## | $SED -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
+
+"$loc/usage" | bzip2 -1 | od -v -t x1 \
+| $SED -e 's/^[^ ]*//' \
+| $SED -e 's/ //g' \
+| grep -v '^$' \
+| $SED -e 's/\(..\)/0x\1,/g'
+
+echo '};'
+echo '#define SIZEOF_usage_messages' `expr 0 + $sz`