aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2020-03-16 15:52:24 +0000
committerPeter Maydell <peter.maydell@linaro.org>2020-03-17 11:36:42 +0000
commit9c85bcd8f5f9f775e8305e580cf5fbc5b7ba2c28 (patch)
treed878721945f4893353581a7e4a711513a804d860 /hw
parentf3ee222f0c5f3681c28991313f76773e6cfed777 (diff)
downloadqemu-9c85bcd8f5f9f775e8305e580cf5fbc5b7ba2c28.zip
qemu-9c85bcd8f5f9f775e8305e580cf5fbc5b7ba2c28.tar.gz
qemu-9c85bcd8f5f9f775e8305e580cf5fbc5b7ba2c28.tar.bz2
m25p80: Improve command handling for unsupported commands
Whenever an unsupported command is encountered, the current code interprets each transferred byte as new command. Most of the time, those 'commands' are interpreted as new unknown commands. However, in rare cases, it may be that for example address or length information passed with the original command is by itself a valid command. If that happens, the state machine may get completely confused and, worst case, start writing data into the flash or even erase it. To avoid the problem, transition into STATE_READING_DATA and keep sending a value of 0 until the chip is deselected after encountering an unsupported command. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/block/m25p80.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 53bf638..8227088 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -1161,6 +1161,11 @@ static void decode_new_cmd(Flash *s, uint32_t value)
s->quad_enable = false;
break;
default:
+ s->pos = 0;
+ s->len = 1;
+ s->state = STATE_READING_DATA;
+ s->data_read_loop = true;
+ s->data[0] = 0;
qemu_log_mask(LOG_GUEST_ERROR, "M25P80: Unknown cmd %x\n", value);
break;
}