From patchwork Wed Sep 27 09:36:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 726694 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp3430631wrm; Wed, 27 Sep 2023 02:37:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYhBwqHV5fsPr4db5hAFZHI16n26gNyLmiMqwYusOAFCYT7aZTzD2a7im5esF6WR0O13DY X-Received: by 2002:adf:cd12:0:b0:321:4d1c:425f with SMTP id w18-20020adfcd12000000b003214d1c425fmr1250814wrm.47.1695807479643; Wed, 27 Sep 2023 02:37:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695807479; cv=none; d=google.com; s=arc-20160816; b=ya6Hw1dQ6VgPGJ5bfGFyaNFIC8CK/xlbWIuObYH/+xRVYUYuBRmRPOyt3f+020+yXw 5JA27OLaf/MJZCTsL8mkTxyf23rtlR5xmflhdWIeeybP3OTNwTryFeFBZ+yoYWRJEbPn 6HUm51B3LiSn26vtc4hAIyQApBTWXmXVN1oNEOL2QgFVn9ebNGWEvT8xtTptQYFVV5cs mck7SjKaTOpx1fyY0cqlZFIf2tD9ukN49Eey79PzV88fNEClr4YtFW8MkL5SlzC4MJiQ OBJAE//qffJwLZE4vjXnGLPb0OROSZmVU4voC2pqZBHYU/z3WvKPnr5sfimoPO0i45Gk PxJg== 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=aYd9QuIRRFZEjERMSFrTJWU1hUggbSoHEBjIrCt4jgQ=; fh=/7JtEi60Oc1He789ODhlJpQcggvkyewSA9z0FHm3qP4=; b=Bh8UQEHnjKtMczKf/f8VLbz7BfEm1Wza4ju526AKe4jgQp35X2hzue6LdZBxb5h7Mn E4zbF2X+aU1PwhXOGCZV3f9n+G5qp2cqtQ78WNv5fJmRt09lgqr6JdlKHhdd1sHdcKtt ypyVrmarjSXyA5Sjl6qe110HMjyAs4ZHNcsTnRylOrLa8ZJcqI5m/eBWoxe0wKvuPk7i mLGmbKOp50fgtlxPUxNYgoiGaAHOU1eUPlTwt/m2GatIu3fACn2JOfhkdKDtiZ5aF9hv gIsltz+FCixWXv/X926RBcB/GuAATzs8MZCtPvTVT+9yETu7ERcv0L0Wg8jHREDIIMjc uoOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HkDMYsNU; 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 s9-20020adfdb09000000b003232f15438esi2793466wri.1039.2023.09.27.02.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:59 -0700 (PDT) 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=HkDMYsNU; 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 66BE286DA7; Wed, 27 Sep 2023 11:37:44 +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="HkDMYsNU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EACEA85C98; Wed, 27 Sep 2023 11:37:43 +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-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) (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 0D39386DB0 for ; Wed, 27 Sep 2023 11:37:41 +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-oi1-x22d.google.com with SMTP id 5614622812f47-3af5b26d5a8so284425b6e.2 for ; Wed, 27 Sep 2023 02:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695807459; x=1696412259; 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=aYd9QuIRRFZEjERMSFrTJWU1hUggbSoHEBjIrCt4jgQ=; b=HkDMYsNU5psf+Ik208GmXw31AWG/UHxdkwTCRmLHmMPccjo41PTNtgRpIVl5A3SWic PHOKiMRKi7GhBhAqPhKtCBL5DM72qvQj8bBn7XWV1feR43Nygc7yTlsMBG3xGx2FYjPe fcONk5obYVClBuiLxVkoWYbLMZTjDBS6Qop7i+grS6NaocRSqBefEZOLTYXHGVT9nFqk /z35drUJ2wMBmYBtD8teUKqGm+h+o2HKALnzUIVSPmOdcrsi4PnQG0Mjfv3meG6Xszdo 06UzRw7RCVwsZdD3tHJvHWdL4OZTRppcK3kkSVJejX64DspAb8bl2/W736AmVPOy0Qpl Ku/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695807459; x=1696412259; 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=aYd9QuIRRFZEjERMSFrTJWU1hUggbSoHEBjIrCt4jgQ=; b=cAvkRF4uSYUzNLz7c6IN+x0XERT0X0HDrHSi/nuSj/Vo9xa91iTnns/ajBTn7ANUZl kWtXV5lkD0lMdABmsbbYTFZlocVKGBI6WRDThtOH0jFK5j34g0p2Wzhnj7t5zNpFOll/ 9Y4FGHZ6dnr1VDzp8Stmn8iKZYxzUzexWb5cyBnOD+UaJYwK32D/EAn7EIjMOVXI6go3 BWa1MJz+sAzKuaR6+2Dt/wssnndEMI0HwbaD7qRxLpnQy9yqXnMZj6rX+DweCxFYo6IW g8aipJHGETdbCrmd/po0w+Y9PSwezFqUJ2briMOHPl9nIFjAXrEeMC1GZpQ4HwPZabkF C5fw== X-Gm-Message-State: AOJu0Yx9zXPx0ktHYVdQon503i+qyQ34vaKpkBtyRrrf1nI4CFbj6MFW k+RMPyn6GTD63C0ys5OcIyeTxndsNtPH4ZX8Ziw= X-Received: by 2002:a05:6808:bd5:b0:3a7:366f:3b01 with SMTP id o21-20020a0568080bd500b003a7366f3b01mr2150777oik.33.1695807459326; Wed, 27 Sep 2023 02:37:39 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id h11-20020a63574b000000b0056368adf5e2sm10947339pgm.87.2023.09.27.02.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 02:37:38 -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 v5 3/7] blk: blkmap: add ramdisk creation utility function Date: Wed, 27 Sep 2023 18:36:27 +0900 Message-Id: <20230927093631.1595494-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230927093631.1595494-1-masahisa.kojima@linaro.org> References: <20230927093631.1595494-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 */