annotate simple-root-filesystem.sh @ 1472:a4673f17b7c0

Add record-commands wrapper and plumbing to target image, so you can record-commands /mnt/init in a native build.
author Rob Landley <rob@landley.net>
date Tue, 06 Dec 2011 21:29:16 -0600
parents b74d36876c0a
children b381adcd7968
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
177
6b4844b708b9 dash->bash.
Rob Landley <rob@landley.net>
parents: 164
diff changeset
1 #!/bin/bash
43
6d16887ec084 Intermediate snapshot. Doesn't work yet.
Rob Landley <rob@landley.net>
parents:
diff changeset
2
1116
2b68517f5b62 Break out simple-root-filesystem.sh and root-filesystem.sh (adding native-compiler.sh output), and use NO_NATIVE_COMPILER to determine which to use. Rename STATIC_CC_HOST to CROSS_HOST_ARCH.
Rob Landley <rob@landley.net>
parents: 1108
diff changeset
3 # Build a basic busybox+uClibc root filesystem for a given target.
888
626288dd5cf3 Lots of comments.
Rob Landley <rob@landley.net>
parents: 882
diff changeset
4
1128
e5f9681a8b3c Lots of comment updates. Add a NO_HOST_TOOLS=1 config option, and a few "time" calls to stages that didn't have them. Put native-compiler.sh after root-filesystem.sh in build so it's slightly easier to document.
Rob Landley <rob@landley.net>
parents: 1116
diff changeset
5 # Requires a cross-compiler (or simple-cross-compiler) in the $PATH or in
e5f9681a8b3c Lots of comment updates. Add a NO_HOST_TOOLS=1 config option, and a few "time" calls to stages that didn't have them. Put native-compiler.sh after root-filesystem.sh in build so it's slightly easier to document.
Rob Landley <rob@landley.net>
parents: 1116
diff changeset
6 # the build directory. In theory you can supply your own as long as the
e5f9681a8b3c Lots of comment updates. Add a NO_HOST_TOOLS=1 config option, and a few "time" calls to stages that didn't have them. Put native-compiler.sh after root-filesystem.sh in build so it's slightly easier to document.
Rob Landley <rob@landley.net>
parents: 1116
diff changeset
7 # prefix- name is correct.
e5f9681a8b3c Lots of comment updates. Add a NO_HOST_TOOLS=1 config option, and a few "time" calls to stages that didn't have them. Put native-compiler.sh after root-filesystem.sh in build so it's slightly easier to document.
Rob Landley <rob@landley.net>
parents: 1116
diff changeset
8
669
1cf41855bb85 More error checking.
Rob Landley <rob@landley.net>
parents: 661
diff changeset
9 source sources/include.sh || exit 1
1398
b74d36876c0a Replace read_arch_dir with load_target, which understands that sources/targets/$TARGET can be a file or a directory.
Rob Landley <rob@landley.net>
parents: 1358
diff changeset
10 load_target "$1"
783
db06a8c1bfed Lots of changes to move buildall.sh functionality into build.sh.
Rob Landley <rob@landley.net>
parents: 782
diff changeset
11 check_for_base_arch || exit 0
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 937
diff changeset
12 check_prerequisite "${ARCH}-cc"
685
90ab1a1f4db5 Teach build not to rebuild base architecture toolchains. Factor out some common code while there.
Rob Landley <rob@landley.net>
parents: 675
diff changeset
13
658
dc5512d734f0 Actually put MANIFEST into mini-native.
Rob Landley <rob@landley.net>
parents: 633
diff changeset
14 # Determine which directory layout we're using
dc5512d734f0 Actually put MANIFEST into mini-native.
Rob Landley <rob@landley.net>
parents: 633
diff changeset
15
1243
0666458bca16 Fix overlay support: copy to original STAGE_DIR (not into usr/) and use tar | tar instead of cp -a (which barfs copying dir/file to a destination where dir symlink).
Rob Landley <rob@landley.net>
parents: 1232
diff changeset
16 OLD_STAGE_DIR="$STAGE_DIR"
783
db06a8c1bfed Lots of changes to move buildall.sh functionality into build.sh.
Rob Landley <rob@landley.net>
parents: 782
diff changeset
17 if [ -z "$ROOT_NODIRS" ]
331
d2820523ee06 When doing BUILD_SHORT (without development tools), use / instead of /tools.
Rob Landley <rob@landley.net>
parents: 326
diff changeset
18 then
1266
68da5da2a403 Provide a mount point for root user's home directory.
Rob Landley <rob@landley.net>
parents: 1245
diff changeset
19 mkdir -p "$STAGE_DIR"/{tmp,proc,sys,dev,home,mnt,root} &&
882
d81382a8bb66 More stuff to make running a guest user potentially useful.
Rob Landley <rob@landley.net>
parents: 876
diff changeset
20 chmod a+rwxt "$STAGE_DIR/tmp" || dienow
1139
2c6d799f0451 Fix a dangling symlink that confuses root-filesystem.sh, and add some comments.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
21
2c6d799f0451 Fix a dangling symlink that confuses root-filesystem.sh, and add some comments.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
22 # Having lots of repeated locations at / and also under /usr is silly, so
2c6d799f0451 Fix a dangling symlink that confuses root-filesystem.sh, and add some comments.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
23 # symlink them together. (The duplication happened back in the 1970's
2c6d799f0451 Fix a dangling symlink that confuses root-filesystem.sh, and add some comments.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
24 # when Ken and Dennis ran out of space on their first RK05 disk pack and
2c6d799f0451 Fix a dangling symlink that confuses root-filesystem.sh, and add some comments.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
25 # leaked the OS into the disk containing the user home directories. It's
2c6d799f0451 Fix a dangling symlink that confuses root-filesystem.sh, and add some comments.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
26 # been mindlessly duplicated ever since.)
735
feec13d32dde Squashfs needs an /etc/resolv.conf, not just /usr/etc/resolv.conf
Rob Landley <rob@landley.net>
parents: 726
diff changeset
27 for i in bin sbin lib etc
423
8029eb9a4a8c Split out BUILD_NOTOOLS from BUILD_SHORT.
Rob Landley <rob@landley.net>
parents: 417
diff changeset
28 do
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
29 mkdir -p "$STAGE_DIR/usr/$i" &&
783
db06a8c1bfed Lots of changes to move buildall.sh functionality into build.sh.
Rob Landley <rob@landley.net>
parents: 782
diff changeset
30 ln -s "usr/$i" "$STAGE_DIR/$i" || dienow
423
8029eb9a4a8c Split out BUILD_NOTOOLS from BUILD_SHORT.
Rob Landley <rob@landley.net>
parents: 417
diff changeset
31 done
1139
2c6d799f0451 Fix a dangling symlink that confuses root-filesystem.sh, and add some comments.
Rob Landley <rob@landley.net>
parents: 1133
diff changeset
32
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
33 STAGE_DIR="$STAGE_DIR/usr"
783
db06a8c1bfed Lots of changes to move buildall.sh functionality into build.sh.
Rob Landley <rob@landley.net>
parents: 782
diff changeset
34 else
db06a8c1bfed Lots of changes to move buildall.sh functionality into build.sh.
Rob Landley <rob@landley.net>
parents: 782
diff changeset
35 mkdir -p "$STAGE_DIR/bin" || dienow
331
d2820523ee06 When doing BUILD_SHORT (without development tools), use / instead of /tools.
Rob Landley <rob@landley.net>
parents: 326
diff changeset
36 fi
395
c2b290c1df40 Upgrade BUILD_SHORT to make a small busybox+uClibc system in /usr, with top level symlinks (/bin, /lib, etc) and adjustments to boot script and run-emulator.
Rob Landley <rob@landley.net>
parents: 390
diff changeset
37
713
9282f84b31a1 Add NATIVE_TOOLCHAIN=only, to build _just_ the native toolchain (sae set of packages as the cross compiler, only --enable-shared and with uClibc++).
Rob Landley <rob@landley.net>
parents: 711
diff changeset
38 # Copy qemu setup script and so on.
9282f84b31a1 Add NATIVE_TOOLCHAIN=only, to build _just_ the native toolchain (sae set of packages as the cross compiler, only --enable-shared and with uClibc++).
Rob Landley <rob@landley.net>
parents: 711
diff changeset
39
1221
6a4968ae5ac8 Add new "/src/host-info" file to target, with CROSS_TARGET and KARCH values.
Rob Landley <rob@landley.net>
parents: 1206
diff changeset
40 cp -r "$SOURCES/root-filesystem/." "$STAGE_DIR/" &&
6a4968ae5ac8 Add new "/src/host-info" file to target, with CROSS_TARGET and KARCH values.
Rob Landley <rob@landley.net>
parents: 1206
diff changeset
41 echo -e "CROSS_TARGET=$CROSS_TARGET\nKARCH=$KARCH" > \
6a4968ae5ac8 Add new "/src/host-info" file to target, with CROSS_TARGET and KARCH values.
Rob Landley <rob@landley.net>
parents: 1206
diff changeset
42 "$STAGE_DIR/src/host-info" &&
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
43 cp "$SRCDIR"/MANIFEST "$STAGE_DIR/src" || dienow
52
6d6551a37687 Add make to mini-native (required one more option switched on in uClibc), add
Rob Landley <rob@landley.net>
parents: 51
diff changeset
44
1151
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
45 # If user specified different files to put in the root filesystem, add them.
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
46 # (This overwrites existing files.)
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
47
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
48 if [ ! -z "$SIMPLE_ROOT_OVERLAY" ]
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
49 then
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
50 cd "$TOP"
1245
313a2569dfe2 Milton Miller pointed out that tar | tar doesn't need gzip. :)
Rob Landley <rob@landley.net>
parents: 1244
diff changeset
51 tar -c -C "$SIMPLE_ROOT_OVERLAY" . | tar -x -C "$OLD_STAGE_DIR" || dienow
1151
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
52 fi
b55c80be32b6 Add SIMPLE_ROOT_OVERLAY.
Rob Landley <rob@landley.net>
parents: 1140
diff changeset
53
1229
313c702a0984 Remove toybox.
Rob Landley <rob@landley.net>
parents: 1221
diff changeset
54 # Build busybox
52
6d6551a37687 Add make to mini-native (required one more option switched on in uClibc), add
Rob Landley <rob@landley.net>
parents: 51
diff changeset
55
1036
e021bba5e22e Yank ugly STAGE_DIR adjustment and instead teach busybox/toybox bilds to auto-detect "bin" directory on install. (And while we're at it, don't build hello-dynamic on static-only system.)
Rob Landley <rob@landley.net>
parents: 1034
diff changeset
56 build_section busybox
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
57 cp "$WORK"/config-busybox "$STAGE_DIR"/src || dienow
280
00ee362817e1 Cross-compile a native distcc for target.
Rob Landley <rob@landley.net>
parents: 278
diff changeset
58
1133
1ad777637d2d Migrate oneit out of toybox into sources/toys as a standalone program, and fix it so pid 1 has / as its working directory so we can umount /home if necessary.
Rob Landley <rob@landley.net>
parents: 1128
diff changeset
59 # Build the world's simplest init program: spawns one task with a controlling
1ad777637d2d Migrate oneit out of toybox into sources/toys as a standalone program, and fix it so pid 1 has / as its working directory so we can umount /home if necessary.
Rob Landley <rob@landley.net>
parents: 1128
diff changeset
60 # TTY, waits (reaping zombies) until it exits, then shuts down the system.
1ad777637d2d Migrate oneit out of toybox into sources/toys as a standalone program, and fix it so pid 1 has / as its working directory so we can umount /home if necessary.
Rob Landley <rob@landley.net>
parents: 1128
diff changeset
61
1232
e93f17722cdf When BUILD_STATIC=all that inclues oneit.
Rob Landley <rob@landley.net>
parents: 1229
diff changeset
62 TEMP=
e93f17722cdf When BUILD_STATIC=all that inclues oneit.
Rob Landley <rob@landley.net>
parents: 1229
diff changeset
63 [ "$BUILD_STATIC" == all ] && TEMP=--static
e93f17722cdf When BUILD_STATIC=all that inclues oneit.
Rob Landley <rob@landley.net>
parents: 1229
diff changeset
64 ${ARCH}-cc "$SOURCES/toys/oneit.c" -Os $CFLAGS $TEMP \
e93f17722cdf When BUILD_STATIC=all that inclues oneit.
Rob Landley <rob@landley.net>
parents: 1229
diff changeset
65 -o "$STAGE_DIR/sbin/oneit" || dienow
1133
1ad777637d2d Migrate oneit out of toybox into sources/toys as a standalone program, and fix it so pid 1 has / as its working directory so we can umount /home if necessary.
Rob Landley <rob@landley.net>
parents: 1128
diff changeset
66
83
8fb80545fe84 Move the "hello world" source into sources/toys. Build (in mini-native)
Rob Landley <rob@landley.net>
parents: 81
diff changeset
67 # Put statically and dynamically linked hello world programs on there for
315
7fe514d773b9 Install setup script even for BUILD_SHORT.
Rob Landley <rob@landley.net>
parents: 311
diff changeset
68 # test purposes.
83
8fb80545fe84 Move the "hello world" source into sources/toys. Build (in mini-native)
Rob Landley <rob@landley.net>
parents: 81
diff changeset
69
1036
e021bba5e22e Yank ugly STAGE_DIR adjustment and instead teach busybox/toybox bilds to auto-detect "bin" directory on install. (And while we're at it, don't build hello-dynamic on static-only system.)
Rob Landley <rob@landley.net>
parents: 1034
diff changeset
70 "${ARCH}-cc" "${SOURCES}/toys/hello.c" -Os $CFLAGS -o "$STAGE_DIR/bin/hello-dynamic" || dienow
e021bba5e22e Yank ugly STAGE_DIR adjustment and instead teach busybox/toybox bilds to auto-detect "bin" directory on install. (And while we're at it, don't build hello-dynamic on static-only system.)
Rob Landley <rob@landley.net>
parents: 1034
diff changeset
71
1083
cb4dbdb7f2cd Make BUILD_STATIC take comma separated list of packages, or "all" or "none". Default behavior should remain the same.
Rob Landley <rob@landley.net>
parents: 1062
diff changeset
72 if [ "$BUILD_STATIC" != none ]
1036
e021bba5e22e Yank ugly STAGE_DIR adjustment and instead teach busybox/toybox bilds to auto-detect "bin" directory on install. (And while we're at it, don't build hello-dynamic on static-only system.)
Rob Landley <rob@landley.net>
parents: 1034
diff changeset
73 then
e021bba5e22e Yank ugly STAGE_DIR adjustment and instead teach busybox/toybox bilds to auto-detect "bin" directory on install. (And while we're at it, don't build hello-dynamic on static-only system.)
Rob Landley <rob@landley.net>
parents: 1034
diff changeset
74 "${ARCH}-cc" "${SOURCES}/toys/hello.c" -Os $CFLAGS -static -o "$STAGE_DIR/bin/hello-static" || dienow
e021bba5e22e Yank ugly STAGE_DIR adjustment and instead teach busybox/toybox bilds to auto-detect "bin" directory on install. (And while we're at it, don't build hello-dynamic on static-only system.)
Rob Landley <rob@landley.net>
parents: 1034
diff changeset
75 fi
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
76
1472
a4673f17b7c0 Add record-commands wrapper and plumbing to target image, so you can record-commands /mnt/init in a native build.
Rob Landley <rob@landley.net>
parents: 1398
diff changeset
77 # Debug wrapper for use with /usr/src/record-commands.sh
a4673f17b7c0 Add record-commands wrapper and plumbing to target image, so you can record-commands /mnt/init in a native build.
Rob Landley <rob@landley.net>
parents: 1398
diff changeset
78
a4673f17b7c0 Add record-commands wrapper and plumbing to target image, so you can record-commands /mnt/init in a native build.
Rob Landley <rob@landley.net>
parents: 1398
diff changeset
79 "${ARCH}-cc" "$SOURCES/toys/wrappy.c" -Os $CFLAGS -o "$STAGE_DIR/bin/record-commands-wrapper" || dienow
a4673f17b7c0 Add record-commands wrapper and plumbing to target image, so you can record-commands /mnt/init in a native build.
Rob Landley <rob@landley.net>
parents: 1398
diff changeset
80
1062
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
81 # Do we need shared libraries?
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
82
1083
cb4dbdb7f2cd Make BUILD_STATIC take comma separated list of packages, or "all" or "none". Default behavior should remain the same.
Rob Landley <rob@landley.net>
parents: 1062
diff changeset
83 if [ "$BUILD_STATIC" != all ]
1062
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
84 then
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
85 echo Copying compiler libraries...
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
86 mkdir -p "$STAGE_DIR/lib" || dienow
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
87 (path_search \
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
88 "$("$ARCH-cc" --print-search-dirs | sed -n 's/^libraries: =*//p')" \
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
89 "*.so*" 'cp -H "$DIR/$FILE" "$STAGE_DIR/lib/$FILE"' \
abc8ddd4d9f0 Don't have root-filesystem.sh suck in the native-compiler.sh output, have build.sh collate those instead before calling system-image.sh. (That way the root-filesystem.sh tarball does't include the native compiler output.)
Rob Landley <rob@landley.net>
parents: 1036
diff changeset
90 || dienow) | dotprogress
1198
78e786334c5b Polish the strip logic a bit.
Rob Landley <rob@landley.net>
parents: 1178
diff changeset
91
78e786334c5b Polish the strip logic a bit.
Rob Landley <rob@landley.net>
parents: 1178
diff changeset
92 [ -z "$SKIP_STRIP" ] &&
78e786334c5b Polish the strip logic a bit.
Rob Landley <rob@landley.net>
parents: 1178
diff changeset
93 "${ARCH}-strip" --strip-unneeded "$STAGE_DIR"/lib/*.so
1034
27c38c82401d Move make, bash, and distcc builds into native-compiler.sh. (Break 'em out into sources/sections/*.build.)
Rob Landley <rob@landley.net>
parents: 1008
diff changeset
94 fi
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
95
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
96 # Clean up and package the result
713
9282f84b31a1 Add NATIVE_TOOLCHAIN=only, to build _just_ the native toolchain (sae set of packages as the cross compiler, only --enable-shared and with uClibc++).
Rob Landley <rob@landley.net>
parents: 711
diff changeset
97
1198
78e786334c5b Polish the strip logic a bit.
Rob Landley <rob@landley.net>
parents: 1178
diff changeset
98 [ -z "$SKIP_STRIP" ] &&
78e786334c5b Polish the strip logic a bit.
Rob Landley <rob@landley.net>
parents: 1178
diff changeset
99 "${ARCH}-strip" "$STAGE_DIR"/{bin/*,sbin/*}
53
3fd961e31444 Build a gcc wrapper for _target_, and add a "strip" command to halve the
Rob Landley <rob@landley.net>
parents: 52
diff changeset
100
783
db06a8c1bfed Lots of changes to move buildall.sh functionality into build.sh.
Rob Landley <rob@landley.net>
parents: 782
diff changeset
101 create_stage_tarball
576
036dbe218036 Add BASE_ARCH support, so a hardware architecture can specify a base architecture and just provide a different kernel.
Rob Landley <rob@landley.net>
parents: 572
diff changeset
102
50
5aeba79b8f5f Remove qemu build (it's in cross-compiler.sh now), move uClibc build right
Rob Landley <rob@landley.net>
parents: 46
diff changeset
103 # Color back to normal
52
6d6551a37687 Add make to mini-native (required one more option switched on in uClibc), add
Rob Landley <rob@landley.net>
parents: 51
diff changeset
104 echo -e "\e[0mBuild complete"