raspi4b is improperly hard-coded to 2GB of RAM with no other options
The Raspberry Pi 4B supports 1GB, 2GB, 4GB or 8GB LPDDR4-3200 SDRAM. Additionally, its Cortex-A72 processor core supports up to 16GB of RAM, and there's no restriction in Raspberry Pi OS (64-bit) that would prevent 16GB of RAM from working.
However, QEMU arbitrarily limits memory to exactly 2GB (no more or less) on a 64-bit architecture (1GB if 32-bit) when -machine raspi4bp is specified. This is hard-coded in hw/arm/raspi4b.c:
#if HOST_LONG_BITS == 32
rmc->board_rev = 0xa03111; /* Revision 1.1, 1 Gb RAM */
#else
rmc->board_rev = 0xb03115; /* Revision 1.5, 2 Gb RAM */
#endif
The ram size is extracted from that ^ board revision in hw/arm/raspi.c:
uint64_t board_ram_size(uint32_t board_rev)
{
assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */
return 256 * MiB << FIELD_EX32(board_rev, REV_CODE, MEMORY_SIZE);
}
And if the specified ram size does not exactly match this extracted ram size, QEMU quits with an error:
uint32_t board_rev = mc->board_rev;
uint64_t ram_size = board_ram_size(board_rev);
...
if (machine->ram_size != ram_size) {
char *size_str = size_to_str(ram_size);
error_report("Invalid RAM size, should be %s", size_str);
g_free(size_str);
exit(1);
}
Here's the output:
$ qemu-system-aarch64 -machine raspi4b -smp 4 -cpu cortex-a72 -m 8G ...
qemu-system-aarch64: Invalid RAM size, should be 2 GiB
I don't see a compelling reason to impose any limit on the memory size for raspi4b (let the user deal with any problems that come from specifying memory sizes that Raspberry Pi OS doesn't support), but if we have to impose a limit, it should be limited at the very least to one of the explicitly supported model options (1GB, 2GB, 4GB, 8GB) and, preferably, also 16GB since the processor and OS are known to support that.