From patchwork Wed Nov 8 11:06:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 742224 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:110f:b0:32d:baff:b0ca with SMTP id z15csp227546wrw; Wed, 8 Nov 2023 03:08:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMuWJ6LbxHuLAuprwai+gEtWTgnoq5YKf98gsETzraeIEQ3Mre9xoh1CidMSGguYVmt+K2 X-Received: by 2002:a50:d5c1:0:b0:543:56d8:eb26 with SMTP id g1-20020a50d5c1000000b0054356d8eb26mr1226194edj.35.1699441703781; Wed, 08 Nov 2023 03:08:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699441703; cv=none; d=google.com; s=arc-20160816; b=a4kq5vB0Z3N9IVoQl++A1vsgZRePoC4Ab3lcbIafyfi6a9haKCeXoevnoKA0JTm1f0 6RYPq0A96Ww5+56udzzLzyLKXVh45Sf6kgK0pYrCv3eC3xgoCvtHYZ/q0R1O4I1Bd8Or A9+at6u/095VAg2oQfe6YfqkUiSiGHUtyMfz1R2vqIsheq0eoL5nbcaDr7NYxzLlSPcb gt4R+9t+cwNRl4CFUAovL296Of7ijeRJ0iSOIq923KauJCxm1V4mVoGz9uREKzmulHhe r3sHSv9qb6De5UK8rT5sLujmkIryztWMmB566lLOtbmYcwiKuMHymX9Z5mngOvu/EGBB s+OA== 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=HGWc3MmfU6IGuN2lAs1xlSuklmYjlSsUvw4VE+MfmqOZBAT+Bek434ashlA39SCVMF D90ivr6NK6ISHHr7n6rnLu7fG22sURMl4B98rzndNtUXKviByOv05Og/gh4Y2O6YZFg7 PXJr1G1hxSBlOlT+cdBvoRHh9bMq6X1RVqwaC+AOfu5vGrxPncbCOGu7TnzygfThIpqc mfzmo4xyu+cjurcyDjxepIkYsV5aw81kaqRY154c3nS2XclpzsavQ9iTwys5xNNBsDbH 1mPKviglSoI2NtnFa3NPKLbLEYypeg1jcad4uKC3ZbirrYO/zWevtIOr0dsqZxljMKWc BxSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nDapdNSp; 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 s26-20020a50ab1a000000b005435556d922si6211366edc.301.2023.11.08.03.08.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:08:23 -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=nDapdNSp; 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 510A38754B; Wed, 8 Nov 2023 12:08:11 +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="nDapdNSp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8CCFF8755B; Wed, 8 Nov 2023 12:08:08 +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-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 F08588752D for ; Wed, 8 Nov 2023 12:07:55 +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-pl1-x631.google.com with SMTP id d9443c01a7336-1cc921a4632so56514485ad.1 for ; Wed, 08 Nov 2023 03:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699441674; x=1700046474; 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=nDapdNSp06iLuNQa0m73zvzwiAEEmahc+hFseoCkjorzbAZ828obDrrUyLeDceKfiW Zb01duP3QLdZCglS5vpmjLd8KcJQSA2C83YGji8A4Mi2jX5o2Tkjf0BB7i84NjvJfUsa AHdDd6omVgBVK/9aHCDt1dn0qWqPlzzgZ97NVyNUp8aXI4HDL6aW4yisUK9nYq8yOVcr FuayAI+S6Af0xpgZP7tTsmw5Jw2qMrYlzyFbikHH3UseT7STUz9GbFbNs6USwEFcLe1W oPYshJWI3MlW50zv6MC/IKnA2WHSJWb4hjb3NON5JOg1hBW2DJHXfeYJjie1NB2USBcM 4wKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699441674; x=1700046474; 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=eEeUDBN2ShywDA5f061bSlpazNCWhh95lVZlpAcy1qcjcG/VQbvhyrtfmCpxKBwmeA TrrJOptxSLQI27BMcSVuxmHiT3tNFat0K7GziqcVtnZX4Cp8GaOWqTT5XZ7i1Az2caOT sjvdR61O/Fvn7ntHZxv4EF9U/nOLWpN+piN5mSCuoLa8gaETXj8/MWMwKLBtSAW8eIYr a1jq7o9oI2SRpVL53MGXaYL9oi6e1MIje0vx7Hwixb8J6ccc1Uft8fncLirzR1WldCyL 0iU9linu3fr2DzMusptciRZVqS9v52FJOJulKxj+12idhWK4l/ylaA7JxF2cxrWHqu3z usDQ== X-Gm-Message-State: AOJu0YwLOQVfIhIQOaLWUvK/ffPCNmvxEMTeLjMdFGgqdYW7Pn0HH9v9 EILye5KwmSV1LTuYZvOP6wsNEFGU9KtL/JIzPQ8= X-Received: by 2002:a17:903:2a84:b0:1cc:617e:9c25 with SMTP id lv4-20020a1709032a8400b001cc617e9c25mr2076768plb.53.1699441673969; Wed, 08 Nov 2023 03:07:53 -0800 (PST) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id kx14-20020a170902f94e00b001c6187f2875sm1486269plb.225.2023.11.08.03.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:07:53 -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 v11 3/9] blk: blkmap: add ramdisk creation utility function Date: Wed, 8 Nov 2023 20:06:30 +0900 Message-Id: <20231108110637.3691441-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108110637.3691441-1-masahisa.kojima@linaro.org> References: <20231108110637.3691441-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 */