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
|
2015-09-16 16:00:24 +02:00
|
|
|
# be replaced by the proper NetBSD infrastructure.
|
2014-08-08 14:05:25 +02:00
|
|
|
#
|
|
|
|
|
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}}
|
2015-09-16 16:00:24 +02:00
|
|
|
: ${TOOLCHAIN_TRIPLET=arm-elf32-minix-}
|
2013-05-23 18:09:19 +02:00
|
|
|
: ${BUILDSH=build.sh}
|
2014-08-08 14:05:25 +02:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
: ${SETS="minix-base minix-comp minix-games minix-man minix-tests tests"}
|
|
|
|
: ${IMG=minix_arm_sd.img}
|
2013-05-23 18:09:19 +02:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
# ARM definitions:
|
|
|
|
: ${BUILDVARS=-V MKGCCCMDS=yes -V MKLLVM=no}
|
|
|
|
# These BUILDVARS are for building with LLVM:
|
|
|
|
#: ${BUILDVARS=-V MKLIBCXX=no -V MKKYUA=no -V MKATF=no -V MKLLVMCMDS=no}
|
|
|
|
: ${FAT_SIZE=$(( 10*(2**20) / 512))} # This is in sectors
|
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
|
|
|
#
|
2015-09-16 16:00:24 +02:00
|
|
|
: ${MLO=MLO}
|
|
|
|
: ${UBOOT=u-boot.img}
|
2013-12-13 13:36:47 +01:00
|
|
|
U_BOOT_GIT_VERSION=cb5178f12787c690cb1c888d88733137e5a47b15
|
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
if [ ! -f ${BUILDSH} ]
|
|
|
|
then
|
|
|
|
echo "Please invoke me from the root source dir, where ${BUILDSH} is."
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-08-08 14:05:25 +02:00
|
|
|
|
2015-09-16 16:00:24 +02: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"
|
|
|
|
echo "Look in ${RELEASETOOLSDIR}/arm_sdimage.sh for suggested values"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-08-08 14:05:25 +02:00
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
# 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) ))}
|
|
|
|
: ${ROOT_SIZE=$(( 64*(2**20) ))}
|
|
|
|
: ${HOME_SIZE=$(( 128*(2**20) ))}
|
|
|
|
: ${USR_SIZE=$(( 1792*(2**20) ))}
|
2014-09-12 12:34:13 +02:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
# set up disk creation environment
|
|
|
|
. releasetools/image.defaults
|
|
|
|
. releasetools/image.functions
|
2014-09-12 12:34:13 +02:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
# all sizes are written in 512 byte blocks
|
|
|
|
ROOTSIZEARG="-b $((${ROOT_SIZE} / 512 / 8))"
|
|
|
|
USRSIZEARG="-b $((${USR_SIZE} / 512 / 8))"
|
|
|
|
HOMESIZEARG="-b $((${HOME_SIZE} / 512 / 8))"
|
2013-04-22 22:53:44 +02:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
# where the kernel & boot modules will be
|
|
|
|
MODDIR=${DESTDIR}/boot/minix/.temp
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
echo "Building work directory..."
|
|
|
|
build_workdir "$SETS"
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
echo "Adding extra files..."
|
2014-08-05 15:35:37 +02:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
# create a fstab entry in /etc
|
|
|
|
cat >${ROOT_DIR}/etc/fstab <<END_FSTAB
|
Add PTYFS, Unix98 pseudo terminal support
This patch adds support for Unix98 pseudo terminals, that is,
posix_openpt(3), grantpt(3), unlockpt(3), /dev/ptmx, and /dev/pts/.
The latter is implemented with a new pseudo file system, PTYFS.
In effect, this patch adds secure support for unprivileged pseudo
terminal allocation, allowing programs such as tmux(1) to be used by
non-root users as well. Test77 has been extended with new tests, and
no longer needs to run as root.
The new functionality is optional. To revert to the old behavior,
remove the "ptyfs" entry from /etc/fstab.
Technical nodes:
o The reason for not implementing the NetBSD /dev/ptm approach is that
implementing the corresponding ioctl (TIOCPTMGET) would require
adding a number of extremely hairy exceptions to VFS, including the
PTY driver having to create new file descriptors for its own device
nodes.
o PTYFS is required for Unix98 PTYs in order to avoid that the PTY
driver has to be aware of old-style PTY naming schemes and even has
to call chmod(2) on a disk-backed file system. PTY cannot be its
own PTYFS since a character driver may currently not also be a file
system. However, PTYFS may be subsumed into a DEVFS in the future.
o The Unix98 PTY behavior differs somewhat from NetBSD's, in that
slave nodes are created on ptyfs only upon the first call to
grantpt(3). This approach obviates the need to revoke access as
part of the grantpt(3) call.
o Shutting down PTY may leave slave nodes on PTYFS, but once PTY is
restarted, these leftover slave nodes will be removed before they
create a security risk. Unmounting PTYFS will make existing PTY
slaves permanently unavailable, and absence of PTYFS will block
allocation of new Unix98 PTYs until PTYFS is (re)mounted.
Change-Id: I822b43ba32707c8815fd0f7d5bb7a438f51421c1
2015-06-22 19:14:34 +02:00
|
|
|
/dev/c0d0p2 /usr mfs rw 0 2
|
|
|
|
/dev/c0d0p3 /home mfs rw 0 2
|
|
|
|
none /sys devman rw,rslabel=devman 0 0
|
|
|
|
none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
|
2013-03-06 19:27:47 +01:00
|
|
|
END_FSTAB
|
2015-09-16 16:00:24 +02:00
|
|
|
add_file_spec "etc/fstab" extra.fstab
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
echo "Bundling packages..."
|
|
|
|
bundle_packages "$BUNDLE_PACKAGES"
|
2013-03-06 19:27:47 +01:00
|
|
|
|
2015-09-16 16:00:24 +02:00
|
|
|
echo "Creating specification files..."
|
|
|
|
create_input_spec
|
|
|
|
create_protos "usr home"
|
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
|
|
|
#
|
2015-09-16 16:00:24 +02:00
|
|
|
dd if=/dev/zero of=${WORK_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
|
|
|
|
#
|
2015-09-16 16:00:24 +02:00
|
|
|
${MKFS_VFAT_CMD} ${MKFS_VFAT_OPTS} ${WORK_DIR}/fat.img
|
|
|
|
|
|
|
|
#
|
|
|
|
# Download the stage 1 bootloader and u-boot
|
|
|
|
#
|
|
|
|
${RELEASETOOLSDIR}/fetch_u-boot.sh -o ${RELEASETOOLSDIR}/u-boot -n $U_BOOT_GIT_VERSION
|
|
|
|
cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/MLO ${WORK_DIR}/
|
|
|
|
cp ${RELEASETOOLSDIR}/u-boot/${U_BOOT_BIN_DIR}/u-boot.img ${WORK_DIR}/
|
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
|
2015-09-16 16:00:24 +02:00
|
|
|
#${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} -n -p bb/ > ${WORK_DIR}/uEnv.txt
|
|
|
|
${RELEASETOOLSDIR}/gen_uEnv.txt.sh -c ${CONSOLE} > ${WORK_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"
|
2015-09-16 16:00:24 +02:00
|
|
|
mcopy -bsp -i ${WORK_DIR}/fat.img ${WORK_DIR}/$MLO ::MLO
|
|
|
|
mcopy -bsp -i ${WORK_DIR}/fat.img ${WORK_DIR}/$UBOOT ::u-boot.img
|
|
|
|
mcopy -bsp -i ${WORK_DIR}/fat.img ${WORK_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
|
2015-09-16 16:00:24 +02:00
|
|
|
mcopy -bsp -i ${WORK_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}
|
2015-09-16 16:00:24 +02:00
|
|
|
mcopy -bsp -i ${WORK_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}
|
2015-09-16 16:00:24 +02:00
|
|
|
mcopy -bsp -i ${WORK_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
|
|
|
#
|
2015-09-16 16:00:24 +02:00
|
|
|
cp ${WORK_DIR}/uEnv.txt ${OBJ}/
|
|
|
|
|
|
|
|
# Clean image
|
|
|
|
if [ -f ${IMG} ] # IMG might be a block device
|
|
|
|
then
|
|
|
|
rm -f ${IMG}
|
|
|
|
fi
|
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
|
|
|
#
|
2015-09-16 16:00:24 +02:00
|
|
|
dd if=/dev/zero of=${IMG} bs=512 count=1 seek=$((($IMG_SIZE / 512) -1))
|
2013-04-22 22:53:44 +02:00
|
|
|
|
|
|
|
#
|
2013-05-23 18:09:19 +02:00
|
|
|
# Generate /root, /usr and /home partition images.
|
|
|
|
#
|
2015-09-16 16:00:24 +02:00
|
|
|
echo "Writing disk image..."
|
|
|
|
FAT_START=2048 # those are sectors
|
|
|
|
ROOT_START=$(($FAT_START + $FAT_SIZE))
|
|
|
|
echo " * ROOT"
|
|
|
|
_ROOT_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${ROOTSIZEARG} -I $((${ROOT_START}*512)) ${IMG} ${WORK_DIR}/proto.root)
|
|
|
|
_ROOT_SIZE=$(($_ROOT_SIZE / 512))
|
|
|
|
USR_START=$((${ROOT_START} + ${_ROOT_SIZE}))
|
|
|
|
echo " * USR"
|
|
|
|
_USR_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${USRSIZEARG} -I $((${USR_START}*512)) ${IMG} ${WORK_DIR}/proto.usr)
|
|
|
|
_USR_SIZE=$(($_USR_SIZE / 512))
|
|
|
|
HOME_START=$((${USR_START} + ${_USR_SIZE}))
|
|
|
|
echo " * HOME"
|
|
|
|
_HOME_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${HOMESIZEARG} -I $((${HOME_START}*512)) ${IMG} ${WORK_DIR}/proto.home)
|
|
|
|
_HOME_SIZE=$(($_HOME_SIZE / 512))
|
2014-08-08 14:05:25 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Write the partition table using the natively compiled
|
|
|
|
# minix partition utility
|
|
|
|
#
|
2015-09-16 16:00:24 +02:00
|
|
|
${CROSS_TOOLS}/nbpartition -f -m ${IMG} ${FAT_START} "c:${FAT_SIZE}*" 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"
|
2015-09-16 16:00:24 +02:00
|
|
|
dd if=${WORK_DIR}/fat.img of=${IMG} seek=$FAT_START conv=notrunc
|
|
|
|
|
|
|
|
echo "Disk image at `pwd`/${IMG}"
|
|
|
|
echo "To boot this image on kvm:"
|
|
|
|
echo "qemu-system-arm -M beaglexm -serial stdio -drive if=sd,cache=writeback,file=`pwd`/${IMG}"
|