Override available memory region passed to Linux by U-boot

It looks that u-boot does not make the whole memory region visible to Linux kernel on my N1 box:

Note the value 78 00 00 00 above, it means u-boot only makes [0, 0x78000000) visible to Linux.

It’s still a puzzle to me why doesn’t u-boot give the whole 2G ram to Linux.

This patch introduced a new property linux,usable-memory to overcome this.

As the memory regions that should be reserved are already listed in /reserved-memory/, I think it should be okay to pass the whole memory region to Linux by adding linux,usable-memory = < 0x00 0x00 0x00 0x80000000 >; to /memory@0/.

Update: After connected to monitor by chance, I just found that the screen messes up, seemingly at the point when u-boot hand control over the Linux. I assume that this is because u-boot somehow programmed the video adaptor uses the memory somewhere in [0x78000000, 0x80000000] as frame buffer. This shouldn’t hurt, though, I think.

This patch for meson-gxbb-odroidc2.dts also seems related. That patch does not expose the first 16M to Linux. But as the first 16M has already been reserved in /reserved-memory/hwrom@0, I don’t see a reason why I should do the same here. It’s still not clear to me why the last 16M is also not exposed to the Linux by that patch.

After applying the patch, Linux is able to see the entire 2G ram:

Of course this is still not 2G (2G should be 524288 pages) in total, that’s because we reserved 5376 pages in /reserved-memory/:

After counting the pages we reserved here ((0x1000000 + 0x200000 + 0x300000) / 4096 is 5376), we finally get the entire 2G ram back.

I run memtester to check if things do work, but as it’s a user-mode program it cannot do a thorough test (for those pages already allocated).

But anyway, it seems to work well:

Diff of the DTS file:

As always, the compiled DTB with the patch above is available here: meson-gxl-s905d-phicomm-n1-usbfix-ethfix-memfix.zip

Update: I can confirm that this dtb completely breaks the display output of my N1 box in Linux 4.20. So, DO NOT USE IT UNLESS YOU’RE RUNNING YOUR N1 BOX HEADLESSLY. However, as I’m indeed using the box headlessly, I’m still using this dtb.

Leave a Reply

Your email address will not be published.