[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2] hw/misc/blob-loader: add a generic blob load
From: |
Peter Crosthwaite |
Subject: |
Re: [Qemu-devel] [PATCH v2] hw/misc/blob-loader: add a generic blob loader |
Date: |
Wed, 15 Jan 2014 17:12:52 +1000 |
On Wed, Jan 15, 2014 at 5:06 PM, Li Guang <address@hidden> wrote:
> ping ...
>
> any other comments?
> or new suggestions?
>
No new suggestions from me, but PMM has a point about
address@hidden doing exactly whats needed, so something
closer to V1 WRT to that may actually be best.
Regards,
peter
> 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<address@hidden>
>> Suggested-by: Peter Crosthwaite<address@hidden>
>> ---
>> 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<address@hidden>
>> + *
>> + * 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
>> +
>>
>
>
>