Commit 5fd1cff2 authored by Adam Wujek's avatar Adam Wujek

common/i2c: fix variable size block writes

The line:
*cmds->cmds[cmd_index].data_len = tx_tmp;
triggered the write to memory, which is declared as read-only (const).
Such writes trigger the memory exception.

To make the code simpler and avoid problematic write,
support only writes that has a size of a register.

The fix was tested for PEC.
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 3266b9f4
...@@ -105,17 +105,20 @@ static void __xMR I2C_rx_complete(const struct i2c_s_async_descriptor *const des ...@@ -105,17 +105,20 @@ static void __xMR I2C_rx_complete(const struct i2c_s_async_descriptor *const des
break; break;
case BLK_GET_LEN: case BLK_GET_LEN:
/* block write from host, len byte */
io_read(io, &tx_tmp, 1); /* read received byte to a random variable */ io_read(io, &tx_tmp, 1); /* read received byte to a random variable */
if (!((cmds->cmds[cmd_index].query_byte) & QUERY_WR)) { /* write not supported for this command
* or wrong length or variable block */
if (!((cmds->cmds[cmd_index].query_byte) & QUERY_WR)
|| -(*cmds->cmds[cmd_index].data_len) != tx_tmp
) {
rx_state = CMD; rx_state = CMD;
send_nack(descr); send_nack(descr);
set_cmd(descr, 2); set_cmd(descr, 2);
break; break;
} }
*cmds->cmds[cmd_index].data_len = tx_tmp;
if (use_pec) if (use_pec)
pec_checksum = crc8_byte(pec_checksum ^ *cmds->cmds[cmd_index].data_len); pec_checksum = crc8_byte(pec_checksum ^ tx_tmp);
*cmds->cmds[cmd_index].data_len = -(*cmds->cmds[cmd_index].data_len);
send_ack(descr); send_ack(descr);
set_cmd(descr, 3); set_cmd(descr, 3);
rx_state = DATA; rx_state = DATA;
...@@ -124,6 +127,7 @@ static void __xMR I2C_rx_complete(const struct i2c_s_async_descriptor *const des ...@@ -124,6 +127,7 @@ static void __xMR I2C_rx_complete(const struct i2c_s_async_descriptor *const des
case DATA: case DATA:
io_read(io, &tx_tmp, 1); /* read received byte to a random variable */ io_read(io, &tx_tmp, 1); /* read received byte to a random variable */
if (!((cmds->cmds[cmd_index].query_byte) & QUERY_WR)) { if (!((cmds->cmds[cmd_index].query_byte) & QUERY_WR)) {
/* write not supported for this command */
rx_state = CMD; rx_state = CMD;
send_nack(descr); send_nack(descr);
set_cmd(descr, 2); set_cmd(descr, 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment