base-files: armsr: add script to migrate GPIO switches on Ten64 board
[openwrt/staging/stintel.git] / target / linux / armsr / base-files / etc / uci-defaults / 05-migrate-ten64-gpio
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-or-later
3
4 # This script migrates GPIO switch pin numbers
5 # from kernel versions prior to 6.6
6 # See https://lists.openwrt.org/pipermail/openwrt-devel/2024-March/042448.html
7
8 . /lib/functions.sh
9
10 ten64_update_gpioswitch_num() {
11 local section="$1"
12 config_get gpio_pin "${section}" gpio_pin
13 config_get gpio_name "${section}" name
14 if [ -z "${gpio_pin}" ]; then
15 return
16 fi
17 local this_pin_name=$(uci get "system.${section}.name")
18 if [ "${gpio_pin}" -lt 640 ]; then
19 new_pin_value=$(( $gpio_pin + 272 ))
20 uci set "system.${section}.gpio_pin=${new_pin_value}"
21 fi
22 }
23
24 board=$(board_name)
25 if [ "${board}" != "traverse,ten64" ]; then
26 exit 0
27 fi
28
29 KERNEL_MINOR=$(uname -r | awk -F '.' '{print $2}')
30 if [ "${KERNEL_MINOR}" -lt "6" ]; then
31 exit 0
32 fi
33
34 config_load system
35 config_foreach ten64_update_gpioswitch_num gpio_switch
36
37 exit 0