From: Sunil V L <sunilvl@ventanamicro.com>
To: Alistair Francis <alistair23@gmail.com>
Cc: qemu-arm <qemu-arm@nongnu.org>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
"open list:RISC-V" <qemu-riscv@nongnu.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Xiaojuan Yang" <yangxiaojuan@loongson.cn>,
"Song Gao" <gaosong@loongson.cn>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Bin Meng" <bin.meng@windriver.com>,
"Andrew Jones" <ajones@ventanamicro.com>,
"Anup Patel" <apatel@ventanamicro.com>,
"Atish Kumar Patra" <atishp@rivosinc.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>
Subject: Re: [PATCH V4 1/3] hw/arm, loongarch: Move load_image_to_fw_cfg() to common location
Date: Thu, 15 Sep 2022 17:29:32 +0530 [thread overview]
Message-ID: <YyMTpMuQ0UP9Mqaz@sunil-laptop> (raw)
In-Reply-To: <CAKmqyKOZSaE9CYGmYSKOEnkQkGDUkchut+i2mQjcZLSVx-qWag@mail.gmail.com>
Hi,
Could maintainers of hw/arm and hw/loongarch to take a look at this? I
have addressed Peter's earlier comment.
Thanks
Sunil
On Thu, Sep 08, 2022 at 11:17:52AM +0200, Alistair Francis wrote:
> On Tue, Sep 6, 2022 at 11:38 AM Sunil V L <sunilvl@ventanamicro.com> wrote:
> >
> > load_image_to_fw_cfg() is duplicated by both arm and loongarch. The same
> > function will be required by riscv too. So, it's time to refactor and
> > move this function to a common path.
> >
> > Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
> > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>
> Alistair
>
> > ---
> > hw/arm/boot.c | 49 ---------------------------------------
> > hw/loongarch/virt.c | 33 --------------------------
> > hw/nvram/fw_cfg.c | 32 +++++++++++++++++++++++++
> > include/hw/nvram/fw_cfg.h | 21 +++++++++++++++++
> > 4 files changed, 53 insertions(+), 82 deletions(-)
> >
> > diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> > index ada2717f76..704f368d9c 100644
> > --- a/hw/arm/boot.c
> > +++ b/hw/arm/boot.c
> > @@ -818,55 +818,6 @@ static void do_cpu_reset(void *opaque)
> > }
> > }
> >
> > -/**
> > - * load_image_to_fw_cfg() - Load an image file into an fw_cfg entry identified
> > - * by key.
> > - * @fw_cfg: The firmware config instance to store the data in.
> > - * @size_key: The firmware config key to store the size of the loaded
> > - * data under, with fw_cfg_add_i32().
> > - * @data_key: The firmware config key to store the loaded data under,
> > - * with fw_cfg_add_bytes().
> > - * @image_name: The name of the image file to load. If it is NULL, the
> > - * function returns without doing anything.
> > - * @try_decompress: Whether the image should be decompressed (gunzipped) before
> > - * adding it to fw_cfg. If decompression fails, the image is
> > - * loaded as-is.
> > - *
> > - * In case of failure, the function prints an error message to stderr and the
> > - * process exits with status 1.
> > - */
> > -static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,
> > - uint16_t data_key, const char *image_name,
> > - bool try_decompress)
> > -{
> > - size_t size = -1;
> > - uint8_t *data;
> > -
> > - if (image_name == NULL) {
> > - return;
> > - }
> > -
> > - if (try_decompress) {
> > - size = load_image_gzipped_buffer(image_name,
> > - LOAD_IMAGE_MAX_GUNZIP_BYTES, &data);
> > - }
> > -
> > - if (size == (size_t)-1) {
> > - gchar *contents;
> > - gsize length;
> > -
> > - if (!g_file_get_contents(image_name, &contents, &length, NULL)) {
> > - error_report("failed to load \"%s\"", image_name);
> > - exit(1);
> > - }
> > - size = length;
> > - data = (uint8_t *)contents;
> > - }
> > -
> > - fw_cfg_add_i32(fw_cfg, size_key, size);
> > - fw_cfg_add_bytes(fw_cfg, data_key, data, size);
> > -}
> > -
> > static int do_arm_linux_init(Object *obj, void *opaque)
> > {
> > if (object_dynamic_cast(obj, TYPE_ARM_LINUX_BOOT_IF)) {
> > diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> > index 5cc0b05538..eee2c193c0 100644
> > --- a/hw/loongarch/virt.c
> > +++ b/hw/loongarch/virt.c
> > @@ -542,39 +542,6 @@ static void reset_load_elf(void *opaque)
> > }
> > }
> >
> > -/* Load an image file into an fw_cfg entry identified by key. */
> > -static void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,
> > - uint16_t data_key, const char *image_name,
> > - bool try_decompress)
> > -{
> > - size_t size = -1;
> > - uint8_t *data;
> > -
> > - if (image_name == NULL) {
> > - return;
> > - }
> > -
> > - if (try_decompress) {
> > - size = load_image_gzipped_buffer(image_name,
> > - LOAD_IMAGE_MAX_GUNZIP_BYTES, &data);
> > - }
> > -
> > - if (size == (size_t)-1) {
> > - gchar *contents;
> > - gsize length;
> > -
> > - if (!g_file_get_contents(image_name, &contents, &length, NULL)) {
> > - error_report("failed to load \"%s\"", image_name);
> > - exit(1);
> > - }
> > - size = length;
> > - data = (uint8_t *)contents;
> > - }
> > -
> > - fw_cfg_add_i32(fw_cfg, size_key, size);
> > - fw_cfg_add_bytes(fw_cfg, data_key, data, size);
> > -}
> > -
> > static void fw_cfg_add_kernel_info(FWCfgState *fw_cfg)
> > {
> > /*
> > diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> > index d605f3f45a..371a45dfe2 100644
> > --- a/hw/nvram/fw_cfg.c
> > +++ b/hw/nvram/fw_cfg.c
> > @@ -41,6 +41,7 @@
> > #include "qapi/error.h"
> > #include "hw/acpi/aml-build.h"
> > #include "hw/pci/pci_bus.h"
> > +#include "hw/loader.h"
> >
> > #define FW_CFG_FILE_SLOTS_DFLT 0x20
> >
> > @@ -1221,6 +1222,37 @@ FWCfgState *fw_cfg_find(void)
> > return FW_CFG(object_resolve_path_type("", TYPE_FW_CFG, NULL));
> > }
> >
> > +void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,
> > + uint16_t data_key, const char *image_name,
> > + bool try_decompress)
> > +{
> > + size_t size = -1;
> > + uint8_t *data;
> > +
> > + if (image_name == NULL) {
> > + return;
> > + }
> > +
> > + if (try_decompress) {
> > + size = load_image_gzipped_buffer(image_name,
> > + LOAD_IMAGE_MAX_GUNZIP_BYTES, &data);
> > + }
> > +
> > + if (size == (size_t)-1) {
> > + gchar *contents;
> > + gsize length;
> > +
> > + if (!g_file_get_contents(image_name, &contents, &length, NULL)) {
> > + error_report("failed to load \"%s\"", image_name);
> > + exit(1);
> > + }
> > + size = length;
> > + data = (uint8_t *)contents;
> > + }
> > +
> > + fw_cfg_add_i32(fw_cfg, size_key, size);
> > + fw_cfg_add_bytes(fw_cfg, data_key, data, size);
> > +}
> >
> > static void fw_cfg_class_init(ObjectClass *klass, void *data)
> > {
> > diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h
> > index 0e7a8bc7af..c1f81a5f13 100644
> > --- a/include/hw/nvram/fw_cfg.h
> > +++ b/include/hw/nvram/fw_cfg.h
> > @@ -342,4 +342,25 @@ bool fw_cfg_dma_enabled(void *opaque);
> > */
> > const char *fw_cfg_arch_key_name(uint16_t key);
> >
> > +/**
> > + * load_image_to_fw_cfg() - Load an image file into an fw_cfg entry identified
> > + * by key.
> > + * @fw_cfg: The firmware config instance to store the data in.
> > + * @size_key: The firmware config key to store the size of the loaded
> > + * data under, with fw_cfg_add_i32().
> > + * @data_key: The firmware config key to store the loaded data under,
> > + * with fw_cfg_add_bytes().
> > + * @image_name: The name of the image file to load. If it is NULL, the
> > + * function returns without doing anything.
> > + * @try_decompress: Whether the image should be decompressed (gunzipped) before
> > + * adding it to fw_cfg. If decompression fails, the image is
> > + * loaded as-is.
> > + *
> > + * In case of failure, the function prints an error message to stderr and the
> > + * process exits with status 1.
> > + */
> > +void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key,
> > + uint16_t data_key, const char *image_name,
> > + bool try_decompress);
> > +
> > #endif
> > --
> > 2.25.1
> >
> >
next prev parent reply other threads:[~2022-09-15 12:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-06 9:02 [PATCH V4 0/3] hw/riscv: virt: Enable booting S-mode firmware from pflash Sunil V L
2022-09-06 9:02 ` [PATCH V4 1/3] hw/arm, loongarch: Move load_image_to_fw_cfg() to common location Sunil V L
2022-09-06 13:32 ` [PATCH V4 1/3] hw/arm,loongarch: " Philippe Mathieu-Daudé via
2022-09-08 9:17 ` [PATCH V4 1/3] hw/arm, loongarch: " Alistair Francis
2022-09-15 11:59 ` Sunil V L [this message]
2022-09-15 12:56 ` gaosong
2022-09-22 11:28 ` Sunil V L
2022-09-06 9:02 ` [PATCH V4 2/3] hw/riscv: virt: Move create_fw_cfg() prior to loading kernel Sunil V L
2022-09-08 9:20 ` Alistair Francis
2022-09-06 9:02 ` [PATCH V4 3/3] hw/riscv: virt: Enable booting S-mode firmware from pflash Sunil V L
2022-09-06 10:41 ` [PATCH V4 0/3] " Gerd Hoffmann
2022-09-06 12:32 ` Sunil V L
2022-09-07 7:10 ` Gerd Hoffmann
2022-09-08 10:25 ` [PATCH V4 0/3] hw/riscv: virt: Enable booting S-mode firmware from pflashy Sunil V L
2022-09-08 10:44 ` [PATCH V4 0/3] hw/riscv: virt: Enable booting S-mode firmware from pflash Sunil V L
2022-09-08 11:19 ` [PATCH V4 0/3] hw/riscv: virt: Enable booting S-mode firmware from pflashy Gerd Hoffmann
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=YyMTpMuQ0UP9Mqaz@sunil-laptop \
--to=sunilvl@ventanamicro.com \
--cc=ajones@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=alistair23@gmail.com \
--cc=apatel@ventanamicro.com \
--cc=atishp@rivosinc.com \
--cc=bin.meng@windriver.com \
--cc=f4bug@amsat.org \
--cc=gaosong@loongson.cn \
--cc=kraxel@redhat.com \
--cc=palmer@dabbelt.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=yangxiaojuan@loongson.cn \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).