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