Skip to content

Commit d0d68d6

Browse files
Lukasz Majewskikartben
authored andcommitted
drivers: net: ot: Provide structure instance for HDLC RCP context
Without this patch the hdlc_iface_init() function assigns to ot_hdlc_rcp_context structure pointer (*ctx) value of 0, as in the NET_DEVICE_DT_INST_DEFINE() preprocessor macro the 'data' field is set to NULL. Afterwards, the ctx->iface is set to iface address passed to the function (as well as the ctx->ot_context is set). Writing those values to address 0x0 is catastrophic to for example mimxrt1020, which uses ITCM memory (mapped from 0x0) to store flash handling functions, as those are used to XIP code directly from SPI NOR memory (as mximxrt1020 doesn't have internal flash). In this particular case - the flash_flexspi_nor_erase() function is mapped (i.e. relocated) to ITCM's 0x0 address. Overwriting first 8 bytes of it causes the SoC to enter "Precise data bus error" exception. The fix is to define the static instance of struct ot_hdlc_rcp_context and pass its address to the NET_DEVICE_DT_INST_DEFINE() macro. As a result its storage is now in RAM, not ITCM. This issue has been discovered on UART based HDLC RCP communication, but as it also may be problematic on the NXP driver, this patch fixes it too. Signed-off-by: Lukasz Majewski <[email protected]>
1 parent 62b911f commit d0d68d6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

drivers/hdlc_rcp_if/hdlc_rcp_if_nxp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
#define LOG_LEVEL CONFIG_HDLC_RCP_IF_DRIVER_LOG_LEVEL
3535
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
3636

37-
struct ot_hdlc_rcp_context {
37+
static struct ot_hdlc_rcp_context {
3838
struct net_if *iface;
3939
struct openthread_context *ot_context;
40-
};
40+
} ot_hdlc_rcp_ctx;
4141

4242
/* -------------------------------------------------------------------------- */
4343
/* Private prototypes */
@@ -111,7 +111,7 @@ static const struct hdlc_api nxp_hdlc_api = {
111111

112112
NET_DEVICE_DT_INST_DEFINE(0, NULL, /* Initialization Function */
113113
NULL, /* No PM API support */
114-
NULL, /* No context data */
114+
&ot_hdlc_rcp_ctx, /* HDLC RCP context data */
115115
NULL, /* Configuration info */
116116
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, /* Initial priority */
117117
&nxp_hdlc_api, /* API interface functions */

drivers/hdlc_rcp_if/hdlc_rcp_if_uart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ struct openthread_uart {
5454
OT_UART_DEFINE(ot_uart, CONFIG_OPENTHREAD_HDLC_RCP_IF_UART_RX_RING_BUFFER_SIZE,
5555
CONFIG_OPENTHREAD_HDLC_RCP_IF_UART_TX_RING_BUFFER_SIZE);
5656

57-
struct ot_hdlc_rcp_context {
57+
static struct ot_hdlc_rcp_context {
5858
struct net_if *iface;
5959
struct openthread_context *ot_context;
60-
};
60+
} ot_hdlc_rcp_ctx;
6161

6262
/* -------------------------------------------------------------------------- */
6363
/* Private functions */
@@ -210,7 +210,7 @@ static const struct hdlc_api uart_hdlc_api = {
210210

211211
NET_DEVICE_DT_INST_DEFINE(0, NULL, /* Initialization Function */
212212
NULL, /* No PM API support */
213-
NULL, /* No context data */
213+
&ot_hdlc_rcp_ctx, /* HDLC RCP context data */
214214
NULL, /* Configuration info */
215215
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, /* Initial priority */
216216
&uart_hdlc_api, /* API interface functions */

0 commit comments

Comments
 (0)