summaryrefslogtreecommitdiffstats
path: root/release/picobsd/build/stage1
blob: 31e9a34e4c892f6ee9fb6e5021a8962ad0072ebc (plain)
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
#! /bin/sh -

# $FreeBSD$
#
# stage1 -- this script fills the mfs for the picobsd kernel

. ../Version

set -e	# abort in case of untested errors

MFS_NAME=fs.PICOBSD
# fail errno errcode
# This function is used to trap errors and print msgs
#
fail() {
    errno=$1
    errcode=$2
    echo "--> Error $errno code $errcode"
    case $errcode in
    no_vnconfig)
	echo "Error while doing vnconfig of ${MFS_NAME} on /dev/rvn0..."
	echo "   Most probably your running kernel doesn't have the vn(4) device."
	;;
    disklabel)
	echo "Error while labeling ${MFS_NAME} size $SIZE"
	;;
    no_mount)
	echo "Error while mounting ${MFS_NAME} (/dev/vn0c) on /mnt"
	;;
    mtree)
	echo "Error while making hierarchy in /mnt"
	;;
    makedevs)
	echo "Error while making devices in /mnt"
	;;
    crunch)
	echo "Error while building ../${TYPE}/crunch1..."
	;;
    vnconfig2)
	echo "Error while doing vnconfig of floppy.img on /dev/rvn0..."
	;;
    disklabel)
	echo "Error while doing disklabel on of floppy.img size $FLOPPY_SIZE"
	;;
    kernel_compress)
	echo "Error while copying compressed kernel to disk"
	;;
    mfs_compress)
	echo "Error while copying compressed mfs image to disk"
	;;
    missing_kernel)
	echo "-> ERROR: you must build PICOBSD${suffix} kernel first"
	;;
    esac
    echo "-> Aborting $0"
    exit 10
}

echo "-> Preparing MFS filesystem..."
umount /dev/vn0 2> /dev/null || true
umount /mnt 2> /dev/null || true
vnconfig -u /dev/rvn0 2> /dev/null || true

dd of=${MFS_NAME} if=/dev/zero count=${SIZE} bs=1k 2> /dev/null

awk 'BEGIN {printf "%c%c", 85, 170}' | \
    dd of=${MFS_NAME} obs=1 seek=510 conv=notrunc  2> /dev/null

vnconfig -s labels -c /dev/rvn0 ${MFS_NAME} 2>/dev/null || fail $? no_vnconfig

dd if=/boot/boot1 of=${MFS_NAME} conv=notrunc 2> /dev/null

# This command does weird things on 2.2.x systems.
# For small image sizes, use std disktypes
if [ ${SIZE} -lt 1024 ] ; then
	disklabel -rw /dev/rvn0 fd${SIZE} || fail $? disklabel
else
	disklabel -rw vn0 auto || fail $? disklabel
fi

newfs -i ${MFS_INODES} -m 0 -p 0 -o space /dev/rvn0c
mount /dev/vn0c /mnt || fail $? no_mount

pwd=`pwd`

echo "-> Populating MFS tree..."
cd ../${TYPE}
make -f Makefile.mfs || fail $? mtree
if [ X"${NO_DEVFS}" != X"" ] ; then
    make -f Makefile.mfs devnodes || fail $? makedevs
fi

MFS_RC=floppy.tree/etc/mfs.rc
if [ ! -f ${MFS_RC} ] ; then # no private version. use generic mfs.rc
    MFS_RC=../${MFS_RC}
fi
if [ "${INIT}" = "oinit" ] ; then
    cat ${MFS_RC} | sed -e "s/@VER@/${VER}/g" > /mnt/etc/oinit.rc
else
    cat ${MFS_RC} | sed -e "s/@VER@/${VER}/g" > /mnt/etc/rc
    if [ -f floppy.tree/etc/mfs.login.conf ] ; then
	cp floppy.tree/etc/mfs.login.conf /mnt/etc/login.conf
    else
	cp ../floppy.tree/etc/mfs.login.conf /mnt/etc/login.conf
    fi
    cat lang/README.${LANGUAGE} | sed -e "s/@VER@/${VER}/g" > /mnt/README
fi
cp lang/update.${LANGUAGE} /mnt/stand/update
if [ "${TYPE}" = "dial" ] ; then
    for i in reboot login dialup; do
	cp lang/${i}.${LANGUAGE} /mnt/stand/${i}
    done
    ln -f /mnt/stand/reboot /mnt/stand/shutdown
    (cd ../help;\
    rm -rf tmp_hlp;\
    mkdir tmp_hlp;\
    for i in `ls *.hlp.${LANGUAGE}`; do \
	    cp $i tmp_hlp/`basename $i .hlp.${LANGUAGE}`;\
    done;\
    cd tmp_hlp;\
    ar -cru help.a *;\
    cp help.a /mnt/help.a)
fi

echo "-> Making and installing crunch1..."
cd crunch1
make "SRC=${SRC}" && make install 2>&1 >/dev/null || fail $? crunch

cd ${pwd}

(echo "-> Fixing permissions"; cd /mnt; chown -R root *)

# stage2

echo "-> Preparing kernel..."
cp -p ${SRC}/sys/compile/PICOBSD${suffix}/kernel kernel || \
	fail $? missing_kernel

echo "-> Preparing kernel with MFS filesystem inside..."
df -ik /mnt
umount /mnt
fsck -p /dev/rvn0c
vnconfig -u /dev/rvn0

strip kernel
strip --remove-section=.note --remove-section=.comment kernel
gzip -9 -v -n kernel

#---- stage3

# stage3 -- prepare floppy filesystem and image.
# by default we are in /usr/src/release/build
#

echo "-> Preparing ${FLOPPY_SIZE}kB floppy filesystem..."
umount /dev/vn0 2> /dev/null || true
umount /mnt 2> /dev/null || true
vnconfig -u /dev/rvn0 2> /dev/null || true

dd of=picobsd.bin if=/dev/zero count=${FLOPPY_SIZE} bs=1k

awk 'BEGIN {printf "%c%c", 85, 170}' | \
                dd of=picobsd.bin obs=1 seek=510 conv=notrunc  2> /dev/null

#vnconfig -s labels -c /dev/rvn0 picobsd.bin 2>/dev/null
vnconfig -c /dev/rvn0 picobsd.bin || fail $? vnconfig2

dd if=/boot/boot1 of=picobsd.bin conv=notrunc 2> /dev/null

# XXX todo: right floppy size!
disklabel -Brw -b /boot/boot1 -s /boot/boot2 /dev/rvn0 fd1440 || \
	fail $?  disklabel

newfs -i ${FLOPPY_INODES} -m 0 -p 0 -o space /dev/rvn0c

mount /dev/vn0c /mnt

echo "-> Populating floppy filesystem..."

### copy floppy tree excluding private files.
excl=../${TYPE}/floppy.tree.exclude
if [ -f ${excl} ] ; then
    excl="--exclude-from ${excl}"
    echo "Exclude following files from ${excl}:\n==="
    cat ${excl}
    echo "==="
else
    excl=""
fi
(cd ../floppy.tree ; tar -cf - ${excl} . ) | (cd /mnt ; tar xvf - )

if [ -d ../${TYPE}/floppy.tree ] ; then
    echo "-> update with private files:"
    (cd ../${TYPE}/floppy.tree ; tar cf - . ) | (cd /mnt ; tar xvf - )
fi

files="hosts motd"
echo "-> Copying language dependent files: ${files} -> /mnt/etc ..."
for i in ${files} ; do
	cat ../${TYPE}/lang/${i}.${LANGUAGE} | \
		sed -e "s/@VER@/${VER}/g" > /mnt/etc/${i}
done

if [ "${TYPE}" = "dial" ] ; then
    cp -p /mnt/etc/master.passwd .
    pwd_mkdb -d . master.passwd
    mv spwd.db /mnt/etc/
    rm pwd.db master.passwd
fi

cp kernel.gz /mnt/kernel.gz || fail $? kernel_compress

gzip -9cv ${MFS_NAME} > /mnt/${MFS_NAME}.gz || fail $? mfs_compress

if [ -d /mnt/boot/defaults ] ; then
    mkdir -p /mnt/boot/defaults
fi
cp /boot/loader .
# Make sure we have the a.out stubs we need...
# This is deprecated for 3.X
if [ ! -f /usr/lib/aout/kzhead.o ] ; then
	(cd ${SRC}/sys/i386/boot/kzipboot && make all install clean)
fi
/usr/bin/kzip -v loader
mv loader.kz /mnt/boot/loader
rm -f loader loader.o
# XXX is next line ok ?
echo "/boot/loader" >/mnt/boot.config
cp ${SRC}/sys/boot/forth/loader.4th /mnt/boot/
cp ${SRC}/sys/boot/forth/support.4th /mnt/boot/
cp ${SRC}/sys/boot/forth/loader.conf /mnt/boot/defaults
echo "userconfig_script_load=\"YES\""	>/mnt/boot/loader.conf
echo "rootfs_load=\"YES\""		>>/mnt/boot/loader.conf
echo "rootfs_name=\"${MFS_NAME}\""	>>/mnt/boot/loader.conf
echo "rootfs_type=\"mfs_root\""		>>/mnt/boot/loader.conf
for i in frames screen ; do
	cp ${SRC}/share/examples/bootforth/${i}.4th /mnt/boot/
done
cp ../forth/loader.rc /mnt/boot/loader.rc
cp ../forth/menu.4th /mnt/boot/menu.4th
(echo "-> Fixing permissions"; cd /mnt; chown -R root *)

df -ik /mnt
umount /mnt
vnconfig -u /dev/rvn0
rm kernel.gz ${MFS_NAME}
OpenPOWER on IntegriCloud