-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.zsh
executable file
·70 lines (57 loc) · 1.78 KB
/
build.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/zsh
# Build the thing
cargo build
if [ $? -eq 0 ]; then
echo "Build succeeded, flashing the binary to the board..."
else
echo "Build failed, please check the errors and try again."
exit 1
fi
# Get the current directory
current_dir=$(pwd)
# Read the Cargo.toml file
cargo_toml="$current_dir/Cargo.toml"
if [[ ! -f "$cargo_toml" ]]; then
echo "Failed to find Cargo.toml"
exit 1
fi
cargo_toml_content=$(cat "$cargo_toml")
# Extract the package name from Cargo.toml
package_name=$(echo "$cargo_toml_content" | grep '^name =' | sed 's/name = "\(.*\)"/\1/')
if [[ -z "$package_name" ]]; then
echo "Failed to find package name in Cargo.toml"
exit 1
fi
# Construct the path to the build binary
build_path="$current_dir/target/thumbv6m-none-eabi/debug/$package_name"
# Update the .vscode/settings.json custom.debug.binaryPath variable to the build path
settings_file="$current_dir/.vscode/settings.json"
if [[ ! -f "$settings_file" ]]; then
echo "Failed to find .vscode/settings.json"
exit 1
fi
# Use jq to update the settings file
jq --arg build_path "$build_path" '.["custom.debug.binaryPath"] = $build_path' "$settings_file" > "${settings_file}.tmp" && mv "${settings_file}.tmp" "$settings_file"
if [ $? -eq 0 ]; then
echo "Updated custom.debug.binaryPath to $build_path"
else
echo "Failed to update custom.debug.binaryPath"
exit 1
fi
# Define the openocd command and arguments
openocd_command="sudo"
openocd_args=(
"openocd"
"-s" "tcl"
"-f" "interface/cmsis-dap.cfg"
"-f" "target/rp2040.cfg"
"-c" "adapter speed 5000"
"-c" "program $build_path verify reset exit"
)
# Execute the openocd command
$openocd_command "${openocd_args[@]}"
status=$?
if [[ $status -ne 0 ]]; then
echo "openocd command failed with status: $status"
exit 1
fi