aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md25
-rwxr-xr-xscripts/disk_image90
-rw-r--r--scripts/imagebuilder_sd2
3 files changed, 109 insertions, 8 deletions
diff --git a/README.md b/README.md
index 3e7f39f..98da5e8 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,31 @@ Where:\
arbitrary command can be used, for instance -t "fatload" is valid.\
+## Stand-alone Usage: scripts/disk\_image
+
+The ImageBuilder script that generates a disk image file to load on a
+SD or SATA drive. This creates 2 partitions: boot partition where the
+boot files from working directory (-c option) are, and the dom0 ramdisk
+uncompressed into the root FS partition.
+
+After you've generated the u-boot scripts using the uboot-script-gen
+script, disk_image is run as follows:
+
+```
+$ sudo bash ./scripts/disk_image -c /path/to/config-file -d . \
+ -w /path/to/tmp/dir \
+ -o /path/to/output/disk.img
+```
+
+Where:\
+-c specifies the path to the config file to use\
+-d specifies the working directory (paths in the config file are relative
+ to it)\
+-w specifies the temporary working directory that the script uses for
+ building the disk image, and if not set, one is created in /tmp\
+-o specifies the output disk image file name\
+
+
## Container Usage
ImageBuilder comes with a Dockerfile to build a container with all the
diff --git a/scripts/disk_image b/scripts/disk_image
index 949e323..88a1663 100755
--- a/scripts/disk_image
+++ b/scripts/disk_image
@@ -3,18 +3,89 @@
# This helps to see what is going on
set -e -x
-# Used to maintain intermediary state. (Not currently used)
-DESTDIR="$(mktemp -d /tmp/imagebuilder-zynqmp.XXXXXX)"
-UBOOT_OUT="/tmp/output"
-OUTDIR="/tmp/img"
-mkdir ${OUTDIR}
+PROG_REQ=( kpartx mkfs.ext4 losetup sgdisk readlink )
+
+function check_depends()
+{
+ for ((i=0; i<${#PROG_REQ[@]}; i++))
+ do
+ if ! command -v ${PROG_REQ[i]} > /dev/null
+ then
+ echo "Please install the needed program: ${PROG_REQ[i]}."
+ exit 1
+ fi
+ done
+}
+
+function print_help
+{
+ echo "usage:"
+ echo " $0 -c CONFIG_FILE -d UBOOT_DIRECTORY <-w WORK_DIRECTORY> -o IMG_FILE"
+ echo " $0 -h"
+ echo "where:"
+ echo " -c CONFIG_FILE - configuration file"
+ echo " -d UBOOT_DIRECTORY - root directory for the paths specified in CONFIG_FILE"
+ echo " -w WORK_DIRECTORY - work directory used when building the image"
+ echo " -o IMG_FILE - the output img file "
+ echo "Example:"
+ echo " $0 -c ../config -d ./build42 -w tmp -o disk.img"
+}
+
+# before anything else, check if we have root privilege
+if ! [ $(id -u) = 0 ]
+then
+ echo "This script needs root privilege to run, exiting."
+ exit 1
+fi
-IMG="${OUTDIR}/zynqmp.img"
+while getopts ":w:d:c:o:h" opt
+do
+ case ${opt} in
+ w )
+ DESTDIR=$OPTARG
+ ;;
+ d )
+ UBOOT_OUT=$OPTARG
+ ;;
+ c )
+ CFG_FILE=$OPTARG
+ ;;
+ o )
+ IMG=$OPTARG
+ ;;
+ h )
+ print_help
+ exit 0
+ ;;
+ * )
+ echo "Unknown option, see \"$0 -h\""
+ exit 1
+ ;;
+ esac
+done
+shift $((OPTIND -1))
+
+if [ -z "$UBOOT_OUT" ] || [ -z "$CFG_FILE" ] || [ -z "$IMG" ]
+then
+ echo "Undefined arguments, see \"$0 -h\""
+ exit 1
+fi
-. config
+# if the user hasn't specified a working directing, create it
+if [ -z "$DESTDIR" ]
+then
+ DESTDIR="$(mktemp -d /tmp/imagebuilder.XXXXXX)"
+ DESTDIR_DEL=true
+else
+ DESTDIR_DEL=false
+fi
UBOOT_OUT_ABS="$(readlink -f $UBOOT_OUT)"
+check_depends
+
+source "$CFG_FILE"
+
offset=$((2*1024*1024))
_part1_size=`stat --printf="%s" $UBOOT_OUT/$XEN`
_part1_size=$(( $_part1_size + `stat --printf="%s" $UBOOT_OUT/$DOM0_KERNEL` ))
@@ -155,3 +226,8 @@ umount $DESTDIR/part/disk1
kpartx -d /dev/mapper/diskimage
dmsetup remove diskimage
losetup -d $_loop_dev
+
+if [ "$DESTDIR_DEL" = true ]
+then
+ rm -rf "$DESTDIR"
+fi
diff --git a/scripts/imagebuilder_sd b/scripts/imagebuilder_sd
index 460746e..13a28e4 100644
--- a/scripts/imagebuilder_sd
+++ b/scripts/imagebuilder_sd
@@ -6,4 +6,4 @@ cp config /tmp/output
cp -r /home/builder/output/* /tmp/output
cd /tmp/output
bash /uboot-script-gen -c ./config -d ./ -t sd
-bash /disk_image
+bash /disk_image -c ./config -d ./ -o /tmp/disk.img