ramips: mt7621: do memory detection on KSEG1
authorChuanhong Guo <[email protected]>
Mon, 21 Feb 2022 02:22:02 +0000 (03:22 +0100)
committerChuanhong Guo <[email protected]>
Tue, 22 Feb 2022 12:48:46 +0000 (20:48 +0800)
commit7612ecb201eebd0b273aa9225539fd45d538a1db
tree70df40423970c482968d5f637d446cc174a1eb69
parent7fc336484b1e4727f419dd930955048f323580be
ramips: mt7621: do memory detection on KSEG1

It's reported that current memory detection code occasionally detects
larger memory under some bootloaders.
Current memory detection code tests whether address space wraps around
on KSEG0, which is unreliable because it's cached.

Rewrite memory size detection to perform the same test on KSEG1 instead.
While at it, this patch also does the following two things:
1. use a fixed pattern instead of a random function pointer as the magic
   value.
2. add an additional memory write and a second comparison as part of the
   test to prevent possible smaller memory detection result due to
   leftover values in memory.

Fixes: 6d91ddf517 ("ramips: mt7621: add support for memory detection")
Reported-by: Rui Salvaterra <[email protected]>
Tested-by: Rui Salvaterra <[email protected]>
Signed-off-by: Chuanhong Guo <[email protected]>
(cherry picked from commit 2f024b79331141e2a62c9bf3601c803b26bde77b)
[backport for OpenWrt 21.02 as it was reproducible with Kernel 5.4, see [1]]
[1]: https://forum.openwrt.org/t/113081
Tested-by: Dimitri Souza <[email protected]> [mt7621/archer-c6-v3]
Signed-off-by: Szabolcs Hubai <[email protected]>
target/linux/ramips/patches-5.4/325-mt7621-fix-memory-detect.patch [new file with mode: 0644]