From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3Ka7-00065v-2i for qemu-devel@nongnu.org; Wed, 15 Jan 2014 02:08:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3Ka2-0001zA-Nr for qemu-devel@nongnu.org; Wed, 15 Jan 2014 02:08:07 -0500 Received: from [222.73.24.84] (port=40805 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3Ka1-0001xi-SD for qemu-devel@nongnu.org; Wed, 15 Jan 2014 02:08:02 -0500 Message-ID: <52D6336B.7030405@cn.fujitsu.com> Date: Wed, 15 Jan 2014 15:06:19 +0800 From: Li Guang MIME-Version: 1.0 References: <1388990263-23511-1-git-send-email-lig.fnst@cn.fujitsu.com> In-Reply-To: <1388990263-23511-1-git-send-email-lig.fnst@cn.fujitsu.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1; format=flowed Subject: Re: [Qemu-devel] [PATCH v2] hw/misc/blob-loader: add a generic blob loader List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Li Guang Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, qemu-devel@nongnu.org, pbonzini@redhat.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 > Suggested-by: Peter Crosthwaite > --- > 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 > + * > + * 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 > + >