From ca9d8162df0bd962853434dfcf8fc3a31ae2e866 Mon Sep 17 00:00:00 2001 From: Isaac Hermida Date: Thu, 28 Nov 2024 08:12:08 +0100 Subject: [PATCH] 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 --- .../bluez/bluez5-init/ccimx9/bluetooth-init | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init index 687b8cff2..e2ea10d99 100644 --- a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init @@ -1,7 +1,7 @@ #!/bin/sh #=============================================================================== # -# Copyright (C) 2023 by Digi International Inc. +# Copyright (C) 2023,2024, Digi International Inc. # All rights reserved. # # 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 } +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() { # # The btnxpuart driver hits a null pointer dereference on module # unloading when the interface is down. So as a workaround, make # sure the interface is UP before unloading the module. # - hciconfig "${HCI_IFACE}" up && rmmod "${MODULE_NAME}" - power 0 + if is_system_running; then + hciconfig "${HCI_IFACE}" up && rmmod "${MODULE_NAME}" + power 0 + else + log "System rebooting... not taking any action" + fi } + case "$1" in start) bluetooth_start