From patchwork Thu Nov 2 06:44:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 740429 Delivered-To: patch@linaro.org Received: by 2002:a5d:538f:0:b0:32d:baff:b0ca with SMTP id d15csp672382wrv; Wed, 1 Nov 2023 23:47:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQLSWnWvgB5pUguU8YyFMtdoP3rSeWgph9RSQA878p+wM7o733f0MYR2lDZ1xX8G4d9wjB X-Received: by 2002:a5d:6d0f:0:b0:32f:91d2:6f1b with SMTP id e15-20020a5d6d0f000000b0032f91d26f1bmr8225811wrq.5.1698907627935; Wed, 01 Nov 2023 23:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698907627; cv=none; d=google.com; s=arc-20160816; b=suCgbw9uQy6GQThVm1SpfgHB+5kHsD6mb1GOFYgCbBAskHAbpN5KQ8kqFe+0+Up0yR RAuUz5AOD90ksWXlonLgSWR4vb6J4Kty6OAB4h8rE6gvPVXD25PJbOk7l29V55JKgYEy vSWfKFU43Tuhf7rti30BYG0xfFDiW+wl6uOHLhct9BnbLQpyN4Z7M+pAvcBFAcaM3TFw 9TQWG5qZxLgX/veycoTX0zIjZmNFQrwawGGb9IAx+rtGOxUzsJIuxLN/ileX/krovf0J jEYirmRShVM/NyPMKpZOqbPRl+q3XQRHwS8SAnctMARoJnVisU4LLQixodD37ay8AmWu +3Sg== 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; fh=zqO2vTczeIKx1OTsr8uErpGVOeopTGT8suxWOXUGpbQ=; b=dSZuzvFqzU/k+EPix6XnPQfvUAdykwmEjU3iRz8iJRNnfA1vPSiX4VDEuISLWVLv5v HfRRootxkogLJkqNIQAQ8et3IPZTS2abkBQx3RPTp2LF60Q0WhPUW5vOHCwBNCGlqIt4 jPAybvBxPX4jmJDbYZIK7LU1UfVutQyKQRlm5ELCNqE1uBQvOS3EQGIg+u4Jp/XFVSNN MWrvPtraFjg7uwBTmF+rUSWi79Apew4dVbpniTdpTgnoCcaXRglM4sPHLdVEtUQaZQS/ 3NpF2iR9KK4/XUta3RVLtyUIsGh8m8jaqgdFdP/F4LhI9fwTJvRq0oZLReC9cV6c72lM p0IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bNO/MzUN"; 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 g8-20020a5d46c8000000b0032dd84270d9si926904wrs.409.2023.11.01.23.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:47:07 -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="bNO/MzUN"; 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 9CB9787467; Thu, 2 Nov 2023 07:46:32 +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="bNO/MzUN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 31F58874D1; Thu, 2 Nov 2023 07:46:31 +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-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (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 E00EE870C9 for ; Thu, 2 Nov 2023 07:46: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=masahisa.kojima@linaro.org Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1cc4f777ab9so4919335ad.0 for ; Wed, 01 Nov 2023 23:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698907585; x=1699512385; 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=bNO/MzUNV7QX7zbFkayeBeZDrs9HjktrOh4Ij6i7IvIC0XI5wy9ly5HGncmpgv+Tr+ nqVpYIMo6FhGkJOPGbv4AyBvwaauMwrd2gCRT7vog0LTyF1XdwDPqkCoaIK6/1Cc/Tfn mb984nTw4CMXSYSmtuatZM/gwtUlmNU1snrcff+HB9hlHefmpedvM2+FfgQrtpiKYsnk 8uARHI5yJeOZXINwCOy72/u7CsVgD05++b3wzhTM8uhCTkOQvrzGbh4+JBI2Td2wAl3t brsxeUjfuknPArdn0dc/0SsOwYV7FcifU/3Z3wYyaEjSHD6Epj9ZFIEr5u9DFvBfNOq2 GO2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698907585; x=1699512385; 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=h+uhty0GdC8R49rdJSut4WnZ0t+PDDOC92B5xrfeuT0=; b=dI3lTSegQssGjTXF+Bh4NG7YWkf7/yx8EZF9Im7CBu44HRF73EA4YU2ixj5DjjWUI6 ZnYK0jgUZytwGoC3PkV3kEDiy31DYO7wVXEiQwNRE4iTTyVJ0t14to/e5l2ubng2qcNI eqTlLyfwIyJB8NZ477Yjygwj4Gx6TIgtjRou7T23HDRz7zYOeTYIIRjFKvAsz2jmLLab EB+ZYcz9XARV8aKsOJELxKv6QqOQiH5LtPkOR6/q4I9e4eRUz5mlt7S2opbcw6a8921G bQ+KSJa3WaGQIPQtBK8fNOryp41Fjbzb3Ylq0u7/4afhmMFgNVuYaldmOj8x25o67Sgr oRiA== X-Gm-Message-State: AOJu0YxIJhbGeiypwQkaF2dtPvlFstKfDnZ2kHVZK25lFarTbZ6Qjofg bus+SaaD+Br2JQs0OyoenAPM2dhWCLZWWbwrNOc= X-Received: by 2002:a17:902:cec1:b0:1cc:345b:c7f5 with SMTP id d1-20020a170902cec100b001cc345bc7f5mr10984204plg.23.1698907584994; Wed, 01 Nov 2023 23:46:24 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id p2-20020a170902eac200b001cc2c7a30ddsm2331737pld.148.2023.11.01.23.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 23:46:24 -0700 (PDT) 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 v9 3/9] blk: blkmap: add ramdisk creation utility function Date: Thu, 2 Nov 2023 15:44:53 +0900 Message-Id: <20231102064459.3466953-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231102064459.3466953-1-masahisa.kojima@linaro.org> References: <20231102064459.3466953-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..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 */