qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Li Guang <lig.fnst@cn.fujitsu.com>
To: Li Guang <lig.fnst@cn.fujitsu.com>
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
	qemu-devel@nongnu.org, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2] hw/misc/blob-loader: add a generic blob loader
Date: Wed, 15 Jan 2014 15:06:19 +0800	[thread overview]
Message-ID: <52D6336B.7030405@cn.fujitsu.com> (raw)
In-Reply-To: <1388990263-23511-1-git-send-email-lig.fnst@cn.fujitsu.com>

ping ...

any other comments?
or new suggestions?

Thanks!


Li Guang wrote:
> this blob loader will be used to load a specified
> blob into a specified RAM address.
>
> Signed-off-by: Li Guang<lig.fnst@cn.fujitsu.com>
> Suggested-by: Peter Crosthwaite<peter.crosthwaite@xilinx.com>
> ---
>   hw/misc/Makefile.objs         |    2 +
>   hw/misc/blob-loader.c         |  112 +++++++++++++++++++++++++++++++++++++++++
>   include/hw/misc/blob-loader.h |   17 ++++++
>   3 files changed, 131 insertions(+), 0 deletions(-)
>   create mode 100644 hw/misc/blob-loader.c
>   create mode 100644 include/hw/misc/blob-loader.h
>
> diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
> index f674365..3edbd5c 100644
> --- a/hw/misc/Makefile.objs
> +++ b/hw/misc/Makefile.objs
> @@ -42,3 +42,5 @@ obj-$(CONFIG_SLAVIO) += slavio_misc.o
>   obj-$(CONFIG_ZYNQ) += zynq_slcr.o
>
>   obj-$(CONFIG_PVPANIC) += pvpanic.o
> +
> +common-obj-y += blob-loader.o
> diff --git a/hw/misc/blob-loader.c b/hw/misc/blob-loader.c
> new file mode 100644
> index 0000000..4f790e5
> --- /dev/null
> +++ b/hw/misc/blob-loader.c
> @@ -0,0 +1,112 @@
> +/*
> + * generic blob loader
> + *
> + * Copyright (C) 2014 Li Guang
> + * Written by Li Guang<lig.fnst@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
> + * for more details.
> + */
> +
> +#include "hw/sysbus.h"
> +#include "hw/devices.h"
> +#include "hw/loader.h"
> +#include "hw/misc/blob-loader.h"
> +#include "qemu/error-report.h"
> +
> +static Property blob_loader_props[] = {
> +    DEFINE_PROP_UINT64("addr", BlobLoaderState, addr, 0),
> +    DEFINE_PROP_STRING("file", BlobLoaderState, file),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static int load_blob_into_ram(const char *file,  uint64_t addr,  int count)
> +{
> +    int fd = -1, size;
> +    uint8_t *data;
> +
> +    fd = open(file, O_RDONLY | O_BINARY);
> +    if (fd == -1) {
> +        error_report("can't open file %s\n", file);
> +        return -1;
> +    }
> +    lseek(fd, 0, SEEK_SET);
> +    data = g_malloc0(count);
> +    size = read(fd, data, count);
> +    if (count != size) {
> +        error_report("%s: read error: %d (expected %d)\n", file, size, count);
> +        return -1;
> +    }
> +    close(fd);
> +
> +    cpu_physical_memory_write_rom(addr, data, size);
> +
> +    g_free(data);
> +    data = NULL;
> +
> +    return 0;
> +}
> +
> +static void blob_loader_reset(DeviceState *dev)
> +{
> +    BlobLoaderState *s = BLOB_LOADER(dev);
> +    int file_size;
> +
> +    file_size = get_image_size(s->file);
> +    if (file_size<  0) {
> +        error_report("can't get file size of %s\n", s->file);
> +        exit(1);
> +    }
> +
> +    if (load_blob_into_ram(s->file, s->addr, file_size)<  0) {
> +        error_report("can't load %s\n", s->file);
> +        exit(1);
> +    }
> +}
> +
> +static void blob_loader_realize(DeviceState *dev, Error **errp)
> +{
> +    BlobLoaderState *s = BLOB_LOADER(dev);
> +    char *file_name;
> +
> +    if (s->file == NULL) {
> +        error_setg(errp, "please spicify a file for blob loader.\n");
> +        return;
> +    }
> +    file_name = qemu_find_file(QEMU_FILE_TYPE_BIOS, s->file);
> +    if (file_name == NULL) {
> +        error_setg(errp, "can't find %s\n", s->file);
> +        return;
> +    }
> +}
> +
> +static void blob_loader_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->reset = blob_loader_reset;
> +    dc->realize = blob_loader_realize;
> +    dc->props = blob_loader_props;
> +    dc->desc = "blob loader";
> +}
> +
> +static TypeInfo blob_loader_info = {
> +    .name = TYPE_BLOB_LOADER,
> +    .parent = TYPE_SYS_BUS_DEVICE,
> +    .instance_size = sizeof(BlobLoaderState),
> +    .class_init = blob_loader_class_init,
> +};
> +
> +static void blob_loader_register_type(void)
> +{
> +    type_register_static(&blob_loader_info);
> +}
> +
> +type_init(blob_loader_register_type)
> diff --git a/include/hw/misc/blob-loader.h b/include/hw/misc/blob-loader.h
> new file mode 100644
> index 0000000..478fd8d
> --- /dev/null
> +++ b/include/hw/misc/blob-loader.h
> @@ -0,0 +1,17 @@
> +#ifndef BLOB_LOADER_H
> +#define BLOB_LOADER_H
> +
> +typedef struct BlobLoaderState {
> +    /*<  private>*/
> +    DeviceState parent_obj;
> +    /*<  public>*/
> +
> +    uint64_t addr;
> +    char *file;
> +} BlobLoaderState;
> +
> +#define TYPE_BLOB_LOADER "blob-loader"
> +#define BLOB_LOADER(obj) OBJECT_CHECK(BlobLoaderState, (obj), TYPE_BLOB_LOADER)
> +
> +#endif
> +
>    

  reply	other threads:[~2014-01-15  7:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-06  6:37 [Qemu-devel] [PATCH v2] hw/misc/blob-loader: add a generic blob loader Li Guang
2014-01-15  7:06 ` Li Guang [this message]
2014-01-15  7:12   ` Peter Crosthwaite
2014-01-16  2:35     ` Li Guang

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=52D6336B.7030405@cn.fujitsu.com \
    --to=lig.fnst@cn.fujitsu.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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).