From patchwork Fri Sep 22 07:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 725218 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp875964wrm; Fri, 22 Sep 2023 00:12:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtE4fR3wmzaJyEMLSjhs30AFXginpPz+b0TnJC2sYL0+xAxiyRxV6YHaLo/Iza4q1YefHj X-Received: by 2002:adf:ec4b:0:b0:319:735f:92c5 with SMTP id w11-20020adfec4b000000b00319735f92c5mr1314671wrn.32.1695366745257; Fri, 22 Sep 2023 00:12:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695366745; cv=none; d=google.com; s=arc-20160816; b=CYbawp2e2iEvj5FRjhlMwjBhHO+pboiEUys78FL6jBB5T6L3l92DHfVQyo59fxmtwJ N9vOku99cIfoVoYyMwozwQ88S4VzO6HCphoUmlaawCzW477aObH4PXwrcO1o9O0xyC0P isfMgBdmjDnJ1BPzfrybkTKXXHYNgZTQCNkujsWVHtsELtS7jvZduc9WiM6lPwxNmUrk tBADq2suttGXzWKZx5HeE+29VLDePCIHfFKQ7YgVt0YKOiQW9Z/QSCdLe+K6cxr72laA NIsWZiCVJ24JTldCl5RRqH7QlNiZGFDldieOS6vJJKNPOFzpdQPpaOu3dA0Is4cqHEMr WGUA== 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=JFLSAFmEVgUsojo60HrPZaY9CRkzcJjwC76kyEprr/8=; fh=/7JtEi60Oc1He789ODhlJpQcggvkyewSA9z0FHm3qP4=; b=awrWlUgM0/a1zd9C1TQh17A4SZKvP4zmuafcJqAYmuRRA63vH0KmVhipSBax8IDqPA WLRCJhVvMbFGzYo4TKogaFEpBlwWBcDj8I8QEbfVOt6df2bKwqHT9245HrzCqUC6LsaC Oq027NvGqwhndxMeJrR672uFsj6gzzvd6m3nqrgR2UJ6dqI8nIliEzJ8g979owH+OaF8 SgeIUknGdhJr3oJZkTHHi2iHDBIGusp1+Mj4se2/yNTzEiMDOjxNo8idniG556WrzOGe 12FuZvEgJzgCvt7vWRM1jg01CqyHKhLSTr/qab/POSFr3XH4sXFfTkxQOGFqueWmYBbk S0Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UZCY8ITf; 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 l9-20020adffe89000000b0031b60f6a160si1513512wrr.815.2023.09.22.00.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:25 -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=UZCY8ITf; 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 345AF869AC; Fri, 22 Sep 2023 09:12:11 +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="UZCY8ITf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3BC0886996; Fri, 22 Sep 2023 09:12:10 +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=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 075C286575 for ; Fri, 22 Sep 2023 09:12:08 +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-x434.google.com with SMTP id d2e1a72fcca58-690bd59322dso1413111b3a.3 for ; Fri, 22 Sep 2023 00:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695366726; x=1695971526; 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=JFLSAFmEVgUsojo60HrPZaY9CRkzcJjwC76kyEprr/8=; b=UZCY8ITful9RbXSA0SGy2cjY2wRBAz9ouicc29z5rxjp93+XPat0Lir93Ss/VNt0Zu aA3nfBNGx1181vQBHyglUiQKmj4kvhV8iWq4cvLETuJ8LYNycDjpdRTOono1opFv5WS4 Rf9YC5VcqsiiePdPZdfMx51yxB3+VjwEJeJkTbc24tTGpPQ1CPSr4t7YnQ7QD0Bkwjhz xMxOXUEGEQXKO17QE/ARbPZNuZKUFtR/AHEJY9LHsg7GvJ6qFfufivoLyGnpjDcf9fEX O41TuOy4Thx/AivgOpd+15aNprf99RHqhPvE3sIfVuhKwxQo4MhoAxqal0AmOhnEFmAP sNZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695366726; x=1695971526; 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=JFLSAFmEVgUsojo60HrPZaY9CRkzcJjwC76kyEprr/8=; b=FX+3i4yjrEq7zMTY0RzLcIUFv3NzgEa5KrYwNCDVHcQjbwb0BoWRe0GMamTo5HYdox SrawDqvEP79ZgXrbIzWVam6FdEQC58IrtGAzHk7pDLz/cj/AQ+buHDDUewhFPr1jZbhk Bwq0HgNDTdTBlrlug8hgX3hDxOO+nEZDNELJLWNCFOCyJ9XW+SF/kVVfCCn9qnWZmVph TLcqZ4UMIjA+uwhV6+8g0onq/B6KOY6UPFj/sL2BfPKqjMoVfHeGFgaIXBfm2SiI4Zec HVZF7tre51cKzxzHXtYLU1UlDsjwOoAtZrV76sh1ro8xsJI2+yJgubyn9rltLawfv9Gr 8BvA== X-Gm-Message-State: AOJu0YwS/jb2ahyCbhdKmqq8qfm99fvsUmOiQRB7Ht65tiY8fk6x8V5P KJPhHr6b2mJYt+0v5TKVJGMXPNe20u1cC5sH3eQ= X-Received: by 2002:a05:6a21:66c5:b0:15d:c86d:27a6 with SMTP id ze5-20020a056a2166c500b0015dc86d27a6mr640509pzb.55.1695366726104; Fri, 22 Sep 2023 00:12:06 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id s10-20020aa78d4a000000b0068fc9025a08sm2510759pfe.151.2023.09.22.00.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 00:12:05 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Tobias Waldekranz , Jaehoon Chung Subject: [PATCH v4 3/8] blk: blkmap: add ramdisk creation utility function Date: Fri, 22 Sep 2023 16:11:14 +0900 Message-Id: <20230922071119.1439482-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922071119.1439482-1-masahisa.kojima@linaro.org> References: <20230922071119.1439482-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 | 1 + drivers/block/blkmap.c | 15 ---------- drivers/block/blkmap_helper.c | 53 +++++++++++++++++++++++++++++++++++ include/blkmap.h | 29 +++++++++++++++++++ 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 drivers/block/blkmap_helper.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index a161d145fd..c3ccfc03e5 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -15,6 +15,7 @@ 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_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 2bb0acc20f..4e95997f61 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 */