From patchwork Fri Nov 10 04:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742839 Delivered-To: patch@linaro.org Received: by 2002:a5d:67cf:0:b0:32d:baff:b0ca with SMTP id n15csp12477wrw; Thu, 9 Nov 2023 20:28:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzGy6zVW/DPUPpfxM5HxHUG4za2zoISZXBwH1OIcsBszdHG/OHz5rqZVlpXjzx8k5VcaJX X-Received: by 2002:a50:baa7:0:b0:53e:7f73:dfbe with SMTP id x36-20020a50baa7000000b0053e7f73dfbemr5940596ede.11.1699590502927; Thu, 09 Nov 2023 20:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699590502; cv=none; d=google.com; s=arc-20160816; b=tB90Vcg8bWzTDtpHzzJbl04jOW4yZVZB7nOLqFVG3PkL7kPQdK4+2sZYUOsq3kVnCb YKRnhheQJrz9/rrMDgSX/BLywkaSp6BejCb269jT0j4bYMnp1oVYqNLw83XzocqUCClb Nsv4cI6ybmK5bNikZldFbxMoBuRIVdUZgN+XYKfqe2pmXHcyOmcO2QfcXqdNnWrRCwmb 4lFgxKrBPq4UhxFjM0uG6MDEcG1xIW5ipjj/rcT6VPRZnYOnhCJbVgB0UpkkQHmtIatC n5LmvnIMaVw2pwf1V7bdA+EgvIWcoCYmes5aQD96QPh8VmWaETA9Z0BbsHz/wAPobnR2 LHug== 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=QYvUuH3FVVoMRY0zdqPyuz3mbSsJykXVGb06Vx0ehSqNuwLoSdpiTBr2Y80AfWfhGr f8pj5jigLWOgjehiQISFOjJ1VrqTGk3zQcSsX0oxTbuOKZLjkFnHIAsX8ateu7BVjg09 SAOuWew22UVXsv4zU2FRB6EPEbEDcbJBvTRXdRtl3YqGHJX+g0uemBSeQ8YRJkWJZ91i 43dl+6lGagwtDwYiUfjL72vkpatZD3YKeEMK7YR7maVIoVMl1wnsaQzJAnUhBBTCi3t9 XmW8srWeNN/PAzeBN4L0UyeYRBshBnyELFxmpxbq9kTCMzD4BVWZLkzyvbYKE9ZBQix8 5uhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ln3k0mF2; 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 q24-20020a50aa98000000b0054349f66a11si8210614edc.601.2023.11.09.20.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 20:28:22 -0800 (PST) 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=Ln3k0mF2; 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 53B6E87790; Fri, 10 Nov 2023 05:27:26 +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="Ln3k0mF2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C156287799; Fri, 10 Nov 2023 05:27:24 +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-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (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 6AB2287779 for ; Fri, 10 Nov 2023 05:27:20 +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-pf1-x431.google.com with SMTP id d2e1a72fcca58-6b20577ef7bso1519318b3a.3 for ; Thu, 09 Nov 2023 20:27:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699590436; x=1700195236; 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=Ln3k0mF2jlGwmqE5KDizpAMtYIUM7YQTzPNdu2m9o7e7ZZqcXf7DLXrBVNj8FOi7C9 qgXQudcvCTX+sK8QI6JEfR+34wz3N7L7McpeD6BlCONjshSRKVLwljUja1zqibp8c+YW FTYtM96UPk7KpSjuNSPgXVfx/sUFbhNAW7TS/3QOIXvQxtvwOTEHiURAkyuaPPIGoabW 2QtG0Wz29SMd19G6F3ZdFYgks2I3frq+NuYGdly3kzJ1v0a0tQ1Ry6RZXEC388H/RMI0 h4iIgWIoSf+O3MvSim3G215GSb3SylGNlXSHLL0ZaIfA2bnSPd4ZBYPrm+YZkOdWFSXu jIPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699590436; x=1700195236; 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=xMkssXuWZyAfhgG6aAP3KVVX6lBXMHYS8mlyCe/1keFg66C58m9giDkmxmhs1mrK7l YfCptK4bC3E36AYe6KrwbKcu97mzOnjXVb6EuHFW81SlKtyHeYtNQJcZURiTlC37NNWt u9JeevUpjb5p76i4yZAN/cmRb0Q1DO/i5KVd/p24OnIN+iYdy/KAb2rXa4vnV6BuVL46 BjgsyxGpjELAmpPaICf+aTi8EHeZOXvSnQmTvS9Kp4E+3xiI3VbKEo+Xw6DRBahazDR5 aj+gaDjn5lK9yVFGguKzeoZ8UBmOfv/rnc27mQb0NzMBFWC4RfTafSuXUZt+pBGB7aPa e4CQ== X-Gm-Message-State: AOJu0YxgD7Xq+WKCQIbA0I+kbLsJKH7DOBxMRQT8P/TfxKR4EBbHOW5A SPRT8Aq+TiGaEoxDgFyGSGBGcElr+byJwUqb98A= X-Received: by 2002:a05:6a21:71c7:b0:172:f4e:5104 with SMTP id ay7-20020a056a2171c700b001720f4e5104mr6898813pzc.20.1699590435683; Thu, 09 Nov 2023 20:27:15 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id ja13-20020a170902efcd00b001c746b986e5sm4371796plb.45.2023.11.09.20.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 20:27:14 -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 v12 3/9] blk: blkmap: add ramdisk creation utility function Date: Fri, 10 Nov 2023 13:25:36 +0900 Message-Id: <20231110042542.3797301-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231110042542.3797301-1-masahisa.kojima@linaro.org> References: <20231110042542.3797301-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 */