From 3d193a9bbe518c4342710145002765419de33dc7 Mon Sep 17 00:00:00 2001 From: Stan Grishin Date: Wed, 6 Oct 2021 21:43:55 +0000 Subject: [PATCH] luci-app-advanced-reboot: bugfix for Linksys E4200v2 * bugfix for Linksys E4200v2 * backport updates from master Signed-off-by: Stan Grishin --- .../luci-app-advanced-reboot/Makefile | 2 +- .../resources/view/system/advanced_reboot.js | 5 +-- .../usr/libexec/rpcd/luci.advanced_reboot | 35 ++++++++++++------- .../devices/linksys-e4200v2.json | 5 ++- .../devices/linksys-ea7500v1.json | 14 ++++++++ 5 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-ea7500v1.json diff --git a/applications/luci-app-advanced-reboot/Makefile b/applications/luci-app-advanced-reboot/Makefile index 9f717d5cbc..114d1cd859 100644 --- a/applications/luci-app-advanced-reboot/Makefile +++ b/applications/luci-app-advanced-reboot/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Stan Grishin -PKG_VERSION:=1.0.0-1 +PKG_VERSION:=1.0.1-3 LUCI_TITLE:=Advanced Linksys Reboot Web UI LUCI_URL:=https://docs.openwrt.melmac.net/luci-app-advanced-reboot/ diff --git a/applications/luci-app-advanced-reboot/htdocs/luci-static/resources/view/system/advanced_reboot.js b/applications/luci-app-advanced-reboot/htdocs/luci-static/resources/view/system/advanced_reboot.js index c9cc20bec0..482b8e2e91 100644 --- a/applications/luci-app-advanced-reboot/htdocs/luci-static/resources/view/system/advanced_reboot.js +++ b/applications/luci-app-advanced-reboot/htdocs/luci-static/resources/view/system/advanced_reboot.js @@ -8,7 +8,8 @@ return view.extend({ translateTable: { NO_BOARD_NAME : function(args) { return _('Unable to find Device Board Name.')}, - NO_DUAL_FLAG : function(args) {return _('Unable to find Dual Boot Flag Partition.')}, + NO_DUAL_FLAG: function (args) { return _('Unable to find Dual Boot Flag Partition.') }, + NO_DUAL_FLAG_BLOCK: function (args) { return _('The Dual Boot Flag Partition: %s is not a block device.').format(args[0])}, ERR_SET_DUAL_FLAG : function(args) { return _('Unable to set Dual Boot Flag Partition entry for partition: %s.').format(args[0])}, NO_FIRM_ENV : function(args) { return _('Unable to obtain firmware environment variable: %s.').format(args[0])}, ERR_SET_ENV : function(args) { return _('Unable to set firmware environment variable: %s to %s.').format(args[0],args[1])} @@ -196,7 +197,7 @@ return view.extend({ if (device_info.error) body.appendChild(E('p', { 'class' : 'alert-message warning'}, _("ERROR: ") + this.translateTable[device_info.error]())); - body.appendChild(E('h3', device_info.device_name + _(' Partitions'))); + body.appendChild(E('h3', (device_info.device_name || '') + _(' Partitions'))); if (device_info.device_name) { var partitions_table = E('table', { 'class': 'table' }, [ E('tr', { 'class': 'tr table-titles' }, [ diff --git a/applications/luci-app-advanced-reboot/root/usr/libexec/rpcd/luci.advanced_reboot b/applications/luci-app-advanced-reboot/root/usr/libexec/rpcd/luci.advanced_reboot index c5dfd74a18..7ec52a3097 100755 --- a/applications/luci-app-advanced-reboot/root/usr/libexec/rpcd/luci.advanced_reboot +++ b/applications/luci-app-advanced-reboot/root/usr/libexec/rpcd/luci.advanced_reboot @@ -1,6 +1,6 @@ #!/bin/sh # Copyright 2017-2020 Stan Grishin (stangri@melmac.net) -# shellcheck disable=SC2039,SC1091 +# shellcheck disable=SC2039,SC1091,SC3043,SC3057,SC3060 readonly devices_dir="/usr/share/advanced-reboot/devices/" @@ -100,7 +100,7 @@ find_device_data(){ print_json() { json_init; json_add_string "$1" "$2"; json_dump; json_cleanup; } obtain_device_info(){ - local romBoardName p zyxelFlagPartition + local romBoardName p zyxelFlagPartition i local vendorName deviceName partition1MTD partition2MTD labelOffset local bootEnv1 bootEnv1Partition1Value bootEnv1Partition2Value local bootEnv2 bootEnv2Partition1Value bootEnv2Partition2Value @@ -167,15 +167,20 @@ obtain_device_info(){ current_partition="$(/usr/sbin/fw_printenv -n "${bootEnv1}")" fi else + for i in '0:dual_flag' '0:DUAL_FLAG'; do + zyxelFlagPartition="$(find_mtd_part "$i" 2>/dev/null)" + [ -n "$zyxelFlagPartition" ] && break + done if [ -z "$zyxelFlagPartition" ]; then - zyxelFlagPartition="$(find_mtd_part 0:DUAL_FLAG 2>/dev/null)" - fi - if [ -n "$zyxelFlagPartition" ]; then - current_partition="$(dd if="${zyxelFlagPartition}" bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 "%d"')" - else print_json 'error' 'NO_DUAL_FLAG' logger "Unable to find Dual Boot Environment or Dual Boot Flag Partition." return + elif [ ! -b "$zyxelFlagPartition" ]; then + print_json 'error' 'NO_DUAL_FLAG_BLOCK' + logger "The Dual Boot Flag Partition: $zyxelFlagPartition is not block device." + return + else + current_partition="$(dd if="${zyxelFlagPartition}" bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 "%d"')" fi fi @@ -202,7 +207,6 @@ obtain_device_info(){ p2_os="$p2_os (Linux ${p2_version})" fi - json_init json_add_int 'current_partition' "$current_partition" json_add_string 'device_name' "$vendorName $deviceName" @@ -231,7 +235,7 @@ obtain_device_info(){ } toggle_boot_partition(){ - local zyxelFlagPartition zyxelBootFlag zyxelNewBootFlag curEnvSetting newEnvSetting + local zyxelFlagPartition i zyxelBootFlag zyxelNewBootFlag curEnvSetting newEnvSetting local romBoardName p local bev1 bev2 bev1p1 bev1p2 bev2p1 bev2p2 local vendorName deviceName partition1MTD partition2MTD labelOffset @@ -333,12 +337,17 @@ toggle_boot_partition(){ json_init json_dump; json_cleanup; else # NetGear device + for i in '0:dual_flag' '0:DUAL_FLAG'; do + zyxelFlagPartition="$(find_mtd_part "$i" 2>/dev/null)" + [ -n "$zyxelFlagPartition" ] && break + done if [ -z "$zyxelFlagPartition" ]; then - zyxelFlagPartition="$(find_mtd_part 0:DUAL_FLAG 2>/dev/null)" - fi - if [ -z "$zyxelFlagPartition" ]; then - logger "Unable to find Dual Boot Flag Partition." print_json 'error' 'NO_DUAL_FLAG' + logger "Unable to find Dual Boot Environment or Dual Boot Flag Partition." + return + elif [ ! -b "$zyxelFlagPartition" ]; then + print_json 'error' 'NO_DUAL_FLAG_BLOCK' + logger "The Dual Boot Flag Partition: $zyxelFlagPartition is not block device." return else zyxelBootFlag="$(dd if="${zyxelFlagPartition}" bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 "%d"')" diff --git a/applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-e4200v2.json b/applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-e4200v2.json index c32aaf8a3c..d42319e2ce 100644 --- a/applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-e4200v2.json +++ b/applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-e4200v2.json @@ -1,7 +1,10 @@ { "vendorName": "Linksys", "deviceName": "E4200v2", - "boardNames": [ "linksys-e4200v2", "linksys,e4200v2" ], + "boardNames": [ + "linksys-e4200v2", + "linksys,e4200-v2" + ], "partition1MTD": "mtd3", "partition2MTD": "mtd5", "labelOffset": 32, diff --git a/applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-ea7500v1.json b/applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-ea7500v1.json new file mode 100644 index 0000000000..4c68639fd3 --- /dev/null +++ b/applications/luci-app-advanced-reboot/root/usr/share/advanced-reboot/devices/linksys-ea7500v1.json @@ -0,0 +1,14 @@ +{ + "vendorName": "Linksys", + "deviceName": "EA7500v1", + "boardNames": [ "linksys,ea7500-v1" ], + "partition1MTD": "mtd13", + "partition2MTD": "mtd15", + "labelOffset": 32, + "bootEnv1": "boot_part", + "bootEnv1Partition1Value": 1, + "bootEnv1Partition2Value": 2, + "bootEnv2": null, + "bootEnv2Partition1Value": null, + "bootEnv2Partition2Value": null +} -- 2.30.2