-
Notifications
You must be signed in to change notification settings - Fork 71
/
cos
executable file
·207 lines (175 loc) · 3.62 KB
/
cos
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
set -e
script=
name=
rebuild_flag=
binary=
arch=
initialize()
{
case ${arch} in
x86_64 )
;;
i386 )
;;
armv7a )
;;
* )
echo "Unsupported architecture"
exit 1
esac
echo "[cos setting arch] make -C src config-${arch}"
make -C src config-${arch}
echo "[cos executing] make -C src config init"
make -C src init
}
build()
{
if ! [ -r "src/.PLATFORM_ID" ]; then
echo "Must \"cos init\" before \"cos build\"."
exit 1
fi
echo "[cos executing] make -C src all"
make -C src all
}
clean()
{
echo "[cos executing] make -C src clean"
make -C src clean
}
distclean()
{
echo "[cos executing] make -C src clean"
make -C src distclean
}
compose()
{
if [ -z "$script" ] || [ -z "$name" ]; then
usage
fi
if ! [ -e "src/composer/target/debug/compose" ]; then
echo "Must \"cos build\" before composition. Could not find src/composer/target/debug/compose"
exit 1
fi
echo "[cos executing] src/composer/target/debug/compose $script $name"
src/composer/target/debug/compose $script $name
local dir="system_binaries/cos_build-${name}"
tools/build_iso.sh ${dir}/cos.img
}
compose_opt()
{
if [ -z "$script" ] || [ -z "$name" ] || [ -z "$rebuild_flag" ]; then
usage
fi
if ! [ -e "src/composer/target/debug/compose" ]; then
echo "Must \"cos build\" before composition. Could not find src/composer/target/debug/compose"
exit 1
fi
echo "[cos executing] src/composer/target/debug/compose $script $name $rebuild_flag"
src/composer/target/debug/compose $script $name $rebuild_flag
local dir="system_binaries/cos_build-${name}"
tools/build_iso.sh ${dir}/cos.img
}
run()
{
local dir="./system_binaries/cos_build-${name}"
if [ ! -f ${dir}/cos.iso ]
then
echo "Cannot find cos.iso, please do compose first"
exit 1
fi
local elf_type=$(readelf -h ${dir}/cos.img | grep "Class:" | awk '{print $2}')
local machine=$(readelf -h ${dir}/cos.img | grep "Machine:" | awk '{print $2}')
if [ "${machine}" == "ARM" ]
then
./tools/arm_qemurun.sh all ${dir}
exit 0
fi
if [ "${elf_type}" == "ELF64" ]
then
tools/run.sh ${dir}/cos.iso x86_64 ${enable_nic}
elif [ "${elf_type}" == "ELF32" ]
then
tools/run.sh ${dir}/cos.iso i386 ${enable_nic}
else
echo "Unsupported image type: ${elf_type} !"
fi
}
debug_run()
{
local dir="system_binaries/cos_build-${name}"
local gdbinit="system_binaries/gdbinit"
if [ ! -f ${dir}/cos.iso ]
then
echo "Cannot find cos.iso, please do compose first and check its name"
exit 1
fi
if [ ! -f ${gdbinit} ]
then
echo "set confirm off" > ${gdbinit}
echo "#file ${dir}/global.booter/no_interface.llbooter.global.booter" >> ${gdbinit}
echo "file ${dir}/cos.img" >> ${gdbinit}
echo "target remote:1234" >> ${gdbinit}
fi
local elf_type=$(readelf -h ${dir}/cos.img | grep "Class:" | awk '{print $2}')
if [ "${elf_type}" == "ELF64" ]
then
tools/run.sh ${dir}/cos.iso x86_64 debug ${enable_nic}
elif [ "${elf_type}" == "ELF32" ]
then
tools/run.sh ${dir}/cos.iso i386 debug ${enable_nic}
else
echo "Unsupported image type!"
fi
}
gdb()
{
command gdb -x ./system_binaries/gdbinit
}
usage()
{
echo "Usage: " $0 " init <arch: [x86_64|i386|armv7a]>|build|clean|compose <script> <output name>|run <composite name> [enable-nic]|debug_run <composite name> [enable_nic]|gdb | distclean"
exit 1
}
case $1 in
init )
arch=$2
initialize
;;
build )
build
;;
clean )
clean
;;
compose )
script=$2
name=$3
compose
;;
compose_opt )
script=$2
name=$3
rebuild_flag=$4
compose_opt
;;
run )
binary=$2
name=$2
enable_nic=$3
run
;;
debug_run )
name=$2
enable_nic=$3
debug_run
;;
gdb )
gdb
;;
distclean )
distclean
;;
* )
usage
esac