ar71xx: cap324: Use standard eth as static lan
[openwrt/openwrt.git] / scripts / ubinize-image.sh
index 1058aba812699cb1ef243bea03056e4161b3617a..09a00b1898cec141bf99a776eb26697d29fec864 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
+part=""
 ubootenv=""
-nokernel=""
 ubinize_param=""
 kernel=""
 rootfs=""
@@ -23,6 +23,7 @@ ubivol() {
        name=$2
        image=$3
        autoresize=$4
+       size="$5"
        echo "[$name]"
        echo "mode=ubi"
        echo "vol_id=$volid"
@@ -30,6 +31,7 @@ ubivol() {
        echo "vol_name=$name"
        if [ "$image" ]; then
                echo "image=$image"
+               [ -n "$size" ] && echo "vol_size=${size}MiB"
        else
                echo "vol_size=1MiB"
        fi
@@ -47,6 +49,22 @@ ubilayout() {
                ubivol $vol_id ubootenv2
                vol_id=$(( $vol_id + 1 ))
        fi
+       for part in $parts; do
+               name="${part%%=*}"
+               prev="$part"
+               part="${part#*=}"
+               [ "$prev" = "$part" ] && part=
+
+               image="${part%%=*}"
+               prev="$part"
+               part="${part#*=}"
+               [ "$prev" = "$part" ] && part=
+
+               size="$part"
+
+               ubivol $vol_id "$name" "$image" "" "$size"
+               vol_id=$(( $vol_id + 1 ))
+       done
        if [ "$3" ]; then
                ubivol $vol_id kernel "$3"
                vol_id=$(( $vol_id + 1 ))
@@ -57,40 +75,45 @@ ubilayout() {
 }
 
 while [ "$1" ]; do
-       if [ "$1" = "--uboot-env" ]; then
+       case "$1" in
+       "--uboot-env")
                ubootenv="ubootenv"
                shift
                continue
-       fi
-       if [ "$1" = "--no-kernel" ]; then
-               nokernel="nokernel"
+               ;;
+       "--kernel")
+               kernel="$2"
                shift
-               continue
-       fi
-       if [ ! "$kernel" -a ! "$nokernel" ]; then
-               [ "${1:0:1}" = "-" ] && break
-               kernel=$1
                shift
                continue
-       fi
-       if [ ! "$rootfs" ]; then
-               [ "${1:0:1}" = "-" ] && break
-               rootfs=$1
+               ;;
+       "--part")
+               parts="$parts $2"
                shift
-               continue
-       fi
-       if [ ! "$outfile" ]; then
-               [ "${1:0:1}" = "-" ] && break
-               outfile=$1
                shift
                continue
-       fi
-       ubinize_param="$@"
-       break
+               ;;
+       "-"*)
+               ubinize_param="$@"
+               break
+               ;;
+       *)
+               if [ ! "$rootfs" ]; then
+                       rootfs=$1
+                       shift
+                       continue
+               fi
+               if [ ! "$outfile" ]; then
+                       outfile=$1
+                       shift
+                       continue
+               fi
+               ;;
+       esac
 done
 
-if [ ! -r "$rootfs" -o ! -r "$kernel" -a ! "$nokernel" -o ! "$outfile" ]; then
-       echo "syntax: $0 [--no-kernel] [--uboot-env] rootfs [kernel] out [ubinize opts]"
+if [ ! -r "$rootfs" -o ! -r "$kernel" -a ! "$outfile" ]; then
+       echo "syntax: $0 [--uboot-env] [--part <name>=<file>] [--kernel kernelimage] rootfs out [ubinize opts]"
        exit 1
 fi
 
@@ -100,7 +123,11 @@ if [ ! -x "$ubinize" ]; then
        exit 1
 fi
 
-ubinizecfg="$( mktemp )"
+ubinizecfg="$( mktemp 2> /dev/null )"
+if [ -z "$ubinizecfg" ]; then
+       # try OSX signature
+       ubinizecfg="$( mktemp -t 'ubitmp' )"
+fi
 ubilayout "$ubootenv" "$rootfs" "$kernel" > "$ubinizecfg"
 
 cat "$ubinizecfg"
@@ -110,4 +137,3 @@ err="$?"
 rm "$ubinizecfg"
 
 exit $err
-