hw/misc/blob-loader: add a generic blob loader
PATCH v2 1/1 hw/misc/blob-loader: add a generic blob loader
this blob loader will be used to load a specified
blob into a specified RAM address.
--- 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
hw/misc/Makefile.objs +2 -0
@@ -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
hw/misc/blob-loader.c new file +112 -0
112 lines not on this page · raw message
include/hw/misc/blob-loader.h new file +17 -0
@@ -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 +
Signature · 1 line
1.7.2.5
ping ...
any other comments?
or new suggestions?
Thanks!
Quoted 165 lines · Li Guang
this blob loader will be used to load a specified
blob into a specified RAM address.Signed-off-by Li Guang<[email protected]>Suggested-by Peter Crosthwaite<[email protected]>--- 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.ccreate mode 100644include/hw/misc/blob-loader.hhw/misc/Makefile.objs +2
-0@@ -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.ohw/misc/blob-loader.c new file +112
-0@@ -0,0 +1,112 @@ +/* +* generic blob loader +* +* Copyright (C) 2014 Li Guang +* Written by Li Guang<[email protected]> +* +* 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)include/hw/misc/blob-loader.h new file +17
-0@@ -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 +
Quoted 5 lines · Li Guang
ping ...
any other comments?
or new suggestions?
No new suggestions from me, but PMM has a point about load_image_targphys@realize doing exactly whats needed, so something closer to V1 WRT to that may actually be best.
Regards,
peter
Quoted 180 lines
Thanks!
Quoted 172 lines · Li Guang
this blob loader will be used to load a specified
blob into a specified RAM address.Signed-off-by Li Guang<[email protected]>Suggested-by Peter Crosthwaite<[email protected]>--- 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.ccreate mode 100644include/hw/misc/blob-loader.hhw/misc/Makefile.objs +2
-0@@ -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.ohw/misc/blob-loader.c new file +7
-0@@ -0,0 +1,112 @@ +/* +* generic blob loader +* +* Copyright (C) 2014 Li Guang +* Written by Li Guang<[email protected]> +* +* 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.
+ */hw/misc/blob-loader.c new file +14
-0+ +#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, intcount)
hw/misc/blob-loader.c new file +14
-0+{ +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);
hw/misc/blob-loader.c new file +68
-0+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)include/hw/misc/blob-loader.h new file +14
-0@@ -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)include/hw/misc/blob-loader.h new file +3
-0+ +#endif +
Quoted 4 lines · Peter Crosthwaite
Quoted 2 lines · Li Guang
ping ...
Quoted 10 lines
Quoted 4 lines
any other comments?
or new suggestions?No new suggestions from me, but PMM has a point about load_image_targphys@realize doing exactly whats needed, so something closer to V1 WRT to that may actually be best.
but I still don't be clear with the direction, as PMM also said "unconvinced by the general approach of having a device with an address property".
or, I should extend the "-machine firmware=xxx" interface
to be general?
Thanks!
Li Guang
Quoted 184 lines
Quoted 182 lines
Thanks!
Quoted 172 lines · Li Guang
this blob loader will be used to load a specified
blob into a specified RAM address.Signed-off-by Li Guang<[email protected]>Suggested-by Peter Crosthwaite<[email protected]>--- 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.ccreate mode 100644include/hw/misc/blob-loader.hhw/misc/Makefile.objs +2
-0@@ -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.ohw/misc/blob-loader.c new file +7
-0@@ -0,0 +1,112 @@ +/* +* generic blob loader +* +* Copyright (C) 2014 Li Guang +* Written by Li Guang<[email protected]> +* +* 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.
+ */hw/misc/blob-loader.c new file +14
-0+ +#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, intcount)
hw/misc/blob-loader.c new file +14
-0+{ +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);
hw/misc/blob-loader.c new file +68
-0+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)include/hw/misc/blob-loader.h new file +14
-0@@ -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)include/hw/misc/blob-loader.h new file +3
-0+ +#endif +