1#!/bin/bash 2set -e 3 4# 5# Source settings if present 6# 7: ${SETTINGS_MINIX=.settings} 8if [ -f "${SETTINGS_MINIX}" ] 9then 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} 15fi 16 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} 27 28# 29# Directory where to store temporary file system images 30# 31: ${IMG_DIR=${OBJ}/img} 32: ${IMG=minix_arm_sd.img} 33: ${MLO=MLO} 34: ${UBOOT=u-boot.img} 35 36 37# Beagleboard-xm 38: ${U_BOOT_BIN_DIR=build/omap3_beagle/} 39: ${CONSOLE=tty02} 40 41 42# BeagleBone (and black) 43#: ${U_BOOT_BIN_DIR=build/am335x_evm/} 44#: ${CONSOLE=tty00} 45 46# 47# 48# We host u-boot binaries. 49U_BOOT_GIT_VERSION=cb5178f12787c690cb1c888d88733137e5a47b15 50 51if [ -n "$BASE_URL" ] 52then 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 59fi 60 61if [ ! -f ${BUILDSH} ] 62then 63 echo "Please invoke me from the root source dir, where ${BUILDSH} is." 64 exit 1 65fi 66 67export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH 68 69for needed in mcopy dd mkfs.vfat git 70do 71 if ! which $needed 2>&1 > /dev/null 72 then 73 echo "**Skipping image creation: missing tool '$needed'" 74 exit 1 75 fi 76done 77 78# 79# Artifacts from this script are stored in the IMG_DIR 80# 81mkdir -p $IMG_DIR 82 83# 84# Download the stage 1 bootloader and u-boot 85# 86./releasetools/fetch_u-boot.sh -o ${RELEASETOOLSDIR}/u-boot -n $U_BOOT_GIT_VERSION 87cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/u-boot.img ${IMG_DIR}/ 88cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/MLO ${IMG_DIR}/ 89 90# 91# Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'. 92# 93rm -f ${FSTAB} 94 95# 96# Now start the build 97# 98export CPPFLAGS=${FLAG} 99sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution 100 101# 102# This script creates a bootable image and should at some point in the future 103# be replaced by makefs. 104# 105# All sized are written in 512 byte blocks 106# 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))} 113 114# 115# create a fstab entry in /etc this is normally done during the 116# setup phase on x86 117# 118cat >${FSTAB} <<END_FSTAB 119/dev/c0d0p2 /home mfs rw 0 2 120/dev/c0d0p3 /usr mfs rw 0 2 121none /sys devman rw,rslabel=devman 0 0 122END_FSTAB 123 124rm -f ${DESTDIR}/SETS.* 125 126${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd 127 128# 129# Now given the sizes above use DD to create separate files representing 130# the partitions we are going to use. 131# 132dd if=/dev/zero of=${IMG_DIR}/fat.img bs=512 count=1 seek=$(($FAT_SIZE -1)) 2>/dev/null 133 134# 135# Create the empty image where we later will put the partitions in. 136# 137rm -f ${IMG} 138dd if=/dev/zero of=${IMG} bs=512 count=1 seek=$(($IMG_SIZE -1)) 139 140# 141# Do some math to determine the start addresses of the partitions. 142# Don't leave holes so the 'partition' invocation later is easy. 143# 144FAT_START=2048 145ROOT_START=$(($FAT_START + $FAT_SIZE)) 146HOME_START=$(($ROOT_START + $ROOT_SIZE)) 147USR_START=$(($HOME_START + $HOME_SIZE)) 148 149# 150# Write the partition table using the natively compiled 151# minix partition utility 152# 153${CROSS_TOOLS}/nbpartition -m ${IMG} ${FAT_START} "c:${FAT_SIZE}*" 81:${ROOT_SIZE} 81:${HOME_SIZE} 81:${USR_SIZE} 154 155# 156# Format the fat partition and put the bootloaders 157# uEnv and the kernel command line in the FAT partition 158# 159mkfs.vfat ${IMG_DIR}/fat.img 160 161# 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 169 170echo "Copying configuration kernel and boot modules" 171mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/$MLO ::MLO 172mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/$UBOOT ::u-boot.img 173mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/uEnv.txt ::uEnv.txt 174 175# 176# For tftp booting 177# 178cp ${IMG_DIR}/uEnv.txt ${OBJ}/ 179 180# 181# Do some last processing of the kernel and servers before also putting 182# them on the FAT 183# 184${CROSS_PREFIX}objcopy ${OBJ}/kernel/kernel -O binary ${OBJ}/kernel.bin 185 186mcopy -bsp -i ${IMG_DIR}/fat.img ${OBJ}/kernel.bin ::kernel.bin 187 188for 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 191do 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} 196done 197 198for f in tty memory 199do 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 203done 204 205# 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 211# 212echo "creating the file systems" 213 214# 215# read METALOG and use mtree to conver the user and group names into uid and gids 216# FIX put "input somwhere clean" 217# 218cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input 219 220# add fstab 221echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input 222 223# fill root.img (skipping /usr entries while keeping the /usr directory) 224cat ${IMG_DIR}/input | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto 225 226# 227# Create proto files for /usr and /home using toproto. 228# 229cat ${IMG_DIR}/input | grep "^\./usr/\|^. " | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto 230cat ${IMG_DIR}/input | grep "^\./home/\|^. " | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto 231 232# 233# Generate /root, /usr and /home partition images. 234# 235echo "Writing Minix filesystem images" 236echo " - ROOT" 237${CROSS_TOOLS}/nbmkfs.mfs -I $((${ROOT_START} * 512)) -b $((${ROOT_SIZE} / 8)) ${IMG} ${IMG_DIR}/root.proto 238echo " - USR" 239${CROSS_TOOLS}/nbmkfs.mfs -I $((${USR_START} * 512)) -b $((${USR_SIZE} / 8)) ${IMG} ${IMG_DIR}/usr.proto 240echo " - HOME" 241${CROSS_TOOLS}/nbmkfs.mfs -I $((${HOME_START} * 512)) -b $((${HOME_SIZE} / 8)) ${IMG} ${IMG_DIR}/home.proto 242 243# 244# Merge the partitions into a single image. 245# 246echo "Merging file systems" 247dd if=${IMG_DIR}/fat.img of=${IMG} seek=$FAT_START conv=notrunc 248