xref: /minix/releasetools/arm_sdimage.sh (revision e39e890e)
1#!/bin/bash
2set -e
3
4#
5# Source settings if present
6#
7if [ -f .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# Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'.
91#
92rm -f ${FSTAB}
93
94#
95# Now start the build
96#
97export CPPFLAGS=${FLAG}
98sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
99
100#
101# This script creates a bootable image and should at some point in the future
102# be replaced by makefs.
103#
104# All sized are written in 512 byte blocks
105#
106# we create a disk image of about 2 gig's
107: ${IMG_SIZE=$((     2*(2**30) / 512))}
108: ${FAT_SIZE=$((    10*(2**20) / 512))}
109: ${ROOT_SIZE=$((   64*(2**20) / 512))}
110: ${HOME_SIZE=$((  128*(2**20) / 512))}
111: ${USR_SIZE=$((  1536*(2**20) / 512))}
112
113#
114# create a fstab entry in /etc this is normally done during the
115# setup phase on x86
116#
117cat >${FSTAB} <<END_FSTAB
118/dev/c0d0p2   /home   mfs     rw                      0       2
119/dev/c0d0p3   /usr    mfs     rw                      0       2
120none          /sys    devman  rw,rslabel=devman       0       0
121END_FSTAB
122
123rm -f ${DESTDIR}/SETS.*
124
125${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd
126
127#
128# Now given the sizes above use DD to create separate files representing
129# the partitions we are going to use.
130#
131dd if=/dev/zero of=${IMG_DIR}/fat.img bs=512 count=1 seek=$(($FAT_SIZE -1)) 2>/dev/null
132
133#
134# Create the empty image where we later will put the partitions in.
135#
136rm -f ${IMG}
137dd if=/dev/zero of=${IMG} bs=512 count=1 seek=$(($IMG_SIZE -1))
138
139#
140# Do some math to determine the start addresses of the partitions.
141# Don't leave holes so the 'partition' invocation later is easy.
142#
143FAT_START=2048
144ROOT_START=$(($FAT_START + $FAT_SIZE))
145HOME_START=$(($ROOT_START + $ROOT_SIZE))
146USR_START=$(($HOME_START + $HOME_SIZE))
147
148#
149# Write the partition table using the natively compiled
150# minix partition utility
151#
152${CROSS_TOOLS}/nbpartition -m ${IMG} ${FAT_START} "c:${FAT_SIZE}*" 81:${ROOT_SIZE} 81:${HOME_SIZE} 81:${USR_SIZE}
153
154#
155# Format the fat partition and put the bootloaders
156# uEnv and the kernel command line in the FAT partition
157#
158mkfs.vfat ${IMG_DIR}/fat.img
159
160#
161# Create a uEnv.txt file
162# -n default to network boot
163# -p add a prefix to the network booted files (e.g. xm/"
164# -c set console e.g. tty02 or tty00
165# -v set verbosity e.g. 0 to 3
166#./releasetools/gen_uEnv.txt.sh -c ${CONSOLE} -n -p bb/ > ${IMG_DIR}/uEnv.txt
167./releasetools/gen_uEnv.txt.sh -c ${CONSOLE}  > ${IMG_DIR}/uEnv.txt
168
169echo "Copying configuration kernel and boot modules"
170mcopy -bsp -i ${IMG_DIR}/fat.img  ${IMG_DIR}/$MLO ::MLO
171mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/$UBOOT ::u-boot.img
172mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/uEnv.txt ::uEnv.txt
173
174#
175# For tftp booting
176#
177cp ${IMG_DIR}/uEnv.txt ${OBJ}/
178
179#
180# Do some last processing of the kernel and servers before also putting
181# them on the FAT
182#
183${CROSS_PREFIX}objcopy ${OBJ}/kernel/kernel -O binary ${OBJ}/kernel.bin
184
185mcopy -bsp -i ${IMG_DIR}/fat.img ${OBJ}/kernel.bin ::kernel.bin
186
187for f in servers/vm/vm servers/rs/rs servers/pm/pm servers/sched/sched \
188	servers/vfs/vfs servers/ds/ds servers/mfs/mfs servers/pfs/pfs \
189	sbin/init/init
190do
191    fn=`basename $f`.elf
192    cp ${OBJ}/${f} ${OBJ}/${fn}
193    ${CROSS_PREFIX}strip -s ${OBJ}/${fn}
194    mcopy -bsp -i ${IMG_DIR}/fat.img  ${OBJ}/${fn} ::${fn}
195done
196
197for f in tty memory
198do
199    cp ${OBJ}/drivers/${f}/${f} ${OBJ}/${f}.elf
200    ${CROSS_PREFIX}strip -s ${OBJ}/${f}.elf
201    mcopy -bsp -i ${IMG_DIR}/fat.img  ${OBJ}/${f}.elf ::${f}.elf
202done
203
204#
205# make the different file system. this part is *also* hacky. We first convert
206# the METALOG.sanitised using mtree into a input METALOG containing uids and
207# gids.
208# Afther that we do some processing to convert the METALOG into a proto file
209# that can be used by mkfs.mfs
210#
211echo "creating the file systems"
212
213#
214# read METALOG and use mtree to conver the user and group names into uid and gids
215# FIX put "input somwhere clean"
216#
217cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input
218
219# add fstab
220echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input
221
222# fill root.img (skipping /usr entries while keeping the /usr directory)
223cat ${IMG_DIR}/input  | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto
224
225#
226# Create proto files for /usr and /home using toproto.
227#
228cat ${IMG_DIR}/input  | grep  "^\./usr/\|^. "  | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto
229cat ${IMG_DIR}/input  | grep  "^\./home/\|^. "  | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto
230
231#
232# Generate /root, /usr and /home partition images.
233#
234echo "Writing Minix filesystem images"
235echo " - ROOT"
236${CROSS_TOOLS}/nbmkfs.mfs -I $((${ROOT_START} * 512)) -b $((${ROOT_SIZE} / 8)) ${IMG} ${IMG_DIR}/root.proto
237echo " - USR"
238${CROSS_TOOLS}/nbmkfs.mfs -I $((${USR_START} * 512)) -b $((${USR_SIZE} / 8))  ${IMG}  ${IMG_DIR}/usr.proto
239echo " - HOME"
240${CROSS_TOOLS}/nbmkfs.mfs -I $((${HOME_START} * 512)) -b $((${HOME_SIZE} / 8)) ${IMG} ${IMG_DIR}/home.proto
241
242#
243# Merge the partitions into a single image.
244#
245echo "Merging file systems"
246dd if=${IMG_DIR}/fat.img of=${IMG} seek=$FAT_START conv=notrunc
247