The commit a9b2e6089d82686564220013f14e9f0ffcc725e2 allowed generating
everything needed in one step. This was however a bit too ambitious.
The script now requires that the Altera Embedded SDK is always
installed. There are situations where this is unwanted.

Beef up the code a little bit to allow having the SDK as an optional
argument and make the other input parameters location independent.

Signed-off-by: Steffen Trumtrar <s.trumt...@pengutronix.de>
---
 Documentation/boards/socfpga.rst |  2 +-
 scripts/socfpga_import_preloader | 88 ++++++++++++++++++++++++++++----
 2 files changed, 78 insertions(+), 12 deletions(-)

diff --git a/Documentation/boards/socfpga.rst b/Documentation/boards/socfpga.rst
index 19d606030003..7e7f0619ea01 100644
--- a/Documentation/boards/socfpga.rst
+++ b/Documentation/boards/socfpga.rst
@@ -121,7 +121,7 @@ Now run the command:
 
 .. code-block:: sh
 
-  scripts/socfpga_import_preloader <EMBEDDED_SDK> <ISW_HANDOFF> 
<BOARD_DIRECTORY>
+  scripts/socfpga_import_preloader -e <EMBEDDED_SDK> -i <ISW_HANDOFF> -b 
<BOARD_DIRECTORY>
 
 where `<SPL_GENERATED_DIR>` is the directory where the bsp-editor generated 
the files,
 `<ISW_HANDOFF>` is the directory where Quartus generated the handoff files, and
diff --git a/scripts/socfpga_import_preloader b/scripts/socfpga_import_preloader
index 23e3c380db12..2bec9f2d2173 100755
--- a/scripts/socfpga_import_preloader
+++ b/scripts/socfpga_import_preloader
@@ -1,16 +1,70 @@
 #!/usr/bin/env bash
 
-if [ "$#" -lt "2" ]
-then
-       echo "USAGE: $0 <EMBEDDED_SDK> <ISW_HANDOFF> <BOARD_DIRECTORY>"
-       echo "EXAMPLE: $0 ~/altera-embedded-sdk/ 
~/cv_soc_devkit_ghrd/hps_isw_handoff/soc_system_hps_0/ 
arch/arm/boards/altera-socdk"
+usage() {
+       echo "USAGE: $0
+       parameters:
+         -s|--spl-dir <SPL_GENERATED_DIR>
+         -i|--isw-handoff <ISW_HANDOFF>
+         -b|--board <BOARD_DIRECTORY>
+       optional:
+         -e|--embedded-sdk <ALTERA_EMBEDDED_SDK>"
+       echo "EXAMPLE: $0 -i 
~/cv_soc_devkit_ghrd/hps_isw_handoff/soc_system_hps_0/ -b 
arch/arm/boards/altera-socdk -e ~/altera-embedded-sdk/" 
        exit 1
-fi
+}
+
+die() {
+       printf '%s\n' "$1" >&2
+       exit 1
+}
+
+generate=
+splroot=
+embeddedsw=
+handoff=
+boardroot=
+
+while :; do
+       case $1 in
+       -e|--embedded-sdk)
+               if [ "$2" ]; then
+                       generate=1
+                       splroot="$(mktemp -d)"
+                       embeddedsw=${2}
+                       shift
+               else
+                       die 'ERROR: "--embedded-sdk" requires a non-empty 
option argument.'
+               fi
+               ;;
+       -s|--spl-dir)
+               if [ "$2" ]; then
+                       splroot="$2"
+                       shift
+               else
+                       die 'ERROR: "--spl-dir" requires a non-empty option 
argument.'
+               fi
+               ;;
+       -i|--isw-handoff)
+               if [ "$2" ]; then
+                       handoff="$2"
+                       shift
+               else
+                       die 'ERROR: "--isw-handoff" requires a non-empty option 
argument.'
+               fi
+               ;;
+       -b|--board)
+               if [ "$2" ]; then
+                       boardroot="$2"
+                       shift
+               else
+                       die 'ERROR: "--board" requires a non-empty option 
argument.'
+               fi
+               ;;
+       *)
+               break
+       esac
+       shift
+done
 
-splroot="$(mktemp -d)"
-embeddedsw=$1
-handoff=$2
-boardroot=$3
 bareboxsrc=.
 
 cd ${bareboxsrc}
@@ -57,7 +111,17 @@ copy_source() {
        sed -i 's/ $//g' $tgt
 }
 
-python2.7 ${embeddedsw}/embedded/ip/altera/preloader/scripts/iswgen.py -i 
${handoff} -o ${splroot}/
+generate_spl() {
+       python2.7 ${embeddedsw}/embedded/ip/altera/preloader/scripts/iswgen.py 
-i ${handoff} -o ${splroot}/
+}
+
+if [ -z $splroot ] || [ -z $boardroot ] || [ -z $handoff ]; then
+       usage
+fi
+
+if [ $generate ]; then
+       generate_spl
+fi
 
 copy_source ${splroot}/iocsr_config_cyclone5.c 
${boardroot}/iocsr_config_cyclone5.c
 copy_source ${splroot}/pinmux_config_cyclone5.c ${boardroot}/pinmux_config.c
@@ -69,6 +133,8 @@ copy_source ${handoff}/sequencer_auto_ac_init.c 
${boardroot}/sequencer_auto_ac_i
 copy_source ${handoff}/sequencer_auto_inst_init.c 
${boardroot}/sequencer_auto_inst_init.c
 copy_source ${handoff}/sequencer_defines.h ${boardroot}/sequencer_defines.h
 
-rm -r ${splroot}
+if [ $generate ]; then
+       rm -r ${splroot}
+fi
 
 echo "DONE"
-- 
2.29.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to