Re: [PATCH v2 3/4] board: Add QEMU m68k virt board support

Daniel Palmer
2025-12-28T01:16:20Z

Hi Kuan-Wei,

On Sat, 27 Dec 2025 at 02:54, Kuan-Wei Chiu <visitorckw@gmail.com> wrote:
> diff --git a/board/emulation/qemu-m68k/qemu-m68k.c b/board/emulation/qemu-m68k/qemu-m68k.c

> +int dram_init(void)
> +{

> + /* QEMU places bootinfo after _end, aligned to 2 bytes */
> + addr = (ulong)&_end;
> + if (addr & 1)
> + addr++;

Maybe ALIGN() or round_up() could be used here instead of manually coding it?

> + record = (struct bi_record *)addr;
> +
> + if (record->tag != BI_MACHTYPE)
> + return 0;
> +
> + while (record->tag != BI_LAST) {
> + if (record->tag == BI_MEMCHUNK) {
> + gd->ram_size = record->data[1];
> + break;
> + }
> + record = (struct bi_record *)((ulong)record + record->size);
> + }

One thing I found when I did the bootinfo parsing in my version is if
I corrupted (during relocation etc) the bootinfo this type of loop
would often get stuck forever.
I'm not sure what the technical limit of the number of bootinfo
entries is but bounding this to something reasonable feels like a good
idea.

Cheers,

Daniel