Skip to content

Commit c2bed99

Browse files
zbalatonnpiggin
authored andcommitted
ppc/amigaone: Add default environment
Initialise empty NVRAM with default values. This also enables IDE UDMA mode in AmigaOS that is faster but has to be enabled in environment due to problems with real hardware but that does not affect emulation so we can use faster defaults here. Signed-off-by: BALATON Zoltan <[email protected]> Reviewed-by: Nicholas Piggin <[email protected]> Message-ID: <4d63f88191612329e0ca8102c7c0d4fc626dc372.1740673173.git.balaton@eik.bme.hu> Signed-off-by: Nicholas Piggin <[email protected]>
1 parent addff51 commit c2bed99

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

hw/ppc/amigaone.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ static const char dummy_fw[] = {
5252
#define NVRAM_ADDR 0xfd0e0000
5353
#define NVRAM_SIZE (4 * KiB)
5454

55+
static char default_env[] =
56+
"baudrate=115200\0"
57+
"stdout=vga\0"
58+
"stdin=ps2kbd\0"
59+
"bootcmd=boota; menu; run menuboot_cmd\0"
60+
"boot1=ide\0"
61+
"boot2=cdrom\0"
62+
"boota_timeout=3\0"
63+
"ide_doreset=on\0"
64+
"pci_irqa=9\0"
65+
"pci_irqa_select=level\0"
66+
"pci_irqb=10\0"
67+
"pci_irqb_select=level\0"
68+
"pci_irqc=11\0"
69+
"pci_irqc_select=level\0"
70+
"pci_irqd=7\0"
71+
"pci_irqd_select=level\0"
72+
"a1ide_irq=1111\0"
73+
"a1ide_xfer=FFFF\0";
74+
#define CRC32_DEFAULT_ENV 0xb5548481
75+
#define CRC32_ALL_ZEROS 0x603b0489
76+
5577
#define TYPE_A1_NVRAM "a1-nvram"
5678
OBJECT_DECLARE_SIMPLE_TYPE(A1NVRAMState, A1_NVRAM)
5779

@@ -94,7 +116,7 @@ static void nvram_realize(DeviceState *dev, Error **errp)
94116
{
95117
A1NVRAMState *s = A1_NVRAM(dev);
96118
void *p;
97-
uint32_t *c;
119+
uint32_t crc, *c;
98120

99121
memory_region_init_rom_device(&s->mr, NULL, &nvram_ops, s, "nvram",
100122
NVRAM_SIZE, &error_fatal);
@@ -113,12 +135,25 @@ static void nvram_realize(DeviceState *dev, Error **errp)
113135
return;
114136
}
115137
}
138+
crc = crc32(0, p + 4, NVRAM_SIZE - 4);
139+
if (crc == CRC32_ALL_ZEROS) { /* If env is uninitialized set default */
140+
*c = cpu_to_be32(CRC32_DEFAULT_ENV);
141+
/* Also copies terminating \0 as env is terminated by \0\0 */
142+
memcpy(p + 4, default_env, sizeof(default_env));
143+
if (s->blk) {
144+
blk_pwrite(s->blk, 0, sizeof(crc) + sizeof(default_env), p, 0);
145+
}
146+
return;
147+
}
116148
if (*c == 0) {
117149
*c = cpu_to_be32(crc32(0, p + 4, NVRAM_SIZE - 4));
118150
if (s->blk) {
119151
blk_pwrite(s->blk, 0, 4, p, 0);
120152
}
121153
}
154+
if (be32_to_cpu(*c) != crc) {
155+
warn_report("NVRAM checksum mismatch");
156+
}
122157
}
123158

124159
static const Property nvram_properties[] = {

0 commit comments

Comments
 (0)