]> xenbits.xensource.com Git - people/andrewcoop/seabios.git/commitdiff
romfile: add support for constant files.
authorGerd Hoffmann <kraxel@redhat.com>
Mon, 18 Sep 2017 08:47:21 +0000 (10:47 +0200)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 22 Sep 2017 15:13:22 +0000 (11:13 -0400)
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
src/romfile.c
src/romfile.h

index 42261a624cee23741afffc3d54a2f15eb07f49e5..b598274edc0925526708c36eabd518d5aab30ce2 100644 (file)
@@ -98,3 +98,49 @@ romfile_loadint(const char *name, u64 defval)
         return defval;
     return val;
 }
+
+struct const_romfile_s {
+    struct romfile_s file;
+    void *data;
+};
+
+static int
+const_read_file(struct romfile_s *file, void *dst, u32 maxlen)
+{
+    if (file->size > maxlen)
+        return -1;
+    struct const_romfile_s *cfile;
+    cfile = container_of(file, struct const_romfile_s, file);
+    if (maxlen > file->size)
+        maxlen = file->size;
+    memcpy(dst, cfile->data, maxlen);
+    return file->size;
+}
+
+static void
+const_romfile_add(char *name, void *data, int size)
+{
+    struct const_romfile_s *cfile = malloc_tmp(sizeof(*cfile));
+    if (!cfile) {
+        warn_noalloc();
+        return;
+    }
+    memset(cfile, 0, sizeof(*cfile));
+    strtcpy(cfile->file.name, name, sizeof(cfile->file.name));
+    cfile->file.size = size;
+    cfile->file.copy = const_read_file;
+    cfile->data = data;
+    romfile_add(&cfile->file);
+}
+
+void
+const_romfile_add_int(char *name, u32 value)
+{
+    u32 *data = malloc_tmp(sizeof(*data));
+    if (!data) {
+        warn_noalloc();
+        return;
+    }
+    *data = value;
+    const_romfile_add(name, data, sizeof(*data));
+}
index c6d62a1ddca0c5c10336c61fe48e5be6bf2c421e..3e0f820047dd7b9acd60a0ad64e46c741e3c81b1 100644 (file)
@@ -16,4 +16,6 @@ struct romfile_s *romfile_find(const char *name);
 void *romfile_loadfile(const char *name, int *psize);
 u64 romfile_loadint(const char *name, u64 defval);
 
+void const_romfile_add_int(char *name, u32 value);
+
 #endif // romfile.h