forked from zilogic-systems/workshop-sessions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd.sh
executable file
·257 lines (212 loc) · 5.76 KB
/
cmd.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
set -e -x -u
cat <<EOF > run-qemu.sh
### START: boot-prebuilt.sh
cd ~/shared
qemu-system-arm -M versatilepb \
-hda disk.img \
-kernel zImage \
-append "root=/dev/sda rw"
### END: boot-prebuilt.sh
EOF
### START: copy-prebuilt.sh
cp ~/yp/pre-built/zImage /media/sf_shared
cp ~/yp/pre-build/disk.img /media/sf_shared
### END: copy-prebuilt.sh
### START: run-qemu.sh
cd ~/shared
bash run-qemu.sh
### END: run-qemu.sh
### START: setup-env.sh
ROOTFS=~/yp/manual/rootfs
DISKIMG=~/yp/manual/disk.img
### END: setup-env.sh
cat > ~/yp/manual/hello.c <<EOF
/* ### START: hello.c */
#include <stdio.h>
#include <unistd.h>
int main()
{
while (1) {
printf("Hello World\n");
sleep(1);
}
}
/* ### END: hello.c */
EOF
### START: build-hello.sh
cd ~/yp/manual
arm-none-linux-gnueabi-gcc -static hello.c -o hello
### END: build-hello.sh
### START: copy-hello.sh
mkdir -p $ROOTFS/bin
cp hello $ROOTFS/bin/sh
### END: copy-hello.sh
### START: create-hello-rootfs.sh
genext2fs -b 131072 -d $ROOTFS $DISKIMG
### END: create-hello-rootfs.sh
### START: boot-hello-rootfs.sh
cd ~/shared
bash run-qemu.sh
### END: boot-hello-rootfs.sh
### START: download-bash.sh
cd ~/yp/dl
wget -c http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
### END: download-bash.sh
### START: unpack-bash.sh
cd ~/yp/manual
tar -x -f ~/yp/dl/bash-4.3.tar.gz
### END: unpack-bash.sh
### START: configure-bash.sh
cd bash-4.3
./configure --prefix=/usr \
--host=arm-none-linux-gnueabi \
--build=i686-pc-linux-gnu
### END: configure-bash.sh
### START: build-bash.sh
make
### END: build-bash.sh
### START: install-bash.sh
make install DESTDIR=$ROOTFS
### END: install-bash.sh
### START: check-bash-deps.sh
arm-none-linux-gnueabi-readelf -d $ROOTFS/usr/bin/bash
### END: check-bash-deps.sh
### START: link-bash.sh
ln -s /usr/bin/bash $ROOTFS/bin/bash
ln -s /usr/bin/bash $ROOTFS/bin/sh
### END: link-bash.sh
### START: cp-bash-deps.sh
mkdir $ROOTFS/lib
TOOLCHAIN="/usr/share/gcc-arm-linux"
cp $TOOLCHAIN/arm-none-linux-gnueabi/libc/lib/libc.so.6 \
$ROOTFS/lib
cp $TOOLCHAIN/arm-none-linux-gnueabi/libc/lib/libdl.so.2 \
$ROOTFS/lib
### END: cp-bash-deps.sh
### START: copy-ld.sh
cp $TOOLCHAIN/arm-none-linux-gnueabi/libc/lib/ld-linux.so.3 \
$ROOTFS/lib
### END: copy-ld.sh
### START: make-dev-tmp.sh
mkdir $ROOTFS/dev $ROOTFS/tmp
### END: make-dev-tmp.sh
### START: create-bash-rootfs.sh
genext2fs -b 131072 -d $ROOTFS $DISKIMG
### END: create-bash-rootfs.sh
### START: boot-bash-rootfs.sh
cd ~/shared
bash run-qemu.sh
### END: boot-bash-rootfs.sh
### START: build-coreutils.sh
cd ~/yp/dl
wget -c http://ftp.gnu.org/gnu/coreutils/coreutils-6.7.tar.bz2
cd ~/yp/manual
tar -x -f ~/yp/dl/coreutils-6.7.tar.bz2
cd coreutils-6.7
./configure --prefix=/usr \
--host=arm-none-linux-gnueabi \
--build=i686-pc-linux-gnu
make
make install DESTDIR=$ROOTFS
### END: build-coreutils.sh
### START: create-ls-rootfs.sh
genext2fs -b 131072 -d $ROOTFS $DISKIMG
### END: create-ls-rootfs.sh
cd ~/shared
bash run-qemu.sh
### START: check-ls-deps.sh
arm-none-linux-gnueabi-readelf -d $ROOTFS/usr/bin/ls
### END: check-ls-deps.sh
cp $TOOLCHAIN/arm-none-linux-gnueabi/libc/lib/librt.so.1 \
$ROOTFS/lib
genext2fs -b 131072 -d $ROOTFS $DISKIMG
qemu-system-arm \
-M versatilepb \
-kernel ~/yp/pre-built/zImage \
-append "root=/dev/sda rw" \
-hda $DISKIMG
cp $TOOLCHAIN/arm-none-linux-gnueabi/libc/lib/libpthread.so.0 \
$ROOTFS/lib
genext2fs -b 131072 -d $ROOTFS $DISKIMG
qemu-system-arm \
-M versatilepb \
-kernel ~/yp/pre-built/zImage \
-append "root=/dev/sda rw" \
-hda $DISKIMG
set +e
### START: build-less-fail.sh
cd ~/yp/dl
wget -c http://www.greenwoodsoftware.com/less/less-458.tar.gz
cd ~/yp/manual
tar -x -f ~/yp/dl/less-458.tar.gz
cd less-458
./configure --prefix=/usr \
--host=arm-none-linux-gnueabi \
--build=i686-pc-linux-gnu
### END: build-less-fail.sh
set -e
### START: build-ncurses.sh
cd ~/yp/dl
wget -c http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz
cd ~/yp/manual
tar -x -f ~/yp/dl/ncurses-5.9.tar.gz
cd ncurses-5.9
./configure --prefix=/usr \
--host=arm-none-linux-gnueabi \
--build=i686-pc-linux-gnu
make
make install DESTDIR=$ROOTFS
### END: build-ncurses.sh
set +e
### START: build-less-fail-2.sh
cd ~/yp/manual/less-458
./configure --prefix=/usr \
--host=arm-none-linux-gnueabi \
--build=i686-pc-linux-gnu
### END: build-less-fail-2.sh
set -e
cat > ~/yp/manual/hello-ncurses.c <<EOF
/* ### START: hello-ncurses.c */
#include <ncurses.h>
int main()
{
initscr();
printw("Hello World!");
refresh();
getch();
endwin();
return 0;
}
/* ### END: hello-ncurses.c */
EOF
### START: build-hello-ncurses.sh
cd ~/yp/manual
arm-none-linux-gnueabi-gcc hello-ncurses.c -o hello-ncurses
### END: build-hello-ncurses.sh
### START: check-ncurses-location.sh
ls $ROOTFS/usr/include
ls $ROOTFS/usr/lib
### END: check-ncurses-location.sh
### START: build-hello-ncurses-2.sh
arm-none-linux-gnueabi-gcc hello-ncurses.c \
-I $ROOTFS/usr/include \
-L $ROOTFS/usr/lib \
-lncurses
### END: build-hello-ncurses-2.sh
### START: build-less.sh
cd ~/yp/manual/less-458
./configure --prefix=/usr \
--host=arm-none-linux-gnueabi \
--build=i686-pc-linux-gnu \
LDFLAGS="-L $ROOTFS/usr/lib" \
CPPFLAGS="-I $ROOTFS/usr/include"
make
make install DESTDIR=$ROOTFS
### END: build-less.sh
genext2fs -b 131072 -d $ROOTFS $DISKIMG
qemu-system-arm \
-M versatilepb \
-kernel ~/yp/pre-built/zImage \
-append "root=/dev/sda rw" \
-hda $DISKIMG