From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10785C4338F for ; Thu, 19 Aug 2021 03:42:14 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 70BD76109E for ; Thu, 19 Aug 2021 03:42:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 70BD76109E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7704582F34; Thu, 19 Aug 2021 05:41:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="av0CVi/J"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9855782E7D; Thu, 19 Aug 2021 05:40:59 +0200 (CEST) Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A8B4C82DBC for ; Thu, 19 Aug 2021 05:40:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x22d.google.com with SMTP id be20so6619129oib.8 for ; Wed, 18 Aug 2021 20:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ux67w590QDVKr0FjTlpmQ37iUlVpFNNVk7OUug3mGZc=; b=av0CVi/JxKT08nCUI67JJYpeuU/xewBGo9hR0kMjYf8Iprwpt60vokXN1q3ITbjMjG m5tD904s0KFKfu8LiQzoJKT7nsXDjG36CHKAMTfzLZDITJPMcVbwZiTGuY3LeAoO3M+n wJQWOVNEI1wiHFqEi56M+JMQ7Jizz8SSMmUeA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ux67w590QDVKr0FjTlpmQ37iUlVpFNNVk7OUug3mGZc=; b=iwr5QzmpiqSuePyoXbee001knLTac2Efa552hl5Ll1srIVKAnTaCjSETD61yVwRhMW 3RTTjD5j/x47bCRGTN9Vr+M2FVp7rscf4eB07fb4+rCD1WJn1EM5fNJ88SwWr+bIEezJ mmiAKn2ajMohS8hOQrVEcVlI8m86kfnOwWopPgDmpMC38SWxVMY3fS/lLzv6u036Cz1d 2qBB4AYdYc57ijSvu5mEAQngYaDaRJfHIrVaXJOUyOwPD9LglXTjvPmSOmFL2QweEWee YSZ4FpTNw0AX3IeVPDh2X7d6hcambCpKT96TBL9zASTIdrilWVyo2dnqsC77zd9ohGgj 2Ueg== X-Gm-Message-State: AOAM5322yTPrpSXrv/tcqhtMN9AeY9aQ+dcsBGlAjcmSMCOtG+CcVSKx motlx2W/Ezrv18wqgZVV2ZRtW0WXzkBKng== X-Google-Smtp-Source: ABdhPJyesG0TuQ+Y696HankUJFutPuiK+i1Zz4hmZUi29wrXZYj62AiZJqT8cj3Sbv3NOV6h/DesrA== X-Received: by 2002:aca:e106:: with SMTP id y6mr1093124oig.62.1629344450061; Wed, 18 Aug 2021 20:40:50 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id q27sm415877oof.12.2021.08.18.20.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 20:40:49 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Jaehoon Chung , Peng Fan Subject: [PATCH 10/11] sandbox: mmc: Support a backing file Date: Wed, 18 Aug 2021 21:40:32 -0600 Message-Id: <20210818214022.10.I42087e8088f8d9fb704821d73f17d7ae246a2e69@changeid> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210819034033.1617201-1-sjg@chromium.org> References: <20210819034033.1617201-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Provide a way for sandbox MMC to present data from a backing file. This allows a filesystem to be created on the host and easily served via an emulated mmc device. Signed-off-by: Simon Glass --- doc/device-tree-bindings/mmc/sandbox,mmc.txt | 18 ++++++++ drivers/mmc/sandbox_mmc.c | 46 ++++++++++++++++---- 2 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 doc/device-tree-bindings/mmc/sandbox,mmc.txt diff --git a/doc/device-tree-bindings/mmc/sandbox,mmc.txt b/doc/device-tree-bindings/mmc/sandbox,mmc.txt new file mode 100644 index 00000000000..1170bcd6a00 --- /dev/null +++ b/doc/device-tree-bindings/mmc/sandbox,mmc.txt @@ -0,0 +1,18 @@ +Sandbox MMC +=========== + +Required properties: +- compatible : "sandbox,mmc" + +Optional properties: +- filename : Name of backing file, if any. This is mapped into the MMC device + so can be used to provide a filesystem or other test data + + +Example +------- + +mmc2 { + compatible = "sandbox,mmc"; + non-removable; +}; diff --git a/drivers/mmc/sandbox_mmc.c b/drivers/mmc/sandbox_mmc.c index 895fbffecfc..1139951c626 100644 --- a/drivers/mmc/sandbox_mmc.c +++ b/drivers/mmc/sandbox_mmc.c @@ -9,23 +9,26 @@ #include #include #include +#include #include +#include #include struct sandbox_mmc_plat { struct mmc_config cfg; struct mmc mmc; + const char *fname; }; -#define MMC_CSIZE 0 -#define MMC_CMULT 8 /* 8 because the card is high-capacity */ -#define MMC_BL_LEN_SHIFT 10 -#define MMC_BL_LEN BIT(MMC_BL_LEN_SHIFT) -#define MMC_CAPACITY (((MMC_CSIZE + 1) << (MMC_CMULT + 2)) \ - * MMC_BL_LEN) /* 1 MiB */ +#define MMC_CMULT 8 /* 8 because the card is high-capacity */ +#define MMC_BL_LEN_SHIFT 10 +#define MMC_BL_LEN BIT(MMC_BL_LEN_SHIFT) +#define SIZE_MULTIPLE ((1 << (MMC_CMULT + 2)) * MMC_BL_LEN) struct sandbox_mmc_priv { - u8 buf[MMC_CAPACITY]; + int csize; /* CSIZE value to report */ + char *buf; + int size; }; /** @@ -60,8 +63,8 @@ static int sandbox_mmc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, case MMC_CMD_SEND_CSD: cmd->response[0] = 0; cmd->response[1] = (MMC_BL_LEN_SHIFT << 16) | - ((MMC_CSIZE >> 16) & 0x3f); - cmd->response[2] = (MMC_CSIZE & 0xffff) << 16; + ((priv->csize >> 16) & 0x3f); + cmd->response[2] = (priv->csize & 0xffff) << 16; cmd->response[3] = 0; break; case SD_CMD_SWITCH_FUNC: { @@ -143,6 +146,8 @@ static int sandbox_mmc_of_to_plat(struct udevice *dev) struct blk_desc *blk; int ret; + plat->fname = dev_read_string(dev, "filename"); + ret = mmc_of_parse(dev, cfg); if (ret) return ret; @@ -156,6 +161,29 @@ static int sandbox_mmc_of_to_plat(struct udevice *dev) static int sandbox_mmc_probe(struct udevice *dev) { struct sandbox_mmc_plat *plat = dev_get_plat(dev); + struct sandbox_mmc_priv *priv = dev_get_priv(dev); + int ret; + + if (plat->fname) { + ret = os_map_file(plat->fname, OS_O_RDWR | OS_O_CREAT, + (void **)&priv->buf, &priv->size); + if (ret) { + log_err("%s: Unable to map file '%s'\n", dev->name, + plat->fname); + return ret; + } + priv->csize = priv->size / SIZE_MULTIPLE - 1; + } else { + priv->csize = 0; + priv->size = (priv->csize + 1) * SIZE_MULTIPLE; /* 1 MiB */ + + priv->buf = malloc(priv->size); + if (!priv->buf) { + log_err("%s: Not enough memory (%x bytes)\n", + dev->name, priv->size); + return -ENOMEM; + } + } return mmc_init(&plat->mmc); } -- 2.33.0.rc1.237.g0d66db33f3-goog