From patchwork Wed Oct 25 06:28:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 737807 Delivered-To: patch@linaro.org Received: by 2002:adf:f842:0:b0:32d:baff:b0ca with SMTP id d2csp131295wrq; Tue, 24 Oct 2023 23:31:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtY1CkgYvxR5EPk7X444+j+qDudo2uUTaF4/orGI9RGLvxkMFttRTODSc13WkR/HwmYEjk X-Received: by 2002:a2e:84d0:0:b0:2c5:1d11:5691 with SMTP id q16-20020a2e84d0000000b002c51d115691mr9821519ljh.28.1698215467378; Tue, 24 Oct 2023 23:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698215467; cv=none; d=google.com; s=arc-20160816; b=TlypLD0QqCfYF/rPbSbHksF16VMCE8JAboCotA7b2q4TDCLBN4UkhopNN9yorRQKsD GFPfYzvv/1Wu+wQTEgKjKRQ6KHjqEtXnahcYrUeqbsRAF2Fzcy5Pt5cFd+cv8/5Oywfm w7a1xhpL7jZDPX/HGk41p9ZIfi6GIkLWzkN6rZSDmMHOjYb5347aE2spFVZ4B0Now6qi qvN04ZDqAgEf/XIJUtloxrhj40Omk5kNQnZJNnSgUByy95aVuH/pMZamFVt5u1TfskOv oGNVqtt36flsXE+Ad3354t0Ri6hsucCNbcqSoRINF/AnU8ztB3v/aphu4HJCC8qzrgrp parg== 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=nGxKOXCACQSu1eN/ZPnZQwsIMUpKToCCLMDjTFnWWa4=; b=wWJDuS5EnbBiLGQDL39E3JiuWgRrcJzv1eGJMArF/4FU78VppP7p290sMBW/AiGCu/ pVYnzjNEBLRYraGL49RxyCa+LbNDG5C0yNVwnLDRGEt/jZdPaW4fAPqONsSRDl5Nqojl HAlcgAG9igFBFjIqlPlxwwsXkwmh+nyALKKmY0blfoCPqCSjgPSKuSfSh0ooEHPnOu8u AZIOjUcdpqsdpSFi6nvO5Q3xczqpOmEhIt+LDgiXbpQtu17qHXDHwV6duZKHKfJpVqml n6BL3sxY4l7O63IcS1cE47FLkvAhCAhJ8z6+yRNOSEJpJ34eSR3PKOCQxjeWkVJDAc5h jSgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQbyKWz+; 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 m17-20020adffe51000000b0032d9cf7ce73si6930513wrs.282.2023.10.24.23.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:31:07 -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=RQbyKWz+; 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 680BF87A50; Wed, 25 Oct 2023 08:30:30 +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="RQbyKWz+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A6644879D8; Wed, 25 Oct 2023 08:30:28 +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-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 3695287A57 for ; Wed, 25 Oct 2023 08:30:22 +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-pl1-x62f.google.com with SMTP id d9443c01a7336-1c434c33ec0so36145725ad.3 for ; Tue, 24 Oct 2023 23:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698215416; x=1698820216; 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=RQbyKWz++ESx+OI4DhD3FJEbw8MIFU+ts+VxHZ9MZygilyId+tQcQEqLMXWinvJuox xpL25GwTq5aUnjvYn1FO0Wrax+i1drqqOWZLjinOJXbLqWzMtFL5t6kuiiPXrW29TLMM BMPcBHE0K7qsa59kRSxDzry5EZuPxabQMVXsrN/rFY/V+fpPZnrWR6uaKP7E00YsJPYk Zmway+hGMKzYQT1qJhnVJGFM0T32cN9ak8oCsi8WNQR5eQ/yQ6GVzET0ZzHALsy5veU2 3lj6xX6DgnK6pQ64GofWjM64Lj4mle2KYNeCZOr5EabWDkhkZMbsAseddu0uqqXNsDF6 M7Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698215416; x=1698820216; 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=J+BzURqnPqLIjS34tMicOWJg7giku/cVqdlCU04wu4pjI1NqUnKOC0SJnc8HfqAqOU dbAHCoh1R7CnlE7PXriEHpG3rmVcNO6so0dJF9AJuUkA3D9XnKbSC4yzNDCLOVfDzsna SbyRhyiTB+mc+yheqh0XK4KSD+ugFgtjNsGjhljmo3Kmuqh2/fD2+WDCdCzai+4KsZ7X MXaQ9U76ujuXVRcAxdw6JtRc8Ao4DttGw6vz8ufJZWNoapBGvdGoLWLLc1GIv8OFLkUL 4hYSaMA885Bdojop6QpoxJkUYKAtxg9YyLjwFs1EHIfk1mqeJupx/wFbnyRZpx6eQd8K LZVw== X-Gm-Message-State: AOJu0YyCWvcnc5CIH4Q7oIjdTtv1+HVs8YbJO5H1N6YytRS35qVZWANL 5c4GllICEXLeL7jkaompT5Foym8K0/IxqxSu+j8= X-Received: by 2002:a17:902:f944:b0:1bd:c7e2:462 with SMTP id kx4-20020a170902f94400b001bdc7e20462mr10399601plb.11.1698215416186; Tue, 24 Oct 2023 23:30:16 -0700 (PDT) Received: from localhost ([164.70.16.189]) by smtp.gmail.com with ESMTPSA id jh1-20020a170903328100b001c5fc291ef9sm8408967plb.209.2023.10.24.23.30.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 23:30:15 -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 , Jaehoon Chung Subject: [PATCH v8 3/7] blk: blkmap: add ramdisk creation utility function Date: Wed, 25 Oct 2023 15:28:41 +0900 Message-Id: <20231025062845.3100964-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025062845.3100964-1-masahisa.kojima@linaro.org> References: <20231025062845.3100964-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 */