Revision 1d06cb7a hw/sd.c

b/hw/sd.c
92 92

  
93 93
    int spi;
94 94
    int current_cmd;
95
    /* True if we will handle the next command as an ACMD. Note that this does
96
     * *not* track the APP_CMD status bit!
97
     */
98
    int expecting_acmd;
95 99
    int blk_written;
96 100
    uint64_t data_start;
97 101
    uint32_t data_offset;
......
341 345
static void sd_response_r1_make(SDState *sd, uint8_t *response)
342 346
{
343 347
    uint32_t status = sd->card_status;
344
    /* Clear the "clear on read" status bits (except APP_CMD) */
345
    sd->card_status &= ~CARD_STATUS_C | APP_CMD;
348
    /* Clear the "clear on read" status bits */
349
    sd->card_status &= ~CARD_STATUS_C;
346 350

  
347 351
    response[0] = (status >> 24) & 0xff;
348 352
    response[1] = (status >> 16) & 0xff;
......
608 612
    uint32_t rca = 0x0000;
609 613
    uint64_t addr = (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : req.arg;
610 614

  
615
    /* Not interpreting this as an app command */
616
    sd->card_status &= ~APP_CMD;
617

  
611 618
    if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc)
612 619
        rca = req.arg >> 16;
613 620

  
......
1116 1123
        if (sd->rca != rca)
1117 1124
            return sd_r0;
1118 1125

  
1126
        sd->expecting_acmd = 1;
1119 1127
        sd->card_status |= APP_CMD;
1120 1128
        return sd_r1;
1121 1129

  
......
1155 1163
                                    SDRequest req)
1156 1164
{
1157 1165
    DPRINTF("ACMD%d 0x%08x\n", req.cmd, req.arg);
1166
    sd->card_status |= APP_CMD;
1158 1167
    switch (req.cmd) {
1159 1168
    case 6:	/* ACMD6:  SET_BUS_WIDTH */
1160 1169
        switch (sd->state) {
......
1251 1260

  
1252 1261
    default:
1253 1262
        /* Fall back to standard commands.  */
1254
        sd->card_status &= ~APP_CMD;
1255 1263
        return sd_normal_command(sd, req);
1256 1264
    }
1257 1265

  
......
1269 1277
     * ACMD41 and ACMD42
1270 1278
     * Anything else provokes an "illegal command" response.
1271 1279
     */
1272
    if (sd->card_status & APP_CMD) {
1280
    if (sd->expecting_acmd) {
1273 1281
        return req->cmd == 41 || req->cmd == 42;
1274 1282
    }
1275 1283
    if (req->cmd == 16 || req->cmd == 55) {
......
1297 1305
    if (sd->card_status & CARD_IS_LOCKED) {
1298 1306
        if (!cmd_valid_while_locked(sd, req)) {
1299 1307
            sd->card_status |= ILLEGAL_COMMAND;
1308
            sd->expecting_acmd = 0;
1300 1309
            fprintf(stderr, "SD: Card is locked\n");
1301 1310
            rtype = sd_illegal;
1302 1311
            goto send_response;
......
1306 1315
    last_state = sd->state;
1307 1316
    sd_set_mode(sd);
1308 1317

  
1309
    if (sd->card_status & APP_CMD) {
1318
    if (sd->expecting_acmd) {
1319
        sd->expecting_acmd = 0;
1310 1320
        rtype = sd_app_command(sd, *req);
1311
        sd->card_status &= ~APP_CMD;
1312
    } else
1321
    } else {
1313 1322
        rtype = sd_normal_command(sd, *req);
1323
    }
1314 1324

  
1315 1325
    if (rtype == sd_illegal) {
1316 1326
        sd->card_status |= ILLEGAL_COMMAND;

Also available in: Unified diff