From patchwork Mon Nov 6 11:14:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 741340 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1027012wrr; Mon, 6 Nov 2023 03:17:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYV0lIBVWxosPZZCISVVKiwULjYI0jHzQ+ke46N+fNL8csdXLoRA7l4Yr+7TByzsnnFnfC X-Received: by 2002:a17:906:db0e:b0:9d3:8d1e:cee with SMTP id xj14-20020a170906db0e00b009d38d1e0ceemr14938157ejb.70.1699269455181; Mon, 06 Nov 2023 03:17:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699269455; cv=none; d=google.com; s=arc-20160816; b=SI8jH0rzZfNrZ3z/YaVkvZkdn2nHJzUk42xjxAYX/pX+jxJyyKbnSbeumpwyaMUttI ShGQ/SJHpqrApvXW8Vzf3wWMvgMN/fd1VwyItF16ekHf6S0GVRm2MLysHZ1N8pQbP6De NSRysmCg0g3DtTUE49IPOrpNy6CySRJ67Ou1EaYjF5vb815pDU2qe7hDMdRB5VOiXo4o wD4oNZt6MJ6lwQlIqSnM2cTDIk/aIvjoCG97qwkpAjB5fISsyASGaFgcJJBgt6lvO7Kk n+eEt8AR1FiT+5yJUq+issyuRKlMguRhBEEgJqtu6KmlWiNOf8ag6FdRfrFDszExWp6a 641A== 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=IW6UuW0tl+AFM9nTW8wKwyaIsXdRioIs6zkSPzK/8Ik=; fh=zqO2vTczeIKx1OTsr8uErpGVOeopTGT8suxWOXUGpbQ=; b=b03aTBh8kfTDXNBT/38JBmRvNZATMxYIfFWaqliwgbR9flEo5uq1j351leO7uo/8Zx 1a4dcZ6xM/KB7TnU033d1ciWvU9iumBsPBOtLcgtigaTNcX3eH7F26U1wb4EsSiWxtVP 1kOqe9T3R2T6/GuDRu2iq5HtTlxY9cIIcCsFtWtXwQT4ax5V4Ki+JzSk5G+0+bTxLem6 1Xa9ec5f9/DaDztu5Gh4XZ706dqt1mrxQFYvLU+E36RjzHutoYpw9fKPWBZeXG2DzO0Q kitpPfvN/nlmE4GQS/cq6jYd3JxucWjG421T1PHUPXW1st74FBouKEUJo6GMI6/WLH3A HqPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NSzOEAkk; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id di12-20020a170906730c00b009c7523e2b89si4109357ejc.12.2023.11.06.03.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:17:35 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NSzOEAkk; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 A210E86BEC; Mon, 6 Nov 2023 12:17:34 +0100 (CET) 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="NSzOEAkk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3EBD86FF2; Mon, 6 Nov 2023 12:17:04 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) (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 773B086FBD for ; Mon, 6 Nov 2023 12:16:48 +0100 (CET) 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-oi1-x22b.google.com with SMTP id 5614622812f47-3b2f5aed39cso2607546b6e.1 for ; Mon, 06 Nov 2023 03:16:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699269406; x=1699874206; 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=IW6UuW0tl+AFM9nTW8wKwyaIsXdRioIs6zkSPzK/8Ik=; b=NSzOEAkkQzT9SOEZRgtikVWbTPG5Ehz8is/fNPL5+Gxz1zdbWzEJBft7Mns3SWjzxK A3GdWhsEWQWjAF0C51JELFPI2ksPEr8QMIia+RSPX8DRA5dpqk1vK9byYk6jcMK2oah1 vHUpCMU10nqnvzjl/S10rgHfE1u6d90VWKhCpMzOZud7lRML5RWYhNruO25aOkq0UONd f2gOZ9X2YPYD2YlUgSyLzob/tKT7Y84y4dCruDhaw4STy9XKkeTxshIo57099wc0JnZ2 IYoyqDeCjab9bajtZWLNPoie9OeZDbnyzuv0kkiJvig65Wv31blPSpPBnTC1hKi+GVH7 V7AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699269407; x=1699874207; 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=IW6UuW0tl+AFM9nTW8wKwyaIsXdRioIs6zkSPzK/8Ik=; b=ABHl7e0jIJfS+73KSWkOY1EYC8076wvKgdQZFK+qutoaRXEU5BItDx44wdEA7CuD+W KYJCxlH4vzo9+t8rC3jHzeI7sskEddj5cRnRjlQem0Jkljdci1hW015NrVZO3f9h1OSn Lm4mKlycXkoCeGk4hdlyr5BDRaEccPgiR2yOqmHqb4dLc/1Fo2cDPOR8vVSWuoOud6YB Yy17Ax8aBW3jHdfKeuj4EhQcbyttn9VwZOZoPaaWFB/+iWkiZpO3E19q/B/d4Q3oecfE Hv4+ZunxHoeLO9kLuOJGpNboL835fk3Sq3+qsu0yJpIbUu36clpEacxjAOYSGTiVf/Cd L/IA== X-Gm-Message-State: AOJu0YxZu/c2FioB6nlj3k5l9Pr8WjbOJAlGxHxdWU7ma+Etl6jEUKoQ WPjf1FurO1lkU+SMg/Vz9WJTdG0B8GET1UO4rZs= X-Received: by 2002:a05:6358:3399:b0:16b:66d3:70af with SMTP id i25-20020a056358339900b0016b66d370afmr3938220rwd.7.1699269406698; Mon, 06 Nov 2023 03:16:46 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id e186-20020a6369c3000000b0057ab7d42a4dsm5331042pgc.86.2023.11.06.03.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:16:46 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Michal Simek , Masahisa Kojima , Tobias Waldekranz Subject: [PATCH v10 3/9] blk: blkmap: add ramdisk creation utility function Date: Mon, 6 Nov 2023 20:14:58 +0900 Message-Id: <20231106111504.3631058-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106111504.3631058-1-masahisa.kojima@linaro.org> References: <20231106111504.3631058-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..bfba14110d --- /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, ulong 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..30dc84a7da 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, ulong image_size, + struct udevice **devp); + #endif /* _BLKMAP_H */