[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/10] hw/sd.c: Fix the set of commands which are fa
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PATCH 01/10] hw/sd.c: Fix the set of commands which are failed when card is locked |
Date: |
Sun, 18 Dec 2011 20:37:51 +0000 |
Fix bugs in the code determining whether to accept a card when the
SD card is locked. Most notably, we had the condition completely
reversed, so we would accept all the commands we should refuse and
refuse all the commands we should accept. Correct this by refactoring
the enormous if () clause into a separate function.
We had also missed ACMD42 off the list of commands which are accepted
in locked state: add it.
This is one of the two problems reported in LP:597641.
Signed-off-by: Peter Maydell <address@hidden>
---
hw/sd.c | 29 ++++++++++++++++++++++-------
1 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/hw/sd.c b/hw/sd.c
index 10e26ad..a1c98c0 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -1265,6 +1265,25 @@ static sd_rsp_type_t sd_app_command(SDState *sd,
return sd_r0;
}
+static int cmd_valid_while_locked(SDState *sd, SDRequest *req)
+{
+ /* Valid commands in locked state:
+ * basic class (0)
+ * lock card class (7)
+ * CMD16
+ * implicitly, the ACMD prefix CMD55
+ * ACMD41 and ACMD42
+ * Anything else provokes an "illegal command" response.
+ */
+ if (sd->card_status & APP_CMD) {
+ return req->cmd == 41 || req->cmd == 42;
+ }
+ if (req->cmd == 16 || req->cmd == 55) {
+ return 1;
+ }
+ return sd_cmd_class[req->cmd] == 0 || sd_cmd_class[req->cmd] == 7;
+}
+
int sd_do_command(SDState *sd, SDRequest *req,
uint8_t *response) {
uint32_t last_status = sd->card_status;
@@ -1283,17 +1302,13 @@ int sd_do_command(SDState *sd, SDRequest *req,
sd->card_status &= ~CARD_STATUS_B;
sd_set_status(sd);
- if (last_status & CARD_IS_LOCKED)
- if (((last_status & APP_CMD) &&
- req->cmd == 41) ||
- (!(last_status & APP_CMD) &&
- (sd_cmd_class[req->cmd] == 0 ||
- sd_cmd_class[req->cmd] == 7 ||
- req->cmd == 16 || req->cmd == 55))) {
+ if (last_status & CARD_IS_LOCKED) {
+ if (!cmd_valid_while_locked(sd, req)) {
sd->card_status |= ILLEGAL_COMMAND;
fprintf(stderr, "SD: Card is locked\n");
return 0;
}
+ }
if (last_status & APP_CMD) {
rtype = sd_app_command(sd, *req);
--
1.7.5.4
- [Qemu-devel] [PATCH 00/10] hw/sd.c: Fix various status related bugs, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 10/10] hw/sd.c: Clear status bits when read via response r6, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 08/10] hw/sd.c: Correct handling of type B SD status bits, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 01/10] hw/sd.c: Fix the set of commands which are failed when card is locked,
Peter Maydell <=
- [Qemu-devel] [PATCH 07/10] hw/sd.c: Set ILLEGAL_COMMAND for ACMDs in invalid state, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 04/10] hw/sd.c: When setting ADDRESS_ERROR bit, don't clear everything else, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 03/10] hw/sd.c: On CRC error, set CRC error status bit rather than clearing it, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 05/10] hw/sd.c: Handle illegal commands in sd_do_command, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 06/10] hw/sd.c: Handle CRC and locked-card errors in normal code path, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 02/10] hw/sd.c: Add comment regarding CARD_STATUS_* defines, Peter Maydell, 2011/12/18
- [Qemu-devel] [PATCH 09/10] hw/sd.c: Correct handling of APP_CMD status bit, Peter Maydell, 2011/12/18
- Re: [Qemu-devel] [PATCH 00/10] hw/sd.c: Fix various status related bugs, andrzej zaborowski, 2011/12/20