Event Timeline
It looks like the memsize is cumulative so if there are multiple regions I think that won't be what the kernel expects. We'll need to make sure we have correct values in the FDT for the DE4 before we turn this on as I believe it will set memsize too large currently.
I have updated the paste. We can fill phys_avail by using all the memory regions provided in FDT, but seems we still need to ignore the start of first region, as it is dynamic
Setting regions from the FDT does seem like the right thing to do when they are available. I'd include an XXX comment that the first region is assumed to include the kernel as there's no guarantee that's the case in the FDT.
I still don't think updating memsize to the cumulative memory size is safe with multiple regions. I think you either want to set it to rm[0].mr_start + mr[0].mr_size or only use the value if there is only a single region. Arguably, if you're using the regions from FDT you don't need to touch it anyway. Also, I'd avoid increasing memory size or the length of the first region based on the FDT.
I still don't think updating memsize to the cumulative memory size is safe with multiple regions. I think you either want to set it to rm[0].mr_start + mr[0].mr_size or only use the value if there is only a single region. Arguably, if you're using the regions from FDT you don't need to touch it anyway.
The idea here is to overwrite memsize in case of using FDT only, after overwriting it only is used for printf() purposes. So it seems it is correct to show to user cumulative memory size. May be some additional checks required to not use memsize in case of FDT.
Also, I'd avoid increasing memory size or the length of the first region based on the FDT.
Sure.
memsize is used to control size of the first region after the point where you're setting it in:
realmem = btoc(memsize); mips_init();
as I see in init_param2() the cumulative physmem is fine.
so is the last patch fine or I still don't understand ?
This looks good. I would like to see an assert that phys_avail[0] is within the first memory region. Otherwise things are going to go badly wrong if a bad FDT is provide where that isn't true.
I would also move memory node in FDT to the root as fdt_get_mem_regions looks to the root node