Stack Exchange
Complete kernel hang after adding bluetooth to system devicetree
I am working right now at adapting yocto distro to run on custom, imx8mm-evk based hardware. I was mostly changing linux devicetree to fit new board needs and everything was fine, but when I added bluetooth over UART node in devicetree:
&uart1 { /* BT */
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_uart1>;
    assigned-clocks = <&clk IMX8MM_CLK_UART1>;
    assigned-clock-parents = <&clk IMX8MM_SYS_PLL1_80M>;
    fsl,uart-has-rtscts;
    status = "okay";

    bluetooth {
        compatible = "brcm,bcm43438-bt";
        shutdown-gpios = <&gpio2 6 GPIO_ACTIVE_HIGH>;
        host-wakeup-gpios = <&gpio2 8 GPIO_ACTIVE_HIGH>;
        device-wakeup-gpios = <&gpio2 7 GPIO_ACTIVE_HIGH>;
        clocks = <&osc_32k>;
        max-speed = <4000000>;
        clock-names = "extclk";
    };
 };

System started to behave weirdly. On first it was just complete system hang on bluetooth initialization, to which I could not find any reason. But when I compiled kernel with BT_HCIUART as module it started to hang randomly (in roughly 40% of cases it will hang, on other 60% it will boot normally) around hci_uart_bcm initialization like this:
[  OK  ] Started Rule-based Manager for Device Events and Files.
[  OK  ] Finished Coldplug All udev Devices.
[  OK  ] Finished Create Volatile Files and Directories.
     Starting Start Psplash Boot Screen...
     Starting Network Time Synchronization...
     Starting Update UTMP about System Boot/Shutdown...
[  OK  ] Started Start Psplash Boot Screen.
[  OK  ] Started Start psplash-syst…progress communication helper.
[  OK  ] Finished Update UTMP about System Boot/Shutdown.
[  OK  ] Started Network Time Synchronization.
[  OK  ] Reached target System Initialization.
[  OK  ] Started Daily Cleanup of Temporary Directories.
[  OK  ] Reached target System Time Set.
[  OK  ] Reached target System Time Synchronized.
[  OK  ] Started Daily rotation of log files.
[  OK  ] Reached target Timers.
[  OK  ] Listening on Avahi mDNS/DNS-SD Stack Activation Socket.
[  OK  ] Listening on D-Bus System Message Bus Socket.
[    7.313814] caam 30900000.crypto: device ID = 0x0a16040100000000 (Era 9)
[    7.322605] caam-snvs 30370000.caam-snvs: violation handlers armed - non-secure state
[    7.324000] caam 30900000.crypto: job rings = 2, qi = 0
[  OK  ] Listening on dropbear.socket.
[    7.340581] CAN device driver interface
[    7.348931] Bluetooth: HCI UART driver ver 2.3
[    7.355484] Bluetooth: HCI UART protocol H4 registered
[    7.362211] hci_uart_bcm serial0-0: supply vbat not found, using dummy regulator
[    7.370252] hci_uart_bcm serial0-0: supply vddio not found, using dummy regulator
[  OK  ] Listening on GPS (Global P…ioning System) Daemon Sockets.
[    7.389583] Bluetooth: HCI UART protocol Broadcom registered
     Starting Weston[    7.404251] mcp251x spi1.0 can0: MCP2515 successfully initialized
 socket.
     Starting Console System Startup Logging...
[  OK  ] Listening on Weston socket.
[  OK  ] Finished Console System Startup Logging.
[    7.488047] imx-sdma 302b0000.dma-controller: firmware found.
[    7.488151] imx-sdma 302c0000.dma-controller: firmware found

After that I started investigation and found that if I blacklist hci_uart module during boot and insert it after user prompt appearing it will work just fine.
The question is: how to make linux load this module after complete boot without inserting weird dependencies (I could make some module really late in boot depend on hci_uart, but thats just ugly) or how to find out real reason for hang?
