2014-08-05 15:35:37 +02:00
|
|
|
#!/usr/bin/env bash
|
2013-03-06 19:27:47 +01:00
|
|
|
set -e
|
2013-03-08 09:42:32 +01:00
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
#
|
|
|
|
# This script creates a bootable image and should at some point in the future
|
|
|
|
# be replaced by makefs.
|
|
|
|
#
|
|
|
|
|
2013-05-30 08:47:39 +02:00
|
|
|
#
|
|
|
|
# Source settings if present
|
|
|
|
#
|
2014-05-26 16:47:45 +02:00
|
|
|
: ${SETTINGS_MINIX=.settings}
|
|
|
|
if [ -f "${SETTINGS_MINIX}" ]
|
2013-05-30 08:47:39 +02:00
|
|
|
then
|
2014-05-26 16:47:45 +02:00
|
|
|
echo "Sourcing settings from ${SETTINGS_MINIX}"
|
2013-05-30 08:47:39 +02:00
|
|
|
# Display the content (so we can check in the build logs
|
|
|
|
# what the settings contain.
|
2014-05-26 16:47:45 +02:00
|
|
|
cat ${SETTINGS_MINIX} | sed "s,^,CONTENT ,g"
|
|
|
|
. ${SETTINGS_MINIX}
|
2013-05-30 08:47:39 +02:00
|
|
|
fi
|
|
|
|
|
2013-03-06 19:27:47 +01:00
|
|
|
: ${ARCH=evbearm-el}
|
2013-03-08 09:42:32 +01:00
|
|
|
: ${OBJ=../obj.${ARCH}}
|
2013-03-06 19:27:47 +01:00
|
|
|
: ${CROSS_TOOLS=${OBJ}/"tooldir.`uname -s`-`uname -r`-`uname -m`"/bin}
|
|
|
|
: ${CROSS_PREFIX=${CROSS_TOOLS}/arm-elf32-minix-}
|
2013-05-23 18:09:19 +02:00
|
|
|
: ${JOBS=1}
|
2013-03-06 19:27:47 +01:00
|
|
|
: ${DESTDIR=${OBJ}/destdir.$ARCH}
|
2013-12-13 13:36:47 +01:00
|
|
|
: ${RELEASETOOLSDIR=./releasetools/}
|
2013-03-08 17:02:27 +01:00
|
|
|
: ${FSTAB=${DESTDIR}/etc/fstab}
|
2013-12-06 16:46:30 +01:00
|
|
|
: ${BUILDVARS=-V MKGCCCMDS=yes -V MKLLVM=no}
|
2014-12-11 15:00:57 +01:00
|
|
|
# These BUILDVARS are for building with LLVM:
|
|
|
|
#: ${BUILDVARS=-V MKLIBCXX=no -V MKKYUA=no -V MKATF=no -V MKLLVMCMDS=no}
|
2013-05-23 18:09:19 +02:00
|
|
|
: ${BUILDSH=build.sh}
|
2014-08-08 14:05:25 +02:00
|
|
|
: ${CREATE_IMAGE_ONLY=0}
|
|
|
|
: ${RC=minix_x86.rc}
|
|
|
|
|
|
|
|
# Where the kernel & boot modules will be
|
|
|
|
MODDIR=${DESTDIR}/boot/minix/.temp
|
2013-05-23 18:09:19 +02:00
|
|
|
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
|
|
|
# Directory where to store temporary file system images
|
|
|
|
#
|
|
|
|
: ${IMG_DIR=${OBJ}/img}
|
|
|
|
: ${MLO=MLO}
|
|
|
|
: ${UBOOT=u-boot.img}
|
2013-05-24 11:04:53 +02:00
|
|
|
|
2013-12-13 13:36:47 +01:00
|
|
|
# Beagleboard-xm
|
|
|
|
: ${U_BOOT_BIN_DIR=build/omap3_beagle/}
|
2013-05-24 11:04:53 +02:00
|
|
|
: ${CONSOLE=tty02}
|
|
|
|
|
2013-12-13 13:36:47 +01:00
|
|
|
# BeagleBone (and black)
|
|
|
|
#: ${U_BOOT_BIN_DIR=build/am335x_evm/}
|
2013-05-24 11:04:53 +02:00
|
|
|
#: ${CONSOLE=tty00}
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2013-12-13 13:36:47 +01:00
|
|
|
#
|
|
|
|
# We host u-boot binaries.
|
2014-08-08 14:05:25 +02:00
|
|
|
#
|
2013-12-13 13:36:47 +01:00
|
|
|
U_BOOT_GIT_VERSION=cb5178f12787c690cb1c888d88733137e5a47b15
|
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
#
|
|
|
|
# All sized are written in 512 byte blocks
|
|
|
|
#
|
|
|
|
# we create a disk image of about 2 gig's
|
|
|
|
# for alignment reasons, prefer sizes which are multiples of 4096 bytes
|
|
|
|
#
|
|
|
|
: ${IMG_SIZE=$(( 2*(2**30) / 512))}
|
|
|
|
: ${FAT_SIZE=$(( 10*(2**20) / 512))}
|
|
|
|
: ${ROOT_SIZE=$(( 64*(2**20) / 512))}
|
|
|
|
: ${HOME_SIZE=$(( 128*(2**20) / 512))}
|
|
|
|
: ${USR_SIZE=$(( 1792*(2**20) / 512))}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Do some math to determine the start addresses of the partitions.
|
|
|
|
# Don't leave holes so the 'partition' invocation later is easy.
|
|
|
|
#
|
|
|
|
FAT_START=2048
|
|
|
|
ROOT_START=$(($FAT_START + $FAT_SIZE))
|
|
|
|
USR_START=$(($ROOT_START + $ROOT_SIZE))
|
|
|
|
HOME_START=$(($USR_START + $USR_SIZE))
|
|
|
|
|
2014-08-05 15:35:37 +02:00
|
|
|
case $(uname -s) in
|
|
|
|
Darwin)
|
|
|
|
MKFS_VFAT_CMD=newfs_msdos
|
2014-10-10 11:19:08 +02:00
|
|
|
MKFS_VFAT_OPTS="-h 64 -u 32 -S 512 -s ${FAT_SIZE} -o 0"
|
2014-08-05 15:35:37 +02:00
|
|
|
;;
|
|
|
|
FreeBSD)
|
|
|
|
MKFS_VFAT_CMD=newfs_msdos
|
|
|
|
MKFS_VFAT_OPTS=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
MKFS_VFAT_CMD=mkfs.vfat
|
|
|
|
MKFS_VFAT_OPTS=
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-12-13 13:36:47 +01:00
|
|
|
if [ -n "$BASE_URL" ]
|
|
|
|
then
|
|
|
|
#we no longer download u-boot but do a checkout
|
|
|
|
#BASE_URL used to be the base url for u-boot
|
|
|
|
#Downloads
|
|
|
|
echo "Warning:** Setting BASE_URL (u-boot) is no longer possible use U_BOOT_BIN_DIR"
|
2014-08-08 14:05:25 +02:00
|
|
|
echo "Look in ${RELEASETOOLSDIR}/arm_sdimage.sh for suggested values"
|
2013-12-13 13:36:47 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-03-08 17:02:27 +01:00
|
|
|
if [ ! -f ${BUILDSH} ]
|
2013-10-16 15:12:30 +02:00
|
|
|
then
|
|
|
|
echo "Please invoke me from the root source dir, where ${BUILDSH} is."
|
2013-03-06 19:27:47 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:${PATH}
|
2013-05-14 11:08:45 +02:00
|
|
|
|
2014-08-05 15:35:37 +02:00
|
|
|
for needed in mcopy dd ${MKFS_VFAT_CMD} git
|
2013-04-22 22:53:44 +02:00
|
|
|
do
|
|
|
|
if ! which $needed 2>&1 > /dev/null
|
|
|
|
then
|
|
|
|
echo "**Skipping image creation: missing tool '$needed'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
: ${IMG=minix_arm_sd.img}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Are we going to build the minix sources?
|
|
|
|
#
|
|
|
|
|
|
|
|
if [ ${CREATE_IMAGE_ONLY} -eq 1 ]
|
|
|
|
then
|
|
|
|
if [ ! -d ${DESTDIR} ]
|
|
|
|
then
|
|
|
|
echo "Minix source code does'nt appear to have been built."
|
|
|
|
echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
|
|
|
# Artifacts from this script are stored in the IMG_DIR
|
|
|
|
#
|
2014-09-12 12:34:13 +02:00
|
|
|
rm -rf ${IMG_DIR}
|
|
|
|
|
|
|
|
if [ -f ${IMG} ] # IMG might be a block device
|
|
|
|
then rm -f ${IMG}
|
|
|
|
fi
|
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
mkdir -p ${IMG_DIR}
|
2013-04-22 22:53:44 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Download the stage 1 bootloader and u-boot
|
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
${RELEASETOOLSDIR}/fetch_u-boot.sh -o ${RELEASETOOLSDIR}/u-boot -n $U_BOOT_GIT_VERSION
|
2013-12-13 13:36:47 +01:00
|
|
|
cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/u-boot.img ${IMG_DIR}/
|
|
|
|
cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/MLO ${IMG_DIR}/
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
if [ ${CREATE_IMAGE_ONLY} -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "Going to build Minix source code..."
|
|
|
|
#
|
|
|
|
# Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'.
|
|
|
|
#
|
|
|
|
rm -f ${FSTAB}
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
#
|
|
|
|
# Now start the build.
|
|
|
|
#
|
|
|
|
sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2014-08-08 14:05:25 +02:00
|
|
|
fi
|
2014-08-05 15:35:37 +02:00
|
|
|
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
|
|
|
# create a fstab entry in /etc this is normally done during the
|
|
|
|
# setup phase on x86
|
|
|
|
#
|
2013-03-08 17:02:27 +01:00
|
|
|
cat >${FSTAB} <<END_FSTAB
|
2014-08-08 14:05:25 +02:00
|
|
|
/dev/c0d0p2 /usr mfs rw 0 2
|
|
|
|
/dev/c0d0p3 /home mfs rw 0 2
|
|
|
|
none /sys devman rw,rslabel=devman 0 0
|
2013-03-06 19:27:47 +01:00
|
|
|
END_FSTAB
|
|
|
|
|
2013-03-08 17:02:27 +01:00
|
|
|
rm -f ${DESTDIR}/SETS.*
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2013-03-08 17:02:27 +01:00
|
|
|
${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2013-04-10 16:58:46 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
# make the different file system. this part is *also* hacky. We first convert
|
|
|
|
# the METALOG.sanitised using mtree into a input METALOG containing uids and
|
|
|
|
# gids.
|
|
|
|
# After that we do some magic processing to add device nodes (also missing from METALOG)
|
|
|
|
# and convert the METALOG into a proto file that can be used by mkfs.mfs
|
2013-04-10 16:58:46 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
echo "Creating the file systems"
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
# read METALOG and use mtree to convert the user and group names into uid and gids
|
|
|
|
# FIX put "input somewhere clean"
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input
|
|
|
|
|
|
|
|
# add rc (if any)
|
|
|
|
if [ -f ${RC} ]; then
|
|
|
|
cp ${RC} ${DESTDIR}/usr/etc/rc.local
|
|
|
|
echo "./usr/etc/rc.local type=file uid=0 gid=0 mode=0644" >> ${IMG_DIR}/input
|
|
|
|
fi
|
|
|
|
|
|
|
|
# add fstab
|
|
|
|
echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input
|
|
|
|
|
|
|
|
# fill root.img (skipping /usr entries while keeping the /usr directory)
|
|
|
|
cat ${IMG_DIR}/input | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
# Create proto files for /usr and /home using toproto.
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
cat ${IMG_DIR}/input | grep "^\./usr/\|^. " | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto
|
|
|
|
cat ${IMG_DIR}/input | grep "^\./home/\|^. " | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto
|
2013-09-26 13:42:31 +02:00
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
# Create the FAT partition, which contains the bootloader files, kernel and modules
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
dd if=/dev/zero of=${IMG_DIR}/fat.img bs=512 count=1 seek=$(($FAT_SIZE -1)) 2>/dev/null
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
|
|
|
# Format the fat partition and put the bootloaders
|
|
|
|
# uEnv and the kernel command line in the FAT partition
|
|
|
|
#
|
2014-08-05 15:35:37 +02:00
|
|
|
${MKFS_VFAT_CMD} ${MKFS_VFAT_OPTS} ${IMG_DIR}/fat.img
|
2013-03-08 17:02:27 +01:00
|
|
|
|
2013-05-24 10:23:44 +02:00
|
|
|
#
|
|
|
|
# Create a uEnv.txt file
|
|
|
|
# -n default to network boot
|
|
|
|
# -p add a prefix to the network booted files (e.g. xm/"
|
|
|
|
# -c set console e.g. tty02 or tty00
|
2013-05-24 11:04:53 +02:00
|
|
|
# -v set verbosity e.g. 0 to 3
|
2014-08-08 14:05:25 +02:00
|
|
|
#${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} -n -p bb/ > ${IMG_DIR}/uEnv.txt
|
|
|
|
${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} > ${IMG_DIR}/uEnv.txt
|
2013-05-24 10:23:44 +02:00
|
|
|
|
2013-04-22 22:53:44 +02:00
|
|
|
echo "Copying configuration kernel and boot modules"
|
|
|
|
mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/$MLO ::MLO
|
|
|
|
mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/$UBOOT ::u-boot.img
|
2013-05-22 09:12:13 +02:00
|
|
|
mcopy -bsp -i ${IMG_DIR}/fat.img ${IMG_DIR}/uEnv.txt ::uEnv.txt
|
2013-03-08 17:02:27 +01:00
|
|
|
|
2013-04-27 09:50:04 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
# Do some last processing of the kernel and servers and then put them on the FAT
|
|
|
|
# partition.
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
2014-07-28 21:19:37 +02:00
|
|
|
${CROSS_PREFIX}objcopy ${OBJ}/minix/kernel/kernel -O binary ${OBJ}/kernel.bin
|
2013-04-22 22:53:44 +02:00
|
|
|
|
|
|
|
mcopy -bsp -i ${IMG_DIR}/fat.img ${OBJ}/kernel.bin ::kernel.bin
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2013-09-09 15:20:18 +02:00
|
|
|
for f in servers/vm/vm servers/rs/rs servers/pm/pm servers/sched/sched \
|
2014-07-28 21:19:37 +02:00
|
|
|
servers/vfs/vfs servers/ds/ds fs/mfs/mfs fs/pfs/pfs \
|
|
|
|
../sbin/init/init
|
2013-03-06 19:27:47 +01:00
|
|
|
do
|
2013-09-09 15:20:18 +02:00
|
|
|
fn=`basename $f`.elf
|
2014-07-28 21:19:37 +02:00
|
|
|
cp ${OBJ}/minix/${f} ${OBJ}/${fn}
|
2013-09-09 15:20:18 +02:00
|
|
|
${CROSS_PREFIX}strip -s ${OBJ}/${fn}
|
|
|
|
mcopy -bsp -i ${IMG_DIR}/fat.img ${OBJ}/${fn} ::${fn}
|
2013-03-06 19:27:47 +01:00
|
|
|
done
|
|
|
|
|
2014-07-28 21:19:37 +02:00
|
|
|
for f in tty/tty/tty storage/memory/memory
|
2013-03-06 19:27:47 +01:00
|
|
|
do
|
2014-07-28 21:19:37 +02:00
|
|
|
fn=`basename $f`.elf
|
|
|
|
cp ${OBJ}/minix/drivers/${f} ${OBJ}/${fn}
|
|
|
|
${CROSS_PREFIX}strip -s ${OBJ}/${fn}
|
|
|
|
mcopy -bsp -i ${IMG_DIR}/fat.img ${OBJ}/${fn} ::${fn}
|
2013-03-06 19:27:47 +01:00
|
|
|
done
|
|
|
|
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
# For tftp booting
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
cp ${IMG_DIR}/uEnv.txt ${OBJ}/
|
2013-04-22 22:53:44 +02:00
|
|
|
|
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
# Create the empty image where we later will put the partitions in.
|
|
|
|
# Make sure it is at least 2GB, otherwise the SD card will not be detected
|
|
|
|
# correctly in qemu / HW.
|
2013-04-22 22:53:44 +02:00
|
|
|
#
|
2014-08-08 14:05:25 +02:00
|
|
|
dd if=/dev/zero of=${IMG} bs=512 count=1 seek=$(($IMG_SIZE -1))
|
2013-04-22 22:53:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
#
|
2013-05-23 18:09:19 +02:00
|
|
|
# Generate /root, /usr and /home partition images.
|
|
|
|
#
|
2013-10-03 18:26:21 +02:00
|
|
|
echo "Writing Minix filesystem images"
|
2013-06-28 20:27:53 +02:00
|
|
|
echo " - ROOT"
|
2014-08-08 14:05:25 +02:00
|
|
|
_ROOT_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -I $((${ROOT_START} * 512)) -b $((${ROOT_SIZE} / 8)) ${IMG} ${IMG_DIR}/root.proto`/512))
|
2013-06-28 20:27:53 +02:00
|
|
|
echo " - USR"
|
2014-08-08 14:05:25 +02:00
|
|
|
_USR_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -I $((${USR_START} * 512)) -b $((${USR_SIZE} / 8)) ${IMG} ${IMG_DIR}/usr.proto`/512))
|
2013-06-28 20:27:53 +02:00
|
|
|
echo " - HOME"
|
2014-08-08 14:05:25 +02:00
|
|
|
_HOME_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -I $((${HOME_START} * 512)) -b $((${HOME_SIZE} / 8)) ${IMG} ${IMG_DIR}/home.proto`/512))
|
|
|
|
|
|
|
|
#
|
|
|
|
# Write the partition table using the natively compiled
|
|
|
|
# minix partition utility
|
|
|
|
#
|
2014-09-12 12:34:13 +02:00
|
|
|
${CROSS_TOOLS}/nbpartition -f -m ${IMG} ${FAT_START} "c:${FAT_SIZE}*" \
|
2014-08-08 14:05:25 +02:00
|
|
|
81:${_ROOT_SIZE} 81:${_USR_SIZE} 81:${_HOME_SIZE}
|
2013-04-22 22:53:44 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Merge the partitions into a single image.
|
|
|
|
#
|
|
|
|
echo "Merging file systems"
|
|
|
|
dd if=${IMG_DIR}/fat.img of=${IMG} seek=$FAT_START conv=notrunc
|