From 992f67709cdaba787d57530c613eb41d5bfe219a Mon Sep 17 00:00:00 2001
From: Bunnaroath Sou <bsou@sifive.com>
Date: Wed, 30 Jan 2019 14:42:47 -0800
Subject: Update to generate bsp at a custom location

---
 bsp/update-targets.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 56 insertions(+), 3 deletions(-)

diff --git a/bsp/update-targets.sh b/bsp/update-targets.sh
index 780d662..fc1b76c 100755
--- a/bsp/update-targets.sh
+++ b/bsp/update-targets.sh
@@ -1,5 +1,60 @@
 #!/usr/bin/env sh
 
+help() {
+    cat >&2 <<EOF
+$0: BSP Generator for the SiFive Freedom E SDK
+    --help                     Prints this help text.
+    --target-name              Specify bsp target name.
+    --sdk-path=*               The path to the freedom-e-sdk clone directory, public or private.
+    --target-dts=*.dts         The path to the target device tree that will be used.
+    --ipdelivery-tgz=*.tar.gz  The path to the ipdelivery that will be used.
+EOF
+}
+
+unset DTSFILE
+unset CUSTOM_PATH
+unset CUSTOM_NAME
+while [[ "$1" != "" ]]
+do
+    case "$1" in
+    --help)               help "$0";                                 exit 0;;
+    --target-name)        CUSTOM_NAME="$2";                          shift 2;;
+    --sdk-path=*)         CUSTOM_PATH="$(echo "$1" | cut -d= -f2-)"; shift 1;;
+    --sdk-path)           CUSTOM_PATH="$2";                          shift 2;;
+    --target-dts=*)       DTSFILE="$(echo "$1" | cut -d= -f2-)";     shift 1;;
+    --target-dts)         DTSFILE="$2";                              shift 2;;
+    *) echo "$0: Unknown argument $1" >&2;                        exit 1;;
+    esac
+done
+
+if [[ "$CUSTOM_PATH" == "" && "$CUSTOM_NAME" == "" && "$DTSFILE" == "" ]]
+then
+    TARGET_LIST="$(ls -d coreip*) "
+    TARGET_LIST+="sifive-hifive1 freedom-e310-arty "
+else
+    if [[ ! -f "$DTSFILE" &&  "$DTSFILE" != "*.dts" ]]
+    then
+        echo "[ERROR] $0: $DTSFILE must be a dts file" >&2
+        help "$0"
+        exit 1
+    fi
+    if [[ "$CUSTOM_NAME" == "" ]]
+    then
+        echo "[ERROR] $0: --target-name is mandatory" >&2
+        help "$0"
+        exit 1
+    fi
+    CUSTOM_TARGET="$CUSTOM_PATH/bsp/$CUSTOM_NAME"
+    if [[ ! -d "$CUSTOM_TARGET" ]]
+    then
+        echo "[ERROR] $0: "$CUSTOM_TARGET" not found!" >&2
+        help "$0"
+        exit 1
+    fi
+    cp $DTSFILE $CUSTOM_TARGET
+    TARGET_LIST="$CUSTOM_TARGET "
+fi
+
 DTC=dtc
 MEE_HEADER_GENERATOR=freedom-mee_header-generator
 LDSCRIPT_GENERATOR=freedom-ldscript-generator
@@ -9,9 +64,6 @@ DTB_FILENAME=temp.dtb
 HEADER_FILENAME=mee.h
 LDSCRIPT_FILENAME=mee.lds
 
-TARGET_LIST="$(ls -d coreip*) "
-TARGET_LIST+="sifive-hifive1 freedom-e310-arty "
-
 update_target() {
     TARGET=$1
 
@@ -30,6 +82,7 @@ update_target() {
     echo ""
 }
 
+echo $PWD
 for TARGET in $TARGET_LIST
 do
     update_target $TARGET
-- 
cgit v1.2.3