forked from arnobroekhof/flashboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-cfcard.sh
executable file
·146 lines (120 loc) · 3.97 KB
/
build-cfcard.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
#!/bin/sh
#
# Instead of creating a diskimage it installs directly to the cf card
askConfirmation() {
echo "All data while be wiped on device $DEVICE"
echo "Do you want to proceed?? [y]"
read CONFIRMATION
if [ -z ${CONFIRMATION} ]; then
echo "please provide y or n"
askConfirmation
fi
if [ "${CONFIRMATION}" == "n" ]; then
echo "Operation cancelled... exiting!"
exit 1
fi
if [ "${CONFIRMATION}" != "y" ]; then
echo "please provide y or n"
askConfirmation
fi
}
getDevice() {
echo "Enter the cf card"
read DEVICE
if [ -z $DEVICE ]; then
echo "No disk given"
exit 1
fi
}
getDevice
askConfirmation
# Check if the confirmation was yes else exit directly
if [ "${CONFIRMATION}" != "y" ]; then
exit 1
fi
echo "Start building cf-card ${DEVICE}"
CWD=`pwd`
WORKDIR=sandbox
SRCDIR=${BSDSRCDIR:-/usr/src}
DESTDIR=${DESTDIR:-${CWD}/${WORKDIR}}
KERNELFILE=${KERNELFILE:-${CWD}/obj/bsd.gz}
SUDO=sudo
MOUNTPOINT=/mnt
TMPFILE=`mktemp`
TEMPFILE=/tmp/build-diskimage.tmp.$$
# This is for boot.conf and should match the kernel ttyspeed.
# Which should be 9600 for GENERIC-RD, 38400 for WRAP12 and 19200 for the rest.
TTYSPEED=${TTYSPEED:-19200}
${SUDO} disklabel ${DEVICE} > ${TMPFILE}
# drive geometry information -- get the right one for your flash!!
totalsize=`grep "total sectors:" ${TMPFILE} | awk '{ print $3 }'`
bytessec=`grep "bytes/sector:" ${TMPFILE} | awk '{ print $2 }'`
sectorstrack=`grep "sectors/track:" ${TMPFILE} | awk '{ print $2 }'`
sectorscylinder=`grep "sectors/cylinder:" ${TMPFILE} | awk '{ print $2 }'`
trackscylinder=`grep "tracks/cylinder:" ${TMPFILE} | awk '{ print $2 }'`
cylinders=`grep "cylinders:" ${TMPFILE} | awk '{ print $2 }'`
if [ ! -f $KERNELFILE ]; then
echo "Kernelfile $KERNELFILE not found...."
exit 1
fi
echo ""
echo "Running fdisk on ${DEVICE}... (Ignore any sysctl(machdep.bios.diskinfo): Device not configured warnings)"
${SUDO} fdisk -c $cylinders -h $trackscylinder -s $sectorstrack -f ${DESTDIR}/usr/mdec/mbr -e $DEVICE << __EOC >/dev/null
reinit
update
write
quit
__EOC
let asize=$totalsize-$sectorstrack
echo "type: SCSI" >> $TEMPFILE
echo "disk: vnd device" >> $TEMPFILE
echo "label: fictitious" >> $TEMPFILE
echo "flags:" >> $TEMPFILE
echo "bytes/sector: ${bytessec}" >> $TEMPFILE
echo "sectors/track: ${sectorstrack}" >> $TEMPFILE
echo "tracks/cylinder: ${trackscylinder}" >> $TEMPFILE
echo "sectors/cylinder: ${sectorscylinder}" >> $TEMPFILE
echo "cylinders: ${cylinders}" >> $TEMPFILE
echo "total sectors: ${totalsize}" >> $TEMPFILE
echo "interleave: 1" >> $TEMPFILE
echo "trackskew: 0" >> $TEMPFILE
echo "cylinderskew: 0" >> $TEMPFILE
echo "headswitch: 0 " >> $TEMPFILE
echo "track-to-track seek: 0 " >> $TEMPFILE
echo "drivedata: 0 " >> $TEMPFILE
echo "" >> $TEMPFILE
echo "16 partitions:" >> $TEMPFILE
echo "a: $asize $sectorstrack 4.2BSD 2048 16384 16" >> $TEMPFILE
echo "c: $totalsize 0 unused 0 0" >> $TEMPFILE
echo ""
echo "Installing disklabel..."
${SUDO} disklabel -R $DEVICE $TEMPFILE
rm $TEMPFILE
echo ""
echo "Creating new filesystem..."
${SUDO} newfs -q /dev/r${DEVICE}a
echo ""
echo "Mounting destination to ${MOUNTPOINT}..."
if ! ${SUDO} mount -o async /dev/${DEVICE}a ${MOUNTPOINT}; then
echo Mount failed..
exit
fi
echo ""
echo "Copying bsd kernel, boot blocks and /etc/boot.conf..."
${SUDO} cp ${DESTDIR}/usr/mdec/boot ${MOUNTPOINT}/boot
${SUDO} cp ${KERNELFILE} ${MOUNTPOINT}/bsd
${SUDO} mkdir ${MOUNTPOINT}/etc
${SUDO} sed "/^stty/s/19200/${TTYSPEED}/" < ${CWD}/initial-conf/boot.conf > ${MOUNTPOINT}/etc/boot.conf
echo ""
echo "Installing boot blocks..."
${SUDO} /usr/mdec/installboot ${MOUNTPOINT}/boot ${DESTDIR}/usr/mdec/biosboot ${DEVICE}
${SUDO} mkdir ${MOUNTPOINT}/conf
${SUDO} mkdir ${MOUNTPOINT}/pkg
# Here is where you add your own packages and configuration to the flash...
echo ""
echo "Unmounting and cleaning up..."
${SUDO} umount $MOUNTPOINT
${SUDO} rm -f ${TMPFILE}
echo ""
echo "And we are done..."
echo "Run \"sudo mount -o async /dev/${DEVICE}a /mnt\" to add configuration and packages."