Browse Source

create_device - Path in parameter

Émile Morel 10 years ago
parent
commit
15cf85fac1
1 changed files with 31 additions and 11 deletions
  1. 31 11
      olinux/create_device.sh

+ 31 - 11
olinux/create_device.sh

@@ -1,6 +1,7 @@
 #!/bin/bash
 
 set -e
+set -x
 
 show_usage() {
 cat <<EOF
@@ -12,16 +13,21 @@ cat <<EOF
 
   -d		device name (img, /dev/sdc, /dev/mmc)	(mandatory)
   -s		size of img in MB		 	(mandatory only for img device option)
+  -t		image name				(default: /olinux/olinux.img)
+  -b		debootstrap directory			(default: /olinux/debootstrap)
+  -u		uboot file				(default: /olinux/sunxi/u-boot/u-boot-sunxi-with-spl.bin)
 
 EOF
 exit 1
 }
 
-DEST=./olinux
+TARGET=/olinux/olinux.img
 MNT=/mnt
 IMAGE=olinux.img
+DEB_DIR=/olinux/deboostrap
+UBOOT_FILE=/olinux/sunxi/u-boot/u-boot-sunxi-with-spl.bin
 
-while getopts "s:d:" opt; do
+while getopts ":s:d:t:b:u:" opt; do
   case $opt in
     d)
       DEVICE=$OPTARG
@@ -29,6 +35,15 @@ while getopts "s:d:" opt; do
     s)
       IMGSIZE=$OPTARG
       ;;
+    t)
+      TARGET=$OPTARG
+      ;;
+    b)
+      DEB_DIR=$OPTARG
+      ;;
+    u)
+      UBOOT_FILE=$OPTARG
+      ;;
     \?)
       show_usage
       ;;
@@ -45,9 +60,9 @@ fi
 
 if [ "${DEVICE}" == "img" ] ; then
   echo "- Create image."
-  rm -f olinux/$IMAGE
+  rm -f ${TARGET}
   # create image file
-  dd if=/dev/zero of=olinux/$IMAGE bs=1MB count=$IMGSIZE status=noxfer >/dev/null 2>&1
+  dd if=/dev/zero of=${TARGET} bs=1MB count=$IMGSIZE status=noxfer >/dev/null 2>&1
   
   # find first avaliable free device
   DEVICE=$(losetup -f)
@@ -55,7 +70,7 @@ if [ "${DEVICE}" == "img" ] ; then
   TYPE="loop"
   
   # mount image as block device
-  losetup $DEVICE $DEST/$IMAGE >/dev/null 2>&1
+  losetup $DEVICE ${TARGET}
   
   sync
 
@@ -67,9 +82,9 @@ fi
 
 # create one partition starting at 2048 which is default
 echo "- Partitioning"
-parted --script -a optimal $DEVICE unit GB mklabel msdos 
-parted --script -a optimal $DEVICE unit GB mkpart primary ext4 2048s ${IMGSIZE}
-parted --script -a optimal $DEVICE unit GB align-check optimal 1
+parted --script $DEVICE mklabel msdos 
+parted --script $DEVICE mkpart primary ext4 2048s ${IMGSIZE}
+parted --script $DEVICE align-check optimal 1
 
 if [ "${TYPE}" == "loop" ] ; then
   DEVICEP1=${DEVICE}p1
@@ -89,12 +104,17 @@ echo "- Mount filesystem"
 mount -t ext4 $DEVICEP1 $MNT
 
 echo "- Copy bootstrap files"
-# copy debootstrap
-cp -ar olinux/debootstrap/* $MNT/
+if [ -d ${DEB_DIR} ] ; then
+  cp -ar ${DEB_DIR}/* $MNT/
+else
+  # Assume that is a tarball file
+  tar xvf ${DEB_DIR} -C $MNT/ .
+fi
 sync
 
 echo "- Write sunxi-with-spl"
-dd if=olinux/sunxi/u-boot/u-boot-sunxi-with-spl.bin of=${DEVICE} bs=1024 seek=8 >/dev/null 2>&1
+dd if=${UBOOT_FILE} of=${DEVICE} bs=1024 seek=8 >/dev/null 2>&1
+sync
 
 echo "- Umount"
 if [ "${TYPE}" == "loop" ] ; then