From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: u-boot@lists.denx.de, Heinrich Schuchardt <xypron.glpk@gmx.de>,
Simon Glass <sjg@chromium.org>,
Takahiro Akashi <takahiro.akashi@linaro.org>,
Tobias Waldekranz <tobias@waldekranz.com>,
Jaehoon Chung <jh80.chung@samsung.com>
Subject: Re: [PATCH v4 3/8] blk: blkmap: add ramdisk creation utility function
Date: Mon, 25 Sep 2023 15:09:38 +0300 [thread overview]
Message-ID: <ZRF4gguigfY6Hnev@hera> (raw)
In-Reply-To: <20230922071119.1439482-4-masahisa.kojima@linaro.org>
On Fri, Sep 22, 2023 at 04:11:14PM +0900, Masahisa Kojima wrote:
> 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 <masahisa.kojima@linaro.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> ---
> 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 <blk.h>
> +#include <blkmap.h>
> +#include <dm/device.h>
> +#include <dm/device-internal.h>
> +
> +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 <dm/lists.h>
> +
> +/**
> + * 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 */
> --
> 2.34.1
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
next prev parent reply other threads:[~2023-09-25 12:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-22 7:11 [PATCH v4 0/8] Add EFI HTTP boot support Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 1/8] net: wget: prevent overwriting reserved memory Masahisa Kojima
2023-09-25 10:50 ` Ilias Apalodimas
2023-09-22 7:11 ` [PATCH v4 2/8] net: wget: add wget with dns utility function Masahisa Kojima
2023-09-25 10:52 ` Ilias Apalodimas
2023-09-22 7:11 ` [PATCH v4 3/8] blk: blkmap: add ramdisk creation " Masahisa Kojima
2023-09-25 12:09 ` Ilias Apalodimas [this message]
2023-09-22 7:11 ` [PATCH v4 4/8] efi_loader: support boot from URI device path Masahisa Kojima
2023-09-25 12:37 ` Ilias Apalodimas
2023-09-26 3:01 ` Masahisa Kojima
2023-09-28 11:35 ` Maxim Uvarov
2023-09-29 2:13 ` Masahisa Kojima
2023-09-29 6:24 ` Maxim Uvarov
2023-09-29 7:00 ` Masahisa Kojima
2023-09-29 7:43 ` Maxim Uvarov
2023-09-22 7:11 ` [PATCH v4 5/8] efi_loader: set EFI HTTP Boot download buffer as reserved Masahisa Kojima
2023-09-25 12:46 ` Ilias Apalodimas
2023-09-26 3:11 ` Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 6/8] cmd: efidebug: add uri device path Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 7/8] doc: uefi: add HTTP Boot support Masahisa Kojima
2023-09-25 12:12 ` Ilias Apalodimas
2023-09-26 3:02 ` Masahisa Kojima
2023-09-22 7:11 ` [PATCH v4 8/8] efi_loader: create BlockIo device boot option Masahisa Kojima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZRF4gguigfY6Hnev@hera \
--to=ilias.apalodimas@linaro.org \
--cc=jh80.chung@samsung.com \
--cc=masahisa.kojima@linaro.org \
--cc=sjg@chromium.org \
--cc=takahiro.akashi@linaro.org \
--cc=tobias@waldekranz.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.