From patchwork Mon Oct 16 06:45:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 734024 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1045:b0:32d:baff:b0ca with SMTP id c5csp69907wrx; Sun, 15 Oct 2023 23:47:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2HIj3qG6wWYvgBntPnJAH21dSajeTp46Mexwd0m8T6qC6mJn6+eGKN+UaQbwZKfOIYIVX X-Received: by 2002:adf:f348:0:b0:32d:9b80:e2c6 with SMTP id e8-20020adff348000000b0032d9b80e2c6mr6091530wrp.26.1697438859700; Sun, 15 Oct 2023 23:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697438859; cv=none; d=google.com; s=arc-20160816; b=qAJeoT6ZTyIz/RGdhn85VRp2IxDIZREE43pHbNp0KKMr/RdhcOHFdxjmdu5VpzsOLo slYq8x13fiGZpH5fCKZGPDcag16Wv4jHPzA1lh9S1vAgxh4RIqaFD/bwIqbsyYJ/5qMi mtVRwhy0HiVB5UkYQoSP0Wl2GJGmvEh9W2sUSW2EPo/pVC/Jsf4EFqZaL4YT57zcGMho 0k5xmFltP3X/wPin+UTgX1dnvc5fmPNPW/t1A7CCr7sn5cTdmOWTzmyNE5PXmfLZ4Pjw IS8xHK5H2NuQbeDFGJKd6lrEQ0TKsx5qdI+N3eBNKFNmJ6wiJ+CNvJttUYVhtru7pN8+ SB/w== 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; fh=nGxKOXCACQSu1eN/ZPnZQwsIMUpKToCCLMDjTFnWWa4=; b=xaxoNW/0J8bQhkhGDI+bOKMg7KYyd11GDPyKmVd7UHnIJxu1fkFpp0IhFe1uqJDNrc G/b6sO0kEBj+gVXS5BUBmqsLILt6U+5c4vh131UD5WYD5b0I/wCwo00WXyMXvPghkSsh ljcbyuTgnFtEk6120aV6Zt4BVr3cd/AJZjojWna7FmdgSB6BoT3buDS9LsTXyplYSDRL AVvquShJI1kfxgnEN9etRblfvMDO7roqne2xGbT1mweYTR5uhMmWn7+feTubZRrSJcgg 4A2WBSnRDh9ns0Sb0CRWgGs/WGvrVFS/ClFZ8H4HwxYIPWK/Es76dV2Kzm5KdEEfFYDL Ft6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uxJZkQGi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id t7-20020a0560001a4700b0032dae6f547esi1128732wry.402.2023.10.15.23.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:47:39 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uxJZkQGi; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7ACF186DC6; Mon, 16 Oct 2023 08:47:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="uxJZkQGi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 189C786DE8; Mon, 16 Oct 2023 08:47:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (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 191118477A for ; Mon, 16 Oct 2023 08:46:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6b201a93c9cso2045296b3a.0 for ; Sun, 15 Oct 2023 23:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697438805; x=1698043605; darn=lists.denx.de; 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=uxJZkQGiINWYoTBGvoAKQauFg6+NdfGhiu7AqNf7qPzTX+ag2Mssau2GW+oVY+PKTQ k6DnTnVK85Ui2xAbTaO6h96KmJnpd9V1sVf1MQpj+ExuXM9IzW/UuP8IVcaaeqmNtz/e VRQxZYFVn5/sOEM6sA4y/1y8Buh8+hANXDwP/zeUYQSNfaPeTy5nggA2+JxGLqrBm9Ts 9VNO/rih96UsUig1hz/4rrNANUFEOsZniMOEmZpRaWiw0jP65cXjkRfZ1LkMo60NYBI3 S+8TJHyDMhwDSXAFOFqh8TlLtQr5OEU9HKqiWO1sm7kcEbR3J0rPgP6oQnzxozpFCW47 RiIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697438805; x=1698043605; 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=NXTGzQtf04g9ZIdkTc3z71lH3mzeoZl2FvILvOoWI+LlFVqctYWcbsPG8z6kfX8h/F VdJY5GJd/mK+3ljgomzflcKvKrZVYvCkTcA4Yp8gXvbCEN06aypQtVAbYwvbaSmG5f6R NEoaM0+c0LopIfd9oPCd12du80scg2zE113DJUk3U4Hoaa1TybJMLva8snlUnNksMqi8 38iJAq3JHPMK49OVLNGbzjT5eAms9ULJV6gqCzKiXsi24Bh+2nS1e1Jo03Myu5uhZHu0 k5e2t+sE1xmeY64YaLoEJyIFXuIYqvO2h613a47VTnYfzun5xHHA96YkQWNKjhSM186E P6qw== X-Gm-Message-State: AOJu0YwxqoUYy6rDDb7a0ToFmzH3Al+EmGtNbWh3wmBTBf0cz4cmDumW 62XnzUy7O9dyQ6/kwYRHfrWrAb2akSXoxS1TdZ0= X-Received: by 2002:a05:6a20:d41e:b0:16b:74bb:e57e with SMTP id il30-20020a056a20d41e00b0016b74bbe57emr21518838pzb.12.1697438805210; Sun, 15 Oct 2023 23:46:45 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h24-20020a170902ac9800b001c3be750900sm7760826plr.163.2023.10.15.23.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 23:46:44 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Tobias Waldekranz , Jaehoon Chung Subject: [PATCH v7 3/9] blk: blkmap: add ramdisk creation utility function Date: Mon, 16 Oct 2023 15:45:20 +0900 Message-Id: <20231016064526.2410856-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016064526.2410856-1-masahisa.kojima@linaro.org> References: <20231016064526.2410856-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean User needs to call several functions to create the ramdisk with blkmap. This adds the utility function to create blkmap device and mount the ramdisk. Signed-off-by: Masahisa Kojima Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- drivers/block/Makefile | 3 +- drivers/block/blkmap.c | 15 ---------- drivers/block/blkmap_helper.c | 53 +++++++++++++++++++++++++++++++++++ include/blkmap.h | 29 +++++++++++++++++++ 4 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 drivers/block/blkmap_helper.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..ec0575d135 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -14,7 +14,8 @@ obj-$(CONFIG_IDE) += ide.o endif obj-$(CONFIG_SANDBOX) += sandbox.o host-uclass.o host_dev.o obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o -obj-$(CONFIG_BLKMAP) += blkmap.o +obj-$(CONFIG_$(SPL_TPL_)BLKMAP) += blkmap.o +obj-$(CONFIG_$(SPL_TPL_)BLKMAP) += blkmap_helper.o obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c index 149a4cac3e..21201409ed 100644 --- a/drivers/block/blkmap.c +++ b/drivers/block/blkmap.c @@ -66,21 +66,6 @@ struct blkmap_slice { void (*destroy)(struct blkmap *bm, struct blkmap_slice *bms); }; -/** - * struct blkmap - Block map - * - * Data associated with a blkmap. - * - * @label: Human readable name of this blkmap - * @blk: Underlying block device - * @slices: List of slices associated with this blkmap - */ -struct blkmap { - char *label; - struct udevice *blk; - struct list_head slices; -}; - static bool blkmap_slice_contains(struct blkmap_slice *bms, lbaint_t blknr) { return (blknr >= bms->blknr) && (blknr < (bms->blknr + bms->blkcnt)); diff --git a/drivers/block/blkmap_helper.c b/drivers/block/blkmap_helper.c new file mode 100644 index 0000000000..0f80035f57 --- /dev/null +++ b/drivers/block/blkmap_helper.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * blkmap helper function + * + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include +#include + +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp) +{ + int ret; + lbaint_t blknum; + struct blkmap *bm; + struct blk_desc *desc; + struct udevice *bm_dev; + + ret = blkmap_create(label, &bm_dev); + if (ret) { + log_err("failed to create blkmap\n"); + return ret; + } + + bm = dev_get_plat(bm_dev); + desc = dev_get_uclass_plat(bm->blk); + blknum = image_size >> desc->log2blksz; + ret = blkmap_map_pmem(bm_dev, 0, blknum, image_addr); + if (ret) { + log_err("Unable to map %#llx at block %d : %d\n", + (unsigned long long)image_addr, 0, ret); + goto err; + } + log_info("Block %d+0x" LBAF " mapped to %#llx\n", 0, blknum, + (unsigned long long)image_addr); + + ret = device_probe(bm->blk); + if (ret) + goto err; + + if (devp) + *devp = bm_dev; + + return 0; + +err: + blkmap_destroy(bm_dev); + + return ret; +} diff --git a/include/blkmap.h b/include/blkmap.h index af54583c7d..0d87e6db6b 100644 --- a/include/blkmap.h +++ b/include/blkmap.h @@ -7,6 +7,23 @@ #ifndef _BLKMAP_H #define _BLKMAP_H +#include + +/** + * struct blkmap - Block map + * + * Data associated with a blkmap. + * + * @label: Human readable name of this blkmap + * @blk: Underlying block device + * @slices: List of slices associated with this blkmap + */ +struct blkmap { + char *label; + struct udevice *blk; + struct list_head slices; +}; + /** * blkmap_map_linear() - Map region of other block device * @@ -74,4 +91,16 @@ int blkmap_create(const char *label, struct udevice **devp); */ int blkmap_destroy(struct udevice *dev); +/** + * blkmap_create_ramdisk() - Create new ramdisk with blkmap + * + * @label: Label of the new blkmap + * @image_addr: Target memory start address of this mapping + * @image_size: Target memory size of this mapping + * @devp: Updated with the address of the created blkmap device + * Returns: 0 on success, negative error code on failure + */ +int blkmap_create_ramdisk(const char *label, ulong image_addr, int image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */