Skip to content

Commit bad82ee

Browse files
committed
Fix EEPROM sizes, add vmstate for EEPROM (hacky)
1 parent 66555da commit bad82ee

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

hw/arm/prusa/prusa-mini.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void prusa_mini_init(MachineState *machine, const mini_config_t* cfg)
158158
bus = qdev_get_child_bus(stm32_soc_get_periph(dev_soc, STM32_P_I2C1),"i2c");
159159
dev = qdev_new("at24c-eeprom");
160160
qdev_prop_set_uint8(dev, "address", 0x53);
161-
qdev_prop_set_uint32(dev, "rom-size", 64*KiB);
161+
qdev_prop_set_uint32(dev, "rom-size", 64*KiB / 8U);
162162
dinfo = drive_get(IF_PFLASH, 0, 0);
163163
if (dinfo) {
164164
qdev_prop_set_drive(dev, "drive",
@@ -170,7 +170,7 @@ static void prusa_mini_init(MachineState *machine, const mini_config_t* cfg)
170170
// bus = qdev_get_child_bus(DEVICE(&SOC->i2cs[0]),"i2c");
171171
dev = qdev_new("at24c-eeprom");
172172
qdev_prop_set_uint8(dev, "address", 0x57);
173-
qdev_prop_set_uint32(dev, "rom-size", 64*KiB);
173+
qdev_prop_set_uint32(dev, "rom-size", 64*KiB / 8U);
174174
dinfo = drive_get(IF_PFLASH, 0, 1);
175175
if (dinfo) {
176176
qdev_prop_set_drive(dev, "drive",

hw/nvram/eeprom_at24c.c

+32-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "hw/qdev-properties.h"
1616
#include "hw/qdev-properties-system.h"
1717
#include "sysemu/block-backend.h"
18+
#include "migration/vmstate.h"
1819
#include "qom/object.h"
1920

2021
/* #define DEBUG_AT24C */
@@ -149,18 +150,8 @@ static void at24c_eeprom_realize(DeviceState *dev, Error **errp)
149150
}
150151

151152
ee->mem = g_malloc0(ee->rsize);
152-
}
153-
154-
static
155-
void at24c_eeprom_reset(DeviceState *state)
156-
{
157-
EEPROMState *ee = AT24C_EE(state);
158153

159-
ee->changed = false;
160-
ee->cur = 0;
161-
ee->haveaddr = 0;
162-
// WTF.. I disabled this because real EEPROMS do not erase themselves on reset. ~VintagePC
163-
// memset(ee->mem, 0, ee->rsize);
154+
memset(ee->mem, 0, ee->rsize);
164155

165156
if (ee->blk) {
166157
int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
@@ -173,6 +164,35 @@ void at24c_eeprom_reset(DeviceState *state)
173164
}
174165
}
175166

167+
static
168+
void at24c_eeprom_reset(DeviceState *state)
169+
{
170+
EEPROMState *ee = AT24C_EE(state);
171+
172+
ee->changed = false;
173+
ee->cur = 0;
174+
ee->haveaddr = 0;
175+
// WTF.. I disabled this because real EEPROMS do not erase themselves on reset. ~VintagePC
176+
}
177+
178+
static const VMStateDescription vmstate_eeprom_at24c = {
179+
.name = TYPE_AT24C_EE,
180+
.version_id = 1,
181+
.minimum_version_id = 1,
182+
// .post_load = at24c_eeprom_post_load,
183+
.fields = (VMStateField[]) {
184+
VMSTATE_I2C_SLAVE(parent_obj, EEPROMState),
185+
VMSTATE_UINT16(cur, EEPROMState),
186+
VMSTATE_UINT32(rsize, EEPROMState),
187+
VMSTATE_BOOL(writable, EEPROMState),
188+
VMSTATE_BOOL(changed, EEPROMState),
189+
VMSTATE_UINT8(haveaddr, EEPROMState),
190+
VMSTATE_VARRAY_UINT32(mem, EEPROMState, rsize, 0,
191+
vmstate_info_uint8, uint8_t),
192+
VMSTATE_END_OF_LIST()
193+
}
194+
};
195+
176196
static Property at24c_eeprom_props[] = {
177197
DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0),
178198
DEFINE_PROP_BOOL("writable", EEPROMState, writable, true),
@@ -190,6 +210,7 @@ void at24c_eeprom_class_init(ObjectClass *klass, void *data)
190210
k->event = &at24c_eeprom_event;
191211
k->recv = &at24c_eeprom_recv;
192212
k->send = &at24c_eeprom_send;
213+
dc->vmsd = &vmstate_eeprom_at24c;
193214

194215
device_class_set_props(dc, at24c_eeprom_props);
195216
dc->reset = at24c_eeprom_reset;

0 commit comments

Comments
 (0)