Skip to content

Commit 4cabc3d

Browse files
committed
tighten up bringup_mmc script
1 parent 686a89b commit 4cabc3d

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

bringup_mmc.sh

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# Environment Config:
44
# Mandatory Environment Variables:
5-
# MMC_PATH=/path/to/marble_mmc
65
# LTM_SCRIPT=/path/to/LTM4673_reglist.txt
76
# Optional Environment Variables:
87
# TTY_MMC=/dev/ttyUSB3
@@ -20,25 +19,22 @@
2019
# Turn on exit on failure
2120
set -e
2221

22+
fail() {
23+
echo "Error: $1" >&2
24+
exit 1
25+
}
26+
27+
# Find directory containing this script (regardless of PWD)
28+
MMC_PATH="$(dirname "$(readlink -f "$0")")"
29+
2330
if [ $# -lt 0 ]; then
2431
echo "Usage: bringup_mmc.sh"
2532
exit 2
2633
fi
2734

2835
# Mandatory Paths Check.
29-
paths_complete=1
30-
if [ -z "$MMC_PATH" ]; then
31-
echo "Define MMC_PATH environment variable"
32-
paths_complete=0
33-
fi
34-
3536
if [ -z "$LTM_SCRIPT" ]; then
36-
echo "Define register list for LTM4673"
37-
paths_complete=0
38-
fi
39-
40-
if [ "$paths_complete" -eq 0 ]; then
41-
exit 1
37+
fail "Must set LTM_SCRIPT= to define register list for LTM4673"
4238
fi
4339

4440
# Optional Environment Variables Check.
@@ -51,13 +47,11 @@ SCRIPTS_PATH=$MMC_PATH/scripts
5147

5248
# Test for exist
5349
if [ ! -e "$MMC_PATH" ]; then
54-
echo "$MMC_PATH does not exist"
55-
exit 1
50+
fail "MMC_PATH=$MMC_PATH does not exist"
5651
fi
5752

5853
if [ ! -d "$MMC_PATH" ]; then
59-
echo "$MMC_PATH is not a directory"
60-
exit 1
54+
fail "MMC_PATH=$MMC_PATH is not a directory"
6155
fi
6256

6357
#### Marble Bringup Steps ####
@@ -66,8 +60,7 @@ fi
6660
echo "Programming MMC...."
6761
cd "$MMC_PATH"
6862
if ! make marble_download; then
69-
echo "Could not program marble_mmc. Is Segger J-Link attached? Is board powered?"
70-
exit 1
63+
fail "Could not program marble_mmc. Is Segger J-Link attached? Is board powered?"
7164
else
7265
echo "Successfully programmed MMC!"
7366
fi
@@ -80,8 +73,7 @@ sleep 5
8073
# 2. Program LTM4673 power management chip
8174
echo "Programming LTM4673 power management chip...."
8275
if ! python3 "$SCRIPTS_PATH"/ltm4673.py -d "$TTY_MMC" write -f "$LTM_SCRIPT"; then
83-
echo "Could not program LTM4673."
84-
exit 1
76+
fail "Could not program LTM4673."
8577
else
8678
echo "##################################"
8779
python3 "$SCRIPTS_PATH"/ltm4673.py -d "$TTY_MMC" store

0 commit comments

Comments
 (0)