Add a way to set a backing store for the mac_nvram similar to what
spapr_nvram or mac_via PRAM already does to allow to save its contents
between runs. Use -drive file=nvram.img,format=raw,if=mtd to specify
backing file where nvram.img must be MACIO_NVRAM_SIZE which is 8192
bytes. It is only wired for mac_oldworld for now but could be used by
mac_newworld in the future too.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
hw/nvram/mac_nvram.c | 28 ++++++++++++++++++++++++++++
hw/ppc/mac_oldworld.c | 8 +++++++-
include/hw/nvram/mac_nvram.h | 1 +
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/hw/nvram/mac_nvram.c b/hw/nvram/mac_nvram.c
index 3d9ddda217..810e84f07e 100644
--- a/hw/nvram/mac_nvram.c
+++ b/hw/nvram/mac_nvram.c
@@ -24,9 +24,12 @@
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "hw/nvram/chrp_nvram.h"
#include "hw/nvram/mac_nvram.h"
#include "hw/qdev-properties.h"
+#include "hw/qdev-properties-system.h"
+#include "sysemu/block-backend.h"
#include "migration/vmstate.h"
#include "qemu/cutils.h"
#include "qemu/module.h"
@@ -44,6 +47,9 @@ static void macio_nvram_writeb(void *opaque, hwaddr addr,
addr = (addr >> s->it_shift) & (s->size - 1);
trace_macio_nvram_write(addr, value);
s->data[addr] = value;
+ if (s->blk) {
+ blk_pwrite(s->blk, addr, 1, &s->data[addr], 0);
+ }
}
static uint64_t macio_nvram_readb(void *opaque, hwaddr addr,
@@ -91,6 +97,27 @@ static void macio_nvram_realizefn(DeviceState *dev,
Error **errp)
s->data = g_malloc0(s->size);
+ if (s->blk) {
+ int64_t len = blk_getlength(s->blk);
+ if (len < 0) {
+ error_setg_errno(errp, -len,
+ "could not get length of nvram backing
image");
+ return;
+ } else if (len != s->size) {
+ error_setg_errno(errp, -len,
+ "invalid size nvram backing image");
+ return;
+ }
+ if (blk_set_perm(s->blk, BLK_PERM_CONSISTENT_READ |
BLK_PERM_WRITE,
+ BLK_PERM_ALL, errp) < 0) {
+ return;
+ }
+ if (blk_pread(s->blk, 0, s->size, s->data, 0) < 0) {
+ error_setg(errp, "can't read-nvram contents");
+ return;
+ }