From: Olivia Yin <hong-hua.yin@freescale.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: Olivia Yin <hong-hua.yin@freescale.com>
Subject: [Qemu-devel] [RFC PATCH v4 1/3] use image_file_reset to reload initrd image
Date: Wed, 14 Nov 2012 21:28:50 +0800 [thread overview]
Message-ID: <1352899732-1197-2-git-send-email-hong-hua.yin@freescale.com> (raw)
In-Reply-To: <1352899732-1197-1-git-send-email-hong-hua.yin@freescale.com>
Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com>
---
hw/loader.c | 39 +++++++++++++++++++++++++++++++++++++++
hw/loader.h | 7 +++++++
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/hw/loader.c b/hw/loader.c
index ba01ca6..a8a0a09 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -86,6 +86,39 @@ int load_image(const char *filename, uint8_t *addr)
return size;
}
+static void image_file_reset(void *opaque)
+{
+ ImageFile *image = opaque;
+ GError *err = NULL;
+ gboolean res;
+ gchar *content;
+ gsize size;
+
+ if(image->dir) {
+ const char *basename;
+ char fw_file_name[56];
+
+ basename = strrchr(image->name, '/');
+ if (basename) {
+ basename++;
+ } else {
+ basename = image->name;
+ }
+ snprintf(fw_file_name, sizeof(fw_file_name), "%s/%s", image->dir,
+ basename);
+ image->name = g_strdup(fw_file_name);
+ }
+
+ res = g_file_get_contents(image->name, &content, &size, &err);
+ if (res == FALSE) {
+ error_report("failed to read image file: %s\n", image->name);
+ g_error_free(err);
+ } else {
+ cpu_physical_memory_write(image->addr, (uint8_t *)content, size);
+ g_free(content);
+ }
+}
+
/* read()-like version */
ssize_t read_targphys(const char *name,
int fd, hwaddr dst_addr, size_t nbytes)
@@ -113,6 +146,12 @@ int load_image_targphys(const char *filename,
}
if (size > 0) {
rom_add_file_fixed(filename, addr, -1);
+ ImageFile *image;
+ image = g_malloc0(sizeof(*image));
+ image->name = g_strdup(filename);
+ image->addr = addr;
+
+ qemu_register_reset(image_file_reset, image);
}
return size;
}
diff --git a/hw/loader.h b/hw/loader.h
index 26480ad..d021629 100644
--- a/hw/loader.h
+++ b/hw/loader.h
@@ -1,6 +1,13 @@
#ifndef LOADER_H
#define LOADER_H
+typedef struct ImageFile ImageFile;
+struct ImageFile {
+ char *name;
+ char *dir;
+ hwaddr addr;
+};
+
/* loader.c */
int get_image_size(const char *filename);
int load_image(const char *filename, uint8_t *addr); /* deprecated */
--
1.7.1
next prev parent reply other threads:[~2012-11-14 14:14 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-14 13:28 [Qemu-devel] [RFC PATCH v4 0/3] reload kernel/initrd/elf images when reset Olivia Yin
2012-11-14 13:28 ` Olivia Yin [this message]
2012-11-14 13:28 ` [Qemu-devel] [RFC PATCH v4 2/3] use uimage_reset to reload uimage Olivia Yin
2012-11-14 13:28 ` [Qemu-devel] [RFC PATCH v4 3/3] use elf_reset to reload elf image Olivia Yin
2012-11-17 16:09 ` [Qemu-devel] [Qemu-ppc] " Blue Swirl
2012-11-15 20:46 ` [Qemu-devel] [RFC PATCH v4 2/3] use uimage_reset to reload uimage Stuart Yoder
2012-11-16 6:11 ` Yin Olivia-R63875
2012-11-19 11:26 ` [Qemu-devel] [Qemu-ppc] " Alexander Graf
2012-11-15 19:52 ` [Qemu-devel] [RFC PATCH v4 1/3] use image_file_reset to reload initrd image Stuart Yoder
2012-11-16 5:50 ` Yin Olivia-R63875
2012-11-15 5:12 ` [Qemu-devel] [RFC PATCH v4 0/3] reload kernel/initrd/elf images when reset Yin Olivia-R63875
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=1352899732-1197-2-git-send-email-hong-hua.yin@freescale.com \
--to=hong-hua.yin@freescale.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).