From patchwork Tue Jul 2 14:08:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 809126 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp235064wru; Tue, 2 Jul 2024 07:18:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUPZw4RCuhVsMr7V5vnC4buOu8X43xmpuo7ihacjB2MRQ4NRWakxgLaDiPBEeGGwU5NlmXZR9OWlINYVeUVmMmB X-Google-Smtp-Source: AGHT+IH7MXxnAhkjV2qkYjaBEkOGNL9FXCBwb4Sn8bpoBXX8UWEKYJw+Hw/5xGC8vkiFxzybnwfz X-Received: by 2002:adf:f787:0:b0:367:61ad:141b with SMTP id ffacd0b85a97d-36775699f7amr5265636f8f.2.1719929926308; Tue, 02 Jul 2024 07:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719929926; cv=none; d=google.com; s=arc-20160816; b=GIWZ7q6eiBRsJEqKDQSGCaB1F/jUeZJu2h8FynP+chcGn/Bd+DRudj3rSYccdctTFg g37QdL/drjDBRNFAQ6kZbtrgkZ0GruOLKAWhhVWAF2n+CQ7Zvay+RwUJomWzo/KaoXGX T/DzU1dfJmmkowRDixiWPOppbEL4KtFE0j4XG32aEkj5pUTLzp6p2o11+4v12SjZ3PKe 8+O7sQ4+UiJwzsA736nCfxELAmo4BSdkfsPhUck5nNKWApkFz7MskOr3HnON185WiUMY kt6/tsa/yGoxhgaD5mgNmCjJeIrgThc74ek0qv1RLdXhz16XBDMrTEZ6vBgTJnNeRRLY yq/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OvsDqyOLxb1We4xAO26ZSKOk+5yWllmPJC+X7Ugk7Rg=; fh=LVsaUFEsC7MmjYfghx2i5Xho5myMEweTOA0yrmdl6dk=; b=BFKwwl53lS3isIPQ8RUfLCKdXSXMZIZrMkI0lWNCv4hP4TumS4bYW6fYN37V2+FGx9 CINX70pfTksjqdQ6k2oE6IuyHGbOWsMf/Uyt/hkM2kRFc/29vmQJazz7VcWZGLAAkeEE FEStqOB3jPv4ow8439Lu87XqJ9inaZ30o823sMB70M1rXFye/6VlGb1nnSqIqG3dxMFX q/Sh+PCjiIPf3Apa5RMcz2K1ahs7Vj4QK6miy7FaJ3fua3/ZqLhZSJRn6y1yHxu8kIll Ugq1XKn1cabu7RiSxDtigtWduPU9EbzmBRSkujEVTcC1Wf0k0g/Osh/PO8Xi1VFFZvEK aimw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gWkO9/D9"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ffacd0b85a97d-3678811cbc6si774116f8f.516.2024.07.02.07.18.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 02 Jul 2024 07:18:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gWkO9/D9"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sOeCa-0000fj-Ly; Tue, 02 Jul 2024 10:09:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sOeCV-0000Cg-4O for qemu-devel@nongnu.org; Tue, 02 Jul 2024 10:09:46 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOeC7-0008Ke-88 for qemu-devel@nongnu.org; Tue, 02 Jul 2024 10:09:40 -0400 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-52cf4ca8904so6958824e87.3 for ; Tue, 02 Jul 2024 07:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719929355; x=1720534155; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OvsDqyOLxb1We4xAO26ZSKOk+5yWllmPJC+X7Ugk7Rg=; b=gWkO9/D9CN2GiRotl8BjLAwtu/J+BswaAdjFItiGpqxDRxbUSt2rdaAsrCeMIa+1v/ qRC/IzWuitgjq31nlDHH9Q/UZrySC+XjBP68SZFVuOSOoPfFG83tziOMHQLUaDMkqX9v TMnaKjaISUzh4NEsW7FNbvxbvIuiFDxTDPTJNyQ4X4e9xLv/zUnlWaIPpHO6a+QW8C0h uX3YuZVVM4ZG1ya11C8dQgcsERYZAwliWEFXCWNqjjYcCoYFwKjFjY75Epf3AeGUtNc5 6xPr5Bfe/sW/1BIQ4glYpzBP3XhwzzMut1sRZlQwBaf2Ar1FZS1ImQUzCFgdOu6kSHy7 arrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719929355; x=1720534155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OvsDqyOLxb1We4xAO26ZSKOk+5yWllmPJC+X7Ugk7Rg=; b=Ovmp3LiRlCPpU7p4bJnv3LmGHM1wanM1FF45ele7Ip2/ytYF3sRxXNpVoyetsaOROL A2rNCnbM/yL4JxliTj6FHrkIIKaCXmkbS9NM16V0fbQGsN6/hbJm6DxwNVDjPbdhKnO5 4TpK2HaTB5luijXISpx5X7OBkwPa6+cid4DuIlXiKPQCwdKAK2422OiLOnDa5PAeNEJE VVC5L/SnJou/CvD8Arq0ec1KfPYEdqMwi2YQA/pXf5+AVvZ0VIrKUTHu7/WJ39bGNCWR 170WKK0wEh/meTenDEYaghNRexnBkR/3eKcEd/cI7uN0w0DjRWV/PBPqKZNOS9Hdmg5t cNoA== X-Gm-Message-State: AOJu0YxWzMcuJCjO7NnUJBckdRSIKdlSs9eZvXNnqjFbvpXmSc72mblT zLf4NbkgX3kFjFx9Hj54Ga2hex70qce47KvZzA8paBndrvpQQfs+ulvfpDklIg0pzK25Gyi6I2W v X-Received: by 2002:a05:6512:2255:b0:52b:c0b1:ab9e with SMTP id 2adb3069b0e04-52e8264bc11mr6428691e87.5.1719929355583; Tue, 02 Jul 2024 07:09:15 -0700 (PDT) Received: from m1x-phil.lan ([176.187.209.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42588492b4fsm59489235e9.4.2024.07.02.07.09.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 02 Jul 2024 07:09:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Tyrone Ting , Paolo Bonzini , Hao Wu , Thomas Huth , Shengtan Mao , Chris Rauer , Joel Stanley , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Sai Pavan Boddu , Laurent Vivier , Luc Michel , Bin Meng , qemu-arm@nongnu.org, qemu-block@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Patrick Venture , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 4/4] hw/sd/sdcard: Generate random RCA value Date: Tue, 2 Jul 2024 16:08:42 +0200 Message-ID: <20240702140842.54242-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240702140842.54242-1-philmd@linaro.org> References: <20240702140842.54242-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::134; envelope-from=philmd@linaro.org; helo=mail-lf1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Rather than using the obscure 0x4567 magic value, use a real random one. Signed-off-by: Philippe Mathieu-Daudé Tested-by: Cédric Le Goater Reviewed-by: Cédric Le Goater --- 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 a48010cfc1..9443a9439d 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" @@ -490,9 +491,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) @@ -1103,11 +1105,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 724365efc3..f1281aecd3 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"