Skip to content

Commit 357c4e3

Browse files
Update - scripts fixes/formatting
1 parent 2471002 commit 357c4e3

33 files changed

+346
-330
lines changed

Marlin/src/HAL/shared/backtrace/unwarm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool UnwReportRetAddr(UnwState * const state, uint32_t addr) {
112112
// Check if name descriptor is valid
113113
if ((v & 0xFFFFFF00) == 0xFF000000 && (v & 0xFF) > 1) {
114114
// Assume the name was found!
115-
entry.name = ((const char*)pf) - 4 - (v & 0xFF);
115+
entry.name = reinterpret_cast<const char*>(pf) - 4 - (v & 0xFF);
116116
entry.function = pf;
117117
break;
118118
}
@@ -125,7 +125,7 @@ bool UnwReportRetAddr(UnwState * const state, uint32_t addr) {
125125
/* Cast away const from reportData.
126126
* The const is only to prevent the unw module modifying the data.
127127
*/
128-
return state->cb->report((void *)state->reportData, &entry);
128+
return state->cb->report(const_cast<void *>(state->reportData), &entry);
129129
}
130130

131131
/**

Marlin/src/HAL/shared/backtrace/unwarm_arm.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,14 @@ UnwResult UnwStartArm(UnwState * const state) {
238238

239239
case 1: /* logical right */
240240
if (!regShift && shiftDist == 0) shiftDist = 32;
241-
op2val = state->regData[rm].v >> shiftDist;
241+
if (shiftDist >= 32)
242+
op2val = 0;
243+
else
244+
op2val = state->regData[rm].v >> shiftDist;
242245
break;
243246

244247
case 2: /* arithmetic right */
245248
if (!regShift && shiftDist == 0) shiftDist = 32;
246-
247249
if (state->regData[rm].v & 0x80000000) {
248250
/* Register shifts maybe greater than 32 */
249251
if (shiftDist >= 32)
@@ -256,7 +258,6 @@ UnwResult UnwStartArm(UnwState * const state) {
256258
break;
257259

258260
case 3: /* rotate right */
259-
260261
if (!regShift && shiftDist == 0) {
261262
/* Rotate right with extend.
262263
* This uses the carry bit and so always has an

buildroot/bin/format_code

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,19 @@
55

66
HERE=`dirname $0`
77

8-
while [[ $# -gt 0 ]]; do
9-
8+
while [[ $# -gt 0 ]]
9+
do
1010
val="$1"
1111

1212
if [ -d "$val" ]; then
13-
1413
find $val -name *.cpp -exec "$HERE/uncrust" '{}' \;
15-
1614
elif [ -d "./Marlin/src/$val" ]; then
17-
1815
find "./Marlin/src/$val" -name *.cpp -exec "$HERE/uncrust" '{}' \;
19-
2016
elif [ -f "./Marlin/src/$val" ]; then
21-
2217
uncrust "./Marlin/src/$val"
23-
2418
elif [ -f "$val" ]; then
25-
2619
uncrust "$val"
27-
2820
fi
2921

22+
shift
3023
done

buildroot/bin/mfenvs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
11
#!/usr/bin/env bash
22
#
3-
# mfenvs Print the current board and environment information
4-
# Use -n to remove "*_xfer" environments from the list.
5-
# Output -> "SHORT_NAME (###): [ env1 env2 env3 ... ]"
3+
# mfenvs - Print the current board and environment information
4+
# Use -n to remove "*_xfer" environments from the list.
5+
# Output -> "SHORT_NAME (###): [ env1 env2 env3 ... ]"
66
#
77

8-
[[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }
9-
which pio >/dev/null || { echo "Make sure 'pio' is in your execution PATH." ; exit 1 ; }
10-
8+
# Error helper
119
errout() { echo -e "\033[0;31m$1\033[0m" ; }
1210

11+
# Validate working directory
12+
[[ -d Marlin/src ]] || { errout "Please 'cd' to the Marlin repo root." ; exit 1 ; }
13+
14+
# Dependency check
15+
command -v pio &>/dev/null || { errout "Make sure 'pio' is in your execution PATH." ; exit 1 ; }
16+
17+
# System type
1318
case $(uname | tr '[:upper:]' '[:lower:]') in
19+
win*|msys*|cygwin*|mingw*) SYS='win' ;;
1420
darwin) SYS='mac' ;;
1521
*linux) SYS='lin' ;;
16-
win*) SYS='win' ;;
17-
msys*) SYS='win' ;;
18-
cygwin*) SYS='win' ;;
19-
mingw*) SYS='win' ;;
2022
*) SYS='uni' ;;
2123
esac
2224

23-
ACODE='/^[[:space:]]*#define[[:space:]]MOTHERBOARD[[:space:]]/ { sub(/^BOARD_/, "", $3); print $3 }'
24-
MB=$(awk "$ACODE" Marlin/Configuration.h 2>/dev/null)
25-
[[ -z $MB ]] && MB=$(awk "$ACODE" Marlin/Config.h 2>/dev/null)
26-
[[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
27-
BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
28-
BNUM=$( sed -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
29-
[[ -z $BNUM ]] && { echo "Error - Can't find BOARD_$MB in core/boards.h." ; exit 1 ; }
30-
ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | sed -E "s/(env|$SYS)://" ) )
31-
[[ "$1" = "-n" ]] && ENVS=( $(printf "%s\n" "${ENVS[@]}" | grep -v "_xfer$") )
32-
[[ -z $ENVS ]] && { errout "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
33-
ECOUNT=${#ENVS[*]}
34-
[[ $ECOUNT == 1 ]] && EOUT=$ENVS || EOUT="${ENVS[@]}"
35-
echo "$MB ($BNUM): [ $EOUT ]"
25+
# Extract motherboard
26+
MB=$(grep -E '^[[:space:]]*#define[[:space:]]MOTHERBOARD[[:space:]]' Marlin/Configuration.h 2>/dev/null | awk '{sub(/^BOARD_/, "", $3); print $3}')
27+
[[ -z $MB ]] && MB=$(grep -E '^[[:space:]]*#define[[:space:]]MOTHERBOARD[[:space:]]' Marlin/Config.h 2>/dev/null | awk '{sub(/^BOARD_/, "", $3); print $3}')
28+
[[ -z $MB ]] && { errout "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
29+
30+
# Extract board number
31+
BNUM=$(grep -Eo "\bBOARD_$MB\s+[0-9]+" Marlin/src/core/boards.h | awk '{print $2}')
32+
[[ -z $BNUM ]] && { errout "Error - Can't find BOARD_$MB in core/boards.h." ; exit 1 ; }
33+
34+
# Collect environments
35+
readarray -t ENVS < <(grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | sed -E "s/(env|$SYS)://" | sort -u)
36+
37+
# Optionally filter *_xfer
38+
[[ ${1:-} == "-n" ]] && ENVS=($(printf "%s\n" "${ENVS[@]}" | grep -v "_xfer$"))
39+
40+
[[ ${#ENVS[@]} -eq 0 ]] && { errout "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
41+
42+
echo "$MB ($BNUM): [ ${ENVS[*]} ]"

buildroot/bin/mftest

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/usr/bin/env bash
22
#
3-
# mftest Select a test to apply and build
4-
# mftest -b [#] Build the auto-detected environment
5-
# mftest -u [#] Upload the auto-detected environment
6-
# mftest -tname -n# [-y] Set config options and optionally build a test
3+
# mftest Select a test to apply and build
4+
# mftest -a [#] Build the auto-detected environment
5+
# mftest -u [#] Upload the auto-detected environment
6+
# mftest -tname -n# [-y] Set config options and optionally build a test
77
#
88

9-
[[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; }
10-
11-
which pio >/dev/null || { echo "Make sure 'pio' is in your execution PATH." ; exit 1 ; }
12-
13-
perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; }
9+
# Error helpers
1410
errout() { echo -e "\033[0;31m$1\033[0m" ; }
11+
perror() { errout "$0: $1 -- $2" ; }
1512
bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }
1613

14+
# Ensure we are in root and PlatformIO is available
15+
[[ -d Marlin/src ]] || { errout "Please 'cd' to the Marlin repo root." ; exit 1 ; }
16+
command -v pio &>/dev/null || { errout "Make sure 'pio' is in your PATH." ; exit 1 ; }
17+
1718
usage() {
1819
echo "
1920
Usage: mftest [-a|--autobuild]
@@ -57,12 +58,13 @@ TESTENV='-'
5758
CHOICE=0
5859
DEBUG=0
5960

60-
while getopts 'adhmn:rst:uvy-:' OFLAG; do
61+
while getopts 'acdhmn:rst:uvy-:' OFLAG; do
6162
case "${OFLAG}" in
6263
a) AUTO_BUILD=1 ; bugout "Auto-Build target..." ;;
64+
c) CLEAN_BUILD=1 ; bugout "Clean build..." ;;
6365
d) DL_DEFAULTS=1 ; bugout "Restore to defaults..." ;;
6466
h) EXIT_USAGE=1 ;;
65-
m) USE_MAKE=1 ; bugout "Using make with Docker..." ;;
67+
m) USE_MAKE=1 ; bugout "Using Make with Docker..." ;;
6668
n) case "$OPTARG" in
6769
*[!0-9]*) perror "option requires a number" $OFLAG ; EXIT_USAGE=2 ;;
6870
*) CHOICE="$OPTARG" ; bugout "Got a number: $CHOICE" ;;
@@ -79,14 +81,15 @@ while getopts 'adhmn:rst:uvy-:' OFLAG; do
7981
help) [[ -z "$OVAL" ]] || perror "option can't take value $OVAL" $ONAM ; EXIT_USAGE=1 ;;
8082
autobuild) AUTO_BUILD=1 ; bugout "Auto-Build target..." ;;
8183
autoupload) AUTO_BUILD=2 ; bugout "Auto-Upload target..." ;;
84+
clean) CLEAN_BUILD=1 ; bugout "Clean build..." ;;
8285
env) case "$OVAL" in
8386
'') perror "option requires a value" $ONAM ; EXIT_USAGE=2 ;;
8487
*) TESTENV="$OVAL" ; bugout "Got a target: $TESTENV" ;;
8588
esac
8689
;;
8790
num) case "$OVAL" in
8891
[0-9]+) CHOICE="$OVAL" ; bugout "Got a number: $CHOICE" ;;
89-
*) perror "option requires a value" $ONAM ; EXIT_USAGE=2 ;;
92+
*) perror "option requires a number" $ONAM ; EXIT_USAGE=2 ;;
9093
esac
9194
;;
9295
rebuild) REBUILD=1 ; bugout "Rebuilding previous..." ;;
@@ -101,7 +104,7 @@ debug|verbose) DEBUG=1 ; bugout "Debug ON" ;;
101104
esac
102105
bugout "Build will initiate? ($BUILD_YES)"
103106
;;
104-
*) perror "Unknown flag" "$OPTARG" ; EXIT_USAGE=2 ;;
107+
*) perror "Unknown value" "$OPTARG" ; EXIT_USAGE=2 ;;
105108
esac
106109
;;
107110
*) EXIT_USAGE=2 ;;
@@ -113,11 +116,18 @@ shift $((OPTIND - 1))
113116

114117
if ((REBUILD)); then
115118
bugout "Rebuilding previous..."
116-
# Build with the last-built env
117-
[[ -f "$STATE_FILE" ]] || { errout "No previous (-r) build state found." ; exit 1 ; }
118-
read TESTENV <"$STATE_FILE"
119-
pio run $SILENT_FLAG -d . -e $TESTENV
120-
exit 0
119+
[[ -f $STATE_FILE ]] || { errout "No previous (-r) build state found." ; exit 1 ; }
120+
read -r TESTENV <"$STATE_FILE"
121+
pio run ${SILENT_FLAG:-} -d . -e $TESTENV
122+
exit $? # Exit with the status of pio run
123+
fi
124+
125+
if ((CLEAN_BUILD)); then
126+
bugout "Cleaning build env..."
127+
[[ -f $STATE_FILE ]] || { errout "No previous (-r) build state found." ; exit 1 ; }
128+
read -r TESTENV <"$STATE_FILE"
129+
pio run ${SILENT_FLAG:-} -d . -e $TESTENV -t clean
130+
exit $? # Exit with the status of pio run
121131
fi
122132

123133
case $TESTENV in
@@ -146,9 +156,7 @@ lp9|lpc9) TESTENV='LPC1769' ;;
146156
esac
147157

148158
if ((AUTO_BUILD)); then
149-
#
150159
# List environments that apply to the current MOTHERBOARD.
151-
#
152160
case $(uname | tr '[:upper:]' '[:lower:]') in
153161
darwin) SYS='mac' ;;
154162
*linux) SYS='lin' ;;
@@ -160,17 +168,15 @@ if ((AUTO_BUILD)); then
160168
esac
161169
echo ; echo -n "Auto " ; ((AUTO_BUILD == 2)) && echo "Upload..." || echo "Build..."
162170

163-
#
164171
# Get the MOTHERBOARD define value from the .h file and strip off the "BOARD_" prefix
165-
#
166172
ACODE='/^[[:space:]]*#define[[:space:]]MOTHERBOARD[[:space:]]/ { sub(/^BOARD_/, "", $3); print $3 }'
167173
MB=$(awk "$ACODE" Marlin/Configuration.h 2>/dev/null)
168174
[[ -z $MB ]] && MB=$(awk "$ACODE" Marlin/Config.h 2>/dev/null)
169-
[[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
175+
[[ -z $MB ]] && { errout "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
170176
BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
171177
BNUM=$( sed -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
172178
BDESC=$( sed -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
173-
[[ -z $BNUM ]] && { echo "Error - Can't find BOARD_$MB in core/boards.h." ; exit 1 ; }
179+
[[ -z $BNUM ]] && { errout "Error - Can't find BOARD_$MB in core/boards.h." ; exit 1 ; }
174180
ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+(env|$SYS):[^ ]+" | grep -oE "(env|$SYS):[^ ]+" | sed -E "s/(env|$SYS)://" ) )
175181
# If AUTO_BUILD is not 2 (upload), strip envs ending in '_xfer' from $ENVS
176182
if [[ $AUTO_BUILD != 2 ]]; then
@@ -196,15 +202,15 @@ if ((AUTO_BUILD)); then
196202
for (( ; ; ))
197203
do
198204
read -p "Select a target for '$MB' (1-$ECOUNT) : " CHOICE
199-
[[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
205+
[[ -z "$CHOICE" ]] && { errout '(canceled)' ; exit 1 ; }
200206
[[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= ECOUNT)) && break
201207
errout ">>> Invalid environment choice '$CHOICE'."
202208
done
203209
echo
204210
fi
205211
else
206212
echo "Detected \"$BDESC\" | $MB ($BNUM)."
207-
[[ $CHOICE > $ECOUNT ]] && { echo "Environment selection out of range." ; exit 66 ; }
213+
[[ $CHOICE > $ECOUNT ]] && { errout "Environment selection out of range." ; exit 66 ; }
208214
fi
209215
TARGET="${ENVS[$CHOICE-1]}"
210216
if [[ $MB == 'SIMULATED' && $TARGET == 'linux_native' ]]; then
@@ -225,10 +231,7 @@ if ((AUTO_BUILD)); then
225231
exit $?
226232
fi
227233

228-
#
229234
# List available tests and ask for selection
230-
#
231-
232235
if [[ $TESTENV == '-' ]]; then
233236
IND=0
234237
NAMES=()
@@ -306,14 +309,10 @@ if [[ $CHOICE == 0 ]]; then
306309
fi
307310
fi
308311

309-
#
310-
# Restore to defaults if requested
311-
#
312+
# Restore defaults if requested
312313
((DL_DEFAULTS)) && use_example_configs
313314

314-
#
315315
# Run the specified test lines
316-
#
317316
echo -ne "\033[0;33m"
318317
echo "$OUT" | {
319318
IND=0
@@ -322,20 +321,18 @@ echo "$OUT" | {
322321
while IFS= read -r LINE
323322
do
324323
if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
325-
((!IND)) && let IND++
324+
(( !IND )) && ((IND++))
326325
if [[ $LINE =~ $ISEXEC ]]; then
327326
((IND++ > CHOICE)) && break
328-
else
329-
((!HEADER)) && {
327+
elif ((IND == CHOICE)); then
328+
if ! ((HEADER)); then
330329
HEADER=1
331-
echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
332-
}
333-
((IND == CHOICE)) && {
330+
echo -e "\n#\n# Test $TESTENV ($CHOICE): $DESC\n#"
334331
GOTX=1
335-
[[ -n $DL_DEFAULTS && $LINE =~ $ISRST ]] && LINE="use_example_configs"
336-
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' | sed -E 's/ +/ /g' )
337-
[[ $LINE =~ $ISCONT ]] || { echo "$CMD" ; eval "$CMD" ; CMD="" ; }
338-
}
332+
fi
333+
[[ -n $DL_DEFAULTS && $LINE =~ $ISRST ]] && LINE="use_example_configs"
334+
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | sed -e 's/\\//g' | sed -E 's/ +/ /g' )
335+
[[ $LINE =~ $ISCONT ]] || { echo "$CMD" ; eval "$CMD" ; CMD="" ; }
339336
fi
340337
fi
341338
done
@@ -345,14 +342,14 @@ echo -ne "\033[0m"
345342
# Make clear it's a TEST
346343
opt_set CUSTOM_MACHINE_NAME "\"Test $TESTENV ($CHOICE)\""
347344

348-
# Build the test too?
349-
if [[ -z "$BUILD_YES" ]]; then
345+
# Build if requested
346+
if [[ -z $BUILD_YES ]]; then
350347
echo
351-
read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
348+
read -r -p "Build $TESTENV test #$CHOICE (y/N)? " BUILD_YES
352349
fi
353350

354-
[[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
351+
[[ $BUILD_YES =~ ^(Y|Yes)$ ]] && {
355352
((USE_MAKE)) && make tests-single-local TEST_TARGET=$TESTENV ONLY_TEST=$CHOICE
356-
((USE_MAKE)) || pio run $SILENT_FLAG -d . -e $TESTENV
353+
((USE_MAKE)) || pio run ${SILENT_FLAG:-} -d . -e $TESTENV
357354
echo "$TESTENV" >"$STATE_FILE"
358355
}

buildroot/bin/mfutil

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@
33
# mfutil - check env and define helpers
44
#
55

6+
# Error and debug helpers
7+
perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; }
8+
bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }
9+
610
# Check dependencies
7-
which curl &>/dev/null || { echo "curl not found! Please install it."; exit 1 ; }
8-
which git &>/dev/null || { echo "git not found! Please install it."; exit 1 ; }
9-
which sed &>/dev/null || { echo "sed not found! Please install it."; exit 1 ; }
11+
for cmd in curl git sed; do
12+
if ! command -v "$cmd" &>/dev/null; then
13+
perror "'$cmd' not found!" "Please install it."
14+
exit 1
15+
fi
16+
done
1017

11-
OPEN=$( which gnome-open xdg-open open | head -n1 )
18+
OPEN=$(command -v gnome-open || command -v xdg-open || command -v open)
1219

13-
SELF=`basename "$0"`
20+
SELF=$(basename "$0")
1421

1522
# Check if called in the right location
16-
[[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; }
17-
18-
perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; }
19-
bugout() { ((DEBUG)) && echo -e "\033[0;32m$1\033[0m" ; }
23+
if [[ ! -e "Marlin/src" ]]; then
24+
perror "Incorrect location." "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF \$1"
25+
exit 1
26+
fi

0 commit comments

Comments
 (0)