-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlinux-analyze-marginal-sizes
executable file
·124 lines (100 loc) · 2.36 KB
/
linux-analyze-marginal-sizes
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
#!/bin/bash
#
# © Copyright 2013 by Geert Uytterhoeven <geert@linux-m68k.org>
#
# This file is subject to the terms and conditions of the GNU General Public
# License.
#
INFO=true
function usage()
{
cat <<END
Usage: $(basename $0) [options] [make arguments ...]
Valid options:
-h, --help Display this help
-k, --keep Keep vmlinux and System.map for each build
-v, --verbose Enable verbose mode
Make arguments are passed to make, e.g.
CROSS_COMPILE=m68k-linux-gnu- ARCH=m68k -j 4
CROSS_COMPILE is also extracted to call the proper size utility.
END
exit -1
}
function extract_sizes
{
${CROSS_COMPILE}size vmlinux > sizes || exit -1
# Extract total
tail -1 sizes | cut -f 4
}
function save_failure()
{
for i in $SAVEFILES_FAILURE; do
mv $i $i.$1;
done
}
function save_success()
{
for i in $SAVEFILES_SUCCESS; do
mv $i $i.$1;
done
}
SAVEFILES_FAILURE=".config build.log"
SAVEFILES_SUCCESS=".config build.log sizes"
for arg in $*; do
case $arg in
-h|--help)
usage
;;
-k|--keep)
SAVEFILES_SUCCESS="$SAVEFILES_SUCCESS vmlinux System.map"
;;
-v|--verbose)
INFO=echo
;;
CROSS_COMPILE=*)
CROSS_COMPILE=${arg#CROSS_COMPILE=}
# Fall through
;&
*)
MAKEARGS="$MAKEARGS $arg"
;;
esac
done
MAKE="make $MAKEARGS"
# Disable modules, if enabled
if grep -q '^CONFIG_MODULES=y$' .config; then
$INFO Disabling modules
sed -i -e 's/^CONFIG_MODULES=y$/CONFIG_MODULES=n/g' \
-e 's/=m$/=n/g' .config
$MAKE olddefconfig >& /dev/null
if grep -q '^CONFIG_MODULES=y$' .config; then
echo CONFIG_MODULES cannot be disabled
exit -1
fi
fi
# Build baseline
$INFO Building baseline kernel image
rm -f vmlinux System.map
$MAKE vmlinux >& build.log || exit -1
size=$(extract_sizes)
$INFO Baseline size is $total
save_success baseline
# For all =y options
for option in $(grep '^CONFIG_.*=y$' .config.baseline | sed -e 's/=y$//g'); do
$INFO Disabling $option
sed -e "s/^$option=y\$/$option=n/g" < .config.baseline > .config
$MAKE olddefconfig >& /dev/null
if grep -q "^$option=y$" .config; then
echo $option cannot be disabled
continue
fi
rm -f vmlinux System.map
if ! $MAKE vmlinux >& build.log; then
echo Build with $option=n failed
save_failure $option=n
continue
fi
delta=$(($size - $(extract_sizes)))
echo Disabling $option saves $delta bytes
save_success $option=n
done