aboutsummaryrefslogtreecommitdiff
path: root/util/chibios_conf_updater.sh
diff options
context:
space:
mode:
Diffstat (limited to 'util/chibios_conf_updater.sh')
-rwxr-xr-xutil/chibios_conf_updater.sh101
1 files changed, 11 insertions, 90 deletions
diff --git a/util/chibios_conf_updater.sh b/util/chibios_conf_updater.sh
index d1640b672..a5699ca3c 100755
--- a/util/chibios_conf_updater.sh
+++ b/util/chibios_conf_updater.sh
@@ -3,6 +3,17 @@
3set -eEuo pipefail 3set -eEuo pipefail
4umask 022 4umask 022
5 5
6#####################
7# You will need to get an older JDK -- JDK 8
8#
9# !!!!!!!! DO NOT INSTALL THIS IF YOU HAVE AN EXISTING JDK OR JRE INSTALLED !!!!!!!!
10#
11# For Debian 10-ish distro's:
12# wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
13# sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
14# sudo apt-get update && sudo apt-get install adoptopenjdk-8-hotspot
15
16
6sinfo() { echo "$@" >&2 ; } 17sinfo() { echo "$@" >&2 ; }
7shead() { sinfo "" ; sinfo "---------------------------------" ; sinfo "-- $@" ; sinfo "---------------------------------" ; } 18shead() { sinfo "" ; sinfo "---------------------------------" ; sinfo "-- $@" ; sinfo "---------------------------------" ; }
8havecmd() { command command type "${1}" >/dev/null 2>&1 || return 1 ; } 19havecmd() { command command type "${1}" >/dev/null 2>&1 || return 1 ; }
@@ -11,8 +22,6 @@ this_script="$(realpath "${BASH_SOURCE[0]}")"
11script_dir="$(realpath "$(dirname "$this_script")")" 22script_dir="$(realpath "$(dirname "$this_script")")"
12qmk_firmware_dir="$(realpath "$script_dir/../")" 23qmk_firmware_dir="$(realpath "$script_dir/../")"
13 24
14declare -A file_hashes
15
16export PATH="$PATH:$script_dir/fmpp/bin" 25export PATH="$PATH:$script_dir/fmpp/bin"
17 26
18build_fmpp() { 27build_fmpp() {
@@ -45,67 +54,6 @@ find_chibi_files() {
45 done 54 done
46} 55}
47 56
48revert_chibi_files() {
49 local search_path="$1"
50 shead "Reverting ChibiOS config/board files..."
51 for file in $(find_chibi_files "$search_path" -name chconf.h -or -name halconf.h -or -name mcuconf.h -or -name board.c -or -name board.h -or -name board.mk -or -name board.chcfg) ; do
52 pushd "$search_path" >/dev/null 2>&1
53 local relpath=$(realpath --relative-to="$search_path" "$file")
54 git checkout upstream/develop -- "$relpath" || git checkout origin/develop -- "$relpath" || true
55 popd >/dev/null 2>&1
56 done
57}
58
59populate_file_hashes() {
60 local search_path="$1"
61 shead "Determining duplicate config/board files..."
62 for file in $(find_chibi_files "$search_path" -name chconf.h -or -name halconf.h -or -name mcuconf.h -or -name board.c -or -name board.h) ; do
63 local key="file_$(clang-format "$file" | sha1sum | cut -d' ' -f1)"
64 local relpath=$(realpath --relative-to="$search_path" "$file")
65 file_hashes[$key]="${file_hashes[$key]:-} $relpath"
66 done
67 for file in $(find_chibi_files "$search_path" -name board.mk -or -name board.chcfg) ; do
68 local key="file_$(cat "$file" | sha1sum | cut -d' ' -f1)"
69 local relpath=$(realpath --relative-to="$search_path" "$file")
70 file_hashes[$key]="${file_hashes[$key]:-} $relpath"
71 done
72}
73
74determine_equivalent_files() {
75 local search_file="$1"
76 for K in "${!file_hashes[@]}"; do
77 for V in ${file_hashes[$K]}; do
78 if [[ "$V" == "$search_file" ]] ; then
79 for V in ${file_hashes[$K]}; do
80 echo "$V"
81 done
82 return 0
83 fi
84 done
85 done
86 return 1
87}
88
89deploy_staged_files() {
90 shead "Deploying staged files..."
91 for file in $(find "$qmk_firmware_dir/util/chibios-upgrade-staging" -type f) ; do
92 local relpath=$(realpath --relative-to="$qmk_firmware_dir/util/chibios-upgrade-staging" "$file")
93 sinfo "Deploying staged file: $relpath"
94 for other in $(determine_equivalent_files "$relpath") ; do
95 sinfo " => $other"
96 cp "$qmk_firmware_dir/util/chibios-upgrade-staging/$relpath" "$qmk_firmware_dir/$other"
97 done
98 done
99}
100
101swap_mcuconf_f3xx_f303() {
102 shead "Swapping STM32F3xx_MCUCONF -> STM32F303_MCUCONF..."
103 for file in $(find_chibi_files "$qmk_firmware_dir" -name mcuconf.h) ; do
104 sed -i 's#STM32F3xx_MCUCONF#STM32F303_MCUCONF#g' "$file"
105 dos2unix "$file" >/dev/null 2>&1
106 done
107}
108
109upgrade_conf_files_generic() { 57upgrade_conf_files_generic() {
110 local search_filename="$1" 58 local search_filename="$1"
111 local update_script="$2" 59 local update_script="$2"
@@ -150,35 +98,8 @@ upgrade_mcuconf_files() {
150 popd >/dev/null 2>&1 98 popd >/dev/null 2>&1
151} 99}
152 100
153update_staged_files() {
154 shead "Updating staged files with ChibiOS upgraded versions..."
155 for file in $(find "$qmk_firmware_dir/util/chibios-upgrade-staging" -type f) ; do
156 local relpath=$(realpath --relative-to="$qmk_firmware_dir/util/chibios-upgrade-staging" "$file")
157 sinfo "Updating staged file: $relpath"
158 cp "$qmk_firmware_dir/$relpath" "$qmk_firmware_dir/util/chibios-upgrade-staging/$relpath"
159 done
160}
161
162havecmd fmpp || build_fmpp 101havecmd fmpp || build_fmpp
163revert_chibi_files "$qmk_firmware_dir"
164populate_file_hashes "$qmk_firmware_dir"
165
166shead "Showing duplicate ChibiOS files..."
167for K in "${!file_hashes[@]}"; do
168 sinfo ${K#file_}:
169 for V in ${file_hashes[$K]}; do
170 sinfo " $V"
171 done
172done
173
174if [ "${1:-}" == "-r" ] ; then
175 exit 0
176fi
177
178swap_mcuconf_f3xx_f303
179 102
180deploy_staged_files
181upgrade_mcuconf_files 103upgrade_mcuconf_files
182upgrade_chconf_files 104upgrade_chconf_files
183upgrade_halconf_files 105upgrade_halconf_files
184update_staged_files