Skip to content

Commit c59d881

Browse files
NeerajSanjayKaleVudentz
authored andcommitted
Bluetooth: btnxpuart: Add correct bootloader error codes
This corrects the bootloader error codes for NXP chipsets. Since we have a common handling for all error codes, there is no backward compatibility issue. Added error handling for CRC error code in V3 bootloader signature. Fixes: 2748936 ("Bluetooth: btnxpuart: Add handling for boot-signature timeout errors") Signed-off-by: Neeraj Sanjay Kale <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 3b5715a commit c59d881

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

drivers/bluetooth/btnxpuart.c

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ struct btnxpuart_dev {
210210
#define NXP_NAK_V3 0x7b
211211
#define NXP_CRC_ERROR_V3 0x7c
212212

213-
/* Bootloader signature error codes */
214-
#define NXP_ACK_RX_TIMEOUT 0x0002 /* ACK not received from host */
215-
#define NXP_HDR_RX_TIMEOUT 0x0003 /* FW Header chunk not received */
216-
#define NXP_DATA_RX_TIMEOUT 0x0004 /* FW Data chunk not received */
213+
/* Bootloader signature error codes: Refer AN12820 from nxp.com */
214+
#define NXP_CRC_RX_ERROR BIT(0) /* CRC error in previous packet */
215+
#define NXP_ACK_RX_TIMEOUT BIT(2) /* ACK not received from host */
216+
#define NXP_HDR_RX_TIMEOUT BIT(3) /* FW Header chunk not received */
217+
#define NXP_DATA_RX_TIMEOUT BIT(4) /* FW Data chunk not received */
217218

218219
#define HDR_LEN 16
219220

@@ -316,6 +317,16 @@ union nxp_v3_rx_timeout_nak_u {
316317
u8 buf[6];
317318
};
318319

320+
struct nxp_v3_crc_nak {
321+
u8 nak;
322+
u8 crc;
323+
} __packed;
324+
325+
union nxp_v3_crc_nak_u {
326+
struct nxp_v3_crc_nak pkt;
327+
u8 buf[2];
328+
};
329+
319330
/* FW dump */
320331
#define NXP_FW_DUMP_SIZE (1024 * 1000)
321332

@@ -1089,25 +1100,27 @@ static void nxp_handle_fw_download_error(struct hci_dev *hdev, struct v3_data_re
10891100
struct btnxpuart_dev *nxpdev = hci_get_drvdata(hdev);
10901101
__u32 offset = __le32_to_cpu(req->offset);
10911102
__u16 err = __le16_to_cpu(req->error);
1092-
union nxp_v3_rx_timeout_nak_u nak_tx_buf;
1093-
1094-
switch (err) {
1095-
case NXP_ACK_RX_TIMEOUT:
1096-
case NXP_HDR_RX_TIMEOUT:
1097-
case NXP_DATA_RX_TIMEOUT:
1098-
nak_tx_buf.pkt.nak = NXP_NAK_V3;
1099-
nak_tx_buf.pkt.offset = __cpu_to_le32(offset);
1100-
nak_tx_buf.pkt.crc = crc8(crc8_table, nak_tx_buf.buf,
1101-
sizeof(nak_tx_buf) - 1, 0xff);
1102-
serdev_device_write_buf(nxpdev->serdev, nak_tx_buf.buf,
1103-
sizeof(nak_tx_buf));
1104-
break;
1105-
default:
1106-
bt_dev_dbg(hdev, "Unknown bootloader error code: %d", err);
1107-
break;
1108-
1103+
union nxp_v3_rx_timeout_nak_u timeout_nak_buf;
1104+
union nxp_v3_crc_nak_u crc_nak_buf;
1105+
1106+
if (err & NXP_CRC_RX_ERROR) {
1107+
crc_nak_buf.pkt.nak = NXP_CRC_ERROR_V3;
1108+
crc_nak_buf.pkt.crc = crc8(crc8_table, crc_nak_buf.buf,
1109+
sizeof(crc_nak_buf) - 1, 0xff);
1110+
serdev_device_write_buf(nxpdev->serdev, crc_nak_buf.buf,
1111+
sizeof(crc_nak_buf));
1112+
} else if (err & NXP_ACK_RX_TIMEOUT ||
1113+
err & NXP_HDR_RX_TIMEOUT ||
1114+
err & NXP_DATA_RX_TIMEOUT) {
1115+
timeout_nak_buf.pkt.nak = NXP_NAK_V3;
1116+
timeout_nak_buf.pkt.offset = __cpu_to_le32(offset);
1117+
timeout_nak_buf.pkt.crc = crc8(crc8_table, timeout_nak_buf.buf,
1118+
sizeof(timeout_nak_buf) - 1, 0xff);
1119+
serdev_device_write_buf(nxpdev->serdev, timeout_nak_buf.buf,
1120+
sizeof(timeout_nak_buf));
1121+
} else {
1122+
bt_dev_err(hdev, "Unknown bootloader error code: %d", err);
11091123
}
1110-
11111124
}
11121125

11131126
static int nxp_recv_fw_req_v3(struct hci_dev *hdev, struct sk_buff *skb)

0 commit comments

Comments
 (0)