From patchwork Wed Jul 10 14:14:08 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: 811782 Delivered-To: patch@linaro.org Received: by 2002:adf:ee12:0:b0:367:895a:4699 with SMTP id y18csp775763wrn; Wed, 10 Jul 2024 07:16:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXz6vZg/uAdjpFRijzGdVEKZvBTFr6Goh5chEmM3zLM8EGpJkIAcTm4SNdhCk6FIKDpzVfBPjpSfbg/imWUJWht X-Google-Smtp-Source: AGHT+IE8c9pCpPTwj3JHeCLt+1ol0Q2g7qIxyLzU2531f04LadrxniUVjQtvBPP089nJIs8viHWz X-Received: by 2002:a05:6870:71c4:b0:25e:129c:222b with SMTP id 586e51a60fabf-25eaec9626dmr4824367fac.57.1720620996309; Wed, 10 Jul 2024 07:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720620996; cv=none; d=google.com; s=arc-20160816; b=dpJd6xsy09CJ6DEYmxQualf72D/uNe6e8Wf1OyJhdccw1nUREVg2VZotzzMAKgsYFW U1+PrhkHii2ufTxPJPGK9g80A0k08FHAFHExBHwwnUfb1wEs0/3+dqfQJcFbO5TfHzCO 4QurcCFVvLcSnD6ywUiHlaRDDfq5wwh1PUp4ZJjnYXix1YzuKxuQc0NBVAQatlffsaJd sTXqKxGBIItvYOBo5A1bzohyGVKYf1Cxsmv5s207H9WDvo5wV6n0uXjqqeSshAuwoohV a4po6YtWmqFsPRABCEq+Fxrrfdq5qtAt+tatpfZi8R41U7s/rHvg6bBMUpVjj6COwuTd SvQA== 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=E592VUjNM/e32MWHdD7KwMvGh3P49D6D0LHQIn1oaLY=; fh=GH5Q+RtWzBCNH9E515TvTIpLJh2pWY/kifiV2Cu7nrY=; b=f7Ad9zXLFkKC+Rwe8F48ZVQ2/1sETjW2S5oSmX5EG2y2bugWDBqgq/G9Al+T2bMbh3 eVSwKmXfqM6/RW3n9VAkwNsapM1n8GlrNrR4JHEC1V3CyAiQs+zUUp65b8xvomkJ890/ Ij6NH6iYIMO3S35x0oi4MeojiDwZVoRs5vnFjF46AI00CFWYMtQwYhh1dopLzODYMG67 B8HZA8Lwid9CSJqYKqJJeSqzIbadNcxdH4urlAvQVh0IBuINNLo4qDBgBWYqmc6x0HQK /wDQVLRpwVkChBv7/8b/1zGNrGna8j9dG9iNI/Ea3EDvMo1rCKOF8Tr8J96XgtRp8nZO dVEQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f+gtcbBt; 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-79f190b6723si465455085a.415.2024.07.10.07.16.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Jul 2024 07:16:36 -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=f+gtcbBt; 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 1sRY7A-0005Xy-9b; Wed, 10 Jul 2024 10:16:12 -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 1sRY6m-0002DQ-GT for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:49 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sRY6W-0004Ek-AM for qemu-devel@nongnu.org; Wed, 10 Jul 2024 10:15:48 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-36798e62aeeso4244983f8f.1 for ; Wed, 10 Jul 2024 07:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720620926; x=1721225726; 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=E592VUjNM/e32MWHdD7KwMvGh3P49D6D0LHQIn1oaLY=; b=f+gtcbBtKrwwRBjIxCkoZUpe7GC7ZnimP78p8wUbldvdcJsZSlfJ1lfeuv5Fv7csd7 j1tnaooeo9r4NdmIY1rG1Hbfvn0voNLrW+wh2x7ymSjrSHE/vQmVfScFUmBVgITWd6qW 5Rl9ZTWOPVHyXzMnDdJG509cPB15xafckqg6DXWxd/6VPORYdCQeO50NW6XJTh37nI1B 0Rts45t/NjSp3RByiQrNs+W5BmwsMzo4/jSFFvj+0RZmi0vXkvpjy34BzNirYi8mCn7r IaJdySSbu0dZQ8GPQQY09Tq1Qujthdp+L9tRsD0GNmWD5y1hj3uAmvSEhJSpJzk8Y6uX avMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720620926; x=1721225726; 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=E592VUjNM/e32MWHdD7KwMvGh3P49D6D0LHQIn1oaLY=; b=tJObPlczPsaMIllKBPui7i3PsddqvfIuHss3VLru01kJSNTsvmtBrphPd1FypZ6RMM 2RUTAdUReRqKwq7mQgaw14fL6WCRwUv9bceBm0mwYxposZO+BLds2KPfjon98H33dLCg wht7SMrAzEAtNMQQNlZwau/iP/flHwXyhLozsG1WKfSWfVNKS7JTY4tbTlsrCFHTF9OI 0WbR8Ov0iFIDw+8TwURhvwXD6fsgnyM9B8mnns8pSNOOvUXnsjPfl0VnK/kzMUYU0tnq yo2pqMZ5AbcVJZSlJX/24riuEobPz8eBCzOg/onABM+jWqdQ7uK28zN/HL9HK0mFpi0x pfWw== X-Gm-Message-State: AOJu0Yz6ne2LamtLVdAn4FQRAPGWuDTLlyPEO0ljAdCkTlOiyNch72w2 Yh6kg8dx1TwqC+834Z/uAPIb2xAsKnTkczQe9GMc+LZoLHBA9IsAPyTRbW3YOoREaylGDK/U0xX h X-Received: by 2002:adf:fdc3:0:b0:367:8a2f:a6dc with SMTP id ffacd0b85a97d-367cead15b8mr3771606f8f.44.1720620926710; Wed, 10 Jul 2024 07:15:26 -0700 (PDT) Received: from m1x-phil.lan ([176.176.167.117]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367cdfab161sm5414331f8f.91.2024.07.10.07.15.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 10 Jul 2024 07:15:26 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Bin Meng , Steven Lee , Andrew Jeffery , Francisco Iglesias , Sai Pavan Boddu , Luc Michel , qemu-arm@nongnu.org, qemu-block@nongnu.org, Troy Lee , Jamin Lin , Peter Maydell , Joel Stanley , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= Subject: [PATCH v48 12/12] hw/sd/sdcard: Support boot area in emmc image Date: Wed, 10 Jul 2024 16:14:08 +0200 Message-ID: <20240710141408.69275-13-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240710141408.69275-1-philmd@linaro.org> References: <20240710141408.69275-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=philmd@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 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,format=raw Signed-off-by: Joel Stanley Signed-off-by: Cédric Le Goater Signed-off-by: Philippe Mathieu-Daudé --- hw/sd/sd.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 86b857d414..8c68494b8b 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -774,6 +774,40 @@ static uint32_t sd_blk_len(SDState *sd) return sd->blk_len; } +/* + * This requires a disk image that has two boot partitions inserted at the + * beginning of it. The size of the boot partitions is the "boot-size" + * property. + */ +static uint32_t sd_bootpart_offset(SDState *sd) +{ + bool partitions_enabled; + unsigned partition_access; + + if (!sd->boot_part_size || !sd_is_emmc(sd)) { + return 0; + } + + partitions_enabled = sd->ext_csd[EXT_CSD_PART_CONFIG] + & EXT_CSD_PART_CONFIG_EN_MASK; + if (!partitions_enabled) { + return 0; + } + + partition_access = sd->ext_csd[EXT_CSD_PART_CONFIG] + & EXT_CSD_PART_CONFIG_ACC_MASK; + switch (partition_access) { + case EXT_CSD_PART_CONFIG_ACC_DEFAULT: + return sd->boot_part_size * 2; + case EXT_CSD_PART_CONFIG_ACC_BOOT0: + return 0; + case EXT_CSD_PART_CONFIG_ACC_BOOT0 + 1: + return sd->boot_part_size * 1; + default: + g_assert_not_reached(); + } +} + static uint64_t sd_req_get_address(SDState *sd, SDRequest req) { uint64_t addr; @@ -806,6 +840,7 @@ static void sd_reset(DeviceState *dev) sect = 0; } size = sect << HWBLOCK_SHIFT; + size -= sd_bootpart_offset(sd); sect = sd_addr_to_wpnum(size) + 1; @@ -1029,6 +1064,7 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert) 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"); } @@ -1037,6 +1073,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"); }