[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 56/67] hw/sd/sdcard: Add sd_cmd_ERASE handler (CMD38)
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 56/67] hw/sd/sdcard: Add sd_cmd_ERASE handler (CMD38) |
Date: |
Tue, 2 Jul 2024 11:20:39 +0200 |
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Message-Id: <20240628070216.92609-63-philmd@linaro.org>
---
hw/sd/sd.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index d517a00ee1..be9437141a 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -241,7 +241,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)
[21] = "DPS_spec",
[25] = "WRITE_MULTIPLE_BLOCK",
[26] = "MANUF_RSVD",
- [38] = "ERASE",
[40] = "DPS_spec",
[42] = "LOCK_UNLOCK",
[54] = "SDIO_RSVD", [55] = "APP_CMD",
@@ -1594,6 +1593,24 @@ static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_END(SDState
*sd, SDRequest req)
return sd_r1;
}
+/* CMD38 */
+static sd_rsp_type_t sd_cmd_ERASE(SDState *sd, SDRequest req)
+{
+ if (sd->state != sd_transfer_state) {
+ return sd_invalid_state_for_cmd(sd, req);
+ }
+ if (sd->csd[14] & 0x30) {
+ sd->card_status |= WP_VIOLATION;
+ return sd_r1b;
+ }
+
+ sd->state = sd_programming_state;
+ sd_erase(sd);
+ /* Bzzzzzzztt .... Operation complete. */
+ sd->state = sd_transfer_state;
+ return sd_r1b;
+}
+
static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
{
uint16_t rca;
@@ -1682,26 +1699,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
SDRequest req)
case 26: /* CMD26: PROGRAM_CID */
return sd_cmd_to_receivingdata(sd, req, 0, sizeof(sd->cid));
- /* Erase commands (Class 5) */
- case 38: /* CMD38: ERASE */
- switch (sd->state) {
- case sd_transfer_state:
- if (sd->csd[14] & 0x30) {
- sd->card_status |= WP_VIOLATION;
- return sd_r1b;
- }
-
- sd->state = sd_programming_state;
- sd_erase(sd);
- /* Bzzzzzzztt .... Operation complete. */
- sd->state = sd_transfer_state;
- return sd_r1b;
-
- default:
- break;
- }
- break;
-
/* Lock card commands (Class 7) */
case 42: /* CMD42: LOCK_UNLOCK */
return sd_cmd_to_receivingdata(sd, req, 0, 0);
@@ -2320,6 +2317,7 @@ static const SDProto sd_proto_spi = {
[35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional},
[36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
[37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional},
+ [38] = {5, sd_spi, "ERASE", sd_cmd_ERASE},
[50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional},
[52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional},
[53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional},
@@ -2363,6 +2361,7 @@ static const SDProto sd_proto_sd = {
[35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional},
[36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
[37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional},
+ [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE},
[43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional},
[44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional},
[45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional},
--
2.41.0
- [PULL 46/67] hw/sd/sdcard: Add sd_cmd_STOP_TRANSMISSION handler (CMD12), (continued)
- [PULL 46/67] hw/sd/sdcard: Add sd_cmd_STOP_TRANSMISSION handler (CMD12), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 47/67] hw/sd/sdcard: Add sd_cmd_SEND_STATUS handler (CMD13), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 49/67] hw/sd/sdcard: Add sd_cmd_SET_BLOCKLEN handler (CMD16), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 48/67] hw/sd/sdcard: Add sd_cmd_GO_INACTIVE_STATE handler (CMD15), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 50/67] hw/sd/sdcard: Add sd_cmd_READ_SINGLE_BLOCK handler (CMD17), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 52/67] hw/sd/sdcard: Add sd_cmd_PROGRAM_CSD handler (CMD27), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 51/67] hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 53/67] hw/sd/sdcard: Add sd_cmd_SET/CLR_WRITE_PROT handler (CMD28 & CMD29), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 54/67] hw/sd/sdcard: Add sd_cmd_SEND_WRITE_PROT handler (CMD30), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 55/67] hw/sd/sdcard: Add sd_cmd_ERASE_WR_BLK_START/END handlers (CMD32 & CMD33), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 56/67] hw/sd/sdcard: Add sd_cmd_ERASE handler (CMD38),
Philippe Mathieu-Daudé <=
- [PULL 57/67] hw/sd/sdcard: Add sd_cmd_LOCK_UNLOCK handler (CMD42), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 58/67] hw/sd/sdcard: Add sd_cmd_APP_CMD handler (CMD55), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 59/67] hw/sd/sdcard: Add spi_cmd_READ_OCR handler (CMD58), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 60/67] hw/sd/sdcard: Add spi_cmd_CRC_ON_OFF handler (CMD59), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 61/67] hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 62/67] hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 64/67] hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 63/67] hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 65/67] hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 66/67] hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42), Philippe Mathieu-Daudé, 2024/07/02