[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v42 16/98] hw/sd/sdcard: Generate random RCA value
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v42 16/98] hw/sd/sdcard: Generate random RCA value |
Date: |
Fri, 28 Jun 2024 09:00:52 +0200 |
Rather than using the obscure 0x4567 magic value,
use a real random one.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Cédric Le Goater <clg@redhat.com>
---
hw/sd/sd.c | 11 ++++++++---
hw/sd/trace-events | 1 +
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 5997e13107..d85b2906f4 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -46,6 +46,7 @@
#include "qemu/error-report.h"
#include "qemu/timer.h"
#include "qemu/log.h"
+#include "qemu/guest-random.h"
#include "qemu/module.h"
#include "sdmmc-internal.h"
#include "trace.h"
@@ -488,9 +489,10 @@ static void sd_set_csd(SDState *sd, uint64_t size)
/* Relative Card Address register */
-static void sd_set_rca(SDState *sd)
+static void sd_set_rca(SDState *sd, uint16_t value)
{
- sd->rca += 0x4567;
+ trace_sdcard_set_rca(value);
+ sd->rca = value;
}
static uint16_t sd_req_get_rca(SDState *s, SDRequest req)
@@ -1113,11 +1115,14 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd,
SDRequest req)
/* CMD3 */
static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req)
{
+ uint16_t random_rca;
+
switch (sd->state) {
case sd_identification_state:
case sd_standby_state:
sd->state = sd_standby_state;
- sd_set_rca(sd);
+ qemu_guest_getrandom_nofail(&random_rca, sizeof(random_rca));
+ sd_set_rca(sd, random_rca);
return sd_r6;
default:
diff --git a/hw/sd/trace-events b/hw/sd/trace-events
index 43eaeba149..6a51b0e906 100644
--- a/hw/sd/trace-events
+++ b/hw/sd/trace-events
@@ -43,6 +43,7 @@ sdcard_response(const char *rspdesc, int rsplen) "%s (sz:%d)"
sdcard_powerup(void) ""
sdcard_inquiry_cmd41(void) ""
sdcard_reset(void) ""
+sdcard_set_rca(uint16_t value) "new RCA: 0x%04x"
sdcard_set_blocklen(uint16_t length) "block len 0x%03x"
sdcard_set_block_count(uint32_t cnt) "block cnt 0x%"PRIx32
sdcard_inserted(bool readonly) "read_only: %u"
--
2.41.0
- Re: [PATCH v42 11/98] hw/sd/sdcard: Simplify sd_inactive_state handling, (continued)
- [PATCH v42 10/98] hw/sd/sdcard: Assign SDCardStates enum values, Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 12/98] hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6), Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 14/98] hw/sd/sdcard: Extract sd_blk_len() helper, Philippe Mathieu-Daudé, 2024/06/28
- [NOTFORMERGE PATCH v42 15/98] tests/qtest: Disable npcm7xx_sdhci tests using hardcoded RCA, Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 13/98] hw/sd/sdcard: Add direct reference to SDProto in SDState, Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 16/98] hw/sd/sdcard: Generate random RCA value,
Philippe Mathieu-Daudé <=
- [PATCH v42 17/98] hw/sd/sdcard: Introduce definitions for EXT_CSD register, Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 18/98] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte, Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 19/98] hw/sd/sdcard: Convert SWITCH_FUNCTION to generic_read_byte (CMD6), Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 20/98] hw/sd/sdcard: Convert SEND_CSD/SEND_CID to generic_read_byte (CMD9 & 10), Philippe Mathieu-Daudé, 2024/06/28
- [PATCH v42 23/98] hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19), Philippe Mathieu-Daudé, 2024/06/28