bluetooth-init: cc9: do not unload the btnxpuart on reboot

Do not take any action such as removing the btnxpuart module When
the system is being restarted (poweroff or reboot), as the driver
tries to restore the UART baudrate when removing the module, and if
the system is being off, some of the entries might be dissapeared in the
middle of the process, leading to a NULL pointer and preventing the
system of being rebooted.
The btnxpuart can be removed on suspend/resume safely, so add the logic
to detect if the system is being rebooted.

https://onedigi.atlassian.net/browse/DEL-9290

Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
This commit is contained in:
Isaac Hermida 2024-11-28 08:12:08 +01:00
parent 17cbe3dda3
commit ca9d8162df
1 changed files with 18 additions and 3 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
#=============================================================================== #===============================================================================
# #
# Copyright (C) 2023 by Digi International Inc. # Copyright (C) 2023,2024, Digi International Inc.
# All rights reserved. # All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify it # This program is free software; you can redistribute it and/or modify it
@ -65,16 +65,31 @@ bluetooth_start() {
log "[ERROR] Cannot initialize Bluetooth correctly" && return 1 log "[ERROR] Cannot initialize Bluetooth correctly" && return 1
} }
is_system_running() {
state=$(systemctl is-system-running 2>/dev/null)
case "$state" in
running|degraded)
return 0 ;; # System is operational
*)
return 1 ;; # Assume not running
esac
}
bluetooth_stop() { bluetooth_stop() {
# #
# The btnxpuart driver hits a null pointer dereference on module # The btnxpuart driver hits a null pointer dereference on module
# unloading when the interface is down. So as a workaround, make # unloading when the interface is down. So as a workaround, make
# sure the interface is UP before unloading the module. # sure the interface is UP before unloading the module.
# #
if is_system_running; then
hciconfig "${HCI_IFACE}" up && rmmod "${MODULE_NAME}" hciconfig "${HCI_IFACE}" up && rmmod "${MODULE_NAME}"
power 0 power 0
else
log "System rebooting... not taking any action"
fi
} }
case "$1" in case "$1" in
start) start)
bluetooth_start bluetooth_start