Skip to content

Commit 6b16d19

Browse files
committed
fix: apply ShellCheck and shfmt
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 1bce38f commit 6b16d19

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

run_arduino_gen.sh

+26-26
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ELF_BINARY=""
2020

2121
autodetect_board() {
2222
if [ ! -d /proc/device-tree/ ]; then
23-
echo "Proc Device tree are not available, Could not detect on which board we are" > /dev/kmsg
23+
echo "Proc Device tree are not available, Could not detect on which board we are" >/dev/kmsg
2424
exit 1
2525
fi
2626

@@ -34,10 +34,10 @@ autodetect_board() {
3434
elif grep -q "stm32mp157" /proc/device-tree/compatible; then
3535
BOARD="STM32MP157_GENERIC"
3636
else
37-
echo "Board is not an STM32MP157 BOARD" > /dev/kmsg
37+
echo "Board is not an STM32MP157 BOARD" >/dev/kmsg
3838
exit 1
3939
fi
40-
echo "Board is $BOARD" > /dev/kmsg
40+
echo "Board is $BOARD" >/dev/kmsg
4141
}
4242

4343
firmware_load() {
@@ -46,42 +46,42 @@ firmware_load() {
4646
exit 1
4747
fi
4848

49-
if (echo "$ELF_HASH $ELF_INSTALL_PATH" | sha256sum --status -c - 2> /dev/null); then
49+
if (echo "$ELF_HASH $ELF_INSTALL_PATH" | sha256sum --status -c - 2>/dev/null); then
5050
# The same firmware already exists, skip this step
5151
echo "The same firmware is already installed. Starting..."
5252
return 0
5353
fi
5454

5555
# Decode base64-encoded binary to a temp directory and check hash
5656
tmp_elf_file="/tmp/$ELF_NAME"
57-
if which uudecode > /dev/null 2>&1; then
58-
printf "%s" "$ELF_BINARY" | uudecode -o /dev/stdout | gzip -d > "$tmp_elf_file"
57+
if which uudecode >/dev/null 2>&1; then
58+
printf "%s" "$ELF_BINARY" | uudecode -o /dev/stdout | gzip -d >"$tmp_elf_file"
5959
else
60-
printf "%s" "$ELF_BINARY" | tail -n +2 | base64 -d - 2> /dev/null | gzip -d > "$tmp_elf_file"
60+
printf "%s" "$ELF_BINARY" | tail -n +2 | base64 -d - 2>/dev/null | gzip -d >"$tmp_elf_file"
6161
fi
6262
echo "$ELF_HASH $tmp_elf_file" | sha256sum --status -c -
6363

6464
# Copy elf into /lib/firmware
6565
mv $tmp_elf_file $ELF_INSTALL_PATH
66-
echo "Arduino: Executable created: $ELF_INSTALL_PATH" > /dev/kmsg
66+
echo "Arduino: Executable created: $ELF_INSTALL_PATH" >/dev/kmsg
6767
}
6868

6969
firmware_start() {
7070
# Change the name of the firmware
71-
printf arduino.ino.elf > $REMOTEPROC_DIR/firmware
71+
printf arduino.ino.elf >$REMOTEPROC_DIR/firmware
7272

7373
# Change path to found firmware
7474
#printf /home/root >/sys/module/firmware_class/parameters/path
7575

7676
# Restart firmware
77-
echo "Arduino: Starting $ELF_INSTALL_PATH" > /dev/kmsg
78-
echo start > $REMOTEPROC_DIR/state 2> /dev/null || true
77+
echo "Arduino: Starting $ELF_INSTALL_PATH" >/dev/kmsg
78+
echo start >$REMOTEPROC_DIR/state 2>/dev/null || true
7979
}
8080

8181
firmware_stop() {
8282
# Stop the firmware
83-
echo "Arduino: Stopping $ELF_INSTALL_PATH" > /dev/kmsg
84-
echo stop > $REMOTEPROC_DIR/state 2> /dev/null || true
83+
echo "Arduino: Stopping $ELF_INSTALL_PATH" >/dev/kmsg
84+
echo stop >$REMOTEPROC_DIR/state 2>/dev/null || true
8585
}
8686

8787
generate_packaged_script() {
@@ -96,25 +96,25 @@ generate_packaged_script() {
9696
# Generate a copy of this script with a self-contained elf binary and its hash
9797
# The elf binary is gzip'ed, making its size to 1/6, and then Base64-encoded
9898
# using uuencode.
99-
head -n "$(grep -n "{%" "$this_script" | cut -d: -f1 | head -n 1)" "$this_script" > "$output_script"
100-
echo "ELF_HASH='$(sha256sum "$elf_path" | cut -d' ' -f1)'" >> "$output_script"
101-
printf "ELF_BINARY='" >> "$output_script"
102-
if which uuencode > /dev/null 2>&1; then
103-
gzip -c "$elf_path" | uuencode -m $ELF_NAME >> "$output_script"
99+
head -n "$(grep -n "{%" "$this_script" | cut -d: -f1 | head -n 1)" "$this_script" >"$output_script"
100+
echo "ELF_HASH='$(sha256sum "$elf_path" | cut -d' ' -f1)'" >>"$output_script"
101+
printf "ELF_BINARY='" >>"$output_script"
102+
if which uuencode >/dev/null 2>&1; then
103+
gzip -c "$elf_path" | uuencode -m $ELF_NAME >>"$output_script"
104104
else
105-
echo "begin-base64 644 $ELF_NAME" >> "$output_script"
106-
gzip -c "$elf_path" | base64 >> "$output_script"
105+
echo "begin-base64 644 $ELF_NAME" >>"$output_script"
106+
gzip -c "$elf_path" | base64 >>"$output_script"
107107
fi
108-
echo "'" >> "$output_script"
109-
tail -n +"$(grep -n "%}" "$this_script" | cut -d: -f1 | head -n 1)" "$this_script" >> "$output_script"
110-
dos2unix "$output_script" 2> /dev/null
108+
echo "'" >>"$output_script"
109+
tail -n +"$(grep -n "%}" "$this_script" | cut -d: -f1 | head -n 1)" "$this_script" >>"$output_script"
110+
dos2unix "$output_script" 2>/dev/null
111111
}
112112

113113
systemd_install() {
114114
mkdir -p "$(dirname $INSTALL_PATH)"
115115
cp "$0" "$INSTALL_PATH"
116116
echo "File created: $INSTALL_PATH"
117-
cat > "$SYSTEMD_SERVICE_PATH" << EOF
117+
cat >"$SYSTEMD_SERVICE_PATH" <<EOF
118118
[Unit]
119119
Description=Run Arduino firmware via remoteproc
120120
After=systemd-modules-load.service
@@ -161,7 +161,7 @@ try_send() {
161161
# Linux host must send any dummy data first to finish initialization of rpmsg
162162
# on the coprocessor side. This message should be discarded.
163163
# See: https://github.com/OpenAMP/open-amp/issues/182
164-
printf "DUMMY" > $RPMSG_DIR
164+
printf "DUMMY" >$RPMSG_DIR
165165
echo "Virtual serial $RPMSG_DIR connection established."
166166
}
167167

@@ -203,7 +203,7 @@ case "$1" in
203203
;;
204204
send-msg)
205205
autodetect_board
206-
echo "${@:2}" > $RPMSG_DIR
206+
echo "${@}" | cut -c 3- >$RPMSG_DIR
207207
;;
208208
send-file)
209209
autodetect_board

0 commit comments

Comments
 (0)