xref: /minix/releasetools/arm_sdimage.sh (revision a06e2ab3)
1#!/bin/bash
2set -e
3
4#
5# Source settings if present
6#
7if [ -e .settings ]
8then
9	echo "Sourcing settings from .settings"
10	# Display the content (so we can check in the build logs
11	# what the settings contain.
12	cat .settings | sed "s,^,CONTENT ,g"
13 	. .settings
14fi
15
16: ${ARCH=evbearm-el}
17: ${OBJ=../obj.${ARCH}}
18: ${CROSS_TOOLS=${OBJ}/"tooldir.`uname -s`-`uname -r`-`uname -m`"/bin}
19: ${CROSS_PREFIX=${CROSS_TOOLS}/arm-elf32-minix-}
20: ${JOBS=1}
21: ${DESTDIR=${OBJ}/destdir.$ARCH}
22: ${RELEASETOOLSDIR=./releasetools/}
23: ${FSTAB=${DESTDIR}/etc/fstab}
24: ${BUILDVARS=}
25: ${BUILDSH=build.sh}
26
27#
28# Directory where to store temporary file system images
29#
30: ${IMG_DIR=${OBJ}/img}
31: ${IMG=minix_arm_sd.img}
32: ${MLO=MLO}
33: ${UBOOT=u-boot.img}
34
35
36# Beagleboard-xm
37: ${U_BOOT_BIN_DIR=build/omap3_beagle/}
38: ${CONSOLE=tty02}
39
40
41# BeagleBone (and black)
42#: ${U_BOOT_BIN_DIR=build/am335x_evm/}
43#: ${CONSOLE=tty00}
44
45#
46#
47# We host u-boot binaries.
48U_BOOT_GIT_VERSION=cb5178f12787c690cb1c888d88733137e5a47b15
49
50if [ -n "$BASE_URL" ]
51then
52	#we no longer download u-boot but do a checkout
53	#BASE_URL used to be the base url for u-boot
54	#Downloads
55	echo "Warning:** Setting BASE_URL (u-boot) is no longer possible use U_BOOT_BIN_DIR"
56	echo "Look in ./releasetools/arm_sdimage.sh for suggested values"
57	exit 1
58fi
59
60if [ ! -f ${BUILDSH} ]
61then
62	echo "Please invoke me from the root source dir, where ${BUILDSH} is."
63	exit 1
64fi
65
66export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
67
68for needed in mcopy dd mkfs.vfat git
69do
70	if ! which $needed 2>&1 > /dev/null
71	then
72		echo "**Skipping image creation: missing tool '$needed'"
73		exit 1
74	fi
75done
76
77#
78# Artifacts from this script are stored in the IMG_DIR
79#
80mkdir -p $IMG_DIR
81
82#
83# Download the stage 1 bootloader  and u-boot
84#
85./releasetools/fetch_u-boot.sh -o ${RELEASETOOLSDIR}/u-boot -n $U_BOOT_GIT_VERSION
86cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/u-boot.img ${IMG_DIR}/
87cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/MLO ${IMG_DIR}/
88
89#
90# Call build.sh using a sloppy file list so we don't need to remove the installed /etc/fstag
91#
92export CPPFLAGS=${FLAG}
93sh ${BUILDSH} -V SLOPPY_FLIST=yes -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
94
95#
96# This script creates a bootable image and should at some point in the future
97# be replaced by makefs.
98#
99# All sized are written in 512 byte blocks
100#
101# we create a disk image of about 2 gig's
102: ${IMG_SIZE=$((     2*(2**30) / 512))}
103: ${FAT_SIZE=$((    10*(2**20) / 512))}
104: ${ROOT_SIZE=$((   64*(2**20) / 512))}
105: ${HOME_SIZE=$((  128*(2**20) / 512))}
106: ${USR_SIZE=$((  1536*(2**20) / 512))}
107
108#
109# create a fstab entry in /etc this is normally done during the
110# setup phase on x86
111#
112cat >${FSTAB} <<END_FSTAB
113/dev/c0d0p2   /home   mfs     rw                      0       2
114/dev/c0d0p3   /usr    mfs     rw                      0       2
115END_FSTAB
116
117rm -f ${DESTDIR}/SETS.*
118
119${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd
120
121#
122# Now given the sizes above use DD to create separate files representing
123# the partitions we are going to use.
124#
125dd if=/dev/zero of=${IMG_DIR}/fat.img bs=512 count=1 seek=$(($FAT_SIZE -1)) 2>/dev/null
126
127#
128# Create the empty image where we later will put the partitions in.
129#
130rm -f ${IMG}
131dd if=/dev/zero of=${IMG} bs=512 count=1 seek=$(($IMG_SIZE -1))
132
133#
134# Do some math to determine the start addresses of the partitions.
135# Don't leave holes so the 'partition' invocation later is easy.
136#
137FAT_START=2048
138ROOT_START=$(($FAT_START + $FAT_SIZE))
139HOME_START=$(($ROOT_START + $ROOT_SIZE))
140USR_START=$(($HOME_START + $HOME_SIZE))
141
142#
143# Write the partition table using the natively compiled
144# minix partition utility
145#
146${CROSS_TOOLS}/nbpartition -m ${IMG} ${FAT_START} "c:${FAT_SIZE}*" 81:${ROOT_SIZE} 81:${HOME_SIZE} 81:${USR_SIZE}
147
148#
149# Format the fat partition and put the bootloaders
150# uEnv and the kernel command line in the FAT partition
151#
152mkfs.vfat ${IMG_DIR}/fat.img
153
154#
155# Create a uEnv.txt file
156# -n default to network boot
157# -p add a prefix to the network booted files (e.g. xm/"
158# -c set console e.g. tty02 or tty00
159# -v set verbosity e.g. 0 to 3
160#./releasetools/gen_uEnv.txt.sh -c ${CONSOLE} -n -p bb/ > ${IMG_DIR}/uEnv.txt
161./releasetools/gen_uEnv.txt.sh -c ${CONSOLE}  > ${IMG_DIR}/uEnv.txt
162
163echo "Copying configuration kernel and boot modules"
164mcopy -bsp -i ${IMG_DIR}/fat.img  ${IMG_DIR}/$MLO ::MLO
165mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/$UBOOT ::u-boot.img
166mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/uEnv.txt ::uEnv.txt
167
168#
169# For tftp booting
170#
171cp ${IMG_DIR}/uEnv.txt ${OBJ}/
172
173#
174# Do some last processing of the kernel and servers before also putting
175# them on the FAT
176#
177${CROSS_PREFIX}objcopy ${OBJ}/kernel/kernel -O binary ${OBJ}/kernel.bin
178
179mcopy -bsp -i ${IMG_DIR}/fat.img ${OBJ}/kernel.bin ::kernel.bin
180
181for f in servers/vm/vm servers/rs/rs servers/pm/pm servers/sched/sched \
182	servers/vfs/vfs servers/ds/ds servers/mfs/mfs servers/pfs/pfs \
183	sbin/init/init
184do
185    fn=`basename $f`.elf
186    cp ${OBJ}/${f} ${OBJ}/${fn}
187    ${CROSS_PREFIX}strip -s ${OBJ}/${fn}
188    mcopy -bsp -i ${IMG_DIR}/fat.img  ${OBJ}/${fn} ::${fn}
189done
190
191for f in tty memory
192do
193    cp ${OBJ}/drivers/${f}/${f} ${OBJ}/${f}.elf
194    ${CROSS_PREFIX}strip -s ${OBJ}/${f}.elf
195    mcopy -bsp -i ${IMG_DIR}/fat.img  ${OBJ}/${f}.elf ::${f}.elf
196done
197
198#
199# make the different file system. this part is *also* hacky. We first convert
200# the METALOG.sanitised using mtree into a input METALOG containing uids and
201# gids.
202# Afther that we do some processing to convert the METALOG into a proto file
203# that can be used by mkfs.mfs
204#
205echo "creating the file systems"
206
207#
208# read METALOG and use mtree to conver the user and group names into uid and gids
209# FIX put "input somwhere clean"
210#
211cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input
212
213# add fstab
214echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input
215
216# fill root.img (skipping /usr entries while keeping the /usr directory)
217cat ${IMG_DIR}/input  | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto
218
219#
220# Create proto files for /usr and /home using toproto.
221#
222cat ${IMG_DIR}/input  | grep  "^\./usr/\|^. "  | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto
223cat ${IMG_DIR}/input  | grep  "^\./home/\|^. "  | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto
224
225#
226# Generate /root, /usr and /home partition images.
227#
228echo "Writing Minix filesystem images"
229echo " - ROOT"
230${CROSS_TOOLS}/nbmkfs.mfs -I $((${ROOT_START} * 512)) -b $((${ROOT_SIZE} / 8)) ${IMG} ${IMG_DIR}/root.proto
231echo " - USR"
232${CROSS_TOOLS}/nbmkfs.mfs -I $((${USR_START} * 512)) -b $((${USR_SIZE} / 8))  ${IMG}  ${IMG_DIR}/usr.proto
233echo " - HOME"
234${CROSS_TOOLS}/nbmkfs.mfs -I $((${HOME_START} * 512)) -b $((${HOME_SIZE} / 8)) ${IMG} ${IMG_DIR}/home.proto
235
236#
237# Merge the partitions into a single image.
238#
239echo "Merging file systems"
240dd if=${IMG_DIR}/fat.img of=${IMG} seek=$FAT_START conv=notrunc
241