forked from landley/aboriginal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem-image.sh
executable file
·128 lines (102 loc) · 3.37 KB
/
system-image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# Combine filesystem images, kernel, and emulator launch scripts
# into something you can boot and run.
source sources/include.sh || exit 1
# We do our own dependency checking (like host-tool.sh) so don't delete stage
# dir when parsing sources/targets/$1
KEEP_STAGEDIR=1 load_target "$1"
# Is $1 newer than cross compiler and all listed prerequisites ($2...)?
is_newer()
{
X="$1"
shift
[ ! -e "$X" ] && return 0
[ "$(which "${CC_PREFIX}cc")" -nt "$X" ] && return 0
while [ ! -z "$1" ]
do
[ ! -z "$(find "$1" -newer "$X" 2>/dev/null)" ] && return 0
shift
done
echo "Keeping $(basename "$X")"
return 1
}
# Provide qemu's common command line options between architectures.
qemu_defaults()
{
echo -n "-nographic -no-reboot -kernel linux"
[ "$SYSIMAGE_TYPE" != "rootfs" ] && echo -n " -initrd rootfs.cpio.gz"
echo -n " -append \"panic=1 console=$CONSOLE HOST=$ARCH \$KERNEL_EXTRA\""
echo -n " \$QEMU_EXTRA"
}
# Write out a script to call the appropriate emulator. We split out the
# filesystem, kernel, and base kernel command line arguments in case you want
# to use an emulator other than qemu, but put the default case in qemu_defaults
cat > "$STAGE_DIR/run-emulator.sh" << EOF &&
#!/bin/bash
# Boot the emulated system to a shell prompt.
ARCH=$ARCH
run_emulator()
{
[ ! -z "\$DEBUG" ] && set -x
cd "\$(dirname "\$0")" &&
$(emulator_command)
}
if [ "\$1" != "--norun" ]
then
run_emulator
fi
EOF
chmod +x "$STAGE_DIR/run-emulator.sh" &&
# Write out development wrapper scripts, substituting INCLUDE lines.
for FILE in dev-environment.sh native-build.sh
do
(export IFS="$(echo -e "\n")"
cat "$SOURCES/toys/$FILE" | while read -r i
do
if [ "${i:0:8}" == "INCLUDE " ]
then
cat "$SOURCES/toys/${i:8}" || dienow
else
# because echo doesn't support --, that's why.
echo "$i" || dienow
fi
done
) > "$STAGE_DIR/$FILE"
chmod +x "$STAGE_DIR/$FILE" || dienow
done
# Package root-filesystem into cpio file for initramfs
if is_newer "$STAGE_DIR/rootfs.cpio.gz" "$BUILD/root-filesystem-$ARCH"
then
SYSIMAGE_TYPE=cpio image_filesystem "$BUILD/root-filesystem-$ARCH" \
"$STAGE_DIR/temp" &&
mv -f "$STAGE_DIR"/{temp,rootfs}.cpio.gz || dienow
[ "$SYSIMAGE_TYPE" == rootfs ] && rm -f "$STAGE_DIR/linux"
fi
# Package native-compiler into squashfs for /dev/hda mount
if [ -e "$BUILD/native-compiler-$ARCH" ] &&
is_newer "$STAGE_DIR/toolchain.sqf" "$BUILD/native-compiler-$ARCH"
then
SYSIMAGE_TYPE=squashfs image_filesystem "$BUILD/native-compiler-$ARCH" \
"$STAGE_DIR/temp" &&
mv -f "$STAGE_DIR"/{temp,toolchain}.sqf || dienow
fi
# Build linux kernel for the target
if is_newer "$STAGE_DIR/linux" "$BUILD/root-filesystem-$ARCH" \
$(package_cache linux)
then
setupfor linux
echo "# make allnoconfig ARCH=${BOOT_KARCH:-$KARCH} KCONFIG_ALLCONFIG=mini.config" \
> $STAGE_DIR/mini.config
getconfig linux >> "$STAGE_DIR"/mini.config
[ "$SYSIMAGE_TYPE" == rootfs ] &&
echo -e "CONFIG_INITRAMFS_SOURCE=\"$STAGE_DIR/rootfs.cpio.gz\"\n" \
>> "$STAGE_DIR"/mini.config
make allnoconfig ARCH=${BOOT_KARCH:-$KARCH} $LINUX_FLAGS \
KCONFIG_ALLCONFIG="$STAGE_DIR"/mini.config >/dev/null &&
make -j $CPUS ARCH=${BOOT_KARCH:-$KARCH} $DO_CROSS $LINUX_FLAGS $VERBOSITY &&
cp "$KERNEL_PATH" "$STAGE_DIR/linux"
cleanup
fi
# Tar it up.
ARCH="$ARCH_NAME" create_stage_tarball
announce "Packaging complete"