From patchwork Mon Nov 6 11:39: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: 741373 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1036057wrr; Mon, 6 Nov 2023 03:41:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGF1l0y0l6ZO6bA/0ujfWAYySTtHNat0+ixpHJ/X9F6tQ51PCK8A42t22i6UF5e09cHmLFi X-Received: by 2002:a17:907:c16:b0:9c7:4dab:20ea with SMTP id ga22-20020a1709070c1600b009c74dab20eamr14036616ejc.67.1699270910504; Mon, 06 Nov 2023 03:41:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699270910; cv=none; d=google.com; s=arc-20160816; b=E4XVtJMghc2yvLMAQ2tfFjs9oUmA8nZpLNvGZ2cp7si2BdaHWgkBtdHhtp0ZJOy164 ecN9mSMv+1EiSN+5x2CI8+B6t6qqeHJ8qKywLy3lfFK7eAvAhWh2V5cpkbJUbs8sRD0R kGMzTLFaGE9Oiluwmoc8gWWuvBEE35ejsCLy3Z5xv1aDtrU7lKtJjS0eN6YWbUYUZSrc 9jaPGU1oPMOUpPHSDJ2Vn5WDuIZp+mQvl7LLjs1anRA1LEYVJ3fKy7xOj6vB0gGmYCuz hs7fculdsZ3NGfS1GM0t1GKXlsITB1zSiF7ms7O9+aScnZdBBRsLPyNds6Qcp2cFYj8j XguA== 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=eVeoX2iAZ6+ylqYCeu6kJAbZcwP/Jp4i6TMGQxenfpWTtamaB0rR/aQkbhnyD4dmvc Fakjj2qi5S+Ux7+Ipd/1yPdEt/B5wA3P+O7t2z8g/SUNYuXlO+5iwjOK9FElBvelrj7Z TX19RC1f9DXSspi3CHnZlHgCxGnRyiNeA4iIQpI5KdhQeZm8wJOq1uJLlBFNUS08mRcT dw7rgjVSPmxURq8GRYY09CYRDPR+RG7r+Z/b251DprUMS0F9WGXq0mvm+VmB71OMqstx isZzS0MR/wlP4/P+3eSRO4XnJ3YjnaRd/4WZjUMfpCPFioQ26ofoodM4ZhZ3Rx2Z37yq u3Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jhIMNfAU; 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 i7-20020a1709064fc700b009cc6c92cb8asi4709266ejw.35.2023.11.06.03.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:41:50 -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=jhIMNfAU; 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 E648D86FE5; Mon, 6 Nov 2023 12:40:42 +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="jhIMNfAU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 019268653E; Mon, 6 Nov 2023 12:40:42 +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-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (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 6BBE686FE5 for ; Mon, 6 Nov 2023 12:40:38 +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-pg1-x536.google.com with SMTP id 41be03b00d2f7-5b7f3f470a9so2789783a12.0 for ; Mon, 06 Nov 2023 03:40:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699270836; x=1699875636; 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=jhIMNfAUZuLf1o38Vk28yN5tEbDftIBrqpwh06GdIT8mVaSrsM/VxGqihb6CeCWeMy fQPdfQZZMrHwUdtTAffoabl6ajf3h3Xf3iOUMOre5nrd4fTIC5zdVOEE8SekxtWJuzur /htXkcCfimSXl3Rayurin/sgQ8oEOq29hvF6xXTEfrtVoDgYVp2U748SKWa+rD3x8p9u VGOFY6CkE5r7tvLgkYCJW5auRZeuMmpR8VjJl2/X3wnH1+UypIRm0a+8umFuGU84dSNQ l1I31de/ff43sSxH47qFZZzj16CYqqclyhSUI54pFMlor5+pgHxPAsAzX60HtJc03Dxz 37Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699270836; x=1699875636; 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=fG68d9NsoDzPIBdT5mwjld6ySVsRE9F5Hf/uXRJknNo6x4q7btxBMeE/7wdS1Vc7H5 r2zpG7rPAqOAF47dWyswYOSS+itkT363AXuU/d53ebDdGqC0c73ZEtrnbfPqCaecqp3v D3y0ucY8wpChy2oUMkiR4mUh5mFCvsAFezX+Ouu2Hib9F4Sq7njbEHCKclrcZENqgyab xMoYJD/gyzvabk58aRat7w9eGi1rS1QrQOjECYm9FxuHrKYXKJ4cIWcaA8xCzD6jIdUA 4lKYds+fIyvDV5aobIo+ylp6z3JEz+E+vl3kG49B2SYw5orYVZxZ2tG/OyEW512YoRwR lHdw== X-Gm-Message-State: AOJu0YxQ/8QDEEcQ0q3I+rg7uOg0Bt24lyY8dvI0geiw/4UJ4NFz4LaR f62qSm1ZfqOln5ZhxSlYi2IdV8NAMONwv68d3s8= X-Received: by 2002:a05:6a21:99a2:b0:151:7d4c:899c with SMTP id ve34-20020a056a2199a200b001517d4c899cmr27607993pzb.25.1699270836455; Mon, 06 Nov 2023 03:40:36 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id iz7-20020a170902ef8700b001ca82a4a9c0sm5736266plb.309.2023.11.06.03.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 03:40:35 -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: [RESEND PATCH v10 3/9] blk: blkmap: add ramdisk creation utility function Date: Mon, 6 Nov 2023 20:39:14 +0900 Message-Id: <20231106113920.3631591-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106113920.3631591-1-masahisa.kojima@linaro.org> References: <20231106113920.3631591-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 */