board: dragonboard410c: Fix BD address
authorStephan Gerhold <stephan.gerhold@linaro.org>
Mon, 7 Apr 2025 16:59:24 +0000 (18:59 +0200)
committerCaleb Connolly <caleb.connolly@linaro.org>
Fri, 11 Apr 2025 13:32:21 +0000 (15:32 +0200)
local-bd-address in the device tree needs to be formatted with the least
significant byte first (i.e. little endian). We're not doing this when
adding it to the DT, which means the MAC address ends up being reversed in
Linux. Fix this by reversing the array before setting it in the DT.

We're also flipping the wrong bit when generating the BD address. Before
reversing the array, the least significant bit is in the last byte.

Fixes: ff06dc240325 ("db410: alter WLAN/BT MAC address fixup")
Signed-off-by: Stephan Gerhold <stephan.gerhold@linaro.org>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Reviewed-by:
Link: https://lore.kernel.org/r/20250407-db410c-fixes-v1-3-524aefbc8bb4@linaro.org
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
board/qualcomm/dragonboard410c/dragonboard410c.c

index d0d8248..744ac4f 100644 (file)
@@ -97,9 +97,9 @@ int qcom_late_init(void)
        return 0;
 }
 
-/* Fixup of DTB for Linux Kernel
- * 1. Fixup installed DRAM.
- * 2. Fixup WLAN/BT Mac address:
+/*
+ * Fixup of DTB for Linux Kernel
+ * 1. Fixup WLAN/BT Mac address:
  *     First, check if MAC addresses for WLAN/BT exists as environemnt
  *     variables wlanaddr,btaddr. if not, generate a unique address.
  */
@@ -107,6 +107,7 @@ int qcom_late_init(void)
 int ft_board_setup(void *blob, struct bd_info *bd)
 {
        u8 mac[ARP_HLEN];
+       int i;
 
        if (!eth_env_get_enetaddr("wlanaddr", mac)) {
                msm_generate_mac_addr(mac);
@@ -118,12 +119,24 @@ int ft_board_setup(void *blob, struct bd_info *bd)
        if (!eth_env_get_enetaddr("btaddr", mac)) {
                msm_generate_mac_addr(mac);
 
-/* The BD address is same as WLAN MAC address but with
- * least significant bit flipped.
- */
-               mac[0] ^= 0x01;
+               /*
+                * The BD address is same as WLAN MAC address but with
+                * least significant bit flipped.
+                */
+               mac[ARP_HLEN - 1] ^= 0x01;
        };
 
+       /*
+        * Reverse array since local-bd-address is formatted with least
+        * significant byte first (little endian).
+        */
+       for (i = 0; i < ARP_HLEN / 2; ++i) {
+               u8 tmp = mac[i];
+
+               mac[i] = mac[ARP_HLEN - 1 - i];
+               mac[ARP_HLEN - 1 - i] = tmp;
+       }
+
        do_fixup_by_compat(blob, "qcom,wcnss-bt",
                           "local-bd-address", mac, ARP_HLEN, 1);
        return 0;