#!/bin/sh -Cefux # # Copyright (c) 2014 Sulev-Madis Silber # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # set -Cefux cd "${0%/*}" || exit 1 src_uboot=src-uboot src_boot=src-boot src_root=src-root overlay_root=overlay-root src_size_megs="`du -mxcs \"$src_boot/\" \"$src_root/\" \"$overlay_root/\" | awk '$2 == \"total\" {print $1}'`" dir_boot=img-boot dir_root=img-root img=bbb-minimal.img img_sparse_size="$((src_size_megs + 100))m" dev=md900 label_boot=bbbboot label_root=bbbroot label_boot_uc="`echo -n \"$label_boot\" | tr a-z A-Z`" mbrpartid_boot=1 mbrpartid_root=2 bsdpartid_root_num=1 bsdpartid_root_letter=a _rsync() { local rc=0 local src= local extra_opts= local type="$1" local dest="$2" extra_opts="$extra_opts -c" case "$type" in boot) src="$src_boot/" extra_opts="$extra_opts --delete -O --modify-window=1 --no-p" ;; root) src="$src_root/" extra_opts="$extra_opts --delete --exclude .snap --fileflags" ;; rootoverlay) src="$overlay_root/" extra_opts="$extra_opts --exclude .snap --fileflags" ;; esac rsync \ \ -vhhixaHAXS \ \ $extra_opts \ \ --stats \ --progress \ --numeric-ids \ --force \ --force-delete \ --force-change \ \ "$src" \ \ "$dest" rc="$?" return "$rc" } ls -lhaoiG "$src_uboot/" ls -lhaoiG "$src_boot/" cp -av "$src_uboot/MLO" "$src_boot/mlo" cp -av "$src_uboot/u-boot.img" "$src_boot/" cp -av "$src_root/boot/ubldr" "$src_boot/" chmod -vv 644 "$src_boot/ubldr" ls -lhaoiG "$src_boot/" umount -v "$dir_boot" "$dir_root" || true mdconfig -d -u "$dev" || true rm -v "$img" "${img}.xz" || true truncate -s "$img_sparse_size" "$img" ls -lhaoiG "$img" mdconfig -a -t vnode -f "$img" -u "$dev" gpart create -s mbr "$dev" gpart add -t !12 -a 4m -s 4m -i "$mbrpartid_boot" "$dev" gpart add -t freebsd -a 4m -i "$mbrpartid_root" "$dev" gpart set -a active -i "$mbrpartid_boot" "$dev" gpart create -s bsd "${dev}s${mbrpartid_root}" gpart add -t freebsd-ufs -a 4m -i "$bsdpartid_root_num" "${dev}s${mbrpartid_root}" gpart show "$dev" "${dev}s${mbrpartid_root}" newfs_msdos -F 12 -L "$label_boot_uc" "/dev/${dev}s${mbrpartid_boot}" newfs -L "$label_root" -U "/dev/${dev}s${mbrpartid_root}${bsdpartid_root_letter}" mount_msdosfs -o noatime "/dev/msdosfs/$label_boot_uc" "$dir_boot" mount -v -o noatime "/dev/ufs/$label_root" "$dir_root" [ "$dir_boot" -a "$dir_root" ] _rsync boot "$dir_boot/" #_rsync root "$dir_root/" tar cf - -C "$src_root" . | tar vxpof - -C "$dir_root" _rsync rootoverlay "$dir_root/" date -u > "$dir_boot/createdt.ime" date -u > "$dir_root/CREATED.time" ls -lhaoiG "$dir_boot" "$dir_root" "$dir_root/boot/kernel" "$dir_root/boot/dtb" df -H -c "$dir_boot" "$dir_root" strings -f "$dir_root/boot/kernel/kernel" | fgrep '@(#)FreeBSD' umount -v "$dir_boot" "$dir_root" gpart show "$dev" "${dev}s${mbrpartid_root}" mdconfig -d -u "$dev" ls -lhaoiG "$img" sha256 "$img" xz -v "$img" sha256 "${img}.xz" ls -lhaoiG "${img}.xz"