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.1 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 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 EA27DC433F5 for ; Sat, 18 Sep 2021 09:35: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 38FE461212 for ; Sat, 18 Sep 2021 09:35:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 38FE461212 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 E5E2182D1C; Sat, 18 Sep 2021 11:35:11 +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="I5hsYb4d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4D8A782849; Sat, 18 Sep 2021 11:35:09 +0200 (CEST) Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) (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 1517382849 for ; Sat, 18 Sep 2021 11:35:04 +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@google.com Received: by mail-vs1-xe36.google.com with SMTP id z62so11753589vsz.9 for ; Sat, 18 Sep 2021 02:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ePcSlT1cT4Yd5dOy+XL6Wq7BefBQKutV6/8rhndHtdk=; b=I5hsYb4dSiyi24zpRtA+17bvtO/WoKFd+1nzxugPI/jmuqWtF/yhE53aRngHEqSRCW XuRNKYlbNKM8US1dTwe7tjGMh59xJvqVXAMEfrhvgJHcjtbmUPVbr3sySZ9Dzx6uMyWz nMvYcbMsGkC98ZkeFnHV+ttEC7D5RbJA5HdVU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ePcSlT1cT4Yd5dOy+XL6Wq7BefBQKutV6/8rhndHtdk=; b=H9wOvu+FVAQvyt1uxg2dHrEUZW8qMratl4w59k64f8qCBzEw8fk1xS8LVD7uiKLPwd yYjVUkZ2/e1a4Yr+WZSUbS2fB7oZ/ynWqv91lBg4W90eVNuwQuRxL07jHX8PcvTsFBPC q9ihgqSNJ3KpnUJXEzJQCJVqQ/v2A2fWVvRcfkLUjrqymPjVuV88EFCjZ4k0AQsrkvIz qaPweIw4dL250MV+89Q7NSfvjDU/rC9AfUntZYD0j4FGkxiXtyvSu1M6nN6sxS9BQoL2 BsW33ICCP+HWvNA4s1dyYs93HB/Nh2RO9+J5oGf1A1AiU9SG0U4PxDCpqrBfc8v3NBtM 6CMg== X-Gm-Message-State: AOAM532Zu9bxwlhygtZQiMPJL04koPaunhxHYp6j/zUBGaIjSslG5fRR +SwpRhFjfIQ5D8NwlGOVTOsOC+F+RCh5Qqjm4VKjGK26yDGmxRYAUus= X-Google-Smtp-Source: ABdhPJwoSUYw/TybebbLqrKu5B1M3XSGx1r2jqham/JXNKkVXmCrGJRBRQavFtW68YIjJYbUCzgjE9eF1reBu9gndjc= X-Received: by 2002:a05:6102:3a59:: with SMTP id c25mr11329778vsu.15.1631957702604; Sat, 18 Sep 2021 02:35:02 -0700 (PDT) MIME-Version: 1.0 References: <20210819034033.1617201-1-sjg@chromium.org> <20210818214022.10.I42087e8088f8d9fb704821d73f17d7ae246a2e69@changeid> <3a1dac7e-71c8-3a0d-e3b6-c2e809cad60e@gmail.com> In-Reply-To: <3a1dac7e-71c8-3a0d-e3b6-c2e809cad60e@gmail.com> From: Simon Glass Date: Sat, 18 Sep 2021 03:34:50 -0600 Message-ID: Subject: Re: [PATCH 10/11] sandbox: mmc: Support a backing file To: Sean Anderson Cc: U-Boot Mailing List , Jaehoon Chung , Peng Fan Content-Type: text/plain; charset="UTF-8" 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 Hi Sean, On Sat, 28 Aug 2021 at 00:39, Sean Anderson wrote: > > On 8/18/21 11:40 PM, Simon Glass wrote: > > 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 > > Can we stick this in the command line arguments somehow? For testing > with different images, I think that editing the device tree is not the > best way to do things. It also makes it trickier to add automated tests. We can, of course. We used to have that with SPI flash but we ended up dropping it as it was unwieldy and disconnected from the devicetree . The automated tests can work by setting up a file in advance. In fact we do this with SPI flash and I2C eeprom. So I think this works much better. See dm_test_spi_flash() for how the file is set up in a unit test. > > > + > > + > > +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; > > nit: to save a whole 2 bytes on 64-bit you can reorder this like > > char * > int > int OK will do. > > > }; > > > > /** > > @@ -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; > > Won't this cut off the end of the file? If we can't avoid this, we > should at least warn the user that we are truncating it. Yes it does and in fact the granularity is 1MB, I think. I can add a warning. > > --Sean > > > + } 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); > > } > > > Regards, Simon