From patchwork Fri Jun 28 07:02:12 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: 808214 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp225374wrr; Fri, 28 Jun 2024 00:15:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUsLBt9/uCCX+aEj8vfzUkT2/i4wuIOGOC0gCOCa7j8yoCc+w15n+zoNrNo2zxZp50skl/Sd4eI39GCH4i8iBQW X-Google-Smtp-Source: AGHT+IGMFaoW0DytGbbNg09sReqpyKxmrUkchORXHvKubLiiUOUQCPEuxkHVXgVzPSdAZX4PyGJS X-Received: by 2002:a67:f1d8:0:b0:48f:46ff:7b64 with SMTP id ada2fe7eead31-48f4eef0dacmr13655045137.9.1719558928717; Fri, 28 Jun 2024 00:15:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719558928; cv=none; d=google.com; s=arc-20160816; b=aJKKUlBh77z4CWRnNMPcR2jjbqQpKc/wNDuOOeZbZn87IGamS9xq0gP2nNS4DPr48r LcPJeFi91Tt66VfFoJM5q5HabeeEuf6FLsba7KaWy6rWjWeAB+Ff3Aj6c7HvCDZlkzIQ VBHYvoYTdeHyY2nCpKasE1AFC++/KnV8pFgR9WJeOEGoT2T/jz7b853zSLFvL/sW01rk DD6uYuTX6RudCqxr1BKyP562HrawvO824smIgLwIR4KqQfM2WhL5vHQ9SU+b57qedMXc iiZp8lohPufb2MktAiPhevrFpL0TUWTAdNBd15IKPxF1aBYARfanmPtBAldRFrPJRj3+ vKtA== 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:to:from :dkim-signature; bh=cc2phwHICPbHNDUMxZA6a+9UcWAynLl1hqKHKReAlY0=; fh=Vqz0ILX7NeXJwCG5xiS+Wtk94IhOmAmLtOfN3kRbil4=; b=xmzvjHmD/CZonUNNFECyN74/3CD0cgZAhAkPQmrmvHplMBmtLRfJkMtuqsQkRvipIQ MgCNedLd3psGQ+5KUca0QdHy3arq3N24BOzn1BodKO3rpUXMzvwfEIXBkXwiBaIzdtLS KOHyNaXgfhC2Fk07Qf++IDGx/tAWXWGSNvhhEqKXaZJci7bIiUeRmt54kgbLgRHjikWK ka0L92dHtaJrBxeLemsXv401i2UokPRQz9g2qAUp83UoOc9dLYIKCqX3r77C+arfVrnN ISMNWR03neHUdrhOdccmLvNlkiVezxkwN8m2WxeJK7Jgzehy545kzuVe1wXbZGrCiXCN 3lPw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Szb2It4p; 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 af79cd13be357-79d6933d40csi119889485a.670.2024.06.28.00.15.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Jun 2024 00:15:28 -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=Szb2It4p; 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 1sN5lq-0004DF-09; Fri, 28 Jun 2024 03:11:46 -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 1sN5lj-0003x0-9N for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:11:39 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN5le-0004xh-PA for qemu-devel@nongnu.org; Fri, 28 Jun 2024 03:11:36 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4248ea53493so1787455e9.3 for ; Fri, 28 Jun 2024 00:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719558692; x=1720163492; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cc2phwHICPbHNDUMxZA6a+9UcWAynLl1hqKHKReAlY0=; b=Szb2It4pksVK/1SYB6AxRhN1oymqeuzwCqLIBfqZxi8eUCdWF+FAQTBwnUgRKIxGKC cNdH3/dxx0wrRnajRfdAJ1W4JVp734Qu9LB0UcZiLsfmolucVdkWM6Yv4Ash2QM8Bsfj DG4P4EG/mLIKMQ5FjOgV5sPUAh31+t9IBJxrNBqTNkGFhjf2dRbwiDYHFhm4rkxM8plI OnEfoHdmRb3KbmmOTPhHNv91lVNtINodMg4K6G5ivUdAhg6hU0BQiP+lyMx3rz3E0Jbo rWP32HVUr2p2/Zfix0rtOqrpNpXDsosI9PFPQ3i0m7qpdE7Rvz4CXgGnNbmCjZRLbIc2 zn9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719558692; x=1720163492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cc2phwHICPbHNDUMxZA6a+9UcWAynLl1hqKHKReAlY0=; b=NjrUivHNw4aVSCRe8irlxysUhvLEA9MFiYpx757zZlWiFh6P7F2DlOqPP1RMGniCSA LlkyW55gQwzlajUhBe5SKr442TOL9YM3H4aphGQUnZarOX9VWRsj7zlqVCENp4/LsDbx b9eUV+fMnloaMInt3BbbSwtNX0CYRBRZesPGNxe3kj0hZQa0gHWTG3K/XHG4L+4NrtEO G0ez8+jbAfkG8ttyUr7DBQJmy1L+q/+O3VR/HxwlH9Nw293acUYTjwQ/ByDYgccN6Dbc 0N3klRONLgnvRlEq4doTc54hIbHphRpxSSDrcoJcESoSBY+VOxCDsVnjqi9Znb7TQIpx GseA== X-Gm-Message-State: AOJu0YyyS81o0Jj3fSBNHOlzvTCBJAPuC0ohaT5iEU1pgocgicynLb6H GqMCDo2Gr/h+XOLyAypP5GwuaC5VWDi+TW+t9xtgSdQyVLfeZIaAQCs9CeepQ/YfD6mfGb6Brs8 d40Q= X-Received: by 2002:a05:600c:470d:b0:422:7eca:db41 with SMTP id 5b1f17b1804b1-4248cc18101mr123694015e9.2.1719558692742; Fri, 28 Jun 2024 00:11:32 -0700 (PDT) Received: from m1x-phil.lan (cho94-h02-176-184-4-239.dsl.sta.abo.bbox.fr. [176.184.4.239]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a0e16a8sm1343948f8f.64.2024.06.28.00.11.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 28 Jun 2024 00:11:31 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [RFC PATCH v42 96/98] hw/sd/sdcard: Support boot area in emmc image Date: Fri, 28 Jun 2024 09:02:12 +0200 Message-ID: <20240628070216.92609-97-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240628070216.92609-1-philmd@linaro.org> References: <20240628070216.92609-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=philmd@linaro.org; helo=mail-wm1-x32b.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 From: Joel Stanley This assumes a specially constructed image: dd if=/dev/zero of=mmc-bootarea.img count=2 bs=1M dd if=u-boot-spl.bin of=mmc-bootarea.img conv=notrunc dd if=u-boot.bin of=mmc-bootarea.img conv=notrunc count=64 bs=1K cat mmc-bootarea.img obmc-phosphor-image.wic > mmc.img truncate --size 16GB mmc.img truncate --size 128MB mmc-bootarea.img For now this still requires a mtd image to load the SPL: qemu-system-arm -M tacoma-bmc -nographic \ -global driver=sd-card,property=emmc,value=true \ -drive file=mmc.img,if=sd,index=2 \ -drive file=mmc-bootarea.img,if=mtd,format=raw Signed-off-by: Joel Stanley Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- include/hw/sd/sd.h | 1 + hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h index d35a839f5e..07435d2e17 100644 --- a/include/hw/sd/sd.h +++ b/include/hw/sd/sd.h @@ -132,6 +132,7 @@ struct SDCardClass { bool (*get_readonly)(SDState *sd); void (*set_cid)(SDState *sd); void (*set_csd)(SDState *sd, uint64_t size); + uint32_t (*bootpart_offset)(SDState *sd); const struct SDProto *proto; }; diff --git a/hw/sd/sd.c b/hw/sd/sd.c index e7d8b9c0fb..2d49be61f6 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -783,6 +783,12 @@ static inline uint64_t sd_addr_to_wpnum(uint64_t addr) return addr >> (HWBLOCK_SHIFT + SECTOR_SHIFT + WPGROUP_SHIFT); } + +static unsigned sd_boot_capacity_bytes(SDState *sd) +{ + return sd->ext_csd[EXT_CSD_BOOT_MULT] << 17; +} + static void sd_reset(DeviceState *dev) { SDState *sd = SD_CARD(dev); @@ -984,9 +990,40 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) qemu_set_irq(insert, sd->blk ? blk_is_inserted(sd->blk) : 0); } +/* + * This requires a disk image that has two boot partitions inserted at the + * beginning of it. The size of the boot partitions are configured in the + * ext_csd structure, which is hardcoded in qemu. They are currently set to + * 1MB each. + */ +static uint32_t sd_emmc_bootpart_offset(SDState *sd) +{ + unsigned int access = sd->ext_csd[EXT_CSD_PART_CONFIG] & + EXT_CSD_PART_CONFIG_ACC_MASK; + unsigned int boot_capacity = sd_boot_capacity_bytes(sd); + + switch (access) { + case EXT_CSD_PART_CONFIG_ACC_DEFAULT: + return boot_capacity * 2; + case EXT_CSD_PART_CONFIG_ACC_BOOT0: + return 0; + case EXT_CSD_PART_CONFIG_ACC_BOOT0 + 1: + return boot_capacity * 1; + default: + g_assert_not_reached(); + } +} + +static uint32_t sd_bootpart_offset(SDState *sd) +{ + SDCardClass *sc = SD_CARD_GET_CLASS(sd); + return sc->bootpart_offset ? sc->bootpart_offset(sd) : 0; +} + static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) { trace_sdcard_read_block(addr, len); + addr += sd_bootpart_offset(sd); if (!sd->blk || blk_pread(sd->blk, addr, len, sd->data, 0) < 0) { fprintf(stderr, "sd_blk_read: read error on host side\n"); } @@ -995,6 +1032,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) { trace_sdcard_write_block(addr, len); + addr += sd_bootpart_offset(sd); if (!sd->blk || blk_pwrite(sd->blk, addr, len, sd->data, 0) < 0) { fprintf(stderr, "sd_blk_write: write error on host side\n"); } @@ -2833,6 +2871,7 @@ static void emmc_class_init(ObjectClass *klass, void *data) dc->realize = emmc_realize; sc->proto = &sd_proto_emmc; sc->set_csd = sd_emmc_set_csd; + sc->bootpart_offset = sd_emmc_bootpart_offset; } static const TypeInfo sd_types[] = {