From patchwork Fri Jul 5 22:04:22 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: 810439 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1775095wru; Fri, 5 Jul 2024 15:05:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUHRpJchKZLsYbHu6Jdu6kMYBZyGKVzHF6AtZdzXKx9kPu+wjgN80/P1HUyOHUwFptLYciWfltzy36T4IY3L0Fz X-Google-Smtp-Source: AGHT+IG5aWI6vgxoXs7tjRRcdsVfPVfYLKCiMMSyuLEtaF8hUtwv560+e6BrzUE5n6IV5Ts4h+I3 X-Received: by 2002:a05:6214:1253:b0:6b5:d311:962 with SMTP id 6a1803df08f44-6b5ecfa8604mr75443526d6.22.1720217123513; Fri, 05 Jul 2024 15:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720217123; cv=none; d=google.com; s=arc-20160816; b=sF8m92uhbNo+W4spDRUlzZPm7cjr6Vn/ltqGXE9EeCv0dEKtWvBPeklpcwYMgfsMPm 2+irsL8EVYUFcTlDB8SkyTjyaTDaMJM10vrze4rowlo/ZWSvp6KTqw/Xz84P6MPQNuWz T46DyQdQClA6KlbTXIWIRhNIQjISA7TQxvYCWSwzw1+xcEIhq1EUvhzsr8Es2ZhsVzkE vQ/wmdDBCtt5SbFS5bIr7EuS+wcfFia7QaHhAb+eSPT90pwoo7Oq/8rCz+VVZxkga9vp cpCVgGwN6PdyYgGPwBljpHWXZQP1eqZvBSAynxay9st8Wjh9WXVrl3PxJh2xkQbZPOZo toug== 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=E7r9/bwMA7Y9aC77VYKrC6dcppuacEWAp1H+HkEgQaQ=; fh=8ly4dktE5qX7scQRc1qmWVsO0MVOdxfDtQTaDzdLLVc=; b=1H9oMzQYhlc63InImtoJrQIitDipmnIYrQng1axDALgBKbVMCJhZbvmliYy9mUDy/i uJJ0Rg3kgF0zU+tANIlwfV7ke84auFn2NWmHN+/J36mEScKeTnc/UOR6omIlOm1yerAp fbzPnUQaJHYWJ2MnaK8rIGeAJ7gb++d1QHKxlOJDpyO+GW1s+esW4Wt6qlRZ86Hem+F+ n7R6WwGqE5yyztA23YG8IcnqiSZ2a5O2IoWAS79fZtRJa7hilGN2o0+Fo1TCCjK+YzVX K/dJ2IHrurkc0YNflvBC6tIqfYqTLdswOpdJ0xkgqZYoSYRStfR0lUEOrkGLKflEqfPH QE+g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nE6thAv/"; 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 6a1803df08f44-6b5f2cc873asi31869276d6.113.2024.07.05.15.05.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Jul 2024 15:05:23 -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="nE6thAv/"; 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 1sPr3B-0001si-Pa; Fri, 05 Jul 2024 18:05:06 -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 1sPr39-0001qH-Mu for qemu-devel@nongnu.org; Fri, 05 Jul 2024 18:05:03 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPr37-0007Bm-CF for qemu-devel@nongnu.org; Fri, 05 Jul 2024 18:05:02 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-367963ea053so1574076f8f.2 for ; Fri, 05 Jul 2024 15:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720217098; x=1720821898; 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=E7r9/bwMA7Y9aC77VYKrC6dcppuacEWAp1H+HkEgQaQ=; b=nE6thAv/gtU5DRGDUnUYdqpI9zF8utS6clazL6K6RAMMdYJG+zW4r/Yre5hZ3DrRB/ i/fR5mQxrmpNKc4YfOtirXxHlnM2sUC2XaZJilvMuxlRUGUvULrNteoEfB5d1okoTul+ EoUsv5pBJe3hFwVwpfMN3TUKdOZcFJXSXv2n0XlwZJoBh7JqDGMOOi8nTzTjNcnRN9CQ ZPW4EuEdyGpwD0q2xh2q06peLJTr4JjHG1KOXJCwus+J2d7QBnMBXy7Hi6wuf2YG/ICs s4W53EJl/E+i/gNyuo+usjsKqmmm5DWZM3vgbqquvJIcYF2ySAi8Xpyb1MXtLEDGkkMK toOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720217098; x=1720821898; 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=E7r9/bwMA7Y9aC77VYKrC6dcppuacEWAp1H+HkEgQaQ=; b=DYiBruBF8BSZ1g1bQDoVVa+O387B16gNdyolpLlpiqmLpKErdZg2FXjJRuqy9gux2G XsmjEsagX/q15uMbqiE4Md8BqMSKiwUCzmIynlvk4DB7hscNywqEoN044F4olVh7wKh0 d1BEHE/baiSyDZeYtf5UueUDboRea9PIqnpZXrZ8rbl1lUI0y6F+70snzEMK6HvBlGMz w6IXkrrxmj69peYFjIlwcQBVK7Nd3/ZZAj/gNm5Ct0aA4/Lxh6WytPjwEWDWVZR5djwB EQ5qjZ+uBRlKdM1ZN15zPfJWr3L1bDbdCuSWNjJEMD4NF/DoTaduZS0zSyVD6m2VKakO 15og== X-Gm-Message-State: AOJu0Yx4ZBSOPT71josD8lRwrG+jqebclYLe8+foEF8y3IvSvkQpqToi cWYBf1GShpE+xtYtcK0wMQXmBIV8jh+GVseqVyAb4rKkULW0eqK2czF09nRrEQf1wP1UkDBNszM 5 X-Received: by 2002:a5d:4745:0:b0:367:8de4:84ef with SMTP id ffacd0b85a97d-3679dd31158mr4923237f8f.30.1720217098129; Fri, 05 Jul 2024 15:04:58 -0700 (PDT) Received: from m1x-phil.lan ([176.176.163.129]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367a8d74e0bsm2700480f8f.52.2024.07.05.15.04.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 05 Jul 2024 15:04:57 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Andrew Jeffery Subject: [PULL 04/16] hw/sd/sdcard: Generate random RCA value Date: Sat, 6 Jul 2024 00:04:22 +0200 Message-ID: <20240705220435.15415-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240705220435.15415-1-philmd@linaro.org> References: <20240705220435.15415-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philmd@linaro.org; helo=mail-wr1-x432.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=ham 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 Tested-by: Andrew Jeffery Message-Id: <20240702140842.54242-5-philmd@linaro.org> --- 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 552957b2e5..b158402704 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" @@ -515,9 +516,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) @@ -1212,11 +1214,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"