From 628cb3b8c989d9b0357727505e3d446bdf017d69 Mon Sep 17 00:00:00 2001 From: BuGu <62454025+Z2Z-GuGu@users.noreply.github.com> Date: Fri, 21 Mar 2025 16:16:53 +0800 Subject: [PATCH] Fix abnormal updates of some models Add function: If the program does not execute after the update, execute a restart --- .../sg2002/additional/kvm/src/kvm_vision.cpp | 6 ++-- .../sg2002/kvm_system/main/include/config.h | 1 + .../main/lib/system_init/system_init.cpp | 4 ++- .../main/lib/system_state/system_state.cpp | 36 ++++++++++++++++++- .../main/lib/system_state/system_state.h | 6 +++- support/sg2002/kvm_system/main/src/main.cpp | 1 + 6 files changed, 49 insertions(+), 5 deletions(-) diff --git a/support/sg2002/additional/kvm/src/kvm_vision.cpp b/support/sg2002/additional/kvm/src/kvm_vision.cpp index a11d159..15b81c2 100644 --- a/support/sg2002/additional/kvm/src/kvm_vision.cpp +++ b/support/sg2002/additional/kvm/src/kvm_vision.cpp @@ -41,6 +41,7 @@ #define hdmi_mode_path "/etc/kvm/hdmi_mode" #define hdmi_state_path "/proc/lt_int" #define watchdog_mode_path "/etc/kvm/watchdog" +#define watchdog_temp_path "/tmp/watchdog" #define watchdog_file "/tmp/nanokvm_wd" #define LT6911_ADDR 0x2B @@ -309,9 +310,10 @@ int get_hdmi_mode(void) return 0; } -uint8_t watchdog_sf_is_open() +uint8_t watchdog_sf_is_open(void) { if(access(watchdog_mode_path, F_OK) == 0) return 1; + else if(access(watchdog_temp_path, F_OK) == 0) return 1; else return 0; } @@ -1017,7 +1019,7 @@ void* watchdog_sf_feed(void * arg) debug("[kvmv] Ion memory is full reboot now!\n"); system("reboot"); } - debug("[kvmv] watchdog_sf_feed now!\n"); + // debug("[kvmv] watchdog_sf_feed now!\n"); vision_update_watchdog(); } } diff --git a/support/sg2002/kvm_system/main/include/config.h b/support/sg2002/kvm_system/main/include/config.h index 1944123..9150cc7 100644 --- a/support/sg2002/kvm_system/main/include/config.h +++ b/support/sg2002/kvm_system/main/include/config.h @@ -37,6 +37,7 @@ #define OLED_SLEEP_DELAY_MIN 10 #define OLED_SLEEP_DELAY_DEFAULT 30 #define KVM_WD_COUNT_MAX 10 +#define RM_Watchdog_times 60 typedef struct { int8_t page = 0; diff --git a/support/sg2002/kvm_system/main/lib/system_init/system_init.cpp b/support/sg2002/kvm_system/main/lib/system_init/system_init.cpp index ae834fc..17670fc 100644 --- a/support/sg2002/kvm_system/main/lib/system_init/system_init.cpp +++ b/support/sg2002/kvm_system/main/lib/system_init/system_init.cpp @@ -130,6 +130,9 @@ void new_app_init(void) else if(RW_Data[0] == 'u') hdmi_ver = 2; } + system("/etc/init.d/S03usbdev stop_start"); + create_temp_watchdog(); + if(hdmi_ver == 2){ if(RW_Data_1[0] != '/'){ system("cp /kvmapp/system/ko/soph_mipi_rx.ko /mnt/system/ko/soph_mipi_rx.ko"); @@ -161,7 +164,6 @@ void new_app_init(void) system("rm -r /tmp/server"); system("cp -r /kvmapp/server /tmp/"); system("/tmp/server/NanoKVM-Server &"); - system("/etc/init.d/S03usbdev stop_start"); } void build_complete_resolv(void) diff --git a/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp b/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp index 4ca4314..d98d576 100644 --- a/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp +++ b/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp @@ -470,9 +470,43 @@ uint8_t ion_free_space(void) return 0; } -uint8_t watchdog_sf_is_open() +int create_temp_watchdog(void) +{ + FILE *file; + + file = fopen(watchdog_temp_path, "w"); + if (file == NULL) { + printf("[kvmv] Temp watchdog create error\n"); + return -1; + } + // fprintf(file, "%s", 'v'); + fclose(file); + return 1; +} + +void rm_temp_watchdog(void) +{ + if(access(watchdog_temp_path, F_OK) == 0) { + remove(watchdog_temp_path); + } +} + +void auto_remove_temp_watchdog(void) +{ + static uint8_t run_times = 0; + static uint8_t temp_watchdog_removed = 0; + if(temp_watchdog_removed) return; + if(run_times++ >= RM_Watchdog_times){ + run_times = 0; + temp_watchdog_removed = 1; + rm_temp_watchdog(); + } +} + +uint8_t watchdog_sf_is_open(void) { if(access(watchdog_mode_path, F_OK) == 0) return 1; + if(access(watchdog_temp_path, F_OK) == 0) return 1; else return 0; } diff --git a/support/sg2002/kvm_system/main/lib/system_state/system_state.h b/support/sg2002/kvm_system/main/lib/system_state/system_state.h index 7494d4f..f076f8c 100644 --- a/support/sg2002/kvm_system/main/lib/system_state/system_state.h +++ b/support/sg2002/kvm_system/main/lib/system_state/system_state.h @@ -14,6 +14,7 @@ enum ip_addr_t #define NIC_STATE_NO_EXIST -2 #define watchdog_mode_path "/etc/kvm/watchdog" +#define watchdog_temp_path "/tmp/watchdog" #define watchdog_file "/tmp/nanokvm_wd" // net_port @@ -34,7 +35,10 @@ void kvm_update_rndis_state(void); void kvm_update_tailscale_state(void); uint8_t ion_free_space(void); int get_nic_state(const char* interface_name); -uint8_t watchdog_sf_is_open(); +int create_temp_watchdog(void); +void rm_temp_watchdog(void); +void auto_remove_temp_watchdog(void); +uint8_t watchdog_sf_is_open(void); int check_watchdog(); #endif // SYSTEM_STATE_H_ diff --git a/support/sg2002/kvm_system/main/src/main.cpp b/support/sg2002/kvm_system/main/src/main.cpp index 2bbcf61..0e4f69f 100644 --- a/support/sg2002/kvm_system/main/src/main.cpp +++ b/support/sg2002/kvm_system/main/src/main.cpp @@ -167,6 +167,7 @@ void* thread_sys_handle(void * arg) } time::sleep_ms(STATE_DELAY); + auto_remove_temp_watchdog(); } kvm_sys_state.sys_thread_running = 0; }